diff --git a/pqs-system/system-api/pom.xml b/pqs-system/system-api/pom.xml index d6086d6f9..2b29a6086 100644 --- a/pqs-system/system-api/pom.xml +++ b/pqs-system/system-api/pom.xml @@ -39,6 +39,10 @@ 4.4.0 compile + + com.github.jeffreyning + mybatisplus-plus + \ No newline at end of file diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/api/EpdFeignClient.java b/pqs-system/system-api/src/main/java/com/njcn/system/api/EpdFeignClient.java new file mode 100644 index 000000000..57b259e24 --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/api/EpdFeignClient.java @@ -0,0 +1,33 @@ +package com.njcn.system.api; + +import com.njcn.common.pojo.constant.ServerInfo; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.system.api.fallback.EpdFeignClientFallbackFactory; +import com.njcn.system.pojo.param.EleEpdPqdParam; +import com.njcn.system.pojo.po.EleEpdPqd; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; +import java.util.Map; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年05月08日 15:11 + */ +@FeignClient(value = ServerInfo.SYSTEM,path = "/csDictData",fallbackFactory = EpdFeignClientFallbackFactory.class,contextId = "csDictData") +public interface EpdFeignClient { + + @PostMapping("/addByModel") + HttpResult addByModel(@RequestBody List eleEpdPqdParam); + + @PostMapping("/dictMarkByDataType") + HttpResult> dictMarkByDataType(@RequestParam("dataType") String dataType); + + @PostMapping("/addEvt") + HttpResult> addEvt(@RequestBody List eleEpdPqdParam); + +} diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/api/fallback/EpdFeignClientFallbackFactory.java b/pqs-system/system-api/src/main/java/com/njcn/system/api/fallback/EpdFeignClientFallbackFactory.java new file mode 100644 index 000000000..de43e51a4 --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/api/fallback/EpdFeignClientFallbackFactory.java @@ -0,0 +1,56 @@ +package com.njcn.system.api.fallback; + +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.system.api.EpdFeignClient; +import com.njcn.system.pojo.param.EleEpdPqdParam; +import com.njcn.system.pojo.po.EleEpdPqd; +import com.njcn.system.utils.SystemEnumUtil; +import feign.hystrix.FallbackFactory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Map; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/5/24 18:46 + */ +@Slf4j +@Component +public class EpdFeignClientFallbackFactory implements FallbackFactory { + @Override + public EpdFeignClient create(Throwable cause) { + //判断抛出异常是否为解码器抛出的业务异常 + Enum exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK; + if(cause.getCause() instanceof BusinessException){ + BusinessException businessException = (BusinessException) cause.getCause(); + exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult()); + } + Enum finalExceptionEnum = exceptionEnum; + return new EpdFeignClient() { + @Override + public HttpResult addByModel(List eleEpdPqdParam) { + log.error("{}异常,降级处理,异常为:{}","通过模板录入字典数据",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + + @Override + public HttpResult> dictMarkByDataType(String dataType) { + log.error("{}异常,降级处理,异常为:{}","通过数据模型获取字典数据组装唯一标识",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + + @Override + public HttpResult> addEvt(List eleEpdPqdParam) { + log.error("{}异常,降级处理,异常为:{}","录入事件字典",cause.toString()); + throw new BusinessException(finalExceptionEnum); + } + }; + } +} diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/EleEpdPqdParam.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/EleEpdPqdParam.java new file mode 100644 index 000000000..d7bb18b0d --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/param/EleEpdPqdParam.java @@ -0,0 +1,118 @@ +package com.njcn.system.pojo.param; + +import com.njcn.web.pojo.param.BaseParam; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/5/24 14:37 + */ +@Data +public class EleEpdPqdParam { + + @ApiModelProperty(value = "数据名称") + @NotBlank(message="数据名称不能为空!") + private String name; + + @ApiModelProperty(value = "别名") + private String otherName; + + @ApiModelProperty(value = "展示名称") + private String showName; + + @ApiModelProperty(value = "序号") + @NotNull(message="序号不能为空!") + private Integer sort; + + @ApiModelProperty(value = "基础数据类型") + private String type; + + @ApiModelProperty(value = "相别") + @NotBlank(message="相别不能为空!") + private String phase; + + @ApiModelProperty(value = "单位") + private String unit; + + @ApiModelProperty(value = "数据开始谐波次数") + private Integer harmStart; + + @ApiModelProperty(value = "数据结束谐波次数") + private Integer harmEnd; + + @ApiModelProperty(value = "数据分类") + @NotBlank(message="数据分类不能为空!") + private String classId; + + @ApiModelProperty(value = "数据统计方法") + private String statMethod; + + @ApiModelProperty(value = "系统类别") + private String systemType; + + @ApiModelProperty(value = "数据模型") + @NotBlank(message="数据模型不能为空!") + private String dataType; + + @ApiModelProperty(value = "数据是否上送") + private Integer tranFlag; + + @ApiModelProperty(value = "上送规则") + private String tranRule; + + @ApiModelProperty(value = "事件类别||参数类别||定值数据类型") + private String eventType; + + @ApiModelProperty(value = "是否存储||是否加密") + private Integer storeFlag; + + @ApiModelProperty(value = "是否需遥控校验") + private Integer curSts; + + @ApiModelProperty(value = "是否可远程控制||是否可修改||是否支持自动控制") + private Integer ctlSts; + + @ApiModelProperty(value = "设置最大值") + private Integer maxNum; + + @ApiModelProperty(value = "设置最小值") + private Integer minNum; + + @ApiModelProperty(value = "参数为enum可设置的所有值序列") + private String setValue; + + @ApiModelProperty(value = "参数string可设置字符串的长度上限") + private Integer strlen; + + @ApiModelProperty(value = "参数缺省值") + private String defaultValue; + + @ApiModelProperty(value = "报表数据来源(mysql表名)") + private String resourcesId; + + @Data + @EqualsAndHashCode(callSuper = true) + public static class EleEpdPqdUpdateParam extends EleEpdPqdParam { + @ApiModelProperty("Id") + @NotBlank(message = "id不为空") + private String id; + } + + /** + * 分页查询实体 + */ + @Data + @EqualsAndHashCode(callSuper = true) + public static class EleEpdPqdQueryParam extends BaseParam { + + } + +} diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/EleEpdPqd.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/EleEpdPqd.java new file mode 100644 index 000000000..45206dfdd --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/EleEpdPqd.java @@ -0,0 +1,150 @@ +package com.njcn.system.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.github.jeffreyning.mybatisplus.anno.MppMultiId; +import lombok.Data; + +/** + *

+ * + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +@Data +@TableName("ele_epd_pqd") +public class EleEpdPqd { + + private static final long serialVersionUID = 1L; + + /** + * Id + */ + private String id; + + /** + * 数据名称 + */ + @MppMultiId(value = "name") + private String name; + + /** + * 别名 + */ + private String otherName; + + /** + * 展示 + */ + private String showName; + + /** + * 数据编号 + */ + private Integer sort; + + /** + * 数据类型 + */ + private String type; + + /** + * 相别 + */ + @MppMultiId(value = "phase") + private String phase; + + /** + * 单位 + */ + private String unit; + + /** + * 数据开始谐波次数 + */ + private Integer harmStart; + + /** + * 数据结束谐波次数 + */ + private Integer harmEnd; + + /** + * 数据分类,唯一类别 + */ + private String classId; + + /** + * 数据统计方法,“max”“min”“avg”“cp95” + */ + private String statMethod; + + /** + * 系统类别(区分用能/电能) + */ + private String systemType; + + /** + * 数据类型(epd、pqd...) + */ + @MppMultiId(value = "data_type") + private String dataType; + + /** + * 数据是否上送 0:不上送 1:上送 + */ + private Integer tranFlag; + + /** + * 上送规则 变化:“change”周期:“period” + */ + private String tranRule; + + /** + * evt的事件类别 "1"、"2"; parm的参数类别 系统参数:“sys”,运行参数:“run”,功能参数:“fun”; set的定值数据类型 “hex”“number” + */ + private String eventType; + + /** + * sts、di的是否存储 1:存储 0:不存储; ctrl的是否加密 1:加密 0:不加密 + */ + private Integer storeFlag; + + /** + * sts、do的当前值; ctrl的是否需遥控校验 1:需要 0:不需要 + */ + private Integer curSts; + + /** + * do的是否可远程控制 1:是 0:否; parm的是否可修改 1:是 0:否; ctrl的是否支持自动控制 1:是 0:否 + */ + private Integer ctlSts; + + /** + * 设置最大值 + */ + private Integer maxNum; + + /** + * 设置最小值 + */ + private Integer minNum; + + /** + * 参数为enum可设置的所有值序列 + */ + private String setValue; + + /** + * 参数string可设置字符串的长度上限 + */ + private Integer strlen; + + /** + * 参数缺省值 + */ + private String defaultValue; + + +} diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/EleEpdPqdVO.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/EleEpdPqdVO.java new file mode 100644 index 000000000..a6fa28eef --- /dev/null +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/vo/EleEpdPqdVO.java @@ -0,0 +1,56 @@ +package com.njcn.system.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * 类的介绍: + * + * @author xuyang + * @version 1.0.0 + * @createTime 2023/5/24 15:30 + */ +@Data +public class EleEpdPqdVO implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "数据名称") + private String name; + + @ApiModelProperty(value = "别名") + private String otherName; + + @ApiModelProperty(value = "展示名称") + private String showName; + + @ApiModelProperty(value = "序号") + private Integer sort; + + @ApiModelProperty(value = "基础数据类型") + private String type; + + @ApiModelProperty(value = "相别") + private String phase; + + @ApiModelProperty(value = "单位") + private String unit; + + @ApiModelProperty(value = "数据开始谐波次数") + private Integer harmStart; + + @ApiModelProperty(value = "数据结束谐波次数") + private Integer harmEnd; + + @ApiModelProperty(value = "数据分类(influxDB表名)") + private String classId; + + @ApiModelProperty(value = "数据模型") + private String dataType; + + @ApiModelProperty(value = "报表数据来源(mysql表名)") + private String resourcesId; + +} diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/SystemBootMain.java b/pqs-system/system-boot/src/main/java/com/njcn/system/SystemBootMain.java index b1ad05045..596cd53a3 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/SystemBootMain.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/SystemBootMain.java @@ -1,5 +1,6 @@ package com.njcn.system; +import com.github.jeffreyning.mybatisplus.conf.EnableMPP; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -15,6 +16,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @MapperScan("com.njcn.**.mapper") @EnableFeignClients(basePackages = "com.njcn") @SpringBootApplication(scanBasePackages = "com.njcn") +@EnableMPP public class SystemBootMain { public static void main(String[] args) { SpringApplication.run(SystemBootMain.class, args); diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/controller/EleEpdPqdController.java b/pqs-system/system-boot/src/main/java/com/njcn/system/controller/EleEpdPqdController.java new file mode 100644 index 000000000..e0114169e --- /dev/null +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/controller/EleEpdPqdController.java @@ -0,0 +1,131 @@ +package com.njcn.system.controller; + + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.annotation.OperateInfo; +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.HttpResultUtil; +import com.njcn.common.utils.LogUtil; +import com.njcn.system.pojo.param.EleEpdPqdParam; +import com.njcn.system.pojo.po.EleEpdPqd; +import com.njcn.system.pojo.vo.EleEpdPqdVO; +import com.njcn.system.service.IEleEpdPqdService; +import com.njcn.web.controller.BaseController; +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 springfox.documentation.annotations.ApiIgnore; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 前端控制器 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +@Slf4j +@RestController +@RequestMapping("/csDictData") +@RequiredArgsConstructor +@Api(tags = "数据字典") +@Validated +public class EleEpdPqdController extends BaseController { + + private final IEleEpdPqdService eleEpdPqdService; + + @PostMapping("/addByModel") + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @ApiOperation("根据模板录入字典数据") + @ApiImplicitParam(name = "eleEpdPqdParam", value = "模板的字典数据", required = true) + @ApiIgnore + public HttpResult addByModel(@RequestBody @Validated List eleEpdPqdParam){ + log.info("根据模板录入字典数据"); + String methodDescribe = getMethodDescribe("addByModel"); + LogUtil.njcnDebug(log, "{},模板当前解析字典数据为:", methodDescribe); + eleEpdPqdService.saveData(eleEpdPqdParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @PostMapping("/add") + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @ApiOperation("新增字典数据") + @ApiImplicitParam(name = "eleEpdPqdParam", value = "字典数据", required = true) + public HttpResult add(@RequestBody @Validated EleEpdPqdParam eleEpdPqdParam){ + log.info("录入字典数据"); + String methodDescribe = getMethodDescribe("add"); + LogUtil.njcnDebug(log, "{},模板当前解析字典数据为:", methodDescribe); + eleEpdPqdService.add(eleEpdPqdParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @PostMapping("/delete") + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @ApiOperation("删除字典数据") + @ApiImplicitParam(name = "id", value = "字典数据id", required = true) + public HttpResult delete(@RequestParam String id){ + log.info("删除字典数据"); + String methodDescribe = getMethodDescribe("delete"); + LogUtil.njcnDebug(log, "{},字典id为:", methodDescribe); + eleEpdPqdService.delete(id); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @PostMapping("/update") + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @ApiOperation("更新字典数据") + @ApiImplicitParam(name = "updateParam", value = "字典数据", required = true) + public HttpResult update(@RequestBody @Validated EleEpdPqdParam.EleEpdPqdUpdateParam updateParam){ + log.info("更新字典数据"); + String methodDescribe = getMethodDescribe("update"); + LogUtil.njcnDebug(log, "{},字典数据为:", updateParam); + eleEpdPqdService.update(updateParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/list") + @ApiOperation("列表分页") + @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true) + public HttpResult> getList(@RequestBody @Validated EleEpdPqdParam.EleEpdPqdQueryParam queryParam) { + String methodDescribe = getMethodDescribe("getList"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam); + Page list = eleEpdPqdService.eleEpdPqdList(queryParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @OperateInfo(info = LogEnum.SYSTEM_COMMON) + @PostMapping("/dictMarkByDataType") + @ApiOperation("字典数据组装唯一标识") + @ApiImplicitParam(name = "dataType", value = "数据模型", required = true) + @ApiIgnore + public HttpResult> dictMarkByDataType(@RequestParam("dataType") @Validated String dataType) { + String methodDescribe = getMethodDescribe("dictMark"); + List list = eleEpdPqdService.dictMarkByDataType(dataType); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe); + } + + @PostMapping("/addEvt") + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @ApiOperation("事件录入字典数据") + @ApiImplicitParam(name = "eleEpdPqdParam", value = "模板的字典数据", required = true) + @ApiIgnore + public HttpResult> addEvt(@RequestBody @Validated List eleEpdPqdParam){ + log.info("根据模板录入字典数据"); + String methodDescribe = getMethodDescribe("addEvt"); + LogUtil.njcnDebug(log, "{},模板当前解析字典数据为:", methodDescribe); + Map map = eleEpdPqdService.saveEvt(eleEpdPqdParam); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, map, methodDescribe); + } + +} + diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/EleEpdPqdMapper.java b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/EleEpdPqdMapper.java new file mode 100644 index 000000000..27be9a093 --- /dev/null +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/EleEpdPqdMapper.java @@ -0,0 +1,22 @@ +package com.njcn.system.mapper; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; +import com.njcn.system.pojo.po.EleEpdPqd; +import com.njcn.system.pojo.vo.EleEpdPqdVO; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +public interface EleEpdPqdMapper extends MppBaseMapper { + + Page page(@Param("page")Page page, @Param("ew") QueryWrapper queryWrapper); + +} diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/EleEpdPqdMapper.xml b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/EleEpdPqdMapper.xml new file mode 100644 index 000000000..79558f015 --- /dev/null +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/mapper/mapping/EleEpdPqdMapper.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/IEleEpdPqdService.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/IEleEpdPqdService.java new file mode 100644 index 000000000..8ae7e8dfd --- /dev/null +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/IEleEpdPqdService.java @@ -0,0 +1,63 @@ +package com.njcn.system.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.system.pojo.param.EleEpdPqdParam; +import com.njcn.system.pojo.po.EleEpdPqd; +import com.njcn.system.pojo.vo.EleEpdPqdVO; + +import java.util.List; +import java.util.Map; + +/** + *

+ * 服务类 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +public interface IEleEpdPqdService { + + /** + * 存储模板的字典数据 + * @param eleEpdPqdParam + */ + void saveData(List eleEpdPqdParam); + + /** + * 存储字典数据 + * @param eleEpdPqdParam + */ + void add(EleEpdPqdParam eleEpdPqdParam); + + /** + * 删除字典数据 + * @param id + */ + void delete(String id); + + /** + * 更新字典数据 + * @param updateParam + */ + void update(EleEpdPqdParam.EleEpdPqdUpdateParam updateParam); + + /** + * 查询字典分页 + * @param queryParam + * @return + */ + Page eleEpdPqdList(EleEpdPqdParam.EleEpdPqdQueryParam queryParam); + + /** + * 查询所有字典数据组成唯一标识,用于验证字典是否重复 + * @return + */ + List dictMarkByDataType(String dataType); + + /** + * 存储事件的字典数据 + * @param eleEpdPqdParam + */ + Map saveEvt(List eleEpdPqdParam); +} diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/EleEpdPqdServiceImpl.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/EleEpdPqdServiceImpl.java new file mode 100644 index 000000000..585aea184 --- /dev/null +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/EleEpdPqdServiceImpl.java @@ -0,0 +1,146 @@ +package com.njcn.system.service.impl; + +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.github.jeffreyning.mybatisplus.service.MppServiceImpl; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.db.constant.DbConstant; +import com.njcn.system.enums.SystemResponseEnum; +import com.njcn.system.mapper.EleEpdPqdMapper; +import com.njcn.system.pojo.param.EleEpdPqdParam; +import com.njcn.system.pojo.po.EleEpdPqd; +import com.njcn.system.pojo.vo.EleEpdPqdVO; +import com.njcn.system.service.IEleEpdPqdService; +import com.njcn.web.factory.PageFactory; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + *

+ * 服务实现类 + *

+ * + * @author xuyang + * @since 2023-05-24 + */ +@Service +public class EleEpdPqdServiceImpl extends MppServiceImpl implements IEleEpdPqdService { + + @Override + public void saveData(List eleEpdPqdParam) { + List list = eleEpdPqdParam.stream().map(item->{ + EleEpdPqd eleEpdPqd = new EleEpdPqd(); + BeanUtils.copyProperties(item,eleEpdPqd); + if (StringUtils.isBlank(item.getType())){ + eleEpdPqd.setType(""); + } + return eleEpdPqd; + }).collect(Collectors.toList()); + this.saveBatch(list,1000); + } + + @Override + public void add(EleEpdPqdParam eleEpdPqdParam) { + checkEleEpdPqdParam(eleEpdPqdParam,false); + EleEpdPqd eleEpdPqd = new EleEpdPqd(); + BeanUtils.copyProperties(eleEpdPqdParam,eleEpdPqd); + this.save(eleEpdPqd); + } + + @Override + public void delete(String id) { + this.baseMapper.deleteById(id); + } + + @Override + public void update(EleEpdPqdParam.EleEpdPqdUpdateParam updateParam) { + checkEleEpdPqdParam(updateParam,true); + EleEpdPqd eleEpdPqd = new EleEpdPqd(); + BeanUtils.copyProperties(updateParam,eleEpdPqd); + this.updateById(eleEpdPqd); + } + + @Override + public Page eleEpdPqdList(EleEpdPqdParam.EleEpdPqdQueryParam queryParam) { + QueryWrapper queryWrapper = new QueryWrapper(); + if (ObjectUtil.isNotNull(queryParam)) { + //查询参数不为空,进行条件填充 + if (StrUtil.isNotBlank(queryParam.getSearchValue())) { + //部门根据名称模糊查询 + queryWrapper + .and(param -> param.like("ele_epd_pqd.Name", queryParam.getSearchValue()) + .or().like("ele_epd_pqd.Other_Name", queryParam.getSearchValue()) + .or().like("ele_epd_pqd.Show_Name", queryParam.getSearchValue())); + } + //排序 + if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) { + queryWrapper.orderBy(true, queryParam.getOrderBy().equalsIgnoreCase(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy())); + } else { + //默认根据sort排序 + queryWrapper.orderBy(true, true, "Sort"); + } + } + return this.baseMapper.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper); + } + + @Override + public List dictMarkByDataType(String dataType) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(EleEpdPqd::getDataType,dataType); + return this.baseMapper.selectList(lambdaQueryWrapper); + } + + @Override + public Map saveEvt(List eleEpdPqdParam) { + List list = eleEpdPqdParam.stream().map(item->{ + EleEpdPqd eleEpdPqd = new EleEpdPqd(); + BeanUtils.copyProperties(item,eleEpdPqd); + if (StringUtils.isBlank(item.getType())){ + eleEpdPqd.setType(""); + } + return eleEpdPqd; + }).collect(Collectors.toList()); + this.saveBatch(list,1000); + List nameList = eleEpdPqdParam.stream().map(EleEpdPqdParam::getName).collect(Collectors.toList()); + List list1 = this.lambdaQuery().in(EleEpdPqd::getName,nameList).list(); + Map map = new HashMap<>(); + list1.forEach(item->{ + map.put(item.getName(),item.getId()); + }); + return map; + } + + /** + * 校验参数, + * 1.检查是否存在相同名称的菜单 + * 名称 && 路径做唯一判断 + */ + private void checkEleEpdPqdParam(EleEpdPqdParam eleEpdPqdParam, boolean isExcludeSelf) { + LambdaQueryWrapper eleEpdPqdLambdaQueryWrapper = new LambdaQueryWrapper<>(); + eleEpdPqdLambdaQueryWrapper + .eq(EleEpdPqd::getName, eleEpdPqdParam.getName()) + .eq(EleEpdPqd::getPhase, eleEpdPqdParam.getPhase()) + .eq(EleEpdPqd::getClassId,eleEpdPqdParam.getClassId()) + .eq(EleEpdPqd::getDataType, eleEpdPqdParam.getDataType()); + //更新的时候,需排除当前记录 + if (isExcludeSelf) { + if (eleEpdPqdParam instanceof EleEpdPqdParam.EleEpdPqdUpdateParam) { + eleEpdPqdLambdaQueryWrapper.ne(EleEpdPqd::getId, ((EleEpdPqdParam.EleEpdPqdUpdateParam) eleEpdPqdParam).getId()); + } + } + int countByAccount = this.count(eleEpdPqdLambdaQueryWrapper); + //大于等于1个则表示重复 + if (countByAccount >= 1) { + throw new BusinessException(SystemResponseEnum.DICT_DATA_NAME_REPEAT); + } + } +} diff --git a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/dto/ComponentDTO.java b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/dto/ComponentDTO.java index 8a6fc08d2..41875dd1e 100644 --- a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/dto/ComponentDTO.java +++ b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/dto/ComponentDTO.java @@ -40,6 +40,9 @@ public class ComponentDTO implements Serializable { @ApiModelProperty("路径") private String path; + @ApiModelProperty("系统类型") + private String systemType; + @ApiModelProperty("子级") List children; diff --git a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/param/ComponentParam.java b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/param/ComponentParam.java index 8a1d71cfb..5a85c8af2 100644 --- a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/param/ComponentParam.java +++ b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/param/ComponentParam.java @@ -53,6 +53,10 @@ public class ComponentParam { @ApiModelProperty("路径") private String path; + @ApiModelProperty("系统类型") + @NotBlank(message = "系统类型不为空") + private String systemType; + /** * 组件更新操作实体 diff --git a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/po/Component.java b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/po/Component.java index 9b419682e..f1d7fa791 100644 --- a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/po/Component.java +++ b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/po/Component.java @@ -8,7 +8,7 @@ import lombok.EqualsAndHashCode; /** * - * @author hongawen + * @author xuyang * @since 2021-12-13 */ @Data @@ -68,4 +68,9 @@ public class Component extends BaseEntity { */ private Integer state; + /** + * 系统类型 + */ + private String systemType; + } diff --git a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/vo/ComponentVO.java b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/vo/ComponentVO.java index 76fa22727..792bc184f 100644 --- a/pqs-user/user-api/src/main/java/com/njcn/user/pojo/vo/ComponentVO.java +++ b/pqs-user/user-api/src/main/java/com/njcn/user/pojo/vo/ComponentVO.java @@ -40,6 +40,9 @@ public class ComponentVO implements Serializable { @ApiModelProperty("路径") private String path; + @ApiModelProperty("系统类型") + private String systemType; + @ApiModelProperty("子级") List children; diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/controller/ComponentController.java b/pqs-user/user-boot/src/main/java/com/njcn/user/controller/ComponentController.java index a720a0eb8..3fd1a1aab 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/controller/ComponentController.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/controller/ComponentController.java @@ -9,6 +9,7 @@ import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.LogUtil; import com.njcn.user.pojo.param.ComponentParam; +import com.njcn.user.pojo.po.Component; import com.njcn.user.pojo.vo.ComponentVO; import com.njcn.user.service.IComponentService; import com.njcn.web.controller.BaseController; @@ -115,5 +116,14 @@ public class ComponentController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe); } + @OperateInfo + @GetMapping("/getFatherComponent") + @ApiOperation("获取父组件节点") + public HttpResult> getFatherComponent(@RequestParam @Validated String systemType){ + String methodDescribe = getMethodDescribe("getFatherComponent"); + List list = componentService.getFatherComponent(systemType); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe); + } + } diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/IComponentService.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/IComponentService.java index 51df319fe..f405bbbe7 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/service/IComponentService.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/IComponentService.java @@ -66,4 +66,6 @@ public interface IComponentService extends IService { * @date 2022/1/24 12:33 */ List getUserComponentTree(); + + List getFatherComponent(String systemType); } diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/ComponentServiceImpl.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/ComponentServiceImpl.java index a6a4c94ce..58492bec4 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/ComponentServiceImpl.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/ComponentServiceImpl.java @@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.system.api.DicDataFeignClient; +import com.njcn.system.pojo.po.DictData; import com.njcn.user.enums.UserResponseEnum; import com.njcn.user.mapper.ComponentMapper; import com.njcn.user.pojo.constant.ComponentState; @@ -21,6 +23,7 @@ import com.njcn.web.utils.RequestUtil; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.util.*; import java.util.stream.Collectors; @@ -46,6 +49,8 @@ public class ComponentServiceImpl extends ServiceImpl getComponentTree() { List list = new ArrayList<>(); + List result = new ArrayList<>(); List componentList = componentMapper.getAllComponent(); - componentList.forEach(item -> { - ComponentVO componentVO = new ComponentVO(); - BeanUtil.copyProperties(item, componentVO); - componentVO.setFunctionGroup(Arrays.stream(item.getFunctionGroup().split(",")).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList())); - list.add(componentVO); - }); - return list.stream() - .filter(fun -> Objects.equals(ComponentState.FATHER_PID, fun.getPid())) - .peek(funS -> funS.setChildren(getChildCategoryList(funS, list))) - .collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(componentList)){ + componentList.forEach(item -> { + ComponentVO componentVO = new ComponentVO(); + BeanUtil.copyProperties(item, componentVO); + componentVO.setFunctionGroup(Arrays.stream(item.getFunctionGroup().split(",")).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList())); + list.add(componentVO); + }); + Map> map = list.stream().collect(Collectors.groupingBy(ComponentVO::getSystemType)); + map.forEach((k,v)->{ + DictData dictData = dicDataFeignClient.getDicDataById(k).getData(); + ComponentVO componentVO = new ComponentVO(); + componentVO.setId(dictData.getId()); + componentVO.setName(dictData.getName()); + componentVO.setChildren( + v.stream() + .filter(fun -> Objects.equals(ComponentState.FATHER_PID, fun.getPid())) + .peek(funS -> funS.setChildren(getChildCategoryList(funS, v))) + .collect(Collectors.toList())); + result.add(componentVO); + }); + } + return result; } @Override @@ -115,21 +129,39 @@ public class ComponentServiceImpl extends ServiceImpl componentList = roleComponentService.selectRoleComponent(roleList.stream().map(Role::getId).collect(Collectors.toList())); list = componentMapper.getComponentByList(componentList); } - list.forEach(item -> { ComponentVO componentVO = new ComponentVO(); BeanUtil.copyProperties(item, componentVO); componentVO.setFunctionGroup(Arrays.stream(item.getFunctionGroup().split(",")).map(s -> Integer.valueOf(s.trim())).collect(Collectors.toList())); componentVOList.add(componentVO); }); - result = componentVOList.stream() - .filter(fun -> Objects.equals(ComponentState.FATHER_PID, fun.getPid())) - .peek(funS -> funS.setChildren(getChildCategoryList(funS, componentVOList))) - .collect(Collectors.toList()); + Map> map = componentVOList.stream().collect(Collectors.groupingBy(ComponentVO::getSystemType)); + map.forEach((k, v)->{ + DictData dictData = dicDataFeignClient.getDicDataById(k).getData(); + ComponentVO componentVO = new ComponentVO(); + componentVO.setName(dictData.getName()); + componentVO.setChildren( + v.stream() + .filter(fun -> Objects.equals(ComponentState.FATHER_PID, fun.getPid())) + .peek(funS -> funS.setChildren(getChildCategoryList(funS, v))) + .collect(Collectors.toList())); + result.add(componentVO); + }); } return result; } + @Override + public List getFatherComponent(String systemType) { + List list = new ArrayList<>(); + Component component = new Component(); + component.setId("0"); + component.setName("无"); + list.add(component); + list.addAll(this.lambdaQuery().eq(Component::getSystemType, systemType).eq(Component::getPid,ComponentState.FATHER_PID).eq(Component::getState, ComponentState.ENABLE).list()); + return list; + } + /** * 递归组装组件表 */ @@ -147,6 +179,7 @@ public class ComponentServiceImpl extends ServiceImpl componentLambdaQueryWrapper = new LambdaQueryWrapper<>(); componentLambdaQueryWrapper .eq(Component::getName, componentParam.getName()) + .eq(Component::getSystemType, componentParam.getSystemType()) .eq(Component::getState, ComponentState.ENABLE); //更新的时候,需排除当前记录 if (isExcludeSelf) {