运营区修改运营商后,需要判断合伙人的分成是否正确

This commit is contained in:
磷叶 2025-04-29 10:20:35 +08:00
parent 655fb876c2
commit 57d5d570f7
9 changed files with 121 additions and 23 deletions

View File

@ -162,4 +162,15 @@ public class MathUtils {
}
return equals(a.setScale(precision, BigDecimal.ROUND_HALF_UP), b.setScale(precision, BigDecimal.ROUND_HALF_UP));
}
// 获取最大值
public static BigDecimal max(BigDecimal a, BigDecimal b) {
if (a == null) {
a = BigDecimal.ZERO;
}
if (b == null) {
b = BigDecimal.ZERO;
}
return a.max(b);
}
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.bst.area.domain;
import java.math.BigDecimal;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -13,6 +15,8 @@ public class AreaVO extends Area {
private String userName;
@ApiModelProperty("用户手机号")
private String userPhone;
@ApiModelProperty("运营商分成比例")
private BigDecimal userPoint;
@ApiModelProperty("创建人名称")
private String createName;

View File

@ -51,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.nick_name as user_name,
su.agent_id as agent_id,
su.user_name as user_phone,
su.point as user_point,
suc.nick_name as create_name
from <include refid="searchTables"/>
</sql>

View File

@ -55,4 +55,10 @@ public interface AreaValidator {
* @return
*/
boolean canAddCustomerService(Long areaId);
/**
* 校验运营区分成
* @param id 运营区ID
*/
void checkPoint(Long id);
}

View File

@ -20,6 +20,7 @@ import com.ruoyi.bst.area.domain.vo.LocationAreaVO;
import com.ruoyi.bst.area.mapper.AreaMapper;
import com.ruoyi.bst.area.service.AreaDashboard;
import com.ruoyi.bst.area.service.AreaService;
import com.ruoyi.bst.area.service.AreaValidator;
import com.ruoyi.bst.area.utils.AreaUtil;
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.areaSub.domain.AreaSubVO;
@ -57,6 +58,9 @@ public class AreaServiceImpl implements AreaService
@Autowired
private AreaDashboard areaDashboard;
@Autowired
private AreaValidator areaValidator;
/**
* 查询运营区
*
@ -150,7 +154,18 @@ public class AreaServiceImpl implements AreaService
Geometry geometry = GeoUtils.toGeometry(area.getBoundaryStr());
area.setBoundary(GeoUtils.wkt(geometry));
}
return areaMapper.updateArea(area);
Integer result = transactionTemplate.execute(status -> {
int rows = areaMapper.updateArea(area);
// 若修改运营商ID则校验运营商的分成
if (area.getUserId() != null) {
areaValidator.checkPoint(area.getId());
}
return rows;
});
return result == null ? 0 : result;
}
/**

View File

@ -1,5 +1,6 @@
package com.ruoyi.bst.area.service.impl;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@ -14,7 +15,9 @@ import com.ruoyi.bst.area.mapper.AreaMapper;
import com.ruoyi.bst.area.service.AreaService;
import com.ruoyi.bst.area.service.AreaValidator;
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinPermission;
import com.ruoyi.bst.areaJoin.service.AreaJoinDashboard;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
@Service
@ -26,6 +29,9 @@ public class AreaValidatorImpl implements AreaValidator {
@Autowired
private AreaService areaService;
@Autowired
private AreaJoinDashboard areaJoinDashboard;
@Override
public boolean canEdit(Long areaId) {
@ -88,5 +94,15 @@ public class AreaValidatorImpl implements AreaValidator {
}
@Override
public void checkPoint(Long id) {
AreaVO area = areaService.selectAreaById(id, true);
ServiceUtil.assertion(area == null, "ID为%s的运营区不存在", id);
BigDecimal maxPoint = areaJoinDashboard.selectMaxOfAreaPoint(id);
ServiceUtil.assertion(maxPoint.compareTo(area.getUserPoint()) > 0,
"运营区【%s】无法设置运营商【%s】,当前运营区已分配最大分成为【%s%%】,超出运营商分成比例【%s%%】",
area.getName(), area.getUserName(), maxPoint, area.getUserPoint());
}
}

View File

@ -29,6 +29,23 @@ public interface AreaJoinDashboard {
* 查询分成总和
*/
BigDecimal selectSumOfPoint(@Param("query") AreaJoinQuery query);
/**
* 查询剩余可分配金额
* @param excludeId 排除ID
* @param areaId 运营区ID
* @param type 类型
* @param totalPoint 总分成
* @return
*/
BigDecimal selectRemainPoint(Long excludeId, Long areaId, String type, BigDecimal totalPoint);
/**
* 查询运营区最大分成比例
* 合伙人加算加盟商取最大值
* @param areaId 运营区ID
* @return
*/
BigDecimal selectMaxOfAreaPoint(Long areaId);
}

View File

@ -12,6 +12,7 @@ import com.ruoyi.bst.areaJoin.domain.vo.AreaJoinStatVO;
import com.ruoyi.bst.areaJoin.mapper.AreaJoinMapper;
import com.ruoyi.bst.areaJoin.service.AreaJoinDashboard;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.dashboard.constants.StatKeys;
@ -57,4 +58,48 @@ public class AreaJoinDashboardImpl implements AreaJoinDashboard {
public BigDecimal selectSumOfPoint(AreaJoinQuery query) {
return areaJoinMapper.selectSumOfPoint(query);
}
@Override
public BigDecimal selectRemainPoint(Long excludeId, Long areaId, String type, BigDecimal totalPoint) {
if (areaId == null || StringUtils.isBlank(type)) {
return BigDecimal.ZERO;
}
if (totalPoint == null) {
totalPoint = BigDecimal.ZERO;
}
// 合伙人查询当前运营区所有合伙人之和
if (AreaJoinType.PARTNER.getCode().equals(type)) {
AreaJoinQuery query = new AreaJoinQuery();
query.setAreaId(areaId);
query.setType(AreaJoinType.PARTNER.getCode());
query.setExcludeId(excludeId);
return MathUtils.subtractDecimal(totalPoint, areaJoinMapper.selectSumOfPoint(query));
}
// 加盟商直接返回运营商的分成比例
else if (AreaJoinType.JOIN.getCode().equals(type)) {
return totalPoint;
}
return BigDecimal.ZERO;
}
@Override
public BigDecimal selectMaxOfAreaPoint(Long areaId) {
if (areaId == null) {
return BigDecimal.ZERO;
}
// 查询合伙人
AreaJoinQuery query = new AreaJoinQuery();
query.setAreaId(areaId);
query.setType(AreaJoinType.PARTNER.getCode());
BigDecimal partnerPoint = areaJoinMapper.selectSumOfPoint(query);
// 查询加盟商
query.setType(AreaJoinType.JOIN.getCode());
BigDecimal joinPoint = areaJoinMapper.selectMaxOfPoint(query);
// 合伙人加算加盟商取最大值
return MathUtils.max(partnerPoint, joinPoint);
}
}

View File

@ -10,13 +10,12 @@ import org.springframework.stereotype.Service;
import com.ruoyi.bst.areaJoin.domain.AreaJoinQuery;
import com.ruoyi.bst.areaJoin.domain.AreaJoinVO;
import com.ruoyi.bst.areaJoin.domain.enums.AreaJoinType;
import com.ruoyi.bst.areaJoin.mapper.AreaJoinMapper;
import com.ruoyi.bst.areaJoin.service.AreaJoinDashboard;
import com.ruoyi.bst.areaJoin.service.AreaJoinValidator;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
@Service
@ -25,6 +24,9 @@ public class AreaJoinValidatorImpl implements AreaJoinValidator {
@Autowired
private AreaJoinMapper areaJoinMapper;
@Autowired
private AreaJoinDashboard areaJoinDashboard;
@Override
public boolean canEdit(Long id) {
return canView(Collections.singletonList(id));
@ -53,7 +55,7 @@ public class AreaJoinValidatorImpl implements AreaJoinValidator {
ServiceUtil.assertion(vo == null, "ID为%s的加盟数据不存在", id);
// 查询剩余可分配比例
BigDecimal remainPoint = this.selectRemainPoint(vo.getId(), vo.getAreaId(), vo.getType(), vo.getMchPoint());
BigDecimal remainPoint = areaJoinDashboard.selectRemainPoint(vo.getId(), vo.getAreaId(), vo.getType(), vo.getMchPoint());
// 判断分成比例是否高于剩余可分配比例
if (MathUtils.biggerThan(vo.getPoint(), remainPoint)) {
@ -64,25 +66,6 @@ public class AreaJoinValidatorImpl implements AreaJoinValidator {
this.checkRepeat(vo);
}
private BigDecimal selectRemainPoint(Long excludeId, Long areaId, String type, BigDecimal mchPoint) {
if (areaId == null || StringUtils.isBlank(type)) {
return BigDecimal.ZERO;
}
// 合伙人查询当前运营区所有合伙人之和
if (AreaJoinType.PARTNER.getCode().equals(type)) {
AreaJoinQuery query = new AreaJoinQuery();
query.setAreaId(areaId);
query.setType(AreaJoinType.PARTNER.getCode());
query.setExcludeId(excludeId);
return MathUtils.subtractDecimal(mchPoint, areaJoinMapper.selectSumOfPoint(query));
}
// 加盟商直接返回运营商的分成比例
else if (AreaJoinType.JOIN.getCode().equals(type)) {
return mchPoint;
}
return BigDecimal.ZERO;
}
private void checkRepeat(AreaJoinVO vo) {
if (vo == null || vo.getUserId() == null || vo.getAreaId() == null) {
return;