CustomPointServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package com.tofly.dyrq.custom.service.impl;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.sun.tools.sjavac.Log;
  4. import com.tofly.common.core.util.Date8Util;
  5. import com.tofly.dyrq.custom.entity.UpdatePoint;
  6. import com.tofly.dyrq.custom.mapper.CustomPlanMapper;
  7. import com.tofly.dyrq.custom.mapper.CustomPointMapper;
  8. import com.tofly.dyrq.custom.service.CustomPointService;
  9. import com.tofly.dyrq.entity.PlanChild;
  10. import com.tofly.dyrq.entity.PlanPointTemp;
  11. import com.tofly.dyrq.entity.SysDeviceType;
  12. import com.tofly.dyrq.entity.TfPlanPathTemp;
  13. import com.tofly.dyrq.service.PlanChildService;
  14. import com.tofly.dyrq.service.PlanPointTempService;
  15. import com.tofly.dyrq.service.SysDeviceTypeService;
  16. import com.tofly.dyrq.service.TfPlanPathTempService;
  17. import lombok.AllArgsConstructor;
  18. import org.apache.commons.lang.StringUtils;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import java.math.BigDecimal;
  22. import java.util.*;
  23. import java.util.concurrent.ExecutorService;
  24. import java.util.concurrent.Executors;
  25. import java.util.stream.Collectors;
  26. @Service
  27. @AllArgsConstructor
  28. public class CustomPointServiceImpl implements CustomPointService {
  29. private CustomPointMapper customPointMapper;
  30. private PlanPointTempService planPointTempService;
  31. private PlanChildService planChildService;
  32. private TfPlanPathTempService planPathTempService;
  33. private final CustomPlanMapper customPlanMapper;
  34. private final SysDeviceTypeService sysDeviceTypeService;
  35. @Override
  36. @Transactional
  37. public Map<String, Long> updatePointOrPathIsover(List<UpdatePoint> updatePoints) {
  38. Map<String, Long> transfer = new HashMap<>();
  39. List<Long> childList = new ArrayList<>();
  40. HashSet<Long> childIds = new HashSet();
  41. for (UpdatePoint u : updatePoints) {
  42. if (u.getTempId() != null && u.getCheckTime() != null && u.getGpsSpeed() != null) {
  43. if ("0".equals(u.getType())) {
  44. String pointChildPlanState = customPointMapper.getStateByPointId(u.getTempId());
  45. if ("7".equals(pointChildPlanState)) {
  46. transfer.put("pointTempId", u.getTempId());
  47. continue;
  48. }
  49. planPointTempService.update(Wrappers.<PlanPointTemp>lambdaUpdate()
  50. .set(PlanPointTemp::getIsover, "1")
  51. .set(PlanPointTemp::getOverDate, u.getCheckTime())
  52. .set(PlanPointTemp::getGpsSpeed, u.getGpsSpeed())
  53. .eq(PlanPointTemp::getId, u.getTempId()));
  54. } else if ("1".equals(u.getType())) {
  55. String childPlanState = customPointMapper.getStateByPath(u.getTempId());
  56. if ("7".equals(childPlanState)) {
  57. transfer.put("pathTempId", u.getTempId());
  58. continue;
  59. } else {
  60. if (!childList.contains(u.getPlanChildId())) {
  61. childList.add(u.getPlanChildId());
  62. }
  63. }
  64. planPathTempService.update(Wrappers.<TfPlanPathTemp>lambdaUpdate()
  65. .set(TfPlanPathTemp::getIsover, "1")
  66. .set(TfPlanPathTemp::getOverDate, u.getCheckTime())
  67. .set(TfPlanPathTemp::getGpsSpeed, u.getGpsSpeed())
  68. .eq(TfPlanPathTemp::getId, u.getTempId()));
  69. //更新完成点所属线的完成率
  70. Long pointTempId =planPathTempService.getById(u.getTempId()).getTempId();
  71. int isOverNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId).eq(TfPlanPathTemp::getIsover, "1"));
  72. int allNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId));
  73. double pathOver = new BigDecimal((float) isOverNum / allNum).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  74. PlanPointTemp one = new PlanPointTemp();
  75. one.setId(pointTempId);
  76. one.setPathIsover(new BigDecimal(pathOver));
  77. planPointTempService.updateById(one);
  78. }
  79. }
  80. childIds.add(u.getPlanChildId());
  81. }
  82. Log.warn("#############################1");
  83. //批量更新所有计划点,线完成率
  84. ExecutorService executorService = Executors.newSingleThreadExecutor();
  85. executorService.execute(new Runnable() {
  86. @Override
  87. public void run() {
  88. String ids = StringUtils.join(childIds, ",");
  89. percentUpdate(ids);
  90. }
  91. });
  92. // for (Long cid : childList) {
  93. // Double percent = (double) planPathTempService.list(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getChildPlanId, cid).eq(TfPlanPathTemp::getIsover, 1)).size()
  94. // / (double) planPathTempService.list(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getChildPlanId, cid)).size();
  95. // planChildService.update(Wrappers.<PlanChild>lambdaUpdate()
  96. // .set(PlanChild::getPercent, percent)
  97. // .set(PlanChild::getPercent1, percent)
  98. // .eq(PlanChild::getId, cid));
  99. // planChildService.update(Wrappers.<PlanChild>lambdaUpdate()
  100. // .set(PlanChild::getChildPlanState, "3")
  101. // .eq(PlanChild::getPercent1, 1.00)
  102. // .eq(PlanChild::getId, cid));
  103. // }
  104. Log.warn("#############################3");
  105. return transfer;
  106. }
  107. @Override
  108. public void percentUpdate(String childPlanIds) {
  109. List<String> list = Arrays.asList(childPlanIds.split(","));
  110. Log.warn("#############################2");
  111. for (String sid : list) {
  112. Long childPlanId = Long.parseLong(sid);
  113. Date now = Date8Util.getCurrentDate();
  114. //查询当天的计划
  115. Map param1 = new HashMap();
  116. param1.put("now", now);
  117. int pointTotal = 0;
  118. int pointIsoverTotal = 0;
  119. int isOver = 0; //---------巡检点,巡检线isover个数,其他设备check个数
  120. int total = 0; //point_temp个数
  121. double percent = 0;
  122. double percent1 = 0;
  123. Map plan = customPlanMapper.getTodayPlan(childPlanId).get(0);
  124. //查询包含巡检检查内容的类型
  125. List<SysDeviceType> devices = sysDeviceTypeService.list(Wrappers.<SysDeviceType>lambdaQuery().isNotNull(SysDeviceType::getCheckContent));
  126. Set<Long> checkTypes = new HashSet<>();
  127. devices.stream().filter(n -> !checkTypes.add(n.getPointTypeId()))
  128. .collect(Collectors.toSet());
  129. //更新巡检线录入状态
  130. if ("1".equals(plan.get("type"))) {
  131. List<Map> pathTotal = customPlanMapper.getPathTotalInfo(childPlanId);
  132. total = Integer.valueOf(pathTotal.get(0).get("total").toString());
  133. isOver = checkTypes.contains(plan.get("deviceTypeId")) ? Integer.valueOf(pathTotal.get(0).get("checkTotal").toString()) : Integer.valueOf(pathTotal.get(0).get("isovertotal").toString());
  134. pointTotal = Integer.valueOf(pathTotal.get(0).get("pointTotal").toString());
  135. pointIsoverTotal = Integer.valueOf(pathTotal.get(0).get("pointIsoverTotal").toString());
  136. // percent1 = pointTotal == 0 ? 0 : new BigDecimal((float) pointIsoverTotal / pointTotal).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  137. // percent = pointTotal == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  138. //修改percent1 为point_temp到位情况
  139. percent = pointTotal == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  140. percent1 = pointTotal == 0 ? 0 : new BigDecimal ((float) pointIsoverTotal / pointTotal).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  141. //更新到位条数
  142. PlanChild planChild = new PlanChild();
  143. planChild.setId(childPlanId);
  144. planChild.setPercent(percent);
  145. planChild.setPercent1(percent1);
  146. planChild.setTotal1(new BigDecimal(pointTotal));
  147. planChild.setIsovertototal(percent * total);
  148. planChild.setIsovertototal1(new BigDecimal(pointIsoverTotal));
  149. planChild.setIsovertototal0(new BigDecimal(isOver));
  150. planChildService.updateById(planChild);
  151. //更新线到位比例
  152. // List<PlanPointTemp> stateList = planPointTempService.list(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId)
  153. // .eq(PlanPointTemp::getState, "0"));
  154. List<PlanPointTemp> pointTemps = new ArrayList<>();
  155. //点所属的线信息更新也转移到到位接口
  156. // for (PlanPointTemp pointTemp : stateList) {
  157. // Long pointTempId = pointTemp.getId();
  158. // int isOverNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId).eq(TfPlanPathTemp::getIsover, "1"));
  159. // int allNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId));
  160. // double pathOver = new BigDecimal((float) isOverNum / allNum).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  161. // PlanPointTemp one = new PlanPointTemp();
  162. // one.setId(pointTempId);
  163. // one.setPathIsover(new BigDecimal(pathOver));
  164. // planPointTempService.updateById(one);
  165. // }
  166. //更新录入状态
  167. List<Map> pathMax = customPlanMapper.getPathMaxSpeed(childPlanId);
  168. for (Map i : pathMax) {
  169. PlanPointTemp planPointTemp = new PlanPointTemp();
  170. planPointTemp.setIsover("1");
  171. planPointTemp.setGpsSpeed((BigDecimal) i.get("gpsSpeed"));
  172. planPointTemp.setState("1");
  173. planPointTemp.setId(Long.parseLong(i.get("tempId").toString()));
  174. planPointTemp.setOverDate((Date) i.get("overDate"));
  175. pointTemps.add(planPointTemp);
  176. // planPointTempService.updateById(planPointTemp);
  177. }
  178. planPointTempService.updateBatchById(pointTemps);
  179. } else {
  180. //更新巡检点录入状态
  181. total = planPointTempService.count(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId));
  182. int pointIsOver = planPointTempService.count(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId).eq(PlanPointTemp::getIsover, "1"));
  183. int pointIsCheck = planPointTempService.count(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId).eq(PlanPointTemp::getCheckState, "1"));
  184. isOver = checkTypes.contains(Long.parseLong(plan.get("deviceTypeId").toString())) ? pointIsCheck : pointIsOver;
  185. percent = isOver == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  186. //更新到位点数
  187. PlanChild planChild = new PlanChild();
  188. planChild.setId(childPlanId);
  189. planChild.setPercent(percent);
  190. planChild.setPercent1(percent);
  191. planChild.setTotal(Double.valueOf(total));
  192. planChild.setTotal1(new BigDecimal(total));
  193. planChild.setIsovertototal(Double.valueOf(isOver));
  194. planChild.setIsovertototal1(new BigDecimal(isOver));
  195. planChildService.updateById(planChild);
  196. }
  197. //更新计划状态 完成进度percent1为1 计划变成完成状态
  198. planChildService.update(Wrappers.<PlanChild>lambdaUpdate().set(PlanChild::getChildPlanState, "3")
  199. .eq(PlanChild::getPercent1, 1).eq(PlanChild::getId, childPlanId));
  200. }
  201. Log.warn("#############################4");
  202. }
  203. /**
  204. * 更新到位点信息
  205. * @param childPlanId
  206. * @param temptIds
  207. */
  208. public void pointPlanUpdate(Long childPlanId,List<Long> temptIds) {
  209. int pointTotal = 0;
  210. int pointIsoverTotal = 0;
  211. int isOver = 0; //---------巡检点,巡检线isover个数,其他设备check个数
  212. int total = 0; //point_temp个数
  213. double percent = 0;
  214. double percent1 = 0;
  215. Map plan = customPlanMapper.getTodayPlan(childPlanId).get(0);
  216. PlanChild planChild= planChildService.getById(childPlanId);
  217. //查询包含巡检检查内容的类型
  218. List<SysDeviceType> devices = sysDeviceTypeService.list(Wrappers.<SysDeviceType>lambdaQuery().isNotNull(SysDeviceType::getCheckContent));
  219. Set<Long> checkTypes = new HashSet<>();
  220. devices.stream().filter(n -> !checkTypes.add(n.getPointTypeId()))
  221. .collect(Collectors.toSet());
  222. //更新巡检线录入状态
  223. if ("1".equals(plan.get("type"))) {
  224. List<Map> pathTotal = customPlanMapper.getPathTotalInfo(childPlanId);
  225. total = Integer.valueOf(pathTotal.get(0).get("total").toString());
  226. isOver = checkTypes.contains(plan.get("deviceTypeId")) ? Integer.valueOf(pathTotal.get(0).get("checkTotal").toString()) : Integer.valueOf(pathTotal.get(0).get("isovertotal").toString());
  227. pointTotal = Integer.valueOf(pathTotal.get(0).get("pointTotal").toString());
  228. pointIsoverTotal = Integer.valueOf(pathTotal.get(0).get("pointIsoverTotal").toString());
  229. // percent1 = pointTotal == 0 ? 0 : new BigDecimal((float) pointIsoverTotal / pointTotal).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  230. // percent = pointTotal == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  231. //修改percent1 为point_temp到位情况
  232. percent = pointTotal == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  233. percent1 = pointTotal == 0 ? 0 : new BigDecimal ((float) pointIsoverTotal / pointTotal).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  234. //更新到位条数
  235. PlanChild planChildUpdate = new PlanChild();
  236. planChildUpdate.setId(childPlanId);
  237. planChildUpdate.setPercent(percent);
  238. planChildUpdate.setPercent1(percent1);
  239. planChildUpdate.setTotal1(new BigDecimal(pointTotal));
  240. planChildUpdate.setIsovertototal(percent * total);
  241. planChildUpdate.setIsovertototal1(new BigDecimal(pointIsoverTotal));
  242. planChildUpdate.setIsovertototal0(new BigDecimal(isOver));
  243. planChildService.updateById(planChildUpdate);
  244. //更新线到位比例
  245. List<PlanPointTemp> stateList = planPointTempService.list(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId)
  246. .eq(PlanPointTemp::getState, "0"));
  247. List<PlanPointTemp> pointTemps = new ArrayList<>();
  248. List<TfPlanPathTemp> pathTemps = new ArrayList<>();
  249. for (PlanPointTemp pointTemp : stateList) {
  250. Long pointTempId = pointTemp.getId();
  251. int isOverNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId).eq(TfPlanPathTemp::getIsover, "1"));
  252. int allNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId));
  253. double pathOver = new BigDecimal((float) isOverNum / allNum).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
  254. PlanPointTemp one = new PlanPointTemp();
  255. one.setId(pointTempId);
  256. one.setPathIsover(new BigDecimal(pathOver));
  257. planPointTempService.updateById(one);
  258. }
  259. }
  260. }
  261. }