| package com.dy.pipIrrApp.workOrder; | 
|   | 
| import com.alibaba.fastjson2.JSON; | 
| import com.alibaba.fastjson2.JSONArray; | 
| import com.alibaba.fastjson2.JSONObject; | 
| import com.dy.common.util.NumUtil; | 
| import com.dy.common.webUtil.QueryResultVo; | 
| import com.dy.pipIrrApp.workOrder.qo.QoWorkOrder; | 
| import com.dy.pipIrrGlobal.daoBa.BaUserMapper; | 
| import com.dy.pipIrrGlobal.daoOp.OpeApproveResultMapper; | 
| import com.dy.pipIrrGlobal.daoOp.OpeProcessingResultMapper; | 
| import com.dy.pipIrrGlobal.daoOp.OpeTaskTypeMapper; | 
| import com.dy.pipIrrGlobal.daoOp.OpeWorkOrderMapper; | 
| import com.dy.pipIrrGlobal.dyFile.FileOperate; | 
| import com.dy.pipIrrGlobal.dyFile.FileRestVo; | 
| import com.dy.pipIrrGlobal.pojoOp.OpeApproveResult; | 
| import com.dy.pipIrrGlobal.pojoOp.OpeProcessingResult; | 
| import com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder; | 
| import com.dy.pipIrrGlobal.voBa.VoRoleSimple; | 
| import com.dy.pipIrrGlobal.voOp.VoProcessingResult; | 
| import com.dy.pipIrrGlobal.voOp.VoProcessingResult_temp; | 
| import com.dy.pipIrrGlobal.voOp.VoTaskType; | 
| import com.dy.pipIrrGlobal.voOp.VoWorkOrder; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.dubbo.common.utils.PojoUtils; | 
| import org.springframework.beans.BeanUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.beans.factory.annotation.Value; | 
| import org.springframework.stereotype.Service; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
| import java.util.Map; | 
| import java.util.Optional; | 
|   | 
| /** | 
|  * @author ZhuBaoMin | 
|  * @date 2024-11-04 9:29 | 
|  * @LastEditTime 2024-11-04 9:29 | 
|  * @Description 工单服务类 | 
|  */ | 
|   | 
| @Slf4j | 
| @Service | 
| public class WorkOrderSv { | 
|     @Autowired | 
|     private OpeWorkOrderMapper opeWorkOrderMapper; | 
|   | 
|     @Autowired | 
|     private OpeProcessingResultMapper opeProcessingResultMapper; | 
|   | 
|     @Autowired | 
|     private OpeApproveResultMapper opeApproveResultMapper; | 
|   | 
|     @Autowired | 
|     private OpeTaskTypeMapper opeTaskTypeMapper; | 
|   | 
|     @Autowired | 
|     private BaUserMapper baUserMapper; | 
|   | 
|     @Value("${dy.webFile.fmUrl}") | 
|     private String fmUrl ; | 
|   | 
|     @Autowired | 
|     private FileOperate fileOp ; | 
|   | 
|     private void dealWebFilePath(JSONArray jsonArray, boolean hasZipFile, boolean isVideo){ | 
|         for (Object obj : jsonArray){ | 
|             if(obj instanceof JSONObject){ | 
|                 JSONObject jsonObject = (JSONObject) obj; | 
|                 Object hashObj = jsonObject.get("hash") ; | 
|                 if(hashObj != null && NumUtil.isIntNumber(hashObj.toString())){ | 
|                     FileRestVo fvo = fileOp.parseHashcode(fmUrl, Integer.valueOf(hashObj.toString())); | 
|                     if(fvo != null && fvo.fileWebUrl != null){ | 
|                         jsonObject.put("webPath", fvo.fileWebUrl + jsonObject.get("filePath")); | 
|                         if(hasZipFile){ | 
|                             if(!isVideo){ | 
|                                 jsonObject.put("webPathZip", fileOp.getFileZipPath(fvo.fileWebUrl + jsonObject.get("filePath"))); | 
|                             }else{ | 
|                                 jsonObject.put("webPathZip", fileOp.getFileZipPath(fvo.fileWebUrl + jsonObject.get("filePath"), "jpg")); | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|     } | 
|     /** | 
|      * 添加工单记录 | 
|      * @param po | 
|      * @return | 
|      */ | 
|     public Long insertWorkOrder(OpeWorkOrder po) { | 
|         po.setDispatchTime(new Date()); | 
|         po.setState((byte) 1); | 
|         po.setRejectTimes(0); | 
|         po.setDeleted(0L); | 
|   | 
|         opeWorkOrderMapper.insert(po); | 
|         return po.getId(); | 
|     } | 
|   | 
|     /** | 
|      * 获取指定派单人的指定未删除工单,删除工单前判断使用使用 | 
|      * @param dispatcherId | 
|      * @param workOrderId | 
|      * @return | 
|      */ | 
|     public OpeWorkOrder getWorkOrder(Long workOrderId, Long dispatcherId) { | 
|         return opeWorkOrderMapper.getWorkOrder(workOrderId, dispatcherId); | 
|     } | 
|   | 
|     /** | 
|      * 逻辑删除一个未删除的工单 | 
|      * @param workOrderId | 
|      * @return | 
|      */ | 
|     public Integer deleteWorkOrder(Long workOrderId) { | 
|         return opeWorkOrderMapper.deleteWorkOrder(workOrderId); | 
|     } | 
|   | 
|     /** | 
|      * 根据指定条件获取工单 | 
|      * @param qo | 
|      * @return | 
|      */ | 
|     public QueryResultVo<List<VoWorkOrder>> getWorkOrders(QoWorkOrder qo) { | 
|         qo.completionTime() ; | 
|   | 
|         Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(qo); | 
|         Long itemTotal = opeWorkOrderMapper.getWorkOrdersCount(params); | 
|   | 
|         QueryResultVo<List<VoWorkOrder>> rsVo = new QueryResultVo<>() ; | 
|         rsVo.pageSize = qo.pageSize ; | 
|         rsVo.pageCurr = qo.pageCurr ; | 
|   | 
|         rsVo.calculateAndSet(itemTotal, params); | 
|         rsVo.obj = opeWorkOrderMapper.getWorkOrders(params); | 
|         return rsVo ; | 
|     } | 
|   | 
|     /** | 
|      * 根据工单主键获取工单视图对象 | 
|      * @param workOrderId | 
|      * @return | 
|      */ | 
|     public VoWorkOrder getWorkOrderById(Long workOrderId) { | 
|         return opeWorkOrderMapper.getWorkOrderById(workOrderId); | 
|     } | 
|   | 
|     /** | 
|      * 上报工单处理结果 | 
|      * @param po | 
|      * @return | 
|      */ | 
|     public String addProcessingResult(OpeProcessingResult po) { | 
|         String result = ""; | 
|         OpeProcessingResult processingResult = opeProcessingResultMapper.getByWorkOrderId(po.getWorkOrderId()); | 
|         if(processingResult == null) { | 
|             // 无处理结果上报处理结果 | 
|             po.setReportTime(new Date()); | 
|             po.setState((byte)1); | 
|             po.setDeleted(0L); | 
|             opeProcessingResultMapper.insert(po); | 
|             if(po.getId() == 0) { | 
|                 result = "工单处理结果上报失败"; | 
|                 return result; | 
|             } | 
|   | 
|             result = "success"; | 
|             return result; | 
|         } | 
|   | 
|         switch (processingResult.getState()) { | 
|             case 1: | 
|                 result = "工单处理结果已上报,请勿重复上报"; | 
|                 break; | 
|             case 2: | 
|                 result = "工单处理结果已通过"; | 
|                 break; | 
|             case 3: | 
|                 // 处理结果被驳回时,删除当前处理结果,上报新的处理结果 | 
|                 processingResult.setDeleted(System.currentTimeMillis()/1000); | 
|                 opeProcessingResultMapper.updateByPrimaryKeySelective(processingResult); | 
|   | 
|                 po.setReportTime(new Date()); | 
|                 po.setState((byte)1); | 
|                 po.setDeleted(0L); | 
|                 opeProcessingResultMapper.insert(po); | 
|                 result = "success"; | 
|                 break; | 
|         } | 
|   | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 获取指定巡检员的指定未删除且未审批的处理结果上报,删除处理结果前判断使用使用 | 
|      * @param proResultId | 
|      * @param inspectorId | 
|      * @return | 
|      */ | 
|     public OpeProcessingResult getProResult(Long proResultId, Long inspectorId) { | 
|         return opeProcessingResultMapper.getProResult(proResultId, inspectorId); | 
|     } | 
|   | 
|     /** | 
|      * 逻辑删除一个未删除的处理结果 | 
|      * @param proResultId | 
|      * @return | 
|      */ | 
|     public Integer deleteProResult(Long proResultId) { | 
|         return opeProcessingResultMapper.deleteProResult(proResultId); | 
|     } | 
|   | 
|     /** | 
|      * 获取处理结果详情 | 
|      * @param proResultId | 
|      * @return | 
|      */ | 
|     public VoProcessingResult getProResultById(Long proResultId) { | 
|         VoProcessingResult_temp result_temp = opeProcessingResultMapper.getProResultById(proResultId); | 
|         VoProcessingResult result = new VoProcessingResult(); | 
|         BeanUtils.copyProperties(result_temp, result); | 
|   | 
|         JSONArray images_array = Optional.ofNullable(JSON.parseArray(result_temp.getImages())).orElse(new JSONArray()); | 
|         JSONArray audios_array = Optional.ofNullable(JSON.parseArray(result_temp.getAudios())).orElse(new JSONArray()); | 
|         JSONArray videos_array = Optional.ofNullable(JSON.parseArray(result_temp.getVideos())).orElse(new JSONArray()); | 
|         this.dealWebFilePath(images_array, true, false) ; | 
|         this.dealWebFilePath(audios_array, false, false) ; | 
|         this.dealWebFilePath(videos_array, true, true) ; | 
|         result.setImages(images_array); | 
|         result.setAudios(audios_array); | 
|         result.setVideos(videos_array); | 
|   | 
|         return result; | 
|     } | 
|   | 
|     /** | 
|      * 审核工单处理结果 | 
|      *      1. 判断指定的工单及处理结果是否存在且未完成 | 
|      *      2. 添加审核记录 | 
|      *      3. 如果审核通过 | 
|      *          处理结果状态改为已通过 | 
|      *          工单补充任务完成时间 | 
|      *          工单状态改为已完成 | 
|      *      4. 如果驳回 | 
|      *          任务处理结果改为驳回 | 
|      *          工单驳回次数加1 | 
|      * @param po | 
|      * @return | 
|      */ | 
|     public String approveProResult(OpeApproveResult po) { | 
|   | 
|         OpeProcessingResult processingResult = opeProcessingResultMapper.selectByPrimaryKey(po.getProcessingResultId()); | 
|         if(processingResult == null || processingResult.getDeleted() != 0 || processingResult.getState() != 1) { | 
|             return "处理结果不存在或已完成审核"; | 
|         } | 
|   | 
|         OpeWorkOrder workOrder = opeWorkOrderMapper.selectByPrimaryKey(po.getWorkOrderId()); | 
|         if(workOrder == null || workOrder.getDeleted() != 0 || workOrder.getState() == 2) { | 
|             return "工单不存在或已完成"; | 
|         } | 
|   | 
|         po.setApproveTime(new Date()); | 
|         po.setDeleted(0L); | 
|         if(opeApproveResultMapper.insert(po) == 0) { | 
|             return "审核记录添加失败"; | 
|         } | 
|   | 
|         if(po.getApproveResult() == 1) { | 
|             // 审核通过 | 
|             processingResult.setState((byte)2); | 
|             opeProcessingResultMapper.updateByPrimaryKeySelective(processingResult); | 
|   | 
|             workOrder.setCompleteTime(processingResult.getCompleteTime()); | 
|             workOrder.setState((byte)2); | 
|             opeWorkOrderMapper.updateByPrimaryKeySelective(workOrder); | 
|   | 
|         } else { | 
|             // 驳回 | 
|             processingResult.setState((byte)3); | 
|             opeProcessingResultMapper.updateByPrimaryKeySelective(processingResult); | 
|   | 
|             workOrder.setRejectTimes(workOrder.getRejectTimes() + 1); | 
|             opeWorkOrderMapper.updateByPrimaryKeySelective(workOrder); | 
|         } | 
|   | 
|         return "success"; | 
|     } | 
|   | 
|     /** | 
|      * 获取任务类型列表 | 
|      * @return | 
|      */ | 
|     public List<VoTaskType> getTaskTypes() { | 
|         return opeTaskTypeMapper.getTaskTypes(); | 
|     } | 
|   | 
|     /** | 
|      * 获取巡检员列表 | 
|      * @param inspector | 
|      * @return | 
|      */ | 
|     public List<VoRoleSimple> getInspectors(String inspector) { | 
|         return baUserMapper.getInspectors(inspector); | 
|     } | 
| } |