Pārlūkot izejas kodu

feat: 风控1, 单个人连续多月结算相同金额

shc 3 gadi atpakaļ
vecāks
revīzija
c947d03ae8

+ 31 - 0
db/v2022/4single_member_settle_same_amount_in_several_months.sql

@@ -0,0 +1,31 @@
+USE hnqzx;
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for single_member_settle_same_amount_in_several_months
+-- ----------------------------
+DROP TABLE IF EXISTS `single_member_settle_same_amount_in_several_months`;
+CREATE TABLE `single_member_settle_same_amount_in_several_months`
+(
+    `record_id`               INT UNSIGNED AUTO_INCREMENT COMMENT 'id',
+    `note_id`                 INT UNSIGNED NOT NULL COMMENT '积分包计算记录id',
+    `realname`                VARCHAR(32)  NOT NULL COMMENT '用户名称',
+    `username`                VARCHAR(11)  NOT NULL COMMENT '用户名',
+    `dept_id`                 INT          NOT NULL COMMENT '结算企业id',
+    `dept_name`               VARCHAR(64)  NOT NULL COMMENT '结算企业名称',
+    `settle_amount`           DECIMAL      NOT NULL COMMENT '结算金额',
+    `sub_to_gig_time`         DATETIME     NULL COMMENT '结算时间',
+    `settle_state`            VARCHAR(16)  NOT NULL COMMENT '结算企业名称',
+    `sub_type_name`           VARCHAR(16)  NOT NULL COMMENT '结算渠道名称',
+    `package_name`            VARCHAR(64)  NOT NULL COMMENT '积分包名称',
+    `settle_note_create_time` DATETIME     NOT NULL COMMENT '结算记录创建时间',
+    `period`                  INT UNSIGNED NOT NULL COMMENT '统计周期',
+    `created_time`            DATETIME     NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    PRIMARY KEY (`record_id`) USING BTREE
+) ENGINE = InnoDB
+  DEFAULT CHARSET = utf8mb4 COMMENT ='单人连续多月结算相同金额';
+
+
+SET FOREIGN_KEY_CHECKS = 1;

+ 90 - 0
hnqz-visual/hnqz-daemon-quartz/src/main/java/com/qunzhixinxi/hnqz/daemon/quartz/entity/SingleMemberSettleSameAmountInSeveralMonths.java

@@ -0,0 +1,90 @@
+package com.qunzhixinxi.hnqz.daemon.quartz.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+
+
+@Data
+@TableName(value = "single_member_settle_same_amount_in_several_months")
+public class SingleMemberSettleSameAmountInSeveralMonths implements Serializable {
+
+	private static final long serialVersionUID = -3597822678068222296L;
+
+	/**
+	 * 记录id
+	 */
+	@TableId(type = IdType.AUTO)
+	private Integer recordId;
+
+	/**
+	 * 结算记录id
+	 */
+	private Integer noteId;
+
+	/**
+	 * 真实名称
+	 */
+	private String realname;
+
+	/**
+	 * 用户名
+	 */
+	private String username;
+
+	/**
+	 * 结算企业id
+	 */
+	private String deptId;
+
+	/**
+	 * 结算企业信息
+	 */
+	private String deptName;
+
+	/**
+	 * 结算金额
+	 */
+	private BigDecimal settleAmount;
+
+	/**
+	 * 提交结算时间
+	 */
+	private LocalDateTime subToGigTime;
+
+	/**
+	 * 结算状态
+	 */
+	private String settleState;
+
+	/**
+	 * 结算渠道名称
+	 */
+	private String subTypeName;
+
+	/**
+	 * 积分包名称
+	 */
+	private String packageName;
+
+	/**
+	 * 结算记录创建时间
+	 */
+	private String settleNoteCreateTime;
+
+	/**
+	 * 统计周期
+	 */
+	private Integer period;
+
+	/**
+	 * 记录创建时间
+	 */
+	private LocalDateTime createTime;
+
+}

+ 9 - 0
hnqz-visual/hnqz-daemon-quartz/src/main/java/com/qunzhixinxi/hnqz/daemon/quartz/mapper/SingleMemberSettleSameAmountInSeveralMonthsMapper.java

@@ -0,0 +1,9 @@
+package com.qunzhixinxi.hnqz.daemon.quartz.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface SingleMemberSettleSameAmountInSeveralMonthsMapper extends BaseMapper<SingleMemberSettleSameAmountInSeveralMonths> {
+}

+ 8 - 4
hnqz-visual/hnqz-daemon-quartz/src/main/java/com/qunzhixinxi/hnqz/daemon/quartz/mapper/WmScorePackageSettleNoteMapper.java

@@ -16,7 +16,9 @@
  */
 
 package com.qunzhixinxi.hnqz.daemon.quartz.mapper;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
 import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmScorePackageSettleNote;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -36,12 +38,14 @@ public interface WmScorePackageSettleNoteMapper extends BaseMapper<WmScorePackag
 	/**
 	 * 查询指定部门对应的结算数据
 	 *
-	 * @param deptId 部门id
-	 * @param subType 结算渠道
+	 * @param deptId    部门id
+	 * @param subType   结算渠道
 	 * @param startTime 开始时间
-	 * @param endTime 结束时间
+	 * @param endTime   结束时间
 	 * @return
 	 */
 	List<WmScorePackageSettleNote> listSettleAmountByDeptId(@Param("deptId") Integer deptId, @Param("subType") String subType,
-														   @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
+															@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
+
+	List<SingleMemberSettleSameAmountInSeveralMonths> singleMemberSettleSameAmountInSeveralMonths(@Param(value = "startTime") LocalDateTime startTime, @Param(value = "endTime") LocalDateTime endTime);
 }

+ 12 - 0
hnqz-visual/hnqz-daemon-quartz/src/main/java/com/qunzhixinxi/hnqz/daemon/quartz/service/WmScorePackageSettleNoteService.java

@@ -1,6 +1,7 @@
 package com.qunzhixinxi.hnqz.daemon.quartz.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
 import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmScorePackageSettleNote;
 
 import java.time.LocalDateTime;
@@ -26,4 +27,15 @@ public interface WmScorePackageSettleNoteService extends IService<WmScorePackage
 	 * @return
 	 */
 	List<WmScorePackageSettleNote> listSettleAmountByDeptId(Integer deptId, String subType, LocalDateTime startTime, LocalDateTime endTime);
+
+	/**
+	 * 同一用户,连续多月结算金额相同
+	 *
+	 * @param startTime 开始时间
+	 * @param endTime   结束时间
+	 * @return 风控对象集合
+	 */
+	List<SingleMemberSettleSameAmountInSeveralMonths> singleMemberSettleSameAmountInSeveralMonths(LocalDateTime startTime, LocalDateTime endTime);
+
+
 }

+ 34 - 0
hnqz-visual/hnqz-daemon-quartz/src/main/java/com/qunzhixinxi/hnqz/daemon/quartz/service/impl/WmScorePackageSettleNoteServiceImpl.java

@@ -1,6 +1,7 @@
 package com.qunzhixinxi.hnqz.daemon.quartz.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
 import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmScorePackageSettleNote;
 import com.qunzhixinxi.hnqz.daemon.quartz.mapper.WmScorePackageSettleNoteMapper;
 import com.qunzhixinxi.hnqz.daemon.quartz.service.WmScorePackageSettleNoteService;
@@ -8,8 +9,12 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * {@code WmScorePackageSettleNoteServiceImpl} 类
@@ -39,4 +44,33 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 	public List<WmScorePackageSettleNote> listSettleAmountByDeptId(Integer deptId, String subType, LocalDateTime startTime, LocalDateTime endTime) {
 		return wmScorePackageSettleNoteMapper.listSettleAmountByDeptId(deptId, subType, startTime, endTime);
 	}
+
+	/**
+	 * 同一用户,连续多月结算金额相同
+	 *
+	 * @param startTime 开始时间
+	 * @param endTime   结束时间
+	 * @return
+	 */
+	@Override
+	public List<SingleMemberSettleSameAmountInSeveralMonths> singleMemberSettleSameAmountInSeveralMonths(LocalDateTime startTime, LocalDateTime endTime) {
+
+		List<SingleMemberSettleSameAmountInSeveralMonths> list = wmScorePackageSettleNoteMapper.singleMemberSettleSameAmountInSeveralMonths(startTime, endTime);
+
+		// 按照用户分组,然后按照结算金额分组,如果结算金额对应的结算记录大于1,则表明有相同的金额
+		Map<String, Map<BigDecimal, List<SingleMemberSettleSameAmountInSeveralMonths>>> collect = list.stream().collect(Collectors.groupingBy(SingleMemberSettleSameAmountInSeveralMonths::getUsername, Collectors.groupingBy(SingleMemberSettleSameAmountInSeveralMonths::getSettleAmount)));
+
+
+		List<SingleMemberSettleSameAmountInSeveralMonths> duplicated = new ArrayList<>(list.size());
+
+		for (Map.Entry<String, Map<BigDecimal, List<SingleMemberSettleSameAmountInSeveralMonths>>> entry : collect.entrySet()){
+			for (Map.Entry<BigDecimal, List<SingleMemberSettleSameAmountInSeveralMonths>> ent : entry.getValue().entrySet()){
+				if (ent.getValue().size() > 1){
+					duplicated.addAll(ent.getValue());
+				}
+			}
+		}
+
+		return duplicated;
+	}
 }

+ 63 - 0
hnqz-visual/hnqz-daemon-quartz/src/main/java/com/qunzhixinxi/hnqz/daemon/quartz/task/SpringBeanTaskDemo.java

@@ -17,8 +17,13 @@
 
 package com.qunzhixinxi.hnqz.daemon.quartz.task;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.qunzhixinxi.hnqz.daemon.quartz.constants.HnqzQuartzEnum;
+import com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths;
 import com.qunzhixinxi.hnqz.daemon.quartz.entity.WmTaskType;
+import com.qunzhixinxi.hnqz.daemon.quartz.mapper.SingleMemberSettleSameAmountInSeveralMonthsMapper;
 import com.qunzhixinxi.hnqz.daemon.quartz.service.*;
 import com.qunzhixinxi.hnqz.daemon.quartz.zhuqu.ZhuaquTest;
 import lombok.AllArgsConstructor;
@@ -27,7 +32,13 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.GetMapping;
 
+import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalAdjusters;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author 郑健楠
@@ -37,12 +48,14 @@ import java.time.LocalDateTime;
 @AllArgsConstructor
 public class SpringBeanTaskDemo {
 	private final WmScorePackageStatusService wmScorePackageStatusService;
+	private final WmScorePackageSettleNoteService scorePackageSettleNoteService;
 	private final WmScorePackageService wmScorePackageService;
 	private final ZhuaquTest zhuaquTest;
 	private final WmTaskTypeService wmTaskTypeService;
 	private final WmTaskService wmTaskService;
 	private final WmWkArticleService wmWkArticleService;
 	private final WmStatisticsService wmStatisticsService;
+	private final SingleMemberSettleSameAmountInSeveralMonthsMapper singleMemberSettleSameAmountInSeveralMonthsMapper;
 
 //	/**
 //	 * 测试Spring Bean的演示方法
@@ -85,6 +98,7 @@ public class SpringBeanTaskDemo {
 
 	/**
 	 * 每日GMVs统计
+	 *
 	 * @param para
 	 * @return
 	 */
@@ -102,7 +116,56 @@ public class SpringBeanTaskDemo {
 		return HnqzQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
 	}
 
+	/**
+	 * 同一用户,连续多月结算金额相同
+	 *
+	 * @param para 参数(月数)
+	 * @return 运行结果
+	 */
+	@SneakyThrows
+	public String singleMemberSettleSameAmountInSeveralMonths(String para) {
+		// 校验参数
+		if (StrUtil.isBlank(para)) {
+			log.error("参数缺失");
+			return HnqzQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
+		}
+
+		int period = Integer.parseInt(para.trim());
+
+		if (period < 2) {
+			log.error("参数错误");
+			return HnqzQuartzEnum.JOB_LOG_STATUS_FAIL.getType();
+		}
+
+		// 计算查询时间
+		LocalDate now = LocalDateTime.now().toLocalDate().with(TemporalAdjusters.firstDayOfNextMonth());
+		LocalDateTime startTime = LocalDateTime.of(now.minusMonths(period), LocalTime.MIN);
+		LocalDateTime endTime = LocalDateTime.of(now, LocalTime.MIN).minusSeconds(1);
+
+		System.out.println(startTime);
+		System.out.println(endTime);
+
+		log.info("singleMemberSettleSameAmountInSeveralMonths开始于:{},输入参数{}", LocalDateTime.now(), para);
+
+		List<SingleMemberSettleSameAmountInSeveralMonths> result = scorePackageSettleNoteService.singleMemberSettleSameAmountInSeveralMonths(startTime, endTime);
+
+		if (CollUtil.isNotEmpty(result)) {
+			List<SingleMemberSettleSameAmountInSeveralMonths> history = singleMemberSettleSameAmountInSeveralMonthsMapper.selectList(Wrappers.<SingleMemberSettleSameAmountInSeveralMonths>lambdaQuery().between(SingleMemberSettleSameAmountInSeveralMonths::getCreateTime, LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX)));
+			// 删除历史记录
+			log.warn("删除当期的历史记录:{}", history);
+			if (CollUtil.isNotEmpty(history)) {
+				List<Integer> ids = history.stream().mapToInt(SingleMemberSettleSameAmountInSeveralMonths::getRecordId).boxed().collect(Collectors.toList());
+				singleMemberSettleSameAmountInSeveralMonthsMapper.deleteBatchIds(ids);
+			}
+
+			result.forEach(e -> {
+				e.setPeriod(period);
+				singleMemberSettleSameAmountInSeveralMonthsMapper.insert(e);
+			});
+		}
 
+		return HnqzQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
+	}
 
 
 }

+ 51 - 2
hnqz-visual/hnqz-daemon-quartz/src/main/resources/mapper/WmScorePackageSettleNoteMapper.xml

@@ -3,7 +3,8 @@
 
 <mapper namespace="com.qunzhixinxi.hnqz.daemon.quartz.mapper.WmScorePackageSettleNoteMapper">
 
-	<resultMap id="wmScorePackageSettleNoteMap" type="com.qunzhixinxi.hnqz.daemon.quartz.entity.WmScorePackageSettleNote">
+	<resultMap id="wmScorePackageSettleNoteMap"
+			   type="com.qunzhixinxi.hnqz.daemon.quartz.entity.WmScorePackageSettleNote">
 		<id property="id" column="id"/>
 		<result property="packageId" column="package_id"/>
 		<result property="packageStatusId" column="package_status_id"/>
@@ -25,11 +26,26 @@
 		<result property="subType" column="sub_type"/>
 	</resultMap>
 
+	<resultMap id="singleMemberSettleSameAmountInSeveralMonthsMap"
+			   type="com.qunzhixinxi.hnqz.daemon.quartz.entity.SingleMemberSettleSameAmountInSeveralMonths">
+		<id property="noteId" column="id"/>
+		<result property="realname" column="realname"/>
+		<result property="username" column="username"/>
+		<result property="deptId" column="dept_id"/>
+		<result property="deptName" column="dept_name"/>
+		<result property="settleAmount" column="settle_amount"/>
+		<result property="subToGigTime" column="sub_to_gig_time"/>
+		<result property="settleState" column="settle_note_status"/>
+		<result property="subTypeName" column="sub_type"/>
+		<result property="packageName" column="score_package_name"/>
+		<result property="settleNoteCreateTime" column="create_time"/>
+	</resultMap>
+
 	<!-- 查询指定部门对应的结算数据 -->
 	<select id="listSettleAmountByDeptId" resultMap="wmScorePackageSettleNoteMap">
 		SELECT n.settle_amount
 		FROM wm_score_package_settle_note n
-				 LEFT JOIN wm_score_package p on p.id = n.package_id
+				 LEFT JOIN wm_score_package p ON p.id = n.package_id
 		WHERE n.settle_note_status = 1
 		  AND n.settle_amount IS NOT NULL
 		  AND p.send_package_dept_id = #{deptId}
@@ -37,4 +53,37 @@
 		  AND n.notify_time BETWEEN #{startTime} AND #{endTime}
 	</select>
 
+	<select id="singleMemberSettleSameAmountInSeveralMonths" resultMap="singleMemberSettleSameAmountInSeveralMonthsMap">
+		SELECT wspsn.id,
+			   su.realname,
+			   su.username,
+			   sd.dept_id,
+			   sd.name AS `dept_name`,
+			   wspsn.settle_amount,
+			   wspsn.sub_to_gig_time,
+			   CASE wspsn.settle_note_status
+				   WHEN 1 THEN '结算成功'
+				   WHEN 2 THEN '结算失败'
+				   WHEN 3 THEN '已提交'
+				   WHEN 4 THEN '未结算'
+				   WHEN 5 THEN '部分成功'
+				   WHEN 8 THEN '结算成功(线下)'
+				   WHEN 9 THEN '待结算'
+				   END AS `settle_note_status`,
+			   CASE wspsn.sub_type
+				   WHEN 0 THEN '仁励家'
+				   WHEN 1 THEN '税邦云'
+				   WHEN 2 THEN '自由职家'
+				   END AS `sub_type`,
+			   sp.score_package_name,
+			   wspsn.create_time
+		FROM wm_score_package_settle_note wspsn
+				 LEFT JOIN sys_user su ON wspsn.user_id = su.user_id
+				 LEFT JOIN wm_score_package sp ON sp.id = wspsn.package_id
+				 LEFT JOIN sys_dept sd ON sd.dept_id = sp.dept_id
+		WHERE (wspsn.create_time BETWEEN #{startTime} AND #{endTime})
+		  AND sd.name NOT IN ('上海问云生物科技有限公司', '北京遥领医疗科技有限公司')
+		ORDER BY wspsn.user_id ASC, wspsn.create_time DESC
+	</select>
+
 </mapper>