Selaa lähdekoodia

Merge branch 'feat-20230531-unpack'

李学松 2 vuotta sitten
vanhempi
commit
0619e7c297

+ 19 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmScorePackageController.java

@@ -40,6 +40,7 @@ import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
 import com.qunzhixinxi.hnqz.admin.api.enums.TargetType;
 import com.qunzhixinxi.hnqz.admin.api.vo.WmScorePackageVO;
 import com.qunzhixinxi.hnqz.admin.entity.*;
+import com.qunzhixinxi.hnqz.admin.entity.dto.UnpackDTO;
 import com.qunzhixinxi.hnqz.admin.entity.model.excel.BatchPackageExcelModel;
 import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
 import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
@@ -61,6 +62,7 @@ import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
@@ -3175,5 +3177,22 @@ public class WmScorePackageController {
 		return Integer.parseInt(model.getScore());
 	}
 
+	/**
+	 * 拆包
+	 *
+	 * @param unpackDTO 拆包参数
+	 * @return 拆包结果
+	 */
+	@SysLog("拆包")
+	@PostMapping("/unpack")
+	public R<?> unpack(@Validated @RequestBody UnpackDTO unpackDTO) {
+		log.info("======================================拆包开始执行===================================");
+		log.info("拆包请求参数:{}", unpackDTO);
+
+		Boolean unpack = wmScorePackageService.unpack(unpackDTO);
+
+		log.info("======================================拆包执行完成===================================");
+		return R.ok(unpack);
+	}
 
 }

+ 2 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmScorePackageStatusController.java

@@ -81,7 +81,8 @@ public class WmScorePackageStatusController {
 		page.addOrder(orderItem);
 		Integer userId = SecurityUtils.getUser().getId();
 		Integer deptId = SecurityUtils.getUser().getDeptId();
-		wmScorePackageStatus.setUserId(String.valueOf(userId));
+//		wmScorePackageStatus.setUserId(String.valueOf(userId));
+		wmScorePackageStatus.setDeptId(String.valueOf(deptId));
 		// 判断当前用户是否配置了团队负责人
 		List<WmTeam> teamList = wmTeamService.list(Wrappers.<WmTeam>lambdaQuery()
 				.eq(WmTeam::getDeptId, deptId)

+ 3 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmTask.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -36,7 +37,7 @@ import java.util.List;
  * @date 2020-06-25 23:35:25
  */
 @Data
-@TableName("wm_task")
+@TableName(value = "wm_task", autoResultMap = true)
 @EqualsAndHashCode(callSuper = true)
 @ApiModel(value = "任务表")
 public class WmTask extends Model<WmTask> {
@@ -189,6 +190,7 @@ public class WmTask extends Model<WmTask> {
 
 	private String platAuditStatus;
 
+	@TableField(typeHandler = JacksonTypeHandler.class)
 	private List<String> extIds;
 
 	private String taskInfoImg;

+ 44 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/dto/UnpackDTO.java

@@ -0,0 +1,44 @@
+package com.qunzhixinxi.hnqz.admin.entity.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 拆包DTO
+ *
+ * @author snows
+ * @date 2023/5/31 10:31
+ */
+@Data
+public class UnpackDTO implements Serializable {
+	private static final long serialVersionUID = -3581313016062588900L;
+
+	/**
+	 * 积分包id
+	 */
+	@NotBlank(message = "积分包id必填")
+	private String scorePackageId;
+
+	/**
+	 * 原积分包剩余积分包值
+	 */
+	@NotNull(message = "原积分包剩余积分包值必填")
+	private Integer remainPackageScore;
+
+	/**
+	 * 已选任务积分值
+	 */
+	@NotNull(message = "已选任务积分值必填")
+	private Integer selectTaskScore;
+
+	/**
+	 * 已选任务id列表
+	 */
+	@NotEmpty(message = "已选任务id列表必填")
+	private List<String> selectTaskIds;
+}

+ 9 - 2
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmScorePackageService.java

@@ -25,12 +25,11 @@ import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
 import com.qunzhixinxi.hnqz.admin.api.vo.WmScorePackageVO;
 import com.qunzhixinxi.hnqz.admin.entity.WmDaDrugEntDrugtable;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
-import com.qunzhixinxi.hnqz.admin.entity.WmTask;
+import com.qunzhixinxi.hnqz.admin.entity.dto.UnpackDTO;
 import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageApiOutput;
 import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleInput;
 import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleOutput;
 import com.qunzhixinxi.hnqz.common.core.util.R;
-import org.apache.ibatis.annotations.Param;
 
 import java.time.LocalDate;
 import java.util.List;
@@ -186,4 +185,12 @@ public interface WmScorePackageService extends IService<WmScorePackage> {
 	 * @param pkg 基本包
 	 */
 	void checkPkgToSettle(WmScorePackage pkg);
+
+	/**
+	 * 拆包
+	 *
+	 * @param unpackDTO 拆包参数
+	 * @return 是否成功
+	 */
+	Boolean unpack(UnpackDTO unpackDTO);
 }

+ 141 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmScorePackageServiceImpl.java

@@ -19,7 +19,7 @@ package com.qunzhixinxi.hnqz.admin.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 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 com.alibaba.csp.sentinel.util.StringUtil;
 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.WmScorePackageVO;
 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.WmScorePackageSettleInput;
 import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleOutput;
 import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
 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.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.service.*;
 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.util.SecurityUtils;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -78,6 +83,7 @@ import static com.qunzhixinxi.hnqz.admin.enums.ReportEnum.REPORT_STATUS_END;
  * @author gaoyanng
  * @date 2020-06-25 23:35:42
  */
+@Slf4j
 @Service
 @AllArgsConstructor
 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;
+	}
 }

+ 5 - 2
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmScorePackageStatusMapper.xml

@@ -133,13 +133,13 @@
 
 
 	<select id="getWmScorePackageStatusPage" resultMap="wmScorePackageStatusMap">
-		select s.*,p.score_package_name from wm_score_package_status s
+		select distinct s.*,p.score_package_name from wm_score_package_status s
 		left join  wm_score_package p on p.id=s.package_id
 		left join sys_user u on u.dept_id=p.send_package_dept_id
 		left join sys_user u1 on u1.user_id = s.user_id
 		where  s.del_flag=0  and p.del_flag=0
 		  and p.typeid=4
-		  and p.source_type = '0'
+		  and (p.source_type = '0' or p.source_type is null)
 		<if test="query.id!=null and query.id!=''">
 			and s.id=#{query.id}
 		</if>
@@ -164,6 +164,9 @@
 				#{teamId}
 			</foreach>
 		</if>
+		<if test="query.deptId != null">
+			and p.dept_id = #{query.deptId}
+		</if>
 		order by s.create_time desc
 	</select>