Merge pull request 'master' (#6) from master into dev

Reviewed-on: https://git.landaiqing.space/Schisandra-Cloud-Storage/schisandra-cloud-storage/pulls/6
This commit is contained in:
2024-05-11 21:53:37 +08:00
124 changed files with 2942 additions and 213 deletions

View File

@@ -66,11 +66,5 @@
<artifactId>schisandra-cloud-storage-auth-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.xkcoding</groupId>
<artifactId>justauth-spring-boot-starter</artifactId>
<version>1.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -12,9 +12,9 @@ import java.util.List;
/**
* @Classname GlobalConfig
* @BelongsProject: qing-yu-club
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.application.config
* @Author: landaiqing
* @Author: schisandra
* @CreateTime: 2024-02-16 15:57
* @Description: MVC全局处理
* @Version: 1.0

View File

@@ -1,31 +1,17 @@
package com.schisandra.auth.application.config;
import com.schisandra.auth.application.convert.SchisandraSmsConfigDTOConvert;
import com.schisandra.auth.application.dto.SchisandraSmsConfigDTO;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.domain.service.SchisandraSmsConfigDomainService;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import javax.annotation.Resource;
import java.util.List;
@Configuration
public class SmsInitConfig {
@Resource
SmsReadConfig smsReadConfig;
@Resource
SchisandraSmsConfigDomainService schisandraSmsConfigDomainService;
@EventListener
public void init(ContextRefreshedEvent event){
List<SchisandraSmsConfigBO> SchisandraSmsConfigBOs= schisandraSmsConfigDomainService.queryAll();
List<SchisandraSmsConfigDTO> schisandraSmsConfigDTOS = SchisandraSmsConfigDTOConvert.INSTANCE.convertBOToDTOList(SchisandraSmsConfigBOs);
for (SchisandraSmsConfigDTO schisandraSmsConfig : schisandraSmsConfigDTOS){
if (schisandraSmsConfig!=null){
// 创建SmsBlend 短信实例
SmsFactory.createSmsBlend(smsReadConfig);
};
}}
public void init(ContextRefreshedEvent event) {
SmsFactory.createSmsBlend(smsReadConfig, "alibaba");
}
}

View File

@@ -1,88 +1,39 @@
package com.schisandra.auth.application.config;
import com.schisandra.auth.application.convert.SchisandraSmsConfigDTOConvert;
import com.schisandra.auth.application.dto.SchisandraSmsConfigDTO;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.domain.service.SchisandraSmsConfigDomainService;
import com.schisandra.auth.infra.basic.dao.SchisandraSmsConfigDao;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
import org.dromara.sms4j.huawei.config.HuaweiConfig;
import com.schisandra.auth.application.factory.SmsTypeHandlerFactory;
import com.schisandra.auth.application.handler.SchisandraSmsTypeHandler;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.dromara.sms4j.tencent.config.TencentConfig;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @Classname SmsConfig
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.common.config
* @Author: landaiqing
* @Author: schisandra
* @CreateTime: 2024-05-08 18:46
* @Description: TODO
* @Version: 1.0
*/
@Component
public class SmsReadConfig implements org.dromara.sms4j.core.datainterface.SmsReadConfig {
@Resource
SchisandraSmsConfigDomainService schisandraSmsConfigDomainService;
private SmsTypeHandlerFactory smsTypeHandlerFactory;
@Override
public BaseConfig getSupplierConfig(String configId) {
return null;
SchisandraSmsTypeHandler handler = smsTypeHandlerFactory.getHandler(configId);
return handler.addConfig(configId);
}
@Override
public List<BaseConfig> getSupplierConfigList() {
List<BaseConfig> configs = new ArrayList<>();
List<SchisandraSmsConfigBO> SchisandraSmsConfigBOs= schisandraSmsConfigDomainService.queryAll();
List<SchisandraSmsConfigDTO> schisandraSmsConfigDTOS = SchisandraSmsConfigDTOConvert.INSTANCE.convertBOToDTOList(SchisandraSmsConfigBOs);
for (SchisandraSmsConfigDTO schisandraSmsConfig : schisandraSmsConfigDTOS){
if ("alibaba".equals(schisandraSmsConfig.getConfigId())) {
AlibabaConfig alibabaConfig = new AlibabaConfig();
alibabaConfig.setConfigId(schisandraSmsConfig.getConfigId());
alibabaConfig.setRequestUrl(schisandraSmsConfig.getRequestUrl());
alibabaConfig.setAccessKeyId(schisandraSmsConfig.getAccessKeyId());
alibabaConfig.setAccessKeySecret(schisandraSmsConfig.getAccessKeySecret());
alibabaConfig.setSignature(schisandraSmsConfig.getSignature());
alibabaConfig.setTemplateId(schisandraSmsConfig.getTemplateId());
alibabaConfig.setTemplateName(schisandraSmsConfig.getTemplateName());
alibabaConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
configs.add(alibabaConfig);
}
if ("tencent".equals(schisandraSmsConfig.getConfigId())) {
TencentConfig tencentConfig=new TencentConfig();
tencentConfig.setConfigId(schisandraSmsConfig.getConfigId());
tencentConfig.setAccessKeyId(schisandraSmsConfig.getAccessKeyId());
tencentConfig.setAccessKeySecret(schisandraSmsConfig.getAccessKeySecret());
tencentConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
tencentConfig.setService(schisandraSmsConfig.getSdkAppId());
tencentConfig.setRequestUrl(schisandraSmsConfig.getRequestUrl());
tencentConfig.setTerritory(schisandraSmsConfig.getRegion());
tencentConfig.setAction(schisandraSmsConfig.getAction());
tencentConfig.setSignature(schisandraSmsConfig.getSignature());
tencentConfig.setTemplateId(schisandraSmsConfig.getTemplateId());
tencentConfig.setVersion(schisandraSmsConfig.getVersion());
tencentConfig.setConnTimeout(schisandraSmsConfig.getConnTimeout());
tencentConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
configs.add(tencentConfig);
}
if ("huawei".equals(schisandraSmsConfig.getConfigId())) {
HuaweiConfig huaweiConfig = new HuaweiConfig();
huaweiConfig.setConfigId(schisandraSmsConfig.getConfigId());
huaweiConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
huaweiConfig.setAccessKeySecret(schisandraSmsConfig.getAccessKeySecret());
huaweiConfig.setAccessKeyId(schisandraSmsConfig.getAccessKeyId());
huaweiConfig.setUrl(schisandraSmsConfig.getUrl());
huaweiConfig.setSignature(schisandraSmsConfig.getSignature());
huaweiConfig.setTemplateId(schisandraSmsConfig.getTemplateId());
configs.add(huaweiConfig);
}}
return configs;
return null;
}

View File

@@ -1,28 +1,21 @@
package com.schisandra.auth.application.controller;
import cn.hutool.core.lang.Assert;
import com.schisandra.auth.application.dto.SchisandraCaptchaDTO;
import com.schisandra.auth.common.entity.CaptchaResult;
import com.schisandra.auth.common.entity.Result;
import com.schisandra.auth.common.redis.RedisUtil;
import com.schisandra.auth.common.utils.AESUtils;
import com.schisandra.auth.common.utils.RotateImageUtils;
import com.schisandra.auth.common.utils.SmsCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Base64;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@@ -39,7 +32,7 @@ public class ReactRotateCaptchaController {
public final String authRotateCaptchaPrefix = "auth.RotateCaptcha";
/**
* @description:获取图片
* @description: 获取图片
* @param: []
* @return: java.lang.String
* @author zlg
@@ -89,7 +82,6 @@ public class ReactRotateCaptchaController {
redisUtil.del(prefix);
return CaptchaResult.ok();
} else {
redisUtil.del(prefix);
return CaptchaResult.fail();
}
} else {

View File

@@ -14,7 +14,7 @@ import javax.annotation.Resource;
* @Classname SchisandraAuthUserController
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.application.controller
* @Author: landaiqing
* @Author: schisandra
* @CreateTime: 2024-03-21 22:48
* @Description: AuthUserController层
* @Version: 1.0
@@ -29,7 +29,7 @@ public class SchisandraAuthUserController {
* @description 更新用户信息
* @param schisandraAuthUserDTO
* @return com.schisandra.auth.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:06
*/
@PostMapping("update")
@@ -111,7 +111,7 @@ public class SchisandraAuthUserController {
* @description 用户信息断言校验
* @param schisandraAuthUserDTO
* @return void
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:09
*/
private void checkUserInfo(@RequestBody SchisandraAuthUserDTO schisandraAuthUserDTO) {

View File

@@ -1,10 +1,14 @@
package com.schisandra.auth.application.controller;
import com.schisandra.auth.application.config.SmsReadConfig;
import com.schisandra.auth.application.factory.SmsTypeHandlerFactory;
import com.schisandra.auth.application.handler.SchisandraSmsTypeHandler;
import com.schisandra.auth.common.entity.Result;
import com.schisandra.auth.common.redis.RedisUtil;
import com.schisandra.auth.common.utils.SmsCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.springframework.web.bind.annotation.GetMapping;
@@ -21,6 +25,8 @@ import static java.util.concurrent.TimeUnit.SECONDS;
public class SchisandraSmsController {
@Resource
private RedisUtil redisUtil;
@Resource
private SmsReadConfig smsReadConfig;
private final String authPhonePrefix="auth.phone";
/**
@@ -35,7 +41,7 @@ public class SchisandraSmsController {
String prefix = redisUtil.buildKey(authPhonePrefix, phone);
String code = SmsCodeUtils.generateValidateCode(4).toString();
if (!redisUtil.exist(prefix)){
SmsResponse smsResponse=SmsFactory.getBySupplier("alibaba").sendMessage(phone,code);
SmsResponse smsResponse=SmsFactory.getSmsBlend("alibaba").sendMessage(phone,code);
if (smsResponse.isSuccess()){
redisUtil.setNx(prefix, code, 60L,SECONDS);
return Result.ok();

View File

@@ -25,7 +25,7 @@ public interface SchisandraAuthRoleDTOConverter {
* @param authRoleDTO
* @return com.schisandra.auth.domain.bo.SchisandraAuthRoleBO
* @description DTO转BO
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:11
*/
@@ -35,7 +35,7 @@ public interface SchisandraAuthRoleDTOConverter {
* @description: BO转DTO
* @param: [authUserBO]
* @return: com.schisandra.auth.application.dto.SchisandraAuthRoleDTO
* @author: landaiqing
* @author: schisandra
* @date: 2024/3/21 23:26
*/
SchisandraAuthRoleDTO convertBOToDTO(SchisandraAuthRoleBO authRoleBO);

View File

@@ -8,7 +8,7 @@ import org.mapstruct.factory.Mappers;
/**
* 用户dto转换器
*
* @author landaiqing
* @author schisandra
*/
@Mapper(componentModel = "spring")
public interface SchisandraAuthUserDTOConverter {
@@ -19,7 +19,7 @@ public interface SchisandraAuthUserDTOConverter {
* @param authUserDTO
* @return com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @description DTO转BO
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:11
*/
@@ -29,7 +29,7 @@ public interface SchisandraAuthUserDTOConverter {
* @description: BO转DTO
* @param: [authUserBO]
* @return: com.schisandra.auth.application.dto.SchisandraAuthUserDTO
* @author: landaiqing
* @author: schisandra
* @date: 2024/3/21 23:26
*/
SchisandraAuthUserDTO convertBOToDTO(SchisandraAuthUserBO authUserBO);

View File

@@ -23,7 +23,7 @@ public interface SchisandraSmsConfigDTOConvert {
* @description 将bo转换为实体
* @param schisandraSmsConfigDTO
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraSmsConfigBO convertDTOToBO(SchisandraSmsConfigDTO schisandraSmsConfigDTO);
@@ -32,7 +32,7 @@ public interface SchisandraSmsConfigDTOConvert {
* @description 将实体转换为bo
* @param schisandraSmsConfigBO
* @return com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraSmsConfigDTO convertBOToDTO(SchisandraSmsConfigBO schisandraSmsConfigBO);

View File

@@ -148,6 +148,16 @@ public class SchisandraSmsConfigDTO implements Serializable {
* 签名ID
*/
private String signatureId;
/**
* 是否删除 0 未删除 1已删除
*/
private Integer isDeleted;
private String extraJson;
/**
* 服务名
*/
private String service;

View File

@@ -0,0 +1,40 @@
package com.schisandra.auth.application.factory;
import com.schisandra.auth.application.handler.SchisandraSmsTypeHandler;
import com.schisandra.auth.common.enums.SmsSupplierType;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Classname SmsTypeHandlerFactory
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.application.factory
* @Author: schisandra
* @CreateTime: 2024-05-11 18:36
* @Description: TODO
* @Version: 1.0
*/
@Component
public class SmsTypeHandlerFactory implements InitializingBean {
@Resource
private List<SchisandraSmsTypeHandler> smsTypeHandlerList;
private HashMap<SmsSupplierType,SchisandraSmsTypeHandler> handlerMap =new HashMap<>();
public SchisandraSmsTypeHandler getHandler(String configId){
SmsSupplierType smsSupplierType = SmsSupplierType.getByKey(configId);
return handlerMap.get(smsSupplierType);
}
@Override
public void afterPropertiesSet() throws Exception {
for(SchisandraSmsTypeHandler smsTypeHandler : smsTypeHandlerList){
handlerMap.put(smsTypeHandler.getHandlerType(),smsTypeHandler);
}
}
}

View File

@@ -0,0 +1,51 @@
package com.schisandra.auth.application.handler;
import com.schisandra.auth.application.convert.SchisandraSmsConfigDTOConvert;
import com.schisandra.auth.application.dto.SchisandraSmsConfigDTO;
import com.schisandra.auth.common.enums.SmsSupplierType;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.domain.service.SchisandraSmsConfigDomainService;
import org.apache.commons.lang3.ObjectUtils;
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @Classname AlibabaSmsHandler
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.application.handler
* @Author: schisandra
* @CreateTime: 2024-05-11 18:20
* @Description: TODO
* @Version: 1.0
*/
@Component
public class AlibabaSmsHandler implements SchisandraSmsTypeHandler{
@Resource
SchisandraSmsConfigDomainService schisandraSmsConfigDomainService;
@Override
public SmsSupplierType getHandlerType() {
return SmsSupplierType.ALIBABA;
}
@Override
public BaseConfig addConfig(String configId) {
SchisandraSmsConfigBO schisandraSmsConfigBO = schisandraSmsConfigDomainService.queryByConfigId(configId);
SchisandraSmsConfigDTO schisandraSmsConfigDTO = SchisandraSmsConfigDTOConvert.INSTANCE.convertBOToDTO(schisandraSmsConfigBO);
if (ObjectUtils.isEmpty(schisandraSmsConfigDTO)){
return null;
}
AlibabaConfig alibabaConfig=new AlibabaConfig();
alibabaConfig.setConfigId(schisandraSmsConfigDTO.getConfigId());
alibabaConfig.setRequestUrl(schisandraSmsConfigDTO.getRequestUrl());
alibabaConfig.setAccessKeyId(schisandraSmsConfigDTO.getAccessKeyId());
alibabaConfig.setAccessKeySecret(schisandraSmsConfigDTO.getAccessKeySecret());
alibabaConfig.setSignature(schisandraSmsConfigDTO.getSignature());
alibabaConfig.setTemplateId(schisandraSmsConfigDTO.getTemplateId());
alibabaConfig.setTemplateName(schisandraSmsConfigDTO.getTemplateName());
alibabaConfig.setSdkAppId(schisandraSmsConfigDTO.getSdkAppId());
return alibabaConfig;
}
}

View File

@@ -0,0 +1,21 @@
package com.schisandra.auth.application.handler;
import com.schisandra.auth.common.enums.SmsSupplierType;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.springframework.stereotype.Component;
/**
* @Classname SchisandraSmsTypeHandler
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.application.handler
* @Author: schisandra
* @CreateTime: 2024-05-11 18:04
* @Description: TODO
* @Version: 1.0
*/
@Component
public interface SchisandraSmsTypeHandler {
SmsSupplierType getHandlerType();
BaseConfig addConfig(String configId);
}

View File

@@ -110,14 +110,6 @@
</dependency>
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.8</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.codec</artifactId>
@@ -125,9 +117,16 @@
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-extra</artifactId>
<version>5.8.27</version>
<groupId>com.xkcoding</groupId>
<artifactId>justauth-spring-boot-starter</artifactId>
<version>1.1.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>hutool-http</artifactId>
<groupId>cn.hutool</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

View File

@@ -32,14 +32,14 @@ public class CaptchaResult<T> {
CaptchaResult result = new CaptchaResult();
result.setCode(1);
result.setMsg("Fail");
result.setMsg("验证失败");
return result;
}
public static <T> CaptchaResult fail(T data) {
CaptchaResult result = new CaptchaResult();
result.setCode(1);
result.setMsg("Fail");
result.setMsg("验证失败");
result.setData(data);
return result;
}

View File

@@ -3,7 +3,7 @@ package com.schisandra.auth.common.entity;
/**
* 分页请求实体
*
* @author: landaiqing
* @author: schisandra
*/
public class PageInfo {

View File

@@ -9,7 +9,7 @@ import java.util.List;
/**
* 分页返回实体
*
* @author: landaiqing
* @author: schisandra
*/
@Data
public class PageResult<T> implements Serializable {

View File

@@ -5,7 +5,7 @@ import lombok.Data;
/**
* @description: 返回结果泛型类
* @author: landaiqing
* @author: schisandra
* @date: 2024/3/22 13:09
*/
@Data

View File

@@ -5,7 +5,7 @@ import lombok.Getter;
/**
* 用户状态枚举
*
* @author: landaiqing
* @author: schisandra
*/
@Getter
public enum AuthUserStatusEnum {

View File

@@ -5,7 +5,7 @@ import lombok.Getter;
/**
* 删除状态枚举
*
* @author: landaiqing
* @author: schisandra
*/
@Getter
public enum IsDeletedFlagEnum {

View File

@@ -4,7 +4,7 @@ import lombok.Getter;
/**
* @description: 返回结果状态枚举
* @author: landaiqing
* @author: schisandra
* @date: 2024/3/22 13:10
*/
@Getter

View File

@@ -0,0 +1,82 @@
package com.schisandra.auth.common.enums;
import lombok.Getter;
@Getter
public enum SmsSupplierType {
/**
* 阿里云
*/
ALIBABA("alibaba"),
/**
* 华为云
*/
HUAWEI("huawei"),
/**
* 云片
*/
YUNPIAN("yunpian"),
/**
* 腾讯云
*/
TENCENT("tenxun"),
/**
* 合一短信
*/
UNI_SMS("uni"),
/**
* 京东云
*/
JD_CLOUD("jd"),
/**
* 容联云
*/
CLOOPEN("cloopen"),
/**
* 亿美软通
*/
EMAY("emay"),
/**
* 天翼云
*/
CTYUN("ctyun"),
/**
* 网易云
*/
WANGYIYUN("wangyiyun"),
/**
* 七牛云
*/
QINIU("qiniu"),
/**
* 助通
*/
ZHUTONG("zhutong"),
/**
* 联麓
*/
LIANLU("lianlu"),
/**
* 鼎众
*/
DINGZHONG("dingzhong"),
;
public String key;
SmsSupplierType(String key) {
this.key = key;
}
public static SmsSupplierType getByKey(String key) {
for (SmsSupplierType resultKeyEnum : SmsSupplierType.values()) {
if (resultKeyEnum.key.equals(key)) {
return resultKeyEnum;
}
}
return null;
}
}

View File

@@ -16,7 +16,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis的config处理
*
* @author: landaiqing
* @author: schisandra
*/
@Configuration
public class RedisConfig {

View File

@@ -13,7 +13,7 @@ import java.util.stream.Stream;
/**
* RedisUtil工具类
*
* @author: landaiqing
* @author: schisandra
* @date: 2024/2/19
*/
@Component

View File

@@ -1,18 +1,16 @@
package com.schisandra.auth.common.utils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.util.Base64;
import java.util.Base64.Encoder;
import java.util.Base64.Decoder;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
public class RotateImageUtils {
@@ -45,8 +43,8 @@ public class RotateImageUtils {
ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流
ImageIO.write(outputImage, "png", baos);//写入流中
byte[] bytes = baos.toByteArray();//转换成字节
BASE64Encoder encoder = new BASE64Encoder();
String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串
Encoder encoder = Base64.getEncoder();
String png_base64 = encoder.encodeToString(bytes);//转换成base64串
png_base64 = png_base64.replaceAll("\n", "").replaceAll("\r", "");//删除 \r\n
return "data:image/jpg;base64," + png_base64;
@@ -60,9 +58,9 @@ public class RotateImageUtils {
* @date: 2024/5/9 13:14
*/
public static BufferedImage base64ToBufferedImage(String base64) {
BASE64Decoder decoder = new sun.misc.BASE64Decoder();
Decoder decoder = Base64.getDecoder();
try {
byte[] bytes1 = decoder.decodeBuffer(base64);
byte[] bytes1 = decoder.decode(base64);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);
return ImageIO.read(bais);
} catch (IOException e) {

View File

@@ -148,6 +148,16 @@ public class SchisandraSmsConfigBO implements Serializable {
* 签名ID
*/
private String signatureId;
/**
* 是否删除 0 未删除 1已删除
*/
private Integer isDeleted;
private String extraJson;
/**
* 服务名
*/
private String service;

View File

@@ -24,7 +24,7 @@ public interface SchisandraAuthRoleBOConverter {
* @description 将bo转换为实体
* @param schisandraAuthRoleBO
* @return com.schisandra.auth.infra.basic.entity.SchisandraRoleUser
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraAuthRole convertBOToEntity(SchisandraAuthRoleBO schisandraAuthRoleBO);
@@ -33,7 +33,7 @@ public interface SchisandraAuthRoleBOConverter {
* @description 将实体转换为bo
* @param schisandraAuthRole
* @return com.schisandra.auth.domain.bo.SchisandraAuthRoleBO
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraAuthRoleBO convertEntityToBO(SchisandraAuthRole schisandraAuthRole);

View File

@@ -8,7 +8,7 @@ import org.mapstruct.factory.Mappers;
/**
* 用户bo转换器
*
* @author landaiqing
* @author schisandra
* @date 2024/3/21
*/
@Mapper(componentModel = "spring")
@@ -20,7 +20,7 @@ public interface SchisandraAuthUserBOConverter {
* @description 将bo转换为实体
* @param schisandraAuthUserBO
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraAuthUser convertBOToEntity(SchisandraAuthUserBO schisandraAuthUserBO);
@@ -29,7 +29,7 @@ public interface SchisandraAuthUserBOConverter {
* @description 将实体转换为bo
* @param schisandraAuthUser
* @return com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraAuthUserBO convertEntityToBO(SchisandraAuthUser schisandraAuthUser);

View File

@@ -27,7 +27,7 @@ public interface SchisandraSmsConfigBOConvert {
* @description 将bo转换为实体
* @param schisandraSmsConfigBO
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraSmsConfig convertBOToEntity(SchisandraSmsConfigBO schisandraSmsConfigBO);
@@ -36,7 +36,7 @@ public interface SchisandraSmsConfigBOConvert {
* @description 将实体转换为bo
* @param schisandraSmsConfig
* @return com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:13
*/
SchisandraSmsConfigBO convertEntityToBO(SchisandraSmsConfig schisandraSmsConfig);

View File

@@ -7,7 +7,7 @@ import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
/**
* 用户领域service
*
* @author landaiqing
* @author schisandra
* @date 2024/3/21
*/
public interface SchisandraAuthUserDomainService {
@@ -16,7 +16,7 @@ public interface SchisandraAuthUserDomainService {
* @description 更新用户信息
* @param schisandraAuthUserBO
* @return java.lang.Object
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:14
*/
Object update(SchisandraAuthUserBO schisandraAuthUserBO);

View File

@@ -9,7 +9,7 @@ import java.util.List;
/**
* 用户领域service
*
* @author landaiqing
* @author schisandra
* @date 2024/3/21
*/
public interface SchisandraSmsConfigDomainService {
@@ -18,5 +18,7 @@ public interface SchisandraSmsConfigDomainService {
List<SchisandraSmsConfigBO> queryAll();
SchisandraSmsConfigBO queryByConfigId(String configId);
}

View File

@@ -21,7 +21,7 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
* @description 更新用户信息
* @param schisandraAuthUserBO
* @return java.lang.Object
* @author landaiqing
* @author schisandra
* @date 2024/3/21 23:14
*/
@Override

View File

@@ -23,4 +23,12 @@ public class SchisandraSmsConfigDomainServiceImpl implements SchisandraSmsConfig
}
@Override
public SchisandraSmsConfigBO queryByConfigId(String configId) {
SchisandraSmsConfig schisandraSmsConfig= schisandraSmsConfigService.queryByConfigId(configId);
SchisandraSmsConfigBO schisandraSmsConfigBO = SchisandraSmsConfigBOConvert.INSTANCE.convertEntityToBO(schisandraSmsConfig);
return schisandraSmsConfigBO;
}
}

View File

@@ -9,7 +9,7 @@ import java.util.List;
/**
* (SchisandraAuthUser)表数据库访问层
*
* @author landaiqing
* @author schisandra
* @since 2024-03-21 20:15:43
*/
public interface SchisandraAuthUserDao {

View File

@@ -10,7 +10,7 @@ import java.util.List;
* (SchisandraSmsConfig)表数据库访问层
*
* @author makejava
* @since 2024-05-08 20:09:54
* @since 2024-05-11 15:47:58
*/
public interface SchisandraSmsConfigDao {
@@ -31,8 +31,6 @@ public interface SchisandraSmsConfigDao {
*/
List<SchisandraSmsConfig> queryAllByLimit(SchisandraSmsConfig schisandraSmsConfig, @Param("pageable") Pageable pageable);
List<SchisandraSmsConfig> queryAll();
/**
* 统计总行数
*
@@ -82,5 +80,8 @@ public interface SchisandraSmsConfigDao {
*/
int deleteById(Integer id);
List<SchisandraSmsConfig> queryAll();
SchisandraSmsConfig queryByConfigId(String configId);
}

View File

@@ -9,7 +9,7 @@ import java.io.Serializable;
* (SchisandraSmsConfig)实体类
*
* @author makejava
* @since 2024-05-08 20:09:54
* @since 2024-05-11 15:47:59
*/
@Data
public class SchisandraSmsConfig implements Serializable {
@@ -169,6 +169,11 @@ public class SchisandraSmsConfig implements Serializable {
*/
private Integer isDeleted;
private String extraJson;
/**
* 服务名
*/
private String service;
}

View File

@@ -7,7 +7,7 @@ import org.springframework.data.domain.PageRequest;
/**
* (SchisandraAuthUser)表服务接口
*
* @author landaiqing
* @author schisandra
* @since 2024-03-21 20:15:44
*/
public interface SchisandraAuthUserService {

View File

@@ -10,7 +10,7 @@ import java.util.List;
* (SchisandraSmsConfig)表服务接口
*
* @author makejava
* @since 2024-05-08 20:09:55
* @since 2024-05-11 15:48:02
*/
public interface SchisandraSmsConfigService {
@@ -22,8 +22,6 @@ public interface SchisandraSmsConfigService {
*/
SchisandraSmsConfig queryById(Integer id);
List<SchisandraSmsConfig> queryAll();
/**
* 分页查询
*
@@ -57,4 +55,7 @@ public interface SchisandraSmsConfigService {
*/
boolean deleteById(Integer id);
List<SchisandraSmsConfig> queryAll();
SchisandraSmsConfig queryByConfigId(String configId);
}

View File

@@ -13,7 +13,7 @@ import javax.annotation.Resource;
/**
* (SchisandraAuthUser)表服务实现类
*
* @author landaiqing
* @author schisandra
* @since 2024-03-21 20:15:44
*/
@Service("schisandraAuthUserService")

View File

@@ -15,7 +15,7 @@ import java.util.List;
* (SchisandraSmsConfig)表服务实现类
*
* @author makejava
* @since 2024-05-08 20:09:55
* @since 2024-05-11 15:48:03
*/
@Service("schisandraSmsConfigService")
public class SchisandraSmsConfigServiceImpl implements SchisandraSmsConfigService {
@@ -46,11 +46,6 @@ public class SchisandraSmsConfigServiceImpl implements SchisandraSmsConfigServic
return new PageImpl<>(this.schisandraSmsConfigDao.queryAllByLimit(schisandraSmsConfig, pageRequest), pageRequest, total);
}
@Override
public List<SchisandraSmsConfig> queryAll() {
return this.schisandraSmsConfigDao.queryAll();
}
/**
* 新增数据
*
@@ -85,4 +80,14 @@ public class SchisandraSmsConfigServiceImpl implements SchisandraSmsConfigServic
public boolean deleteById(Integer id) {
return this.schisandraSmsConfigDao.deleteById(id) > 0;
}
@Override
public List<SchisandraSmsConfig> queryAll() {
return schisandraSmsConfigDao.queryAll();
}
@Override
public SchisandraSmsConfig queryByConfigId(String configId) {
return schisandraSmsConfigDao.queryByConfigId(configId);
}
}

View File

@@ -8,7 +8,7 @@ import java.security.NoSuchProviderException;
/**
* 数据库加密util
*
* @author: landaiqing
* @author: schisandra
* @date: 2024/3/21
*/
public class DruidEncryptUtil {

View File

@@ -44,24 +44,21 @@
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="isDeleted" column="is_deleted" jdbcType="INTEGER"/>
<result property="extraJson" column="extra_json" jdbcType="VARCHAR"/>
<result property="service" column="service" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="SchisandraSmsConfigMap">
select id,config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted
select id,config_id,request_url,template_name,`action`,region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted,extra_json,service
from schisandra_sms_config
where id = #{id}
</select>
<select id="queryAll" resultMap="SchisandraSmsConfigMap">
select
id,config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted
from schisandra_sms_config
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="SchisandraSmsConfigMap">
select
id,config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted
id,config_id,request_url,template_name,`action`,region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted,extra_json,service
from schisandra_sms_config
<where>
<if test="id != null">
@@ -77,7 +74,7 @@
and template_name = #{templateName}
</if>
<if test="action != null and action != ''">
and 'action' = #{action}
and `action` = #{action}
</if>
<if test="region != null and region != ''">
and region = #{region}
@@ -187,6 +184,12 @@
<if test="isDeleted != null">
and is_deleted = #{isDeleted}
</if>
<if test="extraJson != null and extraJson != ''">
and extra_json = #{extraJson}
</if>
<if test="service != null and service != ''">
and service = #{service}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
@@ -209,7 +212,7 @@
and template_name = #{templateName}
</if>
<if test="action != null and action != ''">
and 'action' = #{action}
and action = #{action}
</if>
<if test="region != null and region != ''">
and region = #{region}
@@ -319,30 +322,50 @@
<if test="isDeleted != null">
and is_deleted = #{isDeleted}
</if>
<if test="extraJson != null and extraJson != ''">
and extra_json = #{extraJson}
</if>
<if test="service != null and service != ''">
and service = #{service}
</if>
</where>
</select>
<select id="queryAll" resultMap="SchisandraSmsConfigMap">
select *
from schisandra_sms_config
where is_deleted = 0
</select>
<select id="queryByConfigId" resultMap="SchisandraSmsConfigMap">
select *
from schisandra_sms_config
where config_id = #{configId}
and is_deleted = 0
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into schisandra_sms_config(config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted)
values (#{configId},#{requestUrl},#{templateName},#{action},#{region},#{accessKeyId},#{accessKeySecret},#{supplier},#{signature},#{sdkAppId},#{templateId},#{weight},#{retryInterval},#{maxRetries},#{maximum},#{baseUrl},#{serverIp},#{serverPort},#{sender},#{statusCallBack},#{url},#{templateUrl},#{codeUrl},#{verifyUrl},#{needUp},#{connTimeout},#{isSimple},#{callbackUrl},#{mchId},#{appKey},#{appId},#{version},#{singleMsgUrl},#{massMsgUrl},#{signatureId},#{createdBy},#{createdTime},#{updateTime},#{updateBy},#{isDeleted})
insert into schisandra_sms_config(config_id,request_url,template_name,action,region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted,extra_json,service
)
values (#{configId},#{requestUrl},#{templateName},#{action},#{region},#{accessKeyId},#{accessKeySecret},#{supplier},#{signature},#{sdkAppId},#{templateId},#{weight},#{retryInterval},#{maxRetries},#{maximum},#{baseUrl},#{serverIp},#{serverPort},#{sender},#{statusCallBack},#{url},#{templateUrl},#{codeUrl},#{verifyUrl},#{needUp},#{connTimeout},#{isSimple},#{callbackUrl},#{mchId},#{appKey},#{appId},#{version},#{singleMsgUrl},#{massMsgUrl},#{signatureId},#{createdBy},#{createdTime},#{updateTime},#{updateBy},#{isDeleted},#{extraJson},#{service})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into
schisandra_sms_config(config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted)
schisandra_sms_config(config_id,request_url,template_name,action,region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted,extra_json,service
)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.configId},#{entity.requestUrl},#{entity.templateName},#{entity.action},#{entity.region},#{entity.accessKeyId},#{entity.accessKeySecret},#{entity.supplier},#{entity.signature},#{entity.sdkAppId},#{entity.templateId},#{entity.weight},#{entity.retryInterval},#{entity.maxRetries},#{entity.maximum},#{entity.baseUrl},#{entity.serverIp},#{entity.serverPort},#{entity.sender},#{entity.statusCallBack},#{entity.url},#{entity.templateUrl},#{entity.codeUrl},#{entity.verifyUrl},#{entity.needUp},#{entity.connTimeout},#{entity.isSimple},#{entity.callbackUrl},#{entity.mchId},#{entity.appKey},#{entity.appId},#{entity.version},#{entity.singleMsgUrl},#{entity.massMsgUrl},#{entity.signatureId},#{entity.createdBy},#{entity.createdTime},#{entity.updateTime},#{entity.updateBy},#{entity.isDeleted})
(#{entity.configId},#{entity.requestUrl},#{entity.templateName},#{entity.action},#{entity.region},#{entity.accessKeyId},#{entity.accessKeySecret},#{entity.supplier},#{entity.signature},#{entity.sdkAppId},#{entity.templateId},#{entity.weight},#{entity.retryInterval},#{entity.maxRetries},#{entity.maximum},#{entity.baseUrl},#{entity.serverIp},#{entity.serverPort},#{entity.sender},#{entity.statusCallBack},#{entity.url},#{entity.templateUrl},#{entity.codeUrl},#{entity.verifyUrl},#{entity.needUp},#{entity.connTimeout},#{entity.isSimple},#{entity.callbackUrl},#{entity.mchId},#{entity.appKey},#{entity.appId},#{entity.version},#{entity.singleMsgUrl},#{entity.massMsgUrl},#{entity.signatureId},#{entity.createdBy},#{entity.createdTime},#{entity.updateTime},#{entity.updateBy},#{entity.isDeleted},#{entity.extraJson},#{entity.service})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into
schisandra_sms_config(config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted)
schisandra_sms_config(config_id,request_url,template_name,action,region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted,extra_json,service
)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.configId},#{entity.requestUrl},#{entity.templateName},#{entity.action},#{entity.region},#{entity.accessKeyId},#{entity.accessKeySecret},#{entity.supplier},#{entity.signature},#{entity.sdkAppId},#{entity.templateId},#{entity.weight},#{entity.retryInterval},#{entity.maxRetries},#{entity.maximum},#{entity.baseUrl},#{entity.serverIp},#{entity.serverPort},#{entity.sender},#{entity.statusCallBack},#{entity.url},#{entity.templateUrl},#{entity.codeUrl},#{entity.verifyUrl},#{entity.needUp},#{entity.connTimeout},#{entity.isSimple},#{entity.callbackUrl},#{entity.mchId},#{entity.appKey},#{entity.appId},#{entity.version},#{entity.singleMsgUrl},#{entity.massMsgUrl},#{entity.signatureId},#{entity.createdBy},#{entity.createdTime},#{entity.updateTime},#{entity.updateBy},#{entity.isDeleted})
(#{entity.configId},#{entity.requestUrl},#{entity.templateName},#{entity.action},#{entity.region},#{entity.accessKeyId},#{entity.accessKeySecret},#{entity.supplier},#{entity.signature},#{entity.sdkAppId},#{entity.templateId},#{entity.weight},#{entity.retryInterval},#{entity.maxRetries},#{entity.maximum},#{entity.baseUrl},#{entity.serverIp},#{entity.serverPort},#{entity.sender},#{entity.statusCallBack},#{entity.url},#{entity.templateUrl},#{entity.codeUrl},#{entity.verifyUrl},#{entity.needUp},#{entity.connTimeout},#{entity.isSimple},#{entity.callbackUrl},#{entity.mchId},#{entity.appKey},#{entity.appId},#{entity.version},#{entity.singleMsgUrl},#{entity.massMsgUrl},#{entity.signatureId},#{entity.createdBy},#{entity.createdTime},#{entity.updateTime},#{entity.updateBy},#{entity.isDeleted},#{entity.extraJson},#{entity.service})
</foreach>
on duplicate key update
config_id = values(config_id)request_url = values(request_url)template_name = values(template_name)action =
@@ -357,7 +380,8 @@
values(callback_url)mch_id = values(mch_id)app_key = values(app_key)app_id = values(app_id)version =
values(version)single_msg_url = values(single_msg_url)mass_msg_url = values(mass_msg_url)signature_Id =
values(signature_Id)created_by = values(created_by)created_time = values(created_time)update_time =
values(update_time)update_by = values(update_by)is_deleted = values(is_deleted)
values(update_time)update_by = values(update_by)is_deleted = values(is_deleted)extra_json =
values(extra_json)service = values(service)
</insert>
<!--通过主键修改数据-->
@@ -374,7 +398,7 @@
template_name = #{templateName},
</if>
<if test="action != null and action != ''">
`action` = #{action},
action = #{action},
</if>
<if test="region != null and region != ''">
region = #{region},
@@ -484,6 +508,12 @@
<if test="isDeleted != null">
is_deleted = #{isDeleted},
</if>
<if test="extraJson != null and extraJson != ''">
extra_json = #{extraJson},
</if>
<if test="service != null and service != ''">
service = #{service},
</if>
</set>
where id = #{id}
</update>

View File

@@ -8,7 +8,7 @@ import org.springframework.context.annotation.ComponentScan;
/**
* 鉴权微服务启动类
*
* @author: landaiqing
* @author: schisandra
* @date: 2024/3/21
*/
@SpringBootApplication

View File

@@ -7,7 +7,7 @@
<Properties>
<!-- 格式化输出:%date表示日期%thread表示线程名%-5level级别从左显示5个字符宽度 %msg日志消息%n是换行符-->
<!-- %logger{36} 表示 Logger 名字最长36个字符 -->
<property name="LOG_PATTERN" value="%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx" />
<property name="LOG_PATTERN" value="%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%thread]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx" />
<!-- 定义日志存储的路径 -->
<property name="FILE_PATH" value="../log" />
<property name="FILE_NAME" value="schisandra-cloud-storage-auth.log" />

View File

@@ -0,0 +1,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.schisandra</groupId>
<artifactId>schisandra-cloud-storage-common-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>easy-gen-code-spring-boot-starter</artifactId>
<packaging>jar</packaging>
<name>easy-gen-code-spring-boot-starter</name>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.12.3</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>rdc-releases</id>
<name>dw-repo-releases</name>
<url>https://packages.aliyun.com/maven/repository/2012812-release-SiITng/</url>
</repository>
<snapshotRepository>
<id>rdc-snapshots</id>
<name>dw-repo-snapshots</name>
<url>https://packages.aliyun.com/maven/repository/2012812-snapshot-LHGmjL/</url>
</snapshotRepository>
</distributionManagement>
</project>

View File

@@ -0,0 +1,26 @@
package com.schisandra.core.anno;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Table {
String value() default "";
String keyType() default "";
String col() default "";
String comment() default "";
String myBatisType() default "";
String jdbcType() default "";
}

View File

@@ -0,0 +1,47 @@
package com.schisandra.core.config;
import com.schisandra.core.entity.JdbcConfig;
import lombok.Data;
import java.util.Map;
/**
* 代码生成器配置
*
* @author loser
* @date 2023/9/4
*/
@Data
public class GenConfig {
/**
* 从自定义的类中获取数据
*/
private String handler;
/**
* 从classPath下的json文件中获取数据
*/
private String json;
/**
* 使用jdbc从表结构中获取数据
*/
private JdbcConfig jdbc;
/**
* 模板与生成文件的映射配置文件
*/
private String mapperInfos;
/**
* 针对某一个模板将数据写入该模板上下文
*/
private String filePutHandler;
/**
* 自定义写入全局的参数
*/
private Map<String, Object> params;
}

View File

@@ -0,0 +1,27 @@
package com.schisandra.core.config;
import com.schisandra.core.entity.Mapper;
import lombok.Data;
import java.util.List;
/**
* 模板与生成文件的映射关系
*
* @author loser
* @date 2023/9/4
*/
@Data
public class MapperConfig {
/**
* 文件生成到该项目的哪个模块
*/
private String module;
/**
* 映射关系
*/
private List<Mapper> mappers;
}

View File

@@ -0,0 +1,241 @@
package com.schisandra.core.core;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.schisandra.core.config.GenConfig;
import com.schisandra.core.config.MapperConfig;
import com.schisandra.core.core.impl.JdbcPutContextHandler;
import com.schisandra.core.core.sdk.FilePutContextHandler;
import com.schisandra.core.core.sdk.PostCurFiledContextAware;
import com.schisandra.core.entity.Context;
import com.schisandra.core.entity.MapperInfo;
import com.schisandra.core.utils.*;
import org.apache.velocity.VelocityContext;
import java.io.File;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
public class CodeGenerationCode {
public static void doGenCode() {
doGenCode(null);
}
public static void doGenCode(PostCurFiledContextAware aware) {
try {
// 01 获取入口配置文件
GenConfig genConfig = YamlUtils.loadYaml("genCode/gen.yml", GenConfig.class);
// 02 获取全局的配置上下文
assert genConfig != null;
VelocityContext context = getGlobalContext(genConfig);
Map<String, Object> contexts = new HashMap<>();
for (String key : context.getKeys()) {
Object value = context.get(key);
if (value instanceof String && FunctionUtils.isFunction(value)) {
value = FunctionUtils.doFunction(value);
context.put(key, value);
}
contexts.put(key, context.get(key));
}
System.out.println("==========> getGlobalContext:" + System.lineSeparator() + JSONObject.toJSONString(contexts));
System.out.println();
// 03 获取 模板与生成文件的映射关系
List<MapperInfo> infos = getMapperInfos(genConfig, context, aware);
// 04 通过映射关系生成代码文件
genCode(infos, genConfig.getParams().getOrDefault("templateBasePath", "").toString());
} catch (Exception e) {
e.printStackTrace();
}
}
private static void genCode(List<MapperInfo> infos, String templateBasePath) {
AtomicInteger count = new AtomicInteger(1);
infos.forEach(info -> {
CodeGeneratorUtils codeGenerator = new CodeGeneratorUtils(templateBasePath);
codeGenerator.generateCode(
info.getContext(),
info.getTemplatePath(),
info.getOutPutPath(),
count);
});
}
private static List<MapperInfo> getMapperInfos(GenConfig genConfig, VelocityContext context, PostCurFiledContextAware aware) {
MapperConfig mapperConfig = YamlUtils.loadYaml(genConfig.getMapperInfos(), MapperConfig.class);
assert mapperConfig != null;
// 允许在生成文件前对上下文中的数据进行修改 处理一些导包之类的不好控制业务
if (Objects.nonNull(aware)) {
aware.doAware(genConfig, mapperConfig, context);
Map<String, Object> contexts = new HashMap<>();
for (String key : context.getKeys()) {
Object value = context.get(key);
contexts.put(key, value);
}
System.out.println("==========> modify file context :" + System.lineSeparator() + JSONObject.toJSONString(contexts));
}
AtomicInteger count = new AtomicInteger(1);
return mapperConfig.getMappers().stream().filter(Objects::nonNull).map(item -> {
MapperInfo info = new MapperInfo();
info.setTemplatePath(getResPath(item.getTemplate()));
String cName = item.getName();
if (cName.contains("$")) {
cName = replace$key(context, cName);
}
String pkg = item.getPackageName();
if (StrUtil.isNotEmpty(pkg) && pkg.contains("$")) {
pkg = replace$key(context, pkg);
}
String filePath = item.getFilePath();
if (StrUtil.isNotEmpty(filePath) && filePath.contains("$")) {
filePath = replace$key(context, filePath);
}
String outPutPath = getTargetPath(mapperConfig.getModule(), pkg, filePath);
File file = new File(outPutPath);
if (!file.exists()) {
boolean mkdirs = file.mkdirs();
System.out.println("==========> mkdir " + mkdirs + " " + file.getAbsolutePath());
System.out.println();
}
outPutPath += ("/" + cName + "." + item.getExt());
VelocityContext cloneCtx = (VelocityContext) context.clone();
info.setOutPutPath(outPutPath);
if (StrUtil.isNotBlank(genConfig.getFilePutHandler())) {
try {
FilePutContextHandler handler = (FilePutContextHandler) Class.forName(genConfig.getFilePutHandler()).newInstance();
handler.put(cloneCtx, item.getFileId());
} catch (Exception e) {
e.printStackTrace();
}
}
cloneCtx.put("className", cName);
cloneCtx.put("packageName", pkg);
System.out.println("==========> " + count.get() + " MapperInfo : " + System.lineSeparator() + info);
System.out.println();
Map<String, Object> contexts = new HashMap<>();
for (String key : cloneCtx.getKeys()) {
contexts.put(key, cloneCtx.get(key));
}
System.out.println("==========> MapperInfo context : " + System.lineSeparator() + JSONObject.toJSONString(contexts));
System.out.println();
System.out.println("=============================================================================================================================================");
System.out.println();
info.setContext(cloneCtx);
return info;
}).collect(Collectors.toList());
}
private static String replace$key(VelocityContext velocityContext, String conextkey) {
String key = conextkey.substring(conextkey.indexOf("${") + 2, conextkey.indexOf("}"));
Object value = velocityContext.get(key);
conextkey = conextkey.replace("${" + key + "}", value.toString());
if (conextkey.contains("$")) {
conextkey = replace$key(velocityContext, conextkey);
}
return conextkey;
}
private static VelocityContext getGlobalContext(GenConfig genConfig) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Context context = ConfigUtils.getContext();
boolean putData = false;
// 01 处理优先级第一的处理器
if (StrUtil.isNotBlank(genConfig.getHandler())) {
JdbcPutContextHandler jdbcPutContextHandler = (JdbcPutContextHandler) Class.forName(genConfig.getHandler()).newInstance();
putData = jdbcPutContextHandler.put();
}
// 02 处理优先级第二的json导入
if (!putData && StrUtil.isNotBlank(genConfig.getJson())) {
List<String> lines = FileUtil.readLines(getRealResPath(genConfig.getJson()), "UTF-8");
StringBuilder json = new StringBuilder();
for (String line : lines) {
json.append(line);
}
context = ContextUtils.buildContext(json.toString());
ConfigUtils.reSetContext(context);
putData = true;
}
// 03 处理优先级第三的mysql导入
if (!putData) {
JdbcPutContextHandler jdbcPutContextHandler = new JdbcPutContextHandler();
jdbcPutContextHandler.put();
}
// 04 添加配置中的全局参数
Map<String, Object> params = genConfig.getParams();
for (Map.Entry<String, Object> entry : params.entrySet()) {
context.put(entry.getKey(), entry.getValue());
}
return context.get();
}
private static String getTargetPath(String module, String packageName, String filePath) {
if (StrUtil.isEmpty(module)) {
module = "/";
}
if (SystemUtils.isMacOs()) {
if (StrUtil.isEmpty(filePath)) {
return getCurPath().substring(0, getCurPath().length() - 2) + module + "src/main/java/" + packageName.replaceAll("\\.", "/");
} else {
return getCurPath().substring(0, getCurPath().length() - 2) + module + filePath;
}
} else {
if (StrUtil.isEmpty(filePath)) {
return getCurPath() + module + "src/main/java/" + packageName.replaceAll("\\.", "\\");
} else {
return getCurPath() + module + filePath;
}
}
}
private static URL getRealResPath(String res) {
ClassLoader classLoader = CodeGenerationCode.class.getClassLoader();
return classLoader.getResource(res);
}
private static String getResPath(String res) {
if (SystemUtils.isMacOs()) {
ClassLoader classLoader = CodeGenerationCode.class.getClassLoader();
return classLoader.getResource(res).getPath()
.replaceAll(getCurPath().substring(0, getCurPath().length() - 1), "");
} else {
return res;
}
}
private static String getCurPath() {
if (SystemUtils.isMacOs()) {
return new File("./").getAbsolutePath();
} else {
return System.getProperty("user.dir");
}
}
}

View File

@@ -0,0 +1,134 @@
package com.schisandra.core.core;
import cn.hutool.core.collection.CollectionUtil;
import com.schisandra.core.entity.JdbcConfig;
import com.schisandra.core.entity.TableInfo;
import com.schisandra.core.utils.Lists;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import javax.sql.DataSource;
import java.sql.Driver;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* 简易mysql处理器 查询表备注及表字段
*
* @author loser
* @date 2023/9/4
*/
@AllArgsConstructor
public class MysqlDataHandler {
private String tableName;
private String dbUrl;
private String dbUser;
private String dbPw;
private String dbName;
private String driver;
public String getTableComment() {
JdbcConfig config = new JdbcConfig(
dbUrl + dbName + "?useUnicode=true",
dbUser,
dbPw,
dbName,
driver,
tableName
);
JdbcTemplate jdbcTemplate = initJdbcTemplate(config);
String sql = "SELECT table_comment tableComment FROM information_schema.TABLES WHERE table_schema = ? and table_name = ? ";
List<Object> params = Lists.newArrayList();
params.add(config.getDbName());
params.add(tableName);
BeanPropertyRowMapper<TableInfo> rowMapper = new BeanPropertyRowMapper<>(TableInfo.class);
if (CollectionUtil.isEmpty(params)) {
return jdbcTemplate.query(sql, rowMapper).get(0).getTableComment();
}
List<TableInfo> query = jdbcTemplate.query(sql, rowMapper, params.toArray());
if (CollectionUtil.isEmpty(query)) {
throw new RuntimeException("表不存在:" + tableName);
}
return query.get(0).getTableComment();
}
/**
* 使用表名 查询表结构信息
*/
public List<TableInfo> searchByDb() {
JdbcConfig config = new JdbcConfig(
dbUrl + dbName + "?useUnicode=true",
dbUser,
dbPw,
dbName,
driver,
tableName
);
JdbcTemplate jdbcTemplate = initJdbcTemplate(config);
String sql = "select column_name as name, column_comment as comment,DATA_TYPE as dataType,COLUMN_KEY as keyType " +
"from information_schema.columns where table_schema = ? and table_name = ? ORDER BY ORDINAL_POSITION";
List<Object> params = Lists.newArrayList();
params.add(config.getDbName());
params.add(tableName);
BeanPropertyRowMapper<TableInfo> rowMapper = new BeanPropertyRowMapper<>(TableInfo.class);
if (CollectionUtil.isEmpty(params)) {
return jdbcTemplate.query(sql, rowMapper);
}
List<TableInfo> list = jdbcTemplate.query(sql, rowMapper, params.toArray());
return list.stream().peek(item -> {
item.setCol(item.getName());
item.setName(underlineToHump(item.getName()));
}).collect(Collectors.toList());
}
/**
* 初始化一个jdbc
*/
private static JdbcTemplate initJdbcTemplate(JdbcConfig config) {
DataSource dataSource;
try {
dataSource = new SimpleDriverDataSource(
BeanUtils.instantiateClass((Class<Driver>) Class.forName(config.getDriver())),
config.getUrl(),
config.getUsername(),
config.getPassword());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return new JdbcTemplate(dataSource);
}
private static Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])");
public static String underlineToHump(String str) {
//正则匹配下划线及后一个字符,删除下划线并将匹配的字符转成大写
Matcher matcher = UNDERLINE_PATTERN.matcher(str);
StringBuffer sb = new StringBuffer(str);
if (matcher.find()) {
sb = new StringBuffer();
//将当前匹配的子串替换成指定字符串并且将替换后的子串及之前到上次匹配的子串之后的字符串添加到StringBuffer对象中
//正则之前的字符和被替换的字符
matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
//把之后的字符串也添加到StringBuffer对象中
matcher.appendTail(sb);
} else {
//去除除字母之外的前面带的下划线
return sb.toString().replaceAll("_", "");
}
return underlineToHump(sb.toString());
}
}

View File

@@ -0,0 +1,36 @@
package com.schisandra.core.core.impl;
import com.schisandra.core.config.GenConfig;
import com.schisandra.core.config.MapperConfig;
import com.schisandra.core.core.sdk.PostCurFiledContextAware;
import com.schisandra.core.entity.TableInfo;
import com.schisandra.core.utils.TableUtils;
import org.apache.velocity.VelocityContext;
import java.util.List;
/**
* 从字段注解中获取数据
*
* @author loser
* @date 2023/9/4
*/
public class ClassPutContextHandler implements PostCurFiledContextAware {
private Class<?> clazz;
public ClassPutContextHandler(Class<?> clazz) {
this.clazz = clazz;
}
@Override
public void doAware(GenConfig genConfig, MapperConfig mapperConfig, VelocityContext context) {
String tableComment = TableUtils.getComment(clazz);
List<TableInfo> fields = TableUtils.build(clazz);
context.put("tableComment", tableComment);
context.put("fields", fields);
}
}

View File

@@ -0,0 +1,14 @@
package com.schisandra.core.core.impl;
import com.schisandra.core.core.sdk.FilePutContextHandler;
import java.util.Map;
public class DemoFilePutContextHandler implements FilePutContextHandler {
@Override
public Map<String, Object> putData(String fileId) {
return null;
}
}

View File

@@ -0,0 +1,34 @@
package com.schisandra.core.core.impl;
import com.schisandra.core.config.GenConfig;
import com.schisandra.core.core.sdk.PutContextHandler;
import com.schisandra.core.entity.TableInfo;
import com.schisandra.core.utils.JdbcUtil;
import com.schisandra.core.utils.YamlUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 从配置的mysql数据源中获取表字段及表备注写入到全局上下文
*
* @author loser
* @date 2023/9/4
*/
public class JdbcPutContextHandler implements PutContextHandler {
@Override
public Map<String, Object> putData() {
GenConfig genConfig = YamlUtils.loadYaml("genCode/gen.yml", GenConfig.class);
String tableComment = JdbcUtil.getComment(genConfig.getJdbc(), genConfig.getJdbc().getTableName());
List<TableInfo> fields = JdbcUtil.queryTableInfo(genConfig.getJdbc(), genConfig.getJdbc().getTableName());
Map<String, Object> res = new HashMap<>();
res.put("tableComment", tableComment);
res.put("fields", fields);
return res;
}
}

View File

@@ -0,0 +1,36 @@
package com.schisandra.core.core.sdk;
import cn.hutool.core.map.MapUtil;
import org.apache.velocity.VelocityContext;
import java.util.Map;
/**
* 针对某个生成文件写入独有上下文
*
* @author loser
* @date 2023/9/4
*/
public interface FilePutContextHandler {
/**
* 将map中的键值对写入当前文件的上下文
*
* @param fileId 文件id
* @return 写入的数据
*/
Map<String, Object> putData(String fileId);
default void put(VelocityContext context, String fileId) {
Map<String, Object> map = putData(fileId);
if (MapUtil.isNotEmpty(map)) {
for (Map.Entry<String, Object> entity : map.entrySet()) {
context.put(entity.getKey(), entity.getValue());
}
}
}
}

View File

@@ -0,0 +1,21 @@
package com.schisandra.core.core.sdk;
/**
* 内置函数
*
* @author loser
* @date 2023/9/4
*/
public interface Function {
/**
* 函数key
*/
String funcKey();
/**
* 执行函授后的返回值
*/
String doFunc();
}

View File

@@ -0,0 +1,18 @@
package com.schisandra.core.core.sdk;
import com.schisandra.core.config.GenConfig;
import com.schisandra.core.config.MapperConfig;
import org.apache.velocity.VelocityContext;
/**
* 针对当前文件的上下文进行操作
*
* @author loser
* @date 2023/9/4
*/
@FunctionalInterface
public interface PostCurFiledContextAware {
void doAware(GenConfig genConfig, MapperConfig mapperConfig, VelocityContext context);
}

View File

@@ -0,0 +1,31 @@
package com.schisandra.core.core.sdk;
import com.schisandra.core.entity.Context;
import com.schisandra.core.utils.ConfigUtils;
import java.util.Map;
/**
* 从类中写入数据到全局上下文
*
* @author loser
* @date 2023/9/4
*/
public interface PutContextHandler {
Map<String, Object> putData();
default boolean put() {
boolean res = false;
Map<String, Object> map = putData();
Context context = ConfigUtils.getContext();
for (Map.Entry<String, Object> entry : map.entrySet()) {
context.put(entry.getKey(), entry.getValue());
res = true;
}
return res;
}
}

View File

@@ -0,0 +1,83 @@
package com.schisandra.core.entity;
import com.schisandra.core.utils.PrimitiveTypeUtils;
import lombok.Data;
import org.apache.velocity.VelocityContext;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* 自定义上下文
*
* @author loser
* @date 2023/9/4
*/
@Data
public class Context implements Cloneable {
private VelocityContext context = new VelocityContext();
public VelocityContext get() {
for (Map.Entry<String, Object> entry : contexts.entrySet()) {
context.put(entry.getKey(), entry.getValue());
}
return context;
}
private Map<String, Object> contexts = new ConcurrentHashMap<>();
public void put(String key, Object obj) {
contexts.put(key, obj);
}
public void remove(String key) {
contexts.remove(key);
}
public void put(Object obj) {
if (PrimitiveTypeUtils.isPrimitive(obj)) {
return;
}
Class<?> aClass = obj.getClass();
Field[] fields = aClass.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
Object value = field.get(obj);
put(field.getName(), value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void removeObj(Object obj) {
if (PrimitiveTypeUtils.isPrimitive(obj)) {
return;
}
Class<?> aClass = obj.getClass();
Field[] fields = aClass.getDeclaredFields();
for (Field field : fields) {
String name = field.getName();
remove(name);
}
}
@Override
public Context clone() {
try {
Context clone = (Context) super.clone();
// TODO: copy mutable state here, so the clone can't change the internals of the original
return clone;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}

View File

@@ -0,0 +1,25 @@
package com.schisandra.core.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 数据库配置
*
* @author loser
* @date 2023/9/4
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JdbcConfig {
private String url;
private String username;
private String password;
private String dbName;
private String driver;
private String tableName;
}

View File

@@ -0,0 +1,43 @@
package com.schisandra.core.entity;
import lombok.Data;
/**
* 映射关系
*
* @author loser
* @date 2023/9/4
*/
@Data
public class Mapper {
/**
* 生成文件的id
*/
private String fileId;
/**
* 模板地址
*/
private String template;
/**
* 生成类包名称 可使用占位符 ${}
*/
private String packageName;
/**
* 生成文件的路径 没有指定则用 packageName 进行替换处理 可使用占位符 ${}
*/
private String filePath;
/**
* 生成文件的名称 可使用占位符 ${}
*/
private String name;
/**
* 生成文件的扩展名
*/
private String ext;
}

View File

@@ -0,0 +1,47 @@
package com.schisandra.core.entity;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.apache.velocity.VelocityContext;
import java.util.HashMap;
import java.util.Map;
/**
* 映射关系包裹对象
*
* @author loser
* @date 2023/9/4
*/
@Data
public class MapperInfo {
/**
* 文件id用于自定义忘 context 中存入自己特有的信息
*/
private String fileId;
/**
* 模板路径
*/
private String templatePath;
/**
* 生成文件路径
*/
private String outPutPath;
/**
* 每个文件自个持有的上下文 包含全局的上下文数据
*/
private VelocityContext context;
@Override
public String toString() {
Map<String, Object> res = new HashMap<>();
res.put("fileId", fileId);
res.put("templatePath", templatePath);
res.put("outPutPath", outPutPath);
return JSONObject.toJSONString(res);
}
}

View File

@@ -0,0 +1,65 @@
package com.schisandra.core.entity;
import cn.hutool.core.util.StrUtil;
import com.schisandra.core.utils.MySQLToJavaTypeConverter;
import com.schisandra.core.utils.MySQLToMyBatisTypeConverter;
import lombok.Data;
import org.springframework.util.StringUtils;
/**
* 表信息
*
* @author loser
* @date 2023/9/4
*/
@Data
public class TableInfo {
// 字段索引类型
private String keyType;
private String col;
private String name;
private String upName;
private String comment;
private String dataType;
private String tableComment;
// 转化为java中的数据类型
private String type;
// 转为mybatis中的数据类型
private String myBatisType;
public String getMyBatisType() {
if (StrUtil.isNotEmpty(myBatisType)) {
return myBatisType;
}
return MySQLToMyBatisTypeConverter.convert(dataType);
}
public String getUpName() {
return StrUtil.upperFirst(name);
}
public String getType() {
if (StrUtil.isNotEmpty(type)) {
return type;
}
return MySQLToJavaTypeConverter.convert(dataType).getType();
}
public MySQLToJavaTypeConverter.Item getTypeInfo() {
return MySQLToJavaTypeConverter.convert(dataType);
}
public MySQLToJavaTypeConverter.Item getTypeInfo(String type) {
return MySQLToJavaTypeConverter.trans(type);
}
public String getComment() {
if (StringUtils.isEmpty(comment)) {
return "";
}
return comment.trim().replace("\n" , "");
}
}

View File

@@ -0,0 +1,46 @@
package com.schisandra.core.utils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 使用velocity生成文件
*
* @author loser
* @date 2023/9/4
*/
public class CodeGeneratorUtils {
private final VelocityEngine velocityEngine;
public CodeGeneratorUtils(String templateBasePath) {
this.velocityEngine = new VelocityEngine();
if (SystemUtils.isWindows()) {
this.velocityEngine.setProperty("file.resource.loader.path", templateBasePath);
}
velocityEngine.init();
}
public void generateCode(VelocityContext context, String templatePath, String outputPath, AtomicInteger count) {
Template template = velocityEngine.getTemplate(templatePath, "UTF-8");
StringWriter writer = new StringWriter();
template.merge(context, writer);
try (FileWriter fileWriter = new FileWriter(outputPath)) {
fileWriter.write(writer.toString());
System.out.println();
System.out.println("==========> " + count.getAndIncrement() + " genFile succeed : " + outputPath);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,23 @@
package com.schisandra.core.utils;
import com.schisandra.core.entity.Context;
/**
* 获取全局上下文的配置工具
*
* @author loser
* @date 2023/9/4
*/
public class ConfigUtils {
private static Context ctx = new Context();
public static Context getContext() {
return ctx;
}
public static void reSetContext(Context context) {
ctx = context;
}
}

View File

@@ -0,0 +1,27 @@
package com.schisandra.core.utils;
import com.alibaba.fastjson.JSONObject;
import com.schisandra.core.entity.Context;
import java.util.Map;
/**
* 使用json构建上下文的上下文工具
*
* @author loser
* @date 2023/9/4
*/
public class ContextUtils {
public static Context buildContext(String json) {
Context context = new Context();
JSONObject jsonObject = JSONObject.parseObject(json);
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
context.put(entry.getKey(), entry.getValue());
}
return context;
}
}

View File

@@ -0,0 +1,96 @@
package com.schisandra.core.utils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.schisandra.core.core.sdk.Function;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.MessageDigest;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
public class FunctionUtils implements Serializable {
private static final Map<String, Function> functionMap = new ConcurrentHashMap<>();
static {
register(new Function() {
@Override
public String funcKey() {
return "now()";
}
@Override
public String doFunc() {
return DateUtil.now();
}
});
register(new Function() {
@Override
public String funcKey() {
return "svUid()";
}
@Override
public String doFunc() {
try {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream objectStream = new ObjectOutputStream(byteStream);
objectStream.writeObject(RandomUtil.randomBigDecimal());
objectStream.flush();
objectStream.close();
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] byteArray = md5.digest(byteStream.toByteArray());
long serialVersionUID = 0L;
for (int i = Math.min(byteArray.length, 8) - 1; i >= 0; i--) {
serialVersionUID = (serialVersionUID << 8) | (byteArray[i] & 0xFF);
}
return Long.toString(serialVersionUID);
} catch (Exception ignore) {
}
return null;
}
});
register(new Function() {
@Override
public String funcKey() {
return "date()";
}
@Override
public String doFunc() {
return DateUtil.formatDate(DateUtil.date());
}
});
}
public static boolean isFunction(Object funKey) {
if (!(funKey instanceof String)) {
return false;
}
return functionMap.containsKey(funKey);
}
public static void register(Function function) {
functionMap.put(function.funcKey(), function);
}
public static Object doFunction(Object funKey) {
if (!(funKey instanceof String)) {
return funKey;
}
Function function = functionMap.get(funKey);
if (Objects.isNull(function)) {
return funKey;
}
return function.doFunc();
}
}

View File

@@ -0,0 +1,36 @@
package com.schisandra.core.utils;
import com.schisandra.core.core.MysqlDataHandler;
import com.schisandra.core.entity.JdbcConfig;
import com.schisandra.core.entity.TableInfo;
import java.util.List;
/**
* jdbc工具 用于查询表字段信息 及 表结构信息
*
* @author loser
* @date 2023/9/4
*/
public class JdbcUtil {
private JdbcUtil() {
}
public static List<TableInfo> queryTableInfo(JdbcConfig config, String table) {
return new MysqlDataHandler(table, config.getUrl(), config.getUsername(),
config.getPassword(), config.getDbName(), config.getDriver())
.searchByDb();
}
public static String getComment(JdbcConfig config, String table) {
return new MysqlDataHandler(table, config.getUrl(), config.getUsername(),
config.getPassword(), config.getDbName(), config.getDriver())
.getTableComment();
}
}

View File

@@ -0,0 +1,18 @@
package com.schisandra.core.utils;
import java.util.ArrayList;
import java.util.List;
/**
* 集合类
*
* @author loser
* @date 2023/9/4
*/
public class Lists {
public static List<Object> newArrayList() {
return new ArrayList<>();
}
}

View File

@@ -0,0 +1,64 @@
package com.schisandra.core.utils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* mysql转java转换器
*
* @author loser
* @date 2023/9/4
*/
public class MySQLToJavaTypeConverter {
private static final Map<String, Item> typeMap = new HashMap<>();
static {
typeMap.put("tinyint", new Item(false, "Integer"));
typeMap.put("smallint", new Item(false, "Short"));
typeMap.put("mediumint", new Item(false, "Integer"));
typeMap.put("int", new Item(false, "Integer"));
typeMap.put("bigint", new Item(false, "Long"));
typeMap.put("float", new Item(false, "Float"));
typeMap.put("double", new Item(false, "Double"));
typeMap.put("char", new Item(false, "String"));
typeMap.put("varchar", new Item(false, "String"));
typeMap.put("text", new Item(false, "String"));
typeMap.put("longtext", new Item(false, "String"));
typeMap.put("blob", new Item(false, "Byte"));
typeMap.put("decimal", new Item(true, "BigDecimal"));
typeMap.put("date", new Item(true, "Date"));
typeMap.put("time", new Item(true, "Date"));
typeMap.put("datetime", new Item(true, "Date"));
typeMap.put("timestamp", new Item(true, "Date"));
}
public static Item convert(String mysqlType) {
Item item = typeMap.get(mysqlType.toLowerCase());
if (Objects.isNull(item)) {
return new Item(false, mysqlType);
}
return item;
}
public static Item trans(String type) {
for (Item value : typeMap.values()) {
if (value.type.equals(type)) {
return value;
}
}
return new Item(false, type);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Item {
private boolean flag;
private String type;
}
}

View File

@@ -0,0 +1,33 @@
package com.schisandra.core.utils;
import java.util.HashMap;
import java.util.Map;
public class MySQLToMyBatisTypeConverter {
private static final Map<String, String> typeMap = new HashMap<>();
static {
// 添加MySQL数据类型到MyBatis数据类型的映射关系
typeMap.put("VARCHAR", "VARCHAR");
typeMap.put("CHAR", "CHAR");
typeMap.put("TEXT", "VARCHAR");
typeMap.put("LONGTEXT", "VARCHAR");
typeMap.put("INT", "INTEGER");
typeMap.put("TINYINT", "TINYINT");
typeMap.put("SMALLINT", "SMALLINT");
typeMap.put("MEDIUMINT", "INTEGER");
typeMap.put("BIGINT", "BIGINT");
typeMap.put("FLOAT", "REAL");
typeMap.put("DOUBLE", "DOUBLE");
typeMap.put("DECIMAL", "DECIMAL");
typeMap.put("DATE", "DATE");
typeMap.put("TIME", "TIME");
typeMap.put("DATETIME", "TIMESTAMP");
typeMap.put("TIMESTAMP", "TIMESTAMP");
typeMap.put("YEAR", "DATE");
}
public static String convert(String mysqlType) {
return typeMap.getOrDefault(mysqlType.toUpperCase(), "VARCHAR");
}
}

View File

@@ -0,0 +1,21 @@
package com.schisandra.core.utils;
/**
* 判断是否是基本类型工具类
*
* @author loser
* @date 2023/9/4
*/
public class PrimitiveTypeUtils {
public static boolean isPrimitive(Object obj) {
return obj instanceof Integer ||
obj instanceof Long ||
obj instanceof Float ||
obj instanceof Double ||
obj instanceof Boolean ||
obj instanceof Character ||
obj instanceof Byte;
}
}

View File

@@ -0,0 +1,49 @@
package com.schisandra.core.utils;
public class SystemUtils {
/**
* 判断操作系统是否是 Windows
*
* @return true操作系统是 Windows
* false其它操作系统
*/
public static boolean isWindows() {
String osName = getOsName();
return osName != null && osName.startsWith("Windows");
}
/**
* 判断操作系统是否是 MacOS
*
* @return true操作系统是 MacOS
* false其它操作系统
*/
public static boolean isMacOs() {
String osName = getOsName();
return osName != null && osName.startsWith("Mac");
}
/**
* 判断操作系统是否是 Linux
*
* @return true操作系统是 Linux
* false其它操作系统
*/
public static boolean isLinux() {
String osName = getOsName();
return (osName != null && osName.startsWith("Linux")) || (!isWindows() && !isMacOs());
}
/**
* 获取操作系统名称
*
* @return os.name 属性值
*/
public static String getOsName() {
return System.getProperty("os.name");
}
}

View File

@@ -0,0 +1,46 @@
package com.schisandra.core.utils;
import com.schisandra.core.anno.Table;
import com.schisandra.core.entity.TableInfo;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
public class TableUtils {
private TableUtils() {
}
public static String getComment(Class<?> clazz) {
Table table = clazz.getAnnotation(Table.class);
if (Objects.isNull(table)) {
return "";
}
return table.value();
}
public static List<TableInfo> build(Class<?> clazz) {
String comment = getComment(clazz);
return Arrays.stream(clazz.getDeclaredFields()).filter(item -> {
Table table = item.getAnnotation(Table.class);
return Objects.nonNull(table);
}).map(item -> {
Table table = item.getAnnotation(Table.class);
TableInfo info = new TableInfo();
info.setKeyType(table.keyType());
info.setCol(table.col());
info.setTableComment(comment);
info.setType(table.jdbcType());
info.setMyBatisType(table.myBatisType());
info.setName(item.getName());
info.setComment(table.value());
info.setDataType(item.getType().getSimpleName());
return info;
}).collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,31 @@
package com.schisandra.core.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.schisandra.core.core.CodeGenerationCode;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
/**
* yml 转对象工具类
*
* @author loser
* @date 2023/9/4
*/
public class YamlUtils {
private static final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
public static <T> T loadYaml(String filePath, Class<T> valueType) {
try {
ClassLoader classLoader = CodeGenerationCode.class.getClassLoader();
URL resource = classLoader.getResource(filePath);
InputStream inputStream = resource.openStream();
return objectMapper.readValue(inputStream, valueType);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,44 @@
{
"fields": [
{
"type": "int",
"name": "Element1"
},
{
"type": "boolean",
"name": "Element2"
},
{
"type": "byte",
"name": "Element3"
},
{
"type": "double",
"name": "Element4"
},
{
"type": "float",
"name": "Element5"
},
{
"type": "short",
"name": "Element6"
},
{
"type": "int",
"name": "Element7"
},
{
"type": "char",
"name": "Element8"
},
{
"type": "boolean",
"name": "Element9"
},
{
"type": "long",
"name": "Element10"
}
]
}

View File

@@ -0,0 +1,28 @@
# 01 数据源输入 填充到全局的context中
# 1.1 通过指定类的返回值写入 (优先级第一)
#handler: com.loser.core.impl.JdbcPutContextHandler
# 1.2 直接从classPath中引入一个json数据 可配合 mapperInfos 替换模板 (优先级第二)
json: genCode/fields.json
# 1.3 配置数据库信息从表字段中获取数据 (优先级第三)
#jdbc:
# url: jdbc:mysql://119.91.155.174:3306/
# username: root
# password: 6666888123
# dbName: ape
# driver: com.mysql.cj.jdbc.Driver
# tableName: sys_user
# 02 模板与生成类的映射关系 通过修改该配置 切换不同的生成模板 比如从基础的crud代码模板 切换到 rpc代码模板等
mapperInfos: genCode/mapper.yml
# 03 针对某个生成文件写入独有上下文 通过 mapper.yml > mappers > fileId 关联
#filePutHandler: com.loser.core.impl.DemoFilePutContextHandler
# 04 全局上下文参数
params:
pre: Loser
module: test
author: loser
# 内置函数:now()-获取当前时间;date()-获取当前时间不带时分秒;svUid()-生成序列化ID;
# 扩展新的函数 则在调用生成方法前 使用 FunctionUtils.register(Function function)
date: now()

View File

@@ -0,0 +1,74 @@
# 生成到当前项目的那个子模块,没有则配置 /
module: /ape-demo/
# 模板文件和生成类的映射关系 多个文件 数组形式配置
mappers:
-
- fileId: 001
template: genCode/template/ReqAndRespTemplate.java.vm
# 生成到 src.main.java 下的对应包中
packageName: com.loser.user.${module}.vo.resp
name: ${pre}InfoResp
ext: java
# fileId 用于实现 FilePutContextHandler 接口时 忘对应文件的上下文补充数据
- fileId: 002
template: genCode/template/ReqAndRespTemplate.java.vm
# 优先级比 packageName 使用场景为需要指定目录的文件比如resources下的 mapper 文件等
filePath: src/main/resources/${module}/template
name: ${pre}InfoResp
ext: java.vm
- fileId: 003
template: genCode/template/EntityTemplate.java.vm
packageName: com.loser.user.${module}.entity
name: ${pre}
ext: java
- fileId: 004
template: genCode/template/ReqAndRespTemplate.java.vm
packageName: com.loser.user.${module}.vo.req
name: ${pre}Req
ext: java
- fileId: 005
template: genCode/template/ReqAndRespTemplate.java.vm
packageName: com.loser.user.${module}.vo.resp
name: ${pre}Resp
ext: java
- fileId: 006
template: genCode/template/ServiceTemplate.java.vm
packageName: com.loser.user.${module}.service
name: ${pre}Service
ext: java
- fileId: 007
template: genCode/template/ServiceImplTemplate.java.vm
packageName: com.loser.user.${module}.service.impl
name: ${pre}ServiceImpl
ext: java
- fileId: 008
template: genCode/template/HandlerTemplate.java.vm
packageName: com.loser.user.${module}.handler
name: ${pre}Handler
ext: java
- fileId: 009
template: genCode/template/PageReqTemplate.java.vm
packageName: com.loser.user.${module}.vo.req
name: ${pre}PageReq
ext: java
- fileId: 010
template: genCode/template/ReqAndRespTemplate.java.vm
packageName: com.loser.user.${module}.vo.req
name: ${pre}SaveReq
ext: java
- fileId: 011
template: genCode/template/ReqAndRespTemplate.java.vm
packageName: com.loser.user.${module}.vo.req
name: ${pre}UpdateReq
ext: java

View File

@@ -0,0 +1,19 @@
package ${packageName};
#if($importDate)
import java.util.Date;
#end
/**
* ${tableComment}实体
*
* @author ${author}
* @date ${date}
*/
public class ${className} {
#foreach($field in $fields)
private $field.type $field.name;
#end
}

View File

@@ -0,0 +1,84 @@
package ${packageName};
import com.loser.bean.Result;
import com.loser.user.mongo.ParamsUtil;
import com.loser.user.${module}.entity.${pre};
import com.loser.user.${module}.service.${pre}Service;
import com.loser.user.${module}.vo.req.${pre}PageReq;
import com.loser.user.${module}.vo.req.${pre}SaveReq;
import com.loser.user.${module}.vo.req.${pre}UpdateReq;
import com.loser.user.${module}.vo.resp.${pre}InfoResp;
import com.loser.core.entity.Page;
import com.loser.core.wrapper.LambdaQueryWrapper;
import com.loser.core.wrapper.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 测试数据 处理器
*
* @author loser
* @date 2023-06-13
*/
@Component
public class ${pre}Handler {
@Autowired
private ${pre}Service ${pre}Service;
/**
* 新增测试数据
*/
public Result<Boolean> save(${pre}SaveReq req) {
${pre} save = ParamsUtil.copyProperties(req, ${pre}.class);
return Result.ok(${pre}Service.save(save));
}
/**
* 修改测试数据
*/
public Result<Boolean> update(${pre}UpdateReq req) {
${pre} update = ParamsUtil.copyProperties(req, ${pre}.class);
return Result.ok(${pre}Service.updateById(update));
}
/**
* 通过id删除测试数据
*/
public Result<Boolean> deleteById(String id) {
return Result.ok(${pre}Service.removeById(id));
}
/**
* 通过id获取测试数据
*/
public Result<${pre}InfoResp> getById(String id) {
${pre} dbData = ${pre}Service.getById(id);
if (Objects.isNull(dbData)) {
return Result.ok();
}
return Result.ok(ParamsUtil.copyProperties(dbData, ${pre}InfoResp.class));
}
/**
* 分页获取测试数据
*/
public Result<Page<${pre}>> queryList(${pre}PageReq req) {
LambdaQueryWrapper<${pre}> query = Wrappers.<${pre}>lambdaQuery();
Page<${pre}> page = ${pre}Service.page(query, req.getPageNo(), req.getPageSize());
return Result.ok(page);
}
}

View File

@@ -0,0 +1,26 @@
package ${packageName};
#if($importDate)
import java.util.Date;
#end
import lombok.Data;
/**
* ${tableComment}实体
*
* @author ${author}
* @date ${date}
*/
@Data
public class ${className} {
private Integer pageNo = 1;
private Integer pageSize = 20;
#foreach($field in $fields)
private $field.type $field.name;
#end
}

View File

@@ -0,0 +1,21 @@
package ${packageName};
#if($importDate)
import java.util.Date;
#end
import lombok.Data;
/**
* ${tableComment}试图
*
* @author ${author}
* @date ${date}
*/
@Data
public class $className {
#foreach($field in $fields)
private $field.type $field.name;
#end
}

View File

@@ -0,0 +1,11 @@
package ${packageName};
import com.loser.user.${module}.entity.${pre};
import com.loser.user.${module}.service.${pre}Service;
import com.loser.core.impl.EasyMongoServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class ${pre}ServiceImpl extends EasyMongoServiceImpl<String, ${pre}> implements ${pre}Service {
}

View File

@@ -0,0 +1,8 @@
package ${packageName};
import com.loser.user.${module}.entity.${pre};
import com.loser.core.sdk.EasyMongoService;
public interface ${pre}Service extends EasyMongoService<String, ${pre}> {
}

View File

@@ -0,0 +1,44 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.schisandra</groupId>
<artifactId>schisandra-cloud-storage-common-starter</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>schisandra-cloud-storage-common-starter</name>
<modules>
<module>easy-gen-code-spring-boot-starter</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@@ -7,7 +7,7 @@ import org.springframework.context.annotation.ComponentScan;
/**
* 网关启动类
*
* @author: landaiqing
* @author: schisandra
* @date: 2024/2/7
*/
@SpringBootApplication

View File

@@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration;
/**
* 权限认证的配置器
*
* @author: landaiqing
* @author: schisandra
*/
@Configuration
public class SaTokenConfigure {

View File

@@ -18,7 +18,7 @@ import java.util.stream.Collectors;
/**
* 自定义权限验证接口扩展
*
* @author: landaiqing
* @author: schisandra
*/
@Component
public class StpInterfaceImpl implements StpInterface {

View File

@@ -8,7 +8,7 @@ import java.util.Date;
/**
* (AuthPermission)实体类
*
* @author landaiqing
* @author schisandra
*/
@Data
public class AuthPermission implements Serializable {

View File

@@ -8,7 +8,7 @@ import java.util.Date;
/**
* (AuthRole)实体类
*
* @author landaiqing
* @author schisandra
* @since 2024-2-18 18:55:50
*/
@Data

View File

@@ -15,9 +15,9 @@ import reactor.core.publisher.Mono;
/**
* @Classname GatewayExceptionHandler
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.club.gateway.exception
* @Author: landaiqing
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.club.gateway.exception
* @Author: schisandra
* @CreateTime: 2024-05-18 17:52
* @Description: 网关全局异常处理
* @Version: 1.0

View File

@@ -14,9 +14,9 @@ import reactor.core.publisher.Mono;
/**
* @Classname LoginFilter
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.club.gateway.filter
* @Author: landaiqing
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.club.gateway.filter
* @Author: schisandra
* @CreateTime: 2024-03-03 17:41
* @Description: 登录拦截器
* @Version: 1.0

View File

@@ -15,9 +15,9 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @Classname RedisConfig
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.club.gateway.redis
* @Author: landaiqing
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.club.gateway.redis
* @Author: schisandra
* @CreateTime: 2024-02-18 18:10
* @Description: redis的config处理
* @Version: 1.0

View File

@@ -13,7 +13,7 @@ import java.util.stream.Stream;
/**
* RedisUtil工具类
*
* @author: landaiqing
* @author: schisandra
* @date: 2024/2/19
*/
@Component

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.schisandra</groupId>
<artifactId>schisandra-cloud-storage-gen</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>schisandra-cloud-storage-gen</name>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.schisandra</groupId>
<artifactId>easy-gen-code-spring-boot-starter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,58 @@
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.schisandra.core.config.GenConfig;
import com.schisandra.core.config.MapperConfig;
import com.schisandra.core.core.sdk.PostCurFiledContextAware;
import com.schisandra.core.entity.TableInfo;
import com.schisandra.core.utils.MySQLToJavaTypeConverter;
import org.apache.velocity.VelocityContext;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BizPutContextHandler implements PostCurFiledContextAware {
public static String underlineToHump(String str, boolean removePre) {
if (removePre) {
str = str.substring(str.indexOf("_"));
}
str = str.toLowerCase();
Pattern compile = Pattern.compile("_[a-z]");
Matcher matcher = compile.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group(0).toUpperCase().replace("_", ""));
}
matcher.appendTail(sb);
return StrUtil.upperFirst(sb.toString());
}
private static String convert(String str) {
if (str == null || str.isEmpty()) {
return str;
}
char firstChar = str.charAt(0);
char lowerFirstChar = Character.toLowerCase(firstChar);
return lowerFirstChar + str.substring(1);
}
@Override
public void doAware(GenConfig genConfig, MapperConfig mapperConfig, VelocityContext context) {
// 处理导包标志位
List<TableInfo> files = JSONObject.parseArray(JSONObject.toJSONString(context.get("fields")), TableInfo.class);
for (TableInfo tableInfo : files) {
MySQLToJavaTypeConverter.Item typeInfo = tableInfo.getTypeInfo(tableInfo.getType());
if (typeInfo.isFlag()) {
context.put("import" + typeInfo.getType(), true);
}
}
context.put("modelName", underlineToHump(genConfig.getJdbc().getTableName(), Convert.toBool(context.get("removePre"))));
context.put("_modelName", convert(context.get("modelName").toString()));
context.put("tableName", genConfig.getJdbc().getTableName());
}
}

View File

@@ -0,0 +1,9 @@
import com.schisandra.core.core.CodeGenerationCode;
public class GenCodeMain {
public static void main(String[] args) {
CodeGenerationCode.doGenCode(new BizPutContextHandler());
}
}

View File

@@ -0,0 +1,69 @@
# auth模块映射关系 ${module} 占位符
# 模板文件和生成类的映射关系 多个文件 数组形式配置
mappers:
-
- fileId: 001
template: genCode/template/DemoDTO.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-application/schisandra-cloud-storage-${module}-application-controller/src/main/java/com/schisandra/${module}/application/dto
name: ${modelName}DTO
ext: java
- fileId: 002
template: genCode/template/DemoController.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-application/schisandra-cloud-storage-${module}-application-controller/src/main/java/com/schisandra/${module}/application/controller
name: ${modelName}Controller
ext: java
- fileId: 003
template: genCode/template/DemoDTOConverter.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-application/schisandra-cloud-storage-${module}-application-controller/src/main/java/com/schisandra/${module}/application/convert
name: ${modelName}DTOConverter
ext: java
- fileId: 004
template: genCode/template/DemoBO.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-domain/src/main/java/com/schisandra/${module}/domain/entity
name: ${modelName}BO
ext: java
- fileId: 005
template: genCode/template/DemoDomainService.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-domain/src/main/java/com/schisandra/${module}/domain/service
name: ${modelName}DomainService
ext: java
- fileId: 006
template: genCode/template/DemoDomainServiceImpl.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-domain/src/main/java/com/schisandra/${module}/domain/service/impl
name: ${modelName}DomainServiceImpl
ext: java
- fileId: 007
template: genCode/template/DemoBOConverter.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-domain/src/main/java/com/schisandra/${module}/domain/convert
name: ${modelName}BOConverter
ext: java
- fileId: 008
template: genCode/template/DemoService.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-infra/src/main/java/com/schisandra/${module}/infra/basic/service
name: ${modelName}Service
ext: java
- fileId: 009
template: genCode/template/DemoTable.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-infra/src/main/java/com/schisandra/${module}/infra/basic/entity
name: ${modelName}
ext: java
- fileId: 010
template: genCode/template/DemoServiceImpl.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-infra/src/main/java/com/schisandra/${module}/infra/basic/service/impl
name: ${modelName}ServiceImpl
ext: java
- fileId: 011
template: genCode/template/DemoDao.java.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-infra/src/main/java/com/schisandra/${module}/infra/basic/mapper
name: ${modelName}Dao
ext: java
- fileId: 012
template: genCode/template/DemoXml.xml.vm
filePath: /schisandra-cloud-storage-${module}/schisandra-cloud-storage-${module}-infra/src/main/resources/mapper
name: ${modelName}Dao
ext: xml

View File

@@ -0,0 +1,33 @@
# 使用步骤
# 01 替换数据库连接信息及对应表 jdbc:*
# 02 替换模板映射关系 mapperInfos
# 03 替换作者信息 params:loser
# 04 替换模块 params:module
# 05 替换 controller 前缀 params:api
# 数据库连接信息
jdbc:
dbName: schisandra-cloud-storage
tableName: subject_liked
url: jdbc:mysql://1.95.0.111:3306/
username: schisandra
password: LDQ20020618xxx
driver: com.mysql.cj.jdbc.Driver
# 使用的模板与生成文件映射给关系
mapperInfos: genCode/subjectLikedMapper.yml
# 全局参数
params:
# 作者
author: schisandra
# 模块
module: subject
# controller 通用前缀
api: /subjectLiked
# 生成对象是否移除前缀
removePre: false
# 使用内置函数赋值给变量 FunctionUtils 中替换
genDate: now()
# win 需要补充模板具体目录
templateBasePath: E:/JavaProjects_IDEA/schisandra-cloud-storage/schisandra-cloud-storage-gen/src/main/resources/

View File

@@ -0,0 +1,24 @@
package com.schisandra.${module}.domain.entity;
import lombok.Data;
import java.io.Serializable;
/**
* ${tableComment} bo
*
* @author ${author}
* @since ${genDate}
*/
@Data
public class ${modelName}BO implements Serializable {
#foreach($field in $fields)
/**
* ${field.comment}
*/
private $field.type $field.name;
#end
}

Some files were not shown because too many files have changed in this diff Show More