review code.

This commit is contained in:
lijiahang
2023-07-16 22:58:49 +08:00
parent 462cd81865
commit 90b9dba7ed
38 changed files with 431 additions and 165 deletions

View File

@@ -12,6 +12,11 @@ public class Const implements com.orion.lang.constant.Const {
private Const() {
}
/**
* 同 ${orion.version} 迭代时候需要手动更改
*/
public static String VERSION = "1.0.0";
public static final Integer NOT_DELETE = 0;
public static final Integer IS_DELETED = 1;

View File

@@ -3,6 +3,7 @@ package com.orion.ops.framework.common.constant;
import com.orion.lang.define.wrapper.CodeInfo;
import com.orion.lang.define.wrapper.HttpWrapper;
import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Strings;
/**
* 错误码
@@ -36,39 +37,43 @@ public enum ErrorCode implements CodeInfo {
INTERNAL_SERVER_ERROR(500, "系统异常"),
// -------------------- 自定义 --------------------
// -------------------- 自定义 - 业务 --------------------
NETWORK_FLUCTUATION(700, "当前环境网路波动"),
OTHER_DEVICE_LOGIN(700, "该账号于 {} 已在其他设备登陆 {}({})"),
HTTP_API(701, "api 调用异常"),
// -------------------- 自定义 - 通用 --------------------
IO_EXCEPTION(702, "网络异常"),
NETWORK_FLUCTUATION(900, "当前环境网路波动"),
SQL_EXCEPTION(703, "数据异常"),
HTTP_API(901, "api 调用异常"),
SFTP_EXCEPTION(704, "操作失败"),
IO_EXCEPTION(902, "网络异常"),
EXCEL_PASSWORD_ERROR(705, "文档密码错误"),
SQL_EXCEPTION(903, "数据异常"),
PASER_FAILED(706, "解析失败"),
SFTP_EXCEPTION(904, "操作失败"),
ENCRYPT_ERROR(707, "数据加密异常"),
EXCEL_PASSWORD_ERROR(905, "文档密码错误"),
DECRYPT_ERROR(708, "数据解密异常"),
PASER_FAILED(906, "解析失败"),
EXPRESSION_ERROR(709, "表达式错误"),
ENCRYPT_ERROR(907, "数据加密异常"),
TASK_EXECUTE_ERROR(710, "任务执行异常"),
DECRYPT_ERROR(908, "数据解密异常"),
CONNECT_ERROR(711, "建立连接失败"),
EXPRESSION_ERROR(909, "表达式错误"),
INTERRUPT_ERROR(712, "操作中断"),
TASK_EXECUTE_ERROR(910, "任务执行异常"),
UNSAFE_OPERATOR(713, "不安全的操作"),
CONNECT_ERROR(911, "建立连接失败"),
VCS_OPETATOR_ERROR(714, "仓库操作执行失败"),
INTERRUPT_ERROR(912, "操作中断"),
DIABLED_ERROR(715, "数据已被禁用"),
UNSAFE_OPERATOR(913, "不安全的操作"),
VCS_OPETATOR_ERROR(914, "仓库操作执行失败"),
DIABLED_ERROR(915, "数据已被禁用"),
;
@@ -135,4 +140,12 @@ public enum ErrorCode implements CodeInfo {
return Exceptions.httpWrapper(this);
}
/**
* @param params 错误信息参数
* @return 获取异常
*/
public RuntimeException exception(Object... params) {
return Exceptions.httpWrapper(this.toHttpWrapper().msg(Strings.format(this.message, params)));
}
}

View File

@@ -39,10 +39,10 @@ public class CodeGenerator {
@NotNull
String author = Const.ORION_AUTHOR;
@NotEmpty
String[] tables = {"system_role", "system_user_role", "system_menu", "system_role_menu"};
String[] tables = {"system_user", "system_role", "system_user_role", "system_menu", "system_role_menu"};
// 表业务注释 需要和表一一对应 null则为表注释
@NotEmpty
String[] comment = {"角色", "用户角色关联", "菜单", "角色菜单关联"};
String[] comment = {"用户", "角色", "用户角色关联", "菜单", "角色菜单关联"};
// 模块
@NotNull
String module = "infra";

View File

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
import com.orion.lang.utils.Strings;
import com.orion.ops.framework.common.constant.Const;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
@@ -135,6 +136,8 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
// http 注释标识
objectMap.put("httpComment", "###");
// 版本
objectMap.put("since", Const.VERSION);
// 实体名称
String domainName = tableInfo.getEntityName();

View File

@@ -24,7 +24,7 @@ import java.util.List;
* $!{table.comment} api
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Tag(name = "${package.ModuleName} - $!{table.comment}服务")

View File

@@ -12,7 +12,7 @@ import java.util.List;
* $!{table.comment} 暴露服务转换器
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Mapper

View File

@@ -12,7 +12,7 @@ import java.util.List;
* $!{table.comment} 内部对象转换器
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Mapper

View File

@@ -11,7 +11,7 @@ import java.util.*;
* $!{table.comment} 实体对象
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Data

View File

@@ -10,7 +10,7 @@ import java.util.*;
* $!{table.comment} 业务对象
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Data

View File

@@ -16,7 +16,7 @@ import java.util.*;
* $!{table.comment} 创建请求对象
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Data

View File

@@ -11,7 +11,7 @@ import java.util.*;
* $!{table.comment} 查询请求对象
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Data

View File

@@ -16,7 +16,7 @@ import java.util.*;
* $!{table.comment} 更新请求对象
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Data

View File

@@ -10,7 +10,7 @@ import java.util.*;
* $!{table.comment} 视图响应对象
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Data

View File

@@ -1,5 +1,6 @@
package ${package.Mapper};
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import ${package.Entity}.${entity};
import ${superMapperClassPackage};
#if(${mapperAnnotationClass})
@@ -10,7 +11,7 @@ import ${mapperAnnotationClass.name};
* $!{table.comment} Mapper 接口
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
#if(${mapperAnnotationClass})
@@ -18,4 +19,17 @@ import ${mapperAnnotationClass.name};
#end
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
/**
* 获取全部条件
*
* @param entity entity
* @return 全部条件
*/
default LambdaQueryWrapper<${entity}> condition(${entity} entity) {
return this.wrapper()
#foreach($field in ${table.fields})
.eq(${type}DO::get${field.capitalName}, entity.get${field.capitalName}())#if(!$foreach.hasNext);#end
#end
}
}

View File

@@ -22,7 +22,7 @@ import java.util.List;
* $!{table.comment} 服务实现类
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
@Slf4j
@@ -37,24 +37,27 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
// 转换
${type}DO record = ${type}Convert.MAPPER.to(request);
record.setId(null);
// 查询是否存在
// 查询数据是否冲突
this.check${type}Present(record);
// 插入
int effect = ${typeLower}DAO.insert(record);
log.info("${type}Service-create${type} effect: {}, domain: {}", effect, JSON.toJSONString(record));
log.info("${type}Service-create${type} effect: {}, record: {}", effect, JSON.toJSONString(record));
return record.getId();
}
@Override
public Integer update${type}(${type}UpdateRequest request) {
// 查询
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
${type}DO record = ${typeLower}DAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
${type}DO record = ${type}Convert.MAPPER.to(request);
Valid.notNull(record.getId(), ErrorMessage.ID_MISSING);
// 查询是否存在
this.check${type}Present(record);
${type}DO updateRecord = ${type}Convert.MAPPER.to(request);
// 查询数据是否冲突
this.check${type}Present(updateRecord);
// 更新
int effect = ${typeLower}DAO.updateById(record);
log.info("${type}Service-update${type} effect: {}, domain: {}", effect, JSON.toJSONString(record));
int effect = ${typeLower}DAO.updateById(updateRecord);
log.info("${type}Service-update${type} effect: {}, updateRecord: {}", effect, JSON.toJSONString(updateRecord));
return effect;
}
@@ -83,8 +86,9 @@ public class ${table.serviceImplName} implements ${table.serviceName} {
// 构造条件
LambdaQueryWrapper<${type}DO> wrapper = ${typeLower}DAO.wrapper()
#foreach($field in ${table.fields})
.eq(${type}DO::get${field.capitalName}, request.get${field.capitalName}())#if(!$foreach.hasNext);#end
.eq(${type}DO::get${field.capitalName}, request.get${field.capitalName}())
#end
.orderByDesc(${type}DO::getId);
// 查询
return ${typeLower}DAO.of()
.wrapper(wrapper)

View File

@@ -11,7 +11,7 @@ import java.util.List;
* $!{table.comment} 服务类
*
* @author ${author}
* @version 1.0.0
* @version ${since}
* @since ${date}
*/
public interface ${table.serviceName} {