fix: 分润,讨论后,发现问题统一修复。
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.limap.common.core.domain.entity.SysUser;
|
||||
import com.limap.common.core.domain.entity.SysRole;
|
||||
import com.limap.common.utils.StringUtils;
|
||||
import com.limap.core.basic.service.IBasicUserWithdrawService;
|
||||
@@ -40,6 +41,10 @@ import com.limap.core.basic.vo.SharingRecordSearchVo;
|
||||
@RestController
|
||||
@RequestMapping("/basic/sharingRecord")
|
||||
public class BasicProfitSharingRecordController extends BaseController {
|
||||
private static final String DATA_SCOPE_ALL = "1";
|
||||
private static final String DATA_SCOPE_DEPT = "3";
|
||||
private static final String DATA_SCOPE_DEPT_AND_CHILD = "4";
|
||||
|
||||
@Autowired
|
||||
private IBasicProfitSharingRecordService basicProfitSharingRecordService;
|
||||
@Autowired
|
||||
@@ -53,10 +58,7 @@ public class BasicProfitSharingRecordController extends BaseController {
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(BasicProfitSharingRecord basicProfitSharingRecord) {
|
||||
startPage();
|
||||
List<SysRole> roles = getLoginUser().getUser().getRoles();
|
||||
if(roles.stream().noneMatch(role -> role.getRoleId().compareTo(100L) <0)){
|
||||
basicProfitSharingRecord.setUserId(getUserId());
|
||||
}
|
||||
applySharingRecordDataScope(basicProfitSharingRecord);
|
||||
List<BasicProfitSharingRecord> list = basicProfitSharingRecordService.selectBasicProfitSharingRecordList(basicProfitSharingRecord);
|
||||
return getDataTable(list);
|
||||
}
|
||||
@@ -66,12 +68,7 @@ public class BasicProfitSharingRecordController extends BaseController {
|
||||
@PreAuthorize("@ss.hasPermi('basic:sharingRecord:list')")
|
||||
@GetMapping("/report")
|
||||
public AjaxResult reportData(SharingRecordSearchVo searchVo) {
|
||||
List<SysRole> roles = getLoginUser().getUser().getRoles();
|
||||
if(roles.stream().noneMatch(role -> role.getRoleId().compareTo(100L) >=0)){
|
||||
searchVo.setUserId(getUserId());
|
||||
}else{
|
||||
searchVo.setDeptId(getDeptId());
|
||||
}
|
||||
applySharingRecordDataScope(searchVo);
|
||||
Map<String, Object> resultMap = basicProfitSharingRecordService.getReportData(searchVo);
|
||||
return success(resultMap);
|
||||
}
|
||||
@@ -84,6 +81,7 @@ public class BasicProfitSharingRecordController extends BaseController {
|
||||
@Log(title = "分润记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, BasicProfitSharingRecord basicProfitSharingRecord) {
|
||||
applySharingRecordDataScope(basicProfitSharingRecord);
|
||||
List<BasicProfitSharingRecord> list = basicProfitSharingRecordService.selectBasicProfitSharingRecordList(basicProfitSharingRecord);
|
||||
ExcelUtil<BasicProfitSharingRecord> util = new ExcelUtil<BasicProfitSharingRecord>(BasicProfitSharingRecord.class);
|
||||
util.exportExcel(response, list, "分润记录数据");
|
||||
@@ -149,4 +147,40 @@ public class BasicProfitSharingRecordController extends BaseController {
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(basicProfitSharingRecordService.removeByIds(Arrays.asList(ids)));
|
||||
}
|
||||
|
||||
private void applySharingRecordDataScope(BasicProfitSharingRecord record) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (user == null || user.isAdmin() || hasDataScope(user.getRoles(), DATA_SCOPE_ALL)) {
|
||||
return;
|
||||
}
|
||||
if (hasDataScope(user.getRoles(), DATA_SCOPE_DEPT_AND_CHILD)) {
|
||||
record.getParams().put("scopeType", "deptAndChild");
|
||||
record.getParams().put("scopeDeptId", getDeptId());
|
||||
} else if (hasDataScope(user.getRoles(), DATA_SCOPE_DEPT)) {
|
||||
record.getParams().put("scopeType", "dept");
|
||||
record.getParams().put("scopeDeptId", getDeptId());
|
||||
} else {
|
||||
record.setUserId(getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
private void applySharingRecordDataScope(SharingRecordSearchVo searchVo) {
|
||||
SysUser user = getLoginUser().getUser();
|
||||
if (user == null || user.isAdmin() || hasDataScope(user.getRoles(), DATA_SCOPE_ALL)) {
|
||||
return;
|
||||
}
|
||||
if (hasDataScope(user.getRoles(), DATA_SCOPE_DEPT_AND_CHILD)) {
|
||||
searchVo.setDeptId(getDeptId());
|
||||
searchVo.getParams().put("scopeType", "deptAndChild");
|
||||
} else if (hasDataScope(user.getRoles(), DATA_SCOPE_DEPT)) {
|
||||
searchVo.setDeptId(getDeptId());
|
||||
searchVo.getParams().put("scopeType", "dept");
|
||||
} else {
|
||||
searchVo.setUserId(getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasDataScope(List<SysRole> roles, String dataScope) {
|
||||
return roles != null && roles.stream().anyMatch(role -> dataScope.equals(role.getDataScope()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,16 @@ public class BasicProfitSharingRecordServiceImpl extends ServiceImpl<BasicProfit
|
||||
}
|
||||
// 兼容前端params[beginTime]/params[endTime]传参方式
|
||||
Map<String, Object> params = basicProfitSharingRecord.getParams();
|
||||
String scopeType = (String) params.get("scopeType");
|
||||
Long scopeDeptId = (Long) params.get("scopeDeptId");
|
||||
if (StringUtils.isNotNull(scopeDeptId)) {
|
||||
if ("deptAndChild".equals(scopeType)) {
|
||||
queryWrapper.inSql(BasicProfitSharingRecord::getDeptId,
|
||||
"SELECT dept_id FROM sys_dept WHERE dept_id = " + scopeDeptId + " OR find_in_set(" + scopeDeptId + ", ancestors)");
|
||||
} else if ("dept".equals(scopeType)) {
|
||||
queryWrapper.eq(BasicProfitSharingRecord::getDeptId, scopeDeptId);
|
||||
}
|
||||
}
|
||||
String beginTime = (String) params.get("beginTime");
|
||||
String endTime = (String) params.get("endTime");
|
||||
if (StringUtils.isNotEmpty(beginTime) && StringUtils.isNotEmpty(endTime)) {
|
||||
|
||||
@@ -21,22 +21,28 @@
|
||||
|
||||
|
||||
<select id="selectInfoByHour" 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 >= now() - interval '${hour} hour'
|
||||
AND create_time <= now() - interval '1 hour'
|
||||
AND (profit_status IS NULL OR profit_status = 0)
|
||||
AND pay_type = 1
|
||||
select apd.id, apd.user_id, apd.pay_amount, apd.pay_type, apd.create_time as "createdTime",
|
||||
apd.device_type, apd.serial_num, apd.order_id, apd.profit_status
|
||||
from aqu_pay_device apd
|
||||
inner join aqu_pay_order apo on apo.id = apd.order_id
|
||||
where apd.create_time >= now() - interval '${hour} hour'
|
||||
AND apd.create_time <= now() - interval '1 hour'
|
||||
AND (apd.profit_status IS NULL OR apd.profit_status = 0)
|
||||
AND apd.pay_type = 1
|
||||
AND apd.pay_amount > 0
|
||||
AND apo.order_status = 2
|
||||
</select>
|
||||
|
||||
<!-- 补录用: 查询指定时间范围内所有订单(忽略profit_status) -->
|
||||
<!-- 补录用: 查询指定时间范围内支付成功订单(忽略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 >= now() - interval '${hour} hour'
|
||||
AND create_time <= now() - interval '1 hour'
|
||||
AND pay_type = 1
|
||||
select apd.id, apd.user_id, apd.pay_amount, apd.pay_type, apd.create_time as "createdTime",
|
||||
apd.device_type, apd.serial_num, apd.order_id, apd.profit_status
|
||||
from aqu_pay_device apd
|
||||
inner join aqu_pay_order apo on apo.id = apd.order_id
|
||||
where apd.create_time >= now() - interval '${hour} hour'
|
||||
AND apd.create_time <= now() - interval '1 hour'
|
||||
AND apd.pay_type = 1
|
||||
AND apd.pay_amount > 0
|
||||
AND apo.order_status = 2
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="deptId != null">
|
||||
<if test="deptId != null and params.scopeType == 'dept'">
|
||||
and dept_id = #{deptId}
|
||||
</if>
|
||||
<if test="deptId != null and (params.scopeType == null or params.scopeType == 'deptAndChild')">
|
||||
and dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = #{deptId} or find_in_set( #{deptId} , ancestors ))
|
||||
</if>
|
||||
</where>
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
FROM basic_profit_sharing_user bpsu
|
||||
LEFT JOIN sys_user su ON bpsu.user_id = su.user_id
|
||||
LEFT JOIN basic_user_bind_info bibi ON bpsu.user_id = bibi.user_id
|
||||
WHERE bibi.device_name IS NOT NULL
|
||||
</select>
|
||||
|
||||
<!-- 查询缓存用的分润用户列表 -->
|
||||
|
||||
@@ -304,7 +304,7 @@ public class ProfitTask {
|
||||
|
||||
Map<String, List<SharingUserTaskVo>> result = new HashMap<>();
|
||||
collect.forEach((k, v) -> {
|
||||
List<SharingUserTaskVo> distinctList = v.stream().distinct().collect(Collectors.toList());
|
||||
List<SharingUserTaskVo> distinctList = distinctByUserId(v);
|
||||
List<SharingUserTaskVo> newList = new ArrayList<>();
|
||||
for (SharingUserTaskVo e : distinctList) {
|
||||
if (e != null && e.getParentId() != null) {
|
||||
@@ -313,7 +313,7 @@ public class ProfitTask {
|
||||
newList.add(e);
|
||||
}
|
||||
}
|
||||
result.put(k, newList.stream().distinct().collect(Collectors.toList()));
|
||||
result.put(k, distinctByUserId(newList));
|
||||
});
|
||||
|
||||
return result;
|
||||
@@ -325,8 +325,8 @@ public class ProfitTask {
|
||||
|
||||
// 预处理数据,提高查找效率
|
||||
Map<Long, SharingUserTaskVo> userTaskMap = sharingUserTaskVos.stream()
|
||||
.filter(f -> f != null && f.getDeptId() != null)
|
||||
.collect(Collectors.toMap(SharingUserTaskVo::getDeptId, f -> f, (existing, replacement) -> existing));
|
||||
.filter(f -> f != null && f.getUserId() != null)
|
||||
.collect(Collectors.toMap(SharingUserTaskVo::getUserId, f -> f, (existing, replacement) -> existing));
|
||||
|
||||
Set<Long> visited = new HashSet<>(); // 防止循环引用导致的无限循环
|
||||
|
||||
@@ -354,4 +354,19 @@ public class ProfitTask {
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private List<SharingUserTaskVo> distinctByUserId(List<SharingUserTaskVo> list) {
|
||||
Map<Long, SharingUserTaskVo> map = new LinkedHashMap<>();
|
||||
for (SharingUserTaskVo item : list) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
Long userId = item.getUserId();
|
||||
if (userId == null) {
|
||||
continue;
|
||||
}
|
||||
map.putIfAbsent(userId, item);
|
||||
}
|
||||
return new ArrayList<>(map.values());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user