1. 新增业务流程任务表单可配置自定义路由表单选项
fix: 1. 修复 mysql 脚本部分字段未同步脚本的错误 2. 角色为空无法登录系统 3. 主子表缩写命名下代码生成器错误
This commit is contained in:
@@ -83,7 +83,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode BUSINESS_FILE_NOT_EXISTS = new ErrorCode(1_002_201_010, "业务附件关联不存在");
|
||||
|
||||
// ========== 数据命名与简写标准 ==========
|
||||
ErrorCode STD_NMS_NOT_EXISTS = new ErrorCode(1_002_030_000, "数据命名与简写标准不存在");
|
||||
ErrorCode STANDARD_NAME_NOT_EXISTS = new ErrorCode(1_002_030_000, "数据命名与简写标准不存在");
|
||||
|
||||
ErrorCode STD_ABBR_NOT_EXISTS = new ErrorCode(1_002_030_001, "字段名 {} 不存在命名规范定义,请核对字段定义");
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.api.stdnms;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.api.stdnms.dto.StdNmsRespDTO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO;
|
||||
import cn.iocoder.yudao.module.infra.stdnms.StdNmsService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 API 实现
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||
@Validated
|
||||
public class StdNmsApiImpl implements StdNmsApi {
|
||||
|
||||
@Resource
|
||||
private StdNmsService stdNmsService;
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> deleteStdNms(Long id) {
|
||||
stdNmsService.deleteStdNms(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> deleteStdNmsList(List<Long> ids) {
|
||||
stdNmsService.deleteStdNmsListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<StdNmsRespDTO> getStdNms(Long id) {
|
||||
StdNmsDO stdNms = stdNmsService.getStdNms(id);
|
||||
return success(BeanUtils.toBean(stdNms, StdNmsRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<StdNmsRespDTO> getStdNmsByAbbr(String abbr) {
|
||||
StdNmsDO stdNms = stdNmsService.getStdNmsByAbbr(abbr);
|
||||
return success(BeanUtils.toBean(stdNms, StdNmsRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<StdNmsRespDTO>> getStdNmsListByAbbrs(Collection<String> abbrs) {
|
||||
List<StdNmsDO> stdNmsList = stdNmsService.getStdNmsListByAbbrs(abbrs);
|
||||
return success(BeanUtils.toBean(stdNmsList, StdNmsRespDTO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.codegen.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 基于数据库的表结构,创建代码生成器的表和字段定义 Request VO")
|
||||
@@ -18,4 +18,7 @@ public class CodegenCreateListReqVO {
|
||||
@NotNull(message = "表名数组不能为空")
|
||||
private List<String> tableNames;
|
||||
|
||||
@Schema(description = "是否为规范缩写定义表", example = "true")
|
||||
private Boolean isStandardized = false;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.standardname;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.*;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.standardname.StandardNameDO;
|
||||
import cn.iocoder.yudao.module.infra.service.standardname.StandardNameService;
|
||||
|
||||
@Tag(name = "管理后台 - 数据命名与简写标准")
|
||||
@RestController
|
||||
@RequestMapping("/infra/standard-name")
|
||||
@Validated
|
||||
public class StandardNameController {
|
||||
|
||||
|
||||
@Resource
|
||||
private StandardNameService standardNameService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建数据命名与简写标准")
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:create')")
|
||||
public CommonResult<StandardNameRespVO> createStandardName(@Valid @RequestBody StandardNameSaveReqVO createReqVO) {
|
||||
return success(standardNameService.createStandardName(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新数据命名与简写标准")
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:update')")
|
||||
public CommonResult<Boolean> updateStandardName(@Valid @RequestBody StandardNameSaveReqVO updateReqVO) {
|
||||
standardNameService.updateStandardName(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除数据命名与简写标准")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:delete')")
|
||||
public CommonResult<Boolean> deleteStandardName(@RequestParam("id") Long id) {
|
||||
standardNameService.deleteStandardName(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除数据命名与简写标准")
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:delete')")
|
||||
public CommonResult<Boolean> deleteStandardNameList(@RequestParam("ids") List<Long> ids) {
|
||||
standardNameService.deleteStandardNameListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得数据命名与简写标准")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:query')")
|
||||
public CommonResult<StandardNameRespVO> getStandardName(@RequestParam("id") Long id) {
|
||||
StandardNameDO standardName = standardNameService.getStandardName(id);
|
||||
return success(BeanUtils.toBean(standardName, StandardNameRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得数据命名与简写标准分页")
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:query')")
|
||||
public CommonResult<PageResult<StandardNameRespVO>> getStandardNamePage(@Valid StandardNamePageReqVO pageReqVO) {
|
||||
PageResult<StandardNameDO> pageResult = standardNameService.getStandardNamePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, StandardNameRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出数据命名与简写标准 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('infra:standard-name:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportStandardNameExcel(@Valid StandardNamePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<StandardNameDO> list = standardNameService.getStandardNamePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "数据命名与简写标准.xls", "数据", StandardNameRespVO.class,
|
||||
BeanUtils.toBean(list, StandardNameRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.standardname.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -11,16 +11,16 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||
|
||||
@Schema(description = "管理后台 - 数据命名与简写标准分页 Request VO")
|
||||
@Data
|
||||
public class StdNmsPageReqVO extends PageParam {
|
||||
public class StandardNamePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "英文")
|
||||
private String word;
|
||||
|
||||
@Schema(description = "简写")
|
||||
private String abbr;
|
||||
private String abbreviation;
|
||||
|
||||
@Schema(description = "中文意思")
|
||||
private String info;
|
||||
private String information;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.standardname.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
@@ -10,9 +10,9 @@ import java.time.LocalDateTime;
|
||||
@Schema(description = "管理后台 - 数据命名与简写标准 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class StdNmsRespVO {
|
||||
public class StandardNameRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2987")
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8832")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@@ -22,11 +22,11 @@ public class StdNmsRespVO {
|
||||
|
||||
@Schema(description = "简写", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("简写")
|
||||
private String abbr;
|
||||
private String abbreviation;
|
||||
|
||||
@Schema(description = "中文意思", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("中文意思")
|
||||
private String info;
|
||||
private String information;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo;
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.standardname.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
@@ -6,9 +6,9 @@ import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 数据命名与简写标准新增/修改 Request VO")
|
||||
@Data
|
||||
public class StdNmsSaveReqVO {
|
||||
public class StandardNameSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2987")
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "8832")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "英文", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@@ -17,10 +17,10 @@ public class StdNmsSaveReqVO {
|
||||
|
||||
@Schema(description = "简写", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "简写不能为空")
|
||||
private String abbr;
|
||||
private String abbreviation;
|
||||
|
||||
@Schema(description = "中文意思", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "中文意思不能为空")
|
||||
private String info;
|
||||
private String information;
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO;
|
||||
import cn.iocoder.yudao.module.infra.stdnms.StdNmsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 数据命名与简写标准")
|
||||
@RestController
|
||||
@RequestMapping("/infra/std-nms")
|
||||
@Validated
|
||||
public class StdNmsController {
|
||||
|
||||
@Resource
|
||||
private StdNmsService stdNmsService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建数据命名与简写标准")
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:create')")
|
||||
@TenantIgnore
|
||||
public CommonResult<Long> createStdNms(@Valid @RequestBody StdNmsSaveReqVO createReqVO) {
|
||||
try {
|
||||
return success(stdNmsService.createStdNms(createReqVO));
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
return CommonResult.customize(0L, HttpStatus.BAD_REQUEST.value(), "已存在相同含义的定义");
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新数据命名与简写标准")
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:update')")
|
||||
@TenantIgnore
|
||||
public CommonResult<Boolean> updateStdNms(@Valid @RequestBody StdNmsSaveReqVO updateReqVO) {
|
||||
try {
|
||||
stdNmsService.updateStdNms(updateReqVO);
|
||||
} catch (Exception e) {
|
||||
return CommonResult.customize(true,HttpStatus.BAD_REQUEST.value(), "已存在相同含义的定义");
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除数据命名与简写标准")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:delete')")
|
||||
@TenantIgnore
|
||||
public CommonResult<Boolean> deleteStdNms(@RequestParam("id") Long id) {
|
||||
stdNmsService.deleteStdNms(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除数据命名与简写标准")
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:delete')")
|
||||
@TenantIgnore
|
||||
public CommonResult<Boolean> deleteStdNmsList(@RequestParam("ids") List<Long> ids) {
|
||||
stdNmsService.deleteStdNmsListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得数据命名与简写标准")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:query')")
|
||||
@TenantIgnore
|
||||
public CommonResult<StdNmsRespVO> getStdNms(@RequestParam("id") Long id) {
|
||||
StdNmsDO stdNms = stdNmsService.getStdNms(id);
|
||||
return success(BeanUtils.toBean(stdNms, StdNmsRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得数据命名与简写标准分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:query')")
|
||||
@TenantIgnore
|
||||
public CommonResult<PageResult<StdNmsRespVO>> getStdNmsPage(@Valid StdNmsPageReqVO pageReqVO) {
|
||||
PageResult<StdNmsDO> pageResult = stdNmsService.getStdNmsPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, StdNmsRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出数据命名与简写标准 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:std-nms:export')")
|
||||
@TenantIgnore
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportStdNmsExcel(@Valid StdNmsPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<StdNmsDO> list = stdNmsService.getStdNmsPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "数据命名与简写标准.xls", "数据", StdNmsRespVO.class,
|
||||
BeanUtils.toBean(list, StdNmsRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.standardname;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 DO
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@TableName("infra_std_name")
|
||||
@KeySequence("infra_std_name_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||
*/
|
||||
public class StandardNameDO extends BaseDO {
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 英文
|
||||
*/
|
||||
@TableField("WORD")
|
||||
private String word;
|
||||
/**
|
||||
* 简写
|
||||
*/
|
||||
@TableField("ABBR")
|
||||
private String abbreviation;
|
||||
/**
|
||||
* 中文意思
|
||||
*/
|
||||
@TableField("INF")
|
||||
private String information;
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
/**
|
||||
* 数据命名与简写标准 DO
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@TableName("infra_std_nms")
|
||||
@KeySequence("infra_std_nms_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 支持业务基类继承:isBusiness=true 时继承 BusinessBaseDO,否则继承 BaseDO
|
||||
*/
|
||||
public class StdNmsDO extends BaseDO {
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
/**
|
||||
* 英文
|
||||
*/
|
||||
private String word;
|
||||
/**
|
||||
* 简写
|
||||
*/
|
||||
private String abbr;
|
||||
/**
|
||||
* 中文意思
|
||||
*/
|
||||
private String info;
|
||||
/**
|
||||
* 是否删除(取消逻辑删除)
|
||||
*/
|
||||
private Boolean deleted;
|
||||
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.codegen;
|
||||
|
||||
import cn.hutool.core.lang.func.LambdaUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface CodegenTableMapper extends BaseMapperX<CodegenTableDO> {
|
||||
@@ -18,13 +23,27 @@ public interface CodegenTableMapper extends BaseMapperX<CodegenTableDO> {
|
||||
}
|
||||
|
||||
default PageResult<CodegenTableDO> selectPage(CodegenTablePageReqVO pageReqVO) {
|
||||
return selectPage(pageReqVO, new LambdaQueryWrapperX<CodegenTableDO>()
|
||||
.likeIfPresent(CodegenTableDO::getTableName, pageReqVO.getTableName())
|
||||
.likeIfPresent(CodegenTableDO::getTableComment, pageReqVO.getTableComment())
|
||||
.likeIfPresent(CodegenTableDO::getClassName, pageReqVO.getClassName())
|
||||
.betweenIfPresent(CodegenTableDO::getCreateTime, pageReqVO.getCreateTime())
|
||||
.orderByDesc(CodegenTableDO::getUpdateTime)
|
||||
);
|
||||
LambdaQueryWrapperX<CodegenTableDO> wrapper = new LambdaQueryWrapperX<>();
|
||||
|
||||
Map<String, ColumnCache> columnMap = LambdaUtils.getColumnMap(CodegenTableDO.class);
|
||||
// 大小写不敏感的 like 查询,使用动态获取的列名
|
||||
if (StringUtils.hasText(pageReqVO.getTableName())) {
|
||||
String tableNameColumn = LambdaUtil.getFieldName(CodegenTableDO::getTableName).toUpperCase();
|
||||
wrapper.apply("LOWER(" + columnMap.get(tableNameColumn).getColumn() + ") LIKE LOWER({0})", "%" + pageReqVO.getTableName() + "%");
|
||||
}
|
||||
if (StringUtils.hasText(pageReqVO.getTableComment())) {
|
||||
String tableCommentColumn = LambdaUtil.getFieldName(CodegenTableDO::getTableComment).toUpperCase();
|
||||
wrapper.apply("LOWER(" + columnMap.get(tableCommentColumn).getColumn() + ") LIKE LOWER({0})", "%" + pageReqVO.getTableComment() + "%");
|
||||
}
|
||||
if (StringUtils.hasText(pageReqVO.getClassName())) {
|
||||
String classNameColumn = LambdaUtil.getFieldName(CodegenTableDO::getClassName).toUpperCase();
|
||||
wrapper.apply("LOWER(" + columnMap.get(classNameColumn).getColumn() + ") LIKE LOWER({0})", "%" + pageReqVO.getClassName() + "%");
|
||||
}
|
||||
|
||||
wrapper.betweenIfPresent(CodegenTableDO::getCreateTime, pageReqVO.getCreateTime())
|
||||
.orderByDesc(CodegenTableDO::getUpdateTime);
|
||||
|
||||
return selectPage(pageReqVO, wrapper);
|
||||
}
|
||||
|
||||
default List<CodegenTableDO> selectListByDataSourceConfigId(Long dataSourceConfigId) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.standardname;
|
||||
|
||||
import cn.hutool.core.lang.func.LambdaUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNamePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.standardname.StandardNameDO;
|
||||
import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 Mapper
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@Mapper
|
||||
public interface StandardNameMapper extends BaseMapperX<StandardNameDO> {
|
||||
|
||||
default PageResult<StandardNameDO> selectPage(StandardNamePageReqVO reqVO) {
|
||||
LambdaQueryWrapperX<StandardNameDO> wrapper = new LambdaQueryWrapperX<>();
|
||||
|
||||
Map<String, ColumnCache> columnMap = LambdaUtils.getColumnMap(StandardNameDO.class);
|
||||
// 大小写不敏感的 like 查询,使用动态获取的列名
|
||||
if (StringUtils.hasText(reqVO.getWord())) {
|
||||
String wordColumn = LambdaUtil.getFieldName(StandardNameDO::getWord).toUpperCase();
|
||||
wrapper.apply("LOWER(" + columnMap.get(wordColumn).getColumn() + ") LIKE LOWER({0})", "%" + reqVO.getWord() + "%");
|
||||
}
|
||||
if (StringUtils.hasText(reqVO.getAbbreviation())) {
|
||||
String abbreviationColumn = LambdaUtil.getFieldName(StandardNameDO::getAbbreviation).toUpperCase();
|
||||
wrapper.apply("LOWER(" + columnMap.get(abbreviationColumn).getColumn() + ") LIKE LOWER({0})", "%" + reqVO.getAbbreviation() + "%");
|
||||
}
|
||||
if (StringUtils.hasText(reqVO.getInformation())) {
|
||||
String informationColumn = LambdaUtil.getFieldName(StandardNameDO::getInformation).toUpperCase();
|
||||
wrapper.apply("LOWER(" + columnMap.get(informationColumn).getColumn() + ") LIKE LOWER({0})", "%" + reqVO.getInformation() + "%");
|
||||
}
|
||||
|
||||
wrapper.betweenIfPresent(StandardNameDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByAsc(StandardNameDO::getWord);
|
||||
|
||||
return selectPage(reqVO, wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.mysql.stdnms;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 Mapper
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@Mapper
|
||||
public interface StdNmsMapper extends BaseMapperX<StdNmsDO> {
|
||||
|
||||
// 使用自定义 XML SQL 分页查询,word 不区分大小写
|
||||
List<StdNmsDO> selectPageCustom(StdNmsPageReqVO reqVO);
|
||||
|
||||
default PageResult<StdNmsDO> selectPage(StdNmsPageReqVO reqVO) {
|
||||
List<StdNmsDO> records = selectPageCustom(reqVO);
|
||||
// 这里只做简单封装,如需 total 可自定义 count SQL
|
||||
return new PageResult<>(records, (long) records.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,18 +64,18 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
public List<Long> createCodegenList(String author, CodegenCreateListReqVO reqVO) {
|
||||
List<Long> ids = new ArrayList<>(reqVO.getTableNames().size());
|
||||
// 遍历添加。虽然效率会低一点,但是没必要做成完全批量,因为不会这么大量
|
||||
reqVO.getTableNames().forEach(tableName -> ids.add(createCodegen(author, reqVO.getDataSourceConfigId(), tableName)));
|
||||
reqVO.getTableNames().forEach(tableName -> ids.add(createCodegen(author, reqVO.getDataSourceConfigId(), tableName, reqVO.getIsStandardized())));
|
||||
return ids;
|
||||
}
|
||||
|
||||
private Long createCodegen(String author, Long dataSourceConfigId, String tableName) {
|
||||
private Long createCodegen(String author, Long dataSourceConfigId, String tableName, Boolean isStandardized) {
|
||||
// 从数据库中,获得数据库表结构
|
||||
TableInfo tableInfo = databaseTableService.getTable(dataSourceConfigId, tableName);
|
||||
TableInfo tableInfo = databaseTableService.getTable(dataSourceConfigId, tableName, isStandardized);
|
||||
// 导入
|
||||
return createCodegen0(author, dataSourceConfigId, tableInfo);
|
||||
return createCodegen0(author, dataSourceConfigId, tableInfo, isStandardized);
|
||||
}
|
||||
|
||||
private Long createCodegen0(String author, Long dataSourceConfigId, TableInfo tableInfo) {
|
||||
private Long createCodegen0(String author, Long dataSourceConfigId, TableInfo tableInfo, Boolean isStandardized) {
|
||||
// 校验导入的表和字段非空
|
||||
validateTableInfo(tableInfo);
|
||||
// 校验是否已经存在
|
||||
@@ -85,7 +85,7 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
}
|
||||
|
||||
// 构建 CodegenTableDO 对象,插入到 DB 中
|
||||
CodegenTableDO table = codegenBuilder.buildTable(tableInfo);
|
||||
CodegenTableDO table = codegenBuilder.buildTable(tableInfo, isStandardized);
|
||||
table.setDataSourceConfigId(dataSourceConfigId);
|
||||
table.setScene(CodegenSceneEnum.ADMIN.getScene()); // 默认配置下,使用管理后台的模板
|
||||
table.setFrontType(codegenProperties.getFrontType());
|
||||
@@ -155,7 +155,7 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
throw exception(CODEGEN_TABLE_NOT_EXISTS);
|
||||
}
|
||||
// 从数据库中,获得数据库表结构
|
||||
TableInfo tableInfo = databaseTableService.getTable(table.getDataSourceConfigId(), table.getTableName());
|
||||
TableInfo tableInfo = databaseTableService.getTable(table.getDataSourceConfigId(), table.getTableName(),false);
|
||||
// 执行同步
|
||||
syncCodegen0(tableId, tableInfo);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableField;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -104,9 +105,14 @@ public class CodegenBuilder {
|
||||
LIST_OPERATION_RESULT_EXCLUDE_COLUMN.remove("createTime"); // 创建时间,还是需要返回的
|
||||
}
|
||||
|
||||
public CodegenTableDO buildTable(TableInfo tableInfo) {
|
||||
public CodegenTableDO buildTable(TableInfo tableInfo, Boolean isStandardized) {
|
||||
CodegenTableDO table = CodegenConvert.INSTANCE.convert(tableInfo);
|
||||
initTableDefault(table);
|
||||
if (isStandardized) {
|
||||
initTableDefault(table, table.getTableName().toLowerCase(), tableInfo.getEntityName());
|
||||
}else{
|
||||
initTableDefault(table, table.getTableName().toLowerCase(), null);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
@@ -114,17 +120,20 @@ public class CodegenBuilder {
|
||||
* 初始化 Table 表的默认字段
|
||||
*
|
||||
* @param table 表定义
|
||||
* @param tableName
|
||||
*/
|
||||
private void initTableDefault(CodegenTableDO table) {
|
||||
private void initTableDefault(CodegenTableDO table, String tableName, String entityName) {
|
||||
// 以 system_dept 举例子。moduleName 为 system、businessName 为 dept、className 为 Dept
|
||||
// 如果希望以 System 前缀,则可以手动在【代码生成 - 修改生成配置 - 基本信息】,将实体类名称改为 SystemDept 即可
|
||||
String tableName = table.getTableName().toLowerCase();
|
||||
// 第一步,_ 前缀的前面,作为 module 名字;第二步,moduleName 必须小写;
|
||||
table.setModuleName(subBefore(tableName, '_', false).toLowerCase());
|
||||
String moduleName = subBefore(tableName, '_', false).toLowerCase();
|
||||
table.setModuleName(moduleName.toLowerCase());
|
||||
// 第一步,第一个 _ 前缀的后面,作为 module 名字; 第二步,可能存在多个 _ 的情况,转换成驼峰; 第三步,businessName 必须小写;
|
||||
table.setBusinessName(toCamelCase(subAfter(tableName, '_', false)).toLowerCase());
|
||||
String businessName = toCamelCase(subAfter(tableName, '_', false)).toLowerCase();
|
||||
table.setBusinessName(StringUtils.isBlank(entityName) ? businessName : entityName.toLowerCase());
|
||||
// 驼峰 + 首字母大写;第一步,第一个 _ 前缀的后面,作为 class 名字;第二步,驼峰命名
|
||||
table.setClassName(upperFirst(toCamelCase(subAfter(tableName, '_', false))));
|
||||
String className = upperFirst(toCamelCase(subAfter(tableName, '_', false)));
|
||||
table.setClassName(StringUtils.isBlank(entityName) ? className : entityName);
|
||||
// 去除结尾的表,作为类描述
|
||||
table.setClassComment(StrUtil.removeSuffixIgnoreCase(table.getTableComment(), "表"));
|
||||
table.setTemplateType(CodegenTemplateTypeEnum.ONE.getType());
|
||||
|
||||
@@ -29,13 +29,12 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.enums.codegen.CodegenVOTypeEnum;
|
||||
import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties;
|
||||
import cn.iocoder.yudao.module.infra.stdnms.StdNmsService;
|
||||
import cn.iocoder.yudao.module.infra.service.standardname.StandardNameService;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
@@ -48,14 +47,9 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static cn.hutool.core.map.MapUtil.getStr;
|
||||
import static cn.hutool.core.text.CharSequenceUtil.*;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STD_ABBR_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 代码生成的引擎,用于具体生成代码
|
||||
@@ -67,7 +61,7 @@ import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STD_ABBR_NO
|
||||
@Component
|
||||
public class CodegenEngine {
|
||||
@Resource
|
||||
private StdNmsService stdNmsService;
|
||||
private StandardNameService standardNameService;
|
||||
|
||||
/**
|
||||
* 后端的模板配置
|
||||
@@ -284,6 +278,7 @@ public class CodegenEngine {
|
||||
*/
|
||||
/**
|
||||
* 代码生成,支持传递额外参数
|
||||
*
|
||||
* @param extraParam 额外参数,如 isBusiness
|
||||
*/
|
||||
public Map<String, String> execute(CodegenTableDO table, List<CodegenColumnDO> columns,
|
||||
@@ -291,9 +286,6 @@ public class CodegenEngine {
|
||||
// 1.1 初始化 bindMap 上下文
|
||||
Map<String, Object> bindingMap = initBindingMap(table, columns, subTables, subColumnsList);
|
||||
|
||||
// 标准化命名校验逻辑
|
||||
standardizedJavaField(columns, subColumnsList, extraParam);
|
||||
|
||||
// 传递 extraParam 到模板
|
||||
if (extraParam != null) {
|
||||
bindingMap.putAll(extraParam);
|
||||
@@ -327,68 +319,6 @@ public class CodegenEngine {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是标准化的字段名需要针对标准命名表映射 javaField 全名
|
||||
* @param columns 主表的字段集合
|
||||
* @param subColumnsList 子表的字段集合
|
||||
* @param extraParam 额外参数,包含 isStandardized 标志
|
||||
*/
|
||||
private void standardizedJavaField(List<CodegenColumnDO> columns, List<List<CodegenColumnDO>> subColumnsList, Map<String, Object> extraParam) {
|
||||
if (extraParam != null && Boolean.TRUE.equals(extraParam.get("isStandardized"))) {
|
||||
List<CodegenColumnDO> allColumns = new ArrayList<>();
|
||||
allColumns.addAll(columns);
|
||||
allColumns.addAll(Optional.ofNullable(subColumnsList).orElse(new ArrayList<>()).stream().flatMap(Collection::stream).toList());
|
||||
// BusinessBaseDO 字段集合
|
||||
Set<String> businessBaseFields = CodegenBuilder.BUSINESS_BASE_DO_FIELDS;
|
||||
Map<String, String> abbrToFullName = new HashMap<>();
|
||||
Set<String> columnNameSet = allColumns.stream()
|
||||
// 跳过 BusinessBaseDO 字段
|
||||
.filter(x -> !businessBaseFields.contains(x.getJavaField()))
|
||||
.map(CodegenColumnDO::getColumnName).collect(Collectors.toSet());
|
||||
// 分词(如驼峰转词组)
|
||||
Set<String> phrases = columnNameSet.stream().map(String::toLowerCase)
|
||||
// 分割,最终使用大写
|
||||
.flatMap(y -> Arrays.stream(y.split("_"))).map(String::toUpperCase)
|
||||
.collect(Collectors.toSet());
|
||||
List<StdNmsDO> checkedData = stdNmsService.getStdNmsListByAbbrs(phrases);
|
||||
Set<String> stdAbbrSet = checkedData.stream().map(StdNmsDO::getAbbr).collect(Collectors.toSet());
|
||||
phrases.removeAll(stdAbbrSet);
|
||||
if (CollUtil.isNotEmpty(phrases)) {
|
||||
throw exception(STD_ABBR_NOT_EXISTS, String.join(",", phrases));
|
||||
}
|
||||
Map<String, String> stdNmsAbbrMap = new ConcurrentHashMap<>();
|
||||
checkedData.forEach(x-> {
|
||||
stdNmsAbbrMap.put(x.getAbbr(), x.getWord());
|
||||
});
|
||||
|
||||
// 构造列名和全名的映射(需要根据短语映射的关系进行拼接)
|
||||
abbrToFullName = allColumns.stream()
|
||||
// 跳过 BusinessBaseDO 字段
|
||||
.filter(x -> !businessBaseFields.contains(x.getJavaField()))
|
||||
.collect(Collectors.toMap(
|
||||
CodegenColumnDO::getJavaField,
|
||||
column -> {
|
||||
// 1.1.1 获取短语
|
||||
String columnName = column.getColumnName().toUpperCase();
|
||||
List<String> words = new LinkedList<>(Arrays.asList(columnName.split("_")));
|
||||
List<String> fullWords = words.stream().map(stdNmsAbbrMap::get).map(String::toLowerCase).toList();
|
||||
// 拼接 fullName 除第一个单词外,首字母需要大写
|
||||
return IntStream.range(0, fullWords.size())
|
||||
.mapToObj(i -> i == 0 ? fullWords.get(i) : Character.toUpperCase(fullWords.get(i).charAt(0)) + fullWords.get(i).substring(1))
|
||||
.collect(Collectors.joining());
|
||||
},
|
||||
(v1, v2) -> v1,
|
||||
HashMap::new
|
||||
));
|
||||
// 替换 所有列的 javaField
|
||||
Map<String, String> finalAbbrToFullName = abbrToFullName;
|
||||
columns.stream().filter(x -> !businessBaseFields.contains(x.getJavaField())).forEach(column -> {
|
||||
String fullName = finalAbbrToFullName.get(column.getJavaField());
|
||||
column.setJavaField(fullName);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容原有接口,默认 isBusiness=false
|
||||
*/
|
||||
|
||||
@@ -25,9 +25,10 @@ public interface DatabaseTableService {
|
||||
* 获得指定表名
|
||||
*
|
||||
* @param dataSourceConfigId 数据源配置的编号
|
||||
* @param tableName 表名称
|
||||
* @param name 表名称
|
||||
* @param isStandardized 是否标准化的表名
|
||||
* @return 表
|
||||
*/
|
||||
TableInfo getTable(Long dataSourceConfigId, String tableName);
|
||||
TableInfo getTable(Long dataSourceConfigId, String name, Boolean isStandardized);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,19 +5,27 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.standardname.StandardNameDO;
|
||||
import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder;
|
||||
import cn.iocoder.yudao.module.infra.service.standardname.StandardNameService;
|
||||
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableField;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.query.SQLQuery;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STD_ABBR_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 数据库表 Service 实现类
|
||||
@@ -30,20 +38,27 @@ public class DatabaseTableServiceImpl implements DatabaseTableService {
|
||||
@Resource
|
||||
private DataSourceConfigService dataSourceConfigService;
|
||||
|
||||
@Resource
|
||||
private StandardNameService standardNameService;
|
||||
|
||||
@Override
|
||||
public List<TableInfo> getTableList(Long dataSourceConfigId, String nameLike, String commentLike) {
|
||||
List<TableInfo> tables = getTableList0(dataSourceConfigId, null);
|
||||
return tables.stream().filter(tableInfo -> (StrUtil.isEmpty(nameLike) || tableInfo.getName().contains(nameLike))
|
||||
&& (StrUtil.isEmpty(commentLike) || tableInfo.getComment().contains(commentLike)))
|
||||
.collect(Collectors.toList());
|
||||
List<TableInfo> tables = getTableList0(dataSourceConfigId, null,false);
|
||||
// 转为小写进行不区分大小写的匹配
|
||||
String nameLikeLower = StrUtil.isEmpty(nameLike) ? null : nameLike.toLowerCase();
|
||||
String commentLikeLower = StrUtil.isEmpty(commentLike) ? null : commentLike.toLowerCase();
|
||||
return tables.stream().filter(tableInfo ->
|
||||
(nameLikeLower == null || (tableInfo.getName() != null && tableInfo.getName().toLowerCase().contains(nameLikeLower)))
|
||||
&& (commentLikeLower == null || (tableInfo.getComment() != null && tableInfo.getComment().toLowerCase().contains(commentLikeLower)))
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableInfo getTable(Long dataSourceConfigId, String name) {
|
||||
return CollUtil.getFirst(getTableList0(dataSourceConfigId, name));
|
||||
public TableInfo getTable(Long dataSourceConfigId, String name, Boolean isStandardized) {
|
||||
return CollUtil.getFirst(getTableList0(dataSourceConfigId, name, isStandardized));
|
||||
}
|
||||
|
||||
private List<TableInfo> getTableList0(Long dataSourceConfigId, String name) {
|
||||
private List<TableInfo> getTableList0(Long dataSourceConfigId, String name, Boolean isStandardized) {
|
||||
// 获得数据源配置
|
||||
DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId);
|
||||
Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId);
|
||||
@@ -70,8 +85,107 @@ public class DatabaseTableServiceImpl implements DatabaseTableService {
|
||||
null, globalConfig, null);
|
||||
// 按照名字排序
|
||||
List<TableInfo> tables = builder.getTableInfoList();
|
||||
standardizedAbbrName(tables, isStandardized);
|
||||
tables.sort(Comparator.comparing(TableInfo::getName));
|
||||
return tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果是标准化的字段名需要针对标准命名表映射 javaField 全名
|
||||
*
|
||||
*/
|
||||
private void standardizedAbbrName(List<TableInfo> tableInfos, Boolean isStandardized) {
|
||||
if (isStandardized) {
|
||||
Set<String> businessBaseFields = CodegenBuilder.BUSINESS_BASE_DO_FIELDS;
|
||||
// 获取所有的简写列名
|
||||
Set<String> columnNameSet = tableInfos.stream().flatMap(tableInfo -> {
|
||||
List<TableField> fields = tableInfo.getFields();
|
||||
return fields.stream()
|
||||
// 跳过 BusinessBaseDO 字段
|
||||
.filter(x -> !businessBaseFields.contains(x.getPropertyName()))
|
||||
.map(TableField::getColumnName);
|
||||
}).collect(Collectors.toSet());
|
||||
// 获取所有简写表名
|
||||
Set<String> tableNameSet = tableInfos.stream()
|
||||
.map(TableInfo::getName)
|
||||
// 只取第一个 _ 后面的部分,模块名称不缩写,也不进行匹配
|
||||
.map(tableName -> {
|
||||
int index = tableName.indexOf("_");
|
||||
return index == -1 ? tableName : tableName.substring(index + 1);
|
||||
})
|
||||
.collect(Collectors.toSet());
|
||||
columnNameSet.addAll(tableNameSet);
|
||||
|
||||
// 获取所有列名,表名的分词集合 _ 分割
|
||||
Set<String> phrases = columnNameSet.stream().map(String::toLowerCase)
|
||||
// 分割,最终使用大写
|
||||
.flatMap(y -> Arrays.stream(y.split("_"))).map(String::toUpperCase)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<StandardNameDO> checkedData = standardNameService.getStandardNameListByAbbrs(phrases);
|
||||
Set<String> abbrSet = checkedData.stream().map(StandardNameDO::getAbbreviation).collect(Collectors.toSet());
|
||||
|
||||
// 如果对于的缩写不存在,则抛出异常提示不符合规范的字段缩写单词
|
||||
phrases.removeAll(abbrSet);
|
||||
if (CollUtil.isNotEmpty(phrases)) {
|
||||
throw exception(STD_ABBR_NOT_EXISTS, String.join(",", phrases));
|
||||
}
|
||||
|
||||
// 缩写分词与全写分词的映射关系
|
||||
Map<String, String> abbrToFullWord = new ConcurrentHashMap<>();
|
||||
checkedData.forEach(x -> {
|
||||
abbrToFullWord.put(x.getAbbreviation(), x.getWord());
|
||||
});
|
||||
|
||||
// 缩写列名与全名的映射关系(忽略大小写)
|
||||
Map<String, String> abbrNameToFullName;
|
||||
// 构造列名和全名的映射(需要根据短语映射的关系进行拼接)
|
||||
abbrNameToFullName = (columnNameSet.stream()
|
||||
.collect(Collectors.toMap(
|
||||
x -> x,
|
||||
abbrName -> {
|
||||
// 1.1.1 获取短语
|
||||
String abbrNameUpperCase = abbrName.toUpperCase();
|
||||
List<String> words = new LinkedList<>(Arrays.asList(abbrNameUpperCase.split("_")));
|
||||
List<String> fullWords = words.stream().map(abbrToFullWord::get).toList();
|
||||
// 拼接 fullName 除第一个单词外,首字母需要大写
|
||||
return IntStream.range(0, fullWords.size())
|
||||
.mapToObj(i -> i == 0 ? fullWords.get(i) : Character.toUpperCase(fullWords.get(i).charAt(0)) + fullWords.get(i).substring(1))
|
||||
.collect(Collectors.joining());
|
||||
},
|
||||
(v1, v2) -> v1,
|
||||
() -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)
|
||||
)));
|
||||
// 替换 所有 JavaField
|
||||
Map<String, String> finalAbbrNameToFullName = abbrNameToFullName;
|
||||
tableInfos.forEach(tableInfo -> {
|
||||
// 处理表名/实体名称
|
||||
String tableName = tableInfo.getName();
|
||||
// 只使用第一个_后面的部分,模块名称不缩写,也不进行匹配
|
||||
int index = tableName.indexOf("_");
|
||||
String tableNamePart = index == -1 ? tableName : tableName.substring(index + 1);
|
||||
String entityFullName = finalAbbrNameToFullName.get(tableNamePart.toUpperCase());
|
||||
|
||||
if (entityFullName != null) {
|
||||
tableInfo.setEntityName(entityFullName);
|
||||
tableInfo.getStrategyConfig().mapper().getConverterMapperFileName().convert(tableInfo.getEntityName());
|
||||
tableInfo.getStrategyConfig().mapper().getConverterXmlFileName().convert(tableInfo.getEntityName());
|
||||
tableInfo.getStrategyConfig().service().getConverterServiceFileName().convert(tableInfo.getEntityName());
|
||||
tableInfo.getStrategyConfig().service().getConverterServiceImplFileName().convert(tableInfo.getEntityName());
|
||||
}
|
||||
|
||||
// 处理字段名称
|
||||
tableInfo.getFields().forEach(field -> {
|
||||
String columnName = field.getColumnName();
|
||||
String fieldFullName = finalAbbrNameToFullName.get(columnName);
|
||||
if (fieldFullName != null) {
|
||||
fieldFullName = fieldFullName.substring(0, 1).toLowerCase() + fieldFullName.substring(1);
|
||||
field.setPropertyName(fieldFullName,field.getColumnType());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.iocoder.yudao.module.infra.service.standardname;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNamePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNameRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNameSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.standardname.StandardNameDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 Service 接口
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
public interface StandardNameService {
|
||||
|
||||
/**
|
||||
* 创建数据命名与简写标准
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
StandardNameRespVO createStandardName(@Valid StandardNameSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新数据命名与简写标准
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateStandardName(@Valid StandardNameSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除数据命名与简写标准
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteStandardName(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除数据命名与简写标准
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteStandardNameListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得数据命名与简写标准
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 数据命名与简写标准
|
||||
*/
|
||||
StandardNameDO getStandardName(Long id);
|
||||
|
||||
/**
|
||||
* 获得数据命名与简写标准分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 数据命名与简写标准分页
|
||||
*/
|
||||
PageResult<StandardNameDO> getStandardNamePage(StandardNamePageReqVO pageReqVO);
|
||||
|
||||
List<StandardNameDO> getStandardNameListByAbbrs(Collection<String> abbrs);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package cn.iocoder.yudao.module.infra.service.standardname;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNamePageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNameRespVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.standardname.vo.StandardNameSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.standardname.StandardNameDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.standardname.StandardNameMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STANDARD_NAME_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 Service 实现类
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class StandardNameServiceImpl implements StandardNameService {
|
||||
|
||||
@Resource
|
||||
private StandardNameMapper standardNameMapper;
|
||||
|
||||
@Override
|
||||
public StandardNameRespVO createStandardName(StandardNameSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
StandardNameDO standardName = BeanUtils.toBean(createReqVO, StandardNameDO.class);
|
||||
standardNameMapper.insert(standardName);
|
||||
// 返回
|
||||
return BeanUtils.toBean(standardName, StandardNameRespVO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStandardName(StandardNameSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateStandardNameExists(updateReqVO.getId());
|
||||
// 更新
|
||||
StandardNameDO updateObj = BeanUtils.toBean(updateReqVO, StandardNameDO.class);
|
||||
standardNameMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStandardName(Long id) {
|
||||
// 校验存在
|
||||
validateStandardNameExists(id);
|
||||
// 删除
|
||||
standardNameMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStandardNameListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateStandardNameExists(ids);
|
||||
// 删除
|
||||
standardNameMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateStandardNameExists(List<Long> ids) {
|
||||
List<StandardNameDO> list = standardNameMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(STANDARD_NAME_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateStandardNameExists(Long id) {
|
||||
if (standardNameMapper.selectById(id) == null) {
|
||||
throw exception(STANDARD_NAME_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardNameDO getStandardName(Long id) {
|
||||
return standardNameMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<StandardNameDO> getStandardNamePage(StandardNamePageReqVO pageReqVO) {
|
||||
return standardNameMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StandardNameDO> getStandardNameListByAbbrs(Collection<String> abbrs) {
|
||||
QueryWrapper<StandardNameDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("abbr", abbrs);
|
||||
return standardNameMapper.selectList(queryWrapper);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.stdnms;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 Service 接口
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
public interface StdNmsService {
|
||||
|
||||
/**
|
||||
* 创建数据命名与简写标准
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createStdNms(@Valid StdNmsSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新数据命名与简写标准
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateStdNms(@Valid StdNmsSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除数据命名与简写标准
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteStdNms(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除数据命名与简写标准
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteStdNmsListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得数据命名与简写标准
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 数据命名与简写标准
|
||||
*/
|
||||
StdNmsDO getStdNms(Long id);
|
||||
|
||||
/**
|
||||
* 获得数据命名与简写标准分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 数据命名与简写标准分页
|
||||
*/
|
||||
PageResult<StdNmsDO> getStdNmsPage(StdNmsPageReqVO pageReqVO);
|
||||
/**
|
||||
* 根据缩写查询数据命名与简写标准
|
||||
* @param abbr 缩写
|
||||
* @return 数据命名与简写标准
|
||||
*/
|
||||
StdNmsDO getStdNmsByAbbr(String abbr);
|
||||
|
||||
/**
|
||||
* 根据缩写列表查询数据命名与简写标准
|
||||
* @param abbrs 缩写列表
|
||||
* @return 数据命名与简写标准列表
|
||||
*/
|
||||
List<StdNmsDO> getStdNmsListByAbbrs(Collection<String> abbrs);
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package cn.iocoder.yudao.module.infra.stdnms;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.stdnms.stdnms.vo.StdNmsSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.stdnms.StdNmsMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.STD_NMS_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 数据命名与简写标准 Service 实现类
|
||||
*
|
||||
* @author 后台管理
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@TenantIgnore
|
||||
public class StdNmsServiceImpl implements StdNmsService {
|
||||
|
||||
@Resource
|
||||
private StdNmsMapper stdNmsMapper;
|
||||
|
||||
@Override
|
||||
public StdNmsDO getStdNmsByAbbr(String abbr) {
|
||||
QueryWrapper<StdNmsDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("abbr", abbr);
|
||||
return stdNmsMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StdNmsDO> getStdNmsListByAbbrs(Collection<String> abbrs) {
|
||||
QueryWrapper<StdNmsDO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("abbr", abbrs);
|
||||
return stdNmsMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createStdNms(StdNmsSaveReqVO createReqVO) {
|
||||
StdNmsDO stdNms = BeanUtils.toBean(createReqVO, StdNmsDO.class);
|
||||
stdNmsMapper.insert(stdNms);
|
||||
// 返回
|
||||
return stdNms.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStdNms(StdNmsSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateStdNmsExists(updateReqVO.getId());
|
||||
// 更新
|
||||
StdNmsDO updateObj = BeanUtils.toBean(updateReqVO, StdNmsDO.class);
|
||||
stdNmsMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStdNms(Long id) {
|
||||
// 校验存在
|
||||
validateStdNmsExists(id);
|
||||
// 删除
|
||||
stdNmsMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStdNmsListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateStdNmsExists(ids);
|
||||
// 删除
|
||||
stdNmsMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateStdNmsExists(List<Long> ids) {
|
||||
List<StdNmsDO> list = stdNmsMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(STD_NMS_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateStdNmsExists(Long id) {
|
||||
if (stdNmsMapper.selectById(id) == null) {
|
||||
throw exception(STD_NMS_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StdNmsDO getStdNms(Long id) {
|
||||
return stdNmsMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<StdNmsDO> getStdNmsPage(StdNmsPageReqVO pageReqVO) {
|
||||
return stdNmsMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -173,6 +173,6 @@ yudao:
|
||||
enable: true
|
||||
ignore-urls:
|
||||
ignore-tables:
|
||||
- infra_std_nms
|
||||
- infra_std_name
|
||||
|
||||
debug: false
|
||||
|
||||
@@ -86,7 +86,7 @@ public static final Long ${treeParentColumn_javaField_underlineCase.toUpperCase(
|
||||
#end
|
||||
#if($isStandardized == true)
|
||||
#if(!${column.primaryKey})
|
||||
@TableField("${column.columnName}")
|
||||
@TableField("${column.columnName}")
|
||||
#end
|
||||
#end
|
||||
private ${column.javaType} ${column.javaField};
|
||||
|
||||
@@ -55,7 +55,12 @@ public class ${subTable.className}DO extends BaseDO {
|
||||
#end
|
||||
*/
|
||||
#if (${column.primaryKey})##处理主键
|
||||
@TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#end
|
||||
@TableId#if (${column.javaType} == 'String')(type = IdType.INPUT)#else(type = IdType.ASSIGN_ID)#end
|
||||
#end
|
||||
#if($isStandardized == true)
|
||||
#if(!${column.primaryKey})
|
||||
@TableField("${column.columnName}")
|
||||
#end
|
||||
#end
|
||||
#if ($voType == 20)
|
||||
## 1. 处理 Swagger 注解
|
||||
|
||||
@@ -65,10 +65,13 @@ export const ${simpleClassName}Api = {
|
||||
return await request.download({ url: `${baseURL}/export-excel`, params })
|
||||
},
|
||||
|
||||
#if($isFileUpload && $isFileUpload == true)
|
||||
// 查询接口相关的文件上传元数据信息
|
||||
getFileUploadInfo: async () => {
|
||||
return await request.get({url: `${baseURL}/upload-info`})
|
||||
}
|
||||
},
|
||||
#end
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.standardname.StandardNameMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.stdnms.StdNmsMapper">
|
||||
|
||||
<select id="selectPageCustom" resultType="cn.iocoder.yudao.module.infra.dal.dataobject.stdnms.stdnms.StdNmsDO">
|
||||
SELECT * FROM infra_std_nms
|
||||
<where>
|
||||
<if test="word != null and word != ''">
|
||||
AND LOWER(word) LIKE CONCAT('%', LOWER(#{word}), '%')
|
||||
</if>
|
||||
<if test="abbr != null and abbr != ''">
|
||||
AND abbr = #{abbr}
|
||||
</if>
|
||||
<if test="info != null and info != ''">
|
||||
AND info = #{info}
|
||||
</if>
|
||||
<if test="createTime != null and createTime[0] != null and createTime[1] != null">
|
||||
AND create_time BETWEEN #{createTime[0]} AND #{createTime[1]}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY id DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -79,7 +79,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
o -> o.setDataSourceConfigId(1L).setTableNames(Collections.singletonList("t_yunai")));
|
||||
// mock 方法(TableInfo)
|
||||
TableInfo tableInfo = mock(TableInfo.class);
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai"), false))
|
||||
.thenReturn(tableInfo);
|
||||
when(tableInfo.getComment()).thenReturn("芋艿");
|
||||
// mock 方法(TableInfo fields)
|
||||
@@ -91,7 +91,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
when(tableInfo.getFields()).thenReturn(fields);
|
||||
// mock 方法(CodegenTableDO)
|
||||
CodegenTableDO table = randomPojo(CodegenTableDO.class);
|
||||
when(codegenBuilder.buildTable(same(tableInfo))).thenReturn(table);
|
||||
when(codegenBuilder.buildTable(same(tableInfo), false)).thenReturn(table);
|
||||
// mock 方法(CodegenColumnDO)
|
||||
List<CodegenColumnDO> columns = randomPojoList(CodegenColumnDO.class);
|
||||
when(codegenBuilder.buildColumns(eq(table.getId()), same(fields)))
|
||||
@@ -240,7 +240,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
Long tableId = table.getId();
|
||||
// mock 方法(TableInfo)
|
||||
TableInfo tableInfo = mock(TableInfo.class);
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai"), false))
|
||||
.thenReturn(tableInfo);
|
||||
when(tableInfo.getComment()).thenReturn("芋艿");
|
||||
// mock 方法(TableInfo fields)
|
||||
@@ -250,7 +250,7 @@ public class CodegenServiceImplTest extends BaseDbUnitTest {
|
||||
when(field03.getComment()).thenReturn("分类");
|
||||
List<TableField> fields = Arrays.asList(field01, field03);
|
||||
when(tableInfo.getFields()).thenReturn(fields);
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai")))
|
||||
when(databaseTableService.getTable(eq(1L), eq("t_yunai"), false))
|
||||
.thenReturn(tableInfo);
|
||||
// mock 方法(CodegenTableDO)
|
||||
List<CodegenColumnDO> newColumns = randomPojoList(CodegenColumnDO.class, 2);
|
||||
|
||||
@@ -32,7 +32,7 @@ public class CodegenBuilderTest extends BaseMockitoUnitTest {
|
||||
when(tableInfo.getComment()).thenReturn("用户");
|
||||
|
||||
// 调用
|
||||
CodegenTableDO table = codegenBuilder.buildTable(tableInfo);
|
||||
CodegenTableDO table = codegenBuilder.buildTable(tableInfo, false);
|
||||
// 断言
|
||||
assertEquals("system_user", table.getTableName());
|
||||
assertEquals("用户", table.getTableComment());
|
||||
|
||||
Reference in New Issue
Block a user