Compare commits

..

No commits in common. "5855307c4651c9b6533455b3c404a99e6df437df" and "4a42e7ad5f6cdf1027137fbaaca26e6e120a867e" have entirely different histories.

15 changed files with 8 additions and 703 deletions

View File

@ -1,5 +0,0 @@
-- 若已执行过仅含 code/name 的脚本再执行本增量脚本补充角色ID
-- 日期2026-07-22
ALTER TABLE `org_position`
ADD COLUMN `gbs_role_id` bigint DEFAULT NULL COMMENT '关联GBS角色ID' AFTER `duty_desc`;

View File

@ -1,234 +0,0 @@
package org.qinan.safetyeval.adapter.web;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.system.client.role.response.RoleCO;
import com.jjb.saas.system.client.user.request.RoleDeptAddCmd;
import com.jjb.saas.system.client.user.request.UserAppendRoleCmd;
import com.jjb.saas.system.client.user.request.UserRoleUpdateCmd;
import com.jjb.saas.system.client.user.response.UserDetailCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserInfo;
import org.qinan.safetyeval.infrastructure.adapter.gbs.GbsRoleFacadeClient;
import org.qinan.safetyeval.infrastructure.adapter.gbs.GbsUserFacadeClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* GBS UserFacade / RoleFacade token AuthContext
* <p>
* code=f3efa93b2639429687dc7e4175500a74=test02
* </p>
*/
@Api(tags = "测试-GBS用户角色")
@RestController
@RequestMapping("/safetyEval/test/gbs-user")
public class GbsUserFacadeTestController {
/** 目标角色编码UserRoleUpdateCmd.roleCodes */
public static final String TARGET_ROLE_CODE = "f3efa93b2639429687dc7e4175500a74";
/** 目标角色名称(仅文档/回显Cmd 无 name 字段传角色名) */
public static final String TARGET_ROLE_NAME = "test02";
@Resource
private GbsUserFacadeClient gbsUserFacadeClient;
@Resource
private GbsRoleFacadeClient gbsRoleFacadeClient;
@Value("${auth.deptId.org:#{null}}")
private Long defaultDeptId;
@ApiOperation("通过 token 查看当前登录用户AuthContext")
@GetMapping("/current")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> current() {
AuthUserInfo user = requireLogin();
Map<String, Object> data = new HashMap<String, Object>();
data.put("userId", user.getUserId());
data.put("userName", user.getUserName());
data.put("mobile", user.getMobile());
data.put("account", user.getAccount());
data.put("tenantId", user.getTenantId());
data.put("orgId", user.getOrgId());
return org.qinan.safetyeval.client.dto.SingleResponse.success(data);
}
@ApiOperation("通过 token 拉取 GBS 用户详情(含角色)")
@GetMapping("/detail")
public org.qinan.safetyeval.client.dto.SingleResponse<UserDetailCO> detail() {
AuthUserInfo user = requireLogin();
SingleResponse<UserDetailCO> remote = gbsUserFacadeClient.getDetail(user.getUserId());
return org.qinan.safetyeval.client.dto.SingleResponse.success(remote.getData());
}
@ApiOperation("角色列表RoleFacade.listRoles")
@GetMapping("/roles")
public org.qinan.safetyeval.client.dto.SingleResponse<List<RoleCO>> listRoles() {
requireLogin();
return org.qinan.safetyeval.client.dto.SingleResponse.success(gbsRoleFacadeClient.listRoles());
}
@ApiOperation("按角色编码查名称RoleFacade.getRoleNameByCode")
@GetMapping("/role-name")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> roleNameByCode(
@ApiParam(value = "角色编码", example = TARGET_ROLE_CODE)
@RequestParam(value = "roleCode", required = false) String roleCode) {
requireLogin();
String code = (roleCode == null || roleCode.trim().isEmpty()) ? TARGET_ROLE_CODE : roleCode.trim();
String name = gbsRoleFacadeClient.getRoleNameByCode(code);
Map<String, Object> data = new HashMap<String, Object>();
data.put("roleCode", code);
data.put("roleName", name);
return org.qinan.safetyeval.client.dto.SingleResponse.success(data);
}
@ApiOperation("将当前用户角色更新为 test02覆盖式roleCode=f3efa93b2639429687dc7e4175500a74")
@PostMapping("/update-role-to-test02")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> updateRoleToTest02() {
AuthUserInfo user = requireLogin();
UserRoleUpdateCmd cmd = buildRoleUpdateCmd(user, TARGET_ROLE_CODE);
Response response = gbsUserFacadeClient.updateUserRole(cmd);
return org.qinan.safetyeval.client.dto.SingleResponse.success(
roleOpResult(response, user, TARGET_ROLE_CODE, TARGET_ROLE_NAME, "updateUserRole"));
}
@ApiOperation("更新当前用户角色覆盖式roleCode 必填roleName 仅回显)")
@PostMapping("/update-role")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> updateRole(
@ApiParam(value = "角色编码", required = true, example = TARGET_ROLE_CODE)
@RequestParam("roleCode") String roleCode,
@ApiParam(value = "角色名称(仅回显,不参与 GBS 更新)", example = TARGET_ROLE_NAME)
@RequestParam(value = "roleName", required = false) String roleName) {
AuthUserInfo user = requireLogin();
if (roleCode == null || roleCode.trim().isEmpty()) {
throw new BizException(ErrorCode.UNKNOWN_ERROR.getCode(), "roleCode 不能为空");
}
String code = roleCode.trim();
String name = (roleName == null || roleName.trim().isEmpty()) ? null : roleName.trim();
UserRoleUpdateCmd cmd = buildRoleUpdateCmd(user, code);
Response response = gbsUserFacadeClient.updateUserRole(cmd);
return org.qinan.safetyeval.client.dto.SingleResponse.success(
roleOpResult(response, user, code, name, "updateUserRole"));
}
@ApiOperation("追加角色 test02按 roleCodesUserFacade.updateUserAppendRole")
@PostMapping("/append-role-to-test02")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> appendRoleToTest02() {
AuthUserInfo user = requireLogin();
UserRoleUpdateCmd cmd = buildRoleUpdateCmd(user, TARGET_ROLE_CODE);
Response response = gbsUserFacadeClient.updateUserAppendRole(cmd);
return org.qinan.safetyeval.client.dto.SingleResponse.success(
roleOpResult(response, user, TARGET_ROLE_CODE, TARGET_ROLE_NAME, "updateUserAppendRole"));
}
@ApiOperation("追加角色(按 roleDeptsUserFacade.appendUserRole默认角色 test02")
@PostMapping("/append-user-role")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> appendUserRole(
@ApiParam(value = "角色编码,默认 test02 的 code")
@RequestParam(value = "roleCode", required = false) String roleCode,
@ApiParam(value = "部门id默认 auth.deptId.org其次当前用户 orgId")
@RequestParam(value = "deptId", required = false) Long deptId) {
AuthUserInfo user = requireLogin();
String code = resolveRoleCode(roleCode);
Long resolvedDeptId = resolveDeptId(user, deptId);
UserAppendRoleCmd cmd = new UserAppendRoleCmd();
cmd.setId(user.getUserId());
RoleDeptAddCmd roleDept = new RoleDeptAddCmd();
roleDept.setRoleCode(code);
roleDept.setDeptId(resolvedDeptId);
cmd.setRoleDepts(Collections.singletonList(roleDept));
Response response = gbsUserFacadeClient.appendUserRole(cmd);
Map<String, Object> data = roleOpResult(response, user, code,
TARGET_ROLE_CODE.equals(code) ? TARGET_ROLE_NAME : null, "appendUserRole");
data.put("deptId", resolvedDeptId);
return org.qinan.safetyeval.client.dto.SingleResponse.success(data);
}
@ApiOperation("追加角色按编码UserFacade.appendUserRoleByRoleCode默认角色 test02")
@PostMapping("/append-user-role-by-code")
public org.qinan.safetyeval.client.dto.SingleResponse<Map<String, Object>> appendUserRoleByRoleCode(
@ApiParam(value = "角色编码,默认 test02 的 code")
@RequestParam(value = "roleCode", required = false) String roleCode,
@ApiParam(value = "部门id默认 auth.deptId.org其次当前用户 orgId")
@RequestParam(value = "deptId", required = false) Long deptId) {
AuthUserInfo user = requireLogin();
String code = resolveRoleCode(roleCode);
Long resolvedDeptId = resolveDeptId(user, deptId);
UserAppendRoleCmd cmd = new UserAppendRoleCmd();
cmd.setId(user.getUserId());
RoleDeptAddCmd roleDept = new RoleDeptAddCmd();
roleDept.setRoleCode(code);
roleDept.setDeptId(resolvedDeptId);
cmd.setRoleDepts(Collections.singletonList(roleDept));
Response response = gbsUserFacadeClient.appendUserRoleByRoleCode(cmd);
Map<String, Object> data = roleOpResult(response, user, code,
TARGET_ROLE_CODE.equals(code) ? TARGET_ROLE_NAME : null, "appendUserRoleByRoleCode");
data.put("deptId", resolvedDeptId);
return org.qinan.safetyeval.client.dto.SingleResponse.success(data);
}
private UserRoleUpdateCmd buildRoleUpdateCmd(AuthUserInfo user, String roleCode) {
UserRoleUpdateCmd cmd = new UserRoleUpdateCmd();
cmd.setId(user.getUserId());
cmd.setName(user.getUserName());
cmd.setMobile(user.getMobile());
cmd.setRoleCodes(Collections.singletonList(roleCode));
return cmd;
}
private Map<String, Object> roleOpResult(Response response, AuthUserInfo user,
String roleCode, String roleName, String api) {
Map<String, Object> data = new HashMap<String, Object>();
data.put("api", api);
data.put("success", response.isSuccess());
data.put("userId", user.getUserId());
data.put("userName", user.getUserName());
data.put("roleCode", roleCode);
data.put("roleName", roleName);
data.put("errCode", response.getErrCode());
data.put("errMessage", response.getErrMessage());
return data;
}
private String resolveRoleCode(String roleCode) {
return (roleCode == null || roleCode.trim().isEmpty()) ? TARGET_ROLE_CODE : roleCode.trim();
}
private Long resolveDeptId(AuthUserInfo user, Long deptId) {
if (deptId != null) {
return deptId;
}
if (defaultDeptId != null) {
return defaultDeptId;
}
return user.getOrgId();
}
private AuthUserInfo requireLogin() {
AuthUserInfo user = AuthUserContextAdapter.getCurrentUser();
if (user == null || user.getUserId() == null) {
throw new BizException(ErrorCode.UNKNOWN_ERROR.getCode(), "未登录或 token 无效,无法获取当前用户");
}
return user;
}
}

View File

@ -4,7 +4,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.qinan.safetyeval.client.api.OrgPositionApi;
import org.qinan.safetyeval.client.co.GbsRoleOptionCO;
import org.qinan.safetyeval.client.co.OrgPositionCO;
import org.qinan.safetyeval.client.dto.*;
import org.qinan.safetyeval.infrastructure.dataobject.base.Req;
@ -12,7 +11,6 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* Controller
@ -56,16 +54,4 @@ public class OrgPositionController {
public PageResponse<OrgPositionCO> page(@Validated OrgPositionPageQuery query) {
return orgPositionApi.page(query);
}
@ApiOperation("分配GBS角色若岗位有人员则依次同步其GBS角色")
@PostMapping("/assign-gbs-role")
public SingleResponse<OrgPositionCO> assignGbsRole(@Validated @RequestBody OrgPositionAssignGbsRoleCmd cmd) {
return orgPositionApi.assignGbsRole(cmd);
}
@ApiOperation("GBS角色列表分配角色下拉")
@GetMapping("/gbs-roles")
public SingleResponse<List<GbsRoleOptionCO>> listGbsRoles() {
return orgPositionApi.listGbsRoles();
}
}

View File

@ -1,7 +1,6 @@
package org.qinan.safetyeval.app.executor;
import com.jjb.saas.system.client.user.request.UserAddCmd;
import com.jjb.saas.system.client.user.request.UserRoleUpdateCmd;
import com.jjb.saas.system.client.user.request.UserUpdatePasswordCmd;
import com.zcloud.gbscommon.utils.MD5;
import com.zcloud.gbscommon.utils.Sm2Util;
@ -12,14 +11,12 @@ import org.qinan.safetyeval.client.api.OrgPersonnelApi;
import org.qinan.safetyeval.client.co.OrgPersonnelCO;
import org.qinan.safetyeval.client.dto.*;
import org.qinan.safetyeval.domain.entity.OrgPersonnelEntity;
import org.qinan.safetyeval.domain.entity.OrgPositionEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgResignApplyGateway;
import org.qinan.safetyeval.domain.query.OrgPersonnelQuery;
import org.qinan.safetyeval.domain.query.PageResult;
import org.qinan.safetyeval.domain.service.OrgPersonnelDomainService;
import org.qinan.safetyeval.domain.service.OrgPositionDomainService;
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
import org.qinan.safetyeval.infrastructure.adapter.gbs.GbsUserFacadeClient;
@ -30,11 +27,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* App
@ -63,9 +57,6 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
@Autowired
private GbsUserFacadeClient gbsUserFacadeClient;
@Autowired(required = false)
private OrgPositionDomainService orgPositionDomainService;
@Value("${def.password:a123456}")
private String defPassword;
@Value("${def.publicKey:0402df2195296d4062ac85ad766994d73e871b887e18efb9a9a06b4cebc72372869b7da6c347c129dee2b46a0f279ff066b01c76208c2a052af75977c722a2ccee}")
@ -90,12 +81,8 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
userAddCmd.setName(result.getUserName());
String encrypt = Sm2Util.encryptHex(MD5.md5(defPassword), publicKey);
userAddCmd.setPassword(encrypt);
OrgPositionEntity gbsRolePosition = resolveGbsRolePositionByPostId(result.getPostId());
Long gbsRoleId = gbsRolePosition == null ? null : gbsRolePosition.getGbsRoleId();
String gbsRoleCode = gbsRolePosition == null || !StringUtils.hasText(gbsRolePosition.getGbsRoleCode())
? null : gbsRolePosition.getGbsRoleCode().trim();
try {
gbsUserFacadeClient.add(userAddCmd, gbsRoleId, gbsRoleCode);
gbsUserFacadeClient.add(userAddCmd);
} catch (Exception ex) {
LOGGER.warn("GBS user sync failed while adding personnel", ex);
if (gbsUserSyncFailFast) {
@ -121,11 +108,6 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
entity.setId(cmd.getId());
OrgPersonnelEntity result = orgPersonnelDomainService.modify(entity);
orgPersonnelChangeRecorder.recordChanges(existing, result);
// 岗位变更且新岗位已关联 GBS 角色时,同步该人员 GBS 角色
if (result != null && !Objects.equals(
existing == null ? null : existing.getPostId(), result.getPostId())) {
syncPersonGbsRoleByPost(result);
}
OrgPersonnelCO co = orgPersonnelConvertor.toCO(result);
enrich(co);
return SingleResponse.success(co);
@ -192,40 +174,6 @@ public class OrgPersonnelExecutor implements OrgPersonnelApi {
}
}
}
private void syncPersonGbsRoleByPost(OrgPersonnelEntity person) {
if (person == null || person.getPostId() == null || orgPositionDomainService == null) {
return;
}
OrgPositionEntity position = orgPositionDomainService.get(person.getPostId());
if (position == null || !StringUtils.hasText(position.getGbsRoleCode())) {
return;
}
UserRoleUpdateCmd cmd = new UserRoleUpdateCmd();
cmd.setId(person.getId());
cmd.setName(person.getUserName());
cmd.setMobile(person.getAccount());
cmd.setRoleCodes(Collections.singletonList(position.getGbsRoleCode()));
syncGbsUser("update personnel role by post", () -> gbsUserFacadeClient.updateUserRole(cmd));
}
/**
* GBS null
*/
private OrgPositionEntity resolveGbsRolePositionByPostId(Long postId) {
if (postId == null || orgPositionDomainService == null) {
return null;
}
OrgPositionEntity position = orgPositionDomainService.get(postId);
if (position == null) {
return null;
}
if (position.getGbsRoleId() == null && !StringUtils.hasText(position.getGbsRoleCode())) {
return null;
}
return position;
}
private void enrich(OrgPersonnelCO co) {
if (orgPersonnelViewEnricher != null) {
orgPersonnelViewEnricher.enrichPersonnel(co);

View File

@ -1,40 +1,21 @@
package org.qinan.safetyeval.app.executor;
import com.jjb.saas.system.client.role.response.RoleCO;
import com.jjb.saas.system.client.user.request.UserRoleUpdateCmd;
import org.qinan.safetyeval.client.api.OrgPositionApi;
import org.qinan.safetyeval.client.co.GbsRoleOptionCO;
import org.qinan.safetyeval.client.co.OrgPositionCO;
import org.qinan.safetyeval.client.dto.OrgPositionAddCmd;
import org.qinan.safetyeval.client.dto.OrgPositionAssignGbsRoleCmd;
import org.qinan.safetyeval.client.dto.OrgPositionModifyCmd;
import org.qinan.safetyeval.client.dto.OrgPositionPageQuery;
import org.qinan.safetyeval.client.dto.PageResponse;
import org.qinan.safetyeval.client.dto.SingleResponse;
import org.qinan.safetyeval.domain.entity.OrgPersonnelEntity;
import org.qinan.safetyeval.client.co.OrgPositionCO;
import org.qinan.safetyeval.client.dto.OrgPositionAddCmd;
import org.qinan.safetyeval.client.dto.OrgPositionModifyCmd;
import org.qinan.safetyeval.client.dto.OrgPositionPageQuery;
import org.qinan.safetyeval.domain.entity.OrgPositionEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgPersonnelGateway;
import org.qinan.safetyeval.domain.query.OrgPositionQuery;
import org.qinan.safetyeval.domain.query.PageResult;
import org.qinan.safetyeval.domain.service.OrgPositionDomainService;
import org.qinan.safetyeval.infrastructure.adapter.ThreadLocalUserInfoAdapter;
import org.qinan.safetyeval.infrastructure.adapter.auth.AuthUserContextAdapter;
import org.qinan.safetyeval.infrastructure.adapter.gbs.GbsRoleFacadeClient;
import org.qinan.safetyeval.infrastructure.adapter.gbs.GbsUserFacadeClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* App
@ -44,24 +25,10 @@ import java.util.stream.Collectors;
@Service
public class OrgPositionExecutor implements OrgPositionApi {
private static final Logger LOGGER = LoggerFactory.getLogger(OrgPositionExecutor.class);
@Lazy
@Autowired(required = false)
private OrgPositionDomainService orgPositionDomainService;
@Autowired
private OrgPersonnelGateway orgPersonnelGateway;
@Autowired
private GbsUserFacadeClient gbsUserFacadeClient;
@Autowired
private GbsRoleFacadeClient gbsRoleFacadeClient;
@Value("${safety-eval.gbs-user-sync.fail-fast:true}")
private boolean gbsUserSyncFailFast;
@Override
public SingleResponse<OrgPositionCO> add(OrgPositionAddCmd cmd) {
OrgPositionEntity entity = new OrgPositionEntity();
@ -90,10 +57,6 @@ public class OrgPositionExecutor implements OrgPositionApi {
entity.setRemark(cmd.getRemark());
OrgPositionEntity result = orgPositionDomainService.modify(entity);
// 岗位已关联 GBS 角色且存在人员时,同步人员 GBS 角色
if (result != null && (result.getGbsRoleId() != null || StringUtils.hasText(result.getGbsRoleCode()))) {
syncPersonnelGbsRoles(result.getId(), result.getGbsRoleCode());
}
return SingleResponse.success(toCO(result));
}
@ -118,115 +81,10 @@ public class OrgPositionExecutor implements OrgPositionApi {
return PageResponse.of(
pageResult.getRecords().stream()
.map(this::toCO)
.collect(Collectors.toList()),
.collect(java.util.stream.Collectors.toList()),
pageResult.getTotal());
}
@Override
public SingleResponse<OrgPositionCO> assignGbsRole(OrgPositionAssignGbsRoleCmd cmd) {
if (cmd == null || cmd.getId() == null) {
throw new BizException(ErrorCode.ORG_POSITION_NOT_FOUND);
}
if (cmd.getGbsRoleId() == null) {
throw new BizException(ErrorCode.ORG_POSITION_GBS_ROLE_REQUIRED);
}
if (!StringUtils.hasText(cmd.getGbsRoleCode())) {
throw new BizException(ErrorCode.ORG_POSITION_GBS_ROLE_REQUIRED);
}
OrgPositionEntity existing = orgPositionDomainService.get(cmd.getId());
if (existing == null) {
throw new BizException(ErrorCode.ORG_POSITION_NOT_FOUND);
}
Long roleId = cmd.getGbsRoleId();
String roleCode = cmd.getGbsRoleCode().trim();
String roleName = StringUtils.hasText(cmd.getGbsRoleName()) ? cmd.getGbsRoleName().trim() : null;
if (!StringUtils.hasText(roleName)) {
try {
roleName = gbsRoleFacadeClient.getRoleNameByCode(roleCode);
} catch (Exception ex) {
LOGGER.warn("resolve gbs role name by code failed, code={}", roleCode, ex);
}
}
OrgPositionEntity toUpdate = new OrgPositionEntity();
toUpdate.setId(existing.getId());
toUpdate.setDeptId(existing.getDeptId());
toUpdate.setPositionName(existing.getPositionName());
toUpdate.setDutyDesc(existing.getDutyDesc());
toUpdate.setRemark(existing.getRemark());
toUpdate.setOrgId(existing.getOrgId());
toUpdate.setTenantId(existing.getTenantId());
toUpdate.setGbsRoleId(roleId);
toUpdate.setGbsRoleCode(roleCode);
toUpdate.setGbsRoleName(roleName);
OrgPositionEntity result = orgPositionDomainService.modify(toUpdate);
syncPersonnelGbsRoles(result.getId(), roleCode);
return SingleResponse.success(toCO(result));
}
@Override
public SingleResponse<List<GbsRoleOptionCO>> listGbsRoles() {
List<RoleCO> roles = gbsRoleFacadeClient.listRoles();
List<GbsRoleOptionCO> options = new ArrayList<GbsRoleOptionCO>();
if (roles != null) {
for (RoleCO role : roles) {
if (role == null) {
continue;
}
GbsRoleOptionCO option = new GbsRoleOptionCO();
option.setRoleId(role.getId());
option.setRoleCode(role.getRoleCode());
option.setRoleName(role.getRoleName());
options.add(option);
}
}
return SingleResponse.success(options);
}
/**
* GBS
* GBS UserFacade updateUserRole
*/
private void syncPersonnelGbsRoles(Long positionId, String gbsRoleCode) {
if (positionId == null || !StringUtils.hasText(gbsRoleCode)) {
return;
}
List<OrgPersonnelEntity> personnelList = orgPersonnelGateway.listByPostId(positionId);
if (personnelList == null || personnelList.isEmpty()) {
return;
}
List<UserRoleUpdateCmd> cmds = new ArrayList<UserRoleUpdateCmd>();
for (OrgPersonnelEntity person : personnelList) {
if (person == null || person.getId() == null) {
continue;
}
UserRoleUpdateCmd cmd = new UserRoleUpdateCmd();
cmd.setId(person.getId());
cmd.setName(person.getUserName());
// GBS mobile 字段在本系统通常对应账号
cmd.setMobile(person.getAccount());
cmd.setRoleCodes(Collections.singletonList(gbsRoleCode));
cmds.add(cmd);
}
if (cmds.isEmpty()) {
return;
}
try {
gbsUserFacadeClient.updateUserRolesSequentially(cmds);
} catch (Exception ex) {
LOGGER.warn("sync personnel gbs roles failed, positionId={}, roleCode={}, size={}",
positionId, gbsRoleCode, cmds.size(), ex);
if (gbsUserSyncFailFast) {
if (ex instanceof BizException) {
throw (BizException) ex;
}
throw new BizException(ErrorCode.ORG_POSITION_GBS_ROLE_SYNC_ERROR);
}
}
}
private OrgPositionCO toCO(OrgPositionEntity entity) {
if (entity == null) {
return null;
@ -236,9 +94,6 @@ public class OrgPositionExecutor implements OrgPositionApi {
co.setDeptId(entity.getDeptId());
co.setPositionName(entity.getPositionName());
co.setDutyDesc(entity.getDutyDesc());
co.setGbsRoleId(entity.getGbsRoleId());
co.setGbsRoleCode(entity.getGbsRoleCode());
co.setGbsRoleName(entity.getGbsRoleName());
co.setRemark(entity.getRemark());
co.setTenantId(entity.getTenantId());
return co;

View File

@ -1,11 +1,9 @@
package org.qinan.safetyeval.client.api;
import org.qinan.safetyeval.client.co.OrgPositionCO;
import org.qinan.safetyeval.client.co.GbsRoleOptionCO;
import org.qinan.safetyeval.client.dto.PageResponse;
import org.qinan.safetyeval.client.dto.SingleResponse;
import org.qinan.safetyeval.client.dto.OrgPositionAddCmd;
import org.qinan.safetyeval.client.dto.OrgPositionAssignGbsRoleCmd;
import org.qinan.safetyeval.client.dto.OrgPositionModifyCmd;
import org.qinan.safetyeval.client.dto.OrgPositionPageQuery;
@ -25,14 +23,4 @@ public interface OrgPositionApi {
SingleResponse<Void> delete(Long id);
PageResponse<OrgPositionCO> page(OrgPositionPageQuery query);
/**
* GBS GBS
*/
SingleResponse<OrgPositionCO> assignGbsRole(OrgPositionAssignGbsRoleCmd cmd);
/**
* GBS
*/
SingleResponse<java.util.List<GbsRoleOptionCO>> listGbsRoles();
}

View File

@ -23,15 +23,6 @@ public class OrgPositionCO {
@ApiModelProperty(value = "职责描述")
private String dutyDesc;
@ApiModelProperty(value = "关联GBS角色ID")
private Long gbsRoleId;
@ApiModelProperty(value = "关联GBS角色编码")
private String gbsRoleCode;
@ApiModelProperty(value = "关联GBS角色名称")
private String gbsRoleName;
@ApiModelProperty(value = "备注")
private String remark;

View File

@ -25,15 +25,6 @@ public class OrgPositionEntity {
/** 岗位职责 */
private String dutyDesc;
/** 关联 GBS 角色ID */
private Long gbsRoleId;
/** 关联 GBS 角色编码 */
private String gbsRoleCode;
/** 关联 GBS 角色名称 */
private String gbsRoleName;
/** 备注 */
private String remark;

View File

@ -32,8 +32,6 @@ public enum ErrorCode {
// ---- 岗位 ----
ORG_POSITION_NOT_FOUND("01-08-001", "岗位不存在"),
ORG_POSITION_GBS_ROLE_REQUIRED("01-08-002", "岗位关联GBS角色编码不能为空"),
ORG_POSITION_GBS_ROLE_SYNC_ERROR("01-08-003", "岗位关联人员GBS角色同步失败"),
// ---- 机构资质证书 ----
ORG_QUALIFICATION_NOT_FOUND("01-09-001", "机构资质证书不存在"),

View File

@ -30,9 +30,4 @@ public interface OrgPersonnelGateway {
PageResult<OrgPersonnelEntity> page(OrgPersonnelQuery query);
OrgPersonnelEntity findAnyByIdCardNo(String idCardNo);
/**
* post_id = positionId
*/
java.util.List<OrgPersonnelEntity> listByPostId(Long postId);
}

View File

@ -1,64 +0,0 @@
package org.qinan.safetyeval.infrastructure.adapter.gbs;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.system.client.role.facade.RoleFacade;
import com.jjb.saas.system.client.role.response.RoleCO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.List;
/**
* GBS {@link RoleFacade} UserFacade jjb-saas-system
*/
@Component
public class GbsRoleFacadeClient {
@DubboReference(protocol = "dubbo", url = "${safety-eval.gbs-user-sync.user-facade-url:}")
private RoleFacade roleFacade;
/**
*
*/
public List<RoleCO> listRoles() {
MultiResponse<RoleCO> response = roleFacade.listRoles();
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "listRoles 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
List<RoleCO> data = response.getData();
return data == null ? Collections.<RoleCO>emptyList() : data;
}
/**
* +
*/
public List<RoleCO> listByUserIdAndDeptId(Long userId, Long deptId) {
MultiResponse<RoleCO> response = roleFacade.listByUserIdAndDeptId(userId, deptId);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "listByUserIdAndDeptId 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
List<RoleCO> data = response.getData();
return data == null ? Collections.<RoleCO>emptyList() : data;
}
/**
*
*/
public String getRoleNameByCode(String roleCode) {
SingleResponse<String> response = roleFacade.getRoleNameByCode(roleCode);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "getRoleNameByCode 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
return response.getData();
}
}

View File

@ -29,31 +29,12 @@ public class GbsUserFacadeClient {
private Long roleId;
/**
* GBS 使 {@code auth.roleId.org}
*/
public Integer add(UserAddCmd cmd) {
return add(cmd, null, null);
}
/**
* GBS
*
* @param gbsRoleId ID
* @param gbsRoleCode id/code 使 roleId
*/
public Integer add(UserAddCmd cmd, Long gbsRoleId, String gbsRoleCode) {
//2069596397920849920{key: "1782463085576", deptId: "2069596397920849920", roleId: "2069671307598893058"}
List<RoleDeptAddCmd> list = new ArrayList<>();
RoleDeptAddCmd roleDeptAddCmd = new RoleDeptAddCmd();
roleDeptAddCmd.setDeptId(deptId);
boolean hasRoleId = gbsRoleId != null;
boolean hasRoleCode = gbsRoleCode != null && !gbsRoleCode.trim().isEmpty();
if (hasRoleId || hasRoleCode) {
roleDeptAddCmd.setRoleId(gbsRoleId);
roleDeptAddCmd.setRoleCode(gbsRoleCode);
} else {
roleDeptAddCmd.setRoleId(roleId);
}
list.add(roleDeptAddCmd);
cmd.setRoleDepts(list);
try {
@ -93,87 +74,4 @@ public class GbsUserFacadeClient {
public void updateStatusEnumBatch(FacadeUserUpdateStatusEnumBatchCmd cmd) {
userFacade.updateStatusEnumBatch(cmd);
}
/**
* {@link UserFacade#updateUserRole}
* <p>GBS 使 {@link #updateUserRolesSequentially} </p>
*/
public Response updateUserRole(UserRoleUpdateCmd cmd) {
Response response = userFacade.updateUserRole(cmd);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "updateUserRole 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
return response;
}
/**
* UserFacade {@link #updateUserRole}
*
* @return
*/
public int updateUserRolesSequentially(List<UserRoleUpdateCmd> cmds) {
if (cmds == null || cmds.isEmpty()) {
return 0;
}
int success = 0;
for (UserRoleUpdateCmd cmd : cmds) {
updateUserRole(cmd);
success++;
}
return success;
}
/**
* roleCodes {@link UserFacade#updateUserAppendRole}
*/
public Response updateUserAppendRole(UserRoleUpdateCmd cmd) {
Response response = userFacade.updateUserAppendRole(cmd);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "updateUserAppendRole 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
return response;
}
/**
* roleDeptsroleId/roleCode + deptId {@link UserFacade#appendUserRole}
*/
public Response appendUserRole(UserAppendRoleCmd cmd) {
Response response = userFacade.appendUserRole(cmd);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "appendUserRole 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
return response;
}
/**
* {@link UserFacade#appendUserRoleByRoleCode}
*/
public Response appendUserRoleByRoleCode(UserAppendRoleCmd cmd) {
Response response = userFacade.appendUserRoleByRoleCode(cmd);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "appendUserRoleByRoleCode 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
return response;
}
/**
* id /
*/
public SingleResponse<com.jjb.saas.system.client.user.response.UserDetailCO> getDetail(Long userId) {
SingleResponse<com.jjb.saas.system.client.user.response.UserDetailCO> response = userFacade.getDetail(userId);
if (response == null || !response.isSuccess()) {
String errCode = response == null ? ErrorCode.UNKNOWN_ERROR.getCode() : response.getErrCode();
String errMsg = response == null ? "getDetail 无响应" : response.getErrMessage();
throw new BizException(errCode, errMsg);
}
return response;
}
}

View File

@ -19,12 +19,6 @@ public class OrgPositionDO {
private Long deptId;
private String positionName;
private String dutyDesc;
/** 关联 GBS 角色ID */
private Long gbsRoleId;
/** 关联 GBS 角色编码 */
private String gbsRoleCode;
/** 关联 GBS 角色名称 */
private String gbsRoleName;
// ---- GBS默认字段 ----
private String deleteEnum;

View File

@ -173,20 +173,5 @@ public class OrgPersonnelGatewayImpl implements OrgPersonnelGateway {
return orgPersonnelDoConvertor.converDoToEe(orgPersonnelDO);
}
@Override
public List<OrgPersonnelEntity> listByPostId(Long postId) {
if (postId == null) {
return java.util.Collections.emptyList();
}
LambdaQueryWrapper<OrgPersonnelDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(OrgPersonnelDO::getPostId, postId);
wrapper.eq(OrgPersonnelDO::getDeleteEnum, "false");
Long orgId = orgContextResolver.resolveOrgId(null);
if (orgId != null) {
wrapper.eq(OrgPersonnelDO::getOrgId, orgId);
}
return orgPersonnelDoConvertor.converDosToEes(orgPersonnelMapper.selectList(wrapper));
}
}

View File

@ -49,20 +49,6 @@ public class OrgPositionGatewayImpl implements OrgPositionGateway {
@Override
public OrgPositionEntity modify(OrgPositionEntity entity) {
OrgPositionEntity existing = get(entity.getId());
if (existing == null) {
return null;
}
// 普通编辑未传 GBS 角色时,保留原关联,避免被置空
if (entity.getGbsRoleId() == null) {
entity.setGbsRoleId(existing.getGbsRoleId());
}
if (entity.getGbsRoleCode() == null) {
entity.setGbsRoleCode(existing.getGbsRoleCode());
}
if (entity.getGbsRoleName() == null) {
entity.setGbsRoleName(existing.getGbsRoleName());
}
OrgPositionDO dataObject = toDO(entity);
dataObject.setId(entity.getId());
InsertFieldDefaults.applyForUpdate(dataObject);
@ -105,9 +91,6 @@ public class OrgPositionGatewayImpl implements OrgPositionGateway {
dataObject.setDeptId(entity.getDeptId());
dataObject.setPositionName(entity.getPositionName());
dataObject.setDutyDesc(entity.getDutyDesc());
dataObject.setGbsRoleId(entity.getGbsRoleId());
dataObject.setGbsRoleCode(entity.getGbsRoleCode());
dataObject.setGbsRoleName(entity.getGbsRoleName());
dataObject.setRemarks(entity.getRemark());
dataObject.setTenantId(entity.getTenantId());
return dataObject;
@ -119,13 +102,9 @@ public class OrgPositionGatewayImpl implements OrgPositionGateway {
}
OrgPositionEntity entity = new OrgPositionEntity();
entity.setId(dataObject.getId());
entity.setOrgId(dataObject.getOrgId());
entity.setDeptId(dataObject.getDeptId());
entity.setPositionName(dataObject.getPositionName());
entity.setDutyDesc(dataObject.getDutyDesc());
entity.setGbsRoleId(dataObject.getGbsRoleId());
entity.setGbsRoleCode(dataObject.getGbsRoleCode());
entity.setGbsRoleName(dataObject.getGbsRoleName());
entity.setRemark(dataObject.getRemarks());
entity.setTenantId(dataObject.getTenantId());
return entity;