Merge branch 'feature/resource' of https://gitea.qinmian.online/CY/mcwl-ai into preview

# Conflicts:
#	mcwl-admin/pom.xml
feature/comment
ChenYan 2024-12-31 16:09:18 +08:00
commit 9d5cf6040d
38 changed files with 2410 additions and 36 deletions

View File

@ -61,32 +61,33 @@
<artifactId>mcwl-myInvitation</artifactId>
<version>3.8.8</version>
</dependency>
<!-- 资源中心模块-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-memberCenter</artifactId>
<artifactId>mcwl-resource</artifactId>
<version>3.8.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 代码生成-->
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-generator</artifactId>
</dependency>
<dependency>
<groupId>com.mcwl</groupId>
<artifactId>mcwl-memberCenter</artifactId>
<version>3.8.8</version>
</dependency>
<!-- rabbitmq依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>3.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,96 @@
package com.mcwl.web.controller.resource;
import com.mcwl.common.core.controller.BaseController;
import com.mcwl.common.utils.ResponsePageEntity;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.service.MallProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.web.controller.resource
* @FilenameMallProductController
* @Description
* @Date2024/12/31 10:48
*/
@RestController
@RequestMapping("/MallProduct")
public class MallProductController extends BaseController {
private final MallProductService mallProductService;
public MallProductController(MallProductService mallProductService) {
this.mallProductService = mallProductService;
}
// /**
// * 通过id查询商品图片信息
// *
// * @param id 系统ID
// * @return 商品图片信息
// */
// @ApiOperation(notes = "通过id查询商品图片信息", value = "通过id查询商品图片信息")
// @GetMapping("/findById")
// public MallProduct findById(Long id) {
// return mallProductService.findById(id);
// }
//
// /**
// * 根据条件查询商品图片列表
// *
// * @param mallProduct 条件
// * @return 商品图片列表
// */
// @ApiOperation(notes = "根据条件查询商品图片列表", value = "根据条件查询商品图片列表")
// @PostMapping("/searchByPage")
// public ResponsePageEntity<MallProduct> searchByPage(@RequestBody MallProduct mallProduct) {
// return mallProductService.searchByPage(mallProduct);
// }
//
//
// /**
// * 添加商品图片
// *
// * @param mallProduct 商品实体
// * @return 影响行数
// */
// @ApiOperation(notes = "添加商品", value = "添加商品")
// @PostMapping("/insert")
// public int insert(@RequestBody MallProduct mallProduct) {
// return mallProductService.insert(mallProduct);
// }
//
// /**
// * 修改商品
// *
// * @param mallProduct 商品实体
// * @return 影响行数
// */
// @ApiOperation(notes = "修改商品", value = "修改商品")
// @PostMapping("/update")
// public int update(@RequestBody MallProduct mallProduct) {
// return mallProductService.update(mallProduct);
// }
//
// /**
// * 批量删除商品
// *
// * @param ids 商品ID集合
// * @return 影响行数
// */
// @ApiOperation(notes = "批量删除商品", value = "批量删除商品")
// @PostMapping("/deleteByIds")
// public int deleteByIds(@RequestBody @NotNull List<Long> ids) {
// return mallProductService.deleteByIds(ids);
// }
//
}

View File

@ -17,7 +17,6 @@
</description>
<dependencies>
<!-- Spring框架基本的核心工具 -->
<dependency>
<groupId>org.springframework</groupId>

View File

@ -1,18 +0,0 @@
package com.mcwl.common.domain;
import lombok.Data;
/**
*
*/
@Data
public class ResponsetEntity {
private Integer code;
private String message;
private Object data;
}

View File

@ -0,0 +1,38 @@
package com.mcwl.common.domain.response;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class OCRBackResult {
@JsonProperty("config_str")
private String configStr;
@JsonProperty("start_date")
@Schema(description = "开始日期")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@JsonProperty("end_date")
@Schema(description = "结束日期")
private String endDate;
@JsonProperty("issue")
@Schema(description = "签发机关")
private String issue;
@JsonProperty("is_fake")
private boolean isFake;
private String imagePath;
@JsonProperty("success")
private boolean success;
// Getters and setters
}

View File

@ -0,0 +1,220 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.domain.response;
import com.mcwl.common.i18n.I18nMessage;
/**
* @author FrozenWatermelon
* @date 2020/7/9
*/
public enum ResponseEnum {
/**
* ok
*/
OK("00000", "ok"),
/**
*
*/
SHOW_FAIL("A00001", ""),
/**
*
*/
SHOW_SUCCESS("A00002", ""),
/**
*
*/
UNAUTHORIZED("A00004", "Unauthorized"),
/**
*
*/
EXCEPTION("A00005", "服务器出了点小差"),
/**
* TempUid
*
* 1. tempUid
* 2. localstorage tempUid
* codetempUid
*/
TEMP_UID_ERROR("A00012", "TempUid Error"),
/**
*
*/
NOT_FOUND("A00013", "接口不存在"),
/**
*
*/
METHOD_ARGUMENT_NOT_VALID("A00014", "方法参数没有校验"),
/**
*
*/
PAY_PASSWORD_ERROR("A00015", I18nMessage.getMessage("yami.user.pay.password.error")),
SCANCODE_PAY_ERROR("A00016", "扫描支付发生错误"),
NEW_USER_NO_INVITOR_ERROR("A00017", "新注册用户必须填写邀请码"),
NEW_USER_INVITOR_ERROR("A00018", "邀请码错误"),
/**
* 01
*
*/
// SPU_NOT_EXIST("A01000", "商品不存在"),
/**
* 02
*/
// SHOP_CART_NOT_EXIST("A02000", "商品已下架"),
/**
* 03
*/
API_ORDER_NOT_EXIST("A03000", "订单不存在"),
ORDER_BUSY("A03001", "订单繁忙,请稍后再试"),
/**
*
*/
ORDER_DELIVERY_NOT_SUPPORTED("A03001", "The delivery method is not supported"),
/**
*
* 1.
* 2.
*/
REPEAT_ORDER("A03002", "订单已过期,请重新下单"),
/**
*
*/
COUPON_CANNOT_USE_TOGETHER("A03003", "优惠券不能共用"),
/**
*
*/
COUPON_OF_RMRT_GT_ORDER("A03004", "代金券金额超过了订单金额"),
/**
* bodyskuidskuId
*/
NOT_STOCK("A03010", "not stock"),
/**
*
*/
SOCIAL_ACCOUNT_BIND_BY_OTHER("A04002", "social account bind by other"),
/**
*
*/
DESTROY_USER_FAIL("A05000", "您的账户当前有未完成的订单,请待所有订单完成后再注销账户"),
/**
*
*/
DELIVERY_OVER("A07001", ""),
/**
*
*/
ACCOUNT_REPEAT("P01001", "账号已经被使用"),
ACCOUNT_NOT_EXIT("P01002", "账号不存在"),
ACCOUNT_NOT_ROLE("P01003", "账号不存在角色"),
ACCOUNT_STATUS_ERROR("P01004", "账号被锁"),
ACCOUNT_NOT_AREA("P01005", "账号没绑定经营地区"),
ACCOUNT_CREATE_ERROR("P01006", "账号创建失败"),
ACCOUNT_NO_MENU("P01007", "账号无菜单权限"),
PUSH_ID_NO_ACCOUNT("P01008", "该id无账号"),
ACCOUNT_ERROR("P01009", "账号权限错误"),
QUERY_TYPE_ERROR("P01010", "分页查询用户类型有误"),
// P02 钱包类
PUSH_USER_WALLET_NOT_EXIST("P02001", "用户钱包不存在"),
ORDER_NOT_EXIST("P02002", "订单不存在"),
NOT_SCANCODE_ORDER("P02003", "订单不是扫码下单"),
NOT_PAY_ORDER("P02004", "订单为未支付完成"),
ACTUAL_PAY_LITTLE_ORDER("P02005", "订单支付金额小于1元不进行分成"),
NOT_BIND_ORDER("P02006", "订单商家未被推客绑定,不进行分成"),
PUSH_ERR("P02007", "分成失败"),
ACCOUNT_WX_BIND("P02101","改用户已经绑定openid" ),
WX_APPID_SECRET_ERR("P02102","获取配置的appid错误" ),
WITHDRAW_EXCESS_ERROR("P02005", "提现金额超出可提现额度"),
SHOP_BANK_CARD_NOT_EXIST("P02006", "银行卡不存在"),
SHOP_BANK_CARD_STATE_ERROR("P02007", "申请提现银行卡状态错误"),
SHOP_BANK_ACCOUNT_ERROR("P02008", "注册新生账号异常"),
SHOP_BANK_BIND_CONFIRM("P02010", "请输入验证码绑定银行卡"),
/**
* C
*/
ACCESS_TOKEN_ERR("C01001", "获取access_token失败"),
TICKET_ERR("C01002", "获取ticket失败"),
GENERATE_URL_LINK_ERR("C01003", "创建URLLink失败"),
GET_WX_CODE_SESSION_ERR("C01004", "微信登录凭证校验败"),
DATA_EXISTS("C01009", "数据已存在"),
DATA_NOT_CHANGE_ABLE("C01010", "数据不可变更"),
/**
*
*/
RPC_CALL_EXCEPTION("A08001", ""),
/**
*
*/
RPC_CALL_HTTP_EXCEPTION("A08002", ""),
BAIDU_MAP_CONVERT_ERROR("A08003","百度地图接口调用错误" ),
/**
* T
*/
REPEAT_ACTIVITY_SUB_ITEM("T00001", "重复的活动子项目"),;
private final String code;
private final String msg;
public String value() {
return code;
}
public String getMsg() {
return msg;
}
ResponseEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public String toString() {
return "ResponseEnum{" + "code='" + code + '\'' + ", msg='" + msg + '\'' + "} " + super.toString();
}
}

View File

@ -0,0 +1,215 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.domain.response;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.mcwl.common.config.serializer.SensitiveJsonSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.util.Objects;
/**
*
* @author mcwl
*/
public class ServerResponseEntity<T> implements Serializable {
private static final Logger log = LoggerFactory.getLogger(ServerResponseEntity.class);
/**
*
*/
@Schema(description = "状态码" ) private String code;
/**
*
*/
@Schema(description = "信息" ) private String msg;
/**
*
*/
@Schema(description = "数据" )
@JsonSerialize(using = SensitiveJsonSerializer.class)
private T data;
/**
*
*/
private String version;
/**
*
*/
private Long timestamp;
private String sign;
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public ServerResponseEntity setData(T data) {
this.data = data;
return this;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public boolean isSuccess() {
return Objects.equals(ResponseEnum.OK.value(), this.code);
}
public boolean isFail() {
return !Objects.equals(ResponseEnum.OK.value(), this.code);
}
public ServerResponseEntity() {
// 版本号
this.version = "mall4j.v231204";
}
public static <T> ServerResponseEntity<T> success(T data) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setData(data);
serverResponseEntity.setCode(ResponseEnum.OK.value());
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> success() {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(ResponseEnum.OK.value());
serverResponseEntity.setMsg(ResponseEnum.OK.getMsg());
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> success(Integer code, T data) {
return success(String.valueOf(code), data);
}
public static <T> ServerResponseEntity<T> success(String code, T data) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(code);
serverResponseEntity.setData(data);
return serverResponseEntity;
}
/**
*
* @param msg
* @return
*/
public static <T> ServerResponseEntity<T> showFailMsg(String msg) {
log.error(msg);
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(msg);
serverResponseEntity.setCode(ResponseEnum.SHOW_FAIL.value());
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> fail(ResponseEnum responseEnum) {
log.error(responseEnum.toString());
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(responseEnum.getMsg());
serverResponseEntity.setCode(responseEnum.value());
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> fail(ResponseEnum responseEnum, T data) {
log.error(responseEnum.toString());
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(responseEnum.getMsg());
serverResponseEntity.setCode(responseEnum.value());
serverResponseEntity.setData(data);
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> fail(String code, String msg, T data) {
log.error(msg);
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(msg);
serverResponseEntity.setCode(code);
serverResponseEntity.setData(data);
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> fail(String code, String msg) {
return fail(code, msg, null);
}
public static <T> ServerResponseEntity<T> fail(Integer code, T data) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(String.valueOf(code));
serverResponseEntity.setData(data);
return serverResponseEntity;
}
@SuppressWarnings("unchecked")
public static <T> ServerResponseEntity<T> transform(ServerResponseEntity<?> oldServerResponseEntity) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(oldServerResponseEntity.getMsg());
serverResponseEntity.setCode(oldServerResponseEntity.getCode());
serverResponseEntity.setData((T) oldServerResponseEntity.getData());
log.error(serverResponseEntity.toString());
return serverResponseEntity;
}
@Override
public String toString() {
return "ServerResponseEntity{" +
"code='" + code + '\'' +
", msg='" + msg + '\'' +
", data=" + data +
", version='" + version + '\'' +
", timestamp=" + timestamp +
", sign='" + sign + '\'' +
'}';
}
}

View File

@ -0,0 +1,53 @@
package com.mcwl.common.enums;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.ToString;
@ToString
@AllArgsConstructor
@ApiModel(value = "返回对象", description = "返回状态")
public enum ResponseCodeEnum {
FAILED_STATE_ENUM(0, "failed"),
SUCCESS_STATE_ENUM(1, "success"),
LOCK_STATE_ENUM(2, "lock"),
PAY_SUCCESS_STATE_UPPER_CASE_ENUM(4, "SUCCESS"),
PAY_FAIL_STATE_UPPER_CASE_ENUM(5, "FAIL"),
UNLOCK_STATE_ENUM(3, "unlock");
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
private String name;
private int index;
private ResponseCodeEnum(int index, String name) {
this.index = index;
this.name = name;
}
public static String getName(int index) {
for (ResponseCodeEnum rkd : ResponseCodeEnum.values()) {
if (rkd.index == index) {
return rkd.name;
}
}
return null;
}
}

View File

@ -4,8 +4,6 @@ import com.mcwl.common.enums.ResultCode;
/**
*
* @author DaiZibo
* @date 2024/12/30
* @apiNote
*/

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.exception;
import com.mcwl.common.domain.response.ResponseEnum;
import lombok.Getter;
/**
*
* @author mcwl
*/
@Getter
public class YamiBizException extends RuntimeException{
/**
*
*/
private static final long serialVersionUID = -4137688758944857209L;
/**
* http
*/
private String code;
/**
* @param responseEnum http
*/
public YamiBizException(ResponseEnum responseEnum) {
super(responseEnum.getMsg());
this.code = responseEnum.value();
}
/**
* @param responseEnum http
*/
public YamiBizException(ResponseEnum responseEnum, String msg) {
super(msg);
this.code = responseEnum.value();
}
public YamiBizException(String msg) {
// super(msg);
super(msg);
this.code = ResponseEnum.SHOW_FAIL.value();
}
public YamiBizException(String code,String msg) {
// super(msg);
super(msg);
this.code = code;
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.exception;
import com.mcwl.common.domain.response.ResponseEnum;
import com.mcwl.common.domain.response.ServerResponseEntity;
import com.mcwl.common.i18n.I18nMessage;
import lombok.Getter;
/**
*
* @author mcwl
*/
@Getter
public class YamiShopBindException extends RuntimeException{
/**
*
*/
private static final long serialVersionUID = -4137688758944857209L;
/**
* http
*/
private String code;
private Object object;
private ServerResponseEntity<?> serverResponseEntity;
/**
* @param responseEnum http
*/
public YamiShopBindException(ResponseEnum responseEnum) {
super(responseEnum.getMsg());
this.code = responseEnum.value();
}
/**
* @param responseEnum http
*/
public YamiShopBindException(ResponseEnum responseEnum, String msg) {
super(I18nMessage.getMessage(msg));
this.code = responseEnum.value();
}
public YamiShopBindException(ServerResponseEntity<?> serverResponseEntity) {
this.serverResponseEntity = serverResponseEntity;
}
public YamiShopBindException(String msg) {
// super(msg);
super(I18nMessage.getMessage(msg));
this.code = ResponseEnum.SHOW_FAIL.value();
}
public YamiShopBindException(String msg, Object object) {
super(I18nMessage.getMessage(msg));
this.code = ResponseEnum.SHOW_FAIL.value();
this.object = object;
}
public YamiShopBindException(String code, String msg) {
super(I18nMessage.getMessage(msg));
this.code = code;
}
}

View File

@ -0,0 +1,10 @@
package com.mcwl.common.exception.leaf;
/**
* @author lanhai
*/
public class InitException extends Exception{
public InitException(String msg) {
super(msg);
}
}

View File

@ -0,0 +1,14 @@
package com.mcwl.common.exception.leaf;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* @author lanhai
*/
@ResponseStatus(code=HttpStatus.INTERNAL_SERVER_ERROR)
public class LeafServerException extends RuntimeException {
public LeafServerException(String msg) {
super(msg);
}
}

View File

@ -0,0 +1,11 @@
package com.mcwl.common.exception.leaf;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* @author lanhai
*/
@ResponseStatus(code=HttpStatus.INTERNAL_SERVER_ERROR,reason="Key is none")
public class NoKeyException extends RuntimeException {
}

View File

@ -0,0 +1,144 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.i18n;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import java.io.IOException;
import java.util.Locale;
import java.util.Objects;
/**
*
* @author mcwl
*/
@Slf4j
public class I18nMessage {
private static MessageSourceAccessor accessor;
// private static final String BASE_FOLDE = "i18n";
private static final String BASE_NAME = "i18n/messages";
static{
ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource();
reloadableResourceBundleMessageSource.setBasenames(BASE_NAME);
reloadableResourceBundleMessageSource.setCacheSeconds(5);
reloadableResourceBundleMessageSource.setDefaultEncoding("UTF-8");
accessor = new MessageSourceAccessor(reloadableResourceBundleMessageSource);
}
// /**
// * 获取一条语言配置信息
// *
// * @param message 配置信息属性名,eg: api.response.code.user.signUp
// * @return
// */
// public static String getMessage(String message) {
// Locale locale = LocaleContextHolder.getLocale();
// return I18nMessage.accessor.getMessage(message,locale);
// }
/**
*
*
* @param message ,eg: api.response.code.user.signUp
* @return
*/
public static String getMessage(String message) {
Locale locale = LocaleContextHolder.getLocale();
try {
return accessor.getMessage(message,locale);
}catch (Exception e){
return message;
}
}
/**
*
*
* @return
* @throws IOException
*/
public static Integer getLang() {
Locale locale = LocaleContextHolder.getLocale();
return LanguageEnum.valueOf(locale).getLang();
}
/**
* (pc)
*
* @return
* @throws IOException
*/
public static Integer getDbLang() {
Integer lang = getLang();
if (Objects.equals(lang, 0)) {
return LanguageEnum.LANGUAGE_ZH_CN.getLang();
}
return lang;
}
// /**
// * 获取文件夹下所有的国际化文件名
// *
// * @param folderName 文件名
// * @return
// * @throws IOException
// */
// private static String[] getAllBaseNames(final String folderName) throws IOException {
// URL url = Thread.currentThread().getContextClassLoader()
// .getResource(folderName);
// if (null == url) {
// throw new RuntimeException("无法获取资源文件路径");
// }
//
// List<String> baseNames = new ArrayList<>();
// if (url.getProtocol().equalsIgnoreCase("file")) {
// // 文件夹形式,用File获取资源路径
// File file = new File(url.getFile());
// if (file.exists() && file.isDirectory()) {
// baseNames = Files.walk(file.toPath())
// .filter(path -> path.toFile().isFile())
// .map(Path::toString)
// .map(path -> path.substring(path.indexOf(folderName)))
// .map(I18nMessage::getI18FileName)
// .distinct()
// .collect(Collectors.toList());
// } else {
// log.error("指定的baseFile不存在或者不是文件夹");
// }
// }
// return baseNames.toArray(new String[0]);
// }
//
// /**
// * 把普通文件名转换成国际化文件名
// *
// * @param filename
// * @return
// */
// private static String getI18FileName(String filename) {
// filename = filename.replace(".properties", "");
//// for (int i = 0; i < 2; i++) {
//// int index = filename.lastIndexOf("_");
//// if (index != -1) {
//// filename = filename.substring(0, index);
//// }
//// }
// return filename.replace("\\", "/");
// }
}

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.i18n;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Locale;
import java.util.Objects;
/**
*
* @author LGH
*/
@Getter
@AllArgsConstructor
public enum LanguageEnum {
/**
*
*/
LANGUAGE_ZH_CN("zh", 0),
/**
*
*/
LANGUAGE_EN("en", 1)
;
private String language;
private Integer lang;
/**
* (,)
*
* @param language
* @return
*/
public static String getLanguageType(String language){
if (StrUtil.isEmpty(language)) {
return LANGUAGE_ZH_CN.language;
}
for (LanguageEnum languageEnum : LanguageEnum.values()) {
if (languageEnum.language.equalsIgnoreCase(language)) {
return languageEnum.language;
}
}
return LANGUAGE_ZH_CN.language;
}
public static LanguageEnum valueOf(int lang) {
for (LanguageEnum languageEnum : values()) {
if (languageEnum.lang == lang) {
return languageEnum;
}
}
return LanguageEnum.LANGUAGE_ZH_CN;
}
public static LanguageEnum valueOf(Locale locale) {
for (LanguageEnum languageEnum : values()) {
if (Objects.equals(languageEnum.language, locale.toString())) {
return languageEnum;
}
}
return LanguageEnum.LANGUAGE_ZH_CN;
}
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.i18n;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Locale;
import java.util.Objects;
/**
* RequestContextFilter Locale(-105) RequestContextFilter
* @author LGH
*/
@Slf4j
@Component
@Order(-104)
public class YamiLocaleChangeFilter implements Filter {
public static String ZH_CN = "zh_CN";
public static String ZH_CN_L = "zh_cn";
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String newLocale = request.getHeader("locale");
if(Objects.equals(newLocale,ZH_CN)||Objects.equals(newLocale,ZH_CN_L)){
newLocale = "zh";
}
if (newLocale != null) {
String lowerLocale = newLocale.toLowerCase();
LocaleContextHolder.setLocale(new Locale(lowerLocale));
}
filterChain.doFilter(request, response);
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.i18n;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.support.RequestContextUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author LGH
*/
@Component("localeChangeInterceptor")
@Slf4j
public class YamiLocaleChangeInterceptor extends LocaleChangeInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
String newLocale = request.getHeader(getParamName());
if (newLocale != null) {
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
if (localeResolver == null) {
throw new IllegalStateException(
"No LocaleResolver found: not in a DispatcherServlet request?");
}
try {
localeResolver.setLocale(request, response, parseLocaleValue(newLocale));
}
catch (IllegalArgumentException ex) {
if (isIgnoreInvalidLocale()) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring invalid locale value [" + newLocale + "]: " + ex.getMessage());
}
}
else {
throw ex;
}
}
}
// Proceed in any case.
return true;
}
}

View File

@ -19,7 +19,6 @@ import java.lang.annotation.Target;
/**
* .
*
* @author java
* @date 2024/6/11 4:13
*/
@Target({ElementType.METHOD, ElementType.FIELD})

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.utils;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
*
*/
public class BeanUtil {
public static <S, D> List<D> mapAsList(final Iterable<S> sourceObject, Class<D> clazz) {
return JSONObject.parseArray(JSONObject.toJSONString(sourceObject), clazz);
}
public static <S, D> D map(final S sourceObject, Class<D> clazz) {
return JSONObject.parseObject(JSONObject.toJSONString(sourceObject), clazz);
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.utils;
import lombok.AllArgsConstructor;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Component;
/**
*
*/
@Component
@AllArgsConstructor
public class CacheManagerUtil {
private CacheManager cacheManager;
@SuppressWarnings({"unchecked"})
public <T> T getCache(String cacheName,String key) {
Cache cache = cacheManager.getCache(cacheName);
if (cache == null) {
return null;
}
Cache.ValueWrapper valueWrapper = cache.get(key);
if (valueWrapper == null) {
return null;
}
return (T)valueWrapper.get();
}
public void putCache(String cacheName,String key, Object value) {
Cache cache = cacheManager.getCache(cacheName);
if (cache != null) {
cache.put(key, value);
}
}
public void evictCache(String cacheName,String key) {
Cache cache = cacheManager.getCache(cacheName);
if (cache != null) {
cache.evict(key);
}
}
}

View File

@ -0,0 +1,243 @@
package com.mcwl.common.utils;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
public class EncryptionUtil {
/**
* AES
*
* @param password
* @return
* @throws NoSuchAlgorithmException
*/
private static SecretKey generateAESKey(String password) throws NoSuchAlgorithmException {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128);
byte[] passwordBytes = password.getBytes(StandardCharsets.UTF_8);
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] keyBytes = digest.digest(passwordBytes);
return new SecretKeySpec(keyBytes, "AES");
}
public static String encryptWithAES(String plaintext) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
SecretKey secretKey = generateAESKey("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(encryptedBytes);
}
/**
* AES
*
* @param plaintext
* @param password
* @return
* @throws Exception
*/
public static String encryptWithAES(String plaintext, String password) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
SecretKey secretKey = generateAESKey(password);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(encryptedBytes);
}
/**
* AES
*
* @param ciphertext
* @param password
* @return
* @throws Exception
*/
public static String decryptWithAES(String ciphertext, String password) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
SecretKey secretKey = generateAESKey(password);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(ciphertext));
return new String(decryptedBytes, StandardCharsets.UTF_8);
}
public static String decryptWithAES(String ciphertext) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
SecretKey secretKey = generateAESKey("AES");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(ciphertext));
return new String(decryptedBytes, StandardCharsets.UTF_8);
}
/**
* RSA
*
* @return
* @throws NoSuchAlgorithmException
*/
public static KeyPair generateRSAKeyPair() throws NoSuchAlgorithmException {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048);
return keyPairGenerator.generateKeyPair();
}
/**
* RSABase64
*
* @return RSABase64
*/
public static String getRSAPublicKeyString(PublicKey publicKey) {
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
return Base64.getEncoder().encodeToString(keyFactory.generatePublic(publicKeySpec).getEncoded());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Base64RSA
*
* @param publicKeyString RSABase64
* @return RSA
*/
public static PublicKey getPublicKey(String publicKeyString) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(publicKeyString));
return keyFactory.generatePublic(publicKeySpec);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* RSABase64
*
* @return RSABase64
*/
public static String getRSAPrivateKeyString(PrivateKey privateKey) {
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
return Base64.getEncoder().encodeToString(keyFactory.generatePrivate(privateKeySpec).getEncoded());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Base64RSA
*
* @param privateKeyString RSABase64
* @return RSA
*/
public static PrivateKey getPrivateKey(String privateKeyString) {
try {
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyString));
return keyFactory.generatePrivate(privateKeySpec);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* RSA
*
* @param plaintext
* @param publicKey
* @return
* @throws Exception
*/
public static String encryptWithRSA(String plaintext, PublicKey publicKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
KeyPair keyPair = generateRSAKeyPair();
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(encryptedBytes);
}
/**
* RSA
*
* @param ciphertext
* @param privateKey
* @return
* @throws Exception
*/
public static String decryptWithRSA(String ciphertext, PrivateKey privateKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
KeyPair keyPair = generateRSAKeyPair();
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(ciphertext));
return new String(decryptedBytes, StandardCharsets.UTF_8);
}
/**
* SHA-256
*
* @param plaintext
* @return
* @throws NoSuchAlgorithmException
*/
public static String hashWithSHA256(String plaintext) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashBytes = digest.digest(plaintext.getBytes(StandardCharsets.UTF_8));
return bytesToHex(hashBytes);
}
/**
*
*
* @param bytes
* @return
*/
private static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
/**
* Base64
*
* @param plainText
* @return
*/
public static String encodeBase64(String plainText) {
byte[] plainBytes = plainText.getBytes(StandardCharsets.UTF_8);
return Base64.getEncoder().encodeToString(plainBytes);
}
/**
* Base64
*
* @param base64Text
* @return
*/
public static String decodeBase64(String base64Text) {
byte[] base64Bytes = Base64.getDecoder().decode(base64Text);
return new String(base64Bytes, StandardCharsets.UTF_8);
}
}

View File

@ -0,0 +1,99 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.utils;
import cn.hutool.core.util.StrUtil;
import com.mcwl.common.exception.YamiShopBindException;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
/**
*
*/
public class ImageUtil {
private static final String JPG = "jpg";
private static final String JPEG = "jpeg";
/**
*
* @param imgUrl
* @return
*/
public static byte[] imgToBinary(String imgUrl) {
try {
BufferedImage bufferedImage = ImageIO.read(new URL(imgUrl));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String suffix = imgUrlFileType(imgUrl);
//ImageIO无法写入jpeg文件 报Invalid argument to native writeImage需重画
if(StrUtil.equals(suffix, JPG) || StrUtil.equals(suffix,JPEG)){
BufferedImage tag;
tag = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_BGR);
Graphics g = tag.getGraphics();
g.drawImage(bufferedImage, 0, 0, null);
g.dispose();
bufferedImage = tag;
}
ImageIO.write(bufferedImage, suffix, baos);
byte[] bytes = baos.toByteArray();
return bytes;
} catch (IOException e) {
// 图片丢失,请重新上传图片
throw new YamiShopBindException("yami.img.lose");
}
}
/**
* @param imgUrl
* @return jpg , png , ...
*/
public static String imgUrlFileType(String imgUrl) {
if (StrUtil.isBlank(imgUrl)) {
return imgUrl;
}
imgUrl.trim();
String[] split = imgUrl.split("\\.");
String s = split[split.length - 1];
return s;
}
/**
* @param imgUrl
* @return
*/
public static String imgUrlFileName(String imgUrl) {
if (StrUtil.isBlank(imgUrl)) {
return imgUrl;
}
imgUrl.trim();
String[] split = imgUrl.split("/");
String s = split[split.length - 1];
return s;
}
/**
* @param imgUrl
* @return 45d3631e97d8438d80f9db1369595b8c
*/
public static String imgUrlFileNameNoSuffix(String imgUrl) {
if (StrUtil.isBlank(imgUrl)) {
return imgUrl;
}
imgUrl.trim();
String[] split = imgUrl.split("/");
String s = split[split.length - 1];
String[] split1 = s.split("\\.");
return split1[0];
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.utils;
import cn.hutool.core.util.StrUtil;
import java.util.regex.Pattern;
/**
*
*/
public class PrincipalUtil {
/**
* 110
*/
public static final String MOBILE_REGEXP = "1[0-9]{10}";
/**
*
*/
public static final String TEL_REGEXP = "([0-9]{3,4}-)?[0-9]{7,8}";
/**
*
*/
public static final String WX_NUMBER_REGEXP = "[a-zA-Z][a-zA-Z\\d_-]{5,19}$";
/**
* QQ
*/
public static final String QQ_NUMBER_REGEXP = "[1-9][0-9]{4,14}";
/**
* 1. 2. 线 4-16
*/
public static final String USER_NAME_REGEXP = "(?!\\d+$)([a-zA-Z0-9_]{4,16})";
/**
* 线
*/
public static final String FIELD_REGEXP = "([a-zA-Z0-9_]+)";
/**
*
*/
public static final String WITHOUT_CHINESE = "^[A-Za-z0-9]+$";
/**
* 线
*/
public static final String SIMPLE_CHAR_REGEXP = "([a-z0-9]+)";
/**
*
*/
public static final String MAIL_REGEXP = "([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})";
public static boolean isMobile(String value) {
if(StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(MOBILE_REGEXP, value);
}
public static boolean isTel(String value) {
if(StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(TEL_REGEXP, value);
}
public static boolean isWxNumber(String value) {
if(StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(WX_NUMBER_REGEXP, value);
}
public static boolean isQqNumber(String value) {
if(StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(QQ_NUMBER_REGEXP, value);
}
public static boolean isUserName(String value) {
if(StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(USER_NAME_REGEXP, value);
}
public static boolean isMail(String value) {
if(StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(MAIL_REGEXP, value);
}
/**
*
* @param value
* @return
*/
public static boolean isField(String value) {
return isMatching(FIELD_REGEXP, value);
}
public static boolean isMatching(String regexp, String value) {
if (StrUtil.isBlank(value)) {
return false;
}
return Pattern.matches(regexp, value);
}
/**
*
* @param value
* @return
*/
public static boolean isSimpleChar(String value) {
return isMatching(SIMPLE_CHAR_REGEXP, value);
}
}

View File

@ -0,0 +1,73 @@
package com.mcwl.common.utils;
import cn.hutool.core.collection.CollectionUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
/**
*
*
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class RequestPageEntity implements Serializable {
private static final int DEFAULT_PAGE_SIZE = 10;
/**
*
*/
private Integer pageNo = 1;
/**
* 10
*/
private Integer pageSize = DEFAULT_PAGE_SIZE;
/**
*
*/
private List<String> sortField;
/**
*
*
* @return
*/
public Integer getPageBegin() {
if (Objects.isNull(this.pageNo) || this.pageNo <= 0) {
this.pageNo = 1;
}
if (Objects.isNull(this.pageSize)) {
this.pageSize = DEFAULT_PAGE_SIZE;
}
return (this.pageNo - 1) * this.pageSize;
}
/**
*
*
* @return
*/
public String getSortString() {
List<String> sortField = this.getSortField();
if (CollectionUtil.isEmpty(sortField)) {
return null;
}
StringBuilder sortBuilder = new StringBuilder();
for (String field : sortField) {
String[] values = field.split(",");
sortBuilder.append(String.format("%s %s", values[0], values[1])).append(",");
}
return sortBuilder.deleteCharAt(sortBuilder.length() - 1).toString();
}
}

View File

@ -0,0 +1,84 @@
package com.mcwl.common.utils;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
*
*/
@AllArgsConstructor
@Data
public class ResponsePageEntity<T> implements Serializable {
private static final Integer ZERO = 0;
/**
*
*/
private Integer pageNo;
/**
*
*/
private Integer pageSize;
/**
*
*/
private Integer totalPage;
/**
*
*/
private Integer totalCount;
/**
*
*/
private List<T> data;
/**
*
*
* @param requestPageEntity
* @param <T>
* @return ResponsePageEntity
*/
public static <T> ResponsePageEntity<T> buildEmpty(RequestPageEntity requestPageEntity) {
return build(requestPageEntity, 0, new ArrayList<>(0));
}
/**
*
*
* @param requestPageEntity
* @param totalCount
* @param data
* @param <T>
* @return ResponsePageEntity
*/
public static <T> ResponsePageEntity<T> build(RequestPageEntity requestPageEntity, Integer totalCount, List<T> data) {
Integer totalPage = getTotalPage(requestPageEntity.getPageSize(), totalCount);
return new ResponsePageEntity(requestPageEntity.getPageNo(), requestPageEntity.getPageSize(), totalPage, totalCount, data);
}
private static Integer getTotalPage(Integer pageSize, Integer totalCount) {
if (Objects.isNull(pageSize) || Objects.isNull(totalCount)) {
return ZERO;
}
if (pageSize <= 0 || totalCount <= 0) {
return ZERO;
}
return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
}
}

View File

@ -0,0 +1,106 @@
package com.mcwl.common.utils;
/**
*/
import java.util.Random;
/**
* <br/>
* 1ID1 <br/>
* 2使V <br/>
* 3'A'VA <br/>
* 4VA4VAHKHE <br/>
* 5'A'线'A' <br/>
*
* @author zzs
*/
public class ShareCodeUtils {
/**
* (0,1,o,l)AA31
*/
private static final char[] BASE = new char[]{'H', 'V', 'E', '8', 'S', '2', 'D', 'Z', 'X', '9', 'C', '7', 'P',
'5', 'I', 'K', '3', 'M', 'J', 'U', 'F', 'R', '4', 'W', 'Y', 'L', 'T', 'N', '6', 'B', 'G', 'Q'};
/**
* A
*/
private static final char SUFFIX_CHAR = 'A';
/**
*
*/
private static final int BIN_LEN = BASE.length;
/**
*
*/
private static final int CODE_LEN = 8;
/**
* ID
*
* @param id
* @return
*/
public static String idToCode(Long id) {
char[] buf = new char[BIN_LEN];
int charPos = BIN_LEN;
// 当id除以数组长度结果大于0则进行取模操作并以取模的值作为数组的坐标获得对应的字符
while (id / BIN_LEN > 0) {
int index = (int) (id % BIN_LEN);
buf[--charPos] = BASE[index];
id /= BIN_LEN;
}
buf[--charPos] = BASE[(int) (id % BIN_LEN)];
// 将字符数组转化为字符串
String result = new String(buf, charPos, BIN_LEN - charPos);
// 长度不足指定长度则随机补全
int len = result.length();
if (len < CODE_LEN) {
StringBuilder sb = new StringBuilder();
sb.append(SUFFIX_CHAR);
Random random = new Random();
// 去除SUFFIX_CHAR本身占位之后需要补齐的位数
for (int i = 0; i < CODE_LEN - len - 1; i++) {
sb.append(BASE[random.nextInt(BIN_LEN)]);
}
result += sb.toString();
}
return result;
}
/**
* ID<br/>
* idToCode
*
* @param code
* @return
*/
public static Long codeToId(String code) {
char[] charArray = code.toCharArray();
long result = 0L;
for (int i = 0; i < charArray.length; i++) {
int index = 0;
for (int j = 0; j < BIN_LEN; j++) {
if (charArray[i] == BASE[j]) {
index = j;
break;
}
}
if (charArray[i] == SUFFIX_CHAR) {
break;
}
if (i > 0) {
result = result * BIN_LEN + index;
} else {
result = index;
}
}
return result;
}
public static void main(String[] args) {
String code = idToCode(13653414955L);
System.out.println(code);
System.out.println(codeToId("IKGPUKXA"));
}
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.utils;
import cn.hutool.captcha.LineCaptcha;
import cn.hutool.core.img.ImgUtil;
import cn.hutool.core.util.RandomUtil;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.concurrent.ThreadLocalRandom;
/**
*
* @author yami
*/
public class SimpleCaptcha extends LineCaptcha{
private static final long serialVersionUID = -9042552338521307038L;
private static final String CAPTCHA_CODE = "abcdefhjkmnpqrstuvwxyz2345678";
private int codeCount;
public SimpleCaptcha(int width, int height, int codeCount, int interfereCount) {
super(width, height, codeCount, interfereCount);
this.codeCount = codeCount;
}
@Override
protected void generateCode() {
this.code = RandomUtil.randomString(CAPTCHA_CODE,codeCount);
}
@Override
public Image createImage(String code) {
// 图像buffer
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final ThreadLocalRandom random = RandomUtil.getRandom();
final Graphics2D g = ImgUtil.createGraphics(image, new Color(255,255,255));
// 干扰线
drawInterfere(g, random);
// 创建字体
g.setFont(this.font);
final FontMetrics metrics = g.getFontMetrics();
int minY = metrics.getAscent() - metrics.getLeading() - metrics.getDescent();
// 文字
final int len = codeCount;
int charWidth = width / len;
for (int i = 0; i < len; i++) {
// 产生随机的颜色值,让输出的每个字符的颜色值都将不同。
g.setColor(ImgUtil.randomColor(random));
g.drawString(String.valueOf(code.charAt(i)), i * charWidth, RandomUtil.randomInt(minY, this.height));
}
return image;
}
/**
* 线
*
* @param g {@link Graphics2D}
* @param random
*/
private void drawInterfere(Graphics2D g, ThreadLocalRandom random) {
// 干扰线
for (int i = 0; i < this.interfereCount; i++) {
int xs = random.nextInt(width);
int ys = random.nextInt(height);
int xe = xs + random.nextInt(width / 8);
int ye = ys + random.nextInt(height / 8);
g.setColor(ImgUtil.randomColor(random));
g.drawLine(xs, ys, xe, ye);
}
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2018-2999 广 All rights reserved.
*
* https://www.mall4j.com/
*
*
*
*
*/
package com.mcwl.common.utils;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.context.expression.MethodBasedEvaluationContext;
import org.springframework.core.StandardReflectionParameterNameDiscoverer;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import java.lang.reflect.Method;
/**
* SPEL
*/
public class SpelUtil {
/**
* #p0
* @param rootObject ,method
* @param spel
* @param method
* @param args
* @return
*/
public static String parse(Object rootObject,String spel, Method method, Object[] args) {
if (StrUtil.isBlank(spel)) {
return StrUtil.EMPTY;
}
//获取被拦截方法参数名列表(使用Spring支持类库)
StandardReflectionParameterNameDiscoverer standardReflectionParameterNameDiscoverer = new StandardReflectionParameterNameDiscoverer();
// LocalVariableTableParameterNameDiscoverer u =
// new LocalVariableTableParameterNameDiscoverer();
String[] paraNameArr = standardReflectionParameterNameDiscoverer.getParameterNames(method);
if (ArrayUtil.isEmpty(paraNameArr)) {
return spel;
}
//使用SPEL进行key的解析
ExpressionParser parser = new SpelExpressionParser();
//SPEL上下文
StandardEvaluationContext context = new MethodBasedEvaluationContext(rootObject,method,args,standardReflectionParameterNameDiscoverer);
//把方法参数放入SPEL上下文中
for (int i = 0; i < paraNameArr.length; i++) {
context.setVariable(paraNameArr[i], args[i]);
}
return parser.parseExpression(spel).getValue(context, String.class);
}
}

View File

@ -10,7 +10,7 @@ import java.math.BigDecimal;
/**
*
* @date 2024/6/11 4:13
* @date 2024/12/30 4:13
*/
public class MaxMoneyConstraintValidator implements ConstraintValidator<MaxMoney, BigDecimal> {

View File

@ -9,6 +9,13 @@
<version>3.8.8</version>
</parent>
<artifactId>mcwl-resource</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
resource资源中心模块
</description>
@ -20,5 +27,11 @@
<artifactId>mcwl-common</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,76 @@
package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.common.domain.resource
* @FilenameMallProduct
* @Description TODO
* @Date2024/12/30 17:22
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("mall_product")
public class MallProduct extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId
private Long Id;
/**
* ID
*/
private Integer userId;
/**
* ID
*/
private Integer productId;
/**
*
*/
private String productName;
/**
*
*/
private String detail;
/**
*
*/
private String model;
/**
*
*/
private BigDecimal amount;
/**
*
*/
private String name;
/**
* url
*/
private String url;
/**
* url
*/
private String zipUrl;
/**
* 0 2
*/
private String delFlag;
}

View File

@ -0,0 +1,61 @@
package com.mcwl.resource.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mcwl.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.common.domain.resource
* @FilenameMallProductComment
* @Description TODO
* @Date2024/12/30 17:22
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("mall_product_comment")
public class MallProductComment extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId
private Long Id;
/**
* ID
*/
private Integer parentId;
/**
* ID
*/
private Integer productId;
/**
* ID
*/
private Integer userId;
/**
*
*/
private String content;
/**
*
*/
private Integer rating;
/**
* 0 2
*/
private String delFlag;
}

View File

@ -0,0 +1,17 @@
package com.mcwl.resource.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mcwl.resource.domain.MallProduct;
import org.apache.ibatis.annotations.Mapper;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.mapper
* @FilenameMallProductMapper
* @Description TODO
* @Date2024/12/30 18:23
*/
@Mapper
public interface MallProductMapper extends BaseMapper<MallProduct> {
}

View File

@ -0,0 +1,21 @@
package com.mcwl.resource.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mcwl.common.domain.response.ServerResponseEntity;
import com.mcwl.common.utils.ResponsePageEntity;
import com.mcwl.resource.domain.MallProduct;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service
* @FilenameMallProductServiceImpl
* @Description TODO
* @Date2024/12/30 18:20
*/
public interface MallProductService extends IService<MallProduct> {
}

View File

@ -0,0 +1,46 @@
package com.mcwl.resource.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mcwl.common.annotation.DataSource;
import com.mcwl.common.enums.DataSourceType;
import com.mcwl.common.enums.ResponseCodeEnum;
import com.mcwl.resource.domain.MallProduct;
import com.mcwl.resource.mapper.MallProductMapper;
import com.mcwl.resource.service.MallProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @AuthorChenYan
* @ProjectMcWl
* @Packagecom.mcwl.resource.service.impl
* @FilenameMallProductServiceImpl
* @Description TODO
* @Date2024/12/30 18:22
*/
@Service
public class MallProductServiceImpl extends ServiceImpl<MallProductMapper,MallProduct> implements MallProductService {
@Autowired
private MallProductMapper mapper;
// @Override
// public List<MallProduct> selectMallProductList(MallProduct mallProduct) {
//
// QueryWrapper<MallProduct> queryWrapper = new QueryWrapper<>();
// queryWrapper.lambda().eq(MallProduct::getProductName, mallProduct.getProductName());
// queryWrapper.lambda().eq(MallProduct::getName, mallProduct.getName());
// queryWrapper.lambda().eq(MallProduct::getAmount, mallProduct.getAmount());
// mapper.selectList(queryWrapper);
//
// serviceEntity.setMessage(ResponseCodeEnum.SUCCESS_STATE_ENUM.getName());
// return ;
//
// }
}

View File

@ -35,6 +35,7 @@
<logback.version>1.2.13</logback.version>
<spring-security.version>5.7.12</spring-security.version>
<spring-framework.version>5.3.39</spring-framework.version>
<mybatis-plus.version>3.5.2</mybatis-plus.version>
</properties>
<!-- 依赖声明 -->

View File

@ -7,3 +7,80 @@
-- post_code varchar(64) not null comment '岗位编码',
-- primary key (post_id)
-- ) engine=innodb comment = 'xxxx';
CREATE TABLE `mall_product`
(
`id` bigint NOT NULL COMMENT 'ID',
`product_id` bigint NOT NULL COMMENT '商品ID',
`product_name` varchar(100) NOT NULL COMMENT '商品名称',
`detail` blob NOT NULL COMMENT '商品详情',
`model` varchar(100) NOT NULL COMMENT '商品规格',
`amount` decimal(10, 3) NOT NULL COMMENT '金额',
`name` varchar(60) NOT NULL COMMENT '图片名称',
`url` varchar(200) NOT NULL COMMENT '图片url',
`create_by` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志0代表存在 2代表删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='商品表';
CREATE TABLE `mall_index_product`
(
`id` bigint NOT NULL COMMENT 'ID',
`product_id` bigint NOT NULL COMMENT '商品ID',
`sort` int NOT NULL DEFAULT '999' COMMENT '排序',
`type` int NOT NULL COMMENT '模型类型 1: 热门模型 2: 最新模型 3推荐模型',
`create_by` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志0代表存在 2代表删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='首页商品';
CREATE TABLE `mall_product_comment`
(
`id` bigint NOT NULL COMMENT 'ID',
`parent_id` bigint NOT NULL DEFAULT '0' COMMENT '父评论ID',
`product_id` bigint NOT NULL COMMENT '商品ID',
`user_id` bigint NOT NULL COMMENT '用户ID',
`content` varchar(500) NOT NULL COMMENT '评论内容',
`rating` int NOT NULL COMMENT '评分',
`create_by` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志0代表存在 2代表删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='商品评论表';
CREATE TABLE `order_trade`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID',
`code` varchar(30) NOT NULL COMMENT '订单编码',
`user_id` bigint NOT NULL COMMENT '用户ID',
`product_id` bigint NOT NULL COMMENT '商品ID',
`product_name` varchar(60) NOT NULL COMMENT '商品名称',
`user_name` varchar(30) NOT NULL COMMENT '用户名称',
`order_time` datetime(3) DEFAULT NULL COMMENT '下单时间',
`order_status` int NOT NULL COMMENT '订单状态 1:下单 2:支付 3完成 4取消',
`pay_status` int NOT NULL COMMENT '支付状态 1:待支付 2:已支付 3退款',
`total_amount` decimal(10, 3) NOT NULL COMMENT '总金额',
`payment_amount` decimal(10, 3) NOT NULL COMMENT '付款金额',
`create_by` varchar(64) DEFAULT '' COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT '' COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志0代表存在 2代表删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1798708644507918337 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='订单表';