소스 검색

Merge branch 'feat-20231019-mahv2'

lixuesong 1 년 전
부모
커밋
35d4c127b1
15개의 변경된 파일585개의 추가작업 그리고 99개의 파일을 삭제
  1. 5 0
      db/v2.0/20231019.sql
  2. 33 0
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/UpmsState.java
  3. 31 0
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/UpmsType.java
  4. 37 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmBizReminderController.java
  5. 57 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmPayOffController.java
  6. 95 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmScorePackageController.java
  7. 11 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java
  8. 6 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/input/WmScorePackageSettleInput.java
  9. 10 2
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/ScorePackageStatusEnum.java
  10. 36 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmBizReminderService.java
  11. 16 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmPayOffService.java
  12. 69 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmBizReminderServiceImpl.java
  13. 158 91
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmPayOffServiceImpl.java
  14. 3 2
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmScorePackageServiceImpl.java
  15. 18 2
      hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmScorePackageMapper.xml

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

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

+ 33 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/UpmsState.java

@@ -0,0 +1,33 @@
+package com.qunzhixinxi.hnqz.admin.api.constant;
+
+import com.baomidou.mybatisplus.annotation.EnumValue;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * Upms状态枚举
+ *
+ * @author jimmy
+ * @version 1.0.0
+ * @date 2022-08-15 15:24
+ */
+public class UpmsState {
+
+	/**
+	 * 业务提醒已读状态
+	 *
+	 * @author lixuesong
+	 * @date 2023/10/25
+	 */
+	@Getter
+	@AllArgsConstructor
+	public enum BizReminderReadStatus {
+
+		READ("READ", "已读"),
+		UNREAD("UNREAD", "未读");
+
+		@EnumValue
+		private final String status;
+		private final String description;
+	}
+}

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

@@ -168,4 +168,35 @@ 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;
+	}
+
+	/**
+	 * 业务未读提醒
+	 *
+	 * @author lixuesong
+	 * @date 2023/10/25
+	 */
+	@Getter
+	@AllArgsConstructor
+	public enum BizReminderType {
+		ASSIGN_POINTS_OTHER_REMINDER("ASSIGN_POINTS_OTHER_REMINDER", "ASSIGN:POINTS:OTHE:REMINDER:KEY", "个人承接积分值-其他的提醒");
+
+		@EnumValue
+		private final String type;
+		private final String key;
+		private final String description;
+	}
 }

+ 37 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmBizReminderController.java

@@ -0,0 +1,37 @@
+package com.qunzhixinxi.hnqz.admin.controller;
+
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
+import com.qunzhixinxi.hnqz.admin.service.WmBizReminderService;
+import com.qunzhixinxi.hnqz.common.core.util.R;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 业务未读提醒控制层
+ *
+ * @author lixuesong
+ * @date 2023/10/25
+ */
+@Slf4j
+@RestController
+@AllArgsConstructor
+@RequestMapping("/biz-reminder")
+public class WmBizReminderController {
+
+	private final WmBizReminderService wmBizReminderService;
+
+	/**
+	 * 获取标记状态(TRUE-已读, FALSE-未读)
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @return {@link Boolean} 是否已读
+	 */
+	@GetMapping("/read-status")
+	R<Boolean> getReminder(@RequestParam("bizReminderType") UpmsType.BizReminderType bizReminderType) {
+		return R.ok(wmBizReminderService.getReadStatus(bizReminderType));
+	}
+}

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

@@ -12,6 +12,7 @@ import com.deepoove.poi.XWPFTemplate;
 import com.deepoove.poi.config.Configure;
 import com.deepoove.poi.policy.HackLoopTableRenderPolicy;
 import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
+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.entity.SysDeptSub;
@@ -102,7 +103,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 +152,7 @@ public class WmPayOffController {
 	@SysLog("提交结算")
 	@PostMapping("/settleSubmit")
 	public R<?> settleSubmit(@RequestBody @Valid WmScorePackageSettleInput input) {
+		log.info("提交结算参数:{}", input);
 
 		//1、验证令牌是否合法【令牌的对比和删除必须保证原子性】
 		HnqzUser finaAdmin = SecurityUtils.getUser();
@@ -173,6 +175,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 +218,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 +228,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);
+	}
 
 	/**
 	 * 重新结算
@@ -273,6 +328,7 @@ public class WmPayOffController {
 	public R<?> listMAHPackageSettleList(Page<WmScorePackageSettleOutput> page, WmScorePackageSettleInput input) {
 
 		input.setMahSettleDeptId(SecurityUtils.getUser().getDeptId());
+		input.setMahSettleStep(UpmsType.MahSettleStep.FINANCE);
 		input.setPackageFinishStatus("1");
 		input.setTypeid("4");
 		input.setSettleFlag("1");

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

@@ -121,6 +121,7 @@ public class WmScorePackageController {
 	private final WmScorePackageSettleNoteMapper settleNoteMapper;
 	private final SysDeptRechargeRecordMapper sysDeptRechargeRecordMapper;
 	private final SysDeptRechargeMapper sysDeptRechargeMapper;
+	private final WmBizReminderService wmBizReminderService;
 	private final StringRedisTemplate redisTemplate;
 	private final Sequence pkgSequence;
 
@@ -2802,6 +2803,98 @@ 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)
+				.in("p.mah_settle_step", UpmsType.MahSettleStep.BUSINESS.getType(), UpmsType.MahSettleStep.FINANCE.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.settlement_date"), 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);
+		}
+
+		// 个人承接-其他 标记已读提醒
+		wmBizReminderService.markRead(UpmsType.BizReminderType.ASSIGN_POINTS_OTHER_REMINDER, sendDeptId);
+
+		return R.ok(wmScorePackagePage);
+	}
+
 	/**
 	 * 积分包列表(结算包管理列表、无团队限制)
 	 *
@@ -2915,7 +3008,7 @@ public class WmScorePackageController {
 	}
 
 	/**
-	 * 积分包列表(结算包管理列表、无团队限制)-用于MAH结算
+	 * 结算包结算管理页面-其他(用于MAH结算)
 	 *
 	 * @param packageType1 多个逗号分隔
 	 */
@@ -2948,6 +3041,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);

+ 11 - 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,16 @@ public class WmScorePackage extends Model<WmScorePackage> {
 	 */
 	private Integer mahSettleDeptId;
 
+	/**
+	 * MAH结算-步进状态(BUSINESS-业务, FINANCE-财务)
+	 */
+	private UpmsType.MahSettleStep mahSettleStep;
+
+	/**
+	 * mah结算时间
+	 */
+	private LocalDateTime mahSettleTime;
+
 	/**
 	 * 企业任务上限(单位%)
 	 */

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

@@ -1,5 +1,6 @@
 package com.qunzhixinxi.hnqz.admin.entity.input;
 
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageSettleNote;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
 import lombok.Data;
@@ -92,6 +93,11 @@ public class WmScorePackageSettleInput implements Serializable {
 	 */
 	private Integer mahSettleDeptId;
 
+	/**
+	 * MAH结算-步进状态(BUSINESS-业务, FINANCE-财务)
+	 */
+	private UpmsType.MahSettleStep mahSettleStep;
+
 	/**
 	 * 结算人员
 	 */

+ 10 - 2
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/ScorePackageStatusEnum.java

@@ -32,7 +32,7 @@ public enum ScorePackageStatusEnum {
 	/**
 	 * 已提交结算申请
 	 */
-	SETTLEMENT_SUBMITTED("5", "提交结算申请"),
+	SETTLEMENT_SUBMITTED("5", "全部提交结算申请"),
 	/**
 	 * 已终止
 	 */
@@ -40,7 +40,15 @@ public enum ScorePackageStatusEnum {
 	/**
 	 * 已完成待提交审批
 	 */
-	TO_BE_APPROVAL("7", "已完成待上级审批");
+	TO_BE_APPROVAL("7", "已完成待上级审批"),
+	/**
+	 * 部分提交结算申请
+	 */
+	PART_SETTLEMENT_SUBMITTED("8", "部分提交结算申请"),
+	/**
+	 * 已提交药企
+	 */
+	SUBMITTED_TO_DRUGENT("9", "已提交药企");
 
 	private final String val;
 

+ 36 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmBizReminderService.java

@@ -0,0 +1,36 @@
+package com.qunzhixinxi.hnqz.admin.service;
+
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
+
+/**
+ * 业务未读提醒服务层
+ *
+ * @author lixuesong
+ * @date 2023/10/25
+ */
+public interface WmBizReminderService {
+
+	/**
+	 * 标记未读
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @param deptId 部门id
+	 */
+	void markUnread(UpmsType.BizReminderType bizReminderType, Integer deptId);
+
+	/**
+	 * 标记已读
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @param deptId 部门id
+	 */
+	void markRead(UpmsType.BizReminderType bizReminderType, Integer deptId);
+
+	/**
+	 * 获取标记状态
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @return {@link Boolean} 是否已读
+	 */
+	Boolean getReadStatus(UpmsType.BizReminderType bizReminderType);
+}

+ 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);
+
 	/**
 	 * 财务回退操作
 	 *

+ 69 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmBizReminderServiceImpl.java

@@ -0,0 +1,69 @@
+package com.qunzhixinxi.hnqz.admin.service.impl;
+
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsState;
+import com.qunzhixinxi.hnqz.admin.api.constant.UpmsType;
+import com.qunzhixinxi.hnqz.admin.service.WmBizReminderService;
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+/**
+ * 业务未读提醒服务层
+ *
+ * @author lixuesong
+ * @date 2023/10/25
+ */
+@Slf4j
+@Service
+@AllArgsConstructor
+public class WmBizReminderServiceImpl implements WmBizReminderService {
+
+	private final RedisTemplate redisTemplate;
+
+	/**
+	 * 标记未读提醒
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @param deptId 部门id
+	 */
+	@Override
+	public void markUnread(UpmsType.BizReminderType bizReminderType, Integer deptId) {
+		String cacheKey = bizReminderType.getKey() + deptId;
+
+		redisTemplate.opsForValue().set(cacheKey, UpmsState.BizReminderReadStatus.UNREAD.getStatus());
+	}
+
+	/**
+	 * 标记已读提醒
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @param deptId 部门id
+	 */
+	@Override
+	public void markRead(UpmsType.BizReminderType bizReminderType, Integer deptId) {
+		String cacheKey = bizReminderType.getKey() + deptId;
+
+		redisTemplate.opsForValue().set(cacheKey, UpmsState.BizReminderReadStatus.READ.getStatus());
+	}
+
+	/**
+	 * 获取标记状态
+	 *
+	 * @param bizReminderType 提醒类型
+	 * @return {@link Boolean} 是否已读
+	 */
+	@Override
+	public Boolean getReadStatus(UpmsType.BizReminderType bizReminderType) {
+		Integer deptId = SecurityUtils.getUser().getDeptId();
+		String cacheKey = bizReminderType.getKey() + deptId;
+
+		Object o = redisTemplate.opsForValue().get(cacheKey);
+		if (UpmsState.BizReminderReadStatus.READ.getStatus().equals(o)) {
+			return Boolean.TRUE;
+		}
+
+		return Boolean.FALSE;
+	}
+}

+ 158 - 91
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;
@@ -16,8 +17,8 @@ import com.qunzhixinxi.hnqz.admin.config.UpmsConfig;
 import com.qunzhixinxi.hnqz.admin.entity.*;
 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;
@@ -92,6 +93,8 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 	private final TaxHelperService taxHelperService;
 	private final TaxNotifyConfig taxNotifyConfig;
 
+	private final WmBizReminderService wmBizReminderService;
+
 	private final MathContext mc = new MathContext(2, RoundingMode.HALF_EVEN);
 	private final String GIG_TOKEN_URL = "%s/gig/operation/token?tenantId={tenantId}&action={action}&userId={userId}";
 	private final String GIG_SETTLE_URL = "%s/gig/operation/settlement";
@@ -112,12 +115,20 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		}
 		WmScorePackage updateEntity = new WmScorePackage();
 		updateEntity.setId(wmScorePackage.getId());
-		updateEntity.setScorePackageStatus("4");
+
+		if (UpmsType.MahSettleStep.FINANCE.equals(wmScorePackage.getMahSettleStep())) {
+			// mah结算回退到药企的业务(个人承接-其他)
+			updateEntity.setScorePackageStatus(ScorePackageStatusEnum.SUBMITTED_TO_DRUGENT.val());
+			updateEntity.setMahSettleStep(UpmsType.MahSettleStep.BUSINESS);
+		} else {
+			updateEntity.setScorePackageStatus(ScorePackageStatusEnum.TO_BE_SETTLED.val());
+		}
 		updateEntity.setSettleFlag("0");
 		wmScorePackageService.updateById(updateEntity);
 
 		WmScorePackageSettleNote deleteQuery = new WmScorePackageSettleNote();
 		deleteQuery.setPackageId(input.getId());
+		log.info("回退删除settlenote: {}", deleteQuery);
 		noteService.remove(Wrappers.query(deleteQuery));
 
 		return R.ok(Boolean.TRUE);
@@ -420,15 +431,113 @@ 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.setDescription(input.getDescription());
 		updateEntity.setSubType(String.valueOf(input.getSubjectLocation().getGigType().getCode()));
-		updateEntity.setLocation(input.getSubjectLocation());
+		updateEntity.setLocation(location);
 		updateEntity.setSettlementDate(LocalDateTime.now());
+
+		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 (SubjectLocation.MAH_SETTLE.equals(input.getSubjectLocation())) {
 			updateEntity.setMahSettleDeptId(input.getMahSettleDeptId());
+			// MAH结算提交给上级业务结算的标记
+			updateEntity.setMahSettleStep(UpmsType.MahSettleStep.BUSINESS);
+			// 这里是MAH业务提交到上级业务的情况,设为不可结算
+			updateEntity.setSettleFlag("0");
+			// 积分包状态设为已提交药企
+			updateEntity.setScorePackageStatus(ScorePackageStatusEnum.SUBMITTED_TO_DRUGENT.val());
+		} else {
+			updateEntity.setScorePackageStatus(ScorePackageStatusEnum.SETTLEMENT_SUBMITTED.val());
+			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);
+
+		if (SubjectLocation.MAH_SETTLE.equals(input.getSubjectLocation())) {
+			// 给上级企业标记未读提醒
+			wmBizReminderService.markUnread(UpmsType.BizReminderType.ASSIGN_POINTS_OTHER_REMINDER, input.getMahSettleDeptId());
+		}
+
+		return R.ok(Boolean.TRUE);
+	}
+
+	/**
+	 * 业务提交结算信息到财务-MAH(药企的个人承接-其他-结算)
+	 *
+	 * @param input 输入信息
+	 * @return 提交结果
+	 */
+	@Override
+	public R<?> settleSubmitForMah(WmScorePackageSettleInput input) {
+
+		WmScorePackage wmScorePackage = wmScorePackageService.getById(input.getId());
+
+		if (!ScorePackageStatusEnum.SUBMITTED_TO_DRUGENT.getVal().equals(wmScorePackage.getScorePackageStatus())) {
+			return R.failed("积分包状态不正确");
+		}
+
+		// 校验基本包状态
+		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.setMahSettleTime(LocalDateTime.now());
+		updateEntity.setMahSettleDeptId(deptId);
+		// 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");
@@ -510,6 +619,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);
+	}
+
 	/**
 	 * 重新结算
 	 *
@@ -584,13 +738,6 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		// 结算配置信息
 		HnqzUser operator = SecurityUtils.getUser();
 
-		if (SubjectLocation.MAH_SETTLE.equals(wmScorePackage.getLocation())) {
-			// MAH结算的情况-标记
-			input.setMahSettleDeptId(operator.getDeptId());
-		} else {
-			input.setMahSettleDeptId(null);
-		}
-
 		SysDeptSub sysDeptSub = sysDeptSubService.getDeptSub(operator.getDeptId(), location);
 		SysDept sysDept = sysDeptService.getById(sysDeptSub.getDeptId());
 		String taxCode = sysDept.getTaxCode();
@@ -674,18 +821,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -870,18 +1008,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -1073,18 +1202,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -1271,18 +1391,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -1478,18 +1589,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -1678,18 +1780,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -1889,18 +1982,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -2094,18 +2178,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		for (WmScorePackageSettleNote note : notes) {
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
-
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {
@@ -2245,17 +2320,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 
 			SysUser sysUser = sysUserMapper.selectById(note.getUserId());
 
-			Integer deptId;
-			// MAH结算校验原企业认证信息
-			if (input.getMahSettleDeptId() != null) {
-				deptId = sysUser.getDeptId();
-			} else {
-				deptId = operator.getDeptId();
-			}
 			SysUserSub userSub = sysUserSubMapper.selectOne(Wrappers.<SysUserSub>lambdaQuery()
 					.eq(SysUserSub::getUserId, sysUser.getUserId())
 					.eq(SysUserSub::getSubjectLocation, input.getSubjectLocation())
-					.eq(SysUserSub::getDeptId, deptId)
 			);
 
 			if (userSub == null) {

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

@@ -2807,8 +2807,9 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
 			throw new RuntimeException("不支持该积分包类型");
 		}
 		// 业务校验1
-		if (!ScorePackageStatusEnum.TO_BE_SETTLED.val().equals(scorePackage.getScorePackageStatus())) {
-			throw new RuntimeException("只有“已完成待结算”的积分包可以拆包");
+		if (!ScorePackageStatusEnum.TO_BE_SETTLED.val().equals(scorePackage.getScorePackageStatus())
+				&& !ScorePackageStatusEnum.SUBMITTED_TO_DRUGENT.val().equals(scorePackage.getScorePackageStatus())) {
+			throw new RuntimeException("积分包状态不支持拆包");
 		}
 		// 原审核通过的任务列表
 		QueryWrapper<WmTask> queryWrapper = Wrappers.query();

+ 18 - 2
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmScorePackageMapper.xml

@@ -1435,6 +1435,9 @@
 		<if test="query.mahSettleDeptId != null">
 			AND p.mah_settle_dept_id = #{query.mahSettleDeptId}
 		</if>
+		<if test="query.mahSettleStep != null">
+			AND p.mah_settle_step = #{query.mahSettleStep.type}
+		</if>
 		<if test="query.sendPackageDeptId != null and query.sendPackageDeptId != ''">
 			AND p.send_package_dept_id= #{query.sendPackageDeptId}
 		</if>
@@ -1463,7 +1466,12 @@
 			AND p.sub_type= #{query.subType}
 		</if>
 		ORDER BY
-		p.create_time DESC
+		<if test="query.mahSettleStep != null">
+			p.mah_settle_time DESC
+		</if>
+		<if test="query.mahSettleStep == null">
+			p.create_time DESC
+		</if>
 	</select>
 
 	<!-- 积分包结算(分页) -->
@@ -1491,6 +1499,9 @@
 			<if test="query.mahSettleDeptId != null">
 				AND p.mah_settle_dept_id = #{query.mahSettleDeptId}
 			</if>
+			<if test="query.mahSettleStep != null">
+				AND p.mah_settle_step = #{query.mahSettleStep.type}
+			</if>
 			<if test="query.sendPackageDeptId != null and query.sendPackageDeptId != ''">
 				AND p.send_package_dept_id= #{query.sendPackageDeptId}
 			</if>
@@ -1526,7 +1537,12 @@
 			</if>
 		</where>
 		ORDER BY
-		p.create_time DESC
+		<if test="query.mahSettleStep != null">
+			p.mah_settle_time DESC
+		</if>
+		<if test="query.mahSettleStep == null">
+			p.create_time DESC
+		</if>
 	</select>
 
 	<!-- 积分包结算列表 -->