fix: 分润发现问题,统一修复。

This commit is contained in:
tianyongbao
2026-05-30 16:42:12 +08:00
parent 3b25ecc916
commit 771d46edbb
10 changed files with 330 additions and 50 deletions

View File

@@ -2,7 +2,10 @@ package com.limap.core.basic.domain;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.baomidou.mybatisplus.annotation.IdType;
@@ -109,4 +112,20 @@ public class BasicProfitSharingRecord {
@ApiModelProperty("查询结束时间")
@TableField(exist = false)
private Date endTime;
/** 请求参数 */
@TableField(exist = false)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> params;
public Map<String, Object> getParams() {
if (params == null) {
params = new HashMap<>();
}
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
}

View File

@@ -20,6 +20,8 @@ public interface AquPayOrderMapper extends BaseMapper<AquPayOrder> {
List<AquPayDevice> selectInfoByHour(Integer hour);
List<AquPayDevice> selectInfoForBackfill(Integer hour);
void updatePayDeviceStatus(@Param("list") List<AquPayDevice> list);
void dealRechargeWarnCode();

View File

@@ -24,6 +24,11 @@ public interface IAquPayOrderService extends IService<AquPayOrder> {
List<AquPayDevice> selectInfoByHour(Integer hour);
/**
* 补录用: 查询指定时间范围内所有订单(忽略profit_status)
*/
List<AquPayDevice> selectInfoForBackfill(Integer hour);
void updatePayDeviceStatus(List<AquPayDevice> list);
void dealRechargeWarnCode();

View File

@@ -46,6 +46,11 @@ public class AquPayOrderServiceImpl extends ServiceImpl<AquPayOrderMapper, AquPa
return aquPayOrderMapper.selectInfoByHour(hour);
}
@Override
public List<AquPayDevice> selectInfoForBackfill(Integer hour) {
return aquPayOrderMapper.selectInfoForBackfill(hour);
}
@Override
public void updatePayDeviceStatus(List<AquPayDevice> list) {
aquPayOrderMapper.updatePayDeviceStatus(list);

View File

@@ -3,9 +3,12 @@ package com.limap.core.basic.service.impl;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.limap.common.utils.DateUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -18,6 +21,7 @@ import com.limap.core.basic.service.IBasicUserWithdrawService;
import com.limap.core.basic.vo.BasicUserWithdrawVo;
import com.limap.core.basic.vo.SharingRecordSearchVo;
import com.limap.core.basic.vo.SharingUserTaskVo;
import com.baomidou.dynamic.datasource.annotation.DS;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -29,6 +33,8 @@ import com.limap.core.basic.mapper.BasicProfitSharingRecordMapper;
import com.limap.core.basic.domain.BasicProfitSharingRecord;
import com.limap.core.basic.service.IBasicProfitSharingRecordService;
import java.util.Collection;
/**
* 分润记录Service业务层处理
*
@@ -37,6 +43,7 @@ import com.limap.core.basic.service.IBasicProfitSharingRecordService;
*/
@Service
@Slf4j
@DS("master")
public class BasicProfitSharingRecordServiceImpl extends ServiceImpl<BasicProfitSharingRecordMapper, BasicProfitSharingRecord> implements IBasicProfitSharingRecordService {
@Autowired
private BasicProfitSharingRecordMapper basicProfitSharingRecordMapper;
@@ -82,16 +89,59 @@ public class BasicProfitSharingRecordServiceImpl extends ServiceImpl<BasicProfit
if (StringUtils.isNotNull(basicProfitSharingRecord.getDeviceName())) {
queryWrapper.eq(BasicProfitSharingRecord::getDeviceName, basicProfitSharingRecord.getDeviceName());
}
if (StringUtils.isNotNull(basicProfitSharingRecord.getStartTime())) {
// 兼容前端params[beginTime]/params[endTime]传参方式
Map<String, Object> params = basicProfitSharingRecord.getParams();
String beginTime = (String) params.get("beginTime");
String endTime = (String) params.get("endTime");
if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)) {
queryWrapper.ge(BasicProfitSharingRecord::getGenerateTime, beginTime + " 00:00:00");
queryWrapper.le(BasicProfitSharingRecord::getGenerateTime, endTime + " 23:59:59");
} else if (StringUtils.isNotNull(basicProfitSharingRecord.getStartTime())) {
queryWrapper.between(BasicProfitSharingRecord::getGenerateTime, basicProfitSharingRecord.getStartTime(), basicProfitSharingRecord.getEndTime());
}
if (StringUtils.isNotNull(basicProfitSharingRecord.getTel())) {
queryWrapper.like(BasicProfitSharingRecord::getTel, basicProfitSharingRecord.getTel());
}
if (StringUtils.isNotEmpty(basicProfitSharingRecord.getUserName())) {
queryWrapper.like(BasicProfitSharingRecord::getUserName, basicProfitSharingRecord.getUserName());
}
if (StringUtils.isNotEmpty(basicProfitSharingRecord.getOrderNo())) {
queryWrapper.like(BasicProfitSharingRecord::getOrderNo, basicProfitSharingRecord.getOrderNo());
}
queryWrapper.orderByDesc(BasicProfitSharingRecord::getGenerateTime);
return basicProfitSharingRecordMapper.selectList(queryWrapper);
}
/**
* 重写saveBatch解决dynamic-datasource下批量插入事务不提交的问题
* 1. saveBatch内部BATCH模式绕过@DS
* 2. @Transactional与@DS冲突导致事务不提交
* 去掉@Transactional依赖连接池autoCommit=true逐条提交
*/
@DS("master")
@Override
public boolean saveBatch(Collection<BasicProfitSharingRecord> entityList, int batchSize) {
if (entityList == null || entityList.isEmpty()) {
return false;
}
log.info("saveBatch开始, 待插入{}条记录", entityList.size());
int count = 0;
for (BasicProfitSharingRecord record : entityList) {
try {
int rows = basicProfitSharingRecordMapper.insert(record);
if (rows > 0) {
count++;
} else {
log.warn("insert返回0行, record.orderNo={}, record.userId={}", record.getOrderNo(), record.getUserId());
}
} catch (Exception e) {
log.error("insert单条异常, record.orderNo={}, error={}", record.getOrderNo(), e.getMessage());
}
}
log.info("saveBatch完成, 预期插入{}条, 实际影响行数{}条", entityList.size(), count);
return count > 0;
}
/**
* 处理分润计算
*

View File

@@ -2,6 +2,9 @@ package com.limap.core.basic.vo;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Data
public class SharingRecordSearchVo {
@@ -10,4 +13,7 @@ public class SharingRecordSearchVo {
private Long userId;
private Long deptId;
/** 请求参数(前端传 params[startDate] 等) */
private Map<String, Object> params = new HashMap<>();
}

View File

@@ -21,9 +21,22 @@
<select id="selectInfoByHour" resultType="com.limap.core.basic.domain.AquPayDevice">
select * from aqu_pay_device
select id, user_id, pay_amount, pay_type, create_time as "createdTime",
device_type, serial_num, order_id, profit_status
from aqu_pay_device
where create_time &gt;= now() - interval '${hour} hour'
AND create_time &lt;= now() - interval '1 hour'
AND (profit_status IS NULL OR profit_status = 0)
AND pay_type = 1
</select>
<!-- 补录用: 查询指定时间范围内所有订单(忽略profit_status) -->
<select id="selectInfoForBackfill" resultType="com.limap.core.basic.domain.AquPayDevice">
select id, user_id, pay_amount, pay_type, create_time as "createdTime",
device_type, serial_num, order_id, profit_status
from aqu_pay_device
where create_time &gt;= now() - interval '${hour} hour'
AND create_time &lt;= now() - interval '1 hour'
AND pay_type = 1
</select>
</mapper>

View File

@@ -12,19 +12,24 @@
SUM(CASE WHEN withdrawal_status = 1 THEN amount ELSE 0 END) AS tx
FROM basic_profit_sharing_record
<where>
<if test="startDate != null">
AND created_time &gt;= #{startDate}
<if test="params.startDate != null and params.startDate != ''">
AND generate_time &gt;= #{params.startDate}
</if>
<if test="endDate != null">
AND created_time &lt;= #{endDate}
<if test="params.endDate != null and params.endDate != ''">
AND generate_time &lt;= #{params.endDate}
</if>
<if test="startDate != null and startDate != ''">
AND generate_time &gt;= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
AND generate_time &lt;= #{endDate}
</if>
<if test="userId != null">
AND user_id = #{userId}
</if>
<if test="deptId != null">
and dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} or find_in_set( #{deptId} , ancestors ))
and dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} or find_in_set( #{deptId} , ancestors ))
</if>
</where>
</select>
</mapper>

View File

@@ -34,6 +34,6 @@
<if test="appUserTel != null and appUserTel != ''"> and app_user_tel = #{appUserTel}</if>
<if test="userName != null and userName != ''"> and user_name like CONCAT('%',#{userName},'%')</if>
</where>
order by create_time desc
</select>
</mapper>