diff --git a/entrance/src/main/java/com/njcn/gather/EntranceApplication.java b/entrance/src/main/java/com/njcn/gather/EntranceApplication.java index c1a52fa4..5e43f8f5 100644 --- a/entrance/src/main/java/com/njcn/gather/EntranceApplication.java +++ b/entrance/src/main/java/com/njcn/gather/EntranceApplication.java @@ -1,13 +1,13 @@ package com.njcn.gather; import lombok.extern.slf4j.Slf4j; -//import org.mybatis.spring.annotation.MapperScan; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @Slf4j -//@MapperScan("com.njcn.**.mapper") +@MapperScan("com.njcn.**.mapper") @SpringBootApplication(scanBasePackages = "com.njcn") public class EntranceApplication { diff --git a/entrance/src/main/resources/application.yml b/entrance/src/main/resources/application.yml index 3ef3178f..b65e0c11 100644 --- a/entrance/src/main/resources/application.yml +++ b/entrance/src/main/resources/application.yml @@ -3,6 +3,43 @@ server: spring: application: name: entrance + datasource: + druid: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=CTT + username: root + password: njcnpqs + #初始化建立物理连接的个数、最小、最大连接数 + initial-size: 5 + min-idle: 5 + max-active: 50 + #获取连接最大等待时间,单位毫秒 + max-wait: 60000 + #链接保持空间而不被驱逐的最长时间,单位毫秒 + min-evictable-idle-time-millis: 300000 + validation-query: select 1 + test-while-idle: true + test-on-borrow: false + test-on-return: false + pool-prepared-statements: true + max-pool-prepared-statement-per-connection-size: 20 + +#mybatis配置信息 +mybatis-plus: + mapper-locations: classpath*:com/njcn/**/mapping/*.xml + #别名扫描 + type-aliases-package: com.njcn.gather.system.dictionary.pojo.po + configuration: + #驼峰命名 + map-underscore-to-camel-case: true + #配置sql日志输出 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + #关闭日志输出 + #log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl + global-config: + db-config: + #指定主键生成策略 + id-type: assign_uuid log: homeDir: D:\logs diff --git a/system/pom.xml b/system/pom.xml index 4c16e371..2785ef0f 100644 --- a/system/pom.xml +++ b/system/pom.xml @@ -16,11 +16,11 @@ 0.0.1 - - - - - + + com.njcn + mybatis-plus + 0.0.1 + com.njcn diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java new file mode 100644 index 00000000..fc24b03f --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictDataController.java @@ -0,0 +1,155 @@ +package com.njcn.gather.system.dictionary.controller; + + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.constant.OperateType; +import com.njcn.common.pojo.enums.common.LogEnum; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.LogUtil; +import com.njcn.gather.system.dictionary.pojo.param.DictDataParam; +import com.njcn.gather.system.dictionary.pojo.po.DictData; +import com.njcn.gather.system.dictionary.service.IDictDataService; +import com.njcn.web.controller.BaseController; +import com.njcn.web.pojo.dto.SimpleTreeDTO; +import com.njcn.web.utils.HttpResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author hongawen + * @since 2021-12-13 + */ +@Validated +@Slf4j +@Api(tags = "字典数据操作") +@RestController +@RequestMapping("/dictData") +@RequiredArgsConstructor +public class DictDataController extends BaseController { + + private final IDictDataService dictDataService; + + /** + * 根据字典类型id分页查询字典数据 + */ + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/getTypeIdData") + @ApiOperation("根据字典类型id查询字典数据") + @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true) + public HttpResult> getTypeIdData(@RequestBody @Validated DictDataParam.DicTypeIdQueryParam queryParam) { + String methodDescribe = getMethodDescribe("list"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam); + Page result = dictDataService.getTypeIdData(queryParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + + /** + * 新增字典数据 + * + * @param dictDataParam 字典数据 + */ + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD) + @PostMapping("/add") + @ApiOperation("新增字典数据") + @ApiImplicitParam(name = "dictDataParam", value = "字典数据", required = true) + public HttpResult add(@RequestBody @Validated DictDataParam dictDataParam) { + String methodDescribe = getMethodDescribe("add"); + LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, dictDataParam); + boolean result = dictDataService.addDictData(dictDataParam); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } + + /** + * 修改字典数据 + */ + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) + @PostMapping("/update") + @ApiOperation("修改字典数据") + @ApiImplicitParam(name = "updateParam", value = "字典数据", required = true) + public HttpResult update(@RequestBody @Validated DictDataParam.DictDataUpdateParam updateParam) { + String methodDescribe = getMethodDescribe("update"); + LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, updateParam); + boolean result = dictDataService.updateDictData(updateParam); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } + + + /** + * 批量删除字典数据 + */ + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) + @PostMapping("/delete") + @ApiOperation("删除字典数据") + @ApiImplicitParam(name = "ids", value = "字典索引", required = true, dataTypeClass = List.class) + public HttpResult delete(@RequestBody List ids) { + String methodDescribe = getMethodDescribe("delete"); + LogUtil.njcnDebug(log, "{},字典ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids)); + boolean result = dictDataService.deleteDictData(ids); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } + + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/getDicDataById") + @ApiOperation("根据字典id查询字典数据") + @ApiImplicitParam(name = "dicIndex", value = "查询参数", required = true) + public HttpResult getDicDataById(@RequestParam("dicIndex") String dicIndex) { + String methodDescribe = getMethodDescribe("getDicDataById"); + DictData result = dictDataService.getDicDataById(dicIndex); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/getDicDataByCode") + @ApiOperation("根据字典code查询字典数据") + @ApiImplicitParam(name = "code", value = "查询参数", required = true) + public HttpResult getDicDataByCode(@RequestParam("code") String code) { + String methodDescribe = getMethodDescribe("getDicDataByCode"); + DictData result = dictDataService.getDicDataByCode(code); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + + /** + * 获取所有字典数据基础信息 + */ + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/dictDataCache") + @ApiOperation("获取所有字典数据缓存到前端") + public HttpResult> dictDataCache() { + String methodDescribe = getMethodDescribe("dictDataCache"); + LogUtil.njcnDebug(log, "{},获取所有字典数据缓存到前端", methodDescribe); + List dictData = dictDataService.dictDataCache(); + if (CollectionUtil.isNotEmpty(dictData)) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dictData, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe); + } + } + +} + diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java new file mode 100644 index 00000000..836a5843 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTypeController.java @@ -0,0 +1,119 @@ +package com.njcn.gather.system.dictionary.controller; + + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.constant.OperateType; +import com.njcn.common.pojo.enums.common.DataStateEnum; +import com.njcn.common.pojo.enums.common.LogEnum; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.LogUtil; +import com.njcn.gather.system.dictionary.pojo.param.DictTypeParam; +import com.njcn.gather.system.dictionary.pojo.po.DictType; +import com.njcn.gather.system.dictionary.service.IDictTypeService; +import com.njcn.web.controller.BaseController; +import com.njcn.web.pojo.dto.SimpleTreeDTO; +import com.njcn.web.utils.HttpResultUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * + * @author hongawen + * @since 2021-12-13 + */ +@Slf4j +@Api(tags = "字典类型表操作") +@RestController +@RequestMapping("/dictType") +@RequiredArgsConstructor +public class DictTypeController extends BaseController { + + private final IDictTypeService dictTypeService; + + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/list") + @ApiOperation("查询字典类型") + @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true) + public HttpResult> list(@RequestBody @Validated DictTypeParam.DictTypeQueryParam queryParam) { + String methodDescribe = getMethodDescribe("list"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam); + Page result = dictTypeService.listDictTypes(queryParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @GetMapping("/listAll") + @ApiOperation("查询所有字典类型数据") + public HttpResult> listAll() { + String methodDescribe = getMethodDescribe("listAll"); + LogUtil.njcnDebug(log, "{}", methodDescribe); + List dictTypeList = dictTypeService.list(new LambdaQueryWrapper().eq(DictType::getState, DataStateEnum.ENABLE.getCode())); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, dictTypeList, methodDescribe); + } + + + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD) + @PostMapping("/add") + @ApiOperation("新增字典类型") + @ApiImplicitParam(name = "dictTypeParam", value = "字典类型数据", required = true) + public HttpResult add(@RequestBody @Validated DictTypeParam dictTypeParam) { + String methodDescribe = getMethodDescribe("add"); + LogUtil.njcnDebug(log, "{},字典类型数据为:{}", methodDescribe, dictTypeParam); + boolean result = dictTypeService.addDictType(dictTypeParam); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } + + + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) + @PostMapping("/update") + @ApiOperation("修改字典类型") + @ApiImplicitParam(name = "updateParam", value = "字典类型数据", required = true) + public HttpResult update(@RequestBody @Validated DictTypeParam.DictTypeUpdateParam updateParam) { + String methodDescribe = getMethodDescribe("update"); + LogUtil.njcnDebug(log, "{},字典类型数据为:{}", methodDescribe, updateParam); + boolean result = dictTypeService.updateDictType(updateParam); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } + + + + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE) + @PostMapping("/delete") + @ApiOperation("删除字典类型") + @ApiImplicitParam(name = "ids", value = "字典索引", required = true) + public HttpResult delete(@RequestBody List ids) { + String methodDescribe = getMethodDescribe("delete"); + LogUtil.njcnDebug(log, "{},字典ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids)); + boolean result = dictTypeService.deleteDictType(ids); + if (result) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } else { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe); + } + } + + + +} + diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/mapper/DictDataMapper.java b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/DictDataMapper.java new file mode 100644 index 00000000..219c6151 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/DictDataMapper.java @@ -0,0 +1,19 @@ +package com.njcn.gather.system.dictionary.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.njcn.gather.system.dictionary.pojo.po.DictData; + + + +/** + *

+ * Mapper 接口 + *

+ * + * @author hongawen + * @since 2021-12-13 + */ +public interface DictDataMapper extends MPJBaseMapper { + + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/mapper/DictTypeMapper.java b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/DictTypeMapper.java new file mode 100644 index 00000000..717cd486 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/DictTypeMapper.java @@ -0,0 +1,15 @@ +package com.njcn.gather.system.dictionary.mapper; + +import com.github.yulichang.base.MPJBaseMapper; +import com.njcn.gather.system.dictionary.pojo.po.DictType; + + +/** + + * + * @author hongawen + * @since 2021-12-13 + */ +public interface DictTypeMapper extends MPJBaseMapper { + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/mapper/mapping/DictDataMapper.xml b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/mapping/DictDataMapper.xml new file mode 100644 index 00000000..e917862f --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/mapping/DictDataMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/mapper/mapping/DictTypeMapper.xml b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/mapping/DictTypeMapper.xml new file mode 100644 index 00000000..6fba457c --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/mapper/mapping/DictTypeMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/constant/SystemValidMessage.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/constant/SystemValidMessage.java new file mode 100644 index 00000000..b64a66d7 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/constant/SystemValidMessage.java @@ -0,0 +1,72 @@ +package com.njcn.gather.system.dictionary.pojo.constant; + +/** + * @author hongawen + * @version 1.0 + * @data 2024/10/30 14:46 + */ +public interface SystemValidMessage { + + + String MISS_PREFIX="字段不能为空,请检查"; + + + String ID_NOT_BLANK = "id不能为空,请检查id参数"; + + String ID_FORMAT_ERROR = "id格式错误,请检查id参数"; + + String DICT_TYPE_ID_NOT_BLANK = "typeId不能为空,请检查typeId参数"; + + String DICT_TYPE_ID_FORMAT_ERROR = "typeId格式错误,请检查typeId参数"; + + String NAME_NOT_BLANK = "名称不能为空,请检查name参数"; + + String NAME_FORMAT_ERROR = "名称格式错误,请检查name参数"; + + String INDUSTRY_NOT_BLANK = "行业不能为空,请检查industry参数"; + String INDUSTRY_FORMAT_ERROR = "行业格式错误,请检查industry参数"; + String ADDR_NOT_BLANK = "所属区域不能为空,请检查addr参数"; + + String CODE_NOT_BLANK = "编号不能为空,请检查code参数"; + + String CODE_FORMAT_ERROR = "编号格式错误,请检查code参数"; + + String SORT_NOT_NULL = "排序不能为空,请检查sort参数"; + + String SORT_FORMAT_ERROR = "排序格式错误,请检查sort参数"; + + String OPEN_LEVEL_NOT_NULL = "开启等级不能为空,请检查openLevel参数"; + + String OPEN_LEVEL_FORMAT_ERROR = "开启等级格式错误,请检查openLevel参数"; + + String OPEN_DESCRIBE_NOT_NULL = "开启描述不能为空,请检查openDescribe参数"; + + String OPEN_DESCRIBE_FORMAT_ERROR = "开启描述格式错误,请检查openDescribe参数"; + + String AREA_NOT_BLANK = "行政区域不能为空,请检查area参数"; + + String AREA_FORMAT_ERROR = "行政区域格式错误,请检查area参数"; + + String PID_NOT_BLANK = "父节点不能为空,请检查pid参数"; + + String PID_FORMAT_ERROR = "父节点格式错误,请检查pid参数"; + + String COLOR_NOT_BLANK = "主题色不能为空,请检查color参数"; + + String COLOR_FORMAT_ERROR = "主题色格式错误,请检查color参数"; + + String LOGO_NOT_BLANK = "iconUrl不能为空,请检查iconUrl参数"; + + String FAVICON_NOT_BLANK = "faviconUrl不能为空,请检查faviconUrl参数"; + + String REMARK_NOT_BLANK = "描述不能为空,请检查remark参数"; + + String REMARK_FORMAT_ERROR = "描述格式错误,请检查remark参数"; + + String PARAM_FORMAT_ERROR = "参数值非法"; + + String IP_FORMAT_ERROR = "IP格式非法"; + + String DEVICE_VERSION_NOT_BLANK = "装置版本json文件不能为空,请检查deviceVersionFile参数"; + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/dto/DictDataCache.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/dto/DictDataCache.java new file mode 100644 index 00000000..03304563 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/dto/DictDataCache.java @@ -0,0 +1,33 @@ +package com.njcn.gather.system.dictionary.pojo.dto; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author hongawen + * @version 1.0 + * @data 2024/10/30 15:52 + */ +@Data +public class DictDataCache implements Serializable { + + private String id; + + private String name; + + private String code; + + private String value; + + private int sort; + + private String typeId; + + private String typeName; + + private String typeCode; + + private Integer algoDescribe; + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/enums/SystemResponseEnum.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/enums/SystemResponseEnum.java new file mode 100644 index 00000000..57ab0248 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/enums/SystemResponseEnum.java @@ -0,0 +1,75 @@ +package com.njcn.gather.system.dictionary.pojo.enums; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月20日 09:56 + */ +@Getter +public enum SystemResponseEnum { + + /** + * 系统模块异常响应码的范围: + * A00350 ~ A00449 + */ + SYSTEM_COMMON_ERROR("A00350","系统模块异常"), + DICT_TYPE_NAME_REPEAT("A00351", "字典类型名称重复"), + DICT_DATA_NAME_REPEAT("A00352", "字典数据名称重复"), + AREA_CODE_REPEAT("A00353","行政区域编码重复"), + LOAD_TYPE_EMPTY("A00354","用能负荷数据为空"), + LINE_MARK_EMPTY("A00355","字典监测点评分等级数据为空"), + VOLTAGE_EMPTY("A00356","查询字典电压等级数据为空"), + + INTERFERENCE_EMPTY("A00356","查询字典干扰源类型数据为空"), + BUSINESS_EMPTY("A00356","查询字典行业类型数据为空"), + SYSTEM_TYPE_EMPTY("A00356","查询字典系统类型数据为空"), + DEV_TYPE_EMPTY("A00357","查询字典设备类型数据为空"), + MANUFACTURER("A00358","查询字典终端厂家数据为空"), + DEV_VARIETY("A00359","查询字典终端类型数据为空"), + + /*pms*/ + LINE_TYPE_VARIETY_EMPTY("A00360","查询字典监测点类型数据为空"), + LINE_STATE_EMPTY("A00361","查询字典监测点状态为空"), + LINE_TYPE_EMPTY("A00362","查询字典监测点类型状态为空"), + POTENTIAL_TYPE_EMPTY("A00363","查询字典电压互感器类型为空"), + Neutral_Mode_EMPTY("A00364","查询字典中性点接地方式为空"), + MONITOR_TAG_EMPTY("A00365","查询字典监测点标签类型为空"), + MONITORY_TYPE_EMPTY("A00366","查询字典监测对象类型为空"), + TERMINAL_WIRING_EMPTY("A00367","查询字典监测终端接线方式为空"), + MONITOR_TYPE_EMPTY("A00368","查询字典监测点类别为空"), + ACTIVATED_STATE("A00369","必须存在一个已激活的系统类型"), + ADVANCE_REASON("A00370","查询字典暂降原因为空"), + EFFECT_STATUS_EMPTY("A00370","查询字典实施状态为空"), + + EVENT_REPORT_REPEAT("A00361","暂态报告模板重复"), + NOT_EXISTED("A00361", "您查询的该条记录不存在"), + TIMER_NO_CLASS("A00361", "请检查定时任务是否添加"), + + /** + * 定时任务执行类不存在 + */ + TIMER_NOT_EXISTED("A00361", "定时任务执行类不存在"), + EXE_EMPTY_PARAM("A00361", "请检查定时器的id,定时器cron表达式,定时任务是否为空!"), + + /** + * 审计日志模块异常响应 + */ + NOT_FIND_FILE("A0300", "文件未备份或者备份文件为空,请先备份文件"), + LOG_EXCEPTION("A0301", "导入旧日志文件异常"), + LOG_EXCEPTION_TIME("A0302", "导入旧日志文件异常:缺少时间范围"), + DELETE_DATA("A0303", "导入旧日志文件异常:删除数据失败"), + MULTIPLE_CLICKS_LOG_FILE_WRITER("A0304", "当前文件备份数据未结束,请勿多次点击"), + MULTIPLE_CLICKS_RECOVER_LOG_FILE("A0303", "当前文件恢复数据未结束,请勿多次点击") + ; + + private final String code; + + private final String message; + + SystemResponseEnum(String code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java new file mode 100644 index 00000000..e72bc135 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java @@ -0,0 +1,97 @@ +package com.njcn.gather.system.dictionary.pojo.param; + +import com.njcn.common.pojo.constant.PatternRegex; +import com.njcn.gather.system.dictionary.pojo.constant.SystemValidMessage; +import com.njcn.web.pojo.param.BaseParam; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.*; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月17日 15:49 + */ +@Data +public class DictDataParam { + + + @ApiModelProperty("字典类型id") + @NotBlank(message = SystemValidMessage.DICT_TYPE_ID_NOT_BLANK) + @Pattern(regexp = PatternRegex.SYSTEM_ID, message = SystemValidMessage.DICT_TYPE_ID_FORMAT_ERROR) + private String typeId; + + + @ApiModelProperty("名称") + @NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) + @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) + private String name; + + + @ApiModelProperty("编码") + @NotBlank(message = SystemValidMessage.CODE_NOT_BLANK) + @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.CODE_FORMAT_ERROR) + private String code; + + + @ApiModelProperty("排序") + @NotNull(message = SystemValidMessage.SORT_NOT_NULL) + @Min(value = 0, message = SystemValidMessage.SORT_FORMAT_ERROR) + @Max(value = 999, message = SystemValidMessage.SORT_FORMAT_ERROR) + private Integer sort; + + + @ApiModelProperty("事件等级:0-普通;1-中等;2-严重(默认为0)") + private Integer level; + + @ApiModelProperty("与高级算法内部Id描述对应") + private Integer algoDescribe; + + + @ApiModelProperty("字典值,用于记录字典的计算值如10kV记录为 10") + private String value; + + + /** + * 更新操作实体 + */ + @Data + @EqualsAndHashCode(callSuper = true) + public static class DictDataUpdateParam extends DictDataParam { + + /** + * 表Id + */ + @ApiModelProperty("id") + @NotBlank(message = SystemValidMessage.ID_NOT_BLANK) + @Pattern(regexp = PatternRegex.SYSTEM_ID, message = SystemValidMessage.ID_FORMAT_ERROR) + private String id; + } + + /** + * 分页查询实体 + */ + @Data + @EqualsAndHashCode(callSuper = true) + public static class DictDataQueryParam extends BaseParam { + + + + } + + /** + * 根据字典类型id分页查询字典数据 + */ + @Data + @EqualsAndHashCode(callSuper = true) + public static class DicTypeIdQueryParam extends BaseParam { + @ApiModelProperty("字典类型id") + @NotBlank(message = SystemValidMessage.DICT_TYPE_ID_NOT_BLANK) + @Pattern(regexp = PatternRegex.SYSTEM_ID, message = SystemValidMessage.DICT_TYPE_ID_FORMAT_ERROR) + private String typeId; + + } + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java new file mode 100644 index 00000000..a8d4b58f --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java @@ -0,0 +1,81 @@ +package com.njcn.gather.system.dictionary.pojo.param; + +import com.njcn.common.pojo.constant.PatternRegex; +import com.njcn.gather.system.dictionary.pojo.constant.SystemValidMessage; +import com.njcn.web.pojo.param.BaseParam; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.*; + +/** + * @author hongawen + * @version 1.0 + * @data 2024/10/30 14:39 + */ +@Data +public class DictTypeParam { + + @ApiModelProperty("名称") + @NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) + @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) + private String name; + + @ApiModelProperty("编码") + @NotBlank(message = SystemValidMessage.CODE_NOT_BLANK) + @Pattern(regexp = PatternRegex.ALL_CHAR_1_20, message = SystemValidMessage.CODE_FORMAT_ERROR) + private String code; + + + @ApiModelProperty("排序") + @NotNull(message = SystemValidMessage.SORT_NOT_NULL) + @Min(value = 0, message = SystemValidMessage.SORT_FORMAT_ERROR) + @Max(value = 999, message = SystemValidMessage.SORT_FORMAT_ERROR) + private Integer sort; + + + @ApiModelProperty("开启等级:0-不开启;1-开启,默认不开启") + @NotNull(message = SystemValidMessage.OPEN_LEVEL_NOT_NULL) + @Min(value = 0, message = SystemValidMessage.OPEN_LEVEL_FORMAT_ERROR) + @Max(value = 1, message = SystemValidMessage.OPEN_LEVEL_FORMAT_ERROR) + private Integer openLevel; + + + @ApiModelProperty("开启算法描述:0-不开启;1-开启,默认不开启") + @NotNull(message = SystemValidMessage.OPEN_DESCRIBE_NOT_NULL) + @Min(value = 0, message = SystemValidMessage.OPEN_DESCRIBE_FORMAT_ERROR) + @Max(value = 1, message = SystemValidMessage.OPEN_DESCRIBE_FORMAT_ERROR) + private Integer openDescribe; + + + @ApiModelProperty("描述") + private String remark; + + /** + * 更新操作实体 + */ + @Data + @EqualsAndHashCode(callSuper = true) + public static class DictTypeUpdateParam extends DictTypeParam { + + + @ApiModelProperty("id") + @NotBlank(message = SystemValidMessage.ID_NOT_BLANK) + @Pattern(regexp = PatternRegex.SYSTEM_ID, message = SystemValidMessage.ID_FORMAT_ERROR) + private String id; + + } + + /** + * 分页查询实体 + */ + @Data + @EqualsAndHashCode(callSuper = true) + public static class DictTypeQueryParam extends BaseParam { + + + } + +} + diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictData.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictData.java new file mode 100644 index 00000000..dd78f728 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictData.java @@ -0,0 +1,65 @@ +package com.njcn.gather.system.dictionary.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.njcn.db.mybatisplus.bo.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * + * @author hongawen + * @since 2021-12-13 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("sys_dict_data") +public class DictData extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 字典数据表Id + */ + private String id; + + /** + * 字典类型表Id + */ + private String typeId; + + /** + * 名称 + */ + private String name; + + /** + * 编码 + */ + private String code; + + /** + * 排序 + */ + private Integer sort; + + /** + * 事件等级:0-普通;1-中等;2-严重(默认为0) + */ + private Integer level; + + /** + * 与高级算法内部Id描述对应; + */ + private Integer algoDescribe; + + /** + * 目前只用于表示电压等级数值 + */ + private String value; + + /** + * 状态:0-删除 1-正常 + */ + private Integer state; + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictType.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictType.java new file mode 100644 index 00000000..fb0059f0 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictType.java @@ -0,0 +1,62 @@ +package com.njcn.gather.system.dictionary.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.njcn.db.mybatisplus.bo.BaseEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * + * @author hongawen + * @since 2021-12-13 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("sys_dict_type") +public class DictType extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 字典类型表Id + */ + private String id; + + /** + * 名称 + */ + private String name; + + /** + * 编码 + */ + private String code; + + /** + * 排序 + */ + private Integer sort; + + /** + * 开启等级:0-不开启;1-开启,默认不开启 + */ + private Integer openLevel; + + + /** + * 开启描述:0-不开启;1-开启,默认不开启 + */ + private Integer openDescribe; + + + /** + * 描述 + */ + private String remark; + + /** + * 状态:0-删除 1-正常 + */ + private Integer state; + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictDataService.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictDataService.java new file mode 100644 index 00000000..a9dc9d45 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictDataService.java @@ -0,0 +1,71 @@ +package com.njcn.gather.system.dictionary.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.gather.system.dictionary.pojo.param.DictDataParam; +import com.njcn.gather.system.dictionary.pojo.po.DictData; +import com.njcn.web.pojo.dto.SimpleTreeDTO; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author hongawen + * @since 2021-12-13 + */ +public interface IDictDataService extends IService { + + + /** + * 根据字典类型id查询字典信息 + * @param queryParam 查询参数 + * @return 操作结果 + */ + Page getTypeIdData(DictDataParam.DicTypeIdQueryParam queryParam); + + /** + * 新增数据字典 + * @param dictDataParam 字典数据 + * @return 操作结果 + */ + boolean addDictData(DictDataParam dictDataParam); + + + /** + * 更新字典数据 + * @param updateParam 字典数据 + * @return 操作结果 + */ + boolean updateDictData(DictDataParam.DictDataUpdateParam updateParam); + + /** + * 批量逻辑删除字典数据 + * @param ids 字典id集合 + * @return 操作结果 + */ + boolean deleteDictData(List ids); + + /** + * 根据字典id获取字典数据 + * @param dicIndex 查询参数 + * @return 根据字典id查询字典数据 + */ + DictData getDicDataById(String dicIndex); + + + /** + * 根据字典code获取字典数据 + * @param code 字典code + * @return 根据字典code查询字典数据 + */ + DictData getDicDataByCode(String code); + + /** + * 获取所有字典数据基础信息 + * @return 返回所有字典数据 + */ + List dictDataCache(); +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTypeService.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTypeService.java new file mode 100644 index 00000000..a4197965 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTypeService.java @@ -0,0 +1,49 @@ +package com.njcn.gather.system.dictionary.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.gather.system.dictionary.pojo.param.DictTypeParam; +import com.njcn.gather.system.dictionary.pojo.po.DictType; +import com.njcn.web.pojo.dto.SimpleTreeDTO; + +import java.util.List; + +/** + * @author hongawen + * @since 2021-12-13 + */ +public interface IDictTypeService extends IService { + + /** + * 根据前台传递参数,分页查询字典类型数据 + * @param queryParam 查询参数 + * @return 字典列表 + */ + Page listDictTypes(DictTypeParam.DictTypeQueryParam queryParam); + + /** + * 新增字典类型数据 + * + * @param dictTypeParam 字典类型数据 + * @return 操作结果 + */ + boolean addDictType(DictTypeParam dictTypeParam); + + /** + * 修改字典类型 + * + * @param updateParam 字典类型数据 + * @return 操作结果 + */ + boolean updateDictType(DictTypeParam.DictTypeUpdateParam updateParam); + + /** + * 批量逻辑删除字典类型数据 + * @param ids id集合 + * @return 操作结果 + */ + boolean deleteDictType(List ids); + + + +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java new file mode 100644 index 00000000..dd0b7a68 --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictDataServiceImpl.java @@ -0,0 +1,161 @@ +package com.njcn.gather.system.dictionary.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.njcn.common.pojo.enums.common.DataStateEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.db.mybatisplus.constant.DbConstant; +import com.njcn.gather.system.dictionary.mapper.DictDataMapper; +import com.njcn.gather.system.dictionary.pojo.dto.DictDataCache; +import com.njcn.gather.system.dictionary.pojo.enums.SystemResponseEnum; +import com.njcn.gather.system.dictionary.pojo.param.DictDataParam; +import com.njcn.gather.system.dictionary.pojo.po.DictData; +import com.njcn.gather.system.dictionary.pojo.po.DictType; +import com.njcn.gather.system.dictionary.service.IDictDataService; +import com.njcn.web.factory.PageFactory; +import com.njcn.web.pojo.dto.SimpleDTO; +import com.njcn.web.pojo.dto.SimpleTreeDTO; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author hongawen + * @since 2021-12-13 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class DictDataServiceImpl extends ServiceImpl implements IDictDataService { + + @Override + public Page getTypeIdData(DictDataParam.DicTypeIdQueryParam queryParam) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotNull(queryParam)) { + //查询条件待补充,曹泽辉根据页面实际情况调整 todo... + + //排序 + if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) { + queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy())); + } else { + //没有排序参数,默认根据sort字段排序,没有排序字段的,根据updateTime更新时间排序 + queryWrapper.orderBy(true, true, "sys_dict_data.sort"); + } + } + queryWrapper.ne("sys_dict_data.state", DataStateEnum.DELETED.getCode()) + .eq("sys_dict_data.type_id", queryParam.getTypeId()); + //初始化分页数据 + return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); + } + + + @Override + public boolean addDictData(DictDataParam dictDataParam) { + checkDicDataName(dictDataParam, false); + DictData dictData = new DictData(); + BeanUtil.copyProperties(dictDataParam, dictData); + //默认为正常状态 + dictData.setState(DataStateEnum.ENABLE.getCode()); + return this.save(dictData); + } + + + @Override + public boolean updateDictData(DictDataParam.DictDataUpdateParam updateParam) { + checkDicDataName(updateParam, true); + DictData dictData = new DictData(); + BeanUtil.copyProperties(updateParam, dictData); + return this.updateById(dictData); + } + + @Override + public boolean deleteDictData(List ids) { + return this.lambdaUpdate() + .set(DictData::getState, DataStateEnum.DELETED.getCode()) + .in(DictData::getId, ids) + .update(); + } + + + @Override + public DictData getDicDataById(String dicIndex) { + return this.baseMapper.selectById(dicIndex); + } + + + @Override + public DictData getDicDataByCode(String code) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(DictData::getCode,code) + .eq(DictData::getState, DataStateEnum.ENABLE.getCode()); + return this.baseMapper.selectOne(queryWrapper); + } + + @Override + public List dictDataCache() { + MPJLambdaWrapper dictTypeWrapper = new MPJLambdaWrapper() + .selectAll(DictData.class) + .selectAs(DictType::getId, DictDataCache::getTypeId) + .selectAs(DictType::getName,DictDataCache::getTypeName) + .selectAs(DictType::getCode,DictDataCache::getTypeCode) + .leftJoin(DictType.class, DictType::getId, DictData::getTypeId); + List allDictData = this.getBaseMapper().selectJoinList(DictDataCache.class,dictTypeWrapper); + + Map> dictDataCacheMap = allDictData.stream() + .collect(Collectors.groupingBy(DictDataCache::getTypeId)); + return dictDataCacheMap.keySet().stream().map(typeId -> { + SimpleTreeDTO simpleTreeDTO = new SimpleTreeDTO(); + List dictDataCaches = dictDataCacheMap.get(typeId); + List simpleDTOList = dictDataCaches.stream().map(dictDataCache -> { + simpleTreeDTO.setCode(dictDataCache.getTypeCode()); + simpleTreeDTO.setId(dictDataCache.getTypeId()); + simpleTreeDTO.setName(dictDataCache.getTypeName()); + SimpleDTO simpleDTO = new SimpleDTO(); + simpleDTO.setCode(dictDataCache.getCode()); + simpleDTO.setId(dictDataCache.getId()); + simpleDTO.setName(dictDataCache.getName()); + simpleDTO.setSort(dictDataCache.getSort()); + simpleDTO.setValue(dictDataCache.getValue()); + simpleDTO.setAlgoDescribe(dictDataCache.getAlgoDescribe()); + return simpleDTO; + }).sorted(Comparator.comparing(SimpleDTO::getSort)).collect(Collectors.toList()); + simpleTreeDTO.setChildren(simpleDTOList); + return simpleTreeDTO; + }).collect(Collectors.toList()); + } + + + + /** + * 校验参数,检查是否存在相同名称的字典类型 + */ + private void checkDicDataName(DictDataParam dictDataParam, boolean isExcludeSelf) { + LambdaQueryWrapper dictDataLambdaQueryWrapper = new LambdaQueryWrapper<>(); + dictDataLambdaQueryWrapper + .eq(DictData::getName, dictDataParam.getName()) + .eq(DictData::getTypeId, dictDataParam.getTypeId()) + .eq(DictData::getState, DataStateEnum.ENABLE.getCode()); + //更新的时候,需排除当前记录 + if (isExcludeSelf) { + if (dictDataParam instanceof DictDataParam.DictDataUpdateParam) { + dictDataLambdaQueryWrapper.ne(DictData::getId, ((DictDataParam.DictDataUpdateParam) dictDataParam).getId()); + } + } + int countByAccount = this.count(dictDataLambdaQueryWrapper); + //大于等于1个则表示重复 + if (countByAccount >= 1) { + throw new BusinessException(SystemResponseEnum.DICT_DATA_NAME_REPEAT); + } + } +} diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java new file mode 100644 index 00000000..c1fcf89f --- /dev/null +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTypeServiceImpl.java @@ -0,0 +1,98 @@ +package com.njcn.gather.system.dictionary.service.impl; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.common.pojo.enums.common.DataStateEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.db.mybatisplus.constant.DbConstant; +import com.njcn.gather.system.dictionary.mapper.DictTypeMapper; +import com.njcn.gather.system.dictionary.pojo.enums.SystemResponseEnum; +import com.njcn.gather.system.dictionary.pojo.param.DictTypeParam; +import com.njcn.gather.system.dictionary.pojo.po.DictType; +import com.njcn.gather.system.dictionary.service.IDictTypeService; +import com.njcn.web.factory.PageFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author hongawen + * @since 2021-12-13 + */ +@Service +@RequiredArgsConstructor +public class DictTypeServiceImpl extends ServiceImpl implements IDictTypeService { + + @Override + public Page listDictTypes(DictTypeParam.DictTypeQueryParam queryParam) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (ObjectUtil.isNotNull(queryParam)) { + //查询条件待补充,曹泽辉根据页面实际情况调整 todo... + + + //排序 + if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) { + queryWrapper.orderBy(true, queryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy())); + } else { + //没有排序参数,默认根据sort字段排序,没有排序字段的,根据updateTime更新时间排序 + queryWrapper.orderBy(true, true, "sys_dict_type.sort"); + } + } + queryWrapper.ne("sys_dict_type.state", DataStateEnum.DELETED.getCode()); + return this.baseMapper.selectPage(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); + } + + @Override + public boolean addDictType(DictTypeParam dictTypeParam) { + checkDicTypeName(dictTypeParam, false); + DictType dictType = new DictType(); + BeanUtil.copyProperties(dictTypeParam, dictType); + //默认为正常状态 + dictType.setState(DataStateEnum.ENABLE.getCode()); + return this.save(dictType); + } + + @Override + public boolean updateDictType(DictTypeParam.DictTypeUpdateParam updateParam) { + checkDicTypeName(updateParam, true); + DictType dictType = new DictType(); + BeanUtil.copyProperties(updateParam, dictType); + return this.updateById(dictType); + } + + @Override + public boolean deleteDictType(List ids) { + return this.lambdaUpdate() + .set(DictType::getState, DataStateEnum.DELETED.getCode()) + .in(DictType::getId, ids) + .update(); + } + + + /** + * 校验参数,检查是否存在相同名称的字典类型 + */ + private void checkDicTypeName(DictTypeParam dictTypeParam, boolean isExcludeSelf) { + LambdaQueryWrapper dictTypeLambdaQueryWrapper = new LambdaQueryWrapper<>(); + dictTypeLambdaQueryWrapper + .eq(DictType::getName, dictTypeParam.getName()) + .eq(DictType::getState, DataStateEnum.ENABLE.getCode()); + //更新的时候,需排除当前记录 + if (isExcludeSelf) { + if (dictTypeParam instanceof DictTypeParam.DictTypeUpdateParam) { + dictTypeLambdaQueryWrapper.ne(DictType::getId, ((DictTypeParam.DictTypeUpdateParam) dictTypeParam).getId()); + } + } + int countByAccount = this.count(dictTypeLambdaQueryWrapper); + //大于等于1个则表示重复 + if (countByAccount >= 1) { + throw new BusinessException(SystemResponseEnum.DICT_TYPE_NAME_REPEAT); + } + } +}