123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- package com.tofly.dyrq.custom.service.impl;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.tofly.common.core.util.Date8Util;
- import com.tofly.dyrq.custom.entity.PointContent;
- import com.tofly.dyrq.custom.entity.UpdatePoint;
- import com.tofly.dyrq.custom.mapper.CustomPlanMapper;
- import com.tofly.dyrq.custom.mapper.CustomPointMapper;
- import com.tofly.dyrq.custom.mapper.PointContentMapper;
- import com.tofly.dyrq.custom.service.CustomPointService;
- import com.tofly.dyrq.entity.PlanChild;
- import com.tofly.dyrq.entity.PlanPointTemp;
- import com.tofly.dyrq.entity.SysDeviceType;
- import com.tofly.dyrq.entity.TfPlanPathTemp;
- import com.tofly.dyrq.service.PlanChildService;
- import com.tofly.dyrq.service.PlanPointTempService;
- import com.tofly.dyrq.service.SysDeviceTypeService;
- import com.tofly.dyrq.service.TfPlanPathTempService;
- import lombok.AllArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.collections.CollectionUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.data.redis.core.ValueOperations;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- import javax.annotation.PostConstruct;
- @Service
- @AllArgsConstructor
- @Slf4j
- public class CustomPointServiceImpl implements CustomPointService {
- private CustomPointMapper customPointMapper;
- private PlanPointTempService planPointTempService;
- private PlanChildService planChildService;
- private TfPlanPathTempService planPathTempService;
- private final CustomPlanMapper customPlanMapper;
- private final SysDeviceTypeService sysDeviceTypeService;
- private final ValueOperations<String, String> valueOperations;
- private final RedisTemplate redisTemplate;
- private PointContentMapper pointContentMapper;
-
-
-
- @Override
- @Transactional
- public Map<String, Long> updatePointOrPathIsover(List<UpdatePoint> updatePoints) {
- Map<String, Long> transfer = new HashMap<>();
- List<Long> childList = new ArrayList<>();
- HashSet<Long> childIds = new HashSet();
-
- for (UpdatePoint u : updatePoints) {
- if (u.getTempId() != null && u.getCheckTime() != null && u.getGpsSpeed() != null) {
- if ("0".equals(u.getType())) {
- String pointChildPlanState = customPointMapper.getStateByPointId(u.getTempId());
- if ("7".equals(pointChildPlanState)) {
- transfer.put("pointTempId", u.getTempId());
- continue;
- }
-
- PointContent pc =new PointContent();
- pc.setIsHandle(0);
- pc.setJsonContent(JSON.toJSONString(u));
- pc.setJsonType(1);
- pointContentMapper.insert(pc);
-
-
- } else if ("1".equals(u.getType())) {
- String childPlanState = customPointMapper.getStateByPath(u.getTempId());
- if ("7".equals(childPlanState)) {
- transfer.put("pathTempId", u.getTempId());
- continue;
- } else {
- if (!childList.contains(u.getPlanChildId())) {
- childList.add(u.getPlanChildId());
- }
- }
- PointContent pc1 =new PointContent();
- pc1.setIsHandle(0);
- pc1.setJsonContent(JSON.toJSONString(u));
- pc1.setJsonType(2);
- pointContentMapper.insert(pc1);
-
-
- }
- }
- childIds.add(u.getPlanChildId());
- }
-
- PointContent pc2 =new PointContent();
- pc2.setIsHandle(0);
- pc2.setJsonContent(StringUtils.join(childIds, ","));
- pc2.setJsonType(3);
- pointContentMapper.insert(pc2);
-
-
- return transfer;
- }
-
-
-
- @Async("asyncServiceExecutor")
- @PostConstruct
- @Scheduled(fixedDelay = 5000)
- public void executPoint() {
- try {
-
- List<PointContent> pcList= pointContentMapper.selectList(Wrappers.<PointContent>lambdaQuery()
- .eq(PointContent::getIsHandle, 0).eq(PointContent::getJsonType, 1));
- if (pcList.size()!=0) {
- for(PointContent pc : pcList) {
- String pointValue = pc.getJsonContent();
- JSONObject jsonObject = JSONObject.parseObject(pointValue);
- UpdatePoint u = JSON.toJavaObject(jsonObject,UpdatePoint.class);
- planPointTempService.update(Wrappers.<PlanPointTemp>lambdaUpdate()
- .set(PlanPointTemp::getIsover, "1")
- .set(PlanPointTemp::getOverDate, u.getCheckTime())
- .set(PlanPointTemp::getGpsSpeed, u.getGpsSpeed())
- .eq(PlanPointTemp::getId, u.getTempId()));
- pc.setIsHandle(1);
- pointContentMapper.updateById(pc);
- }
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- @Async("asyncServiceExecutor")
- @PostConstruct
- @Scheduled(fixedDelay = 5000)
- public void executPath() {
-
- try {
- List<PointContent> pcList= pointContentMapper.selectList(Wrappers.<PointContent>lambdaQuery()
- .eq(PointContent::getIsHandle, 0).eq(PointContent::getJsonType, 2));
-
-
- System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&"+pcList.size());
-
- if (pcList.size()!=0) {
- for(PointContent pc : pcList) {
- String pathValue = pc.getJsonContent();;
- JSONObject jsonObject = JSONObject.parseObject(pathValue);
- UpdatePoint up = JSON.toJavaObject(jsonObject,UpdatePoint.class);
- TfPlanPathTemp tppt = planPathTempService.getById(up.getTempId());
- if(null!=tppt) {
- boolean pathflag =planPathTempService.update(Wrappers.<TfPlanPathTemp>lambdaUpdate()
- .set(TfPlanPathTemp::getIsover, "1")
- .set(TfPlanPathTemp::getOverDate, up.getCheckTime())
- .set(TfPlanPathTemp::getGpsSpeed, up.getGpsSpeed())
- .eq(TfPlanPathTemp::getId, up.getTempId()));
-
- Long pointTempId =tppt.getTempId();
- int isOverNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId).eq(TfPlanPathTemp::getIsover, "1"));
- int allNum = planPathTempService.count(Wrappers.<TfPlanPathTemp>lambdaQuery().eq(TfPlanPathTemp::getTempId, pointTempId));
- double pathOver = new BigDecimal((float) isOverNum / allNum).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
- PlanPointTemp one = new PlanPointTemp();
- one.setId(pointTempId);
- one.setPathIsover(new BigDecimal(pathOver));
- planPointTempService.updateById(one);
- pc.setIsHandle(1);
- pointContentMapper.updateById(pc);
- }
- }
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- @Async("asyncServiceExecutor")
- @PostConstruct
- @Scheduled(fixedDelay = 6000)
- public void executChild() {
- try {
- List<PointContent> pcList= pointContentMapper.selectList(Wrappers.<PointContent>lambdaQuery()
- .eq(PointContent::getIsHandle, 0).eq(PointContent::getJsonType, 3));
-
- if (pcList.size()!=0) {
- for(PointContent pc : pcList) {
- String childValue = pc.getJsonContent();
- List<String> list = Arrays.asList(childValue.split(","));
-
- for (String sid : list) {
- Long childPlanId = Long.parseLong(sid);
- Date now = Date8Util.getCurrentDate();
-
- Map param1 = new HashMap();
- param1.put("now", now);
- int pointTotal = 0;
- int pointIsoverTotal = 0;
- int isOver = 0;
- int total = 0;
- double percent = 0;
- double percent1 = 0;
-
- Map plan = null;
-
- if(customPlanMapper.getTodayPlan(childPlanId).size()!=0) {
- plan = customPlanMapper.getTodayPlan(childPlanId).get(0);
- }else {
- continue;
- }
-
-
- List<SysDeviceType> devices = sysDeviceTypeService.list(Wrappers.<SysDeviceType>lambdaQuery().isNotNull(SysDeviceType::getCheckContent));
- Set<Long> checkTypes = new HashSet<>();
- devices.stream().filter(n -> !checkTypes.add(n.getPointTypeId()))
- .collect(Collectors.toSet());
-
-
- if ("1".equals(plan.get("type"))) {
- List<Map> pathTotal = customPlanMapper.getPathTotalInfo(childPlanId);
- total = Integer.valueOf(pathTotal.get(0).get("total").toString());
- isOver = checkTypes.contains(plan.get("deviceTypeId")) ? Integer.valueOf(pathTotal.get(0).get("checkTotal").toString()) : Integer.valueOf(pathTotal.get(0).get("isovertotal").toString());
- pointTotal = Integer.valueOf(pathTotal.get(0).get("pointTotal").toString());
- pointIsoverTotal = Integer.valueOf(pathTotal.get(0).get("pointIsoverTotal").toString());
-
- percent = pointTotal == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
- percent1 = pointTotal == 0 ? 0 : new BigDecimal ((float) pointIsoverTotal / pointTotal).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
-
- PlanChild planChild = new PlanChild();
- planChild.setId(childPlanId);
- planChild.setPercent(percent);
- planChild.setPercent1(percent1);
- planChild.setTotal1(new BigDecimal(pointTotal));
- planChild.setIsovertototal(percent * total);
- planChild.setIsovertototal1(new BigDecimal(pointIsoverTotal));
- planChild.setIsovertototal0(new BigDecimal(isOver));
- planChildService.updateById(planChild);
- List<PlanPointTemp> pointTemps = new ArrayList<>();
-
-
- List<Map> pathMax = customPlanMapper.getPathMaxSpeed(childPlanId);
- for (Map i : pathMax) {
- PlanPointTemp planPointTemp = new PlanPointTemp();
- planPointTemp.setIsover("1");
- planPointTemp.setGpsSpeed((BigDecimal) i.get("gpsSpeed"));
- planPointTemp.setState("1");
- planPointTemp.setId(Long.parseLong(i.get("tempId").toString()));
- planPointTemp.setOverDate((Date) i.get("overDate"));
- pointTemps.add(planPointTemp);
- }
- if(pointTemps.size()!=0) {
- planPointTempService.updateBatchById(pointTemps);
- }
- } else {
-
- total = planPointTempService.count(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId));
- int pointIsOver = planPointTempService.count(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId).eq(PlanPointTemp::getIsover, "1"));
- int pointIsCheck = planPointTempService.count(Wrappers.<PlanPointTemp>lambdaQuery().eq(PlanPointTemp::getChildPlanId, childPlanId).eq(PlanPointTemp::getCheckState, "1"));
- isOver = checkTypes.contains(Long.parseLong(plan.get("deviceTypeId").toString())) ? pointIsCheck : pointIsOver;
- percent = isOver == 0 ? 0 : new BigDecimal((float) isOver / total).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
-
- PlanChild planChild = new PlanChild();
- planChild.setId(childPlanId);
- planChild.setPercent(percent);
- planChild.setPercent1(percent);
- planChild.setTotal(Double.valueOf(total));
- planChild.setTotal1(new BigDecimal(total));
- planChild.setIsovertototal(Double.valueOf(isOver));
- planChild.setIsovertototal1(new BigDecimal(isOver));
- planChildService.updateById(planChild);
- }
-
- planChildService.update(Wrappers.<PlanChild>lambdaUpdate().set(PlanChild::getChildPlanState, "3")
- .eq(PlanChild::getPercent1, 1).eq(PlanChild::getId, childPlanId));
- }
- pc.setIsHandle(1);
- pointContentMapper.updateById(pc);
- }
- }
- }catch (Exception e) {
-
- }
- }
- }
|