package com.gkhy.safePlatform.safeCheck.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService;
|
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserRPCRespDTO;
|
import com.gkhy.safePlatform.commons.co.ContextCacheUser;
|
import com.gkhy.safePlatform.commons.enums.E;
|
import com.gkhy.safePlatform.commons.exception.AusinessException;
|
import com.gkhy.safePlatform.commons.vo.ResultVO;
|
import com.gkhy.safePlatform.safeCheck.entity.AbnormalWorkOrder;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckRfid;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckTask;
|
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckTaskAndQuota;
|
import com.gkhy.safePlatform.safeCheck.enums.DelectStatusEnum;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckSmartScreenRepsDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO;
|
import com.gkhy.safePlatform.safeCheck.model.dto.resp.SafeCheckTaskAndQuotaRespDTO;
|
import com.gkhy.safePlatform.safeCheck.rpc.apimodel.model.resp.SafeCheckTaskAndQuotaExcepOrderRPCRespDTO;
|
import com.gkhy.safePlatform.safeCheck.rpc.apimodel.model.resp.SafeCheckTaskAndQuotaGBRfidAndExcpOrderRPCRespDTO;
|
import com.gkhy.safePlatform.safeCheck.service.SafeCheckMinioAccessService;
|
import com.gkhy.safePlatform.safeCheck.service.SafeCheckSmartScreenService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.AbnormalWorkOrderService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckRfidService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckTaskAndQuotaService;
|
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckTaskService;
|
import com.gkhy.safePlatform.safeCheck.util.UserInfoUtil;
|
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.ArrayList;
|
import java.util.HashSet;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class SafeCheckSmartScreenServiceImpl implements SafeCheckSmartScreenService {
|
|
@DubboReference(check = false)
|
private AccountAuthService accountAuthService;
|
|
|
@Autowired
|
private SafeCheckTaskService taskService;
|
|
@Autowired
|
private SafeCheckTaskAndQuotaService taskAndQuotaService;
|
|
@Autowired
|
private SafeCheckRfidService safeCheckRfidService;
|
|
@Autowired
|
private AbnormalWorkOrderService abnormalWorkOrderService;
|
|
@Autowired
|
private SafeCheckMinioAccessService safeCheckMinioAccessService;
|
|
/**
|
* @description 根据巡检任务id获取所有的巡检链数据,对相同的rfid进行分组反馈
|
*/
|
@Transactional
|
@Override
|
public List<SafeCheckSmartScreenRepsDTO> getSmartScreenData(Long taskId) {
|
|
if (taskId == null){
|
throw new AusinessException(E.DATA_PARAM_NULL,"巡检任务id不能为空");
|
}
|
SafeCheckTask task = taskService.getTaskById(taskId);
|
if (task == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"任务不存在");
|
}
|
List<SafeCheckTaskAndQuota> taskAndQuotasSource = taskAndQuotaService.listTaskAndQuotaByTaskId(taskId);
|
|
|
if (taskAndQuotasSource == null){
|
throw new AusinessException(E.DATA_DATABASE_NO_EXISTENT,"该任务无对应的巡检链数据");
|
}
|
List<SafeCheckTaskAndQuotaRespDTO> taskAndQuotas = taskAndQuotasSource.stream().map((taskAndQuotaSource)->{
|
SafeCheckTaskAndQuotaRespDTO taskAndQuota = new SafeCheckTaskAndQuotaRespDTO();
|
BeanUtils.copyProperties(taskAndQuotaSource,taskAndQuota);
|
return taskAndQuota;
|
}).collect(Collectors.toList());
|
|
|
List<SafeCheckSmartScreenRepsDTO> smartScreenDataS = new ArrayList<>();
|
//首先获取有哪些巡检点 利用set属性进行去重
|
HashSet<String> rfids = new HashSet<>();
|
|
for (SafeCheckTaskAndQuotaRespDTO taskAndQuota : taskAndQuotas) {
|
String rfid = taskAndQuota.getRfid();
|
rfids.add(rfid);
|
}
|
if (rfids.size() == 0){
|
return smartScreenDataS;
|
}
|
|
for (String rfid : rfids) {
|
SafeCheckSmartScreenRepsDTO smartScreenData = new SafeCheckSmartScreenRepsDTO();
|
List<SafeCheckTaskAndQuotaRespDTO> points = new ArrayList<>();
|
HashSet<String> regionNames = new HashSet<>();
|
for (int i = 0; i < taskAndQuotas.size(); i++) {
|
String sonRfid = taskAndQuotas.get(i).getRfid();
|
if (rfid.equals(sonRfid)){
|
if(smartScreenData.getRfid() == null){
|
SafeCheckRfid safeCheckRfid = safeCheckRfidService.getRfid(rfid, DelectStatusEnum.DELECT_NO.getStatus().intValue());
|
if (safeCheckRfid.getRfidImage() == null){
|
smartScreenData.setRfidImage(null);
|
}else {
|
String rfidImageAddress = safeCheckMinioAccessService.viewFile(safeCheckRfid.getRfidImage());
|
smartScreenData.setRfidImage(rfidImageAddress);
|
}
|
smartScreenData.setId(taskAndQuotas.get(i).getTaskId());
|
smartScreenData.setTaskUuid(taskAndQuotas.get(i).getTaskUuid());
|
smartScreenData.setRfid(taskAndQuotas.get(i).getRfid());
|
smartScreenData.setRfidName(taskAndQuotas.get(i).getRfidName());
|
}
|
regionNames.add(taskAndQuotas.get(i).getRegion());
|
points.add(taskAndQuotas.get(i));
|
smartScreenData.setPoints(points);
|
}
|
}
|
ArrayList<String> regions = new ArrayList<>();
|
for (String regionName : regionNames) {
|
if (regionName != null){
|
regions.add(regionName);
|
}
|
}
|
smartScreenData.setRegion(regions);
|
smartScreenDataS.add(smartScreenData);
|
}
|
return smartScreenDataS;
|
}
|
|
/**
|
* @description 根据巡检任务id获取该任务的异常工单信息
|
*/
|
@Override
|
public List<SafeCheckTaskAndQuotaExcepOrderRPCRespDTO> getSmartScreenExcepOrderInfos(Long taskId) {
|
LambdaQueryWrapper<AbnormalWorkOrder> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(AbnormalWorkOrder::getTaskId,taskId)
|
.orderByDesc(AbnormalWorkOrder::getOccurrenceTime);
|
List<AbnormalWorkOrder> abnormalWorkOrders = abnormalWorkOrderService.list(wrapper);
|
if (CollectionUtils.isEmpty(abnormalWorkOrders)){
|
return null;
|
}
|
List<SafeCheckTaskAndQuotaExcepOrderRPCRespDTO> dtos = abnormalWorkOrders.stream().map((abnormalWorkOrder) -> {
|
SafeCheckTaskAndQuotaExcepOrderRPCRespDTO excepOrderRPCRespDTO = new SafeCheckTaskAndQuotaExcepOrderRPCRespDTO();
|
BeanUtils.copyProperties(abnormalWorkOrder, excepOrderRPCRespDTO);
|
return excepOrderRPCRespDTO;
|
}).collect(Collectors.toList());
|
return dtos;
|
}
|
|
/**
|
* @description 根据巡检任务id获取所有的巡检链数据,对相同的rfid进行分组反馈 以及异常信息
|
*/
|
@Override
|
public SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO getSmartScreenDataAndExcOrderInfo(Long taskId) {
|
SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO dto = new SafeCheckTaskAndQuotaGBRfidAndExcpOrderRespDTO();
|
List<SafeCheckTaskAndQuotaExcepOrderRPCRespDTO> excepOrderInfos = getSmartScreenExcepOrderInfos(taskId);
|
List<SafeCheckSmartScreenRepsDTO> screenData = getSmartScreenData(taskId);
|
dto.setExcepOrder(excepOrderInfos);
|
dto.setRfidInfos(screenData);
|
return dto;
|
}
|
}
|