## 加购升级报单赠送部分bug修改
This commit is contained in:
parent
0a5edf9a78
commit
e3606433a3
|
@ -147,6 +147,5 @@ public interface ISaOrderServiceApi {
|
||||||
*/
|
*/
|
||||||
List<SingleItemStatDTO> singleItemStat(SingleItemStatParamDTO singleItemStatParamDTO);
|
List<SingleItemStatDTO> singleItemStat(SingleItemStatParamDTO singleItemStatParamDTO);
|
||||||
|
|
||||||
R<?> autoPushDeclaration();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import com.hzs.common.core.web.domain.AjaxResult;
|
||||||
import com.hzs.common.security.service.UserTokenService;
|
import com.hzs.common.security.service.UserTokenService;
|
||||||
import com.hzs.common.security.utils.SecurityUtils;
|
import com.hzs.common.security.utils.SecurityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -51,7 +52,7 @@ public class AcDeclarationGiftConfigController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@Log(module = EOperationModule.AC_DECLARATION_GIFT_SAVE, business = EOperationBusiness.AC_DECLARATION_GIFT_SAVE, method = EOperationMethod.INSERT, remark = "报单赠送添加")
|
@Log(module = EOperationModule.AC_DECLARATION_GIFT_SAVE, business = EOperationBusiness.AC_DECLARATION_GIFT_SAVE, method = EOperationMethod.INSERT, remark = "报单赠送添加")
|
||||||
@PostMapping("/save")
|
@PostMapping("/save")
|
||||||
public AjaxResult declarationConfigSave(@RequestBody AcDeclarationParam acDeclarationParam) {
|
public AjaxResult declarationConfigSave(@RequestBody @Validated AcDeclarationParam acDeclarationParam) {
|
||||||
acDeclarationParam.setPkCountry(SecurityUtils.getPkCountry());
|
acDeclarationParam.setPkCountry(SecurityUtils.getPkCountry());
|
||||||
acDeclarationParam.setPkMember(SecurityUtils.getUserId());
|
acDeclarationParam.setPkMember(SecurityUtils.getUserId());
|
||||||
acDeclarationParam.setLoginUser(userTokenService.getLoginUser());
|
acDeclarationParam.setLoginUser(userTokenService.getLoginUser());
|
||||||
|
|
|
@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@ -32,6 +34,7 @@ public class AcDeclarationProductParam {
|
||||||
* 产品规格(逗号分隔)
|
* 产品规格(逗号分隔)
|
||||||
*/
|
*/
|
||||||
@Excel(name = "产品规格")
|
@Excel(name = "产品规格")
|
||||||
|
@NotNull(message = "产品规格不能为空")
|
||||||
private String specsName;
|
private String specsName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.hzs.common.core.constant.CountryConstants;
|
||||||
import com.hzs.common.core.enums.EActType;
|
import com.hzs.common.core.enums.EActType;
|
||||||
import com.hzs.common.core.enums.EApprovalBusiness;
|
import com.hzs.common.core.enums.EApprovalBusiness;
|
||||||
import com.hzs.common.core.enums.EControlType;
|
import com.hzs.common.core.enums.EControlType;
|
||||||
|
import com.hzs.common.core.enums.ERegistrationAuthority;
|
||||||
import com.hzs.common.core.utils.StringUtils;
|
import com.hzs.common.core.utils.StringUtils;
|
||||||
import com.hzs.common.core.web.domain.AjaxResult;
|
import com.hzs.common.core.web.domain.AjaxResult;
|
||||||
import com.hzs.common.domain.activity.base.AcBaseConfig;
|
import com.hzs.common.domain.activity.base.AcBaseConfig;
|
||||||
|
@ -33,6 +34,8 @@ import com.hzs.common.domain.activity.base.AcGoalMemberConfig;
|
||||||
import com.hzs.common.domain.activity.pick.AcPick;
|
import com.hzs.common.domain.activity.pick.AcPick;
|
||||||
import com.hzs.common.security.utils.SecurityUtils;
|
import com.hzs.common.security.utils.SecurityUtils;
|
||||||
import com.hzs.sale.product.service.IBdProductService;
|
import com.hzs.sale.product.service.IBdProductService;
|
||||||
|
import com.hzs.sale.wares.service.IBdWaresGradeService;
|
||||||
|
import com.hzs.system.config.IGradeServiceApi;
|
||||||
import com.hzs.system.sys.dto.LoginUser;
|
import com.hzs.system.sys.dto.LoginUser;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
@ -71,6 +74,8 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
private IAcBaseConfigService iAcBaseConfigService;
|
private IAcBaseConfigService iAcBaseConfigService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAcDeclarationGiftConfigService iAcDeclarationGiftConfigService;
|
private IAcDeclarationGiftConfigService iAcDeclarationGiftConfigService;
|
||||||
|
@Autowired
|
||||||
|
private IGradeServiceApi iGradeServiceApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult getDetail(Integer pkId) {
|
public AjaxResult getDetail(Integer pkId) {
|
||||||
|
@ -94,13 +99,14 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String saveConfig(AcDeclarationParam acDeclarationParam) {
|
public String saveConfig(AcDeclarationParam acDeclarationParam) {
|
||||||
LoginUser loginUser = acDeclarationParam.getLoginUser();
|
LoginUser loginUser = acDeclarationParam.getLoginUser();
|
||||||
if (loginUser == null) {
|
if (loginUser == null) {
|
||||||
log.error("登录用户信息为空");
|
log.error("登录用户信息为空");
|
||||||
return "登录用户信息为空";
|
return "登录用户信息为空";
|
||||||
}
|
}
|
||||||
String validated = validateDuplicateConfig(acDeclarationParam.getAcDeclarationConfigParams());
|
String validated = validateDuplicateConfig(acDeclarationParam);
|
||||||
if (validated != null) {
|
if (validated != null) {
|
||||||
return validated;
|
return validated;
|
||||||
}
|
}
|
||||||
|
@ -118,23 +124,42 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String validateDuplicateConfig(List<AcDeclarationConfigParam> acDeclarationConfigParams) {
|
private String validateDuplicateConfig(AcDeclarationParam acDeclarationParam) {
|
||||||
|
List<AcDeclarationConfigParam> acDeclarationConfigParams = acDeclarationParam.getAcDeclarationConfigParams();
|
||||||
|
|
||||||
// 获取当前时间还有效的报单赠送活动
|
// 获取当前时间还有效的报单赠送活动
|
||||||
List<AcBaseConfig> validBaseConfigs = iAcBaseConfigService.list(
|
LambdaQueryWrapper<AcBaseConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
new LambdaQueryWrapper<AcBaseConfig>()
|
queryWrapper.le(AcBaseConfig::getActStartDate, new Date())
|
||||||
.le(AcBaseConfig::getActStartDate, new Date())
|
|
||||||
.ge(AcBaseConfig::getActEndDate, new Date())
|
.ge(AcBaseConfig::getActEndDate, new Date())
|
||||||
.eq(AcBaseConfig::getActType, EActType.DECLARATION_GIFT.getValue())
|
.eq(AcBaseConfig::getActType, EActType.DECLARATION_GIFT.getValue())
|
||||||
.eq(AcBaseConfig::getDelFlag, 0)
|
.eq(AcBaseConfig::getDelFlag, 0);
|
||||||
);
|
if (acDeclarationParam.getActivityParam().getPkId() != null) {
|
||||||
|
queryWrapper.ne(AcBaseConfig::getPkId, acDeclarationParam.getActivityParam().getPkId());
|
||||||
|
}
|
||||||
|
List<AcBaseConfig> validBaseConfigs = iAcBaseConfigService.list(queryWrapper);
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(validBaseConfigs)) {
|
// 先把新增组合转换成List
|
||||||
log.info("当前没有有效的报单赠送活动,可以直接添加新配置");
|
List<String> newComboList = acDeclarationConfigParams.stream()
|
||||||
// 可以直接执行新增
|
.filter(Objects::nonNull)
|
||||||
return null;
|
.map(cfg -> ERegistrationAuthority.getEnumByValue(cfg.getRegisterAuthority()).getLabel()
|
||||||
|
+ "_" + iGradeServiceApi.getGrade(cfg.getSpecifyLevel()).getData().getGradeName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 校验新增组合内部是否有重复
|
||||||
|
Map<String, Long> newCountMap = newComboList.stream()
|
||||||
|
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
||||||
|
|
||||||
|
Set<String> internalDuplicates = newCountMap.entrySet().stream()
|
||||||
|
.filter(entry -> entry.getValue() > 1)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
if (!internalDuplicates.isEmpty()) {
|
||||||
|
return "新增活动配置内部存在重复的报单等级+指定等级组合: " + internalDuplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取报单赠送详情配置
|
// 校验新增组合是否与已有数据库组合重复
|
||||||
|
if (!CollectionUtils.isEmpty(validBaseConfigs)) {
|
||||||
List<Long> baseIds = validBaseConfigs.stream()
|
List<Long> baseIds = validBaseConfigs.stream()
|
||||||
.map(AcBaseConfig::getPkId)
|
.map(AcBaseConfig::getPkId)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -145,36 +170,33 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
.eq(AcDeclarationGiftConfig::getDelFlag, 0)
|
.eq(AcDeclarationGiftConfig::getDelFlag, 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取报单赠送报单等级和指定等级组合
|
|
||||||
Set<String> existingComboSet = existingConfigs.stream()
|
Set<String> existingComboSet = existingConfigs.stream()
|
||||||
.map(cfg -> cfg.getRegisterAuthority() + "_" + cfg.getSpecifyLevel())
|
.map(cfg -> ERegistrationAuthority.getEnumByValue(cfg.getRegisterAuthority()).getLabel()
|
||||||
|
+ "_" + iGradeServiceApi.getGrade(cfg.getSpecifyLevel()).getData().getGradeName())
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 当前配置活动数据报单等级和指定等级组合
|
Set<String> dbDuplicates = newComboList.stream()
|
||||||
Set<String> newComboSet = acDeclarationConfigParams.stream()
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.map(cfg -> cfg.getRegisterAuthority() + "_" + cfg.getSpecifyLevel())
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
// 判断是否有重复值,有重复值不允许添加
|
|
||||||
Set<String> duplicates = newComboSet.stream()
|
|
||||||
.filter(existingComboSet::contains)
|
.filter(existingComboSet::contains)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
if (!duplicates.isEmpty()) {
|
if (!dbDuplicates.isEmpty()) {
|
||||||
return "新增活动配置中存在重复的报单等级+指定等级组合: " + duplicates;
|
return "新增活动配置中存在与已有活动重复的报单等级+指定等级组合: " + dbDuplicates;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String updateConfig(AcDeclarationParam acDeclarationParam) {
|
public String updateConfig(AcDeclarationParam acDeclarationParam) {
|
||||||
LoginUser loginUser = acDeclarationParam.getLoginUser();
|
LoginUser loginUser = acDeclarationParam.getLoginUser();
|
||||||
if (loginUser == null) {
|
if (loginUser == null) {
|
||||||
log.error("登录用户信息为空");
|
log.error("登录用户信息为空");
|
||||||
return "登录用户信息为空";
|
return "登录用户信息为空";
|
||||||
}
|
}
|
||||||
String validated = validateDuplicateConfig(acDeclarationParam.getAcDeclarationConfigParams());
|
String validated = validateDuplicateConfig(acDeclarationParam);
|
||||||
if (validated != null) {
|
if (validated != null) {
|
||||||
return validated;
|
return validated;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +210,7 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String deleteConfig(Long pkId) {
|
public String deleteConfig(Long pkId) {
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
|
@ -202,7 +225,6 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void removeDeclarationConfig(Long pkId) {
|
private void removeDeclarationConfig(Long pkId) {
|
||||||
// 删除活动基本配置
|
// 删除活动基本配置
|
||||||
baseConfigService.removeById(pkId);
|
baseConfigService.removeById(pkId);
|
||||||
|
@ -267,6 +289,7 @@ public class AcDeclarationGiftConfigServiceImpl extends ServiceImpl<AcDeclaratio
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDeclarationData() {
|
public void handleDeclarationData() {
|
||||||
// 所属国家
|
// 所属国家
|
||||||
|
|
|
@ -1,12 +1,34 @@
|
||||||
package com.hzs.activity.tourism.provider;
|
package com.hzs.activity.tourism.provider;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.hzs.activity.base.service.IAcBaseConfigService;
|
||||||
import com.hzs.activity.declaration.service.IAcDeclarationGiftConfigService;
|
import com.hzs.activity.declaration.service.IAcDeclarationGiftConfigService;
|
||||||
|
import com.hzs.activity.declaration.service.IAcDeclarationGiftRecordService;
|
||||||
|
import com.hzs.activity.declaration.vo.AcDeclarationGiftConfig;
|
||||||
|
import com.hzs.activity.declaration.vo.AcDeclarationGiftRecord;
|
||||||
import com.hzs.activity.tourism.IAcTourismServiceApi;
|
import com.hzs.activity.tourism.IAcTourismServiceApi;
|
||||||
import com.hzs.activity.tourism.service.IAcTourismDataService;
|
import com.hzs.activity.tourism.service.IAcTourismDataService;
|
||||||
|
import com.hzs.common.core.constant.CountryConstants;
|
||||||
import com.hzs.common.core.domain.R;
|
import com.hzs.common.core.domain.R;
|
||||||
|
import com.hzs.common.domain.activity.base.AcBaseConfig;
|
||||||
|
import com.hzs.common.domain.member.base.CuMember;
|
||||||
|
import com.hzs.common.domain.sale.order.SaOrder;
|
||||||
|
import com.hzs.member.base.IMemberServiceApi;
|
||||||
|
import com.hzs.sale.order.service.ISaOrderService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 旅游活动数据dubbo服务
|
* @Description: 旅游活动数据dubbo服务
|
||||||
|
@ -24,6 +46,14 @@ public class AcTourismServiceProvider implements IAcTourismServiceApi {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAcDeclarationGiftConfigService iAcDeclarationGiftConfigService;
|
private IAcDeclarationGiftConfigService iAcDeclarationGiftConfigService;
|
||||||
|
@Autowired
|
||||||
|
private IAcDeclarationGiftRecordService iAcDeclarationGiftRecordService;
|
||||||
|
@Autowired
|
||||||
|
private ISaOrderService iSaOrderService;
|
||||||
|
@Autowired
|
||||||
|
private IAcBaseConfigService iAcBaseConfigService;
|
||||||
|
@Autowired
|
||||||
|
private IMemberServiceApi iMemberServiceApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public R<?> handleTourismData() {
|
public R<?> handleTourismData() {
|
||||||
|
@ -37,9 +67,13 @@ public class AcTourismServiceProvider implements IAcTourismServiceApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public R<?> handleDeclarationData() {
|
public R<?> handleDeclarationData() {
|
||||||
try {
|
try {
|
||||||
|
R<?> del = saOrderPushDel();
|
||||||
|
if (del.isSuccess()) {
|
||||||
iAcDeclarationGiftConfigService.handleDeclarationData();
|
iAcDeclarationGiftConfigService.handleDeclarationData();
|
||||||
|
}
|
||||||
return R.ok();
|
return R.ok();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("报单赠送更新提货列表异常", e);
|
log.error("报单赠送更新提货列表异常", e);
|
||||||
|
@ -47,4 +81,110 @@ public class AcTourismServiceProvider implements IAcTourismServiceApi {
|
||||||
return R.fail();
|
return R.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private R<?> saOrderPushDel() {
|
||||||
|
// 获取所属国家
|
||||||
|
Integer pkCountry = CountryConstants.CHINA_COUNTRY;
|
||||||
|
// 获取 record 表最后一条数据
|
||||||
|
AcDeclarationGiftRecord lastRecord = iAcDeclarationGiftRecordService.selectLastRecord();
|
||||||
|
|
||||||
|
// 默认查 7 天前的数据
|
||||||
|
int daysAgo = 7;
|
||||||
|
|
||||||
|
// 如果上次记录不是昨天(表示有漏数据)
|
||||||
|
if (lastRecord != null) {
|
||||||
|
LocalDate lastDate = lastRecord.getCreationTime().toInstant()
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDate();
|
||||||
|
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
long diff = ChronoUnit.DAYS.between(lastDate, today);
|
||||||
|
|
||||||
|
if (diff > 1) {
|
||||||
|
// 有漏跑天数,就加上差值
|
||||||
|
daysAgo = (int) (7 + (diff - 1));
|
||||||
|
log.info("检测到漏跑 {} 天,将查询 {} 天前的订单", diff - 1, daysAgo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取目标日期(SYSDATE - daysAgo)
|
||||||
|
Date targetDate = java.sql.Date.valueOf(LocalDate.now().minusDays(7));
|
||||||
|
log.info("处理日期: {}", targetDate);
|
||||||
|
|
||||||
|
// 查询订单
|
||||||
|
List<SaOrder> orderList = iSaOrderService.list(new LambdaQueryWrapper<SaOrder>()
|
||||||
|
.in(SaOrder::getOrderType, 1, 2, 4, 5)
|
||||||
|
.apply("TRUNC(PAY_TIME) = TRUNC(SYSDATE - {0})", daysAgo)
|
||||||
|
.eq(SaOrder::getOrderStatus, 1)
|
||||||
|
.eq(SaOrder::getDelFlag, 0));
|
||||||
|
log.info("{}天无有效订单,处理结束", daysAgo);
|
||||||
|
// 获取所有7天前有效的报单赠送活动
|
||||||
|
List<AcBaseConfig> acBaseConfigList = iAcBaseConfigService.list(new LambdaQueryWrapper<AcBaseConfig>()
|
||||||
|
.le(AcBaseConfig::getActStartDate, targetDate)
|
||||||
|
.ge(AcBaseConfig::getActEndDate, targetDate)
|
||||||
|
.eq(AcBaseConfig::getActType, 32)
|
||||||
|
.eq(AcBaseConfig::getDelFlag, 0));
|
||||||
|
if (acBaseConfigList.isEmpty()) {
|
||||||
|
log.info("{}天前无有效报单赠送活动,处理结束", daysAgo);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
// 报单赠送活动主键集合
|
||||||
|
List<Long> declarationBaseIds = acBaseConfigList.stream().map(AcBaseConfig::getPkId).collect(Collectors.toList());
|
||||||
|
// 查询所有报单赠送活动数据
|
||||||
|
List<AcDeclarationGiftConfig> declarationGiftConfigs = iAcDeclarationGiftConfigService.list(new LambdaQueryWrapper<AcDeclarationGiftConfig>()
|
||||||
|
.in(AcDeclarationGiftConfig::getPkBaseId, declarationBaseIds)
|
||||||
|
.eq(AcDeclarationGiftConfig::getDelFlag, 0));
|
||||||
|
Map<String, AcDeclarationGiftConfig> configMap = declarationGiftConfigs.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
cfg -> cfg.getRegisterAuthority() + "_" + cfg.getSpecifyLevel(),
|
||||||
|
Function.identity(),
|
||||||
|
(a, b) -> b
|
||||||
|
));
|
||||||
|
|
||||||
|
orderList.forEach(order -> {
|
||||||
|
// 查看是否有重复订单
|
||||||
|
int count = iAcDeclarationGiftRecordService.count(new LambdaQueryWrapper<AcDeclarationGiftRecord>()
|
||||||
|
.eq(AcDeclarationGiftRecord::getOrderCode, order.getOrderCode())
|
||||||
|
.eq(AcDeclarationGiftRecord::getDelFlag, 0));
|
||||||
|
if (count > 0) {
|
||||||
|
log.warn("当前订单已同步至报单明细{}", order.getOrderCode());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 查询会员信息
|
||||||
|
R<CuMember> memberResult = iMemberServiceApi.getMember(order.getPkCreator());
|
||||||
|
CuMember member = memberResult.getData();
|
||||||
|
|
||||||
|
if (member == null) {
|
||||||
|
log.warn("会员信息不存在, orderId={}", order.getPkId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组合 key 匹配活动配置
|
||||||
|
String key = member.getRegisterAuthority() + "_" + member.getPkSettleGrade();
|
||||||
|
AcDeclarationGiftConfig matchedConfig = configMap.get(key);
|
||||||
|
|
||||||
|
if (matchedConfig == null) {
|
||||||
|
log.info("未找到匹配的报单赠送配置, 会员id={}, 注册权限={}, 结算等级={}",
|
||||||
|
member.getPkId(), member.getRegisterAuthority(), member.getPkSettleGrade());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AcDeclarationGiftRecord record = AcDeclarationGiftRecord.builder()
|
||||||
|
.pkRuleId(matchedConfig.getPkId())
|
||||||
|
.pkBaseId(matchedConfig.getPkBaseId())
|
||||||
|
.orderCode(order.getOrderCode())
|
||||||
|
.syncStatus(0)
|
||||||
|
.build();
|
||||||
|
record.setCreationTime(new Date());
|
||||||
|
record.setDelFlag(0);
|
||||||
|
record.setPkCreator(member.getPkId());
|
||||||
|
record.setPkCountry(pkCountry);
|
||||||
|
// 插入数据库
|
||||||
|
iAcDeclarationGiftRecordService.save(record);
|
||||||
|
|
||||||
|
log.info("成功插入报单赠送记录 -> memberId={}, ruleId={}",
|
||||||
|
member.getPkId(), matchedConfig.getPkId());
|
||||||
|
});
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,112 +206,6 @@ public class SaOrderServiceProvider implements ISaOrderServiceApi {
|
||||||
return singleItemStatVoList.stream().map(a -> BeanUtil.copyProperties(a, SingleItemStatDTO.class)).collect(Collectors.toList());
|
return singleItemStatVoList.stream().map(a -> BeanUtil.copyProperties(a, SingleItemStatDTO.class)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public R<?> autoPushDeclaration() {
|
|
||||||
// 获取所属国家
|
|
||||||
Integer pkCountry = CountryConstants.CHINA_COUNTRY;
|
|
||||||
// 获取 record 表最后一条数据
|
|
||||||
AcDeclarationGiftRecord lastRecord = iAcDeclarationGiftRecordService.selectLastRecord();
|
|
||||||
|
|
||||||
// 默认查 7 天前的数据
|
|
||||||
int daysAgo = 7;
|
|
||||||
|
|
||||||
// 如果上次记录不是昨天(表示有漏数据)
|
|
||||||
if (lastRecord != null) {
|
|
||||||
LocalDate lastDate = lastRecord.getCreationTime().toInstant()
|
|
||||||
.atZone(ZoneId.systemDefault())
|
|
||||||
.toLocalDate();
|
|
||||||
|
|
||||||
LocalDate today = LocalDate.now();
|
|
||||||
long diff = ChronoUnit.DAYS.between(lastDate, today);
|
|
||||||
|
|
||||||
if (diff > 1) {
|
|
||||||
// 有漏跑天数,就加上差值
|
|
||||||
daysAgo = (int) (7 + (diff - 1));
|
|
||||||
log.info("检测到漏跑 {} 天,将查询 {} 天前的订单", diff - 1, daysAgo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取目标日期(SYSDATE - daysAgo)
|
|
||||||
Date targetDate = java.sql.Date.valueOf(LocalDate.now().minusDays(7));
|
|
||||||
log.info("处理日期: {}", targetDate);
|
|
||||||
|
|
||||||
// 查询订单
|
|
||||||
List<SaOrder> orderList = iSaOrderService.list(new LambdaQueryWrapper<SaOrder>()
|
|
||||||
.in(SaOrder::getOrderType, 1, 2, 4, 5)
|
|
||||||
.apply("TRUNC(PAY_TIME) = TRUNC(SYSDATE - {0})", daysAgo)
|
|
||||||
.eq(SaOrder::getOrderStatus, 1)
|
|
||||||
.eq(SaOrder::getDelFlag, 0));
|
|
||||||
log.info("{}天无有效订单,处理结束",daysAgo);
|
|
||||||
// 获取所有7天前有效的报单赠送活动
|
|
||||||
List<AcBaseConfig> acBaseConfigList = iAcBaseConfigService.list(new LambdaQueryWrapper<AcBaseConfig>()
|
|
||||||
.le(AcBaseConfig::getActStartDate, targetDate)
|
|
||||||
.ge(AcBaseConfig::getActEndDate, targetDate)
|
|
||||||
.eq(AcBaseConfig::getActType, 32)
|
|
||||||
.eq(AcBaseConfig::getDelFlag, 0));
|
|
||||||
if (acBaseConfigList.isEmpty()) {
|
|
||||||
log.info("{}天前无有效报单赠送活动,处理结束",daysAgo);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
// 报单赠送活动主键集合
|
|
||||||
List<Long> declarationBaseIds = acBaseConfigList.stream().map(AcBaseConfig::getPkId).collect(Collectors.toList());
|
|
||||||
// 查询所有报单赠送活动数据
|
|
||||||
List<AcDeclarationGiftConfig> declarationGiftConfigs = iAcDeclarationGiftConfigService.list(new LambdaQueryWrapper<AcDeclarationGiftConfig>()
|
|
||||||
.in(AcDeclarationGiftConfig::getPkBaseId, declarationBaseIds)
|
|
||||||
.eq(AcDeclarationGiftConfig::getDelFlag, 0));
|
|
||||||
Map<String, AcDeclarationGiftConfig> configMap = declarationGiftConfigs.stream()
|
|
||||||
.collect(Collectors.toMap(
|
|
||||||
cfg -> cfg.getRegisterAuthority() + "_" + cfg.getSpecifyLevel(),
|
|
||||||
Function.identity(),
|
|
||||||
(a, b) -> b
|
|
||||||
));
|
|
||||||
|
|
||||||
orderList.forEach(order -> {
|
|
||||||
// 查看是否有重复订单
|
|
||||||
int count = iAcDeclarationGiftRecordService.count(new LambdaQueryWrapper<AcDeclarationGiftRecord>()
|
|
||||||
.eq(AcDeclarationGiftRecord::getOrderCode, order.getOrderCode())
|
|
||||||
.eq(AcDeclarationGiftRecord::getDelFlag, 0));
|
|
||||||
if (count > 0) {
|
|
||||||
log.warn("当前订单已同步至报单明细{}",order.getOrderCode());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 查询会员信息
|
|
||||||
R<CuMember> memberResult = iMemberServiceApi.getMember(order.getPkCreator());
|
|
||||||
CuMember member = memberResult.getData();
|
|
||||||
|
|
||||||
if (member == null) {
|
|
||||||
log.warn("会员信息不存在, orderId={}", order.getPkId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 组合 key 匹配活动配置
|
|
||||||
String key = member.getRegisterAuthority() + "_" + member.getPkSettleGrade();
|
|
||||||
AcDeclarationGiftConfig matchedConfig = configMap.get(key);
|
|
||||||
|
|
||||||
if (matchedConfig == null) {
|
|
||||||
log.info("未找到匹配的报单赠送配置, 会员id={}, 注册权限={}, 结算等级={}",
|
|
||||||
member.getPkId(), member.getRegisterAuthority(), member.getPkSettleGrade());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AcDeclarationGiftRecord record = AcDeclarationGiftRecord.builder()
|
|
||||||
.pkRuleId(matchedConfig.getPkId())
|
|
||||||
.pkBaseId(matchedConfig.getPkBaseId())
|
|
||||||
.orderCode(order.getOrderCode())
|
|
||||||
.syncStatus(0)
|
|
||||||
.build();
|
|
||||||
record.setCreationTime(new Date());
|
|
||||||
record.setDelFlag(0);
|
|
||||||
record.setPkCreator(member.getPkId());
|
|
||||||
record.setPkCountry(pkCountry);
|
|
||||||
// 插入数据库
|
|
||||||
iAcDeclarationGiftRecordService.save(record);
|
|
||||||
|
|
||||||
log.info("成功插入报单赠送记录 -> memberId={}, ruleId={}",
|
|
||||||
member.getPkId(), matchedConfig.getPkId());
|
|
||||||
});
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
LEFT JOIN BD_GRADE bgg ON aauc.UPGRADE_LEVEL = bgg.PK_ID
|
LEFT JOIN BD_GRADE bgg ON aauc.UPGRADE_LEVEL = bgg.PK_ID
|
||||||
WHERE aauc.PK_BASE_ID = #{pkId}
|
WHERE aauc.PK_BASE_ID = #{pkId}
|
||||||
AND aauc.DEL_FLAG = 0
|
AND aauc.DEL_FLAG = 0
|
||||||
|
AND aauc.ORDER_TYPE = #{orderType}
|
||||||
</select>
|
</select>
|
||||||
<select id="selectOrderTypeByBaseId" resultType="java.lang.Integer">
|
<select id="selectOrderTypeByBaseId" resultType="java.lang.Integer">
|
||||||
SELECT DISTINCT ORDER_TYPE
|
SELECT DISTINCT ORDER_TYPE
|
||||||
|
|
|
@ -26,20 +26,5 @@ public class OrderJob {
|
||||||
public void timingCloseOrder() {
|
public void timingCloseOrder() {
|
||||||
iSaOrderServiceApi.closeOrder();
|
iSaOrderServiceApi.closeOrder();
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 报单赠送订单推送
|
|
||||||
*/
|
|
||||||
@XxlJob("autoPushDeclaration")
|
|
||||||
public void autoPushDeclaration() {
|
|
||||||
log.info("推送报单赠送订单 开始执行");
|
|
||||||
R<?> resultR = iSaOrderServiceApi.autoPushDeclaration();
|
|
||||||
if (resultR.isSuccess()) {
|
|
||||||
log.info("推送报单赠送订单 执行成功");
|
|
||||||
} else {
|
|
||||||
log.error("推送报单赠送订单 执行失败");
|
|
||||||
}
|
|
||||||
log.info("推送报单赠送订单 结束执行");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue