|
@@ -16,18 +16,29 @@
|
|
|
*/
|
|
|
package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.SysDeptSub;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmDaAgent;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmDaDrugEnt;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.DeptSubLimitAmountInput;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.input.SettleAmountMonitorInput;
|
|
|
import com.qunzhixinxi.hnqz.admin.entity.output.SettleAmountMonitorOutput;
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.EnableEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.SubjectTypeEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.SysDeptMapper;
|
|
|
import com.qunzhixinxi.hnqz.admin.mapper.SysDeptSubMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.WmDaAgentMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.WmDaDrugEntMapper;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.SysDeptSubService;
|
|
|
import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -43,6 +54,12 @@ public class SysDeptSubServiceImpl extends ServiceImpl<SysDeptSubMapper, SysDept
|
|
|
|
|
|
private final SysDeptSubMapper sysDeptSubMapper;
|
|
|
|
|
|
+ private final SysDeptMapper sysDeptMapper;
|
|
|
+
|
|
|
+ private final WmDaAgentMapper wmDaAgentMapper;
|
|
|
+
|
|
|
+ private final WmDaDrugEntMapper wmDaDrugEntMapper;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public R updateSubLimitAmount(DeptSubLimitAmountInput input) {
|
|
@@ -64,4 +81,72 @@ public class SysDeptSubServiceImpl extends ServiceImpl<SysDeptSubMapper, SysDept
|
|
|
public List<SettleAmountMonitorOutput> getDeptAmountMonitor(SettleAmountMonitorInput input) {
|
|
|
return sysDeptSubMapper.getDeptAmountMonitor(input);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算管理配置
|
|
|
+ *
|
|
|
+ * @param input
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void saveSettleConfig(DeptSubLimitAmountInput input) {
|
|
|
+ // 更新结算主体
|
|
|
+ String[] subTypeArr = input.getSubList().stream()
|
|
|
+ .map(SysDeptSub::getSubjectType)
|
|
|
+ .toArray(String[]::new);
|
|
|
+ SysDept dept = sysDeptMapper.selectById(input.getDeptId());
|
|
|
+ if (dept.getLevel() == 2) {
|
|
|
+ // 药企
|
|
|
+ wmDaDrugEntMapper.update(null, Wrappers.<WmDaDrugEnt>lambdaUpdate()
|
|
|
+ .eq(WmDaDrugEnt::getDeptId, String.valueOf(input.getDeptId()))
|
|
|
+ .eq(WmDaDrugEnt::getEnableFlag, EnableEnum.ENABLE.val())
|
|
|
+ .eq(WmDaDrugEnt::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
+ .set(WmDaDrugEnt::getSubjectType, subTypeArr));
|
|
|
+ } else if (dept.getLevel() == 3) {
|
|
|
+ // 更新agent
|
|
|
+ wmDaAgentMapper.update(null, Wrappers.<WmDaAgent>lambdaUpdate()
|
|
|
+ .eq(WmDaAgent::getDeptId, String.valueOf(input.getDeptId()))
|
|
|
+ .eq(WmDaAgent::getEnableFlag, EnableEnum.ENABLE.val())
|
|
|
+ .eq(WmDaAgent::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
+ .set(WmDaAgent::getSubjectType, subTypeArr));
|
|
|
+ }
|
|
|
+ // 更新dept
|
|
|
+ sysDeptMapper.update(null, Wrappers.<SysDept>lambdaUpdate()
|
|
|
+ .eq(SysDept::getDeptId, input.getDeptId())
|
|
|
+ .set(SysDept::getSubjectType, subTypeArr));
|
|
|
+ // 更新/保存deptSub
|
|
|
+ // 先设置所有deptSub为无效
|
|
|
+ SysDeptSub deptSubWhere = new SysDeptSub();
|
|
|
+ deptSubWhere.setDeptId(input.getDeptId());
|
|
|
+ sysDeptSubMapper.update(deptSubWhere, Wrappers.<SysDeptSub>lambdaUpdate()
|
|
|
+ .eq(SysDeptSub::getDeptId, input.getDeptId())
|
|
|
+ .set(SysDeptSub::getEnableFlag, SubjectTypeEnum.ENABLE_FLAG_FALSE.getCode()));
|
|
|
+
|
|
|
+ input.getSubList().forEach(sysDeptSub -> {
|
|
|
+ SysDeptSub queryDeptSub = sysDeptSubMapper.selectOne(Wrappers.<SysDeptSub>lambdaQuery()
|
|
|
+ .eq(SysDeptSub::getDeptId, input.getDeptId())
|
|
|
+ .eq(SysDeptSub::getSubjectType, sysDeptSub.getSubjectType()));
|
|
|
+ if (queryDeptSub != null) {
|
|
|
+ // 更新
|
|
|
+ SysDeptSub updateDeptSub = new SysDeptSub();
|
|
|
+ updateDeptSub.setSubId(queryDeptSub.getSubId());
|
|
|
+ updateDeptSub.setSubjectChannel(sysDeptSub.getSubjectChannel() == null ? 0 : sysDeptSub.getSubjectChannel());
|
|
|
+ updateDeptSub.setSubjectInvoiceCategory(sysDeptSub.getSubjectInvoiceCategory());
|
|
|
+ updateDeptSub.setLimitAmount(sysDeptSub.getLimitAmount());
|
|
|
+ updateDeptSub.setEnableFlag(SubjectTypeEnum.ENABLE_FLAG_TRUE.getCode());
|
|
|
+ updateDeptSub.setUpdateTime(LocalDateTime.now());
|
|
|
+ sysDeptSubMapper.updateById(updateDeptSub);
|
|
|
+ } else {
|
|
|
+ // 新增
|
|
|
+ SysDeptSub insertDeptSub = new SysDeptSub();
|
|
|
+ insertDeptSub.setDeptId(input.getDeptId());
|
|
|
+ insertDeptSub.setSubjectType(sysDeptSub.getSubjectType());
|
|
|
+ insertDeptSub.setSubjectChannel(sysDeptSub.getSubjectChannel() == null ? 0 : sysDeptSub.getSubjectChannel());
|
|
|
+ insertDeptSub.setSubjectInvoiceCategory(sysDeptSub.getSubjectInvoiceCategory());
|
|
|
+ insertDeptSub.setLimitAmount(sysDeptSub.getLimitAmount());
|
|
|
+ insertDeptSub.setEnableFlag(SubjectTypeEnum.ENABLE_FLAG_TRUE.getCode());
|
|
|
+ sysDeptSubMapper.insert(insertDeptSub);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|