Quellcode durchsuchen

Merge branch 'feat-20231019-mahv2' into temp-pre

lixuesong vor 1 Jahr
Ursprung
Commit
9417bcc142

+ 3 - 0
db/v2.0/20231019.sql

@@ -0,0 +1,3 @@
+alter table wm_score_package
+    add mah_settle_step char(8) default 'BUSINESS' null comment 'MAH结算-步进状态(BUSINESS-业务, FINANCE-财务)' after mah_settle_dept_id;
+

+ 14 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/UpmsType.java

@@ -168,4 +168,18 @@ public final class UpmsType {
 			return null;
 		}
 	}
+
+	/**
+	 * MAH结算-步进状态
+	 */
+	@Getter
+	@AllArgsConstructor
+	public enum MahSettleStep {
+		BUSINESS("BUSINESS", "业务"),
+		FINANCE("FINANCE", "财务");
+
+		@EnumValue
+		private final String type;
+		private final String description;
+	}
 }

+ 55 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmPayOffController.java

@@ -102,7 +102,7 @@ public class WmPayOffController {
 	 * @return 回退结果
 	 */
 	@ApiOperation(value = "结算回退", notes = "提交结算")
-	@SysLog("提交结算")
+	@SysLog("提交结算回退")
 	@PostMapping("/settleBack")
 	public R<?> settleBack(@RequestBody WmScorePackageSettleInput input) {
 		if (StringUtils.isEmpty(input.getId())) {
@@ -151,6 +151,7 @@ public class WmPayOffController {
 	@SysLog("提交结算")
 	@PostMapping("/settleSubmit")
 	public R<?> settleSubmit(@RequestBody @Valid WmScorePackageSettleInput input) {
+		log.info("提交结算参数:{}", input);
 
 		//1、验证令牌是否合法【令牌的对比和删除必须保证原子性】
 		HnqzUser finaAdmin = SecurityUtils.getUser();
@@ -173,6 +174,39 @@ public class WmPayOffController {
 		return wmPayOffService.settleSubmit(input);
 	}
 
+	/**
+	 * 业务提交结算信息到财务-MAH(药企的个人承接-其他-结算)
+	 *
+	 * @param input 结算信息
+	 * @return 提交结果
+	 */
+	@ApiOperation(value = "提交结算", notes = "提交结算")
+	@SysLog("MAH提交结算")
+	@PostMapping("/settleSubmitForMah")
+	public R<?> settleSubmitForMah(@RequestBody @Valid WmScorePackageSettleInput input) {
+		log.info("MAH提交结算参数:{}", input);
+
+		//1、验证令牌是否合法【令牌的对比和删除必须保证原子性】
+		HnqzUser finaAdmin = SecurityUtils.getUser();
+		final String REDIS_DEL_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
+		Long execute = redisTemplate.execute(new DefaultRedisScript<>(REDIS_DEL_SCRIPT, Long.class),
+				Collections.singletonList(String.format("%d:order_batch:%d:token", finaAdmin.getTenantId(), finaAdmin.getId())), input.getToken());
+		// 通过EVAL脚本原子验证令牌和删除令牌
+		boolean oops = (execute != null && execute == 0);
+
+		// 令牌验证失败
+		if (oops) {
+			log.error(String.format("提交 TOKEN 不正确:%s", input.getToken()));
+			return R.failed("提交 TOKEN 不正确,请刷新页面重试");
+		}
+
+		if (input.getSubjectLocation() == null) {
+			return R.failed("人员结算渠道不存在,不能结算");
+		}
+
+		return wmPayOffService.settleSubmitForMah(input);
+	}
+
 	/**
 	 * 业务保存结算记录
 	 *
@@ -183,6 +217,7 @@ public class WmPayOffController {
 	@SysLog("保存结算")
 	@PostMapping("/settleSave")
 	public R<?> settleSave(@RequestBody WmScorePackageSettleInput input) {
+		log.info("保存结算参数:{}", input);
 
 		if (CollectionUtils.isEmpty(input.getNotes()) || StringUtils.isEmpty(input.getId()) || input.getSubjectLocation() == null) {
 
@@ -192,6 +227,25 @@ public class WmPayOffController {
 		return wmPayOffService.settleSave(input);
 	}
 
+	/**
+	 * 业务保存结算记录-MAH(药企的个人承接-其他-结算)
+	 *
+	 * @param input 结算信息
+	 * @return 提交结果
+	 */
+	@ApiOperation(value = "保存结算", notes = "保存结算")
+	@SysLog("MAH保存结算")
+	@PostMapping("/settleSaveForMah")
+	public R<?> settleSaveForMah(@RequestBody WmScorePackageSettleInput input) {
+		log.info("MAH保存结算参数:{}", input);
+
+		if (CollectionUtils.isEmpty(input.getNotes()) || StringUtils.isEmpty(input.getId()) || input.getSubjectLocation() == null) {
+
+			return R.failed("数据异常或人员结算渠道不存在,不能结算");
+		}
+
+		return wmPayOffService.settleSaveForMah(input);
+	}
 
 	/**
 	 * 重新结算

+ 92 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmScorePackageController.java

@@ -2728,6 +2728,7 @@ public class WmScorePackageController {
 				.eq("p.package_type2", packageType2)
 				.eq(scorePackageStatus != null, "p.score_package_status", scorePackageStatus)
 				.eq("p.send_package_dept_id", sendDeptId)
+				.isNull("p.mah_settle_dept_id")
 				.between(start != null && end != null, "p.create_time", start, end);
 
 		if (StrUtil.isNotBlank(scorePackageName)) {
@@ -2803,6 +2804,95 @@ public class WmScorePackageController {
 		return R.ok(wmScorePackagePage);
 	}
 
+	/**
+	 * 积分包列表-其他(用于MAH结算:药企查询下级提交的)
+	 *
+	 * @param acceptUser 接单对象,模糊查询
+	 */
+	@ApiOperation(value = "分页查询", notes = "分页查询")
+	@GetMapping("/getScorePackagePageForMah")
+	public R getScorePackagePageForMah(@RequestParam(value = "current") Integer current,
+								 @RequestParam(value = "size") Integer size,
+								 @RequestParam(value = "packageType1") Integer packageType1,
+								 @RequestParam(value = "packageType2") Integer packageType2,
+								 @RequestParam(value = "scorePackageName", required = false) String scorePackageName,
+								 @RequestParam(value = "scorePackageStatus", required = false) Integer scorePackageStatus,
+								 @RequestParam(value = "typeid", required = false) String typeId,
+								 @RequestParam(value = "monthStart", required = false) String monthStart,
+								 @RequestParam(value = "monthEnd", required = false) String monthEnd,
+								 @RequestParam(value = "acceptUser", required = false) String acceptUser,
+								 @RequestParam(value = "relationScoreId", required = false) String relationScoreId,
+								 @RequestParam(value = "toApproval", required = false) Boolean toApproval
+	) {
+
+		Integer sendDeptId = SecurityUtils.getUser().getDeptId();
+
+		LocalDateTime start = null;
+		LocalDateTime end = null;
+
+		if (StrUtil.isNotEmpty(monthStart) && StrUtil.isNotEmpty(monthEnd)) {
+			start = LocalDateTime.of(LocalDate.parse(monthStart + "-01", DatePattern.NORM_DATE_FORMATTER), LocalTime.MIN);
+			LocalDate e = LocalDate.parse(monthEnd + "-01", DatePattern.NORM_DATE_FORMATTER);
+			end = LocalDateTime.of(e.with(TemporalAdjusters.lastDayOfMonth()), LocalTime.MAX);
+
+		}
+
+		QueryWrapper<WmScorePackage> queryWrapper = Wrappers.<WmScorePackage>query()
+				.eq("p.package_type1", packageType1)
+				.eq("p.package_type2", packageType2)
+				.eq(scorePackageStatus != null, "p.score_package_status", scorePackageStatus)
+				.eq("p.mah_settle_dept_id", sendDeptId)
+				.eq("p.mah_settle_step", UpmsType.MahSettleStep.BUSINESS.getType())
+				.between(start != null && end != null, "p.create_time", start, end);
+
+		if (StrUtil.isNotBlank(scorePackageName)) {
+			queryWrapper.and(wrapper -> wrapper.like("p.score_package_name", scorePackageName).or().like("p.pkg_sn", scorePackageName));
+		}
+
+		if (StringUtil.isEmpty(typeId)) {
+			queryWrapper.in("p.typeid", "3", "4", "5");
+		} else {
+			List<String> split = StrUtil.split(typeId, StrUtil.COMMA);
+			queryWrapper.in("p.typeid", split);
+		}
+
+		long startMillis = System.currentTimeMillis();
+		Page<WmScorePackage> wmScorePackagePage = wmScorePackageMapper.listScorePackage(new Page<>(current, size),
+				queryWrapper.orderByDesc("p.create_time"), acceptUser, relationScoreId, toApproval);
+
+		log.info("MAH积分包列表sql耗时:{}", System.currentTimeMillis() - startMillis);
+
+		List<WmScorePackage> pageRecords = wmScorePackagePage.getRecords();
+
+		if (CollUtil.isNotEmpty(pageRecords)) {
+			long buildStartMillis = System.currentTimeMillis();
+			List<Future<WmScorePackage>> futureList = new ArrayList<>(pageRecords.size());
+
+			for (WmScorePackage scorePackage : pageRecords) {
+				log.info("====> MAH积分包SN:{}", scorePackage.getPackageSn());
+				Future<WmScorePackage> wmScorePackageFuture = wmScorePackageService.buildScorePackage(scorePackage, packageType1, packageType2);
+				futureList.add(wmScorePackageFuture);
+			}
+
+			List<WmScorePackage> finalRecords = new ArrayList<>(pageRecords.size());
+			try {
+				for (Future<WmScorePackage> future : futureList) {
+					WmScorePackage wmScorePackage = future.get();
+					finalRecords.add(wmScorePackage);
+
+				}
+
+				wmScorePackagePage.setRecords(finalRecords);
+			} catch (ExecutionException | InterruptedException e) {
+				log.error("获取分页信息失败", e);
+				return R.failed("获取分页信息失败");
+			}
+			log.info("MAHbuild积分包耗时:{}", System.currentTimeMillis() - buildStartMillis);
+		}
+
+		return R.ok(wmScorePackagePage);
+	}
+
 	/**
 	 * 积分包列表(结算包管理列表、无团队限制)
 	 *
@@ -2916,7 +3006,7 @@ public class WmScorePackageController {
 	}
 
 	/**
-	 * 积分包列表(结算包管理列表、无团队限制)-用于MAH结算
+	 * 结算包结算管理页面-其他(用于MAH结算)
 	 *
 	 * @param packageType1 多个逗号分隔
 	 */
@@ -2949,6 +3039,7 @@ public class WmScorePackageController {
 				.like(StrUtil.isNotEmpty(scorePackageName), WmScorePackage::getScorePackageName, scorePackageName)
 				.eq(scorePackageStatus != null, WmScorePackage::getScorePackageStatus, scorePackageStatus)
 				.eq(WmScorePackage::getMahSettleDeptId, sendDeptId)
+				.eq(WmScorePackage::getMahSettleStep, UpmsType.MahSettleStep.FINANCE.getType())
 				.between(start != null && end != null, WmScorePackage::getCreateTime, start, end);
 
 		List<String> packageType1List = StrUtil.split(packageType1, StrUtil.COMMA);

+ 6 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java

@@ -22,6 +22,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.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
 import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
 import io.swagger.annotations.ApiModel;
@@ -559,6 +560,11 @@ public class WmScorePackage extends Model<WmScorePackage> {
 	 */
 	private Integer mahSettleDeptId;
 
+	/**
+	 * MAH结算-步进状态(BUSINESS-业务, FINANCE-财务)
+	 */
+	private UpmsType.MahSettleStep mahSettleStep;
+
 	/**
 	 * 企业任务上限(单位%)
 	 */

+ 16 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmPayOffService.java

@@ -56,6 +56,22 @@ public interface WmPayOffService extends IService<WmPayOff> {
 	 */
 	R<?> settleSubmit(WmScorePackageSettleInput input);
 
+	/**
+	 * 业务保存操作-MAH结算
+	 *
+	 * @param input 提交信息
+	 * @return 保存结果
+	 */
+	R<?> settleSaveForMah(WmScorePackageSettleInput input);
+
+	/**
+	 * 业务提交结算信息到财务-MAH结算
+	 *
+	 * @param input 输入信息
+	 * @return 提交结果
+	 */
+	R<?> settleSubmitForMah(WmScorePackageSettleInput input);
+
 	/**
 	 * 财务回退操作
 	 *

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

@@ -8,6 +8,7 @@ import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 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.SysDictItem;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
@@ -18,6 +19,7 @@ import com.qunzhixinxi.hnqz.admin.entity.input.SettleNoteStatusOutput;
 import com.qunzhixinxi.hnqz.admin.entity.input.WmScorePackageSettleInput;
 import com.qunzhixinxi.hnqz.admin.enums.PackageStatusEnum;
 import com.qunzhixinxi.hnqz.admin.enums.PackageTypeEnum;
+import com.qunzhixinxi.hnqz.admin.enums.ScorePackageStatusEnum;
 import com.qunzhixinxi.hnqz.admin.enums.SettleStatusEnum;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
@@ -420,13 +422,15 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		updateEntity.setSettleAmount(total);
 		updateEntity.setId(input.getId());
 		updateEntity.setSettleStatus(DingEnum.SETTLE_STATUS_WAIT.getType());
-		updateEntity.setScorePackageStatus("5");
+		updateEntity.setScorePackageStatus(ScorePackageStatusEnum.SETTLEMENT_SUBMITTED.val());
 		updateEntity.setDescription(input.getDescription());
 		updateEntity.setSubType(String.valueOf(input.getSubjectLocation().getGigType().getCode()));
 		updateEntity.setLocation(input.getSubjectLocation());
 		updateEntity.setSettlementDate(LocalDateTime.now());
 		if (SubjectLocation.MAH_SETTLE.equals(input.getSubjectLocation())) {
 			updateEntity.setMahSettleDeptId(input.getMahSettleDeptId());
+			// MAH结算提交给上级业务结算的标记
+			updateEntity.setMahSettleStep(UpmsType.MahSettleStep.BUSINESS);
 		}
 
 		if (PackageTypeEnum.TYPE2_SETTLE_PACKAGE.val().equals(wmScorePackage.getPackageType2())
@@ -448,6 +452,88 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		return R.ok(Boolean.TRUE);
 	}
 
+	/**
+	 * 业务提交结算信息到财务-MAH(药企的个人承接-其他-结算)
+	 *
+	 * @param input 输入信息
+	 * @return 提交结果
+	 */
+	@Override
+	public R<?> settleSubmitForMah(WmScorePackageSettleInput input) {
+
+		WmScorePackage wmScorePackage = wmScorePackageService.getById(input.getId());
+
+		// 校验基本包状态
+		wmScorePackageService.checkPkgToSettle(wmScorePackage);
+
+		List<WmScorePackageSettleNote> notes = input.getNotes();
+		SubjectLocation location = input.getSubjectLocation();
+
+		Integer deptId = SecurityUtils.getUser().getDeptId();
+
+		// 校验是否配置了结算限制
+		SysDeptSub queryDeptSub = sysDeptSubService.getOne(Wrappers.<SysDeptSub>lambdaQuery()
+				.eq(SysDeptSub::getDeptId, deptId)
+				.eq(SysDeptSub::getSubjectLocation, location)
+				.eq(SysDeptSub::getEnableFlag, SubjectTypeEnum.ENABLE_FLAG_TRUE.getCode()));
+		if (!queryDeptSub.getSettleEnable()) {
+			log.info("{}企业配置了结算限制", deptId);
+			throw new RuntimeException("系统维护中,请联系管理员");
+		}
+
+		// 校验人员信息
+		Set<Integer> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).map(Integer::valueOf).collect(Collectors.toSet());
+		userService.checkUserInfoToSettle(userIds, location);
+
+		// 校验结算
+		BigDecimal total = monitoringIndicatorService.settleMonitoringIndicator(notes, location);
+
+		LocalDateTime now = LocalDateTime.now();
+		notes.forEach(note -> {
+			note.setUpdateTime(now);
+			note.setSubTime(now);
+			note.setSubType(String.valueOf(location.getGigType().getCode()));
+			note.setSubjectLocation(location);
+			note.setInvoiceType(input.getInvoiceCategory());
+			note.setCategoryName(input.getCategoryName());
+			if (null == note.getId()) {
+				note.setCreateTime(LocalDateTime.now());
+			}
+		});
+
+		WmScorePackage updateEntity = new WmScorePackage();
+		updateEntity.setInvoiceCategory(input.getInvoiceCategory());
+		updateEntity.setSettleAmount(total);
+		updateEntity.setId(input.getId());
+		updateEntity.setSettleStatus(DingEnum.SETTLE_STATUS_WAIT.getType());
+		updateEntity.setScorePackageStatus(ScorePackageStatusEnum.SETTLEMENT_SUBMITTED.val());
+		updateEntity.setDescription(input.getDescription());
+		updateEntity.setSubType(String.valueOf(input.getSubjectLocation().getGigType().getCode()));
+		updateEntity.setLocation(input.getSubjectLocation());
+		updateEntity.setSettlementDate(LocalDateTime.now());
+		updateEntity.setMahSettleDeptId(input.getMahSettleDeptId());
+		// MAH提交到财务结算的标记
+		updateEntity.setMahSettleStep(UpmsType.MahSettleStep.FINANCE);
+
+		if (PackageTypeEnum.TYPE2_SETTLE_PACKAGE.val().equals(wmScorePackage.getPackageType2())
+				&& !StrUtil.equals(PackageTypeEnum.TYPE1_SCORE_AND_TASK_PACKAGE.val(), wmScorePackage.getPackageType1())) {
+			updateEntity.setPackageFinishStatus("1");
+			updateEntity.setTaskAddFlag("0");
+		}
+
+		if (StrUtil.equals(PackageTypeEnum.TYPE1_SCORE_AND_TASK_PACKAGE.val(), wmScorePackage.getPackageType1())) {
+			// 多人承接积分包可以一直结算
+			updateEntity.setSettleFlag("0");
+		} else {
+			updateEntity.setSettleFlag("1");
+		}
+
+		wmScorePackageService.updateById(updateEntity);
+		noteService.saveOrUpdateBatch(notes);
+
+		return R.ok(Boolean.TRUE);
+	}
+
 	/**
 	 * 业务保存操作
 	 *
@@ -510,6 +596,51 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		return R.ok(Boolean.TRUE);
 	}
 
+	/**
+	 * 业务保存操作-MAH(药企的个人承接-其他-结算)
+	 *
+	 * @param input 提交信息
+	 * @return 保存结果
+	 */
+	@Override
+	public R<?> settleSaveForMah(WmScorePackageSettleInput input) {
+
+		List<WmScorePackageSettleNote> notes = input.getNotes();
+		SubjectLocation location = input.getSubjectLocation();
+
+		// 校验人员信息
+		Set<Integer> userIds = notes.stream().map(WmScorePackageSettleNote::getUserId).map(Integer::valueOf).collect(Collectors.toSet());
+		userService.checkUserInfoToSettle(userIds, location);
+
+		// 校验结算
+		BigDecimal total = monitoringIndicatorService.settleMonitoringIndicator(notes, location);
+
+		LocalDateTime now = LocalDateTime.now();
+		notes.forEach(note -> {
+			note.setUpdateTime(now);
+			note.setSubTime(now);
+			note.setSubType(String.valueOf(location.getGigType().getCode()));
+			note.setSubjectLocation(location);
+			note.setInvoiceType(input.getInvoiceCategory());
+			note.setCategoryName(input.getCategoryName());
+			if (null == note.getId()) {
+				note.setCreateTime(LocalDateTime.now());
+			}
+		});
+		WmScorePackage updateEntity = new WmScorePackage();
+		updateEntity.setInvoiceCategory(input.getInvoiceCategory());
+		updateEntity.setSettleAmount(total);
+		updateEntity.setId(input.getId());
+		updateEntity.setDescription(input.getDescription());
+		updateEntity.setSubType(String.valueOf(location.getGigType().getCode()));
+		updateEntity.setLocation(input.getSubjectLocation());
+
+		wmScorePackageService.updateById(updateEntity);
+		noteService.saveOrUpdateBatch(notes);
+
+		return R.ok(Boolean.TRUE);
+	}
+
 	/**
 	 * 重新结算
 	 *