|
@@ -204,49 +204,34 @@ public class InstitutionService {
|
|
|
*/
|
|
*/
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public InstitutionVO create(InstitutionCreateDTO dto) {
|
|
public InstitutionVO create(InstitutionCreateDTO dto) {
|
|
|
- // 如果携带适用范围数据,走完整串联流程
|
|
|
|
|
- if (StrUtil.isNotBlank(dto.getApplicableScope()) && !"none".equals(dto.getApplicableScope())) {
|
|
|
|
|
- Map<String, Object> data = new LinkedHashMap<>();
|
|
|
|
|
- data.put("institution_name", dto.getInstitutionName());
|
|
|
|
|
- data.put("institution_desc", dto.getInstitutionDesc());
|
|
|
|
|
- data.put("enterprise_id", dto.getEnterpriseId());
|
|
|
|
|
- data.put("scene_type", dto.getSceneType());
|
|
|
|
|
- data.put("expense_type", dto.getExpenseType());
|
|
|
|
|
- data.put("expense_sub_type", dto.getExpenseSubType());
|
|
|
|
|
- data.put("effective", dto.getEffective());
|
|
|
|
|
- data.put("effective_start_date", dto.getEffectiveStartDate());
|
|
|
|
|
- data.put("effective_end_date", dto.getEffectiveEndDate());
|
|
|
|
|
- data.put("consult_mode", dto.getConsultMode());
|
|
|
|
|
- data.put("multi_employee_share_mode", dto.getMultiEmployeeShareMode());
|
|
|
|
|
- data.put("grant_mode", dto.getGrantMode());
|
|
|
|
|
- data.put("period_type", dto.getPeriodType());
|
|
|
|
|
- data.put("amount", dto.getAmount());
|
|
|
|
|
- data.put("single_limit", dto.getSingleLimit());
|
|
|
|
|
- data.put("effective_time_type", dto.getEffectiveTimeType());
|
|
|
|
|
- data.put("applicable_scope", dto.getApplicableScope());
|
|
|
|
|
- data.put("currency", dto.getCurrency());
|
|
|
|
|
- data.put("scope_owner_id_list", dto.getScopeOwnerIdList());
|
|
|
|
|
- data.put("scope_owner_type", dto.getScopeOwnerType());
|
|
|
|
|
- data.put("standard_info_list", dto.getStandardInfoList());
|
|
|
|
|
- return createFullFlow(data);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 简单模式:仅创建制度记录
|
|
|
|
|
- String institutionId = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
|
- ExpenseInstitutionEntity entity = BeanUtil.copyProperties(dto, ExpenseInstitutionEntity.class);
|
|
|
|
|
- entity.setInstitutionId(institutionId);
|
|
|
|
|
- // expense_type 映射: GENERAL → DEFAULT (对应 Python controller)
|
|
|
|
|
- if ("GENERAL".equals(entity.getExpenseType())) {
|
|
|
|
|
- entity.setExpenseType("DEFAULT");
|
|
|
|
|
- }
|
|
|
|
|
- // 制度状态不允许外部传入,始终由服务端控制
|
|
|
|
|
- entity.setStatus(InstitutionEnums.InstitutionStatus.INSTITUTION_CREATE.getValue());
|
|
|
|
|
- if (StrUtil.isBlank(entity.getCurrency())) {
|
|
|
|
|
- entity.setCurrency("CNY");
|
|
|
|
|
- }
|
|
|
|
|
- institutionMapper.insert(entity);
|
|
|
|
|
- log.info("创建费控制度成功: institutionId={}, name={}", institutionId, dto.getInstitutionName());
|
|
|
|
|
- return BeanUtil.copyProperties(institutionMapper.selectById(entity.getId()), InstitutionVO.class);
|
|
|
|
|
|
|
+ // 统一走完整串联流程(对应 Python: 始终调 create_institution_full_flow)
|
|
|
|
|
+ Map<String, Object> data = new LinkedHashMap<>();
|
|
|
|
|
+ data.put("institution_name", dto.getInstitutionName());
|
|
|
|
|
+ data.put("institution_desc", dto.getInstitutionDesc());
|
|
|
|
|
+ data.put("enterprise_id", dto.getEnterpriseId());
|
|
|
|
|
+ data.put("scene_type", dto.getSceneType());
|
|
|
|
|
+ data.put("expense_type", dto.getExpenseType());
|
|
|
|
|
+ data.put("expense_sub_type", dto.getExpenseSubType());
|
|
|
|
|
+ data.put("effective", dto.getEffective());
|
|
|
|
|
+ data.put("effective_start_date", dto.getEffectiveStartDate() != null ? dto.getEffectiveStartDate().toString() : null);
|
|
|
|
|
+ data.put("effective_end_date", dto.getEffectiveEndDate() != null ? dto.getEffectiveEndDate().toString() : null);
|
|
|
|
|
+ data.put("consult_mode", dto.getConsultMode());
|
|
|
|
|
+ data.put("multi_employee_share_mode", dto.getMultiEmployeeShareMode());
|
|
|
|
|
+ data.put("grant_mode", dto.getGrantMode());
|
|
|
|
|
+ data.put("period_type", dto.getPeriodType());
|
|
|
|
|
+ data.put("amount", dto.getAmount());
|
|
|
|
|
+ data.put("single_limit", dto.getSingleLimit());
|
|
|
|
|
+ data.put("effective_time_type", dto.getEffectiveTimeType());
|
|
|
|
|
+ data.put("applicable_scope", dto.getApplicableScope());
|
|
|
|
|
+ data.put("currency", dto.getCurrency());
|
|
|
|
|
+ data.put("scope_owner_id_list", dto.getScopeOwnerIdList());
|
|
|
|
|
+ data.put("scope_owner_type", dto.getScopeOwnerType());
|
|
|
|
|
+ data.put("standard_info_list", dto.getStandardInfoList() != null ? dto.getStandardInfoList() : List.of());
|
|
|
|
|
+ // 对应 Python: name → institution_name
|
|
|
|
|
+ if (data.get("institution_name") == null && dto.getInstitutionName() == null) {
|
|
|
|
|
+ data.put("institution_name", "默认制度");
|
|
|
|
|
+ }
|
|
|
|
|
+ return createFullFlow(data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -319,7 +304,41 @@ public class InstitutionService {
|
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
|
List<Map<String, Object>> standardInfoList =
|
|
List<Map<String, Object>> standardInfoList =
|
|
|
(List<Map<String, Object>>) data.get("standard_info_list");
|
|
(List<Map<String, Object>>) data.get("standard_info_list");
|
|
|
- if (standardInfoList != null && !standardInfoList.isEmpty()) {
|
|
|
|
|
|
|
+ if (standardInfoList == null || standardInfoList.isEmpty()) {
|
|
|
|
|
+ // 对应 Python: 前端不传时自动构造默认使用规则
|
|
|
|
|
+ String instName = (String) data.getOrDefault("institution_name", data.get("name"));
|
|
|
|
|
+ StandardInfo defaultStd = new StandardInfo();
|
|
|
|
|
+ defaultStd.setStandardName(instName != null ? instName : "默认规则");
|
|
|
|
|
+ defaultStd.setStandardDesc("通用规则");
|
|
|
|
|
+ defaultStd.setStandardId("");
|
|
|
|
|
+ defaultStd.setOuterSourceId(java.util.UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
|
+ defaultStd.setConsumeMode("DEFAULT");
|
|
|
|
|
+ defaultStd.setPaymentPolicy("PERSONAL");
|
|
|
|
|
+ defaultStd.setPersonalQrcodeMode(0L);
|
|
|
|
|
+ // 默认条件
|
|
|
|
|
+ java.util.List<StandardConditionInfo> condList = new java.util.ArrayList<>();
|
|
|
|
|
+ StandardConditionInfo defaultCond = new StandardConditionInfo();
|
|
|
|
|
+ defaultCond.setRuleFactor("QUOTA_TOTAL");
|
|
|
|
|
+ defaultCond.setRuleValue(String.valueOf(data.getOrDefault("single_limit", "0")));
|
|
|
|
|
+ condList.add(defaultCond);
|
|
|
|
|
+ defaultStd.setStandardConditionInfoList(condList);
|
|
|
|
|
+ createModel.setStandardInfoList(java.util.List.of(defaultStd));
|
|
|
|
|
+
|
|
|
|
|
+ // 回写到 data,确保后续本地DB保存步骤能写入 pay_expense_rule
|
|
|
|
|
+ Map<String, Object> defaultStdMap = new LinkedHashMap<>();
|
|
|
|
|
+ defaultStdMap.put("outer_source_id", defaultStd.getOuterSourceId());
|
|
|
|
|
+ defaultStdMap.put("standard_id", defaultStd.getStandardId());
|
|
|
|
|
+ defaultStdMap.put("standard_name", defaultStd.getStandardName());
|
|
|
|
|
+ defaultStdMap.put("standard_desc", defaultStd.getStandardDesc());
|
|
|
|
|
+ defaultStdMap.put("expense_type_sub_category", "DEFAULT");
|
|
|
|
|
+ java.util.List<Map<String, Object>> defaultCondMapList = new java.util.ArrayList<>();
|
|
|
|
|
+ Map<String, Object> defaultCondMap = new LinkedHashMap<>();
|
|
|
|
|
+ defaultCondMap.put("rule_factor", "QUOTA_TOTAL");
|
|
|
|
|
+ defaultCondMap.put("rule_value", String.valueOf(data.getOrDefault("single_limit", "0")));
|
|
|
|
|
+ defaultCondMapList.add(defaultCondMap);
|
|
|
|
|
+ defaultStdMap.put("standard_condition_info_list", defaultCondMapList);
|
|
|
|
|
+ data.put("standard_info_list", java.util.List.of(defaultStdMap));
|
|
|
|
|
+ } else {
|
|
|
List<StandardInfo> stdList = new java.util.ArrayList<>();
|
|
List<StandardInfo> stdList = new java.util.ArrayList<>();
|
|
|
for (Map<String, Object> std : standardInfoList) {
|
|
for (Map<String, Object> std : standardInfoList) {
|
|
|
StandardInfo si = new StandardInfo();
|
|
StandardInfo si = new StandardInfo();
|
|
@@ -489,13 +508,17 @@ public class InstitutionService {
|
|
|
|
|
|
|
|
// --- 第4步: 保存制度到本地DB ---
|
|
// --- 第4步: 保存制度到本地DB ---
|
|
|
ExpenseInstitutionEntity entity = new ExpenseInstitutionEntity();
|
|
ExpenseInstitutionEntity entity = new ExpenseInstitutionEntity();
|
|
|
|
|
+ // 从认证上下文获取 tenantId
|
|
|
|
|
+ Long tenantId = getCurrentTenantId();
|
|
|
|
|
+ if (tenantId != null) entity.setTenantId(tenantId);
|
|
|
entity.setInstitutionId(institutionId);
|
|
entity.setInstitutionId(institutionId);
|
|
|
entity.setInstitutionName(institutionName);
|
|
entity.setInstitutionName(institutionName);
|
|
|
entity.setInstitutionDesc((String) data.get("institution_desc"));
|
|
entity.setInstitutionDesc((String) data.get("institution_desc"));
|
|
|
entity.setEnterpriseId(enterpriseId);
|
|
entity.setEnterpriseId(enterpriseId);
|
|
|
entity.setSceneType((String) data.get("scene_type"));
|
|
entity.setSceneType((String) data.get("scene_type"));
|
|
|
entity.setExpenseType(expenseType);
|
|
entity.setExpenseType(expenseType);
|
|
|
- entity.setExpenseSubType((String) data.get("expense_sub_type"));
|
|
|
|
|
|
|
+ String expenseSubType = (String) data.get("expense_sub_type");
|
|
|
|
|
+ entity.setExpenseSubType(expenseSubType != null ? expenseSubType : "DEFAULT");
|
|
|
entity.setStatus(InstitutionEnums.InstitutionStatus.INSTITUTION_CREATE.getValue());
|
|
entity.setStatus(InstitutionEnums.InstitutionStatus.INSTITUTION_CREATE.getValue());
|
|
|
entity.setCurrency((String) data.getOrDefault("currency", "CNY"));
|
|
entity.setCurrency((String) data.getOrDefault("currency", "CNY"));
|
|
|
entity.setEffective((String) data.getOrDefault("effective", "1"));
|
|
entity.setEffective((String) data.getOrDefault("effective", "1"));
|
|
@@ -566,6 +589,7 @@ public class InstitutionService {
|
|
|
rule.setExpenseTypeSubCategory(
|
|
rule.setExpenseTypeSubCategory(
|
|
|
(String) std.getOrDefault("expense_type_sub_category", "DEFAULT"));
|
|
(String) std.getOrDefault("expense_type_sub_category", "DEFAULT"));
|
|
|
rule.setEnterpriseId(enterpriseId);
|
|
rule.setEnterpriseId(enterpriseId);
|
|
|
|
|
+ rule.setTenantId(tenantId);
|
|
|
rule.setSingleLimit(singleLimitVal);
|
|
rule.setSingleLimit(singleLimitVal);
|
|
|
|
|
|
|
|
// 序列化 condition_info 为 JSON
|
|
// 序列化 condition_info 为 JSON
|
|
@@ -1295,7 +1319,7 @@ public class InstitutionService {
|
|
|
private LambdaQueryWrapper<ExpenseInstitutionEntity> buildQuery(InstitutionQueryDTO q) {
|
|
private LambdaQueryWrapper<ExpenseInstitutionEntity> buildQuery(InstitutionQueryDTO q) {
|
|
|
LambdaQueryWrapper<ExpenseInstitutionEntity> w = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<ExpenseInstitutionEntity> w = new LambdaQueryWrapper<>();
|
|
|
if (q == null) return w;
|
|
if (q == null) return w;
|
|
|
- if (StrUtil.isNotBlank(q.getEnterpriseId())) w.eq(ExpenseInstitutionEntity::getEnterpriseId, q.getEnterpriseId());
|
|
|
|
|
|
|
+ if (StrUtil.isNotBlank(q.getEnterprise_id())) w.eq(ExpenseInstitutionEntity::getEnterpriseId, q.getEnterprise_id());
|
|
|
// 支持 name 和 institutionName 两种前端参数 (对应 Python: name or institution_name)
|
|
// 支持 name 和 institutionName 两种前端参数 (对应 Python: name or institution_name)
|
|
|
String instName = StrUtil.isNotBlank(q.getInstitutionName()) ? q.getInstitutionName() : q.getName();
|
|
String instName = StrUtil.isNotBlank(q.getInstitutionName()) ? q.getInstitutionName() : q.getName();
|
|
|
if (StrUtil.isNotBlank(instName)) w.like(ExpenseInstitutionEntity::getInstitutionName, instName);
|
|
if (StrUtil.isNotBlank(instName)) w.like(ExpenseInstitutionEntity::getInstitutionName, instName);
|
|
@@ -1611,4 +1635,13 @@ public class InstitutionService {
|
|
|
.filter(StrUtil::isNotBlank)
|
|
.filter(StrUtil::isNotBlank)
|
|
|
.collect(Collectors.toSet());
|
|
.collect(Collectors.toSet());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private Long getCurrentTenantId() {
|
|
|
|
|
+ var auth = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
+ if (auth != null && auth.getPrincipal() instanceof com.payment.platform.core.security.LoginUser user) {
|
|
|
|
|
+ return user.getTenantId();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|