Sfoglia il codice sorgente

提交推送数据逻辑

hxl13994548489 1 anno fa
parent
commit
3e732c4097

+ 70 - 0
src/main/java/com/ydtech/modules/order/orderThread/OrderRunnableThread.java

@@ -0,0 +1,70 @@
+package com.ydtech.modules.order.orderThread;
+
+import com.alibaba.fastjson.JSON;
+import com.ydtech.modules.order.entity.po.InsOrderPushMsg;
+import com.ydtech.modules.order.entity.vo.PushDataVo;
+import com.ydtech.modules.order.service.InsOrderPushMsgService;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.core.MessageProperties;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.UUID;
+
+import static org.springframework.amqp.core.MessageProperties.CONTENT_TYPE_TEXT_PLAIN;
+
+/**
+ *  @version
+ *  @author: hxl
+ *  @Date: 2024/11/5 15:50
+ *  @Description:  发送订单的线程池
+ */
+public class OrderRunnableThread implements Runnable {
+
+    //private RabbitTemplate rabbitTemplate;
+
+    private ArrayList<String> message =new ArrayList<>();
+
+    private InsOrderPushMsgService insOrderPushMsgService;
+
+   // public OrderRunnableThread(RabbitTemplate rabbitTemplate, ArrayList<String> message, InsOrderPushMsgService insOrderPushMsgService) {
+   //     this.rabbitTemplate = rabbitTemplate;
+   //     this.message = message;
+   //     this.insOrderPushMsgService = insOrderPushMsgService;
+    //}
+
+    public OrderRunnableThread() {
+    }
+
+    public OrderRunnableThread(InsOrderPushMsgService insOrderPushMsgService, ArrayList<String> message) {
+        this.message = message;
+        this.insOrderPushMsgService = insOrderPushMsgService;
+    }
+
+    @Override
+    public void run() {
+        //发送数据
+        this.message.forEach(item ->{
+            //修改执行相应业务逻辑
+            MessageProperties messageProperties = new MessageProperties();
+            messageProperties.setMessageId(UUID.randomUUID().toString());
+            messageProperties.setContentType(CONTENT_TYPE_TEXT_PLAIN);
+            messageProperties.setContentEncoding("UTF-8");
+            Message message_cj = new Message(item.getBytes(StandardCharsets.UTF_8), messageProperties);
+            PushDataVo pushDataVo = JSON.parseObject(item, PushDataVo.class);
+            //推送
+            InsOrderPushMsg insOrderPushMsg = new InsOrderPushMsg(null, pushDataVo.getInsAreaCompany().getId(), "0", new Date(), pushDataVo.toString());
+            try{
+                //更新狀態
+                insOrderPushMsgService.save(insOrderPushMsg);
+                //this.rabbitTemplate.convertAndSend(RabbitMqEnum.ORDER_EXCHANGE.getCode(), RabbitMqEnum.ORDER_ROUTINGKEY.getCode(), message_cj);
+            }catch(Exception e){
+                e.getStackTrace();
+            }
+
+        });
+
+    }
+}
+

+ 159 - 0
src/main/java/com/ydtech/modules/order/service/impl/InsOrderPushMsgServiceImpl.java

@@ -0,0 +1,159 @@
+package com.ydtech.modules.order.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ydtech.constants.enums.dict.InsOrderStatusEnum;
+import com.ydtech.modules.admin.utils.SliceUpDateUtil;
+import com.ydtech.modules.order.dao.InsOrderPushMsgMapper;
+import com.ydtech.modules.order.dao.InsTaskImagesMapper;
+import com.ydtech.modules.order.entity.InsAreaCompany;
+import com.ydtech.modules.order.entity.InsOrders;
+import com.ydtech.modules.order.entity.dto.InsTaskImagesDto;
+import com.ydtech.modules.order.entity.po.InsOrderPushMsg;
+import com.ydtech.modules.order.entity.vo.PushDataVo;
+import com.ydtech.modules.order.service.InsAreaCompanyService;
+import com.ydtech.modules.order.service.InsOrderPushMsgService;
+import com.ydtech.modules.order.service.InsOrdersService;
+import com.ydtech.utils.OrderUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Administrator
+ * @description 针对表【ins_order_push_msg(子订单推送数据表)】的数据库操作Service实现
+ * @createDate 2024-11-05 11:45:52
+ */
+@Service
+public class InsOrderPushMsgServiceImpl extends ServiceImpl<InsOrderPushMsgMapper, InsOrderPushMsg>
+        implements InsOrderPushMsgService {
+
+    private static final Logger log = LoggerFactory.getLogger(InsOrderPushMsgServiceImpl.class);
+
+    @Autowired
+    private  InsOrderPushMsgMapper  insOrderPushMsgMapper;
+
+    @Autowired
+    private  InsAreaCompanyService insAreaCompanyService;
+
+    @Autowired
+    private InsOrdersService insOrdersService;
+
+    @Autowired
+    private InsTaskImagesMapper insTaskImagesMapper;
+
+    //@Autowired
+    //private RabbitTemplate rabbitTemplate;
+
+
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/11/5 14:50
+     *  @Description: 推送历史的订单信息
+     */
+    @Override
+    public void getPushInsAreaCompanyList() {
+        List<String> dateList = insOrderPushMsgMapper.getPushInsAreaCompanyDateList();
+       // List<String> dateList  =new ArrayList<String>();
+       // dateList.add("2024-10");
+        if(dateList!=null && !dateList.isEmpty()){
+            //启动线程池
+            dateList.forEach(item ->{
+                String benginTime = SliceUpDateUtil.getStartOfMonth(Integer.parseInt(item.split("-")[0]), Integer.parseInt(item.split("-")[1]));
+                String endTime = SliceUpDateUtil.getEndOfMonth(Integer.parseInt(item.split("-")[0]), Integer.parseInt(item.split("-")[1]));
+                List<String> orderList = insOrderPushMsgMapper.getPushInsAreaCompanyList(benginTime,endTime);
+                ArrayList<String>  pushDataList =new ArrayList<String>();
+                if(orderList!=null && !orderList.isEmpty()){
+                    orderList.forEach(orderId ->{
+                        pushDataList.add(getPushDataJsonString(orderId));
+                    });
+                }
+                if(pushDataList!=null && !pushDataList.isEmpty()){
+                   // Thread thread = new Thread(new OrderRunnableThread(rabbitTemplate, pushDataList,this));
+                    //thread.start();
+                }
+            });
+        }
+    }
+
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/11/11 8:39
+     *  @Description:  查询补偿的订单数据并推送
+     */
+    @Override
+    public void getPushCompensateInsAreaCompanyList() {
+        List<String> orderList = insOrderPushMsgMapper.getPushCompensateInsAreaCompanyList();
+        ArrayList<String>  pushDataList =new ArrayList<String>();
+        if(orderList!=null && !orderList.isEmpty()){
+            //通过
+            orderList.forEach(orderId ->{
+                pushDataList.add(getPushDataJsonString(orderId));
+            });
+        }
+        if(pushDataList!=null && !pushDataList.isEmpty()){
+            //Thread thread = new Thread(new OrderRunnableThread(rabbitTemplate, pushDataList,this));
+            //thread.start();
+        }
+     }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/11/11 8:39
+     *  @Description:  承保数据推送
+     */
+    @Override
+    public void getPushSignInsAreaCompanyList(String item) {
+        try{
+            ArrayList<String>  pushDataList =new ArrayList<String>();
+            pushDataList.add(getPushDataJsonString(item));
+            //Thread thread = new Thread(new OrderRunnableThread(rabbitTemplate, pushDataList,this));
+            //thread.start();
+        }catch(Exception e){
+            log.error(e.getMessage());
+        }
+
+    }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/11/11 8:45
+     *  @Description: 通过订单id查询订单数据
+     */
+    public String getPushDataJsonString(String orderId) {
+        //小订单的数据
+        InsAreaCompany insAreaCompany = insAreaCompanyService.getById(orderId);
+        //大订单数据
+        InsOrders orders = insOrdersService.getById(insAreaCompany.getOrderno());
+        String jyPolicyNo="";
+        String apiType = insAreaCompany.getApiType() == null ? null : insAreaCompany.getApiType() + "";
+        if (insAreaCompany.getCrossInsurance() != null) {
+            jyPolicyNo = OrderUtils.getJyPolicyNo(insAreaCompany.getCompanyId(), apiType, insAreaCompany.getCrossInsurance().toString(), String.valueOf(orders.getIsExternal()));
+        }
+        insAreaCompany.setJyPolicyNo(jyPolicyNo);
+        //影像数据
+        List<InsTaskImagesDto> taskImagesList = insTaskImagesMapper.getTaskImagesList(insAreaCompany.getOrderno());
+        PushDataVo pushDataVo  =new PushDataVo(insAreaCompany,orders,taskImagesList);
+        String json = JSONObject.toJSONString(pushDataVo);
+        return json;
+    }
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2024/11/11 9:04
+     *  @Description: 测试承保推送
+     */
+    public void testSignData(String orderId) {
+        //小订单的数据
+        InsAreaCompany insAreaCompany = insAreaCompanyService.getById(orderId);
+        insAreaCompany.setOrderstatus(InsOrderStatusEnum.ACCEPT_INSURANCE.getCode());
+        insAreaCompanyService.updateCompanyAndOrders(insAreaCompany);
+    }
+
+}