| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.constant.BattSingalIdEnum; |
| | | import com.whyc.constant.DevAlarmEnum; |
| | | import com.whyc.constant.PowerAlarmEnum; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.AlarmInspectionMapper; |
| | | import com.whyc.pojo.db_user.Baojigroup; |
| | | import com.whyc.pojo.db_user.User; |
| | | import com.whyc.pojo.web_site.AlarmInspection; |
| | | import com.whyc.pojo.web_site.AlarmInspectionResult; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.DateUtil; |
| | | import com.whyc.util.ThreadLocalUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class AlarmInspectionService { |
| | |
| | | @Resource |
| | | private AlarmInspectionMapper mapper; |
| | | |
| | | @Autowired |
| | | private AlarmInspectionResultService resultService; |
| | | |
| | | public Response getList(Integer stationId, Integer inspectionType) { |
| | | //需要附加填充 负责班组信息 及 告警诊断信息 |
| | | List<AlarmInspection> list = mapper.getList(stationId,inspectionType); |
| | | return new Response().set(1,list); |
| | | } |
| | | |
| | | @Transactional |
| | | public Response submitInspection(AlarmInspectionResult result, List<MultipartFile> file) throws IOException { |
| | | //对file进行处理,保存到文件夹中 |
| | | //对存储路径进行定义 |
| | | String stationName = result.getStationName(); |
| | | Date now = new Date(); |
| | | String timeFormat = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM_DD_HH_MM_SS_UNION, now); |
| | | String fileDirPath = CommonUtil.getRootFile() + "alarmInspection" + File.separator + stationName + "_" + timeFormat; |
| | | File fileDir = new File(fileDirPath); |
| | | //如果文件夹不存在则创建 |
| | | if (!fileDir.exists()) { |
| | | fileDir.mkdirs(); |
| | | } |
| | | StringBuilder pictureUrlSb = new StringBuilder(); |
| | | if (file != null && file.size() > 0) { |
| | | for (MultipartFile multipartFile : file) { |
| | | String fileName = multipartFile.getOriginalFilename(); |
| | | //将fileName中可能存在的,去掉 |
| | | fileName = fileName.replace(",",""); |
| | | String filePath = fileDirPath + File.separator + fileName; |
| | | |
| | | multipartFile.transferTo(new File(filePath)); |
| | | String split = "pis_file"+File.separator+"alarmInspection"; |
| | | pictureUrlSb.append(File.separator + filePath.substring(filePath.indexOf(split))).append(","); |
| | | } |
| | | } |
| | | result.setPictureUrl(pictureUrlSb.toString()); |
| | | |
| | | //根据提交的站点id和inspectionType查询出对应的工单 |
| | | List<AlarmInspection> list = mapper.getList(result.getStationId(),result.getInspectionType()); |
| | | //校验告警是否全部消失,是则通过 |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getIsExist() == 1) { |
| | | return new Response().set(1,false,"当前巡检单内告警未全部消失"); |
| | | } |
| | | } |
| | | //检验通过,进行巡检结果提交,形成巡检历史 |
| | | //判断stationName,powerName,devName,battGroupName是否存在,逐个存在则拼接成一个字符串 |
| | | StringBuilder alarmDescriptionSb = new StringBuilder(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | AlarmInspection temp = list.get(i); |
| | | if (temp.getStationName() != null) { |
| | | alarmDescriptionSb.append(temp.getStationName()).append("-"); |
| | | } |
| | | if (temp.getPowerName() != null) { |
| | | alarmDescriptionSb.append(temp.getPowerName()).append("-"); |
| | | } |
| | | if (temp.getDevName() != null) { |
| | | alarmDescriptionSb.append(temp.getDevName()).append("-"); |
| | | } |
| | | if (temp.getBattGroupName() != null) { |
| | | alarmDescriptionSb.append(temp.getBattGroupName()); |
| | | } |
| | | if(temp.getMonNum() != null){ |
| | | alarmDescriptionSb.append("单体编号:").append(temp.getMonNum()); |
| | | } |
| | | if(temp.getType() == 1) { //电源告警 |
| | | alarmDescriptionSb.append("在" + DateUtil.YYYY_MM_DD_HH_MM_SS.format(temp.getAlmStartTime()) + "发生" + PowerAlarmEnum.getValue(temp.getAlmId()) + "告警,告警级别为" + temp.getAlmLevel() + ".\n"); |
| | | } |
| | | else if(temp.getType() == 2) { //设备告警 |
| | | alarmDescriptionSb.append("在" + DateUtil.YYYY_MM_DD_HH_MM_SS.format(temp.getAlmStartTime()) + "发生" + DevAlarmEnum.getValue(temp.getAlmId()) + "告警,告警级别为" + temp.getAlmLevel() + ".\n"); |
| | | }else{ //电池告警 |
| | | alarmDescriptionSb.append("在" + DateUtil.YYYY_MM_DD_HH_MM_SS.format(temp.getAlmStartTime()) + "发生" + BattSingalIdEnum.getValue(temp.getAlmId()) +"告警,告警级别为" + temp.getAlmLevel() + ".\n"); |
| | | } |
| | | } |
| | | result.setAlarmDescription(alarmDescriptionSb.toString()); |
| | | User user = CommonUtil.getUser(); |
| | | result.setSubmitUserId(user.getId()); |
| | | result.setSubmitUserName(user.getName()); |
| | | result.setCreateTime(new Date()); |
| | | //所属班组 |
| | | Baojigroup baoJiGroup = list.get(0).getBaoJiGroup(); |
| | | result.setBaoJiGroupId(baoJiGroup.getBaojiGroupId()); |
| | | result.setBaoJiGroupName(baoJiGroup.getBaojiGroupName()); |
| | | resultService.add(result); |
| | | |
| | | //删除当前巡检单记录 |
| | | List<Long> ids = list.stream().map(AlarmInspection::getId).collect(Collectors.toList()); |
| | | mapper.deleteBatchIds(ids); |
| | | |
| | | return new Response().set(1,true,"提交完成"); |
| | | } |
| | | } |