|
@@ -22,6 +22,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.DesensitizedUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.csp.sentinel.util.StringUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -33,6 +34,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysDeptRelation;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.entity.SysDictItem;
|
|
@@ -2862,4 +2864,197 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
|
|
|
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 终止积分包(个人)
|
|
|
+ * 用于个人承接积分值/多人承接积分值的包
|
|
|
+ *
|
|
|
+ * @param packageId 积分包id
|
|
|
+ * @param terminatePackageType 终止积分包类型
|
|
|
+ * @return {@link Boolean} 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean terminatePackageForPersonal(String packageId, UpmsType.TerminatePackageType terminatePackageType) {
|
|
|
+ Integer userId = SecurityUtils.getUser().getId();
|
|
|
+ Integer deptId = SecurityUtils.getUser().getDeptId();
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+
|
|
|
+ // 查询积分包
|
|
|
+ WmScorePackage scorePackage = this.getById(packageId);
|
|
|
+ // 查询上级积分包
|
|
|
+ WmScorePackage parentScorePackage = null;
|
|
|
+ if (StrUtil.isNotBlank(scorePackage.getRelationScoreId())) {
|
|
|
+ parentScorePackage = this.getById(scorePackage.getRelationScoreId());
|
|
|
+ }
|
|
|
+ // 查询所有任务
|
|
|
+ List<WmTask> taskList = wmTaskMapper.selectList(Wrappers.<WmTask>lambdaQuery().eq(WmTask::getScorePackageId, packageId)
|
|
|
+ .eq(WmTask::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
+ .eq(WmTask::getEnableFlag, EnableEnum.ENABLE.val()));
|
|
|
+ int approvedScore = 0;
|
|
|
+ if (CollUtil.isNotEmpty(taskList)) {
|
|
|
+ boolean pendingTaskApprovalFlag = taskList.stream()
|
|
|
+ .anyMatch(wmTask -> TaskStatusEnum.UNDER_REVIEW.val().equals(wmTask.getTaskStatus())
|
|
|
+ || TaskStatusEnum.INIT.val().equals(wmTask.getTaskStatus()));
|
|
|
+ if (pendingTaskApprovalFlag) {
|
|
|
+ throw new RuntimeException("有在途任务,不允许终止");
|
|
|
+ }
|
|
|
+ boolean pendingReportApprovalFlag = taskList.stream()
|
|
|
+ .filter(t -> TaskStatusEnum.APPROVED.val().equals(t.getTaskStatus()))
|
|
|
+ .anyMatch(wmTask -> ReportEnum.REPORT_STATUS_APPROVAL.getType().equals(wmTask.getReportDrugApprovalStatus())
|
|
|
+ || ReportEnum.REPORT_STATUS_APPROVAL.getType().equals(wmTask.getReportOneApprovalStatus())
|
|
|
+ || ReportEnum.REPORT_STATUS_PART_APPROVAL.getType().equals(wmTask.getReportDrugApprovalStatus())
|
|
|
+ || ReportEnum.REPORT_STATUS_PART_APPROVAL.getType().equals(wmTask.getReportOneApprovalStatus()));
|
|
|
+ if (pendingReportApprovalFlag) {
|
|
|
+ throw new RuntimeException("有待审批的任务,不允许终止");
|
|
|
+ }
|
|
|
+ // 审核通过的任务
|
|
|
+ List<WmTask> approvedTasks = taskList.stream()
|
|
|
+ .filter(t -> TaskStatusEnum.APPROVED.val().equals(t.getTaskStatus()))
|
|
|
+ .filter(wmTask -> ReportEnum.APPROVAL_OPINION_YES.getType().equals(wmTask.getReportDrugApprovalOpinion())
|
|
|
+ || ReportEnum.APPROVAL_OPINION_YES.getType().equals(wmTask.getReportOneApprovalOpinion()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 审核通过的积分
|
|
|
+ approvedScore = approvedTasks.stream()
|
|
|
+ .mapToInt(WmTask::getScore).sum();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询所有领包记录
|
|
|
+ List<WmScorePackageStatus> packageStatusList = wmScorePackageStatusService.list(Wrappers.<WmScorePackageStatus>lambdaQuery()
|
|
|
+ .eq(WmScorePackageStatus::getPackageId, packageId)
|
|
|
+ .eq(WmScorePackageStatus::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
+ .eq(WmScorePackageStatus::getEnableFlag, EnableEnum.ENABLE.val()));
|
|
|
+
|
|
|
+
|
|
|
+ // 更新积分包状态
|
|
|
+ WmScorePackage updateScorePackage = new WmScorePackage();
|
|
|
+ updateScorePackage.setId(packageId);
|
|
|
+ if (UpmsType.TerminatePackageType.ALL.equals(terminatePackageType)) {
|
|
|
+ // 全部终止: 改为已终止
|
|
|
+ updateScorePackage.setScorePackageStatus(ScorePackageStatusEnum.TERMINATED.val());
|
|
|
+ } else {
|
|
|
+ // 剩余回收: 改为已完成待结算/已完成待上级审批
|
|
|
+ updateScorePackage.setScore(approvedScore);
|
|
|
+ // 根据是否存在父级包,更新积分包完成状态
|
|
|
+ updateScorePackage.setScorePackageStatus(ScorePackageStatusEnum.TO_BE_SETTLED.val());
|
|
|
+ }
|
|
|
+ // 终止方式
|
|
|
+ updateScorePackage.setEnableType(terminatePackageType.getEnableType());
|
|
|
+ // 禁用
|
|
|
+ updateScorePackage.setEnableFlag(EnableEnum.DISABLE.val());
|
|
|
+ // 不允许新增任务
|
|
|
+ updateScorePackage.setTaskAddFlag("0");
|
|
|
+ // 不允许接单
|
|
|
+ updateScorePackage.setIsReceive("1");
|
|
|
+ log.info("积分包更新参数:{}", updateScorePackage);
|
|
|
+ this.updateById(updateScorePackage);
|
|
|
+
|
|
|
+ // 更新任务状态
|
|
|
+ if (UpmsType.TerminatePackageType.ALL.equals(terminatePackageType)) {
|
|
|
+ // 全部终止: 更新所有任务状态为禁用
|
|
|
+ Set<String> taskIds = taskList.stream().map(WmTask::getId).collect(Collectors.toSet());
|
|
|
+ log.info("任务更新参数(全部终止):taskIds={},packageId={},enableFlag={}", taskIds, packageId, EnableEnum.DISABLE.val());
|
|
|
+ wmTaskMapper.update(null, Wrappers.<WmTask>lambdaUpdate()
|
|
|
+ .in(WmTask::getId, taskIds)
|
|
|
+ .eq(WmTask::getScorePackageId, packageId)
|
|
|
+ .set(WmTask::getEnableFlag, EnableEnum.DISABLE.val()));
|
|
|
+ } else {
|
|
|
+ // 剩余回收: 暂不操作
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新领包记录状态
|
|
|
+ //将所有未接单审核的,改成审核不通过
|
|
|
+ wmScorePackageStatusService.update(Wrappers.<WmScorePackageStatus>lambdaUpdate()
|
|
|
+ .eq(WmScorePackageStatus::getPackageId, packageId)
|
|
|
+ .eq(WmScorePackageStatus::getStatus, "1")
|
|
|
+ .set(WmScorePackageStatus::getStatus, "3")
|
|
|
+ .set(WmScorePackageStatus::getTaskAddFlag, "0"));
|
|
|
+
|
|
|
+ // 回收积分
|
|
|
+ int recoveryScore = 0;
|
|
|
+ if (UpmsType.TerminatePackageType.ALL.equals(terminatePackageType)) {
|
|
|
+ // 全部终止
|
|
|
+ recoveryScore = scorePackage.getScore();
|
|
|
+ } else {
|
|
|
+ // 剩余回收
|
|
|
+ recoveryScore = approvedScore;
|
|
|
+ }
|
|
|
+ // 如果关联了大包 回收整包的积分值到大包的可分配积分值。如果没有关联大包,回收整包积分值到该企业的余额
|
|
|
+ if (parentScorePackage != null) {
|
|
|
+ // 更新父级积分包
|
|
|
+ WmScorePackage updateParentPackage = new WmScorePackage();
|
|
|
+ updateParentPackage.setId(parentScorePackage.getId());
|
|
|
+ updateParentPackage.setKfpjf(recoveryScore);
|
|
|
+ updateParentPackage.setUpdateTime(now);
|
|
|
+ updateParentPackage.setUpdateUser(userId);
|
|
|
+ log.info("父级积分包更新参数:{}", updateParentPackage);
|
|
|
+ this.updateById(updateParentPackage);
|
|
|
+ } else {
|
|
|
+ // 更新该企业的余额
|
|
|
+ SysDeptRecharge deptRecharge = sysDeptRechargeMapper.selectOne(Wrappers.<SysDeptRecharge>lambdaQuery()
|
|
|
+ .eq(SysDeptRecharge::getDeptId, deptId));
|
|
|
+ if (deptRecharge == null) {
|
|
|
+ throw new RuntimeException("没有配置企业余额信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是通过积分充值的积分发的包,则回收积分
|
|
|
+ SysDeptRechargeRecord rechargeRecord = sysDeptRechargeRecordMapper.selectOne(Wrappers.<SysDeptRechargeRecord>lambdaQuery()
|
|
|
+ .eq(SysDeptRechargeRecord::getPackageId, packageId)
|
|
|
+ .in(SysDeptRechargeRecord::getType, RechargeRecordType.SEND_PACKAGE_DEPT, RechargeRecordType.SEND_PACKAGE_PERSONAL));
|
|
|
+
|
|
|
+ if (rechargeRecord != null) {
|
|
|
+ log.info("终止积分包,更新积分余额信息");
|
|
|
+ int currentScore = deptRecharge.getScore() + recoveryScore;
|
|
|
+ // 更新企业配置的积分信息
|
|
|
+ int update = sysDeptRechargeMapper.update(null, Wrappers.<SysDeptRecharge>lambdaUpdate()
|
|
|
+ .eq(SysDeptRecharge::getId, rechargeRecord.getRechargeId())
|
|
|
+ .eq(SysDeptRecharge::getVersion, deptRecharge.getVersion())
|
|
|
+ .set(SysDeptRecharge::getScore, currentScore)
|
|
|
+ .set(SysDeptRecharge::getVersion, deptRecharge.getVersion() + 1)
|
|
|
+ .set(SysDeptRecharge::getUpdateUser, userId)
|
|
|
+ .set(SysDeptRecharge::getUpdateTime, LocalDateTime.now()));
|
|
|
+ if (update <= 0) {
|
|
|
+ throw new RuntimeException("更新余额失败");
|
|
|
+ }
|
|
|
+ // 新增积分记录
|
|
|
+ SysDeptRechargeRecord newRechargeRecord = new SysDeptRechargeRecord();
|
|
|
+ newRechargeRecord.setRechargeId(deptRecharge.getId());
|
|
|
+ newRechargeRecord.setChangeScore(recoveryScore);
|
|
|
+ newRechargeRecord.setCurrentScore(currentScore);
|
|
|
+ newRechargeRecord.setType(RechargeRecordType.RECOVERY);
|
|
|
+ newRechargeRecord.setDeptId(deptRecharge.getDeptId());
|
|
|
+ newRechargeRecord.setRelationDeptId(rechargeRecord.getRelationDeptId());
|
|
|
+ newRechargeRecord.setPackageId(packageId);
|
|
|
+ newRechargeRecord.setCreateUser(userId);
|
|
|
+ sysDeptRechargeRecordMapper.insert(newRechargeRecord);
|
|
|
+ } else {
|
|
|
+ log.info("终止积分包,更新积分配置信息(历史积分包处理)");
|
|
|
+ int currentScore = deptRecharge.getScore() + recoveryScore;
|
|
|
+ // 更新企业配置的积分信息
|
|
|
+ int update = sysDeptRechargeMapper.update(null, Wrappers.<SysDeptRecharge>lambdaUpdate()
|
|
|
+ .eq(SysDeptRecharge::getId, deptRecharge.getId())
|
|
|
+ .eq(SysDeptRecharge::getVersion, deptRecharge.getVersion())
|
|
|
+ .set(SysDeptRecharge::getScore, currentScore)
|
|
|
+ .set(SysDeptRecharge::getVersion, deptRecharge.getVersion() + 1)
|
|
|
+ .set(SysDeptRecharge::getUpdateUser, userId)
|
|
|
+ .set(SysDeptRecharge::getUpdateTime, LocalDateTime.now()));
|
|
|
+ if (update <= 0) {
|
|
|
+ throw new RuntimeException("更新余额失败");
|
|
|
+ }
|
|
|
+ // 新增积分记录
|
|
|
+ SysDeptRechargeRecord newRechargeRecord = new SysDeptRechargeRecord();
|
|
|
+ newRechargeRecord.setRechargeId(deptRecharge.getId());
|
|
|
+ newRechargeRecord.setChangeScore(recoveryScore);
|
|
|
+ newRechargeRecord.setCurrentScore(currentScore);
|
|
|
+ newRechargeRecord.setType(RechargeRecordType.RECOVERY);
|
|
|
+ newRechargeRecord.setDeptId(deptRecharge.getDeptId());
|
|
|
+ newRechargeRecord.setPackageId(packageId);
|
|
|
+ newRechargeRecord.setCreateUser(userId);
|
|
|
+ sysDeptRechargeRecordMapper.insert(newRechargeRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
}
|