Browse Source

任务提交 缓存维护信息,增加redisKey枚举

张均强 4 years ago
parent
commit
84fbb3bd86

+ 132 - 0
common/fire-dto/src/main/java/com/fire/dto/FlowOrderInfo.java

@@ -0,0 +1,132 @@
+package com.fire.dto;
+
+import java.util.Date;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@ApiModel(value = "订单记录表实体")
+@Data
+public class FlowOrderInfo {
+
+    @ApiModelProperty(value = "接入ID号")
+    private String flowAppId;
+
+    @ApiModelProperty(value = "订单ID号")
+    private String orderId;
+
+    @ApiModelProperty(value = "产品ID号")
+    private String packageId;
+
+    @ApiModelProperty(value = "客户id")
+    private Long customerId;
+
+    @ApiModelProperty(value = "1--直接生成流量  2--使用类型订单 3--话费")
+    private Integer orderType;
+
+    @ApiModelProperty(value = "客户名称")
+    private String customerName;
+
+    @ApiModelProperty(value = "充值手机号码")
+    private String phoneNo;
+
+    @ApiModelProperty(value = "CP订单号 客户订单号")
+    private String extorderId;
+
+    @ApiModelProperty(value = "分发订单号")
+    private String recId;
+
+    @ApiModelProperty(value = "下单时间")
+    private Date applyDate;
+
+    @ApiModelProperty(value = "激活日期")
+    private Date activeDate;
+
+    @ApiModelProperty(value = "订单超时")
+    private Date limitedDate;
+
+    @ApiModelProperty(value = "1-待发 2-已发 6-成功 4-失败 5-风控")
+    private Integer status;
+
+    @ApiModelProperty(value = "订单备注")
+    private String note;
+
+    @ApiModelProperty(value = "供应商返回订单号")
+    private String gwSeqNo;
+
+    @ApiModelProperty(value = "供应商返回状态")
+    private String gwStatus;
+
+    @ApiModelProperty(value = "最后修改日期")
+    private Date lastModifyDate;
+
+    @ApiModelProperty(value = "网关错误代码")
+    private String gwErrorCode;
+
+    @ApiModelProperty(value = "面额")
+    private Integer flowAmount;
+
+    @ApiModelProperty(value = "流量下发适配器")
+    private String adapterName;
+
+    @ApiModelProperty(value = "成本")
+    private Integer usageLimit;
+
+    @ApiModelProperty(value = "通道发送次数")
+    private Integer batchCount;
+
+    @ApiModelProperty(value = "总下发次数")
+    private Integer sendCount;
+
+    @ApiModelProperty(value = "省级行政编码")
+    private String areaCode;
+
+    @ApiModelProperty(value = "客户结算价格")
+    private Integer price;
+
+    @ApiModelProperty(value = "代理商结算价格")
+    private Integer partnerBalancePrice;
+
+    @ApiModelProperty(value = "成本价")
+    private Integer operatorBalancePrice;
+
+    @ApiModelProperty(value = "客户产品id")
+    private Integer customerProductId;
+
+    @ApiModelProperty(value = "通道ID")
+    private Integer channelId;
+
+    @ApiModelProperty(value = "回调时间")
+    private Date callbackTime;
+
+    @ApiModelProperty(value = "产品ID号")
+    private String productId;
+
+    @ApiModelProperty(value = "官方凭证")
+    private String attr1;
+
+    private String attr2;
+
+    private String attr3;
+
+    @ApiModelProperty(value = "通道名称")
+    private String channelName;
+
+    @ApiModelProperty(value = "APP接入名称")
+    private String appId;
+
+    @ApiModelProperty(value = "通道产品id")
+    private Long channelProductId;
+
+    @ApiModelProperty(value = "回调状态:6-成功 4-失败")
+    private Integer callbackStatus;
+
+    @ApiModelProperty(value = "运营商:1、移动 2、电信 3、联通")
+    private Integer phoneOperator;
+
+    @ApiModelProperty(value = "归属地市行政编码")
+    private String phoneCity;
+
+
+}

+ 35 - 0
common/fire-dto/src/main/java/com/fire/dto/OperatorMaintenance.java

@@ -0,0 +1,35 @@
+package com.fire.dto;
+
+import java.util.Date;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@ApiModel(value = "运营商系统维护表实体")
+@Data
+public class OperatorMaintenance {
+
+    @ApiModelProperty(value = "地区")
+    private String province;
+
+    @ApiModelProperty(value = "运营商")
+    private String operator;
+
+    @ApiModelProperty(value = "维护状态:0-否 ;1-维护")
+    private Integer status;
+
+    @ApiModelProperty(value = "开始维护时间")
+    private Date startTime;
+
+    @ApiModelProperty(value = "结束维护时间")
+    private Date endTime;
+
+    @ApiModelProperty(value = "0 表示所有面额")
+    private Integer facePrice;
+
+    @ApiModelProperty(value = "0 表示所有面额")
+    private Integer operType;
+
+
+}

+ 26 - 0
common/fire-dto/src/main/java/com/fire/dto/enums/RedisKey.java

@@ -0,0 +1,26 @@
+package com.fire.dto.enums;
+
+public enum RedisKey {
+
+    //系统
+    ORDER_ID_INCR("order.id.incr", "自增订单id"),
+    ORDER_ID_CUSTOMER("order.id.customer", "客户订单id");
+
+    private final String key;
+
+    private final String desc;
+
+    RedisKey(String key, String desc) {
+        this.key = key;
+        this.desc = desc;
+    }
+
+    public String key() {
+        return key;
+    }
+
+    public String desc() {
+        return desc;
+    }
+
+}

+ 1 - 2
common/fire-dto/src/main/java/com/fire/es/OrderEsDto.java

@@ -1,7 +1,6 @@
 package com.fire.es;
 
 
-import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import org.springframework.data.annotation.Id;
 import org.springframework.data.elasticsearch.annotations.Document;
@@ -78,7 +77,7 @@ public class OrderEsDto {
     private Date limitedDate;
     /**
      * 订单状态 1-待发 2-已发 3-成功
-     *   4-失败 5-风控
+     * 4-失败 5-风控
      */
     @Field(type = FieldType.Integer)
     private Integer status;

+ 0 - 5
modules/admin/pom.xml

@@ -74,11 +74,6 @@
             <artifactId>spring-boot-starter-aop</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>redis.clients</groupId>
-            <artifactId>jedis</artifactId>
-        </dependency>
-
     </dependencies>
 
 </project>

+ 6 - 0
modules/make-order/src/main/java/com/fire/order/data/DataPool.java

@@ -1,6 +1,7 @@
 package com.fire.order.data;
 
 import com.fire.dto.FlowAppInfo;
+import com.fire.dto.OperatorMaintenance;
 import com.fire.dto.PhoneZone;
 
 import java.util.HashMap;
@@ -32,4 +33,9 @@ public class DataPool {
      * 号码归属地
      */
     public static Map<String, PhoneZone> phoneZoneMap = new HashMap<>();
+
+    /**
+     * 运营商维护信息
+     */
+    public static Map<String, OperatorMaintenance> maintenanceMap = new HashMap<>();
 }

+ 24 - 0
modules/make-order/src/main/java/com/fire/order/mapper/FlowOrderInfoMapper.java

@@ -0,0 +1,24 @@
+package com.fire.order.mapper;
+
+import com.fire.dto.FlowOrderInfo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 订单记录表(FlowOrderInfo)表数据库访问层
+ *
+ * @author ZJQ  2021-05-20 11:39:33
+ */
+public interface FlowOrderInfoMapper {
+
+    /**
+     * 新增数据
+     *
+     * @param flowOrderInfo 实例对象
+     * @return 影响行数
+     */
+    int insert(FlowOrderInfo flowOrderInfo);
+
+}
+

+ 21 - 0
modules/make-order/src/main/java/com/fire/order/mapper/OperatorMaintenanceMapper.java

@@ -0,0 +1,21 @@
+package com.fire.order.mapper;
+
+import com.fire.dto.OperatorMaintenance;
+
+import java.util.List;
+
+/**
+ * 运营商系统维护表(OperatorMaintenance)表数据库访问层
+ *
+ * @author ZJQ  2021-05-19 17:16:32
+ */
+public interface OperatorMaintenanceMapper {
+
+    /**
+     * 查询全部有效的
+     */
+    List<OperatorMaintenance> queryAll();
+
+
+}
+

+ 5 - 0
modules/make-order/src/main/java/com/fire/order/service/CacheService.java

@@ -28,4 +28,9 @@ public interface CacheService {
      */
     void cachePhoneZone();
 
+    /**
+     * 缓存维护信息
+     */
+    void cacheMaintenance();
+
 }

+ 20 - 0
modules/make-order/src/main/java/com/fire/order/service/impl/CacheServiceImpl.java

@@ -9,6 +9,7 @@ import com.fire.order.service.CacheService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -39,6 +40,9 @@ public class CacheServiceImpl implements CacheService {
     @Resource
     private PhoneZoneMapper phoneZoneMapper;
 
+    @Resource
+    private OperatorMaintenanceMapper operatorMaintenanceMapper;
+
     /**
      * 缓存客户信息
      */
@@ -108,4 +112,20 @@ public class CacheServiceImpl implements CacheService {
             DataPool.phoneZoneMap = phoneZones.stream().collect(Collectors.toMap(PhoneZone::getPhone, a -> a, (k1, k2) -> k2));
         }
     }
+
+    /**
+     * 缓存维护信息
+     */
+    @Override
+    public void cacheMaintenance() {
+        List<OperatorMaintenance> maintenances = operatorMaintenanceMapper.queryAll();
+        if (CollectionUtils.isNotEmpty(maintenances)) {
+            Map<String, OperatorMaintenance> maintenanceMap = new HashMap<>();
+            for (OperatorMaintenance om : maintenances) {
+                String key = om.getProvince() + "." + om.getOperator() + "." + om.getFacePrice();
+                maintenanceMap.put(key, om);
+            }
+            DataPool.maintenanceMap = maintenanceMap;
+        }
+    }
 }

+ 58 - 6
modules/make-order/src/main/java/com/fire/order/service/impl/MakeOrderServiceImpl.java

@@ -2,11 +2,9 @@ package com.fire.order.service.impl;
 
 
 import com.alibaba.nacos.api.utils.StringUtils;
+import com.alibaba.nacos.common.utils.CollectionUtils;
 import com.alibaba.nacos.common.utils.MD5Utils;
-import com.fire.dto.CustomerInfo;
-import com.fire.dto.CustomerProduct;
-import com.fire.dto.FlowAppInfo;
-import com.fire.dto.PhoneZone;
+import com.fire.dto.*;
 import com.fire.order.data.DataPool;
 import com.fire.order.request.OrderRequestContent;
 import com.fire.order.request.OrderRequestMsgBody;
@@ -19,12 +17,17 @@ import com.fire.param.HeaderDto;
 import com.fire.utils.date.DateUtils;
 import com.fire.utils.string.FireStringUtils;
 import org.springframework.stereotype.Service;
+import redis.clients.jedis.JedisCluster;
 
+import javax.annotation.Resource;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import static com.fire.dto.enums.PriceCheck.CHECK;
 import static com.fire.dto.enums.Province.QG_ALL;
+import static com.fire.dto.enums.RedisKey.ORDER_ID_INCR;
 import static com.fire.dto.enums.Status.*;
 import static com.fire.dto.enums.ValidStatus.INVALID;
 
@@ -36,6 +39,9 @@ import static com.fire.dto.enums.ValidStatus.INVALID;
 @Service
 public class MakeOrderServiceImpl implements MakeOrderService {
 
+    @Resource
+    private JedisCluster jedisCluster;
+
     /**
      * 下单方法
      *
@@ -64,14 +70,14 @@ public class MakeOrderServiceImpl implements MakeOrderService {
         }
         responseDto.setHeader(header);
         //校验时间戳
-        Long now = System.currentTimeMillis();
+        long now = System.currentTimeMillis();
         String orderTime = header.getTimestamp();
         if (null == orderTime) {
             orderResp.setRCode(FAILURE_SERVER.status());
             orderResp.setRMsg("时间戳为空");
             return responseDto;
         }
-        Long orderT = DateUtils.String2Long(orderTime);
+        long orderT = DateUtils.String2Long(orderTime);
         if (orderT == 0) {
             orderResp.setRCode(FAILURE_SERVER.status());
             orderResp.setRMsg("时间戳格式错误");
@@ -224,6 +230,52 @@ public class MakeOrderServiceImpl implements MakeOrderService {
             orderResp.setRMsg("结算价格不一致");
             return responseDto;
         }
+        //校验维护信息
+        //组装提取维护信息的key
+        //key1 全国 + 运营商 + 面额
+        String key1 = QG_ALL.getCode() + "." + product.getOperator() + "." + product.getFacePrice();
+        //key2 全国 + 运营商 + 所有面额
+        String key2 = QG_ALL.getCode() + "." + product.getOperator() + "." + 0;
+        //key3 省 + 运营商 + 面额
+        String key3 = product.getAreaNum() + "." + product.getOperator() + "." + product.getFacePrice();
+        //key4 省 + 运营商 + 所有面额
+        String key4 = product.getAreaNum() + "." + product.getOperator() + "." + 0;
+        //存储所有的时候适合的维护信息
+        List<OperatorMaintenance> maintenances = new ArrayList<>(4);
+        OperatorMaintenance maintenance1 = DataPool.maintenanceMap.get(key1);
+        OperatorMaintenance maintenance2 = DataPool.maintenanceMap.get(key2);
+        OperatorMaintenance maintenance3 = DataPool.maintenanceMap.get(key3);
+        OperatorMaintenance maintenance4 = DataPool.maintenanceMap.get(key4);
+        if (maintenance1 != null) {
+            maintenances.add(maintenance1);
+        }
+        if (maintenance2 != null) {
+            maintenances.add(maintenance2);
+        }
+        if (maintenance3 != null) {
+            maintenances.add(maintenance3);
+        }
+        if (maintenance4 != null) {
+            maintenances.add(maintenance4);
+        }
+        if (CollectionUtils.isNotEmpty(maintenances)) {
+            //遍历,如果维护信息时间能对应上 那么返回运营商维护
+            for (OperatorMaintenance om : maintenances) {
+                if (om.getStartTime().getTime() < now && om.getEndTime().getTime() > now) {
+                    orderResp.setRCode(PROVINCE_MAINTAIN.status());
+                    orderResp.setRMsg(PROVINCE_MAINTAIN.message());
+                    return responseDto;
+                }
+
+            }
+        }
+
+        jedisCluster.incr(ORDER_ID_INCR.key());
+
+        //初始化订单详情
+        FlowOrderInfo order = new FlowOrderInfo();
+        order.setFlowAppId(appId);
+        order.setOrderId("待生成");
 
         return responseDto;
     }

+ 7 - 1
modules/make-order/src/main/resources/bootstrap.yml

@@ -12,4 +12,10 @@ spring:
       discovery:
         server-addr: 192.168.101.104:8848
         namespace: fire
-        service: make-order
+        service: make-order
+  redis:
+    cluster:
+      nodes:
+        - 192.168.101.101:7001
+        - 192.168.101.101:7002
+        - 192.168.101.101:7003

+ 68 - 0
modules/make-order/src/main/resources/mapper/FlowOrderInfoMapper.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fire.order.mapper.FlowOrderInfoMapper">
+
+    <resultMap type="com.fire.dto.FlowOrderInfo" id="FlowOrderInfoMap">
+        <result property="flowAppId" column="flow_app_id" jdbcType="VARCHAR"/>
+        <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
+        <result property="packageId" column="package_id" jdbcType="VARCHAR"/>
+        <result property="customerId" column="customer_id" jdbcType="INTEGER"/>
+        <result property="orderType" column="order_type" jdbcType="INTEGER"/>
+        <result property="customerName" column="customer_name" jdbcType="VARCHAR"/>
+        <result property="phoneNo" column="phone_no" jdbcType="VARCHAR"/>
+        <result property="extorderId" column="extorder_id" jdbcType="VARCHAR"/>
+        <result property="recId" column="rec_id" jdbcType="VARCHAR"/>
+        <result property="applyDate" column="apply_date" jdbcType="TIMESTAMP"/>
+        <result property="activeDate" column="active_date" jdbcType="TIMESTAMP"/>
+        <result property="limitedDate" column="limited_date" jdbcType="TIMESTAMP"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="note" column="note" jdbcType="VARCHAR"/>
+        <result property="gwSeqNo" column="gw_seq_no" jdbcType="VARCHAR"/>
+        <result property="gwStatus" column="gw_status" jdbcType="VARCHAR"/>
+        <result property="lastModifyDate" column="last_modify_date" jdbcType="TIMESTAMP"/>
+        <result property="gwErrorCode" column="gw_error_code" jdbcType="VARCHAR"/>
+        <result property="flowAmount" column="flow_amount" jdbcType="INTEGER"/>
+        <result property="adapterName" column="adapter_name" jdbcType="VARCHAR"/>
+        <result property="usageLimit" column="usage_limit" jdbcType="INTEGER"/>
+        <result property="batchCount" column="batch_count" jdbcType="INTEGER"/>
+        <result property="sendCount" column="send_count" jdbcType="INTEGER"/>
+        <result property="areaCode" column="area_code" jdbcType="VARCHAR"/>
+        <result property="price" column="price" jdbcType="INTEGER"/>
+        <result property="partnerBalancePrice" column="partner_balance_price" jdbcType="INTEGER"/>
+        <result property="operatorBalancePrice" column="operator_balance_price" jdbcType="INTEGER"/>
+        <result property="customerProductId" column="customer_product_id" jdbcType="INTEGER"/>
+        <result property="channelId" column="channel_id" jdbcType="INTEGER"/>
+        <result property="callbackTime" column="callback_time" jdbcType="TIMESTAMP"/>
+        <result property="productId" column="product_id" jdbcType="VARCHAR"/>
+        <result property="attr1" column="attr1" jdbcType="VARCHAR"/>
+        <result property="attr2" column="attr2" jdbcType="VARCHAR"/>
+        <result property="attr3" column="attr3" jdbcType="VARCHAR"/>
+        <result property="channelName" column="channel_name" jdbcType="VARCHAR"/>
+        <result property="appId" column="app_id" jdbcType="VARCHAR"/>
+        <result property="channelProductId" column="channel_product_id" jdbcType="INTEGER"/>
+        <result property="callbackStatus" column="callback_status" jdbcType="INTEGER"/>
+        <result property="phoneOperator" column="phone_operator" jdbcType="INTEGER"/>
+        <result property="phoneCity" column="phone_city" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="orderId" useGeneratedKeys="true">
+        insert into flow_order_info(order_id, flow_app_id, package_id, customer_id, order_type, customer_name, phone_no,
+                                    extorder_id, rec_id, apply_date, active_date, limited_date, status, note,
+                                    gw_seq_no, gw_status, last_modify_date, gw_error_code, flow_amount,
+                                    adapter_name, usage_limit, batch_count, send_count, area_code, price,
+                                    partner_balance_price, operator_balance_price, customer_product_id, channel_id,
+                                    callback_time, product_id, attr1, attr2, attr3, channel_name, app_id,
+                                    channel_product_id, callback_status, phone_operator, phone_city)
+        values (#{orderId}, #{flowAppId}, #{packageId}, #{customerId}, #{orderType}, #{customerName}, #{phoneNo},
+                #{extorderId},
+                #{recId}, #{applyDate}, #{activeDate}, #{limitedDate}, #{status}, #{note}, #{gwSeqNo}, #{gwStatus},
+                #{lastModifyDate}, #{gwErrorCode}, #{flowAmount}, #{adapterName}, #{usageLimit}, #{batchCount},
+                #{sendCount}, #{areaCode}, #{price}, #{partnerBalancePrice}, #{operatorBalancePrice},
+                #{customerProductId}, #{channelId}, #{callbackTime}, #{productId}, #{attr1}, #{attr2}, #{attr3},
+                #{channelName}, #{appId}, #{channelProductId}, #{callbackStatus}, #{phoneOperator}, #{phoneCity})
+    </insert>
+
+
+</mapper>
+

+ 30 - 0
modules/make-order/src/main/resources/mapper/OperatorMaintenanceMapper.xml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fire.order.mapper.OperatorMaintenanceMapper">
+
+    <resultMap type="com.fire.dto.OperatorMaintenance" id="OperatorMaintenanceMap">
+        <result property="province" column="province" jdbcType="VARCHAR"/>
+        <result property="operator" column="operator" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
+        <result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
+        <result property="facePrice" column="face_price" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!--查询全部-->
+    <select id="queryAll" resultMap="OperatorMaintenanceMap">
+        <include refid="baseSql"/>
+        where status = 1
+    </select>
+
+    <sql id="baseSql">
+        select province,
+               operator,
+               status,
+               start_time,
+               end_time,
+               face_price
+        from operator_maintenance
+    </sql>
+</mapper>
+

+ 4 - 1
modules/pom.xml

@@ -47,7 +47,10 @@
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>redis.clients</groupId>
+            <artifactId>jedis</artifactId>
+        </dependency>
         <!--这里引入本地公共的类-->
         <dependency>
             <groupId>com.blue</groupId>