¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.requier.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.basic.mapper.StructureItemParameterMapper; |
| | | import com.ruoyi.basic.pojo.StructureItemParameter; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.ruoyi.requier.mapper.DeviceFaultMapper; |
| | | import com.ruoyi.requier.mapper.DeviceFaultOneMapper; |
| | | import com.ruoyi.requier.mapper.DeviceMaintenanceMapper; |
| | | import com.ruoyi.requier.mapper.DeviceMapper; |
| | | import com.ruoyi.requier.pojo.*; |
| | | import com.ruoyi.requier.service.DeviceFaultService; |
| | | import com.ruoyi.system.mapper.SysDictDataMapper; |
| | | import com.ruoyi.system.mapper.SysDictTypeMapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class DeviceFaultServiceImpl extends ServiceImpl<DeviceFaultMapper, DeviceFault> implements DeviceFaultService { |
| | | |
| | | @Autowired |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @Autowired |
| | | private QrShowServiceImpl qrShowService; |
| | | |
| | | @Resource |
| | | private SysDictDataMapper sysDictDataMapper; |
| | | |
| | | @Autowired |
| | | private DeviceMaintenanceMapper deviceMaintenanceMapper; |
| | | |
| | | @Autowired |
| | | private StructureItemParameterMapper structureItemParameterMapper; |
| | | |
| | | @Autowired |
| | | private DeviceFaultOneMapper deviceFaultOneMapper; |
| | | |
| | | @Override |
| | | public Map<String,Object> findByDeviceId(Integer deviceId) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | if(Objects.isNull(deviceId)){ |
| | | return map; |
| | | } |
| | | //æ¥è¯¢è®¾å¤ä¸»è¡¨ä¿¡æ¯ |
| | | Device device = deviceMapper.selectById(deviceId); |
| | | if(!Objects.isNull(device)){ |
| | | //æ¥è¯¢è®¾å¤æ ¡åä¿¡æ¯ |
| | | DeviceMetricRecord calibrate = qrShowService.getDeviceMetricRecord(device.getId(), "calibrate"); |
| | | //æ¥è¯¢è®¾å¤æ ¸æ¥ä¿¡æ¯ |
| | | DeviceMetricRecord examine = qrShowService.getDeviceMetricRecord(device.getId(), "examine"); |
| | | //æ¥è¯¢è®¾å¤ç»´æ¤è®°å½ |
| | | DeviceMaintenance deviceMaintenance = Optional.ofNullable(deviceMaintenanceMapper.selectOne(Wrappers.<DeviceMaintenance>lambdaQuery() |
| | | .eq(DeviceMaintenance::getDeviceId, device.getId()) |
| | | .orderByDesc(DeviceMaintenance::getId) |
| | | .last("limit 1"))).orElse(new DeviceMaintenance()); |
| | | //æ¥è¯¢è®¾å¤æ
éä¿¡æ¯ |
| | | List<DeviceFaultOne> deviceFaultOneList = Optional.ofNullable(deviceFaultOneMapper.selectList(Wrappers.<DeviceFaultOne>lambdaQuery() |
| | | .eq(DeviceFaultOne::getDeviceId, device.getId()) |
| | | .orderByDesc(DeviceFaultOne::getId))).orElse(new ArrayList<>()); |
| | | //æ¥è¯¢è®¾å¤ç¶æåå
¸ |
| | | List<SysDictData> sysDictDataList = sysDictDataMapper.selectDictDataByType("device_status"); |
| | | // List<SysDictData> sysDictDataList = DictUtils.getDictCache("设å¤ç¶æ"); |
| | | SysDictData findEnum = sysDictDataList.stream().filter(e-> Integer.parseInt(e.getDictValue()) ==device.getDeviceStatus()).findFirst().orElse(new SysDictData()); |
| | | map.put("progress",qrShowService.calcDeviceNextCheckRatio(calibrate.getCalibrationDate(),calibrate.getNextCalibrationDate()));//è·ç¦»ä¸æ¬¡æ ¡åæ¥æç天æ°ç¾åæ¯ |
| | | map.put("deviceName",device.getDeviceName());//设å¤åç§° |
| | | map.put("deviceCode",device.getManagementNumber());//设å¤ç¼å· |
| | | map.put("usedYears",qrShowService.calcUsedYears(device.getActivationDate()));//å¯ç¨æ¶é¿(å¹´) |
| | | map.put("deviceStatus",findEnum.getDictLabel());//设å¤è¿è¡ç¶æ |
| | | map.put("faultCount",deviceFaultOneList.size());//æ
鿬¡æ° |
| | | String faultDate = !deviceFaultOneList.isEmpty() ?qrShowService.formatDate(deviceFaultOneList.get(0).getFaultDate(),"yyyy-MM-dd"):""; |
| | | map.put("faultDate",faultDate);//æè¿æ
鿥æ |
| | | map.put("lastCalibrationDate",qrShowService.formatDate(calibrate.getCalibrationDate(),"yyyy-MM-dd"));//æè¿æ ¡åæ¥æ |
| | | map.put("nextCalibrationDate",qrShowService.formatDate(calibrate.getNextCalibrationDate(),"yyyy-MM-dd"));//䏿¬¡æ ¡åæ¥æ |
| | | String calibrateStatus = "0yes".equals(calibrate.getStatus())?"åæ ¼":"1no".equals(calibrate.getStatus())?"ä¸åæ ¼":"å
¶ä»"; |
| | | map.put("calibrateStatus",Objects.isNull(calibrate.getCalibrationDate())?"":calibrateStatus);//æ ¡åæ»ç»è®º |
| | | map.put("lastExamineDate",examine.getCalibrationDate());//æè¿æ ¸æ¥æ¥æ |
| | | map.put("nextExamineDate",examine.getNextCalibrationDate());//䏿¬¡æ ¸æ¥æ¥æ |
| | | String examineStatus = "0yes".equals(examine.getStatus())?"åæ ¼":"1no".equals(examine.getStatus())?"ä¸åæ ¼":"å
¶ä»"; |
| | | map.put("examineStatus",Objects.isNull(examine.getCalibrationDate())?"":examineStatus);//æ ¸æ¥æ»ç»è®º |
| | | map.put("maintenanceDate",deviceMaintenance.getDate());//æè¿ç»´æ¤æ¥æ |
| | | map.put("nextMaintenanceDate",deviceMaintenance.getNextDate());//䏿¬¡ç»´æ¤æ¥æ |
| | | String maintenanceType = ""; |
| | | if(!Objects.isNull(deviceMaintenance.getMaintenanceType())){ |
| | | maintenanceType = 0==deviceMaintenance.getMaintenanceType()?"使ç¨åç»´æ¤":"使ç¨åç»´æ¤"; |
| | | } |
| | | map.put("maintenanceType",maintenanceType);//ç»´æ¤æ»ç»è®º |
| | | //æµéé¡¹ç® |
| | | String insProduct = ""; |
| | | if(StringUtils.isNotBlank(device.getInsProductIds())){ |
| | | String[] ids = device.getInsProductIds().split(","); |
| | | List<StructureItemParameter> parameters = structureItemParameterMapper.selectBatchIds(Arrays.asList(ids)); |
| | | List<String> itemList = parameters.stream().map(StructureItemParameter::getInspectionItem).distinct().collect(Collectors.toList()); |
| | | insProduct = String.join(",",itemList); |
| | | } |
| | | map.put("insProduct",insProduct);//æµéé¡¹ç® |
| | | } |
| | | return map; |
| | | } |
| | | } |