| | |
| | | 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.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.validation.BindingResult; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | |
| | | public class WorkOrderCtrl { |
| | | private final WorkOrderSv workOrderSv; |
| | | |
| | | @Autowired |
| | | private RocketMQTemplate rocketMQTemplate; |
| | | @Value("${mqtt.broker}") |
| | | private String broker; |
| | | |
| | | @Value("${mqtt.username}") |
| | | private String username; |
| | | |
| | | @GetMapping("/sendWorkOrder") |
| | | @Value("${mqtt.password}") |
| | | private String password; |
| | | |
| | | @Value("${mqtt.topic}") |
| | | private String topic; |
| | | |
| | | @Value("${mqtt.qos}") |
| | | private Integer qos; |
| | | |
| | | /** |
| | | * 创建工单 |
| | | * @param po |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "addWorkOrder", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public void sendWorkOrder() throws MQClientException, MQBrokerException, RemotingException, InterruptedException { |
| | | ConsumerListener_push ConsumerListener_push = new ConsumerListener_push(); |
| | | ConsumerListener_push.receiveMessage(); |
| | | public BaseResponse<Boolean> addWorkOrder(@RequestBody @Valid OpeWorkOrder po, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | String topic = "workOrder"; |
| | | String tag = "王五"; |
| | | String key = "11"; |
| | | String message = "Hello World"; |
| | | //SendResult sendResult = rocketMQTemplate.syncSend(topic + ":" + tag, message); |
| | | //System.out.println("send result:" + sendResult.toString()); |
| | | if(po.getClientReportId() != null && po.getInspectorReportId() != null) { |
| | | return BaseResponseUtils.buildErrorMsg("工单仅能关联一个问题上报"); |
| | | } |
| | | |
| | | DefaultMQProducer producer = new DefaultMQProducer("producer_group"); |
| | | producer.setNamesrvAddr("127.0.0.1:9876"); |
| | | producer.start(); |
| | | Message msg = new Message(topic,tag,"11",message.getBytes(StandardCharsets.UTF_8)); |
| | | SendResult approveSendResult = producer.send(msg); |
| | | System.out.println("send result:" + approveSendResult.toString()); |
| | | Long workOrderId = workOrderSv.insertWorkOrder(po); |
| | | if(workOrderId == null || workOrderId == 0) { |
| | | return BaseResponseUtils.buildErrorMsg("创建工单失败"); |
| | | } |
| | | |
| | | VoWorkOrder voWorkOrder = workOrderSv.getWorkOrderById(workOrderId); |
| | | if(voWorkOrder == null) { |
| | | return BaseResponseUtils.buildErrorMsg("获取工单失败"); |
| | | } |
| | | |
| | | if(!sendWorkOrder(voWorkOrder, workOrderId)) { |
| | | return BaseResponseUtils.buildErrorMsg("工单推送失败"); |
| | | } |
| | | |
| | | return BaseResponseUtils.buildSuccess(); |
| | | } |
| | | |
| | | /** |
| | | * 通过mosquitto发送巡检员ID及工单ID |
| | | * @param voWorkOrder 工单对象 |
| | | * @param workOrderId 工单ID |
| | | * @return |
| | | */ |
| | | public Boolean sendWorkOrder(VoWorkOrder voWorkOrder, Long workOrderId) { |
| | | //String message = JSON.toJSONString(voWorkOrder); |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 逻辑删除指定派单人的指定未删除工单 |
| | | * 先判断指定派单人、未删除的指定工单是否存在 |
| | | * @param deleteWorkOrder 删除工单传输类 |
| | | * @param bindingResult |
| | | * @return |
| | | */ |
| | | @PostMapping(path = "deleteWorkOrder") |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> deleteWorkOrder(@RequestBody @Valid DtoDeleteWorkOrder deleteWorkOrder, BindingResult bindingResult) { |
| | | if(bindingResult != null && bindingResult.hasErrors()){ |
| | | return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | /** |
| | | * 根据指定条件获取未删除的工单列表 |
| | | * @param qo |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getWorkOrders") |
| | | @SsoAop() |
| | | public BaseResponse<QueryResultVo<List<VoWorkOrder>>> getWorkOrders(QoWorkOrder qo){ |
| | | try { |
| | | return BaseResponseUtils.buildSuccess(workOrderSv.getWorkOrders(qo)); |
| | | } catch (Exception e) { |
| | | return BaseResponseUtils.buildException(e.getMessage()) ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取工单详情 |
| | | * @param workOrderId |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getOneWorkOrder") |
| | | @SsoAop() |
| | | public BaseResponse<VoWorkOrder> getOneWorkOrder(@RequestParam("workOrderId") Long workOrderId) { |
| | | try { |
| | | return BaseResponseUtils.buildSuccess(workOrderSv.getWorkOrderById(workOrderId)); |
| | | } catch (Exception e) { |
| | | log.error("获取工单详情异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 上报工单处理结果 |
| | | * 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()); |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | } |
| | | } |