| | |
| | | import com.dy.pipIrrApp.workOrder.dto.DtoDeleteProResult; |
| | | import com.dy.pipIrrApp.workOrder.dto.DtoDeleteWorkOrder; |
| | | 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.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("${rocketmq.name-server}") |
| | | protected String nameServer; |
| | | |
| | | @Value("${rocketmq.producer.group}") |
| | | protected String producerGroup; |
| | | |
| | | @Value("${rocketmq.topic}") |
| | | protected String topic; |
| | | |
| | | /** |
| | | * 创建工单 |
| | | * @param po |
| | |
| | | @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()); |
| | | } |
| | |
| | | return BaseResponseUtils.buildErrorMsg("获取工单失败"); |
| | | } |
| | | |
| | | if(!sendWorkOrder(voWorkOrder, workOrderId)) { |
| | | return BaseResponseUtils.buildErrorMsg("工单推送失败"); |
| | | } |
| | | //if(!sendWorkOrder(voWorkOrder, workOrderId)) { |
| | | // return BaseResponseUtils.buildErrorMsg("工单推送失败"); |
| | | //} |
| | | |
| | | return BaseResponseUtils.buildSuccess(); |
| | | } |
| | | |
| | | /** |
| | | * 通过RocketMQ推送工单主键 |
| | | * @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(); |
| | | //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")) { |
| | | 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) ; |
| | | } |
| | | } |