|
@@ -19,7 +19,7 @@ package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
-import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.csp.sentinel.util.StringUtil;
|
|
import com.alibaba.csp.sentinel.util.StringUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
@@ -40,13 +40,17 @@ import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
|
|
import com.qunzhixinxi.hnqz.admin.api.vo.UserVO;
|
|
import com.qunzhixinxi.hnqz.admin.api.vo.UserVO;
|
|
import com.qunzhixinxi.hnqz.admin.api.vo.WmScorePackageVO;
|
|
import com.qunzhixinxi.hnqz.admin.api.vo.WmScorePackageVO;
|
|
import com.qunzhixinxi.hnqz.admin.entity.*;
|
|
import com.qunzhixinxi.hnqz.admin.entity.*;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.dto.UnpackDTO;
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageApiOutput;
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageApiOutput;
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleInput;
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleInput;
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleOutput;
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleOutput;
|
|
import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.PackageStatusEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.ReportEnum;
|
|
import com.qunzhixinxi.hnqz.admin.enums.ReportEnum;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.ScorePackageStatusEnum;
|
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.TaskStatusEnum;
|
|
import com.qunzhixinxi.hnqz.admin.mapper.*;
|
|
import com.qunzhixinxi.hnqz.admin.mapper.*;
|
|
import com.qunzhixinxi.hnqz.admin.service.*;
|
|
import com.qunzhixinxi.hnqz.admin.service.*;
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
@@ -54,6 +58,7 @@ import com.qunzhixinxi.hnqz.common.data.datascope.DataScope;
|
|
import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -78,6 +83,7 @@ import static com.qunzhixinxi.hnqz.admin.enums.ReportEnum.REPORT_STATUS_END;
|
|
* @author gaoyanng
|
|
* @author gaoyanng
|
|
* @date 2020-06-25 23:35:42
|
|
* @date 2020-06-25 23:35:42
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper, WmScorePackage> implements WmScorePackageService {
|
|
public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper, WmScorePackage> implements WmScorePackageService {
|
|
@@ -2484,4 +2490,138 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
|
|
}
|
|
}
|
|
;
|
|
;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 拆包
|
|
|
|
+ *
|
|
|
|
+ * @param unpackDTO 拆包参数
|
|
|
|
+ * @return 是否成功
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Boolean unpack(UnpackDTO unpackDTO) {
|
|
|
|
+ // 原积分包
|
|
|
|
+ WmScorePackage scorePackage = this.getById(unpackDTO.getScorePackageId());
|
|
|
|
+ if (scorePackage == null) {
|
|
|
|
+ throw new RuntimeException("原积分包不存在");
|
|
|
|
+ }
|
|
|
|
+ if (!PackageTypeEnum.TYPE1_SCOTE_PACKAGE.val().equals(scorePackage.getPackageType1())
|
|
|
|
+ || !PackageTypeEnum.TYPE2_TASK_PACKAGE.val().equals(scorePackage.getPackageType2())) {
|
|
|
|
+ throw new RuntimeException("不支持该积分包类型");
|
|
|
|
+ }
|
|
|
|
+ // 业务校验1
|
|
|
|
+ if (!ScorePackageStatusEnum.TO_BE_SETTLED.val().equals(scorePackage.getScorePackageStatus())) {
|
|
|
|
+ throw new RuntimeException("只有“已完成待结算”的积分包可以拆包");
|
|
|
|
+ }
|
|
|
|
+ // 原审核通过的任务列表
|
|
|
|
+ QueryWrapper<WmTask> queryWrapper = Wrappers.query();
|
|
|
|
+ queryWrapper.eq("task_status", TaskStatusEnum.APPROVED.val());
|
|
|
|
+ queryWrapper.eq("score_package_id", unpackDTO.getScorePackageId());
|
|
|
|
+ queryWrapper.eq("del_flag", DelEnum.NOT_DEL.val());
|
|
|
|
+ queryWrapper.eq("real_flag", "0");
|
|
|
|
+ queryWrapper.orderByDesc("lookinto_date");
|
|
|
|
+ List<WmTask> taskList = wmTaskMapper.selectList(queryWrapper);
|
|
|
|
+
|
|
|
|
+ Set<String> taskIds = taskList.stream().map(WmTask::getId).collect(Collectors.toSet());
|
|
|
|
+ // 校验已选择的任务是否都在原任务中
|
|
|
|
+ if (!CollUtil.containsAll(taskIds, unpackDTO.getSelectTaskIds())) {
|
|
|
|
+ throw new RuntimeException("已选择的任务不在原任务中");
|
|
|
|
+ }
|
|
|
|
+ // 已选择的任务
|
|
|
|
+ List<WmTask> selectTaskList = wmTaskMapper.selectBatchIds(unpackDTO.getSelectTaskIds());
|
|
|
|
+ if (CollUtil.isEmpty(selectTaskList)) {
|
|
|
|
+ throw new RuntimeException("已选择的任务不存在");
|
|
|
|
+ }
|
|
|
|
+ // 校验已选择的任务分值
|
|
|
|
+ int selectTaskScore = selectTaskList.stream().mapToInt(WmTask::getScore).sum();
|
|
|
|
+ if (!unpackDTO.getSelectTaskScore().equals(selectTaskScore)) {
|
|
|
|
+ throw new RuntimeException("已选任务分值不正确");
|
|
|
|
+ }
|
|
|
|
+ // 业务校验2
|
|
|
|
+ if (selectTaskScore >= scorePackage.getScore()) {
|
|
|
|
+ throw new RuntimeException("“已选总任务积分”必须小于“总积分包值”");
|
|
|
|
+ }
|
|
|
|
+ // 拆包后的原积分包包值:取剩任务分值
|
|
|
|
+ int oldScorePackageScore = scorePackage.getScore() - selectTaskScore;
|
|
|
|
+ if (!unpackDTO.getRemainPackageScore().equals(oldScorePackageScore)) {
|
|
|
|
+ throw new RuntimeException("原积分包剩余积分包值不正确");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
|
+// Integer operatorId = SecurityUtils.getUser().getId();
|
|
|
|
+ // 创建新包
|
|
|
|
+ String newScorePackageName = null;
|
|
|
|
+ // 校验积分包名称是否存在
|
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
|
+ newScorePackageName = String.format("%s-%s", scorePackage.getScorePackageName(), RandomUtil.randomNumbers(3));
|
|
|
|
+ int newScorePackageCount = this.count(Wrappers.<WmScorePackage>lambdaQuery().eq(WmScorePackage::getScorePackageName, newScorePackageName));
|
|
|
|
+ if (newScorePackageCount <= 0) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ WmScorePackage newScorePackage = BeanUtil.copyProperties(scorePackage, WmScorePackage.class);
|
|
|
|
+ newScorePackage.setId(null);
|
|
|
|
+// newScorePackage.setUpdateTime(null);
|
|
|
|
+// newScorePackage.setUpdateUser(null);
|
|
|
|
+// newScorePackage.setCreateTime(now);
|
|
|
|
+// newScorePackage.setCreateUser(operatorId);
|
|
|
|
+// newScorePackage.setReceiveDate(now);
|
|
|
|
+ newScorePackage.setScore(unpackDTO.getSelectTaskScore());
|
|
|
|
+ newScorePackage.setScorePackageName(newScorePackageName);
|
|
|
|
+ newScorePackage.setRemark(String.format("拆包自原积分包id=%s", unpackDTO.getScorePackageId()));
|
|
|
|
+ log.info("创建新积分包参数:{}", newScorePackage);
|
|
|
|
+ this.save(newScorePackage);
|
|
|
|
+ // 复制原包积分规则
|
|
|
|
+ List<WmScoreTaskType> oldScoreTaskTypes = wmScoreTaskTypeMapper.selectList(Wrappers.<WmScoreTaskType>lambdaQuery()
|
|
|
|
+ .eq(WmScoreTaskType::getScoreId, unpackDTO.getScorePackageId()));
|
|
|
|
+ if (CollUtil.isNotEmpty(oldScoreTaskTypes)) {
|
|
|
|
+ oldScoreTaskTypes.forEach(wmScoreTaskType -> {
|
|
|
|
+ WmScoreTaskType newScoreTaskType = BeanUtil.copyProperties(wmScoreTaskType, WmScoreTaskType.class);
|
|
|
|
+ newScoreTaskType.setId(null);
|
|
|
|
+ newScoreTaskType.setScoreId(newScorePackage.getId());
|
|
|
|
+ wmScoreTaskTypeMapper.insert(newScoreTaskType);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新原积分包包值
|
|
|
|
+ WmScorePackage updateOldPackage = new WmScorePackage();
|
|
|
|
+ updateOldPackage.setId(unpackDTO.getScorePackageId());
|
|
|
|
+ updateOldPackage.setScore(oldScorePackageScore);
|
|
|
|
+// updateOldPackage.setUpdateTime(now);
|
|
|
|
+// updateOldPackage.setUpdateUser(operatorId);
|
|
|
|
+ updateOldPackage.setRemark(String.format("%s; 原积分包值%s更新为%s",
|
|
|
|
+ StrUtil.emptyIfNull(updateOldPackage.getRemark()), scorePackage.getScore(), oldScorePackageScore));
|
|
|
|
+ log.info("更新原积分包参数:{}", updateOldPackage);
|
|
|
|
+ this.updateById(updateOldPackage);
|
|
|
|
+
|
|
|
|
+ // 原积分包的领包记录
|
|
|
|
+ WmScorePackageStatus oldScorePackageStatus = wmScorePackageStatusService.getOne(Wrappers.<WmScorePackageStatus>lambdaQuery()
|
|
|
|
+ .eq(WmScorePackageStatus::getPackageId, unpackDTO.getScorePackageId())
|
|
|
|
+ .eq(WmScorePackageStatus::getStatus, PackageStatusEnum.APPROVED.val()));
|
|
|
|
+ // 创建新积分包的领包记录
|
|
|
|
+ WmScorePackageStatus newScorePackageStatus = BeanUtil.copyProperties(oldScorePackageStatus, WmScorePackageStatus.class);
|
|
|
|
+ newScorePackageStatus.setPackageId(newScorePackage.getId());
|
|
|
|
+ newScorePackageStatus.setUserScore(String.valueOf(newScorePackage.getScore()));
|
|
|
|
+ newScorePackageStatus.setTaskNum(newScorePackage.getTaskNum());
|
|
|
|
+// newScorePackageStatus.setCreateTime(now);
|
|
|
|
+// newScorePackageStatus.setCreateUser(operatorId);
|
|
|
|
+// newScorePackageStatus.setUpdateUser(null);
|
|
|
|
+// newScorePackageStatus.setUpdateTime(null);
|
|
|
|
+ log.info("创建新积分包的领包记录:{}", newScorePackageStatus);
|
|
|
|
+ wmScorePackageStatusService.save(newScorePackageStatus);
|
|
|
|
+
|
|
|
|
+ // 任务关联到新积分包
|
|
|
|
+ selectTaskList.forEach(wmTask -> {
|
|
|
|
+ WmTask updateTask = new WmTask();
|
|
|
|
+ updateTask.setId(wmTask.getId());
|
|
|
|
+ updateTask.setScorePackageId(newScorePackage.getId());
|
|
|
|
+// updateTask.setUpdateUser(String.valueOf(operatorId));
|
|
|
|
+// updateTask.setUpdateTime(now);
|
|
|
|
+ updateTask.setExtIds(Collections.singletonList(String.format("拆包任务,原积分包id=%s", unpackDTO.getScorePackageId())));
|
|
|
|
+ log.info("更新任务参数:{}", updateTask);
|
|
|
|
+ wmTaskMapper.updateById(updateTask);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return Boolean.TRUE;
|
|
|
|
+ }
|
|
}
|
|
}
|