| | |
| | | package com.dy.pipIrrApp.workOrder; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.aop.SsoAop; |
| | | import com.dy.common.webUtil.BaseResponse; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrApp.workOrder.dto.DtoDeleteProResult; |
| | | import com.dy.pipIrrApp.workOrder.dto.DtoDeleteWorkOrder; |
| | | import com.dy.pipIrrApp.workOrder.mqtt.MqttClientConnectorPool; |
| | | import com.dy.pipIrrApp.workOrder.mqtt.MqttMsgSender; |
| | | import com.dy.pipIrrApp.workOrder.qo.QoWorkOrder; |
| | | import com.dy.pipIrrGlobal.pojoOp.OpeApproveResult; |
| | | import com.dy.pipIrrGlobal.pojoOp.OpeProcessingResult; |
| | | import com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder; |
| | | import com.dy.pipIrrGlobal.voOp.VoProcessingResult; |
| | | import com.dy.pipIrrGlobal.voOp.VoTaskType; |
| | | import com.dy.pipIrrGlobal.voOp.VoWorkOrder; |
| | | import jakarta.validation.Valid; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.rocketmq.client.exception.MQBrokerException; |
| | | import org.apache.rocketmq.client.exception.MQClientException; |
| | | import org.apache.rocketmq.client.producer.DefaultMQProducer; |
| | | import org.apache.rocketmq.client.producer.SendResult; |
| | | import org.apache.rocketmq.common.message.Message; |
| | | import org.apache.rocketmq.remoting.exception.RemotingException; |
| | | import org.apache.rocketmq.spring.core.RocketMQTemplate; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.eclipse.paho.client.mqttv3.MqttClient; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | public class WorkOrderCtrl { |
| | | private final WorkOrderSv workOrderSv; |
| | | |
| | | @Autowired |
| | | private RocketMQTemplate rocketMQTemplate; |
| | | @Value("${mqtt.broker}") |
| | | private String broker; |
| | | |
| | | @Value("${rocketmq.name-server}") |
| | | protected String nameServer; |
| | | @Value("${mqtt.username}") |
| | | private String username; |
| | | |
| | | @Value("${rocketmq.producer.group}") |
| | | protected String producerGroup; |
| | | @Value("${mqtt.password}") |
| | | private String password; |
| | | |
| | | @Value("${rocketmq.topic}") |
| | | protected String topic; |
| | | @Value("${mqtt.topic}") |
| | | private String topic; |
| | | |
| | | @Value("${mqtt.qos}") |
| | | private Integer qos; |
| | | |
| | | /** |
| | | * 创建工单 |
| | |
| | | @PostMapping(path = "addWorkOrder", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> addWorkOrder(@RequestBody @Valid OpeWorkOrder po, BindingResult bindingResult) throws MQBrokerException, RemotingException, InterruptedException, MQClientException { |
| | | public BaseResponse<Boolean> addWorkOrder(@RequestBody @Valid OpeWorkOrder po, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过RocketMQ推送工单主键 |
| | | * @param voWorkOrder 工单视图对象 |
| | | * 通过mosquitto发送巡检员ID及工单ID |
| | | * @param voWorkOrder 工单对象 |
| | | * @param workOrderId 工单ID |
| | | * @return |
| | | * @throws MQClientException |
| | | * @throws MQBrokerException |
| | | * @throws RemotingException |
| | | * @throws InterruptedException |
| | | */ |
| | | private Boolean sendWorkOrder(VoWorkOrder voWorkOrder, Long workOrderId) throws MQClientException, MQBrokerException, RemotingException, InterruptedException { |
| | | String tag = voWorkOrder.getInspector(); |
| | | String key = voWorkOrder.getInspectorId().toString(); |
| | | public Boolean sendWorkOrder(VoWorkOrder voWorkOrder, Long workOrderId) { |
| | | //String message = JSON.toJSONString(voWorkOrder); |
| | | String message = workOrderId.toString(); |
| | | |
| | | DefaultMQProducer producer = new DefaultMQProducer(producerGroup); |
| | | producer.setNamesrvAddr(nameServer); |
| | | producer.start(); |
| | | Message msg = new Message(topic, tag, key, message.getBytes(StandardCharsets.UTF_8)); |
| | | SendResult approveSendResult = producer.send(msg); |
| | | if(!approveSendResult.getSendStatus().toString().equals("SEND_OK")) { |
| | | JSONObject message_job = new JSONObject(); |
| | | message_job.put("inspectorId", voWorkOrder.getInspectorId().toString()); |
| | | message_job.put("workOrderId", workOrderId.toString()); |
| | | String message = JSON.toJSONString(message_job); |
| | | |
| | | MqttClient mqttClient = MqttClientConnectorPool.connectMQTT(broker, username, password); |
| | | MqttMsgSender sender = new MqttMsgSender(); |
| | | if (null != mqttClient){ |
| | | sender.sendMessage(mqttClient, topic, message, qos); |
| | | } else { |
| | | log.info("MqttClient为空,无法发送!"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | OpeWorkOrder workOrder = workOrderSv.getWorkOrder(deleteWorkOrder.getDispatcherId(), deleteWorkOrder.getWorkOrderId()); |
| | | OpeWorkOrder workOrder = workOrderSv.getWorkOrder(deleteWorkOrder.getWorkOrderId(), deleteWorkOrder.getDispatcherId()); |
| | | if(workOrder == null) { |
| | | return BaseResponseUtils.buildErrorMsg("您要删除的工单不存在"); |
| | | } |
| | |
| | | if(workOrderSv.deleteWorkOrder(deleteWorkOrder.getWorkOrderId()) == 0) { |
| | | return BaseResponseUtils.buildErrorMsg("工单删除失败"); |
| | | } |
| | | |
| | | |
| | | return BaseResponseUtils.buildSuccess(); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getOneWorkOrder") |
| | | @SsoAop() |
| | | public BaseResponse<VoWorkOrder> getOneWorkOrder(@RequestParam("workOrderId") Long workOrderId) { |
| | | try { |
| | | return BaseResponseUtils.buildSuccess(workOrderSv.getWorkOrderById(workOrderId)); |
| | |
| | | |
| | | /** |
| | | * 上报工单处理结果 |
| | | * 判断该工单是否存在有效的处理结果,如果存在则提示用户该工单已存在处理结果 |
| | | * 添加处理结果回复 |
| | | * 1.未上报的,直接上报 |
| | | * 2. 已上报的的,提示用户不能重复上报 |
| | | * 3. 已通过的,提示用户处理结果处理结果已通过 |
| | | * 4. 驳回的,逻辑删除原处理结果,上报新的处理结果 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "addProcessingResult") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> addProcessingResult(@RequestBody @Valid OpeProcessingResult po, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | if(workOrderSv.hasValidProcessingResult(po.getWorkOrderId())) { |
| | | return BaseResponseUtils.buildErrorMsg("该工单存在有效的处理结果"); |
| | | } |
| | | |
| | | Long processingResultId = workOrderSv.insertProcessingResult(po); |
| | | if(processingResultId == null) { |
| | | return BaseResponseUtils.buildErrorMsg("上报工单处理结果失败"); |
| | | String result = workOrderSv.addProcessingResult(po); |
| | | if(!result.equals("success")) { |
| | | return BaseResponseUtils.buildErrorMsg(result); |
| | | } |
| | | |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | |
| | | /** |
| | | * 逻辑删除一个处理结果 |
| | | * @param deleteProResult |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "deleteProResult") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> deleteProResult(@RequestBody @Valid DtoDeleteProResult deleteProResult, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | OpeProcessingResult proResult = workOrderSv.getProResult(deleteProResult.getProResultId(), deleteProResult.getInspectorId()); |
| | | if(proResult == null) { |
| | | return BaseResponseUtils.buildErrorMsg("您要删除的处理结果不存在"); |
| | | } |
| | | |
| | | if(workOrderSv.deleteProResult(deleteProResult.getProResultId()) == 0) { |
| | | return BaseResponseUtils.buildErrorMsg("处理结果删除失败"); |
| | | } |
| | | |
| | | return BaseResponseUtils.buildSuccess(); |
| | | } |
| | | |
| | | /** |
| | | * 获取处理结果详情 |
| | | * @param proResultId |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getProResult") |
| | | @SsoAop() |
| | | public BaseResponse<VoProcessingResult> getProResult(@RequestParam("proResultId") Long proResultId) { |
| | | try { |
| | | String aa = JSON.toJSONString(workOrderSv.getProResultById(proResultId)); |
| | | System.out.println(aa); |
| | | return BaseResponseUtils.buildSuccess(workOrderSv.getProResultById(proResultId)); |
| | | } catch (Exception e) { |
| | | log.error("获取处理结果详情异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 审核处理结果 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "approveProResult") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> approveProResult(@RequestBody @Valid OpeApproveResult po, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | String result = workOrderSv.approveProResult(po); |
| | | if(!result.equals("success")) { |
| | | return BaseResponseUtils.buildErrorMsg(result); |
| | | } |
| | | |
| | | return BaseResponseUtils.buildSuccess(true) ; |
| | | } |
| | | |
| | | /** |
| | | * 获取任务类型列表 |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getTaskTypes") |
| | | @SsoAop() |
| | | public BaseResponse<List<VoTaskType>> getTaskTypes() { |
| | | try { |
| | | return BaseResponseUtils.buildSuccess(workOrderSv.getTaskTypes()); |
| | | } catch (Exception e) { |
| | | log.error("获取任务类型异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | } |