|
@@ -0,0 +1,169 @@
|
|
|
+package com.persagy.dmp.rwd.define.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+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.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.persagy.dmp.basic.dto.RequestData;
|
|
|
+import com.persagy.dmp.basic.model.QueryCriteria;
|
|
|
+import com.persagy.dmp.basic.utils.QueryCriteriaHelper;
|
|
|
+import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
+import com.persagy.dmp.common.context.AppContext;
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
+import com.persagy.dmp.common.lang.PsDateTime;
|
|
|
+import com.persagy.dmp.common.model.response.CommonResult;
|
|
|
+import com.persagy.dmp.common.utils.ResultHelper;
|
|
|
+import com.persagy.dmp.define.entity.DigitalEquipClassRel;
|
|
|
+import com.persagy.dmp.define.entity.RelationDefine;
|
|
|
+import com.persagy.dmp.mybatis.utils.ConditionUtil;
|
|
|
+import com.persagy.dmp.rwd.basic.constant.BusinessErrorRwdCode;
|
|
|
+import com.persagy.dmp.rwd.define.dao.DigitalEquipClassRelMapper;
|
|
|
+import com.persagy.dmp.rwd.define.service.DigitalEquipClassRelService;
|
|
|
+import com.persagy.dmp.rwd.define.service.IRelationDefineService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+ * Description: 项目设备类关系逻辑处理类
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/14 21:27
|
|
|
+ * Update By lijie 2021/9/14 21:27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class DigitalEquipClassRelServiceImpl extends ServiceImpl<DigitalEquipClassRelMapper, DigitalEquipClassRel>
|
|
|
+implements DigitalEquipClassRelService {
|
|
|
+
|
|
|
+ private final IRelationDefineService relationDefineService;
|
|
|
+
|
|
|
+
|
|
|
+ * Description: 创建设备类关系对象
|
|
|
+ * @param voList : 设备类关系对象列表
|
|
|
+ * @return : com.persagy.dmp.define.entity.DigitalEquipClassRel
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/14 21:09
|
|
|
+ * Update By lijie 2021/9/14 21:09
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = BusinessException.class)
|
|
|
+ public List<DigitalEquipClassRel> create(List<DigitalEquipClassRel> voList) {
|
|
|
+ Set<String> calcNames = new HashSet<>();
|
|
|
+
|
|
|
+ for (DigitalEquipClassRel vo : voList) {
|
|
|
+ if ((StrUtil.isBlank(vo.getGraphCode())
|
|
|
+ || StrUtil.isBlank(vo.getRelCode()))
|
|
|
+ && StrUtil.isBlank(vo.getCalcName())){
|
|
|
+ throw new BusinessException(ResponseCode.A0402.getCode(),"缺少图类型编码和关系类型编码");
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(vo.getCalcName())){
|
|
|
+ calcNames.add(vo.getCalcName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, RelationDefine> relationDefineMap = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(calcNames)){
|
|
|
+
|
|
|
+ LambdaQueryWrapper<RelationDefine> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(RelationDefine::getName,calcNames);
|
|
|
+ queryWrapper.eq(RelationDefine::getValid,true);
|
|
|
+ List<RelationDefine> defines = relationDefineService.queryByCondition(queryWrapper);
|
|
|
+ if (CollUtil.isEmpty(defines)){
|
|
|
+ throw new BusinessException(ResponseCode.A0402.getCode(),"关系类型编码不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (RelationDefine define : defines) {
|
|
|
+ RelationDefine relationDefine = relationDefineMap.get(define.getName());
|
|
|
+ if (null!=relationDefine){
|
|
|
+ throw new BusinessException(ResponseCode.A0402.getCode(),define.getName()+"关系类型编码存在多条");
|
|
|
+ }
|
|
|
+ relationDefineMap.put(define.getName(),define);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<DigitalEquipClassRel> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ for (DigitalEquipClassRel vo : voList) {
|
|
|
+ if (StrUtil.isNotBlank(vo.getCalcName())){
|
|
|
+ if(!relationDefineMap.containsKey(vo.getCalcName())){
|
|
|
+ throw new BusinessException(ResponseCode.A0402.getCode(),vo.getCalcName()+"关系类型编码不存在");
|
|
|
+ }
|
|
|
+ RelationDefine relationDefine = relationDefineMap.get(vo.getCalcName());
|
|
|
+ vo.setGraphCode(relationDefine.getGraphCode());
|
|
|
+ vo.setRelCode(relationDefine.getCode());
|
|
|
+ }
|
|
|
+ vo.setProjectId(AppContext.getContext().getProjectId());
|
|
|
+ vo.setCreator(AppContext.getContext().getAccountId());
|
|
|
+ updateWrapper.or(wrapper->{
|
|
|
+ wrapper.eq(DigitalEquipClassRel::getGraphCode,vo.getGraphCode());
|
|
|
+ wrapper.eq(DigitalEquipClassRel::getRelCode,vo.getRelCode());
|
|
|
+ wrapper.eq(DigitalEquipClassRel::getProjectId,vo.getProjectId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ DigitalEquipClassRel digitalEquipClassRel = new DigitalEquipClassRel();
|
|
|
+ digitalEquipClassRel.setModifier(AppContext.getContext().getAccountId());
|
|
|
+ digitalEquipClassRel.setModifiedTime(new PsDateTime());
|
|
|
+ digitalEquipClassRel.setValid(0);
|
|
|
+ this.update(digitalEquipClassRel,updateWrapper);
|
|
|
+ this.saveBatch(voList);
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Description: 根据条件查询设备类关系对象列表
|
|
|
+ * @param criteria : 查询条件
|
|
|
+ * @return : com.persagy.dmp.common.model.response.CommonResult<java.util.List<com.persagy.dmp.define.entity.DigitalEquipClassRel>>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/14 21:14
|
|
|
+ * Update By lijie 2021/9/14 21:14
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CommonResult<List<DigitalEquipClassRel>> query(QueryCriteria criteria) {
|
|
|
+ QueryWrapper<DigitalEquipClassRel> wrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ ConditionUtil.ensureProjectCriteriaDirectly(wrapper);
|
|
|
+
|
|
|
+ QueryCriteriaHelper.toWrapper(wrapper, criteria, DigitalEquipClassRel.class);
|
|
|
+ if(criteria.isOnlyCount()) {
|
|
|
+ int total = count(wrapper);
|
|
|
+ return ResultHelper.multi(new ArrayList<>(),total);
|
|
|
+ }
|
|
|
+ Page<DigitalEquipClassRel> page = page(QueryCriteriaHelper.toPage(criteria), wrapper);
|
|
|
+
|
|
|
+ List<DigitalEquipClassRel> records = page.getRecords();
|
|
|
+ if (CollUtil.isEmpty(records)){
|
|
|
+ return ResultHelper.multi(new ArrayList<>(),page.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> graphCodes = records.stream()
|
|
|
+ .map(DigitalEquipClassRel::getGraphCode)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Set<String> relCodes = records.stream()
|
|
|
+ .map(DigitalEquipClassRel::getRelCode)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ Map<String, RelationDefine> relCodeMap = relationDefineService.queryRelMapByCodes(graphCodes,relCodes);
|
|
|
+ records.forEach(record->{
|
|
|
+ String key = record.getGraphCode() + StrUtil.UNDERLINE + record.getRelCode();
|
|
|
+ if (!relCodeMap.containsKey(key)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ record.setCalcName(relCodeMap.get(key).getName());
|
|
|
+ });
|
|
|
+ return ResultHelper.multi(page.getRecords(), page.getTotal());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|