Browse Source

代码优化

master
sunyuchao 4 years ago
parent
commit
6627e28486
  1. 45
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java

45
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffPatrolRecordServiceImpl.java

@ -1,13 +1,17 @@
package com.epmet.service.impl; 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.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.rocketmq.messages.StaffPatrolMQMsg; import com.epmet.commons.rocketmq.messages.StaffPatrolMQMsg;
import com.epmet.commons.tools.constant.NumConstant; 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.constant.StrConstant;
import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException; 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.security.dto.TokenDto;
import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
@ -42,9 +46,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -73,6 +75,8 @@ public class StaffPatrolRecordServiceImpl extends BaseServiceImpl<StaffPatrolRec
private GovProjectOpenFeignClient govProjectOpenFeignClient; private GovProjectOpenFeignClient govProjectOpenFeignClient;
@Autowired @Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Autowired
private RedisUtils redisUtils;
/** /**
@ -469,19 +473,32 @@ public class StaffPatrolRecordServiceImpl extends BaseServiceImpl<StaffPatrolRec
return resultDTO; return resultDTO;
} }
//2.查询网格信息 //2.查询网格信息并赋值
OrgInfoFormDTO org = new OrgInfoFormDTO(); Map<String, CustomerGridDTO> map = new HashMap<>();
List<String> orgIds = result.getList().stream().map(PcworkRecordListResultDTO.StaffPatrol::getGridId).collect(Collectors.toList()); for (PcworkRecordListResultDTO.StaffPatrol r : result.getList()) {
orgIds = orgIds.stream().distinct().collect(Collectors.toList()); if (map.containsKey(r.getGridId())) {
org.setOrgIds(orgIds); r.setGridName(map.get(r.getGridId()).getGridName());
org.setOrgType("grid"); continue;
Result<List<OrgInfoResultDTO>> orgResult = govOrgOpenFeignClient.selectOrgInfo(org); }
if (!orgResult.success()) { String redisKey = RedisKeys.getGridInfoKey(r.getGridId());
throw new RenException("获取网格基础信息失败......"); Map<String, Object> 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<CustomerGridDTO> resultGrid = govOrgOpenFeignClient.getGridBaseInfoByGridId(form);
if (!resultGrid.success()) {
throw new RenException("调用org服务获取网格基础信息失败......");
}
r.setGridName(resultGrid.getData().getGridName());
map.put(r.getGridId(), resultGrid.getData());
}
} }
//3.封装数据并返回 //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.setTotal((int)result.getTotal());
resultDTO.setList(result.getList()); resultDTO.setList(result.getList());
return resultDTO; return resultDTO;

Loading…
Cancel
Save