Files
flow-center-service/src/main/java/com/yunhai/flowcenter/service/FlowMapAdminService.java
T
chenxing c1103aeb29
build / build-push (push) Successful in 28s
feat: 提交流程中心后端代码
Spring Boot 流程引擎服务:流程定义/实例/任务、审批人解析、
回调分发、oapi 接口及单元测试。
保留远程 .gitea/workflows/build.yml 与 docker/Dockerfile,
新增 .gitignore 排除 target/ 构建产物。
2026-09-15 10:42:56 +08:00

86 lines
3.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.yunhai.flowcenter.service;
import com.yunhai.flowcenter.entity.FlwAssigneeMap;
import com.yunhai.flowcenter.repository.FlwAssigneeMapRepository;
import com.yunhai.platform.apistd.BizException;
import com.yunhai.platform.utils.exception.ErrorCode;
import com.yunhai.platform.utils.model.BoaUser;
import com.yunhai.platform.openapi.client.OpenApiUserClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 办理人映射管理(概览 §4.7/§六):DEPT_KEY → 办理人显式映射,成员检索经
* UserBase /oapi/user/byId 补全姓名快照(检索按 id 精确查;按名检索二期接 UserBase 模糊端点)。
*/
@Service
@RequiredArgsConstructor
public class FlowMapAdminService {
private final FlwAssigneeMapRepository mapRepository;
private final OpenApiUserClient userClient;
public List<FlwAssigneeMap> listByDept(Long schId, String deptKey) {
if (deptKey == null || deptKey.trim().isEmpty()) {
return mapRepository.findEnabledBySchId(schId);
}
return mapRepository.findBySchIdAndDeptKeyOrderByUserIdAsc(schId, deptKey.trim());
}
/** 新增/启用映射(uk: sch+dept+user;已存在则刷新姓名/状态) */
@Transactional
public FlwAssigneeMap save(Long schId, String deptKey, String deptName,
Integer userId, String userName) {
if (deptKey == null || deptKey.trim().isEmpty() || userId == null) {
throw new BizException(ErrorCode.PARAM_ERROR, "deptKey/userId 必填");
}
if (userName == null || userName.trim().isEmpty()) {
userName = fetchName(userId);
}
FlwAssigneeMap map = mapRepository.findBySchIdAndDeptKeyAndUserId(schId, deptKey.trim(), userId);
if (map == null) {
map = new FlwAssigneeMap();
map.setSchId(schId);
map.setDeptKey(deptKey.trim());
map.setUserId(userId);
}
map.setDeptName(deptName);
map.setUserName(userName);
map.setStatus(0);
return mapRepository.save(map);
}
/** 停用映射(保留历史,DEPT_KEY 解析只取 status=0) */
@Transactional
public void disable(Long schId, Long id) {
FlwAssigneeMap map = mapRepository.findById(id)
.orElseThrow(() -> new BizException(ErrorCode.PARAM_ERROR, "映射不存在:" + id));
if (!map.getSchId().equals(schId)) {
throw new BizException(ErrorCode.FORBIDDEN, "映射不属于该学校");
}
map.setStatus(1);
mapRepository.save(map);
}
/** 成员检索:按用户 id 从 UserBase 取姓名快照(管理端录入校验) */
public BoaUser lookupUser(Integer userId) {
try {
return userClient.getUserById(String.valueOf(userId));
} catch (Exception e) {
throw new BizException(ErrorCode.PARAM_ERROR, "UserBase 用户检索失败(服务不可达)");
}
}
private String fetchName(Integer userId) {
try {
BoaUser user = userClient.getUserById(String.valueOf(userId));
return user == null ? "" : (user.getName() == null ? "" : user.getName());
} catch (Exception e) {
return "";
}
}
}