diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/PatrolRoutineWorkServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/PatrolRoutineWorkServiceImpl.java index c44832771c..0859689498 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/PatrolRoutineWorkServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/PatrolRoutineWorkServiceImpl.java @@ -36,6 +36,7 @@ import com.epmet.dto.form.CustomerGridFormDTO; import com.epmet.dto.form.PatrolRoutineWorkFormDTO; import com.epmet.dto.form.PcWorkListFormDTO; import com.epmet.dto.form.patrol.PatrolQueryFormDTO; +import com.epmet.dto.result.AllGridsByUserIdResultDTO; import com.epmet.dto.result.PatrolRoutineWorkResult; import com.epmet.dto.result.PcWorkListResultDTO; import com.epmet.entity.PatrolRoutineWorkEntity; @@ -60,6 +61,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * 巡查例行工作 @@ -171,10 +173,40 @@ public class PatrolRoutineWorkServiceImpl extends BaseServiceImpl> workTypeResult = adminOpenFeignClient.dictTree(DictTypeEnum.PATROL_WORK_TYPE.getCode()); + if (!workTypeResult.success()){ + throw new EpmetException("查询例行工作分类失败..."); + } + List gridIds = list.stream().map(m -> m.getGridId()).distinct().collect(Collectors.toList()); + Result> gridNamesResult = govOrgOpenFeignClient.getGridListByGridIds(gridIds); + if (!gridNamesResult.success()){ + throw new EpmetException("查询网格名字失败..."); + } + list.forEach(l -> { + l.setWorkTypeName(disposeWorkTypeCode(workTypeResult.getData(),l.getWorkTypeCode())); + gridNamesResult.getData().stream().filter(g -> l.getGridId().equals(g.getGridId())).forEach(g -> l.setGridName(g.getGridName())); + }); result.setList(list); return result; } + public List disposeWorkTypeCode(List workTypeList,List code){ + if (CollectionUtils.isEmpty(code)){ + return new ArrayList<>(); + } + List result = new ArrayList<>(); + code.forEach(c -> { + workTypeList.forEach(w1 -> { + w1.getChildren().forEach(w2 -> { + if (c.equals(w2.getId())){ + result.add(w1.getName() + "-" + w2.getName()); + } + }); + }); + }); + return result; + } + /** * desc:递归遍历树形结构 构建pids 根节点pids 为空字符串 * diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java index 860aa91c3d..bcb27c0410 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java @@ -1,13 +1,17 @@ package com.epmet.service.impl; +import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.rocketmq.messages.StaffPatrolMQMsg; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.constant.StrConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.RedisKeys; +import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.Result; @@ -42,9 +46,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -73,6 +75,8 @@ public class StaffPatrolRecordServiceImpl extends BaseServiceImpl orgIds = result.getList().stream().map(PcworkRecordListResultDTO.StaffPatrol::getGridId).collect(Collectors.toList()); - orgIds = orgIds.stream().distinct().collect(Collectors.toList()); - org.setOrgIds(orgIds); - org.setOrgType("grid"); - Result> orgResult = govOrgOpenFeignClient.selectOrgInfo(org); - if (!orgResult.success()) { - throw new RenException("获取网格基础信息失败......"); + //2.查询网格信息并赋值 + Map map = new HashMap<>(); + for (PcworkRecordListResultDTO.StaffPatrol r : result.getList()) { + if (map.containsKey(r.getGridId())) { + r.setGridName(map.get(r.getGridId()).getGridName()); + continue; + } + String redisKey = RedisKeys.getGridInfoKey(r.getGridId()); + Map gridCache = redisUtils.hGetAll(redisKey); + if (gridCache != null && gridCache.size() > 0) { + // 直接取缓存中的 + CustomerGridDTO dto = BeanUtil.mapToBean(gridCache, CustomerGridDTO.class, true); + r.setGridName(dto.getGridName()); + map.put(r.getGridId(), dto); + } else { + CustomerGridFormDTO form = new CustomerGridFormDTO(); + form.setGridId(r.getGridId()); + Result resultGrid = govOrgOpenFeignClient.getGridBaseInfoByGridId(form); + if (!resultGrid.success()) { + throw new RenException("调用org服务获取网格基础信息失败......"); + } + r.setGridName(resultGrid.getData().getGridName()); + map.put(r.getGridId(), resultGrid.getData()); + } } - //3.封装数据并返回 - result.getList().forEach(r -> orgResult.getData().stream().filter(u -> r.getGridId().equals(u.getOrgId())).forEach(u -> r.setGridName(u.getOrgName()))); resultDTO.setTotal((int)result.getTotal()); resultDTO.setList(result.getList()); return resultDTO; diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/PatrolRoutineWorkDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/PatrolRoutineWorkDao.xml index 48137ecd50..78cf718131 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/PatrolRoutineWorkDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/PatrolRoutineWorkDao.xml @@ -47,6 +47,7 @@ + @@ -61,8 +62,10 @@ w.USER_ID AS staffId, w.GRID_ID AS gridId, DATE_FORMAT(w.CREATED_TIME,'%Y-%m-%d %H:%i:%s') AS createdTime, - w.WORK_CONTENT AS workContent + w.WORK_CONTENT AS workContent, + s.REAL_NAME AS staffName FROM patrol_routine_work w + INNER JOIN customer_staff s ON (s.USER_ID = w.USER_ID AND s.DEL_FLAG = 0) WHERE w.DEL_FLAG = 0 AND w.USER_ID = #{staffId}