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