| | |
| | | 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 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 |
| | | */ |
| | | @GetMapping(path = "/getOneWorkOrder") |
| | | @SsoAop() |
| | | public BaseResponse<VoWorkOrder> getOneWorkOrder(@RequestParam("workOrderId") Long workOrderId) { |
| | | try { |
| | | return BaseResponseUtils.buildSuccess(workOrderSv.getWorkOrderById(workOrderId)); |
| | |
| | | */ |
| | | @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()); |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getProResult") |
| | | @SsoAop() |
| | | public BaseResponse<VoProcessingResult> getProResult(@RequestParam("proResultId") Long proResultId) { |
| | | try { |
| | | String aa = JSON.toJSONString(workOrderSv.getProResultById(proResultId)); |
| | |
| | | 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) ; |
| | | } |
| | | } |