mac 2 ani în urmă
părinte
comite
03a080d714

+ 4 - 0
kxs-gateway/pom.xml

@@ -70,6 +70,10 @@
             <groupId>com.alibaba</groupId>
             <artifactId>fastjson</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.kxs</groupId>
+            <artifactId>kxs-common-mq</artifactId>
+        </dependency>
         <!--接口文档-->
         <dependency>
             <groupId>com.github.xiaoymin</groupId>

+ 1 - 1
kxs-gateway/src/main/java/com/kxs/gateway/api/config/ResponseProperties.java

@@ -12,7 +12,7 @@ import java.util.List;
  * @time : 2020/9/22 - 17:03
  */
 @Data
-@ConfigurationProperties(prefix = "spring.response")
+@ConfigurationProperties(prefix = "gateway.dts.response")
 public class ResponseProperties {
 
     /**

+ 69 - 11
kxs-gateway/src/main/java/com/kxs/gateway/api/filter/ResponseFilter.java

@@ -3,7 +3,8 @@ package com.kxs.gateway.api.filter;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.kxs.gateway.api.config.GatewayConfigProperties;
+import com.kxs.common.core.constant.enums.ErrorTypeEnum;
+import com.kxs.common.mq.handlers.IMQSender;
 import com.kxs.gateway.api.config.ResponseProperties;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -16,15 +17,20 @@ import org.springframework.core.Ordered;
 import org.springframework.core.io.buffer.DataBuffer;
 import org.springframework.core.io.buffer.DataBufferFactory;
 import org.springframework.core.io.buffer.DataBufferUtils;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.server.reactive.ServerHttpRequest;
 import org.springframework.http.server.reactive.ServerHttpResponse;
 import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
 import org.springframework.stereotype.Component;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.reactive.function.server.HandlerStrategies;
+import org.springframework.web.reactive.function.server.ServerRequest;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
@@ -44,22 +50,23 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.O
 @RequiredArgsConstructor
 public class ResponseFilter implements GlobalFilter, Ordered {
 
-    private final ResponseProperties properties;
+    private final  ResponseProperties properties;
+
+    private final IMQSender imqSender;
 
     @Override
     public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
 
         ServerHttpRequest request = exchange.getRequest();
         String path = request.getURI().getPath();
-        // 排除不需要的路径
         if(!properties.getFilterUrl().contains(path)){
-            return chain.filter(exchange);
+            return  chain.filter(exchange);
         }
         ServerHttpResponse originalResponse = exchange.getResponse();
 
         DataBufferFactory bufferFactory = originalResponse.bufferFactory();
 
-        new ServerHttpResponseDecorator(originalResponse) {
+        ServerHttpResponseDecorator response = new ServerHttpResponseDecorator(originalResponse) {
             @NotNull
             @Override
             public Mono<Void> writeWith(@NotNull Publisher<? extends DataBuffer> body) {
@@ -93,8 +100,7 @@ public class ResponseFilter implements GlobalFilter, Ordered {
 
                             String responseData = String.join("", list);;
 
-                            log.info("responseData:" + responseData);
-                            sendMsg(request, responseData);
+                            sendMsg(exchange, responseData);
 
                             byte[] uppedContent = new String(responseData.getBytes(), StandardCharsets.UTF_8).getBytes();
 
@@ -117,7 +123,8 @@ public class ResponseFilter implements GlobalFilter, Ordered {
             }
 
         };
-        return chain.filter(exchange);
+        return chain.filter(exchange.mutate().response(response).build());
+
     }
 
 
@@ -126,16 +133,67 @@ public class ResponseFilter implements GlobalFilter, Ordered {
         return -1;
     }
 
-    private void sendMsg(ServerHttpRequest request, String data){
+    private void sendMsg(ServerWebExchange exchange, String data){
         JSONObject parse = JSON.parseObject(data);
         Integer status = parse.getInteger("status");
         if(status == 1){
-            log.info("操作成功,发送消息");
+            //获取请求内容
+            String param = null;
+            if(exchange.getRequest().getMethod() == HttpMethod.DELETE){
+                param = getDeleteRequestParam(exchange);
+            }
+            if(exchange.getRequest().getMethod() == HttpMethod.GET){
+                param = getRequestParam(exchange);
+            }
+            if(exchange.getRequest().getMethod() == HttpMethod.POST || exchange.getRequest().getMethod() ==  HttpMethod.PUT){
+                Mono<String> postBodyParam = getPostBodyParam(exchange);
+                param = postBodyParam.block();
+            }
+
+            log.info("操作成功,发送消息:{}", param);
             //发送消息
-            String msg = parse.getString("msg");
+//            RabbitDtsMethodQueueMQ msg = RabbitDtsMethodQueueMQ.build(RabbitDtsMethodQueueMQ.MsgEntity.builder()
+//                    .url(exchange.getRequest().getURI().getPath())
+//                    .param(param)
+//                    .build());
+//            imqSender.send(msg);
+        }
 
+    }
+
+    private String getRequestParam(ServerWebExchange exchange) {
+
+        try {
+            MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
+            return  JSON.toJSONString(queryParams);
+        } catch (Exception e) {
+            log.error(ErrorTypeEnum.DECRYPT_ERROR.getDescription(), e);
         }
+        return null;
+    }
+    private Mono<String> getPostBodyParam(ServerWebExchange exchange) {
+        //获取请求体,修改请求体
+        ServerRequest serverRequest = ServerRequest.create(exchange,
+                HandlerStrategies.withDefaults().messageReaders());
+
+        return serverRequest.bodyToMono(String.class).flatMap(body -> {
+            log.info("获取请求参数:{}", body);
+            //添加到请求体
+            return Mono.just(body);
+        });
+    }
+
+    private String getDeleteRequestParam(ServerWebExchange exchange) {
 
+        URI uri = exchange.getRequest().getURI();
+        String path = uri.getPath();
+        try{
+            String[] pathSegments = path.split("/");
+            return pathSegments[pathSegments.length - 1];
+        }catch (Exception e) {
+            log.error("解密异常,请求地址:{}", path);
+        }
+        return null;
     }
 
 }

+ 1 - 1
kxs-gateway/src/main/java/com/kxs/gateway/api/handler/GlobalExceptionHandler.java

@@ -47,7 +47,7 @@ public class GlobalExceptionHandler implements ErrorWebExceptionHandler {
 		return response.writeWith(Mono.fromSupplier(() -> {
 			DataBufferFactory bufferFactory = response.bufferFactory();
 			try {
-				log.warn("Error Spring Gateway : {} {}", exchange.getRequest().getPath(), ex.getMessage());
+				log.error("Error Spring Gateway : {} {}", exchange.getRequest().getPath(), ex.getMessage());
 				return bufferFactory.wrap(objectMapper.writeValueAsBytes(R.failed(ex.getMessage())));
 			}
 			catch (JsonProcessingException e) {

+ 106 - 0
kxs-gateway/src/main/java/com/kxs/gateway/api/rabbit/RabbitDtsMethodQueueMQ.java

@@ -0,0 +1,106 @@
+package com.kxs.gateway.api.rabbit;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.kxs.common.mq.enums.MQSendTypeEnum;
+import com.kxs.common.mq.model.AbstractMQ;
+import lombok.*;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.core.MessageBuilder;
+import org.springframework.amqp.core.MessageDeliveryMode;
+import org.springframework.amqp.core.MessageProperties;
+
+import java.util.UUID;
+
+/**
+ * mq 接口数据同步
+ *
+ * @author 没秃顶的码农
+ * @date 2024-04-25
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+@AllArgsConstructor
+public class RabbitDtsMethodQueueMQ extends AbstractMQ {
+
+
+    /**
+     * 订单交易队列
+     */
+    public static final String QUEUE_NAME = "QUEUE_DTS_URL_DATA_DIVISION";
+
+    /**
+     * 死队列名称
+     */
+    public static final String DEAD_QUEUE_NAME = "DEAD_QUEUE_DTS_URL_DATA_DIVISION";
+
+    /**
+     * 内置msg 消息体定义
+     **/
+    private MsgEntity msgEntity;
+
+    /**
+     *  定义Msg消息载体
+     **/
+    @Data
+    @Builder
+    public static class MsgEntity {
+
+        /**
+         * 接口地址
+         */
+        private String url;
+
+        /**
+         * 请求参数
+         */
+        private String param;
+
+    }
+
+    @Override
+    public String getQueueName() {
+
+        return QUEUE_NAME;
+    }
+
+    @Override
+    public String getDeadQueueName() {
+
+        return DEAD_QUEUE_NAME;
+    }
+
+    @Override
+    public MQSendTypeEnum getMqType() {
+
+        return MQSendTypeEnum.QUEUE;
+    }
+
+    @Override
+    public Message toMessage() {
+        String message = JSONObject.toJSONString(msgEntity);
+        // 构建消息体
+        return MessageBuilder.withBody(message.getBytes())
+                .setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
+                .setDeliveryMode(MessageDeliveryMode.PERSISTENT)
+                .setMessageId(UUID.randomUUID().toString())
+                .build();
+    }
+
+    /**
+     * 构造发送消息
+     */
+    public static RabbitDtsMethodQueueMQ build(MsgEntity message){
+
+        return new RabbitDtsMethodQueueMQ(message);
+    }
+
+    /**
+     * 解析MQ消息, 一般用于接收MQ消息时
+     */
+    public static MsgEntity parse(String msg){
+        return JSON.parseObject(msg, MsgEntity.class);
+    }
+
+}

+ 3 - 3
kxs-transfer/src/main/resources/import.txt

@@ -135,7 +135,7 @@ left join KxsBsServer.Col c on a.AdColId = c.ColId
 where a.`Status` > 0
 
 //机具表
-select a.Id as id, a.UserId as user_id,a.CreateDate as create_time, a.UpdateDate as update_time,
+select a.Id as id, a.BuyUserId as user_id,a.CreateDate as create_time, a.UpdateDate as update_time,
 a.PosSn as pos_sn, a.StoreId as warehouse_id, a.BindMerchantId as merchant_id, a.BrandId as brand_id, a.PreUserId as pre_user_id, a.BatchNo as batch_no,
 (case when a.IsPurchase = 0 && a.RecycEndDate > NOW() && a.ActivationState = 1 then 1 ELSE 0 end) as  recycle_status, a.RecycEndDate as recycle_end_time,
 a.PosSnType as machine_type, ifnull(a.PrizeParams, 299) as cash_pledge, case when a.SeoKeyword > 1000 then a.SeoKeyword / 100 ELSE a.SeoKeyword end as source_pledge,
@@ -225,9 +225,9 @@ SELECT a.Id as id, a.CreateDate as create_time, a.UpdateDate as update_time,
 a.PosCouponId as ticket_id,a.OrderNo as order_sn, b.ExchangeCode as ticket_code
 FROM PosCouponRecord a left join PosCoupons b on a.PosCouponId = b.id
 //商户表
-SELECT a.Id as id, a.UserId as user_id, a.CreateDate as create_time, a.UpdateDate as update_time,
+SELECT a.Id as id, b.BuyUserId as user_id, a.CreateDate as create_time, a.UpdateDate as update_time,
 a.MerchantNo as merchant_no, a.MerchantName as merchant_name, a.MerIdcardNo as merchant_card, a.MerchantMobile as merchant_phone,
-a.BrandId as brand_id, a.MerUserId as maker_user_id, a.MerUserType as is_maker, b.id as machine_id, a.StandardStatus as standard_status, a.StandardMonths as standard_months,
+a.BrandId as brand_id, a.UserId as maker_user_id, a.MerUserType as is_maker, b.id as machine_id, a.StandardStatus as standard_status, a.StandardMonths as standard_months,
 a.Remark as remark
 FROM PosMerchantInfo a LEFT JOIN PosMachinesTwo b on a.KqSnNo = b.PosSn
 

+ 2 - 2
kxs-user/kxs-user-biz/src/main/java/com/kxs/user/biz/controller/kxsapp/UserPresetLevelController.java

@@ -39,8 +39,8 @@ public class UserPresetLevelController {
      * @return 预设职级-预设记录
      */
     @GetMapping("/list")
-    public R list(@ParameterObject Page<UserPresetLogVO> page, @RequestParam("keyword") String keyword) {
-        return R.ok(kxsUserPresetLogService.logList(page, keyword));
+    public R list(@ParameterObject Page<UserPresetLogVO> page) {
+        return R.ok(kxsUserPresetLogService.logList(page));
     }
 
 

+ 1 - 2
kxs-user/kxs-user-biz/src/main/java/com/kxs/user/biz/mapper/KxsUserPresetLogMapper.java

@@ -21,9 +21,8 @@ public interface KxsUserPresetLogMapper extends BaseMapper<KxsUserPresetLog> {
      *
      * @param page    页
      * @param userId  用户 ID
-     * @param keyword 关键词
      * @return {@link Page}<{@link UserPresetLogVO}>
      */
-    Page<UserPresetLogVO> logList(Page<UserPresetLogVO> page, @Param("userId") Long userId, @Param("keyword") String keyword);
+    Page<UserPresetLogVO> logList(Page<UserPresetLogVO> page, @Param("userId") Long userId);
 }
 

+ 1 - 2
kxs-user/kxs-user-biz/src/main/java/com/kxs/user/biz/service/KxsUserPresetLogService.java

@@ -18,9 +18,8 @@ public interface KxsUserPresetLogService extends IService<KxsUserPresetLog> {
      * 预设记录日志
      *
      * @param page    页
-     * @param keyword 关键词
      * @return {@link Page}<{@link UserPresetLogVO}>
      */
-    IPage<UserPresetLogVO> logList(Page<UserPresetLogVO> page, String keyword);
+    IPage<UserPresetLogVO> logList(Page<UserPresetLogVO> page);
 }
 

+ 2 - 2
kxs-user/kxs-user-biz/src/main/java/com/kxs/user/biz/service/impl/KxsUserPresetLogServiceImpl.java

@@ -20,11 +20,11 @@ import org.springframework.stereotype.Service;
 public class KxsUserPresetLogServiceImpl extends ServiceImpl<KxsUserPresetLogMapper, KxsUserPresetLog> implements KxsUserPresetLogService {
 
     @Override
-    public IPage<UserPresetLogVO> logList(Page<UserPresetLogVO> page, String keyword) {
+    public IPage<UserPresetLogVO> logList(Page<UserPresetLogVO> page) {
 
         Long userId = SecurityUtils.getUser().getId();
 
-        return baseMapper.logList(page, userId, keyword);
+        return baseMapper.logList(page, userId);
     }
 }
 

+ 0 - 3
kxs-user/kxs-user-biz/src/main/resources/mapper/KxsUserPresetLogMapper.xml

@@ -19,9 +19,6 @@
         select u.id, a.end_time, a.preset_level, u.username, u.avatar from kxs_user_preset_log a
                  left join kxs_user u on u.id = a.user_id
                  where a.create_by_id = #{userId}
-                 <if test="keyword != null and keyword != ''">
-                     and u.user_code = #{keyword}
-                 </if>
                  order by a.end_time desc
     </select>