diff --git a/cloud-auth/src/main/resources/bootstrap.yml b/cloud-auth/src/main/resources/bootstrap.yml index 8581ac4..1eaec3e 100644 --- a/cloud-auth/src/main/resources/bootstrap.yml +++ b/cloud-auth/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 106.15.136.7:8848 user-name: nacos password: nacos - namespace: xzr + namespace: crj # Spring spring: application: diff --git a/cloud-gateway/src/main/resources/bootstrap.yml b/cloud-gateway/src/main/resources/bootstrap.yml index ae3ee7b..5c23eb1 100644 --- a/cloud-gateway/src/main/resources/bootstrap.yml +++ b/cloud-gateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 106.15.136.7:8848 user-name: nacos password: nacos - namespace: xzr + namespace: crj # Spring spring: diff --git a/cloud-modules/cloud-modules-fault/pom.xml b/cloud-modules/cloud-modules-fault/pom.xml new file mode 100644 index 0000000..c068b4b --- /dev/null +++ b/cloud-modules/cloud-modules-fault/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + com.muyu + cloud-modules + 3.6.3 + + + cloud-modules-fault + + + 17 + 17 + UTF-8 + + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.mysql + mysql-connector-j + + + + + com.muyu + cloud-common-datasource + + + + + com.muyu + cloud-common-datascope + + + + + com.muyu + cloud-common-log + + + + + com.muyu + cloud-common-api-doc + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/CloudFaultApplication.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/CloudFaultApplication.java new file mode 100644 index 0000000..1017e81 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/CloudFaultApplication.java @@ -0,0 +1,16 @@ +package com.muyu; + + +import com.muyu.common.security.annotation.EnableCustomConfig; +import com.muyu.common.security.annotation.EnableMyFeignClients; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableCustomConfig +@EnableMyFeignClients +@SpringBootApplication +public class CloudFaultApplication { + public static void main(String[] args) { + SpringApplication.run(CloudFaultApplication.class,args); + } +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FalutNotify.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FalutNotify.java new file mode 100644 index 0000000..b742eb6 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FalutNotify.java @@ -0,0 +1,34 @@ +package com.muyu.fault.common; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "falut_notify",autoResultMap = true) +public class FalutNotify { + /** + * ID + */ + @TableId(value = "falutNotifyId", type= IdType.AUTO) + @Schema(defaultValue = "ID",type = "Long",description = "ID") + private Long falutNotifyId; + /** + * 通知方 + */ + @Schema(defaultValue = "通知方",type = "String",description = "通知方") + private String falutNotifyParty; + /** + * 联系方式 + */ + @Schema(defaultValue = "联系方式",type = "String",description = "联系方式") + private String falutNotifyManner; +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FalutType.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FalutType.java new file mode 100644 index 0000000..2de911a --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FalutType.java @@ -0,0 +1,34 @@ +package com.muyu.fault.common; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "falut_type",autoResultMap = true) +public class FalutType { + /** + * 故障类型ID + */ + @TableId(value = "faultTypeId", type= IdType.AUTO) + @Schema(defaultValue = "故障类型ID",type = "Long",description = "故障类型ID") + private Long faultTypeId; + /** + * 故障类型名称 + */ + @Schema(defaultValue = "故障类型名称",type = "String",description = "故障类型名称") + private String faultTypeName; + /** + * 故障类型描述 + */ + @Schema(defaultValue = "故障类型描述",type = "String",description = "故障类型描述") + private String faultTypeDescription; +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultLog.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultLog.java new file mode 100644 index 0000000..4ced773 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultLog.java @@ -0,0 +1,45 @@ +package com.muyu.fault.common; + +import cn.hutool.core.date.DateTime; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "fault_log",autoResultMap = true) +public class FaultLog { + /** + * 日志ID + */ + @TableId(value = "faultLogId", type= IdType.AUTO) + @Schema(defaultValue = "日志ID",type = "Long",description = "日志ID") + private Long faultLogId; + /** + * 故障码 + */ + @Schema(defaultValue = "故障码",type = "String",description = "故障码") + private String faultLogCodes; + /** + * 车辆VIN + */ + @Schema(defaultValue = "车辆VIN",type = "String",description = "车辆VIN") + private String faultLogVIN; + /** + * 开始报警时间 + */ + @Schema(defaultValue = "开始报警时间",type = "DateTime",description = "开始报警时间") + private DateTime faultLogStartTime; + /** + * 结束报警时间 + */ + @Schema(defaultValue = "结束报警时间",type = "DateTime",description = "结束报警时间") + private DateTime faultLogEndTime; +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultSeverity.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultSeverity.java new file mode 100644 index 0000000..cdb3ba6 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultSeverity.java @@ -0,0 +1,43 @@ +package com.muyu.fault.common; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.common.core.web.domain.BaseEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "fault_severity",autoResultMap = true) +public class FaultSeverity extends BaseEntity { + /** + * 等级ID + */ + @TableId(value = "id", type= IdType.AUTO) + @Schema(defaultValue = "等级ID",type = "Long",description = "等级ID") + private Long faultSeverityId; + /** + * 等级名称 + */ + @Schema(defaultValue = "等级名称",type = "String",description = "等级名称") + private String faultSeverityName; + /** + * 优先级 + */ + @Schema(defaultValue = "优先级",type = "Integer",description = "优先级: 1_(立即) 2_(1小时内) 3_(24小时内)") + private Integer faultSeverityPriority; + /** + * 通知策略 + */ + @Schema(defaultValue = "通知策略",type = "String",description = "通知策略: 提示:邮件通知团队\n" + + "警告:邮件通知负责人\n" + + "严重:立即通知技术人员") + private String faultSeverityNotificationPolicy; +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultrRule.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultrRule.java new file mode 100644 index 0000000..bc71d5a --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/FaultrRule.java @@ -0,0 +1,36 @@ +package com.muyu.fault.common; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.common.core.web.domain.BaseEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "faultr_rule",autoResultMap = true) +public class FaultrRule extends BaseEntity { + /** + * 故障规则ID + */ + @TableId(value = "faultrRuleId", type= IdType.AUTO) + @Schema(defaultValue = "故障规则ID",type = "Long",description = "故障规则ID") + private Long faultrRuleId; + /** + * 故障规则名称 + */ + @Schema(defaultValue = "故障规则名称",type = "String",description = "故障规则名称") + private String faultrRuleName; + /** + * 故障规则描述 + */ + @Schema(defaultValue = "故障规则描述",type = "String",description = "故障规则描述") + private String faultrRuleDescription; +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/SysCarFault.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/SysCarFault.java new file mode 100644 index 0000000..3217fe0 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/common/SysCarFault.java @@ -0,0 +1,76 @@ +package com.muyu.fault.common; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.common.core.web.domain.BaseEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@TableName(value = "sys_car_fault", autoResultMap = true) +@EqualsAndHashCode(callSuper = true) +public class SysCarFault extends BaseEntity { + /** + * 自增主键 + */ + @TableId(value = "id", type= IdType.AUTO) + @Schema(defaultValue = "自增主键",type = "Long",description = "自增主键") + private Long id; + /** + * 车辆故障编码 + */ + @Schema(defaultValue = "车辆故障编码",type = "String",description = "车辆故障编码") + private String faultCode; + /** + * 车辆故障类型 + */ + @Schema(defaultValue = "车辆故障类型",type = "String",description = "车辆故障类型") + private String faultType; + /** + * 故障VIN编码 + */ + @Schema(defaultValue = "故障VIN编码",type = "String",description = "故障VIN编码") + private String carVin; + /** + * 车辆故障标签 + */ + @Schema(defaultValue = "车辆故障标签",type = "String",description = "车辆故障标签") + private String faultLabel; + /** + * 车辆故障位 + */ + @Schema(defaultValue = "车辆故障位",type = "String",description = "车辆故障位") + private String faultBit; + /** + * 车辆故障值 + */ + @Schema(defaultValue = "车辆故障值",type = "String",description = "车辆故障值") + private String faultValue; + /** + * 故障级别 + */ + @Schema(defaultValue = "故障级别",type = "String",description = "故障级别") + private String faultWarn; + /** + * 报警状态(Y.是,N.否) + */ + @Schema(defaultValue = "报警状态",type = "String",description = "报警状态") + private String warnStatus; + /** + * 故障描述信息 + */ + @Schema(defaultValue = "故障描述信息",type = "String",description = "故障描述信息") + private String faultDesc; + /** + * 启用状态(1.待处理 2.处理中 3.已处理 4.忽略) + */ + @Schema(defaultValue = "启用状态",type = "String",description = "启用状态") + private String state; +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/controller/FaultLogController.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/controller/FaultLogController.java new file mode 100644 index 0000000..013de02 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/controller/FaultLogController.java @@ -0,0 +1,11 @@ +package com.muyu.fault.controller; + + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/log") +public class FaultLogController{ + +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/controller/SysCarFaultController.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/controller/SysCarFaultController.java new file mode 100644 index 0000000..c744d2e --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/controller/SysCarFaultController.java @@ -0,0 +1,112 @@ +package com.muyu.fault.controller; + +import java.util.Arrays; +import java.util.List; +import java.util.Random; + +import com.muyu.fault.common.SysCarFault; +import com.muyu.fault.service.impl.SysCarFaultService; +import jakarta.servlet.http.HttpServletResponse; +import javax.annotation.Resource; + +import org.springframework.web.bind.annotation.*; +import com.muyu.common.security.annotation.RequiresPermissions; +import com.muyu.common.core.web.controller.BaseController; +import com.muyu.common.core.domain.Result; +import com.muyu.common.core.utils.poi.ExcelUtil; +import com.muyu.common.security.utils.SecurityUtils; +import org.springframework.validation.annotation.Validated; +import com.muyu.common.core.web.page.TableDataInfo; + +@RestController +@RequestMapping("/faultInfo") +public class SysCarFaultController extends BaseController +{ + @Resource + private SysCarFaultService sysCarFaultService; + + /** + * 查询车辆故障列表 + */ + @RequestMapping(value = "/list", method = RequestMethod.GET) + public Result> list(SysCarFault sysCarFault) + { + List list = sysCarFaultService.selectSysCarFaultList(sysCarFault); + return success(list); + } + + /** + * 导出车辆故障列表 + */ + @RequestMapping(value = "export",method = RequestMethod.POST) + public void export(HttpServletResponse response, SysCarFault sysCarFault) + { + List list = sysCarFaultService.selectSysCarFaultList(sysCarFault); + ExcelUtil util = new ExcelUtil(SysCarFault.class); + util.exportExcel(response, list, "车辆故障数据"); + } + + /** + * 获取车辆故障详细信息 + */ + @RequestMapping(value = "/getInfo/{id}",method = RequestMethod.GET) + public Result> getInfo(@PathVariable("id") Long id) + { + return success(sysCarFaultService.selectSysCarFaultById(id)); + } + + /** + * 新增车辆故障 + */ + @RequestMapping(value = "add",method = RequestMethod.POST) + public Result add( + @Validated @RequestBody SysCarFault sysCarFault) + { + + if (sysCarFaultService.checkIdUnique(sysCarFault)) { + return error("新增 车辆故障 '" + sysCarFault + "'失败,车辆故障已存在"); + } + String prefix = "GT"; // 随机码的前缀 + int minNumber = 1; // 随机数字的最小值 + int maxNumber = 999; // 随机数字的最大值 + Random random = new Random(); // 创建一个随机对象 + // 生成一个随机数字 + int number = random.nextInt(maxNumber - minNumber + 1) + minNumber; + // 将数字格式化为三位字符串,不足三位前面补0 + String formattedNumber = String.format("%03d", number); + // 生成一个随机字母 + String alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + String randomLetter = alphabets.charAt(random.nextInt(alphabets.length())) + ""; + // 拼接前缀、随机字母和随机数字 + String randomCode = prefix + randomLetter + formattedNumber; + System.out.println(randomCode); // 输出随机码 + //赋值 + sysCarFault.setFaultCode(randomCode); + sysCarFault.setCreateBy(SecurityUtils.getUsername()); + return toAjax(sysCarFaultService.save(sysCarFault)); + } + + /** + * 修改车辆故障 + */ + @RequestMapping(value = "edit",method = RequestMethod.PUT) + public Result edit( + @Validated @RequestBody SysCarFault sysCarFault) + { + if (!sysCarFaultService.checkIdUnique(sysCarFault)) { + return error("修改 车辆故障 '" + sysCarFault + "'失败,车辆故障不存在"); + } + sysCarFault.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(sysCarFaultService.updateById(sysCarFault)); + } + + /** + * 删除车辆故障 + */ + @RequestMapping(value = "/remove/{ids}",method = RequestMethod.DELETE) + public Result remove(@PathVariable("ids") Long[] ids) + { + sysCarFaultService.removeBatchByIds(Arrays.asList(ids)); + return success(); + } +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/mapper/FaultLogMapper.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/mapper/FaultLogMapper.java new file mode 100644 index 0000000..5e9fc19 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/mapper/FaultLogMapper.java @@ -0,0 +1,10 @@ +package com.muyu.fault.mapper; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.fault.common.FaultLog; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface FaultLogMapper extends BaseMapper { +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/mapper/SysCarFaultMapper.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/mapper/SysCarFaultMapper.java new file mode 100644 index 0000000..92ece6a --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/mapper/SysCarFaultMapper.java @@ -0,0 +1,8 @@ +package com.muyu.fault.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.fault.common.SysCarFault; +import org.apache.ibatis.annotations.Mapper; +@Mapper +public interface SysCarFaultMapper extends BaseMapper{ +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/FaultLogService.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/FaultLogService.java new file mode 100644 index 0000000..325939e --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/FaultLogService.java @@ -0,0 +1,7 @@ +package com.muyu.fault.service.impl; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.fault.common.FaultLog; + +public interface FaultLogService extends IService { +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/FaultLogServiceImpl.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/FaultLogServiceImpl.java new file mode 100644 index 0000000..c42007d --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/FaultLogServiceImpl.java @@ -0,0 +1,10 @@ +package com.muyu.fault.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.fault.common.FaultLog; +import com.muyu.fault.mapper.FaultLogMapper; +import org.springframework.stereotype.Service; + +@Service +public class FaultLogServiceImpl extends ServiceImpl implements FaultLogService{ +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/SysCarFaultService.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/SysCarFaultService.java new file mode 100644 index 0000000..ed175a3 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/SysCarFaultService.java @@ -0,0 +1,31 @@ +package com.muyu.fault.service.impl; + +import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.fault.common.SysCarFault; + +public interface SysCarFaultService extends IService { + /** + * 精确查询车辆故障 + * + * @param id 车辆故障主键 + * @return 车辆故障 + */ + public SysCarFault selectSysCarFaultById(Long id); + + /** + * 查询车辆故障列表 + * + * @param sysCarFault 车辆故障 + * @return 车辆故障集合 + */ + public List selectSysCarFaultList(SysCarFault sysCarFault); + + /** + * 判断 车辆故障 id是否唯一 + * @param sysCarFault 车辆故障 + * @return 结果 + */ + Boolean checkIdUnique(SysCarFault sysCarFault); + +} diff --git a/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/SysCarFaultServiceImpl.java b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/SysCarFaultServiceImpl.java new file mode 100644 index 0000000..ead1679 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/java/com/muyu/fault/service/impl/SysCarFaultServiceImpl.java @@ -0,0 +1,69 @@ +package com.muyu.fault.service.impl; + +import java.util.List; + +import com.muyu.fault.common.SysCarFault; +import org.springframework.stereotype.Service; +import com.muyu.fault.mapper.SysCarFaultMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.utils.StringUtils; +import org.springframework.util.Assert; + +@Service +public class SysCarFaultServiceImpl + extends ServiceImpl + implements SysCarFaultService { + + /** + * 精确查询车辆故障 + * + * @param id 车辆故障主键 + * @return 车辆故障 + */ + @Override + public SysCarFault selectSysCarFaultById(Long id) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + Assert.notNull(id, "id不可为空"); + queryWrapper.eq(SysCarFault::getId, id); + return this.getOne(queryWrapper); + } + + + /** + * 查询车辆故障列表 + * + * @param sysCarFault 车辆故障 + * @return 车辆故障 + */ + @Override + public List selectSysCarFaultList(SysCarFault sysCarFault) + { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.like(StringUtils.isNotEmpty(sysCarFault.getFaultType()), + SysCarFault::getFaultType, sysCarFault.getFaultType()); + queryWrapper.eq(StringUtils.isNotEmpty(sysCarFault.getState()), + SysCarFault::getState, sysCarFault.getState()); + queryWrapper.eq(StringUtils.isNotEmpty(sysCarFault.getFaultType()), + SysCarFault::getFaultType, sysCarFault.getFaultType()); + queryWrapper.like(StringUtils.isNotEmpty(sysCarFault.getCarVin()), + SysCarFault::getCarVin, sysCarFault.getCarVin()); + queryWrapper.eq(StringUtils.isNotEmpty(sysCarFault.getFaultWarn()), + SysCarFault::getFaultWarn, sysCarFault.getFaultWarn()); + return this.list(queryWrapper); + } + + /** + * 唯一 判断 + * @param sysCarFault 车辆故障 + * @return 车辆故障 + */ + @Override + public Boolean checkIdUnique(SysCarFault sysCarFault) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysCarFault::getId, sysCarFault.getId()); + return this.count(queryWrapper) > 0; + } + +} diff --git a/cloud-modules/cloud-modules-fault/src/main/resources/banner.txt b/cloud-modules/cloud-modules-fault/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-fault/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-fault/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..c1a49c1 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/resources/bootstrap.yml @@ -0,0 +1,50 @@ +# Tomcat +server: + port: 9709 + +# nacos线上地址 +nacos: + addr: 106.15.136.7:8848 + user-name: nacos + password: nacos + namespace: crj + +spring: + application: + # 应用名称 + name: cloud-fault + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + config: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + # 系统共享配置 + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # 系统环境Config共享配置 + - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + +logging: + level: + com.muyu.system.mapper: DEBUG diff --git a/cloud-modules/cloud-modules-fault/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-fault/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..d1b5629 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-fault/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-fault/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..76a0d8f --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-fault/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-fault/src/main/resources/logback/test.xml new file mode 100644 index 0000000..2cd69e4 --- /dev/null +++ b/cloud-modules/cloud-modules-fault/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml index b6ae6e2..ed3a86f 100644 --- a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 106.15.136.7:8848 user-name: nacos password: nacos - namespace: xzr + namespace: crj # Spring spring: diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/CloudGenApplication.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/CloudGenApplication.java index da3eb43..3cb1f39 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/CloudGenApplication.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/CloudGenApplication.java @@ -16,5 +16,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; public class CloudGenApplication { public static void main (String[] args) { SpringApplication.run(CloudGenApplication.class, args); + System.out.println("CloudGen 模块启动成功!"); } } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/controller/GenController.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/controller/GenController.java index 1dfe039..100a2c4 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/controller/GenController.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/controller/GenController.java @@ -1,22 +1,24 @@ package com.muyu.gen.controller; +import com.muyu.common.core.domain.Result; import com.muyu.common.core.text.Convert; import com.muyu.common.core.web.controller.BaseController; -import com.muyu.common.core.domain.Result; import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.common.log.annotation.Log; import com.muyu.common.log.enums.BusinessType; import com.muyu.common.security.annotation.RequiresPermissions; import com.muyu.gen.domain.GenTable; import com.muyu.gen.domain.GenTableColumn; +import com.muyu.gen.domain.GenTableResp; import com.muyu.gen.service.IGenTableColumnService; import com.muyu.gen.service.IGenTableService; +import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.servlet.http.HttpServletResponse; +import javax.annotation.Resource; import java.io.IOException; import java.util.HashMap; import java.util.List; @@ -25,15 +27,19 @@ import java.util.Map; /** * 代码生成 操作处理 * - * @author muyu + * @author ruoyi */ @RequestMapping("/gen") @RestController -public class GenController extends BaseController { - @Autowired +public class GenController extends BaseController +{ + @Resource private IGenTableService genTableService; - @Autowired + @Resource + private HttpServletResponse response; + + @Resource private IGenTableColumnService genTableColumnService; /** @@ -41,7 +47,8 @@ public class GenController extends BaseController { */ @RequiresPermissions("tool:gen:list") @GetMapping("/list") - public Result> genList (GenTable genTable) { + public Result genList(GenTable genTable) + { startPage(); List list = genTableService.selectGenTableList(genTable); return getDataTable(list); @@ -52,7 +59,8 @@ public class GenController extends BaseController { */ @RequiresPermissions("tool:gen:query") @GetMapping(value = "/{tableId}") - public Result getInfo (@PathVariable("tableId") Long tableId) { + public Result getInfo(@PathVariable("tableId") Long tableId) + { GenTable table = genTableService.selectGenTableById(tableId); List tables = genTableService.selectGenTableAll(); List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); @@ -63,12 +71,14 @@ public class GenController extends BaseController { return success(map); } + /** * 查询数据库列表 */ @RequiresPermissions("tool:gen:list") @GetMapping("/db/list") - public Result> dataList (GenTable genTable) { + public Result dataList(GenTable genTable) + { startPage(); List list = genTableService.selectDbTableList(genTable); return getDataTable(list); @@ -78,26 +88,26 @@ public class GenController extends BaseController { * 查询数据表字段列表 */ @GetMapping(value = "/column/{tableId}") - public Result> columnList (Long tableId) { + public Result columnList(@PathVariable("tableId") Long tableId) + { + TableDataInfo dataInfo = new TableDataInfo(); List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); - return Result.success( - TableDataInfo.builder() - .total(list.size()) - .rows(list) - .build() - ); + dataInfo.setRows(list); + dataInfo.setTotal(list.size()); + return success(dataInfo); } /** * 导入表结构(保存) */ - @RequiresPermissions("tool:gen:import") +// @RequiresPermissions("tool:gen:import") @Log(title = "代码生成", businessType = BusinessType.IMPORT) @PostMapping("/importTable") - public Result importTableSave (String tables) { + public Result importTableSave(@RequestParam("tables") String tables, @RequestParam("dbName") String dbName) + { String[] tableNames = Convert.toStrArray(tables); // 查询表信息 - List tableList = genTableService.selectDbTableListByNames(tableNames); + List tableList = genTableService.selectDbTableListByNames(tableNames,dbName); genTableService.importGenTable(tableList); return success(); } @@ -108,7 +118,8 @@ public class GenController extends BaseController { @RequiresPermissions("tool:gen:edit") @Log(title = "代码生成", businessType = BusinessType.UPDATE) @PutMapping - public Result editSave (@Validated @RequestBody GenTable genTable) { + public Result editSave(@Validated @RequestBody GenTable genTable) + { genTableService.validateEdit(genTable); genTableService.updateGenTable(genTable); return success(); @@ -120,7 +131,8 @@ public class GenController extends BaseController { @RequiresPermissions("tool:gen:remove") @Log(title = "代码生成", businessType = BusinessType.DELETE) @DeleteMapping("/{tableIds}") - public Result remove (@PathVariable("tableIds") Long[] tableIds) { + public Result remove(@PathVariable("tableIds") Long[] tableIds) + { genTableService.deleteGenTableByIds(tableIds); return success(); } @@ -130,7 +142,8 @@ public class GenController extends BaseController { */ @RequiresPermissions("tool:gen:preview") @GetMapping("/preview/{tableId}") - public Result preview (@PathVariable("tableId") Long tableId) throws IOException { + public Result preview(@PathVariable("tableId") Long tableId) throws IOException + { Map dataMap = genTableService.previewCode(tableId); return success(dataMap); } @@ -141,7 +154,8 @@ public class GenController extends BaseController { @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) @GetMapping("/download/{tableName}") - public void download (HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException { + public void download(@PathVariable("tableName") String tableName) throws IOException + { byte[] data = genTableService.downloadCode(tableName); genCode(response, data); } @@ -152,7 +166,8 @@ public class GenController extends BaseController { @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) @GetMapping("/genCode/{tableName}") - public Result genCode (@PathVariable("tableName") String tableName) { + public Result genCode(@PathVariable("tableName") String tableName) + { genTableService.generatorCode(tableName); return success(); } @@ -162,9 +177,10 @@ public class GenController extends BaseController { */ @RequiresPermissions("tool:gen:edit") @Log(title = "代码生成", businessType = BusinessType.UPDATE) - @GetMapping("/synchDb/{tableName}") - public Result synchDb (@PathVariable("tableName") String tableName) { - genTableService.synchDb(tableName); + @GetMapping("/synchDb/{tableName}/{dbName}") + public Result synchDb(@PathVariable("tableName") String tableName,@PathVariable("dbName") String dbName) + { + genTableService.synchDb(tableName,dbName); return success(); } @@ -174,7 +190,8 @@ public class GenController extends BaseController { @RequiresPermissions("tool:gen:code") @Log(title = "代码生成", businessType = BusinessType.GENCODE) @GetMapping("/batchGenCode") - public void batchGenCode (HttpServletResponse response, String tables) throws IOException { + public void batchGenCode(@RequestParam("tables") String tables) throws IOException + { String[] tableNames = Convert.toStrArray(tables); byte[] data = genTableService.downloadCode(tableNames); genCode(response, data); @@ -183,11 +200,37 @@ public class GenController extends BaseController { /** * 生成zip文件 */ - private void genCode (HttpServletResponse response, byte[] data) throws IOException { + private void genCode(HttpServletResponse response, byte[] data) throws IOException + { response.reset(); - response.setHeader("Content-Disposition", "attachment; filename=\"muyu.zip\""); - response.addHeader("Content-Length", String.valueOf(data.length)); + response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); + response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); } + + /** + * 查询所有数据库名称 + */ + @GetMapping("/selDbNameAll") + public Result> selDbNameAll(){ + return Result.success(genTableService.selDbNameAll()); + } + + /** + * 查询所有表,不分数据库 + */ + @GetMapping("/db/listAll") + public Result> genListAll() { + return success(genTableService.selectDbTableListAll()); + } + + /** + * 根据数据库名称与表名称查询表字段 + */ + @GetMapping("/selectDbTableColumnsByName") + public Result> selTableAll(@RequestParam("dbName") String dbName,@RequestParam("table") String table){ + List genTableColumns = genTableColumnService.selectDbTableColumnsByName(table, dbName); + return Result.success(genTableColumns); + } } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTable.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTable.java index edb6510..c906725 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTable.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTable.java @@ -35,6 +35,8 @@ public class GenTable extends BaseEntity { */ private Long tableId; + private String dbName; + /** * 表名称 */ diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTableResp.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTableResp.java new file mode 100644 index 0000000..70b30dc --- /dev/null +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/domain/GenTableResp.java @@ -0,0 +1,43 @@ +package com.muyu.gen.domain; + +import com.muyu.common.core.constant.GenConstants; +import com.muyu.common.core.utils.StringUtils; +import com.muyu.common.core.web.domain.BaseEntity; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; +import org.apache.commons.lang3.ArrayUtils; + +import java.util.List; + + +/** + * 业务表 gen_table + * + * @author muyu + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +public class GenTableResp extends BaseEntity { + + private String dbName; + + /** + * 表名称 + */ + private String tableName; + + /** + * 表描述 + */ + private String tableComment; + + +} diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableColumnMapper.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableColumnMapper.java index 5825d59..76f5909 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableColumnMapper.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableColumnMapper.java @@ -1,67 +1,64 @@ package com.muyu.gen.mapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.muyu.gen.domain.GenTableColumn; +import org.apache.ibatis.annotations.Param; import java.util.List; + /** * 业务字段 数据层 * - * @author muyu + * @author ruoyi */ -public interface GenTableColumnMapper extends BaseMapper { +public interface GenTableColumnMapper +{ /** * 根据表名称查询列信息 * * @param tableName 表名称 - * + * @param dbName * @return 列信息 */ - List selectDbTableColumnsByName (String tableName); + public List selectDbTableColumnsByName(@Param("tableName") String tableName, @Param("dbName") String dbName); /** * 查询业务字段列表 * * @param tableId 业务字段编号 - * * @return 业务字段集合 */ - List selectGenTableColumnListByTableId (Long tableId); + public List selectGenTableColumnListByTableId(@Param("tableId") Long tableId); /** * 新增业务字段 * * @param genTableColumn 业务字段信息 - * * @return 结果 */ - int insertGenTableColumn (GenTableColumn genTableColumn); + public int insertGenTableColumn(GenTableColumn genTableColumn); /** * 修改业务字段 * * @param genTableColumn 业务字段信息 - * * @return 结果 */ - int updateGenTableColumn (GenTableColumn genTableColumn); + public int updateGenTableColumn(GenTableColumn genTableColumn); /** * 删除业务字段 * * @param genTableColumns 列数据 - * * @return 结果 */ - int deleteGenTableColumns (List genTableColumns); + public int deleteGenTableColumns(@Param("genTableColumns") List genTableColumns); /** * 批量删除业务字段 * * @param ids 需要删除的数据ID - * * @return 结果 */ - int deleteGenTableColumnByIds (Long[] ids); + public int deleteGenTableColumnByIds(@Param("ids") Long[] ids); } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableMapper.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableMapper.java index 66858cb..aa49b3f 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableMapper.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/mapper/GenTableMapper.java @@ -1,92 +1,91 @@ package com.muyu.gen.mapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.muyu.gen.domain.GenTable; +import com.muyu.gen.domain.GenTableResp; +import org.apache.ibatis.annotations.Param; import java.util.List; /** * 业务 数据层 * - * @author muyu + * @author ruoyi */ -public interface GenTableMapper extends BaseMapper { +public interface GenTableMapper +{ /** * 查询业务列表 * * @param genTable 业务信息 - * * @return 业务集合 */ - List selectGenTableList (GenTable genTable); + public List selectGenTableList(GenTable genTable); /** * 查询据库列表 * * @param genTable 业务信息 - * * @return 数据库表集合 */ - List selectDbTableList (GenTable genTable); + public List selectDbTableList(GenTable genTable); /** * 查询据库列表 * * @param tableNames 表名称组 - * + * @param dbName * @return 数据库表集合 */ - List selectDbTableListByNames (String[] tableNames); + public List selectDbTableListByNames(@Param("tableNames") String[] tableNames, @Param("dbName") String dbName); /** * 查询所有表信息 * * @return 表信息集合 */ - List selectGenTableAll (); + public List selectGenTableAll(); /** * 查询表ID业务信息 * * @param id 业务ID - * * @return 业务信息 */ - GenTable selectGenTableById (Long id); + public GenTable selectGenTableById(@Param("id") Long id); /** * 查询表名称业务信息 * * @param tableName 表名称 - * * @return 业务信息 */ - GenTable selectGenTableByName (String tableName); + public GenTable selectGenTableByName(@Param("tableName") String tableName); /** * 新增业务 * * @param genTable 业务信息 - * * @return 结果 */ - int insertGenTable (GenTable genTable); + public int insertGenTable(GenTable genTable); /** * 修改业务 * * @param genTable 业务信息 - * * @return 结果 */ - int updateGenTable (GenTable genTable); + public int updateGenTable(GenTable genTable); /** * 批量删除业务 * * @param ids 需要删除的数据ID - * * @return 结果 */ - int deleteGenTableByIds (Long[] ids); + public int deleteGenTableByIds(@Param("ids") Long[] ids); + + List selDbNameAll(); + + List selectDbTableListAll(); } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java index 895b1ed..043c83b 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java @@ -3,7 +3,7 @@ package com.muyu.gen.service; import com.muyu.common.core.text.Convert; import com.muyu.gen.domain.GenTableColumn; import com.muyu.gen.mapper.GenTableColumnMapper; -import org.springframework.beans.factory.annotation.Autowired; + import javax.annotation.Resource; import org.springframework.stereotype.Service; import java.util.List; @@ -11,58 +11,64 @@ import java.util.List; /** * 业务字段 服务层实现 * - * @author muyu + * @author ruoyi */ @Service -public class GenTableColumnServiceImpl implements IGenTableColumnService { - @Autowired - private GenTableColumnMapper genTableColumnMapper; +public class GenTableColumnServiceImpl implements IGenTableColumnService +{ + @Resource + private GenTableColumnMapper genTableColumnMapper; - /** + /** * 查询业务字段列表 * * @param tableId 业务字段编号 - * * @return 业务字段集合 */ - @Override - public List selectGenTableColumnListByTableId (Long tableId) { - return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); - } + @Override + public List selectGenTableColumnListByTableId(Long tableId) + { + return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); + } /** * 新增业务字段 * * @param genTableColumn 业务字段信息 - * * @return 结果 */ - @Override - public int insertGenTableColumn (GenTableColumn genTableColumn) { - return genTableColumnMapper.insertGenTableColumn(genTableColumn); - } + @Override + public int insertGenTableColumn(GenTableColumn genTableColumn) + { + return genTableColumnMapper.insertGenTableColumn(genTableColumn); + } - /** + /** * 修改业务字段 * * @param genTableColumn 业务字段信息 - * * @return 结果 */ - @Override - public int updateGenTableColumn (GenTableColumn genTableColumn) { - return genTableColumnMapper.updateGenTableColumn(genTableColumn); - } + @Override + public int updateGenTableColumn(GenTableColumn genTableColumn) + { + return genTableColumnMapper.updateGenTableColumn(genTableColumn); + } - /** + /** * 删除业务字段对象 * * @param ids 需要删除的数据ID - * * @return 结果 */ + @Override + public int deleteGenTableColumnByIds(String ids) + { + return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); + } + @Override - public int deleteGenTableColumnByIds (String ids) { - return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); + public List selectDbTableColumnsByName(String table, String dbName) { + return genTableColumnMapper.selectDbTableColumnsByName(table,dbName); } } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java index 6273779..8cdefc5 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java @@ -10,6 +10,7 @@ import com.muyu.common.core.utils.StringUtils; import com.muyu.common.security.utils.SecurityUtils; import com.muyu.gen.domain.GenTable; import com.muyu.gen.domain.GenTableColumn; +import com.muyu.gen.domain.GenTableResp; import com.muyu.gen.mapper.GenTableColumnMapper; import com.muyu.gen.mapper.GenTableMapper; import com.muyu.gen.util.GenUtils; @@ -22,7 +23,7 @@ import org.apache.velocity.VelocityContext; import org.apache.velocity.app.Velocity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; + import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -41,43 +42,28 @@ import java.util.zip.ZipOutputStream; /** * 业务 服务层实现 * - * @author muyu + * @author ruoyi */ @Service -public class GenTableServiceImpl implements IGenTableService { +public class GenTableServiceImpl implements IGenTableService +{ private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); - @Autowired + @Resource private GenTableMapper genTableMapper; - @Autowired + @Resource private GenTableColumnMapper genTableColumnMapper; - /** - * 获取代码生成地址 - * - * @param table 业务表信息 - * @param template 模板文件路径 - * - * @return 生成地址 - */ - public static String getGenPath (GenTable table, String template) { - String genPath = table.getGenPath(); - if (StringUtils.equals(genPath, "/")) { - return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); - } - return genPath + File.separator + VelocityUtils.getFileName(template, table); - } - /** * 查询业务信息 * * @param id 业务ID - * * @return 业务信息 */ @Override - public GenTable selectGenTableById (Long id) { + public GenTable selectGenTableById(Long id) + { GenTable genTable = genTableMapper.selectGenTableById(id); setTableFromOptions(genTable); return genTable; @@ -87,11 +73,11 @@ public class GenTableServiceImpl implements IGenTableService { * 查询业务列表 * * @param genTable 业务信息 - * * @return 业务集合 */ @Override - public List selectGenTableList (GenTable genTable) { + public List selectGenTableList(GenTable genTable) + { return genTableMapper.selectGenTableList(genTable); } @@ -99,11 +85,11 @@ public class GenTableServiceImpl implements IGenTableService { * 查询据库列表 * * @param genTable 业务信息 - * * @return 数据库表集合 */ @Override - public List selectDbTableList (GenTable genTable) { + public List selectDbTableList(GenTable genTable) + { return genTableMapper.selectDbTableList(genTable); } @@ -111,12 +97,13 @@ public class GenTableServiceImpl implements IGenTableService { * 查询据库列表 * * @param tableNames 表名称组 - * + * @param dbName * @return 数据库表集合 */ @Override - public List selectDbTableListByNames (String[] tableNames) { - return genTableMapper.selectDbTableListByNames(tableNames); + public List selectDbTableListByNames(String[] tableNames, String dbName) + { + return genTableMapper.selectDbTableListByNames(tableNames,dbName); } /** @@ -125,7 +112,8 @@ public class GenTableServiceImpl implements IGenTableService { * @return 表信息集合 */ @Override - public List selectGenTableAll () { + public List selectGenTableAll() + { return genTableMapper.selectGenTableAll(); } @@ -133,17 +121,19 @@ public class GenTableServiceImpl implements IGenTableService { * 修改业务 * * @param genTable 业务信息 - * * @return 结果 */ @Override @Transactional(rollbackFor = Exception.class) - public void updateGenTable (GenTable genTable) { + public void updateGenTable(GenTable genTable) + { String options = JSON.toJSONString(genTable.getParams()); genTable.setOptions(options); int row = genTableMapper.updateGenTable(genTable); - if (row > 0) { - for (GenTableColumn cenTableColumn : genTable.getColumns()) { + if (row > 0) + { + for (GenTableColumn cenTableColumn : genTable.getColumns()) + { genTableColumnMapper.updateGenTableColumn(cenTableColumn); } } @@ -153,12 +143,12 @@ public class GenTableServiceImpl implements IGenTableService { * 删除业务对象 * * @param tableIds 需要删除的数据ID - * * @return 结果 */ @Override @Transactional(rollbackFor = Exception.class) - public void deleteGenTableByIds (Long[] tableIds) { + public void deleteGenTableByIds(Long[] tableIds) + { genTableMapper.deleteGenTableByIds(tableIds); genTableColumnMapper.deleteGenTableColumnByIds(tableIds); } @@ -170,23 +160,31 @@ public class GenTableServiceImpl implements IGenTableService { */ @Override @Transactional(rollbackFor = Exception.class) - public void importGenTable (List tableList) { + public void importGenTable(List tableList) + { String operName = SecurityUtils.getUsername(); - try { - for (GenTable table : tableList) { + try + { + for (GenTable table : tableList) + { + String dbName = table.getDbName(); String tableName = table.getTableName(); GenUtils.initTable(table, operName); int row = genTableMapper.insertGenTable(table); - if (row > 0) { + if (row > 0) + { // 保存列信息 - List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); - for (GenTableColumn column : genTableColumns) { + List genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName, dbName); + for (GenTableColumn column : genTableColumns) + { GenUtils.initColumnField(column, table); genTableColumnMapper.insertGenTableColumn(column); } } } - } catch (Exception e) { + } + catch (Exception e) + { throw new ServiceException("导入失败:" + e.getMessage()); } } @@ -195,11 +193,11 @@ public class GenTableServiceImpl implements IGenTableService { * 预览代码 * * @param tableId 表编号 - * * @return 预览数据列表 */ @Override - public Map previewCode (Long tableId) { + public Map previewCode(Long tableId) + { Map dataMap = new LinkedHashMap<>(); // 查询表信息 GenTable table = genTableMapper.selectGenTableById(tableId); @@ -213,7 +211,8 @@ public class GenTableServiceImpl implements IGenTableService { // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) { + for (String template : templates) + { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); @@ -227,11 +226,11 @@ public class GenTableServiceImpl implements IGenTableService { * 生成代码(下载方式) * * @param tableName 表名称 - * * @return 数据 */ @Override - public byte[] downloadCode (String tableName) { + public byte[] downloadCode(String tableName) + { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); generatorCode(tableName, zip); @@ -245,7 +244,8 @@ public class GenTableServiceImpl implements IGenTableService { * @param tableName 表名称 */ @Override - public void generatorCode (String tableName) { + public void generatorCode(String tableName) + { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); // 设置主子表信息 @@ -259,16 +259,21 @@ public class GenTableServiceImpl implements IGenTableService { // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) { - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) { + for (String template : templates) + { + if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) + { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - try { + try + { String path = getGenPath(table, template); FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); - } catch (IOException e) { + } + catch (IOException e) + { throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); } } @@ -279,45 +284,54 @@ public class GenTableServiceImpl implements IGenTableService { * 同步数据库 * * @param tableName 表名称 + * @param dbName */ @Override @Transactional(rollbackFor = Exception.class) - public void synchDb (String tableName) { + public void synchDb(String tableName, String dbName) + { GenTable table = genTableMapper.selectGenTableByName(tableName); List tableColumns = table.getColumns(); Map tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); - List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); - if (StringUtils.isEmpty(dbTableColumns)) { + List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName, dbName); + if (StringUtils.isEmpty(dbTableColumns)) + { throw new ServiceException("同步数据失败,原表结构不存在"); } List dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); dbTableColumns.forEach(column -> { GenUtils.initColumnField(column, table); - if (tableColumnMap.containsKey(column.getColumnName())) { + if (tableColumnMap.containsKey(column.getColumnName())) + { GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); column.setColumnId(prevColumn.getColumnId()); - if (column.isList()) { + if (column.isList()) + { // 如果是列表,继续保留查询方式/字典类型选项 column.setDictType(prevColumn.getDictType()); column.setQueryType(prevColumn.getQueryType()); } if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() && (column.isInsert() || column.isEdit()) - && ((column.isUsableColumn()) || (!column.isSuperColumn()))) { + && ((column.isUsableColumn()) || (!column.isSuperColumn()))) + { // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 column.setIsRequired(prevColumn.getIsRequired()); column.setHtmlType(prevColumn.getHtmlType()); } genTableColumnMapper.updateGenTableColumn(column); - } else { + } + else + { genTableColumnMapper.insertGenTableColumn(column); } }); List delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); - if (StringUtils.isNotEmpty(delColumns)) { + if (StringUtils.isNotEmpty(delColumns)) + { genTableColumnMapper.deleteGenTableColumns(delColumns); } } @@ -326,14 +340,15 @@ public class GenTableServiceImpl implements IGenTableService { * 批量生成代码(下载方式) * * @param tableNames 表数组 - * * @return 数据 */ @Override - public byte[] downloadCode (String[] tableNames) { + public byte[] downloadCode(String[] tableNames) + { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); - for (String tableName : tableNames) { + for (String tableName : tableNames) + { generatorCode(tableName, zip); } IOUtils.closeQuietly(zip); @@ -343,7 +358,8 @@ public class GenTableServiceImpl implements IGenTableService { /** * 查询表信息并生成代码 */ - private void generatorCode (String tableName, ZipOutputStream zip) { + private void generatorCode(String tableName, ZipOutputStream zip) + { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); // 设置主子表信息 @@ -357,19 +373,23 @@ public class GenTableServiceImpl implements IGenTableService { // 获取模板列表 List templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) { + for (String template : templates) + { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - try { + try + { // 添加到zip zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); IOUtils.write(sw.toString(), zip, Constants.UTF8); IOUtils.closeQuietly(sw); zip.flush(); zip.closeEntry(); - } catch (IOException e) { + } + catch (IOException e) + { log.error("渲染模板失败,表名:" + table.getTableName(), e); } } @@ -381,49 +401,80 @@ public class GenTableServiceImpl implements IGenTableService { * @param genTable 业务信息 */ @Override - public void validateEdit (GenTable genTable) { - if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) { + public void validateEdit(GenTable genTable) + { + if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) + { String options = JSON.toJSONString(genTable.getParams()); JSONObject paramsObj = JSON.parseObject(options); - if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) { + if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) + { throw new ServiceException("树编码字段不能为空"); - } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) { + } + else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) + { throw new ServiceException("树父编码字段不能为空"); - } else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) { + } + else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) + { throw new ServiceException("树名称字段不能为空"); - } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) { - if (StringUtils.isEmpty(genTable.getSubTableName())) { + } + else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) + { + if (StringUtils.isEmpty(genTable.getSubTableName())) + { throw new ServiceException("关联子表的表名不能为空"); - } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) { + } + else if (StringUtils.isEmpty(genTable.getSubTableFkName())) + { throw new ServiceException("子表关联的外键名不能为空"); } } } } + @Override + public List selDbNameAll() { + return genTableMapper.selDbNameAll(); + } + + @Override + public List selectDbTableListAll() { + return genTableMapper.selectDbTableListAll(); + } + + /** * 设置主键列信息 * * @param table 业务表信息 */ - public void setPkColumn (GenTable table) { - for (GenTableColumn column : table.getColumns()) { - if (column.isPk()) { + public void setPkColumn(GenTable table) + { + for (GenTableColumn column : table.getColumns()) + { + if (column.isPk()) + { table.setPkColumn(column); break; } } - if (StringUtils.isNull(table.getPkColumn())) { + if (StringUtils.isNull(table.getPkColumn())) + { table.setPkColumn(table.getColumns().get(0)); } - if (GenConstants.TPL_SUB.equals(table.getTplCategory())) { - for (GenTableColumn column : table.getSubTable().getColumns()) { - if (column.isPk()) { + if (GenConstants.TPL_SUB.equals(table.getTplCategory())) + { + for (GenTableColumn column : table.getSubTable().getColumns()) + { + if (column.isPk()) + { table.getSubTable().setPkColumn(column); break; } } - if (StringUtils.isNull(table.getSubTable().getPkColumn())) { + if (StringUtils.isNull(table.getSubTable().getPkColumn())) + { table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); } } @@ -434,9 +485,11 @@ public class GenTableServiceImpl implements IGenTableService { * * @param table 业务表信息 */ - public void setSubTable (GenTable table) { + public void setSubTable(GenTable table) + { String subTableName = table.getSubTableName(); - if (StringUtils.isNotEmpty(subTableName)) { + if (StringUtils.isNotEmpty(subTableName)) + { table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); } } @@ -446,9 +499,11 @@ public class GenTableServiceImpl implements IGenTableService { * * @param genTable 设置后的生成对象 */ - public void setTableFromOptions (GenTable genTable) { + public void setTableFromOptions(GenTable genTable) + { JSONObject paramsObj = JSON.parseObject(genTable.getOptions()); - if (StringUtils.isNotNull(paramsObj)) { + if (StringUtils.isNotNull(paramsObj)) + { String treeCode = paramsObj.getString(GenConstants.TREE_CODE); String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); String treeName = paramsObj.getString(GenConstants.TREE_NAME); @@ -462,4 +517,21 @@ public class GenTableServiceImpl implements IGenTableService { genTable.setParentMenuName(parentMenuName); } } + + /** + * 获取代码生成地址 + * + * @param table 业务表信息 + * @param template 模板文件路径 + * @return 生成地址 + */ + public static String getGenPath(GenTable table, String template) + { + String genPath = table.getGenPath(); + if (StringUtils.equals(genPath, "/")) + { + return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table); + } + return genPath + File.separator + VelocityUtils.getFileName(template, table); + } } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableColumnService.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableColumnService.java index b60ea57..e6d4d55 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableColumnService.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableColumnService.java @@ -7,42 +7,41 @@ import java.util.List; /** * 业务字段 服务层 * - * @author muyu + * @author ruoyi */ -public interface IGenTableColumnService { +public interface IGenTableColumnService +{ /** * 查询业务字段列表 * * @param tableId 业务字段编号 - * * @return 业务字段集合 */ - List selectGenTableColumnListByTableId (Long tableId); + public List selectGenTableColumnListByTableId(Long tableId); /** * 新增业务字段 * * @param genTableColumn 业务字段信息 - * * @return 结果 */ - int insertGenTableColumn (GenTableColumn genTableColumn); + public int insertGenTableColumn(GenTableColumn genTableColumn); /** * 修改业务字段 * * @param genTableColumn 业务字段信息 - * * @return 结果 */ - int updateGenTableColumn (GenTableColumn genTableColumn); + public int updateGenTableColumn(GenTableColumn genTableColumn); /** * 删除业务字段信息 * * @param ids 需要删除的数据ID - * * @return 结果 */ - int deleteGenTableColumnByIds (String ids); + public int deleteGenTableColumnByIds(String ids); + + List selectDbTableColumnsByName(String table, String dbName); } diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableService.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableService.java index f34dc37..f79d5e8 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableService.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/IGenTableService.java @@ -1,6 +1,7 @@ package com.muyu.gen.service; import com.muyu.gen.domain.GenTable; +import com.muyu.gen.domain.GenTableResp; import java.util.List; import java.util.Map; @@ -8,124 +9,121 @@ import java.util.Map; /** * 业务 服务层 * - * @author muyu + * @author ruoyi */ -public interface IGenTableService { +public interface IGenTableService +{ /** * 查询业务列表 * * @param genTable 业务信息 - * * @return 业务集合 */ - List selectGenTableList (GenTable genTable); + public List selectGenTableList(GenTable genTable); /** * 查询据库列表 * * @param genTable 业务信息 - * * @return 数据库表集合 */ - List selectDbTableList (GenTable genTable); + public List selectDbTableList(GenTable genTable); /** * 查询据库列表 * * @param tableNames 表名称组 - * + * @param dbName * @return 数据库表集合 */ - List selectDbTableListByNames (String[] tableNames); + public List selectDbTableListByNames(String[] tableNames, String dbName); /** * 查询所有表信息 * * @return 表信息集合 */ - List selectGenTableAll (); + public List selectGenTableAll(); /** * 查询业务信息 * * @param id 业务ID - * * @return 业务信息 */ - GenTable selectGenTableById (Long id); + public GenTable selectGenTableById(Long id); /** * 修改业务 * * @param genTable 业务信息 - * * @return 结果 */ - void updateGenTable (GenTable genTable); + public void updateGenTable(GenTable genTable); /** * 删除业务信息 * * @param tableIds 需要删除的表数据ID - * * @return 结果 */ - void deleteGenTableByIds (Long[] tableIds); + public void deleteGenTableByIds(Long[] tableIds); /** * 导入表结构 * * @param tableList 导入表列表 */ - void importGenTable (List tableList); + public void importGenTable(List tableList); /** * 预览代码 * * @param tableId 表编号 - * * @return 预览数据列表 */ - Map previewCode (Long tableId); + public Map previewCode(Long tableId); /** * 生成代码(下载方式) * * @param tableName 表名称 - * * @return 数据 */ - byte[] downloadCode (String tableName); + public byte[] downloadCode(String tableName); /** * 生成代码(自定义路径) * * @param tableName 表名称 - * * @return 数据 */ - void generatorCode (String tableName); + public void generatorCode(String tableName); /** * 同步数据库 * * @param tableName 表名称 + * @param dbName */ - void synchDb (String tableName); + public void synchDb(String tableName, String dbName); /** * 批量生成代码(下载方式) * * @param tableNames 表数组 - * * @return 数据 */ - byte[] downloadCode (String[] tableNames); + public byte[] downloadCode(String[] tableNames); /** * 修改保存参数校验 * * @param genTable 业务信息 */ - void validateEdit (GenTable genTable); + public void validateEdit(GenTable genTable); + + List selDbNameAll(); + + List selectDbTableListAll(); } diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml index 435f3f0..c2cac97 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 106.15.136.7:8848 user-name: nacos password: nacos - namespace: xzr + namespace: crj # Spring spring: diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml index fb9800e..ea0616b 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -1,58 +1,36 @@ +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - select column_id, - table_id, - column_name, - column_comment, - column_type, - java_type, - java_field, - is_pk, - is_increment, - is_required, - is_insert, - is_edit, - is_list, - is_query, - query_type, - html_type, - dict_type, - sort, - create_by, - create_time, - update_by, - update_time - from gen_table_column + + select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column + select column_name, (case when (is_nullable = 'no' column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type + from information_schema.columns where + + and table_name = (#{tableName}) + order by ordinal_position + insert into gen_table_column ( - table_id, - column_name, - column_comment, - column_type, - java_type, - java_field, - is_pk, - is_increment, - is_required, - is_insert, - is_edit, - is_list, - is_query, - query_type, - html_type, - dict_type, - sort, - create_by, - create_time - )values( - #{tableId}, - #{columnName}, - #{columnComment}, - #{columnType}, - #{javaType}, - #{javaField}, - #{isPk}, - #{isIncrement}, - #{isRequired}, - #{isInsert}, - #{isEdit}, - #{isList}, - #{isQuery}, - #{queryType}, - #{htmlType}, - #{dictType}, - #{sort}, - #{createBy}, - sysdate() - ) + table_id, + column_name, + column_comment, + column_type, + java_type, + java_field, + is_pk, + is_increment, + is_required, + is_insert, + is_edit, + is_list, + is_query, + query_type, + html_type, + dict_type, + sort, + create_by, + create_time + )values( + #{tableId}, + #{columnName}, + #{columnComment}, + #{columnType}, + #{javaType}, + #{javaField}, + #{isPk}, + #{isIncrement}, + #{isRequired}, + #{isInsert}, + #{isEdit}, + #{isList}, + #{isQuery}, + #{queryType}, + #{htmlType}, + #{dictType}, + #{sort}, + #{createBy}, + sysdate() + ) @@ -141,17 +113,20 @@ - delete from gen_table_column where table_id in - + delete from gen_table_column where table_id in ( + #{tableId} + ) + - delete from gen_table_column where column_id in - + delete from gen_table_column where column_id in ( + #{item.columnId} + ) diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableMapper.xml b/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableMapper.xml index 42ab2cf..ba9b0cf 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/cloud-modules/cloud-modules-gen/src/main/resources/mapper/generator/GenTableMapper.xml @@ -1,291 +1,208 @@ +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - select table_id, - table_name, - table_comment, - sub_table_name, - sub_table_fk_name, - class_name, - tpl_category, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - options, - create_by, - create_time, - update_by, - update_time, - remark - from gen_table + + select table_id, db_name, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table + + + + table_schema in (#{dbName}) + + + table_schema = (select database()) + + + + + + + + AND lower(table_name) like lower(concat('%', #{tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) + + + AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + + + AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + + + - + select table_name, table_comment, create_time, update_time from information_schema.tables + where + + AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' + AND table_name NOT IN (select table_name from gen_table) + + AND lower(table_name) like lower(concat('%', #{tableName}, '%')) + + + AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) + + + AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + + + AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + order by create_time desc - + - + select table_name, table_schema db_name, table_comment, create_time, update_time from information_schema.tables + where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' + and + and table_name in + + #{name} - + - + - + - + - + + + + + + insert into gen_table ( - table_name, - table_comment, - class_name, - tpl_category, - package_name, - module_name, - business_name, - function_name, - function_author, - gen_type, - gen_path, - remark, - create_by, - create_time - )values( - #{tableName}, - #{tableComment}, - #{className}, - #{tplCategory}, - #{packageName}, - #{moduleName}, - #{businessName}, - #{functionName}, - #{functionAuthor}, - #{genType}, - #{genPath}, - #{remark}, - #{createBy}, - sysdate() - ) + db_name, + table_name, + table_comment, + class_name, + tpl_category, + package_name, + module_name, + business_name, + function_name, + function_author, + gen_type, + gen_path, + remark, + create_by, + create_time + )values( + #{dbName}, + #{tableName}, + #{tableComment}, + #{className}, + #{tplCategory}, + #{packageName}, + #{moduleName}, + #{businessName}, + #{functionName}, + #{functionAuthor}, + #{genType}, + #{genPath}, + #{remark}, + #{createBy}, + sysdate() + ) update gen_table + db_name = #{dbName}, table_name = #{tableName}, table_comment = #{tableComment}, sub_table_name = #{subTableName}, @@ -294,8 +211,7 @@ function_author = #{functionAuthor}, gen_type = #{genType}, gen_path = #{genPath}, - tpl_category = #{tplCategory}, - package_name = #{packageName}, + tpl_category = #{tplCategory}, package_name = #{packageName}, module_name = #{moduleName}, business_name = #{businessName}, function_name = #{functionName}, @@ -308,10 +224,11 @@ - delete from gen_table where table_id in - + delete from gen_table where table_id in ( + #{tableId} + ) diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/controller.java.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/controller.java.vm index 1df5be0..c62cc8b 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/controller.java.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/controller.java.vm @@ -1,9 +1,9 @@ package ${packageName}.controller; +import java.util.Arrays; import java.util.List; -import java.io.IOException; import jakarta.servlet.http.HttpServletResponse; -import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.Resource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -12,14 +12,14 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.muyu.common.log.annotation.Log; -import com.muyu.common.log.enums.BusinessType; import com.muyu.common.security.annotation.RequiresPermissions; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; import com.muyu.common.core.web.controller.BaseController; import com.muyu.common.core.domain.Result; import com.muyu.common.core.utils.poi.ExcelUtil; +import com.muyu.common.security.utils.SecurityUtils; +import org.springframework.validation.annotation.Validated; #if($table.crud || $table.sub) import com.muyu.common.core.web.page.TableDataInfo; #elseif($table.tree) @@ -35,7 +35,7 @@ import com.muyu.common.core.web.page.TableDataInfo; @RequestMapping("/${businessName}") public class ${ClassName}Controller extends BaseController { - @Autowired + @Resource private I${ClassName}Service ${className}Service; /** @@ -44,14 +44,14 @@ public class ${ClassName}Controller extends BaseController @RequiresPermissions("${permissionPrefix}:list") @GetMapping("/list") #if($table.crud || $table.sub) - public Result list(${ClassName} ${className}) + public Result> list(${ClassName} ${className}) { startPage(); List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); return getDataTable(list); } #elseif($table.tree) - public Result list(${ClassName} ${className}) + public Result<${ClassName}> list(${ClassName} ${className}) { List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); return success(list); @@ -62,7 +62,6 @@ public class ${ClassName}Controller extends BaseController * 导出${functionName}列表 */ @RequiresPermissions("${permissionPrefix}:export") - @Log(title = "${functionName}", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, ${ClassName} ${className}) { @@ -76,7 +75,7 @@ public class ${ClassName}Controller extends BaseController */ @RequiresPermissions("${permissionPrefix}:query") @GetMapping(value = "/{${pkColumn.javaField}}") - public Result getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) + public Result> getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) { return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField})); } @@ -85,32 +84,40 @@ public class ${ClassName}Controller extends BaseController * 新增${functionName} */ @RequiresPermissions("${permissionPrefix}:add") - @Log(title = "${functionName}", businessType = BusinessType.INSERT) @PostMapping - public Result add(@RequestBody ${ClassName} ${className}) + public Result add( + @Validated @RequestBody ${ClassName} ${className}) { - return toAjax(${className}Service.insert${ClassName}(${className})); + if (${className}Service.checkIdUnique(${className})) { + return error("新增 ${functionName} '" + ${className} + "'失败,${functionName}已存在"); + } + ${className}.setCreateBy(SecurityUtils.getUsername()); + return toAjax(${className}Service.save(${className})); } /** * 修改${functionName} */ @RequiresPermissions("${permissionPrefix}:edit") - @Log(title = "${functionName}", businessType = BusinessType.UPDATE) @PutMapping - public Result edit(@RequestBody ${ClassName} ${className}) + public Result edit( + @Validated @RequestBody ${ClassName} ${className}) { - return toAjax(${className}Service.update${ClassName}(${className})); + if (!${className}Service.checkIdUnique(${className})) { + return error("修改 ${functionName} '" + ${className} + "'失败,${functionName}不存在"); + } + ${className}.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(${className}Service.updateById(${className})); } /** * 删除${functionName} */ @RequiresPermissions("${permissionPrefix}:remove") - @Log(title = "${functionName}", businessType = BusinessType.DELETE) @DeleteMapping("/{${pkColumn.javaField}s}") - public Result remove(@PathVariable("${pkColumn.javaField}s") ${pkColumn.javaType}[] ${pkColumn.javaField}s) + public Result remove(@PathVariable("${pkColumn.javaField}s") ${pkColumn.javaType}[] ${pkColumn.javaField}s) { - return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s)); + ${className}Service.removeBatchByIds(Arrays.asList(${pkColumn.javaField}s)); + return success(); } } diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/domain.java.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/domain.java.vm index 1292991..4c89918 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/domain.java.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/domain.java.vm @@ -9,6 +9,13 @@ import com.muyu.common.core.web.domain.BaseEntity; #elseif($table.tree) import com.muyu.common.core.web.domain.TreeEntity; #end +import lombok.*; +import lombok.experimental.SuperBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; /** * ${functionName}对象 ${tableName} @@ -16,13 +23,20 @@ import com.muyu.common.core.web.domain.TreeEntity; * @author ${author} * @date ${datetime} */ + #if($table.crud || $table.sub) #set($Entity="BaseEntity") #elseif($table.tree) #set($Entity="TreeEntity") #end -public class ${ClassName} extends ${Entity} -{ +@Data +@Setter +@Getter +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +@TableName("${tableName}") +public class ${ClassName} extends ${Entity}{ private static final long serialVersionUID = 1L; #foreach ($column in $columns) @@ -44,33 +58,19 @@ public class ${ClassName} extends ${Entity} @Excel(name = "${comment}") #end #end + #if($column.javaField == $pkColumn.javaField) + @TableId( type = IdType.AUTO) + #end private $column.javaType $column.javaField; #end #end + #if($table.sub) /** $table.subTable.functionName信息 */ private List<${subClassName}> ${subclassName}List; #end -#foreach ($column in $columns) -#if(!$table.isSuperColumn($column.javaField)) -#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) -#set($AttrName=$column.javaField) -#else -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) -#end - public void set${AttrName}($column.javaType $column.javaField) - { - this.$column.javaField = $column.javaField; - } - - public $column.javaType get${AttrName}() - { - return $column.javaField; - } -#end -#end #if($table.sub) public List<${subClassName}> get${subClassName}List() diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/mapper.java.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/mapper.java.vm index 7e7d7c2..e6f420b 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/mapper.java.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/mapper.java.vm @@ -5,87 +5,16 @@ import ${packageName}.domain.${ClassName}; #if($table.sub) import ${packageName}.domain.${subClassName}; #end +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; /** * ${functionName}Mapper接口 - * + * * @author ${author} * @date ${datetime} */ -public interface ${ClassName}Mapper -{ - /** - * 查询${functionName} - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return ${functionName} - */ - public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); +@Mapper +public interface ${ClassName}Mapper extends BaseMapper<${ClassName}>{ - /** - * 查询${functionName}列表 - * - * @param ${className} ${functionName} - * @return ${functionName}集合 - */ - public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); - - /** - * 新增${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int insert${ClassName}(${ClassName} ${className}); - - /** - * 修改${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int update${ClassName}(${ClassName} ${className}); - - /** - * 删除${functionName} - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); - - /** - * 批量删除${functionName} - * - * @param ${pkColumn.javaField}s 需要删除的数据主键集合 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); -#if($table.sub) - - /** - * 批量删除${subTable.functionName} - * - * @param ${pkColumn.javaField}s 需要删除的数据主键集合 - * @return 结果 - */ - public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); - - /** - * 批量新增${subTable.functionName} - * - * @param ${subclassName}List ${subTable.functionName}列表 - * @return 结果 - */ - public int batch${subClassName}(List<${subClassName}> ${subclassName}List); - - - /** - * 通过${functionName}主键删除${subTable.functionName}信息 - * - * @param ${pkColumn.javaField} ${functionName}ID - * @return 结果 - */ - public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); -#end } diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/service.java.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/service.java.vm index 264882b..1a01fae 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/service.java.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/service.java.vm @@ -2,18 +2,18 @@ package ${packageName}.service; import java.util.List; import ${packageName}.domain.${ClassName}; +import com.baomidou.mybatisplus.extension.service.IService; /** * ${functionName}Service接口 - * + * * @author ${author} * @date ${datetime} */ -public interface I${ClassName}Service -{ +public interface I${ClassName}Service extends IService<${ClassName}> { /** - * 查询${functionName} - * + * 精确查询${functionName} + * * @param ${pkColumn.javaField} ${functionName}主键 * @return ${functionName} */ @@ -21,41 +21,17 @@ public interface I${ClassName}Service /** * 查询${functionName}列表 - * + * * @param ${className} ${functionName} * @return ${functionName}集合 */ public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); /** - * 新增${functionName} - * + * 判断 ${functionName} id是否唯一 * @param ${className} ${functionName} * @return 结果 */ - public int insert${ClassName}(${ClassName} ${className}); + Boolean checkIdUnique(${ClassName} ${className}); - /** - * 修改${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ - public int update${ClassName}(${ClassName} ${className}); - - /** - * 批量删除${functionName} - * - * @param ${pkColumn.javaField}s 需要删除的${functionName}主键集合 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); - - /** - * 删除${functionName}信息 - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return 结果 - */ - public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}); } diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/serviceImpl.java.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/serviceImpl.java.vm index 3904af5..38f1eca 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/serviceImpl.java.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/serviceImpl.java.vm @@ -7,7 +7,6 @@ import com.muyu.common.core.utils.DateUtils; #break #end #end -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; #if($table.sub) import java.util.ArrayList; @@ -18,6 +17,10 @@ import ${packageName}.domain.${subClassName}; import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.common.core.utils.StringUtils; +import org.springframework.util.Assert; /** * ${functionName}Service业务层处理 @@ -26,13 +29,12 @@ import ${packageName}.service.I${ClassName}Service; * @date ${datetime} */ @Service -public class ${ClassName}ServiceImpl implements I${ClassName}Service -{ - @Autowired - private ${ClassName}Mapper ${className}Mapper; +public class ${ClassName}ServiceImpl + extends ServiceImpl<${ClassName}Mapper, ${ClassName}> + implements I${ClassName}Service { /** - * 查询${functionName} + * 精确查询${functionName} * * @param ${pkColumn.javaField} ${functionName}主键 * @return ${functionName} @@ -40,9 +42,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service @Override public ${ClassName} select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) { - return ${className}Mapper.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); + LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>(); + Assert.notNull(${pkColumn.javaField}, "${pkColumn.javaField}不可为空"); + queryWrapper.eq(${ClassName}::get${pkColumn.capJavaField}, ${pkColumn.javaField}); + return this.getOne(queryWrapper); } + /** * 查询${functionName}列表 * @@ -52,118 +58,58 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service @Override public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) { - return ${className}Mapper.select${ClassName}List(${className}); - } - - /** - * 新增${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ -#if($table.sub) - @Transactional -#end - @Override - public int insert${ClassName}(${ClassName} ${className}) - { -#foreach ($column in $columns) -#if($column.javaField == 'createTime') - ${className}.setCreateTime(DateUtils.getNowDate()); -#end -#end -#if($table.sub) - int rows = ${className}Mapper.insert${ClassName}(${className}); - insert${subClassName}(${className}); - return rows; -#else - return ${className}Mapper.insert${ClassName}(${className}); -#end - } - - /** - * 修改${functionName} - * - * @param ${className} ${functionName} - * @return 结果 - */ -#if($table.sub) - @Transactional -#end - @Override - public int update${ClassName}(${ClassName} ${className}) - { -#foreach ($column in $columns) -#if($column.javaField == 'updateTime') - ${className}.setUpdateTime(DateUtils.getNowDate()); -#end -#end -#if($table.sub) - ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}()); - insert${subClassName}(${className}); -#end - return ${className}Mapper.update${ClassName}(${className}); - } - - /** - * 批量删除${functionName} - * - * @param ${pkColumn.javaField}s 需要删除的${functionName}主键 - * @return 结果 - */ -#if($table.sub) - @Transactional -#end - @Override - public int delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaType}[] ${pkColumn.javaField}s) - { -#if($table.sub) - ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s); -#end - return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s); - } - - /** - * 删除${functionName}信息 - * - * @param ${pkColumn.javaField} ${functionName}主键 - * @return 结果 - */ -#if($table.sub) - @Transactional -#end - @Override - public int delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaType} ${pkColumn.javaField}) - { -#if($table.sub) - ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); -#end - return ${className}Mapper.delete${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}); - } -#if($table.sub) - - /** - * 新增${subTable.functionName}信息 - * - * @param ${className} ${functionName}对象 - */ - public void insert${subClassName}(${ClassName} ${className}) - { - List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); - ${pkColumn.javaType} ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); - if (StringUtils.isNotNull(${subclassName}List)) - { - List<${subClassName}> list = new ArrayList<${subClassName}>(); - for (${subClassName} ${subclassName} : ${subclassName}List) - { - ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField}); - list.add(${subclassName}); - } - if (list.size() > 0) - { - ${className}Mapper.batch${subClassName}(list); - } + LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>(); +#foreach($column in $columns) + #set($queryType=$column.queryType) + #set($javaField=$column.javaField) + #set($javaType=$column.javaType) + #set($columnName=$column.columnName) + #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) + #if($column.query) + #if($column.queryType == "EQ") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.eq(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); } - } + #elseif($queryType == "NE") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.ne(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); + } + #elseif($queryType == "GT") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.gt(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); + } + #elseif($queryType == "GTE") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.ge(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); + } + #elseif($queryType == "LT") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.lt(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); + } + #elseif($queryType == "LTE") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.le(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); + } + #elseif($queryType == "LIKE") + if (StringUtils.isNotEmpty(${className}.get${AttrName}())){ + queryWrapper.like(${ClassName}::get${AttrName}, ${className}.get${AttrName}()); + } + #end + #end #end + return this.list(queryWrapper); + } + + /** + * 唯一 判断 + * @param ${className} ${functionName} + * @return ${functionName} + */ + @Override + public Boolean checkIdUnique(${ClassName} ${className}) { + LambdaQueryWrapper<${ClassName}> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(${ClassName}::get${pkColumn.capJavaField}, ${className}.get${pkColumn.capJavaField}()); + return this.count(queryWrapper) > 0; + } + } diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/sub-domain.java.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/sub-domain.java.vm index a5c170c..61c6273 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/sub-domain.java.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/java/sub-domain.java.vm @@ -17,8 +17,7 @@ import com.muyu.common.core.web.domain.BaseEntity; @NoArgsConstructor @AllArgsConstructor @EqualsAndHashCode(callSuper = true) -public class ${subClassName} extends BaseEntity -{ +public class ${subClassName} extends BaseEntity { private static final long serialVersionUID = 1L; #foreach ($column in $subTable.columns) diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/vm/vue/index.vue.vm b/cloud-modules/cloud-modules-gen/src/main/resources/vm/vue/index.vue.vm index 6296014..cf9b3b0 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/vm/vue/index.vue.vm +++ b/cloud-modules/cloud-modules-gen/src/main/resources/vm/vue/index.vue.vm @@ -170,7 +170,7 @@ - +