Browse Source

8.29 将信息同步至航通(未完)

Mechrevo 1 year ago
parent
commit
cfd319ead5

+ 1 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterface.java

@@ -22,6 +22,7 @@ import java.util.List;
 )
 public interface AdminInterface {
 
+
     /**
      * 收购商认证 步骤2
      */

+ 28 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/async_server/AsyncServerInterface.java

@@ -0,0 +1,28 @@
+package com.pj.api.client.async_server;
+
+import com.pj.api.FeignInterceptor;
+import com.pj.api.consts.FeignConsts;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * 异步通信
+ * @Author Mechrevo
+ * @Date 2023 08 29 13 02
+ **/
+@FeignClient(
+        name = FeignConsts.ASYNC_SERVER,                // 服务名称
+        configuration = FeignInterceptor.class,        // 请求拦截器
+        fallbackFactory = AsyncServerInterfaceFallback.class    // 服务降级
+)
+public interface AsyncServerInterface {
+
+    /**
+     * 发送对象至航通
+     * @param t
+     * @param <T>
+     */
+    @RequestMapping("/async/rpc/send")
+    public <T> void sendMessage(T t,String dataType);
+
+}

+ 28 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/async_server/AsyncServerInterfaceFallback.java

@@ -0,0 +1,28 @@
+package com.pj.api.client.async_server;
+
+import com.pj.api.client.cfg.SpCfgInterfaceFallback;
+import feign.hystrix.FallbackFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 08 29 13 03
+ **/
+@Component
+public class AsyncServerInterfaceFallback implements FallbackFactory<AsyncServerInterface> {
+
+    private static final Logger log = LoggerFactory.getLogger(SpCfgInterfaceFallback.class);
+
+    @Override
+    public AsyncServerInterface create(Throwable throwable) {
+        return new AsyncServerInterface() {
+
+            @Override
+            public <T> void sendMessage(T t,String dataType) {
+                log.error("错误对象:{},类型:{}",t,dataType);
+            }
+        };
+    }
+}

+ 1 - 0
sp-core/sp-api/src/main/java/com/pj/api/consts/FeignConsts.java

@@ -11,6 +11,7 @@ public class FeignConsts {
 	public static final String TRANSPORT_SERVER = "transport-server";
 	public static final String LEVEL_ONE_SERVER = "level-one-server";
 	public static final String LEVEL_TWO_SERVER = "level-two-server";
+	public static final String ASYNC_SERVER = "async-server";
 
 	
 	

+ 11 - 1
sp-core/sp-api/src/main/java/com/pj/api/consts/FeignFactory.java

@@ -1,6 +1,7 @@
 package com.pj.api.consts;
 
 import com.pj.api.client.admin.AdminInterface;
+import com.pj.api.client.async_server.AsyncServerInterface;
 import com.pj.api.client.level_one_server.LevelOneServerInterface;
 import com.pj.api.client.level_two_server.LevelTwoServerInterface;
 import com.pj.api.client.transport.TransportInterface;
@@ -54,7 +55,16 @@ public class FeignFactory {
 	 */
 	public static LevelTwoServerInterface levelTwoServerInterface;
 	@Autowired
-	public void setLevelTwoServerInterface(LevelTwoServerInterface levelTwoServerInterface) {
+	public void setLevelTwoServerInterface(LevelTwoServerInterface levelTwoServerInterface){
 		FeignFactory.levelTwoServerInterface = levelTwoServerInterface;
 	}
+
+	/**
+	 * 异步通信接口
+	 */
+	public static AsyncServerInterface ansyncServerInterface;
+	@Autowired
+	public void setAnsyncServerInterface(AsyncServerInterface ansyncServerInterface){
+		FeignFactory.ansyncServerInterface = ansyncServerInterface;
+	}
 }

+ 30 - 0
sp-core/sp-base/src/main/java/com/pj/enummj/DataType.java

@@ -0,0 +1,30 @@
+package com.pj.enummj;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 08 29 15 47
+ **/
+@Getter
+@AllArgsConstructor
+public enum DataType {
+
+    /**
+     * 发送航通的类型
+     */
+    DATA_TYPE_ONE("1","更新状态保存交易记录"),
+    DATA_TYPE_TWO("2","进口申报确认成功"),
+    DATA_TYPE_THREE("3","给出回执信息,订单支付状态更新"),
+    DATA_TYPE_FOUR("4","支付成功"),
+    DATA_TYPE_FIVE("5","订单状态更新,通知边民缴税以及各服务费,边民发起缴税申请以及缴费申请"),
+    DATA_TYPE_SIX("6","交易完成,形成记录,数据同步;边民可申请开票");
+
+    private String code;
+
+    private String msg;
+
+
+
+}

+ 38 - 0
sp-service/async-server/src/main/java/com/pj/feign/AmqpTemplateController.java

@@ -0,0 +1,38 @@
+package com.pj.feign;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.pj.dto.DataDto;
+import com.pj.rabbitmq.RabbitMQ;
+import com.pj.utils.MD5;
+import com.pj.utils.ht.AESUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 08 29 14 15
+ **/
+@RestController
+@RequestMapping("/async/")
+public class AmqpTemplateController {
+
+    @Autowired
+    private AmqpTemplateFeign amqpTemplateFeign;
+
+    /**
+     * 发送对象至航通
+     * @param t
+     * @param <T>
+     */
+    @RequestMapping("rpc/send")
+    public <T> void sendMessage(T t,String dataType){
+        //发送
+        amqpTemplateFeign.sendObject(t,dataType);
+    }
+
+}

+ 60 - 0
sp-service/async-server/src/main/java/com/pj/feign/AmqpTemplateFeign.java

@@ -0,0 +1,60 @@
+package com.pj.feign;
+
+import com.alibaba.fastjson.JSON;
+import com.pj.dto.DataDto;
+import com.pj.rabbitmq.RabbitMQ;
+import com.pj.utils.MD5;
+import com.pj.utils.ht.AESUtil;
+import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @Author Mechrevo
+ * @Date 2023 08 29 13 08
+ **/
+@Service
+public class AmqpTemplateFeign {
+
+    @Autowired
+    private AmqpTemplate amqpTemplate;
+
+
+    /**
+     * 发送对象至航通
+     * @param t
+     * @param <T>
+     */
+    public<T> void sendObject(T t,String dataType){
+        //todo: 数据暂时定死
+        DataDto dataDto = new DataDto();
+        //msgId
+        String msgId = "";
+        dataDto.setMsgId(msgId);
+        //appId
+        String appId = "shop01";
+        dataDto.setAppId(appId);
+        //dataType
+        dataType = "001";
+        dataDto.setDataType(dataType);
+        //data
+        //加密
+        String jsonString = JSON.toJSONString(t);
+        String encryptCBC = AESUtil.encryptCBC(jsonString, RabbitMQ.ACC_KEY);
+        dataDto.setData(encryptCBC);
+        //msgTime
+        String msgTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+        dataDto.setMsgTime(msgTime);
+        //sign
+        String signString = "msgId=" + msgId + "&appId=" + appId + "&dataType=" + dataType + "&msgTime=" + msgTime + "&data=" + encryptCBC;
+        String sign = MD5.getMd5(signString, 32);
+        dataDto.setSign(sign);
+
+        //mq发送信息
+        amqpTemplate.convertAndSend(RabbitMQ.TEST_SEND_QUEUE,t);
+    }
+
+}

+ 11 - 0
sp-service/async-server/src/main/java/com/pj/listen/BaseInfoListen.java

@@ -41,4 +41,15 @@ public class BaseInfoListen {
     }
 
 
+//    /**
+//     * 测试接收
+//     */
+//    @RabbitListener(queuesToDeclare = @Queue(RabbitMQ.TEST_SEND_QUEUE))
+//    public void sendMessage(Message message){
+//        System.out.println("\n测试:接收信息\n");
+//        byte[] body = message.getBody();
+//        String s = new String(body);
+//        System.out.println("\n" + s + "\n");
+//    }
+
 }

+ 29 - 0
sp-service/async-server/src/main/java/com/pj/rabbitmq/RabbitmqConfig.java

@@ -4,6 +4,9 @@ import org.springframework.amqp.core.Binding;
 import org.springframework.amqp.core.BindingBuilder;
 import org.springframework.amqp.core.DirectExchange;
 import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -16,6 +19,32 @@ import org.springframework.context.annotation.Configuration;
  **/
 @Configuration
 public class RabbitmqConfig {
+//
+//
+//    @Value("${spring.rabbitmq.host}")
+//    private String host;
+//
+//    @Value("${spring.rabbitmq.port}")
+//    private int port;
+//
+//    @Value("${spring.rabbitmq.username}")
+//    private String username;
+//
+//    @Value("${spring.rabbitmq.password}")
+//    private String password;
+//
+//    @Value("${spring.rabbitmq.virtual-host}")
+//    private String virtualHost;
+//
+//    @Bean
+//    public ConnectionFactory connectionFactory() {
+//        System.out.println(host + port + username + password + virtualHost);
+//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
+//        connectionFactory.setUsername(username);
+//        connectionFactory.setPassword(password);
+//        connectionFactory.setVirtualHost(virtualHost);
+//        return connectionFactory;
+//    }
 
 
     /**

+ 0 - 66
sp-service/async-server/src/main/java/com/pj/service/ObjectService.java

@@ -1,66 +0,0 @@
-//package com.pj.service;
-//
-//import com.alibaba.fastjson2.JSONObject;
-//import com.pj.bo.PersonBO;
-//import com.pj.rabbitmq.RabbitMQ;
-//import com.pj.utils.ht.AESUtil;
-//import org.springframework.stereotype.Service;
-//
-///**
-// * @Author Mechrevo
-// * @Date 2023 08 25 15 48
-// **/
-//@Service
-//public class ObjectService {
-//
-//
-//    /**
-//     * 报文类型
-//     * 001=边民备案
-//     * 002=商铺备案
-//     * 003=边民互助组备案
-//     * 004=边民合作社备案
-//     * 005=车辆
-//     * 006=进境申报单
-//     * 007=进口申报单
-//     * @param htBytes
-//     */
-//    public void saveEntityByType(HtBytes htBytes){
-//        //数据解析
-//        String decrypt = AESUtil.decryptCBC(htBytes.getData(), RabbitMQ.ACC_KEY);
-//        //身份证是唯一的,有身份证就是修改,没有就是新增
-//        // 根据类型匹配对象
-//        switch (htBytes.getDataType()){
-//            case "001":
-//                //对象转换
-//                PersonBO personBO = JSONObject.parseObject(decrypt, PersonBO.class);
-//                break;
-//            case "002":
-//                //商铺备案
-//
-//                break;
-//            case "003":
-//                //边民互助组备案
-//
-//                break;
-//            case "004":
-//                //边民合作社备案
-//
-//                break;
-//            case "005":
-//                //车辆
-//
-//                break;
-//            case "006":
-//                //进境申报单
-//
-//                break;
-//            case "007":
-//                //进口申报单
-//
-//                break;
-//        }
-//
-//    }
-//
-//}

+ 12 - 0
sp-service/async-server/src/main/java/com/pj/task/HtByteTask.java

@@ -2,12 +2,14 @@ package com.pj.task;
 
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.pj.api.client.async_server.AsyncServerInterface;
 import com.pj.api.client.level_one_server.LevelOneServerInterface;
 import com.pj.api.dto.CooperativeDto;
 import com.pj.api.dto.GroupDto;
 import com.pj.api.dto.PeopleDto;
 import com.pj.api.dto.ShopDto;
 import com.pj.dto.DataDto;
+import com.pj.enummj.DataType;
 import com.pj.enummj.FinishStatus;
 import com.pj.ht_byte.HtByte;
 import com.pj.ht_byte.HtByteMapper;
@@ -38,6 +40,11 @@ public class HtByteTask {
      */
     @Autowired
     private LevelOneServerInterface levelOneServerInterface;
+    /**
+     * mq测试
+     */
+    @Autowired
+    private AsyncServerInterface asyncServerInterface;
 
     /**
      * 启动定时任务
@@ -53,6 +60,11 @@ public class HtByteTask {
      */
     @Scheduled(cron = "*/7 * * * * ?")  // 测试阶段,每7秒扫描一次
     private void htByteTask(){
+        /*  测试mq */
+//        List<HtByte> htBytes = htByteMapper.selectList(new LambdaQueryWrapper<HtByte>().eq(HtByte::getFinishStatus, 2));
+//        asyncServerInterface.sendMessage(htBytes.get(0), DataType.DATA_TYPE_ONE.getCode());
+//        return;
+        /*  测试mq */
         //扫描表内是否有待处理任务
         List<HtByte> byteList = htByteMapper.selectList(new LambdaQueryWrapper<HtByte>().eq(HtByte::getFinishStatus, FinishStatus.FINISH_STATUS_ZERO.getCode()));
         //判断是否有任务,没有则返回

+ 1 - 1
sp-service/async-server/src/main/resources/bootstrap.yml

@@ -4,6 +4,6 @@ server:
 
 spring: 
     # 服务名称 
-    application.name: async-serverw
+    application.name: async-server
     # 当前环境
     profiles.active: dev

+ 7 - 4
sp-service/level-one-server/src/main/java/com/pj/tb_order/TbOrderService.java

@@ -6,6 +6,7 @@ import java.util.*;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.pj.api.client.admin.AdminInterface;
+import com.pj.api.client.async_server.AsyncServerInterface;
 import com.pj.api.client.level_one_server.LevelOneServerInterface;
 import com.pj.api.dto.MessageDto;
 import com.pj.api.dto.OrderDto;
@@ -61,6 +62,8 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
 	private LevelOneServerInterface levelOneServerInterface;
 	@Autowired
 	private TbEnterpriseMapper tbEnterpriseMapper;
+	@Autowired
+	private AsyncServerInterface asyncServerInterface;
 
 	/**
 	 * 远程调用
@@ -382,7 +385,7 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
 	 * 易
 	 */
 	public void receiveOrderMessageFromHT(){
-		//todo: 8月27日 接收航通单推送消息
+		//todo: 8月27日 接收航通申报单推送消息
 		//1. 获取订单,并将订单保存到订单表
 
 		//2 根据订单内容获取边民集合,创建订单监听表,将该订单内需要完成的边民数逐条保存到监听表内
@@ -423,7 +426,7 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
 
 		// TODO: 2023/8/29 同步交易信息(由于目前未知航通传过来的订单数据形式,暂未做)
 		// TODO: 2023/8/29 监听航通传过来的大订单里的所有边民订单,当所有边民都进行订单确认后,调用航通接口发送信息
-
+		asyncServerInterface.sendMessage(tbOrderMapper.selectById(orderId),DataType.DATA_TYPE_ONE.getCode()); // 发送至航通
 
 		return result;
 	}
@@ -449,7 +452,7 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
 
 		// TODO: 2023/8/29 发送信息(由于目前未知航通传过来的订单数据形式,暂未做)
 		// TODO: 2023/8/29 监听航通传过来的大订单里的所有边民订单,当所有边民都进行进口申报确认后,调用航通接口发送信息
-
+		asyncServerInterface.sendMessage(tbOrderMapper.selectById(orderId),DataType.DATA_TYPE_TWO.getCode());
 
 		return result;
 	}
@@ -487,7 +490,7 @@ public class TbOrderService extends ServiceImpl<TbOrderMapper, TbOrder> implemen
 		}
 
 		//3、todo: 调用航通接口,发送划扣成功回执信息给航通(只发送)
-
+		asyncServerInterface.sendMessage(order,DataType.DATA_TYPE_THREE.getCode());
 	}
 
 	/** 远程调用  查订单 */

+ 4 - 2
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersService.java

@@ -9,6 +9,7 @@ import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.pj.api.client.admin.AdminInterface;
+import com.pj.api.client.async_server.AsyncServerInterface;
 import com.pj.api.client.level_one_server.LevelOneServerInterface;
 import com.pj.api.dto.GoodsDto;
 import com.pj.api.dto.MessageDto;
@@ -17,6 +18,7 @@ import com.pj.common.core.utils.StringUtils;
 import com.pj.current.config.SystemObject;
 import com.pj.current.dto.APPLoginUserInfo;
 import com.pj.current.satoken.StpAPPUserUtil;
+import com.pj.enummj.DataType;
 import com.pj.enummj.DeleteStatus;
 import com.pj.enummj.OrderStatus;
 import com.pj.tb_company.TbCompany;
@@ -61,7 +63,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
     @Autowired
     private TbDemandQuotationService demandQuotationService;
     @Autowired
-    private MethodOrdersService methodOrdersService;
+    private AsyncServerInterface asyncServerInterface;
     @Autowired
     TbOrdersCartMapper tbOrdersCartMapper;
 
@@ -115,7 +117,7 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
         //todo 接收国内采购商的货款支付申请,划扣至边民账户并给出回执 并且同步至航通
         orders.setIsPay(1);//支付成功
         orders.setPayTime(new Date());
-
+        asyncServerInterface.sendMessage(orders, DataType.DATA_TYPE_FOUR.getCode()); // 发送航通
 
         for (Long id : idArr) {