Sfoglia il codice sorgente

Merge branch 'feat-yaoyelimit'

shc 1 anno fa
parent
commit
112b91d30b

+ 2 - 11
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmPayOffController.java

@@ -141,7 +141,8 @@ public class WmPayOffController {
 	 */
 	@SysLog("提交结算")
 	@PostMapping("/settleSubmit")
-	public R<?> settleSubmit(@RequestBody @Valid WmScorePackageSettleInput input) {
+	public R<?>
+	settleSubmit(@RequestBody @Valid WmScorePackageSettleInput input) {
 		log.info("提交结算参数:{}", input);
 
 		//1、验证令牌是否合法【令牌的对比和删除必须保证原子性】
@@ -617,16 +618,6 @@ public class WmPayOffController {
 	@PostMapping("/settleIssueBySubType")
 	public R<?> settleIssueBySubType(@RequestBody WmScorePackageSettleInput input) {
 
-		// 获取当日所在月份
-		LocalDateTime today = LocalDateTime.now();
-		int monthValue = today.getMonthValue();
-
-		Optional<WmScorePackageSettleNote> any = input.getNotes().stream().filter(note -> note.getSubTime() == null || note.getSubTime().getMonthValue() != monthValue).findAny();
-
-		if (any.isPresent()){
-			return R.failed("不支持结算非当月提交记录,请回退并重新提交后重试");
-		}
-
 
 		if (StrUtil.isBlank(input.getId()) || StrUtil.isBlank(input.getScorePackageName()) || input.getSubjectLocation() == null || CollUtil.isEmpty(input.getNotes()) || null == input.getInvoiceCategory()) {
 			return R.failed("数据异常");

+ 89 - 94
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/MonitoringIndicatorServiceImpl.java

@@ -23,26 +23,21 @@ import com.qunzhixinxi.hnqz.admin.entity.SysDeptSub;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageSettleNote;
 import com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
-import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
 import com.qunzhixinxi.hnqz.admin.mapper.MonitoringIndicatorMapper;
 import com.qunzhixinxi.hnqz.admin.service.MonitoringIndicatorService;
 import com.qunzhixinxi.hnqz.admin.service.SysDeptSubService;
-import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
 import java.util.Collection;
 import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 
-import static com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants.MONITORING_INDICATOR;
 
 /**
  * 风险监控
@@ -55,93 +50,93 @@ import static com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants.MONITORING_
 @AllArgsConstructor
 public class MonitoringIndicatorServiceImpl extends ServiceImpl<MonitoringIndicatorMapper, MonitoringIndicator> implements MonitoringIndicatorService {
 
-	private final SysDeptSubService sysDeptSubService;
-
-	/**
-	 * 获取税源地限额
-	 *
-	 * @param subjectLocation 税源地
-	 * @return 限额信息
-	 */
-	@Override
-	public MonitoringIndicator locationLimit(SubjectLocation subjectLocation) {
-		MonitoringIndicator one = this.getOne(Wrappers.<MonitoringIndicator>lambdaQuery().eq(MonitoringIndicator::getSubjectLocation, subjectLocation));
-
-		if (one == null) {
-			throw new RuntimeException("风控信息不存在");
-		}
-
-		log.info("风控信息:{}", one);
-		return one;
-	}
-
-	/**
-	 * 结算校验
-	 *
-	 * @param notes    结算记录
-	 * @param location 税源地
-	 * @return 总结算额
-	 */
-	@Override
-	public BigDecimal settleMonitoringIndicator(Collection<WmScorePackageSettleNote> notes, SubjectLocation location) {
-		// 结算渠道
-		SysDeptSub sysDeptSub = sysDeptSubService.getDeptSub(SecurityUtils.getUser().getDeptId(), location);
-
-		// 校验当月结算额度
-		List<String> idCards = notes.stream().map(WmScorePackageSettleNote::getIdCardNumber).collect(Collectors.toList());
-		List<Integer> noteIds = notes.stream().map(WmScorePackageSettleNote::getId).filter(Objects::nonNull).collect(Collectors.toList());
-		Set<Integer> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).map(Integer::valueOf).collect(Collectors.toSet());
-
-		List<SettleAmountMonitorOutput> monitorOutputList = sysDeptSubService.getSettleAmountMonitor(idCards, noteIds, location);
-		List<SettleAmountMonitorOutput> yaoyiAmountMonitor = sysDeptSubService.getYaoyiAmountMonitor(idCards, noteIds, location);
-		List<SettleAmountMonitorOutput> deptAmountMonitor = sysDeptSubService.getDeptAmountMonitor(userIds, noteIds, location);
-
-		// 限额
-		MonitoringIndicator monitoringIndicator = this.locationLimit(location);
-
-		BigDecimal deptLimit = sysDeptSub.getLimitAmount();
-		BigDecimal monitoringLimit = monitoringIndicator.getLimitAmount();
-		BigDecimal yaoyiLimitAmount = monitoringIndicator.getYaoyiLimitAmount();
-
-		BigDecimal total = BigDecimal.ZERO;
-		for (WmScorePackageSettleNote note : notes) {
-			total = total.add(note.getSettleAmount());
-			BigDecimal monitorAmount = note.getSettleAmount();
-			BigDecimal deptMonitorAmount = note.getSettleAmount();
-			BigDecimal yaoyiMonitorAmount = note.getSettleAmount();
-			SettleAmountMonitorOutput monitorOutput = monitorOutputList.stream().filter(item -> item.getIdCardNumber()
-					.equals(note.getIdCardNumber())).findFirst().orElse(null);
-
-			SettleAmountMonitorOutput deptMonitorOutput = deptAmountMonitor.stream().filter(item -> item.getUserId()
-					.equals(note.getUserId())).findFirst().orElse(null);
-
-			SettleAmountMonitorOutput yaoyiMonitorOutput = yaoyiAmountMonitor.stream().filter(item -> item.getIdCardNumber()
-					.equals(note.getIdCardNumber())).findFirst().orElse(null);
-
-			if (null != monitorOutput) {
-				monitorAmount = monitorAmount.add(monitorOutput.getTotalAmount());
-			}
-
-			if (null != deptMonitorOutput) {
-				deptMonitorAmount = deptMonitorAmount.add(deptMonitorOutput.getTotalAmount());
-			}
-
-			if (null != yaoyiMonitorOutput) {
-				yaoyiMonitorAmount = yaoyiMonitorAmount.add(yaoyiMonitorOutput.getTotalAmount());
-			}
-
-			if (null != deptLimit && deptMonitorAmount.compareTo(deptLimit) > 0) {
-				throw new RuntimeException(note.getRealName() + ":超过当月限额");
-			}
-
-			if (null != monitoringLimit && monitorAmount.compareTo(monitoringLimit) > 0) {
-				throw new RuntimeException(note.getRealName() + ":超过结算渠道限额");
-			}
-			if (null != yaoyiLimitAmount && yaoyiMonitorAmount.compareTo(yaoyiLimitAmount) > 0) {
-				throw new RuntimeException(note.getRealName() + ":超过平台限额");
-			}
-		}
-
-		return total;
-	}
+    private final SysDeptSubService sysDeptSubService;
+
+    /**
+     * 获取税源地限额
+     *
+     * @param subjectLocation 税源地
+     * @return 限额信息
+     */
+    @Override
+    public MonitoringIndicator locationLimit(SubjectLocation subjectLocation) {
+        MonitoringIndicator one = this.getOne(Wrappers.<MonitoringIndicator>lambdaQuery().eq(MonitoringIndicator::getSubjectLocation, subjectLocation));
+
+        if (one == null) {
+            throw new RuntimeException("风控信息不存在");
+        }
+
+        log.info("风控信息:{}", one);
+        return one;
+    }
+
+    /**
+     * 结算校验
+     *
+     * @param notes    结算记录
+     * @param location 税源地
+     * @return 总结算额
+     */
+    @Override
+    public BigDecimal settleMonitoringIndicator(Collection<WmScorePackageSettleNote> notes, SubjectLocation location) {
+        // 结算渠道
+        SysDeptSub sysDeptSub = sysDeptSubService.getDeptSub(SecurityUtils.getUser().getDeptId(), location);
+
+        // 校验当月结算额度
+        List<String> idCards = notes.stream().map(WmScorePackageSettleNote::getIdCardNumber).collect(Collectors.toList());
+        List<Integer> noteIds = notes.stream().map(WmScorePackageSettleNote::getId).filter(Objects::nonNull).collect(Collectors.toList());
+        Set<Integer> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).map(Integer::valueOf).collect(Collectors.toSet());
+
+        List<SettleAmountMonitorOutput> monitorOutputList = sysDeptSubService.getSettleAmountMonitor(idCards, noteIds, location);
+        List<SettleAmountMonitorOutput> yaoyiAmountMonitor = sysDeptSubService.getYaoyiAmountMonitor(idCards, noteIds, location);
+        List<SettleAmountMonitorOutput> deptAmountMonitor = sysDeptSubService.getDeptAmountMonitor(userIds, noteIds, location);
+
+        // 限额
+        MonitoringIndicator monitoringIndicator = this.locationLimit(location);
+
+        BigDecimal deptLimit = sysDeptSub.getLimitAmount();
+        BigDecimal monitoringLimit = monitoringIndicator.getLimitAmount();
+        BigDecimal yaoyiLimitAmount = monitoringIndicator.getYaoyiLimitAmount();
+
+        BigDecimal total = BigDecimal.ZERO;
+        for (WmScorePackageSettleNote note : notes) {
+            total = total.add(note.getSettleAmount());
+            BigDecimal monitorAmount = note.getSettleAmount();
+            BigDecimal deptMonitorAmount = note.getSettleAmount();
+            BigDecimal yaoyiMonitorAmount = note.getSettleAmount();
+            SettleAmountMonitorOutput monitorOutput = monitorOutputList.stream().filter(item -> item.getIdCardNumber()
+                    .equals(note.getIdCardNumber())).findFirst().orElse(null);
+
+            SettleAmountMonitorOutput deptMonitorOutput = deptAmountMonitor.stream().filter(item -> item.getUserId()
+                    .equals(note.getUserId())).findFirst().orElse(null);
+
+            SettleAmountMonitorOutput yaoyiMonitorOutput = yaoyiAmountMonitor.stream().filter(item -> item.getIdCardNumber()
+                    .equals(note.getIdCardNumber())).findFirst().orElse(null);
+
+            if (null != monitorOutput) {
+                monitorAmount = monitorAmount.add(monitorOutput.getTotalAmount());
+            }
+
+            if (null != deptMonitorOutput) {
+                deptMonitorAmount = deptMonitorAmount.add(deptMonitorOutput.getTotalAmount());
+            }
+
+            if (null != yaoyiMonitorOutput) {
+                yaoyiMonitorAmount = yaoyiMonitorAmount.add(yaoyiMonitorOutput.getTotalAmount());
+            }
+
+            if (null != deptLimit && deptMonitorAmount.compareTo(deptLimit) > 0) {
+                throw new RuntimeException("企业限额:[" + deptLimit + "]," + note.getRealName() + "存在:[" + deptMonitorAmount + "], 超过企业限额");
+            }
+
+            if (null != monitoringLimit && monitorAmount.compareTo(monitoringLimit) > 0) {
+                throw new RuntimeException("渠道限额:[" + monitoringLimit + "]," + note.getRealName() + "存在:[" + monitorAmount + "], 超过结算渠道限额");
+            }
+            if (null != yaoyiLimitAmount && yaoyiMonitorAmount.compareTo(yaoyiLimitAmount) > 0) {
+                throw new RuntimeException("渠道限额:[" + yaoyiLimitAmount + "]," + note.getRealName() + "存在:[" + yaoyiMonitorAmount + "],可用于结算(结算失败、待结算)和当月在途结算的记录总额超过平台限额");
+            }
+        }
+
+        return total;
+    }
 }

+ 94 - 82
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/SysDeptSubMapper.xml

@@ -3,91 +3,103 @@
 
 <mapper namespace="com.qunzhixinxi.hnqz.admin.mapper.SysDeptSubMapper">
 
-	<resultMap id="sysDeptSubMap" type="com.qunzhixinxi.hnqz.admin.entity.SysDeptSub">
-		<id property="deptId" column="dept_id"/>
-		<result property="appId" column="app_id"/>
-		<result property="appSecret" column="app_secret"/>
-		<result property="rsaPublicKey" column="rsa_public_key"/>
-		<result property="queryUrl" column="query_url"/>
-		<result property="subjectName" column="subject_name"/>
-		<result property="subjectType" column="subject_type"/>
-		<result property="limitAmount" column="limit_amount"/>
-		<result property="enableFlag" column="enable_flag"/>
-	</resultMap>
+    <resultMap id="sysDeptSubMap" type="com.qunzhixinxi.hnqz.admin.entity.SysDeptSub">
+        <id property="deptId" column="dept_id"/>
+        <result property="appId" column="app_id"/>
+        <result property="appSecret" column="app_secret"/>
+        <result property="rsaPublicKey" column="rsa_public_key"/>
+        <result property="queryUrl" column="query_url"/>
+        <result property="subjectName" column="subject_name"/>
+        <result property="subjectType" column="subject_type"/>
+        <result property="limitAmount" column="limit_amount"/>
+        <result property="enableFlag" column="enable_flag"/>
+    </resultMap>
 
-	<resultMap id="serviceChargeMap" type="com.qunzhixinxi.hnqz.admin.api.vo.SysEnterpriseServiceChargeVO">
-		<id property="entId" column="ent_id"/>
-		<result property="subjectLocation" column="subject_location"/>
-		<result property="serviceCharge" column="service_charge"/>
-	</resultMap>
+    <resultMap id="serviceChargeMap" type="com.qunzhixinxi.hnqz.admin.api.vo.SysEnterpriseServiceChargeVO">
+        <id property="entId" column="ent_id"/>
+        <result property="subjectLocation" column="subject_location"/>
+        <result property="serviceCharge" column="service_charge"/>
+    </resultMap>
 
-	<select id="getSettleAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
-		SELECT
-		t.id_card_number,
-		sum(t.settle_amount) AS totalAmount
-		FROM wm_score_package_settle_note t
-		WHERE t.subject_location = #{query.location, jdbcType=VARCHAR}
-		AND t.create_time &gt; #{query.startTime,jdbcType=TIMESTAMP}
-		AND t.create_time &lt; #{query.endTime,jdbcType=TIMESTAMP}
-		AND t.id_card_number IN
-		<foreach item="item" index="index" collection="query.idCards" open="(" separator="," close=")">
-			#{item}
-		</foreach>
-		<if test="query.settleNoteIds != null and query.settleNoteIds.size()>0">
-			AND t.id NOT IN
-			<foreach item="item" index="index" collection="query.settleNoteIds" open="(" separator="," close=")">
-				#{item}
-			</foreach>
-		</if>
-		GROUP BY t.id_card_number
-	</select>
+    <select id="getSettleAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
+        SELECT
+        t.id_card_number,
+        sum(t.settle_amount) AS totalAmount
+        FROM wm_score_package_settle_note t
+        WHERE t.subject_location = #{query.location, jdbcType=VARCHAR}
+        AND (t.settle_note_status IN ('2', '9', '0')
+        OR (t.settle_note_status = '3' AND (t.sub_to_gig_time BETWEEN #{query.startTime,jdbcType=TIMESTAMP} AND
+        #{query.endTime,jdbcType=TIMESTAMP})))
+        AND t.id_card_number IN
+        <foreach item="item" index="index" collection="query.idCards" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        <if test="query.settleNoteIds != null and query.settleNoteIds.size()>0">
+            AND t.id NOT IN
+            <foreach item="item" index="index" collection="query.settleNoteIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY t.id_card_number
+    </select>
 
-	<select id="getDeptAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
-		SELECT
-		t.user_id,
-		sum(t.settle_amount) AS totalAmount
-		FROM wm_score_package_settle_note t
-		WHERE t.subject_location = #{query.location, jdbcType=VARCHAR}
-		AND t.create_time &gt; #{query.startTime,jdbcType=TIMESTAMP}
-		AND t.create_time &lt; #{query.endTime,jdbcType=TIMESTAMP}
-		AND t.user_id IN
-		<foreach item="item" index="index" collection="query.userIds" open="(" separator="," close=")">
-			#{item}
-		</foreach>
-		<if test="query.settleNoteIds != null and query.settleNoteIds.size()>0">
-			AND t.id NOT IN
-			<foreach item="item" index="index" collection="query.settleNoteIds" open="(" separator="," close=")">
-				#{item}
-			</foreach>
-		</if>
-		GROUP BY t.user_id
-	</select>
-	<select id="getYaoyiAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
-		SELECT
-		t.id_card_number,
-		sum(t.settle_amount) AS totalAmount
-		FROM wm_score_package_settle_note t
-		WHERE t.create_time &gt; #{query.startTime,jdbcType=TIMESTAMP}
-		AND t.create_time &lt; #{query.endTime,jdbcType=TIMESTAMP}
-		AND t.id_card_number IN
-		<foreach item="item" index="index" collection="query.idCards" open="(" separator="," close=")">
-			#{item}
-		</foreach>
-		<if test="query.settleNoteIds != null and query.settleNoteIds.size()>0">
-			AND t.id NOT IN
-			<foreach item="item" index="index" collection="query.settleNoteIds" open="(" separator="," close=")">
-				#{item}
-			</foreach>
-		</if>
-		GROUP BY t.id_card_number
-	</select>
+    <select id="getDeptAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
+        SELECT
+        t.user_id,
+        sum(t.settle_amount) AS totalAmount
+        FROM wm_score_package_settle_note t
+        WHERE t.subject_location = #{query.location, jdbcType=VARCHAR}
+        AND (t.settle_note_status IN ('2', '9', '0')
+        OR (t.settle_note_status = '3' AND (t.sub_to_gig_time BETWEEN #{query.startTime,jdbcType=TIMESTAMP} AND
+        #{query.endTime,jdbcType=TIMESTAMP})))
+        AND t.user_id IN
+        <foreach item="item" index="index" collection="query.userIds" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        <if test="query.settleNoteIds != null and query.settleNoteIds.size()>0">
+            AND t.id NOT IN
+            <foreach item="item" index="index" collection="query.settleNoteIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY t.user_id
+    </select>
 
-	<select id="listSysEnterpriseServiceCharge" resultMap="serviceChargeMap">
-		SELECT ds.dept_id AS `ent_id`,
-			   ds.subject_location ,
-			   ds.service_charge
-		FROM  sys_dept_sub ds
-		WHERE ds.dept_id = #{deptId}
-	</select>
+	<!--
+	  * "1", "结算成功",
+     * "2", "结算失败",
+     * "3", "已提交",
+     * "9", "待结算"
+    平台限额
+	-->
+    <select id="getYaoyiAmountMonitor" resultType="com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput">
+        SELECT
+        t.id_card_number,
+        sum(t.settle_amount) AS totalAmount
+        FROM wm_score_package_settle_note t
+        WHERE
+        (t.settle_note_status IN ('2', '9', '0')
+        OR (t.settle_note_status = '3' AND (t.sub_to_gig_time BETWEEN #{query.startTime,jdbcType=TIMESTAMP} AND
+        #{query.endTime,jdbcType=TIMESTAMP})))
+        AND t.id_card_number IN
+        <foreach item="item" index="index" collection="query.idCards" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        <if test="query.settleNoteIds != null and query.settleNoteIds.size()>0">
+            AND t.id NOT IN
+            <foreach item="item" index="index" collection="query.settleNoteIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        GROUP BY t.id_card_number
+    </select>
+
+    <select id="listSysEnterpriseServiceCharge" resultMap="serviceChargeMap">
+        SELECT ds.dept_id AS `ent_id`,
+               ds.subject_location,
+               ds.service_charge
+        FROM sys_dept_sub ds
+        WHERE ds.dept_id = #{deptId}
+    </select>
 
 </mapper>