Browse Source

feat: MAH支付-提交结算部分1

李学松 2 years ago
parent
commit
7711624466

+ 8 - 1
db/v2.0/230710.sql

@@ -1,2 +1,9 @@
 alter table wm_da_agent
-    add mah_settle_flag tinyint default 0 null comment '是否允许结算';
+    add mah_settle_dept_id int null comment 'MAH结算-药企deptId';
+
+alter table wm_score_package
+    add mah_settle_dept_id int null comment 'MAH结算-药企deptId';
+
+create index wm_score_package_mah_settle_dept_id_index
+    on wm_score_package (mah_settle_dept_id);
+

+ 59 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/SysDeptSubController.java

@@ -6,9 +6,16 @@ import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDeptRelation;
+import com.qunzhixinxi.hnqz.admin.entity.WmDaAgent;
+import com.qunzhixinxi.hnqz.admin.entity.WmDaDrugEnt;
 import com.qunzhixinxi.hnqz.admin.entity.dto.SettleConfigDTO;
 import com.qunzhixinxi.hnqz.admin.entity.input.DeptSubLimitAmountInput;
+import com.qunzhixinxi.hnqz.admin.enums.SubjectLocation;
 import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
+import com.qunzhixinxi.hnqz.admin.service.SysDeptRelationService;
+import com.qunzhixinxi.hnqz.admin.service.WmDaAgentService;
+import com.qunzhixinxi.hnqz.admin.service.WmDaDrugEntService;
 import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
 import com.qunzhixinxi.hnqz.admin.entity.SysDeptSub;
@@ -24,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 /**
@@ -39,6 +47,57 @@ import java.util.List;
 public class SysDeptSubController {
 
     private final  SysDeptSubService sysDeptSubService;
+	private final SysDeptRelationService sysDeptRelationService;
+	private final WmDaAgentService wmDaAgentService;
+	private final WmDaDrugEntService wmDaDrugEntService;
+
+	/**
+	 * 查询结算渠道(用于结算页面)
+	 *
+	 * @return 结果
+	 */
+	@GetMapping("/get-settle-subject")
+	public R getSettleSubejct() {
+		Integer deptId = SecurityUtils.getUser().getDeptId();
+		List<SysDeptSub> resultList = new ArrayList<>();
+
+		// 原有结算渠道
+		SysDeptSub sysDeptSub = new SysDeptSub();
+		sysDeptSub.setDeptId(deptId);
+		sysDeptSub.setEnableFlag(SubjectTypeEnum.ENABLE_FLAG_TRUE.getCode());
+		List<SysDeptSub> subList = sysDeptSubService.list(Wrappers.query(sysDeptSub));
+		if (CollUtil.isNotEmpty(subList)) {
+			resultList.addAll(subList);
+		}
+
+		// MAH结算渠道-拼接上级药企作为渠道名称
+		WmDaAgent daAgent = wmDaAgentService.getOne(Wrappers.<WmDaAgent>lambdaQuery()
+				.eq(WmDaAgent::getDeptId, deptId));
+		if(daAgent!= null) {
+            if (daAgent.getMahSettleDeptId() != null) {
+				// 查询上级药企
+				List<SysDeptRelation> deptRelations = sysDeptRelationService.list(Wrappers.<SysDeptRelation>lambdaQuery()
+						.eq(SysDeptRelation::getDescendant, deptId)
+						.ne(SysDeptRelation::getAncestor, deptId)
+						.ne(SysDeptRelation::getAncestor, 1));
+				if (CollUtil.isNotEmpty(deptRelations)) {
+					List<WmDaDrugEnt> drugEnts = wmDaDrugEntService.list(Wrappers.<WmDaDrugEnt>lambdaQuery()
+							.in(WmDaDrugEnt::getDeptId, deptRelations.stream().map(SysDeptRelation::getAncestor).collect(Collectors.toSet())));
+					drugEnts.forEach(drugEnt -> {
+						SysDeptSub newDeptSub = new SysDeptSub();
+						newDeptSub.setDeptId(Integer.valueOf(drugEnt.getDeptId()));
+						newDeptSub.setSubjectLocation(SubjectLocation.MAH_SETTLE);
+						newDeptSub.setSubjectType(String.valueOf(SubjectLocation.MAH_SETTLE.getGigType().getCode()));
+						newDeptSub.setSubjectName(drugEnt.getEntname());
+						resultList.add(newDeptSub);
+					});
+                }
+
+			}
+        }
+
+		return R.ok(resultList);
+	}
 
 	/**
 	 * 查询结算渠道列表-无参

+ 8 - 4
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmDaAgentController.java

@@ -858,10 +858,14 @@ public class WmDaAgentController {
 			return R.failed("必填参数不能为空");
 		}
 
-		WmDaAgent update = new WmDaAgent();
-		update.setId(wmDaAgent.getId());
-		update.setMahSettleFlag(wmDaAgent.getMahSettleFlag());
+		Integer mahSettleDeptId = null;
+		if (Boolean.TRUE.equals(wmDaAgent.getMahSettleFlag())) {
+			// 如果是允许结算,则保存当前药企deptId
+			mahSettleDeptId = SecurityUtils.getUser().getDeptId();
+		}
 
-		return R.ok(wmDaAgentService.updateById(update));
+		return R.ok(wmDaAgentService.update(Wrappers.<WmDaAgent>lambdaUpdate()
+				.eq(WmDaAgent::getId, wmDaAgent.getId())
+				.set(WmDaAgent::getMahSettleDeptId, mahSettleDeptId)));
 	}
 }

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

@@ -184,9 +184,15 @@ public class WmDaAgent extends Model<WmDaAgent> {
 	@ApiModelProperty(value="结算主体类型")
 	private String[] subjectType;
 
+	/**
+	 * MAH结算-药企deptId
+	 */
+	private Integer mahSettleDeptId;
+
 	/**
 	 * 是否允许结算(选择“允许结算”时,相当于打开了MAH支付权限,该CSO结算时可以选择药企,走药企结算。)
 	 */
+	@TableField(exist = false)
 	private Boolean mahSettleFlag;
 
 	@ApiModelProperty(value="结算主体类型和通道")

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

@@ -554,6 +554,11 @@ public class WmScorePackage extends Model<WmScorePackage> {
 	@ApiModelProperty(value = "关联药品的生产厂商列表")
 	private String[] drugProducerList;
 
+	/**
+	 * MAH结算-药企deptId
+	 */
+	private Integer mahSettleDeptId;
+
 	@AllArgsConstructor
 	public enum PackageStopStatus {
 		NOTHING(0, "不能操作"),

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

@@ -209,6 +209,12 @@ public class WmScorePackageSettleNote extends Model<WmScorePackageSettleNote> {
 	@TableField(exist = false)
 	private LocalDateTime endSubTime;
 
+	/**
+	 * MAH结算-药企deptId
+	 */
+	@TableField(exist = false)
+	private Integer mahSettleDeptId;
+
 	/**
 	 * 获取发票类目
 	 * @Modify: start

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

@@ -87,6 +87,11 @@ public class WmScorePackageSettleInput implements Serializable {
 	// 税源地
 	private SubjectLocation subjectLocation;
 
+	/**
+	 * MAH结算-药企deptId
+	 */
+	private Integer mahSettleDeptId;
+
 	/**
 	 * 结算人员
 	 */

+ 3 - 8
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/GigTypeEnum.java

@@ -24,8 +24,9 @@ public enum GigTypeEnum {
 	LANG_CHAO(5, "浪潮", "浪潮", LangChaoCertStatus.class),
 	HUI_QI_YUN(6, "汇企云", "汇企云", HuiQiYunCertStatus.class),
 	ZHONG_YI_YUN(7, "众蚁云", "众蚁云", ZhongYiYunCertStatus.class),
-	ZHONG_ZHI(8, "中智", "中智", ZhongZhiCertStatus.class);
-//	HAN_TANG(9, "汉唐", "汉唐", HanTangCertStatus.class);
+	ZHONG_ZHI(8, "中智", "中智", ZhongZhiCertStatus.class),
+
+	MAH_SETTLE(9999, "MAH结算", "MAH结算", null);
 
 	@EnumValue
 	private int code;
@@ -79,9 +80,6 @@ public enum GigTypeEnum {
 			case ZHONG_YI_YUN:
 				certStatusStr = ZhongYiYunCertStatus.resolve(certStatus).name();
 				break;
-//			case HAN_TANG:
-//				certStatusStr = HanTangCertStatus.resolve(certStatus).name();
-//				break;
 			case ZHONG_ZHI:
 				certStatusStr = ZhongZhiCertStatus.resolve(certStatus).name();
 				break;
@@ -125,9 +123,6 @@ public enum GigTypeEnum {
 			case ZHONG_YI_YUN:
 				certStatusStr = ZhongYiYunCertStatus.resolve(certStatus).getMessage();
 				break;
-//			case HAN_TANG:
-//				 certStatusStr = HanTangCertStatus.resolve(certStatus).getMessage();
-//				break;
 			case ZHONG_ZHI:
 				certStatusStr = ZhongZhiCertStatus.resolve(certStatus).getMessage();
 				break;

+ 4 - 3
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/enums/SubjectLocation.java

@@ -45,11 +45,12 @@ public enum SubjectLocation {
 
 	// 众蚁云
 	ZHONG_YI_YUN("ZHONG_YI_YUN", GigTypeEnum.ZHONG_YI_YUN, "众蚁云", 11, "zhong_yi_yun_invoice"),
-	// 汉唐
-//	HAN_TANG("HAN_TANG", GigTypeEnum.HAN_TANG, "汉唐", 12),
 	// 中智
 	ZHONG_ZHI("ZHONG_ZHI", GigTypeEnum.ZHONG_ZHI, "中智", 12, "zhongzhi_invoice"),
-	ZHAO_YU("ZHAO_YU", GigTypeEnum.OLADING, "钉灵工-河南兆宇", 13, "olading_zhaoyu_invoice");
+	ZHAO_YU("ZHAO_YU", GigTypeEnum.OLADING, "钉灵工-河南兆宇", 13, "olading_zhaoyu_invoice"),
+
+
+	MAH_SETTLE("MAH_SETTLE", GigTypeEnum.MAH_SETTLE, "MAH结算", 9999, "");
 
 	/**
 	 * 税源地类型

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

@@ -411,6 +411,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		updateEntity.setSubType(String.valueOf(location.getGigType().getCode()));
 		updateEntity.setLocation(input.getSubjectLocation());
 		updateEntity.setSettlementDate(LocalDateTime.now());
+		if (SubjectLocation.MAH_SETTLE.equals(input.getSubjectLocation())) {
+			updateEntity.setMahSettleDeptId(input.getMahSettleDeptId());
+		}
 
 		if (PackageTypeEnum.TYPE2_SETTLE_PACKAGE.val().equals(wmScorePackage.getPackageType2())
 				&& !StrUtil.equals(PackageTypeEnum.TYPE1_SCORE_AND_TASK_PACKAGE.val(), wmScorePackage.getPackageType1())) {
@@ -469,6 +472,9 @@ public class WmPayOffServiceImpl extends ServiceImpl<WmPayOffMapper, WmPayOff> i
 		updateEntity.setDescription(input.getDescription());
 		updateEntity.setSubType(String.valueOf(location.getGigType().getCode()));
 		updateEntity.setLocation(input.getSubjectLocation());
+		if (SubjectLocation.MAH_SETTLE.equals(input.getSubjectLocation())) {
+			updateEntity.setMahSettleDeptId(input.getMahSettleDeptId());
+		}
 
 		wmScorePackageService.updateById(updateEntity);
 		noteService.saveOrUpdateBatch(notes);

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

@@ -469,6 +469,7 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 
 			WmScorePackage wmScorePackage = wmScorePackageMapper.selectById(settleNote.getPackageId());
 			wmScorePackage.setSettlementDate(LocalDateTime.now());
+			wmScorePackage.setMahSettleDeptId(note.getMahSettleDeptId());
 			wmScorePackageMapper.updateById(wmScorePackage);
 			return R.ok();
 		} else {
@@ -493,6 +494,11 @@ public class WmScorePackageSettleNoteServiceImpl extends ServiceImpl<WmScorePack
 			entity.setIdCardNumber(user.getIdCardNumber());
 
 			this.baseMapper.insert(entity);
+
+			// 更新 MAH结算-药企deptId
+			wmScorePackageMapper.update(null, Wrappers.<WmScorePackage>lambdaUpdate()
+					.eq(WmScorePackage::getId, note.getPackageId())
+					.set(WmScorePackage::getMahSettleDeptId, note.getMahSettleDeptId()));
 		}
 
 		return R.ok();