Commit bbe05248 by 张富康

Merge remote-tracking branch 'origin/v5.6.0' into v5.6.0

2 parents 33f38c47 c28b0310
......@@ -10,7 +10,7 @@ import java.math.BigDecimal;
*/
@AllArgsConstructor
@Getter
public enum CommissionMethodEnum {
public enum CommissionTypeEnum {
BL("BL", "比例", BigDecimal.ZERO, BigDecimal.valueOf(100)),
XS("XS", "系数", BigDecimal.ONE, BigDecimal.valueOf(10)),
GDJE("GDJE", "固定金额", BigDecimal.ZERO, BigDecimal.valueOf(9999999));
......@@ -20,8 +20,8 @@ public enum CommissionMethodEnum {
private final BigDecimal min;
private final BigDecimal max;
public static CommissionMethodEnum getByCode(String code) {
for (CommissionMethodEnum value : values()) {
public static CommissionTypeEnum getByCode(String code) {
for (CommissionTypeEnum value : values()) {
if (value.getCode().equals(code)) {
return value;
}
......@@ -31,10 +31,10 @@ public enum CommissionMethodEnum {
// 检测区间
public static boolean check(String code, BigDecimal value) {
CommissionMethodEnum commissionMethodEnum = getByCode(code);
if (commissionMethodEnum == null) {
CommissionTypeEnum commissionTypeEnum = getByCode(code);
if (commissionTypeEnum == null) {
return false;
}
return value.doubleValue() >= commissionMethodEnum.getMin().doubleValue() && value.doubleValue() <= commissionMethodEnum.getMax().doubleValue();
return value.doubleValue() >= commissionTypeEnum.getMin().doubleValue() && value.doubleValue() <= commissionTypeEnum.getMax().doubleValue();
}
}
\ No newline at end of file
......@@ -3,22 +3,31 @@ package cn.com.glsx.dj.staff.enums;
/**
* 商品配置类型枚举
*/
public enum ProductConfigTypeEnum implements BaseEnum<Integer, String> {
ALL_PRODUCT(-1, "全部商品"),
PRODUCT_CATEGORY(0, "商品分类"),
DESIGNATED_PRODUCT(1, "圈定产品"),
DESIGNATED_PACKAGE(2, "圈定套餐");
public enum GoodsConfigTypeEnum implements BaseEnum<Byte, String> {
ALL_PRODUCT((byte) -1, "全部商品"),
PRODUCT_CATEGORY((byte) 0, "商品分类"),
DESIGNATED_PRODUCT((byte) 1, "圈定产品"),
DESIGNATED_PACKAGE((byte) 2, "圈定套餐");
private final Integer code;
private final Byte code;
private final String desc;
ProductConfigTypeEnum(Integer code, String desc) {
GoodsConfigTypeEnum(Byte code, String desc) {
this.code = code;
this.desc = desc;
}
public static GoodsConfigTypeEnum getByCode(Byte goodsConfigType) {
for (GoodsConfigTypeEnum type : GoodsConfigTypeEnum.values()) {
if (type.getCode().equals(goodsConfigType)) {
return type;
}
}
return null;
}
@Override
public Integer getCode() {
public Byte getCode() {
return code;
}
......
package cn.com.glsx.dj.staff.enums;
/**
* 绩效参数配置条件类型枚举
*/
public enum PerformanceConditionTypeEnum implements BaseEnum<Byte, String> {
PENETRATION_RATE_LIMIT((byte) 1, "渗透率限制"),
ORDER_COUNT_DEDUCTION((byte) 2, "订单数不足扣减"),
TARGET_ACHIEVEMENT_REWARD((byte) 3, "整体指标达成奖励"),
ORDER_EXCLUSION_INCLUSION((byte) 4, "订单数剔除/包含");
private final Byte code;
private final String desc;
PerformanceConditionTypeEnum(Byte code, String desc) {
this.code = code;
this.desc = desc;
}
public static PerformanceConditionTypeEnum getByCode(Number code) {
if (code == null) {
return null;
}
for (PerformanceConditionTypeEnum type : PerformanceConditionTypeEnum.values()) {
if (type.getCode().equals(code.intValue())) {
return type;
}
}
return null;
}
@Override
public Byte getCode() {
return code;
}
@Override
public String getDesc() {
return desc;
}
}
......@@ -34,13 +34,13 @@ public class PerformanceParamConfigCondition implements Serializable {
@Column(name = "performance_param_config_id")
private Integer performanceParamConfigId;
@ApiModelProperty(notes = "条件类型(1:渗透率限制,2.订单数不足扣减,3.整体指标达成奖励,4.订单数剔除/包含)")
@ApiModelProperty(notes = "条件类型(1:渗透率限制,2.订单数不足扣减,3.整体指标达成奖励,4.订单数剔除/包含), 详见PerformanceConditionTypeEnum")
@Column(name = "condition_type")
private Integer conditionType;
private Byte conditionType;
@ApiModelProperty(notes = "条件商品配置类型(-1:全部商品,0:商品分类,1:圈定产品,2圈定套餐)")
@ApiModelProperty(notes = "条件商品配置类型(-1:全部商品,0:商品分类,1:圈定产品,2圈定套餐), 详见ProductConfigTypeEnum")
@Column(name = "condition_goods_config_type")
private Integer conditionGoodsConfigType;
private Byte conditionGoodsConfigType;
@ApiModelProperty(notes = "条件商品分类(一级)")
@Column(name = "condition_goods_type")
......
......@@ -19,5 +19,5 @@ public interface StaffProductPerformanceMapper extends OreMapper<StaffProductPer
@Param("staffPhone") String staffPhone,
@Param("updatedBy") String updatedBy);
List<StaffProductPerformanceDTO> listStaffPerformance(@Param("dto") StaffProductPerformanceDTO dto);
List<StaffProductPerformanceDTO> listStaffPerformance(StaffProductPerformanceDTO dto);
}
\ No newline at end of file
......@@ -50,9 +50,9 @@ public class StaffPerformanceDetailService {
return;
}
// 1. 调用mapper,通过update更新相同merchantId businessType brandId childBrandId
// performanceMonth的记录的deletedFlag = 'D'
// 1. 逻辑删除旧数据
StaffPerformanceDetail query = StaffPerformanceDetail.builder()
.staffPhone(performanceDetailDTOS.get(0).getStaffPhone())
.merchantId(config.getMerchantId())
.businessType(config.getBusinessType())
.brandId(config.getBrandId())
......
......@@ -5,7 +5,7 @@ import cn.com.glsx.dj.staff.dto.StaffPerformanceCalContextDTO;
import cn.com.glsx.dj.staff.dto.StaffPerformanceDetailDTO;
import cn.com.glsx.dj.staff.dto.StaffProductPerformanceDTO;
import cn.com.glsx.dj.staff.dto.performance.StaffPerformanceDTO;
import cn.com.glsx.dj.staff.enums.CommissionMethodEnum;
import cn.com.glsx.dj.staff.enums.CommissionTypeEnum;
import cn.com.glsx.dj.staff.mapper.StaffPerformanceMapper;
import cn.com.glsx.dj.staff.model.StaffBeisenBaseInfo;
import cn.com.glsx.dj.staff.model.StaffPerformance;
......@@ -52,43 +52,31 @@ public class StaffPerformanceService {
log.error("输入数据无效: context 为空或 performanceDetailDTOS 为空");
return;
}
// 1. 根据 merchantId, businessType, brandId, childBrandId 分组
Map<String, List<StaffPerformanceDetailDTO>> groupedMap = groupPerformanceDetails(performanceDetailDTOS);
String staffPhone = context.getStaffPhone();
Integer merchantId = context.getMerchantId();
Byte businessType = context.getBusinessType();
Integer brandId = context.getBrandId();
Integer childBrandId = context.getChildBrandId();
String performanceMonth = context.getPerformanceMonth();
if (merchantId == null || businessType == null || brandId == null || childBrandId == null
|| StringUtils.isBlank(performanceMonth) || StringUtils.isBlank(staffPhone)) {
log.error(
"输入数据无效: merchantId={}, businessType={}, brandId={}, childBrandId={}, performanceMonth={}, staffPhone={}",
merchantId, businessType, brandId, childBrandId, performanceMonth, staffPhone);
return;
}
// 2. 检查是否处于新人保护期
boolean isNewcomerProtection = checkNewcomerProtection(context.getStaffPhone(), context.getPerformanceMonth());
List<StaffPerformance> insertList = new ArrayList<>();
Date now = new Date();
for (List<StaffPerformanceDetailDTO> groupList : groupedMap.values()) {
if (CollectionUtils.isEmpty(groupList)) {
continue;
}
// 3. 构建 StaffPerformance
StaffPerformance staffPerformance = buildStaffPerformance(groupList, context, isNewcomerProtection, now);
insertList.add(staffPerformance);
// 3. 构建 StaffPerformance
StaffPerformance staffPerformance = buildStaffPerformance(performanceDetailDTOS, context, isNewcomerProtection);
// 4. 逻辑删除旧数据
staffPerformanceMapper.removeStaffPerformance(staffPerformance);
}
// 5. 批量插入新数据
if (CollectionUtils.isNotEmpty(insertList)) {
staffPerformanceMapper.insertList(insertList);
}
}
// 4. 逻辑删除旧数据
staffPerformanceMapper.removeStaffPerformance(staffPerformance);
/**
* 对详情数据进行分组
*/
private Map<String, List<StaffPerformanceDetailDTO>> groupPerformanceDetails(
List<StaffPerformanceDetailDTO> details) {
return details.stream()
.collect(Collectors.groupingBy(dto -> dto.getMerchantId() + "_" + dto.getBusinessType()
+ "_" + dto.getBrandId() + "_" + dto.getChildBrandId()));
// 5. 插入新数据
staffPerformanceMapper.insertSelective(staffPerformance);
}
/**
......@@ -136,8 +124,7 @@ public class StaffPerformanceService {
*/
private StaffPerformance buildStaffPerformance(List<StaffPerformanceDetailDTO> groupList,
StaffPerformanceCalContextDTO context,
boolean isNewcomerProtection,
Date now) {
boolean isNewcomerProtection) {
StaffPerformanceDetailDTO first = groupList.get(0);
StaffPerformance staffPerformance = new StaffPerformance();
......@@ -153,6 +140,7 @@ public class StaffPerformanceService {
staffPerformance.setChildBrandName(first.getChildBrandName());
staffPerformance.setMonth(first.getMonth());
Date now = new Date();
staffPerformance.setCreatedBy(CommonConstants.DEFAULT_UPDATE_BY);
staffPerformance.setUpdatedBy(CommonConstants.DEFAULT_UPDATE_BY);
staffPerformance.setCreatedDate(now);
......@@ -193,7 +181,7 @@ public class StaffPerformanceService {
// 遍历详情计算
for (StaffPerformanceDetailDTO detail : groupList) {
// 判断是否为系数类型 (假设 'XS' 为系数代码)
if (CommissionMethodEnum.XS.getCode().equals(detail.getCommissionType())) {
if (CommissionTypeEnum.XS.getCode().equals(detail.getCommissionType())) {
if (detail.getCommissionTypeValue() != null) {
multiplyCoeff = multiplyCoeff.multiply(detail.getCommissionTypeValue());
}
......
......@@ -3,8 +3,9 @@ package cn.com.glsx.dj.staff.service.staffPerformance.util;
import cn.com.glsx.dj.smartcarlife.dto.merchantPerformanceConfig.MerchantPerformanceProductDefineDTO;
import cn.com.glsx.dj.smartcarlife.model.MerchantPerformanceProductDefineItem;
import cn.com.glsx.dj.staff.dto.StaffPerformanceSubOrderDTO;
import cn.com.glsx.dj.staff.enums.ProductConfigTypeEnum;
import cn.com.glsx.dj.staff.enums.GoodsConfigTypeEnum;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.core.util.RpcAssert;
import org.apache.commons.collections.CollectionUtils;
......@@ -81,37 +82,47 @@ public class StaffPerformanceOrderUtil {
* @param productDefine 圈定商品定义(含套餐)
* @return 匹配数量
*/
public static long countMatchingOrders(List<StaffPerformanceSubOrderDTO> orders,
Integer goodsConfigType,
public static Integer countMatchingOrders(List<StaffPerformanceSubOrderDTO> orders,
Byte goodsConfigType,
Integer goodsType,
Integer secondaryGoodsType,
Integer thirdLevelGoodsType,
MerchantPerformanceProductDefineDTO productDefine) {
if (CollectionUtils.isEmpty(orders) || goodsConfigType == null) {
if (CollectionUtils.isEmpty(orders)) {
return 0;
}
// 3. 根据配置类型分别处理
GoodsConfigTypeEnum configType = GoodsConfigTypeEnum.getByCode(goodsConfigType);
if (configType == null) {
throw new RpcServiceException("不支持的商品配置类型: " + goodsConfigType);
}
switch (configType) {
case DESIGNATED_PACKAGE:
RpcAssert.assertNotNull(productDefine, DefaultErrorEnum.DATA_NULL,
"conditionProductDefine be null");
RpcAssert.assertNotEmpty(productDefine.getPackageItemList(), DefaultErrorEnum.DATA_NULL,
"conditionProductDefine.getPackageItemList() is empty");
if (goodsConfigType == 2) {
RpcAssert.assertNotNull(productDefine, DefaultErrorEnum.DATA_NULL,
"conditionProductDefine be null");
RpcAssert.assertNotEmpty(productDefine.getPackageItemList(), DefaultErrorEnum.DATA_NULL,
"conditionProductDefine.getPackageItemList() is empty");
Map<String, List<StaffPerformanceSubOrderDTO>> groupedOrders = orders.stream()
.collect(Collectors.groupingBy(StaffPerformanceSubOrderDTO::getOrderCode));
return groupedOrders.values().stream()
.filter(o -> isOrderMatchPackage(o, productDefine.getPackageItemList()))
.count();
} else {
return orders.stream()
.filter(o -> isOrderMatchCategory(o,
goodsConfigType.byteValue(),
goodsType,
secondaryGoodsType,
thirdLevelGoodsType,
productDefine))
.count();
Map<String, List<StaffPerformanceSubOrderDTO>> groupedOrders = orders.stream()
.collect(Collectors.groupingBy(StaffPerformanceSubOrderDTO::getOrderCode));
return (int) groupedOrders.values().stream()
.filter(o -> isOrderMatchPackage(o, productDefine.getPackageItemList()))
.count();
case ALL_PRODUCT:
case PRODUCT_CATEGORY:
case DESIGNATED_PRODUCT:
return (int) orders.stream()
.filter(o -> isOrderMatchCategory(o,
goodsConfigType,
goodsType,
secondaryGoodsType,
thirdLevelGoodsType,
productDefine))
.count();
default:
throw new RpcServiceException("不支持的商品配置类型: " + goodsConfigType);
}
}
/**
......@@ -134,12 +145,12 @@ public class StaffPerformanceOrderUtil {
RpcAssert.assertNotNull(goodsConfigType, DefaultErrorEnum.DATA_NULL, "goodsConfigType不能为空");
// TODO 改用枚举
// -1:全部商品
if (Objects.equals(ProductConfigTypeEnum.ALL_PRODUCT.getCode(), goodsConfigType)) {
if (Objects.equals(GoodsConfigTypeEnum.ALL_PRODUCT.getCode(), goodsConfigType)) {
return true;
}
// 0:商品分类
if (Objects.equals(ProductConfigTypeEnum.PRODUCT_CATEGORY.getCode(), goodsConfigType)) {
if (Objects.equals(GoodsConfigTypeEnum.PRODUCT_CATEGORY.getCode(), goodsConfigType)) {
boolean match = true;
if (goodsType != null) {
match = match && Objects.equals(goodsType, order.getGoodsType());
......@@ -154,7 +165,7 @@ public class StaffPerformanceOrderUtil {
}
// 1:圈定产品
if (Objects.equals(ProductConfigTypeEnum.DESIGNATED_PRODUCT.getCode(), goodsConfigType)) {
if (Objects.equals(GoodsConfigTypeEnum.DESIGNATED_PRODUCT.getCode(), goodsConfigType)) {
RpcAssert.assertNotNull(productDefine, DefaultErrorEnum.DATA_NULL,
"productDefine不能为空");
return productDefine.getItemList().stream()
......
......@@ -6,6 +6,9 @@ import java.math.BigDecimal;
public class DataCalUtil {
public static BigDecimal divideToPercent(BigDecimal dividend, BigDecimal divisor) {
if (dividend == null || divisor == null) {
return null;
}
if (divisor.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
......@@ -14,8 +17,10 @@ public class DataCalUtil {
BigDecimal.ROUND_HALF_UP);
}
public static BigDecimal divide(BigDecimal dividend, BigDecimal divisor) {
if (dividend == null || divisor == null) {
return null;
}
if (divisor.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO;
}
......
......@@ -71,7 +71,8 @@
updated_by = #{updatedBy},
updated_date = now()
WHERE
merchant_id = #{merchantId,jdbcType=INTEGER}
staff_phone = #{staffPhone,jdbcType=VARCHAR}
AND merchant_id = #{merchantId,jdbcType=INTEGER}
AND business_type = #{businessType,jdbcType=TINYINT}
AND brand_id = #{brandId,jdbcType=INTEGER}
AND child_brand_id = #{childBrandId,jdbcType=INTEGER}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!