Browse Source

处理流量统计功能

yjwang 1 month ago
parent
commit
0b4461042c

+ 47 - 0
fs-service/src/main/java/com/fs/hisStore/enums/StatTypeEnum.java

@@ -0,0 +1,47 @@
+package com.fs.hisStore.enums;
+
+/**
+ * 统计类型枚举
+ **/
+public enum StatTypeEnum {
+    DAY(1, "日统计"),
+    MONTH(2, "月统计"),
+    YEAR(3, "年统计"),
+    DATE(4, "日期");
+
+    private final Integer code;
+    private final String desc;
+
+    StatTypeEnum(Integer code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public static boolean isValid(Integer code) {
+        if (code == null) {
+            return false;
+        }
+        for (StatTypeEnum type : values()) {
+            if (type.code.equals(code)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static String getAllValidTypes() {
+        StringBuilder sb = new StringBuilder();
+        for (StatTypeEnum type : values()) {
+            sb.append(type.code).append("(").append(type.desc).append(")、");
+        }
+        return sb.deleteCharAt(sb.length() - 1).toString();
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+}

+ 30 - 1
fs-service/src/main/java/com/fs/hisStore/mapper/FsStorePaymentScrmMapper.java

@@ -4,12 +4,13 @@ import java.util.List;
 import java.util.Map;
 
 import com.alibaba.fastjson.JSONObject;
-import com.fs.his.domain.FsStorePayment;
 import com.fs.hisStore.domain.FsStorePaymentScrm;
 import com.fs.hisStore.param.FsStorePaymentParam;
+import com.fs.hisStore.param.FsStoreScanPaymentStatParam;
 import com.fs.hisStore.param.FsStoreStatisticsParam;
 import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
 import com.fs.hisStore.vo.FsStorePaymentVO;
+import com.fs.hisStore.vo.FsStoreScanPaymentStatVo;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
@@ -358,4 +359,32 @@ public interface FsStorePaymentScrmMapper
 
     @Select("select * from fs_store_payment_scrm where business_type=2 and bank_transaction_id=#{bankTransactionId}")
     FsStorePaymentScrm queryFsStorePaymentByBusinessOrderId(@Param("bankTransactionId") String bankTransactionId);
+
+    /**
+     * 销售扫码流水日统计
+     * @param dayParam 查询条件
+     * @return 日统计数据
+     * **/
+    FsStoreScanPaymentStatVo getScanPaymentDayStat(@Param("dayParam")FsStoreScanPaymentStatParam dayParam);
+
+    /**
+     * 销售流水月统计
+     * @param monthParam 查询条件
+     * @return 日统计数据
+     * **/
+    FsStoreScanPaymentStatVo getScanPaymentMonthStat(@Param("monthParam")FsStoreScanPaymentStatParam monthParam);
+
+    /**
+     * 销售流水年统计
+     * @param yearParam 查询条件
+     * @return 日统计数据
+     * **/
+    FsStoreScanPaymentStatVo getScanPaymentYearStat(@Param("yearParam")FsStoreScanPaymentStatParam yearParam);
+
+    /**
+     * 销售流水时间统计
+     * @param dateParam 查询条件
+     * @return 日统计数据
+     * **/
+    FsStoreScanPaymentStatVo getScanPaymentDateStat(@Param("dateParam")FsStoreScanPaymentStatParam dateParam);
 }

+ 52 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsStoreScanPaymentStatParam.java

@@ -0,0 +1,52 @@
+package com.fs.hisStore.param;
+
+import com.fs.common.param.BaseQueryParam;
+import com.fs.hisStore.enums.StatTypeEnum;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * 扫码支付统计类
+ * **/
+@Data
+public class FsStoreScanPaymentStatParam extends BaseQueryParam implements Serializable {
+    /**
+     * 销售ID
+     */
+    @NotNull(message = "操作失败,销售信息不能为空!")
+    private Long companyUserId;
+
+    /**
+     * 统计类型 1:日统计 2:月统计 3:年统计
+     */
+    @NotNull(message = "操作失败,统计类型不能为空!")
+    private Integer statType;
+
+    /**
+     * 开始时间
+     * **/
+    private String startDate;
+
+    /**
+     * 结束时间
+     * **/
+    private String endDate;
+
+    /**
+     * 将数字类型的 statType 转换为 StatTypeEnum 枚举
+     * @return 对应的枚举实例
+     */
+    public StatTypeEnum toStatTypeEnum() {
+        if (statType == null) {
+            return null;
+        }
+        for (StatTypeEnum type : StatTypeEnum.values()) {
+            if (type.getCode().equals(statType)) {
+                return type;
+            }
+        }
+        return null;
+    }
+}

+ 8 - 1
fs-service/src/main/java/com/fs/hisStore/service/IFsStorePaymentScrmService.java

@@ -116,4 +116,11 @@ public interface IFsStorePaymentScrmService
     R getWxaCodeByPayment(FsStorePaymentGetWxaCodeParam param);
 
     R paymentByWxaCode(FsStorePaymentPayParam param);
-}
+
+    /**
+     * 商户扫码统计接口
+     * @param param 查询语句
+     * @return 扫码流水日统计
+     * **/
+    R getScanPaymentStat(FsStoreScanPaymentStatParam param);
+}

+ 35 - 5
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStorePaymentScrmServiceImpl.java

@@ -30,19 +30,19 @@ import com.fs.course.config.RedPacketConfig;
 import com.fs.course.domain.FsCourseRedPacketLog;
 import com.fs.course.mapper.FsCourseRedPacketLogMapper;
 import com.fs.course.service.IFsCourseRedPacketLogService;
-import com.fs.his.config.FsSysConfig;
 import com.fs.his.domain.FsUser;
 import com.fs.his.domain.FsUserWx;
 import com.fs.his.service.IFsUserService;
 import com.fs.his.service.IFsUserWxService;
 import com.fs.his.utils.ConfigUtil;
-import com.fs.his.utils.HttpUtil;
+import com.fs.hisStore.enums.StatTypeEnum;
 import com.fs.hisStore.enums.SysConfigEnum;
 import com.fs.hisStore.param.*;
+import com.fs.hisStore.vo.FsStoreScanPaymentStatVo;
 import com.fs.huifuPay.domain.HuiFuCreateOrder;
 import com.fs.huifuPay.domain.HuifuCreateOrderResult;
+import com.fs.huifuPay.sdk.opps.core.utils.ObjectUtils;
 import com.fs.huifuPay.service.HuiFuService;
-import com.fs.pay.pay.config.PayConfig;
 import com.fs.pay.pay.dto.WxJspayDTO;
 import com.fs.hisStore.vo.FsStorePaymentStatisticsVO;
 import com.fs.system.oss.CloudStorageService;
@@ -64,8 +64,6 @@ import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.TransferService;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
-import com.google.common.reflect.TypeToken;
-import com.google.gson.Gson;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -896,4 +894,36 @@ public class FsStorePaymentScrmServiceImpl implements IFsStorePaymentScrmService
             return R.error(result.getResp_desc());
         }
     }
+
+    @Override
+    public R getScanPaymentStat(FsStoreScanPaymentStatParam param) {
+        //验证类型是否错误
+        if (!StatTypeEnum.isValid(param.getStatType())) {
+            return R.error("操作失败,无效的统计类型!有效类型为:" + StatTypeEnum.getAllValidTypes());
+        }
+
+        StatTypeEnum statTypeEnum = param.toStatTypeEnum();
+        FsStoreScanPaymentStatVo paymentStatVo = null;
+        switch (statTypeEnum) {
+            case DAY://日
+                paymentStatVo = fsStorePaymentMapper.getScanPaymentDayStat(param);
+                break;
+            case MONTH://月
+                paymentStatVo = fsStorePaymentMapper.getScanPaymentMonthStat(param);
+                break;
+            case YEAR://年
+                paymentStatVo = fsStorePaymentMapper.getScanPaymentYearStat(param);
+                break;
+            case DATE://日期
+                if(StringUtils.isEmpty(param.getStartDate())){
+                    return R.error("操作失败,开始日期不能为空!");
+                }else if(StringUtils.isEmpty(param.getEndDate())){
+                    return R.error("操作失败,结日期不能为空!");
+                }
+                paymentStatVo = fsStorePaymentMapper.getScanPaymentDateStat(param);
+                break;
+        }
+
+        return R.ok("操作成功!").put("data", paymentStatVo);
+    }
 }

+ 27 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreScanPaymentStatVo.java

@@ -0,0 +1,27 @@
+package com.fs.hisStore.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 扫码流水统计类
+ * **/
+@Data
+public class FsStoreScanPaymentStatVo implements Serializable {
+    /**
+     * 统计时期
+     * **/
+    private String statPeriod;
+
+    /**
+     * 支付单数
+     * **/
+    private Integer payCount;
+
+    /**
+     * 总金额
+     * **/
+    private BigDecimal totalSales;
+}

+ 71 - 0
fs-service/src/main/resources/mapper/hisStore/FsStorePaymentScrmMapper.xml

@@ -192,5 +192,76 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </if>
     </select>
 
+    <select id="getScanPaymentDayStat" resultType="com.fs.hisStore.vo.FsStoreScanPaymentStatVo">
+        SELECT
+            DATE_FORMAT(pay_time, '%Y-%m-%d') AS statPeriod,
+            COUNT(payment_id) AS payCount,
+            SUM(pay_money) AS totalSales
+        FROM
+            fs_store_payment_scrm
+        WHERE
+            business_type = 1
+          AND `status` = 1
+          AND pay_time > '2025-05-01 00:00:00'
+          AND company_user_id = #{dayParam.companyUserId}
+          AND DATE_FORMAT(pay_time, '%Y-%m-%d')= DATE_FORMAT(NOW(), '%Y-%m-%d')
+        GROUP BY
+            statPeriod
+        ORDER BY
+            statPeriod ASC
+    </select>
+
+    <select id="getScanPaymentMonthStat" resultType="com.fs.hisStore.vo.FsStoreScanPaymentStatVo">
+        SELECT
+            DATE_FORMAT(pay_time, '%Y-%m') AS statPeriod,
+            COUNT(payment_id) AS payCount,
+            SUM(pay_money) AS totalSales
+        FROM
+            fs_store_payment_scrm
+        WHERE
+            business_type = 1
+          AND `status` = 1
+          AND pay_time > '2025-05-01 00:00:00'
+          AND company_user_id = #{monthParam.companyUserId}
+          AND DATE_FORMAT(pay_time, '%Y-%m')= DATE_FORMAT(NOW(), '%Y-%m')
+        GROUP BY
+            statPeriod
+        ORDER BY
+            statPeriod ASC
+    </select>
 
+    <select id="getScanPaymentYearStat" resultType="com.fs.hisStore.vo.FsStoreScanPaymentStatVo">
+        SELECT
+            DATE_FORMAT(pay_time, '%Y') AS statPeriod,
+            COUNT(payment_id) AS payCount,
+            SUM(pay_money) AS totalSales
+        FROM
+            fs_store_payment_scrm
+        WHERE
+            business_type = 1
+          AND `status` = 1
+          AND pay_time > '2025-05-01 00:00:00'
+          AND company_user_id = #{yearParam.companyUserId}
+          AND DATE_FORMAT(pay_time, '%Y')= DATE_FORMAT(NOW(), '%Y')
+        GROUP BY
+            statPeriod
+        ORDER BY
+            statPeriod ASC
+    </select>
+
+    <select id="getScanPaymentDateStat" resultType="com.fs.hisStore.vo.FsStoreScanPaymentStatVo">
+        SELECT
+            CONCAT(#{dateParam.startDate},'至',#{dateParam.endDate}) AS statPeriod,
+            COUNT(payment_id) AS payCount,
+            SUM(pay_money) AS totalSales
+        FROM
+            fs_store_payment_scrm
+        WHERE
+            business_type = 1
+          AND `status` = 1
+          AND pay_time > '2025-05-01 00:00:00'
+          AND company_user_id = #{dateParam.companyUserId}
+          AND pay_time >= CONCAT(#{dateParam.startDate}, ' 00:00:00')
+          AND pay_time &lt;= CONCAT(#{dateParam.endDate}, ' 23:59:59')
+    </select>
 </mapper>

+ 29 - 0
fs-user-app/src/main/java/com/fs/app/controller/store/FsStoreScanPaymentStatController.java

@@ -0,0 +1,29 @@
+package com.fs.app.controller.store;
+
+import com.fs.app.controller.AppBaseController;
+import com.fs.common.core.domain.R;
+import com.fs.hisStore.param.FsStoreScanPaymentStatParam;
+import com.fs.hisStore.service.IFsStorePaymentScrmService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+@Api("扫码流水统计接口")
+@RestController
+@RequestMapping("/store/app/scan/payment")
+public class FsStoreScanPaymentStatController extends AppBaseController {
+    @Autowired
+    private IFsStorePaymentScrmService paymentService;
+
+    /**
+     * 扫码支付统计接口
+     */
+    @ApiOperation("销售收款码金额统计")
+    @PostMapping("/getScanPayStat")
+    public R getScanPayStat(@Valid @RequestBody FsStoreScanPaymentStatParam param) {
+        return paymentService.getScanPaymentStat(param);
+    }
+}