Browse Source

任务提交 数据库查询客户信息,下单的所有参数校验

张均强 4 years ago
parent
commit
e37ce3a21e

+ 74 - 0
common/fire-dto/src/main/java/com/fire/dto/CustomerInfo.java

@@ -0,0 +1,74 @@
+package com.fire.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@ApiModel(value = "客户表实体")
+@Data
+public class CustomerInfo {
+
+    @ApiModelProperty(value = "客户ID")
+    private Long customerId;
+
+    @ApiModelProperty(value = "合作伙伴ID")
+    private Long partnerId;
+
+    @ApiModelProperty(value = "客户名称")
+    private String customerName;
+
+    @ApiModelProperty(value = "客户简称")
+    private String shorterName;
+
+    @ApiModelProperty(value = "联系人姓名")
+    private String linkmanName;
+
+    @ApiModelProperty(value = "联系人电话")
+    private String linkmanMobile;
+
+    @ApiModelProperty(value = "联系人邮箱")
+    private String linkmanEmail;
+
+    @ApiModelProperty(value = "联系人地址")
+    private String address;
+
+    @ApiModelProperty(value = "状态,0:待提交 1:商用2:暂停")
+    private Integer status;
+
+    @ApiModelProperty(value = "帐号余额")
+    private Double balance;
+
+    @ApiModelProperty(value = "授信额度")
+    private Double creditAmount;
+
+    @ApiModelProperty(value = "当前费用")
+    private Double currentAmount;
+
+    @ApiModelProperty(value = "是否第一次登录,1:不是0:是")
+    private Integer isFirstLogin;
+
+    @ApiModelProperty(value = "删除标识,1:已删除0:未删除")
+    private Integer isDeleted;
+
+    @ApiModelProperty(value = "创建者")
+    private String creator;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty(value = "修改者")
+    private String updator;
+
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "代理商提成比例(按照面额计算)")
+    private Object partnerCommission;
+
+    @ApiModelProperty(value = "跟用户关联,客户登录使用")
+    private Integer userId;
+
+
+}

+ 3 - 1
common/fire-dto/src/main/java/com/fire/param/HeaderDto.java

@@ -1,11 +1,13 @@
 package com.fire.param;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @ApiModel(value = "请求参数头信息")
+@JsonIgnoreProperties(ignoreUnknown = true)
 @Data
 public class HeaderDto {
 
@@ -15,7 +17,7 @@ public class HeaderDto {
 
     @ApiModelProperty(value = "时间戳")
     @JsonProperty(value = "TIMESTAMP")
-    private Long timestamp;
+    private String timestamp;
 
     @ApiModelProperty(value = "流水号")
     @JsonProperty(value = "SEQNO")

+ 25 - 0
common/fire-utils/src/main/java/com/fire/utils/date/DateUtils.java

@@ -1,4 +1,29 @@
 package com.fire.utils.date;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * 日期工具
+ *
+ * @author ZJQ 2021年5月14日17:54:47
+ */
 public class DateUtils {
+
+    /**
+     * 老系统时间戳转long的毫秒
+     *
+     * @param dateStr 日期字符串
+     * @return Long
+     */
+    public static Long String2Long(String dateStr) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        try {
+            Date date = sdf.parse(dateStr);
+            return date.getTime();
+        } catch (ParseException e) {
+            return 0L;
+        }
+    }
 }

+ 30 - 0
common/fire-utils/src/main/java/com/fire/utils/string/StringUtils.java

@@ -0,0 +1,30 @@
+package com.fire.utils.string;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 字符串工具类
+ *
+ * @author ZJQ 2021年5月17日11:02:32
+ */
+public class StringUtils {
+
+    /**
+     * 手机号验证
+     *
+     * @param str 手机号
+     * @return 验证通过返回true
+     */
+    public static boolean isMobile(String str) {
+        boolean b = false;
+        if (null == str) {
+            return b;
+        }
+        Pattern p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号
+        Matcher m = p.matcher(str);
+        b = m.matches();
+        return b;
+    }
+
+}

+ 0 - 5
modules/admin/pom.xml

@@ -48,11 +48,6 @@
             <artifactId>hutool-all</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-
        <dependency>
             <groupId>javax.xml.bind</groupId>
             <artifactId>jaxb-api</artifactId>

+ 2 - 0
modules/make-order/src/main/java/com/fire/order/MakeOrderApplication.java

@@ -1,6 +1,7 @@
 package com.fire.order;
 
 import com.spring4all.swagger.EnableSwagger2Doc;
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -14,6 +15,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 @SpringBootApplication
 @EnableDiscoveryClient
 @EnableSwagger2Doc
+@MapperScan({"com.fire.order.mapper"})
 public class MakeOrderApplication {
     public static void main(String[] args) {
         SpringApplication.run(MakeOrderApplication.class, args);

+ 44 - 0
modules/make-order/src/main/java/com/fire/order/config/MybatisPlusConfig.java

@@ -0,0 +1,44 @@
+package com.fire.order.config;
+
+
+import cn.hutool.core.lang.Snowflake;
+import cn.hutool.core.util.IdUtil;
+import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * MybatisPlus 插件配置
+ *
+ * @author liuliu 2021年5月17日11:41:25
+ */
+@Configuration
+public class MybatisPlusConfig {
+
+    /**
+     * MybatisPlus 分页插件配置
+     *
+     * @return PaginationInterceptor
+     */
+    @Bean
+    public PaginationInterceptor paginationInterceptor() {
+        return new PaginationInterceptor();
+    }
+
+
+    /**
+     * 分布式id生成
+     *
+     * @return Snowflake
+     */
+    @Bean
+    public Snowflake snowflake() {
+        return IdUtil.createSnowflake(1, 1);
+    }
+
+    @Bean
+    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
+        return new OptimisticLockerInterceptor();
+    }
+}

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

@@ -0,0 +1,21 @@
+package com.fire.order.mapper;
+
+import com.fire.dto.CustomerInfo;
+
+/**
+ * 客户表(CustomerInfo)表数据库访问层
+ *
+ * @author ZJQ  2021-05-17 13:40:04
+ */
+public interface CustomerInfoMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param customerId 主键
+     * @return 实例对象
+     */
+    CustomerInfo queryById(Long customerId);
+
+}
+

+ 4 - 0
modules/make-order/src/main/java/com/fire/order/request/OrderRequestContent.java

@@ -1,9 +1,13 @@
 package com.fire.order.request;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+@ApiModel(value = "请求参数正文")
+@JsonIgnoreProperties(ignoreUnknown = true)
 @Data
 public class OrderRequestContent {
 

+ 2 - 0
modules/make-order/src/main/java/com/fire/order/request/OrderRequestMsgBody.java

@@ -1,11 +1,13 @@
 package com.fire.order.request;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @ApiModel(value = "请求参数消息体")
+@JsonIgnoreProperties(ignoreUnknown = true)
 @Data
 public class OrderRequestMsgBody {
 

+ 2 - 0
modules/make-order/src/main/java/com/fire/order/request/OrderRequestParam.java

@@ -1,5 +1,6 @@
 package com.fire.order.request;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fire.param.HeaderDto;
 import io.swagger.annotations.ApiModel;
@@ -7,6 +8,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 @ApiModel(value = "下单接口请求参数")
+@JsonIgnoreProperties(ignoreUnknown = true)
 @Data
 public class OrderRequestParam {
 

+ 7 - 3
modules/make-order/src/main/java/com/fire/order/rest/MakeOrderRest.java

@@ -2,12 +2,15 @@ package com.fire.order.rest;
 
 import com.fire.order.request.OrderRequestParam;
 import com.fire.order.response.OrderResponseDto;
+import com.fire.order.service.MakeOrderService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+
 /**
  * 下单接口rest类
  *
@@ -17,6 +20,9 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 public class MakeOrderRest {
 
+    @Resource
+    private MakeOrderService makeOrderService;
+
     /**
      * 下单接口
      *
@@ -26,8 +32,6 @@ public class MakeOrderRest {
     @PostMapping("/gateway/flowservice/makeorder.ws")
     @ApiOperation(value = "下单接口", notes = "request_make_order.py")
     public OrderResponseDto makeOrder(@RequestBody OrderRequestParam makeOrderParam) {
-
-
-        return new OrderResponseDto();
+        return makeOrderService.makeOrder(makeOrderParam);
     }
 }

+ 21 - 0
modules/make-order/src/main/java/com/fire/order/service/MakeOrderService.java

@@ -0,0 +1,21 @@
+package com.fire.order.service;
+
+
+import com.fire.order.request.OrderRequestParam;
+import com.fire.order.response.OrderResponseDto;
+
+/**
+ * 下单服务接口
+ *
+ * @author ZJQ 2021年5月14日17:13:54
+ */
+public interface MakeOrderService {
+
+    /**
+     * 下单方法
+     *
+     * @param orderRequestParam 下单参数
+     */
+    OrderResponseDto makeOrder(OrderRequestParam orderRequestParam);
+
+}

+ 98 - 0
modules/make-order/src/main/java/com/fire/order/service/impl/MakeOrderServiceImpl.java

@@ -0,0 +1,98 @@
+package com.fire.order.service.impl;
+
+
+import com.fire.order.request.OrderRequestContent;
+import com.fire.order.request.OrderRequestMsgBody;
+import com.fire.order.request.OrderRequestParam;
+import com.fire.order.response.OrderResp;
+import com.fire.order.response.OrderResponseDto;
+import com.fire.order.response.OrderResponseMsgBody;
+import com.fire.order.service.MakeOrderService;
+import com.fire.param.HeaderDto;
+import com.fire.utils.date.DateUtils;
+import com.fire.utils.string.StringUtils;
+import org.springframework.stereotype.Service;
+
+import static com.fire.dto.enums.Status.*;
+
+/**
+ * 下单服务实现层
+ *
+ * @author ZJQ 2021年5月14日17:13:54
+ */
+@Service
+public class MakeOrderServiceImpl implements MakeOrderService {
+
+    /**
+     * 下单方法
+     *
+     * @param orderRequestParam 下单参数
+     */
+    @Override
+    public OrderResponseDto makeOrder(OrderRequestParam orderRequestParam) {
+        //初始化下单响应类
+        OrderResponseDto responseDto = new OrderResponseDto();
+        OrderResp orderResp = new OrderResp();
+        OrderResponseMsgBody msgBody = new OrderResponseMsgBody();
+        msgBody.setResp(orderResp);
+        responseDto.setMsgBody(msgBody);
+        //判断请求参数是否为空
+        if (null == orderRequestParam) {
+            orderResp.setRCode(FAILURE_SERVER.status());
+            orderResp.setRMsg("请求参数为空");
+            return responseDto;
+        }
+        HeaderDto header = orderRequestParam.getHeader();
+        //判断头信息是否为空
+        if (null == header) {
+            orderResp.setRCode(FAILURE_SERVER.status());
+            orderResp.setRMsg("请求参数头信息为空");
+            return responseDto;
+        }
+        responseDto.setHeader(header);
+        //校验时间戳
+        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);
+        if (orderT == 0) {
+            orderResp.setRCode(FAILURE_SERVER.status());
+            orderResp.setRMsg("时间戳格式错误");
+            return responseDto;
+        }
+
+        if (Math.abs(now - orderT) > 300000) {
+            orderResp.setRCode(OVER_TIME.status());
+            orderResp.setRMsg(OVER_TIME.message());
+            return responseDto;
+        }
+        //校验消息体
+        OrderRequestMsgBody requestMsgBody = orderRequestParam.getMsgBody();
+        if (null == requestMsgBody) {
+            orderResp.setRCode(FAILURE_SERVER.status());
+            orderResp.setRMsg("请求消息体为空");
+            return responseDto;
+        }
+        //参数正文校验
+        OrderRequestContent content = requestMsgBody.getContent();
+        if (null == content) {
+            orderResp.setRCode(FAILURE_SERVER.status());
+            orderResp.setRMsg("请求参数正文为空");
+            return responseDto;
+        }
+        //手机号校验
+        String phoneNo = content.getUser();
+        if (!StringUtils.isMobile(phoneNo)) {
+            orderResp.setRCode(PHONE_NUM_ERROR.status());
+            orderResp.setRMsg(PHONE_NUM_ERROR.message());
+            return responseDto;
+        }
+
+        return responseDto;
+    }
+
+}

+ 56 - 0
modules/make-order/src/main/resources/mapper/CustomerInfoMapper.xml

@@ -0,0 +1,56 @@
+<?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.CustomerInfoMapper">
+
+    <resultMap type="com.fire.dto.CustomerInfo" id="CustomerInfoMap">
+        <result property="customerId" column="customer_id" jdbcType="INTEGER"/>
+        <result property="partnerId" column="partner_id" jdbcType="INTEGER"/>
+        <result property="customerName" column="customer_name" jdbcType="VARCHAR"/>
+        <result property="shorterName" column="shorter_name" jdbcType="VARCHAR"/>
+        <result property="linkmanName" column="linkman_name" jdbcType="VARCHAR"/>
+        <result property="linkmanMobile" column="linkman_mobile" jdbcType="VARCHAR"/>
+        <result property="linkmanEmail" column="linkman_email" jdbcType="VARCHAR"/>
+        <result property="address" column="address" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="balance" column="balance" jdbcType="NUMERIC"/>
+        <result property="creditAmount" column="credit_amount" jdbcType="NUMERIC"/>
+        <result property="currentAmount" column="current_amount" jdbcType="NUMERIC"/>
+        <result property="isFirstLogin" column="is_first_login" jdbcType="INTEGER"/>
+        <result property="isDeleted" column="is_deleted" jdbcType="INTEGER"/>
+        <result property="creator" column="creator" jdbcType="VARCHAR"/>
+        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+        <result property="updator" column="updator" jdbcType="VARCHAR"/>
+        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
+        <result property="partnerCommission" column="partner_commission" jdbcType="VARCHAR"/>
+        <result property="userId" column="user_id" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!--查询单个-->
+    <select id="queryById" resultMap="CustomerInfoMap">
+        select customer_id,
+               partner_id,
+               customer_name,
+               shorter_name,
+               linkman_name,
+               linkman_mobile,
+               linkman_email,
+               address,
+               status,
+               balance,
+               credit_amount,
+               current_amount,
+               is_first_login,
+               is_deleted,
+               creator,
+               create_time,
+               updator,
+               update_time,
+               partner_commission,
+               user_id
+        from fmp.customer_info
+        where customer_id = #{customerId}
+    </select>
+
+
+</mapper>
+