提交 41016e69 编写于 作者: minghao.wu's avatar minghao.wu

fix: 设置角色

上级 76b3a078
流水线 #43199 已取消 于阶段
......@@ -110,7 +110,7 @@ public class HospitalSaasUserServiceImpl implements HospitalSaasUserService {
Account account = buildDoctorMsg(req, mobileEncrypt, currentTime, req.getSourceType(), md5Pwd, acctId);
accountMapper.insertSelective(account);
insertAppRole(account.getId());
insertSaasRole(req, account.getId(), account.getId());
insertSaasRole(req.getRoleId(), req.getHospitalId().longValue(), account.getId(), account.getId());
redisClient.del(nxKey);
return 1;
}
......@@ -135,18 +135,15 @@ public class HospitalSaasUserServiceImpl implements HospitalSaasUserService {
return 1;
}
private void insertSaasRole(HospitalSaasUserReq req, Long doctorId, Long userId) {
if (CollectionUtils.isEmpty(req.getRoleId())) {
return;
}
if (req.getRoleId().contains(SaasRoleEnum.NULL_ROLE)) {
private void insertSaasRole(List<Long> roleIdList, Long hospitalId, Long doctorId, Long userId) {
if (CollectionUtils.isEmpty(roleIdList)) {
return;
}
List<PermissionDoctorRole> list = new ArrayList<>();
req.getRoleId().forEach(t -> {
roleIdList.forEach(t -> {
PermissionDoctorRole doctorRole = new PermissionDoctorRole();
doctorRole.setDoctorId(doctorId);
doctorRole.setHospitalId(req.getHospitalId().longValue());
doctorRole.setHospitalId(hospitalId);
doctorRole.setRoleId(t);
doctorRole.setDeleteFlag(1);
doctorRole.setCreatedId(userId);
......@@ -183,51 +180,55 @@ public class HospitalSaasUserServiceImpl implements HospitalSaasUserService {
String phone = EncryptUtils.decryptContent(t.getMobile(), EncryptConstants.ENCRYPT_TYPE_MOBILE, EncryptConstants.ENCRYPT_DECRYPT_KEY);
String mixMobile = mixMobile(phone);
t.setMobile(mixMobile);
if (req.getLoginFlag() == 1 && CollectionUtils.isNotEmpty(roleIds) && (
roleIds.contains(SaasRoleEnum.SAAS_MAIN_ADMIN.getCode()) || roleIds.contains(SaasRoleEnum.ADMIN_ROLE.getCode()) || roleIds.contains(SaasRoleEnum.MAIN_ADMIN_ROLE.getCode()))) {
t.setAdminSaasFlag(1);
}
if (req.getLoginFlag() == 0 && CollectionUtils.isNotEmpty(roleIds) && (roleIds.contains(SaasRoleEnum.SAAS_MAIN_ADMIN.getCode()) || roleIds.contains(SaasRoleEnum.ADMIN_ROLE.getCode()))
) {
t.setAdminSaasFlag(1);
}
});
return new HospitalSaasUserResp(lists, count);
}
private void validatorAdminRole(List<Long> roleId, Long hospitalId) {
int count = accountMapper.adminRoleCountByhospitalId(hospitalId);
if (count >= 1 && CollectionUtils.isNotEmpty(roleId) && roleId.contains(SaasRoleEnum.SAAS_MAIN_ADMIN)) {
if (count >= 1 && CollectionUtils.isNotEmpty(roleId) && roleId.contains(SaasRoleEnum.SAAS_MAIN_ADMIN.getCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "当前已存在系统管理员,请勿重复设置");
}
}
@Override
public int upsert(HospitalSaasUserReq req, Long doctorId) {
if (Objects.isNull(req) || Objects.isNull(req.getHospitalId())) {
if (Objects.isNull(req) || Objects.isNull(req.getHospitalId()) || CollectionUtils.isEmpty(req.getRoleId())) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "参数错误");
}
validatorAdminRole(req.getRoleId(), req.getHospitalId().longValue());
if (CollectionUtils.isNotEmpty(req.getRoleId()) && ((req.getRoleId().contains(SaasRoleEnum.MAIN_ADMIN_ROLE)) || req.getRoleId().contains(SaasRoleEnum.ADMIN_ROLE))) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "主管理员或系统管理员不可被编辑");
}
if (CollectionUtils.isNotEmpty(req.getRoleId()) && (req.getRoleId().contains(SaasRoleEnum.NULL_ROLE)) && req.getRoleId().size() > 1) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "角色选择非法");
List<Long> inputRoleIdList = new ArrayList<>();
inputRoleIdList.addAll(req.getRoleId());
List<Long> delRoleIdList = new ArrayList<>();
/** 移除不可编辑的角色 */
if (req.getLoginFlag() == 0) {
inputRoleIdList.removeIf(ele -> ele.equals(SaasRoleEnum.MAIN_ADMIN_ROLE.getCode()));
inputRoleIdList.removeIf(ele -> ele.equals(SaasRoleEnum.ADMIN_ROLE.getCode()));
delRoleIdList.addAll(Arrays.asList(SaasRoleEnum.MAIN_ADMIN_ROLE.getCode(), SaasRoleEnum.ADMIN_ROLE.getCode()));
} else if (req.getLoginFlag() == 1) {
inputRoleIdList.removeIf(ele -> ele.equals(SaasRoleEnum.MAIN_ADMIN_ROLE.getCode()));
inputRoleIdList.removeIf(ele -> ele.equals(SaasRoleEnum.ADMIN_ROLE.getCode()));
inputRoleIdList.removeIf(ele -> ele.equals(SaasRoleEnum.SAAS_MAIN_ADMIN.getCode()));
delRoleIdList.addAll(Arrays.asList(SaasRoleEnum.MAIN_ADMIN_ROLE.getCode(), SaasRoleEnum.ADMIN_ROLE.getCode(), SaasRoleEnum.SAAS_MAIN_ADMIN.getCode()));
}
if (req.getLoginFlag() == 1) {
List<RoleDto> roleDtos = doctorRoleMapper.selectRoleByUserId(req.getId());
if (CollectionUtils.isNotEmpty(roleDtos) && roleDtos.contains(SaasRoleEnum.SAAS_MAIN_ADMIN)) {
if (CollectionUtils.isNotEmpty(req.getRoleId()) && !req.getRoleId().contains(SaasRoleEnum.SAAS_MAIN_ADMIN)) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "saas角色管理员角色不可移除");
}
if (CollectionUtils.isNotEmpty(inputRoleIdList)) {
Map<String, Object> map = new HashMap(3);
map.put("id", req.getId());
map.put("delRoleIdList", delRoleIdList);
map.put("modifiedId", doctorId);
map.put("modifiedTime", new Date());
doctorRoleMapper.deleteByDoctorId(map);
if (!inputRoleIdList.contains(SaasRoleEnum.NULL_ROLE.getCode())) {
insertSaasRole(inputRoleIdList, req.getHospitalId().longValue(), req.getId(), doctorId);
} else if (inputRoleIdList.size() > 1) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "角色清除与其他角色添加不可以并存");
}
}
String mobileEncrypt = AESUtil.encryptV0(req.getMobile());
Account accountExist = accountMapper.getByMobilePhone(mobileEncrypt);
if (accountExist == null) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "当前用户不存在");
}
/** 修改备注 */
Account account = new Account();
account.setId(req.getId());
account.setModifyId(doctorId);
......@@ -238,16 +239,17 @@ public class HospitalSaasUserServiceImpl implements HospitalSaasUserService {
accountService.updateAccountById(account);
/** 修改密码 */
if (StringUtils.isNotEmpty(req.getPassword()) && StringUtils.isEmpty(accountExist.getPassword())) {
passwordService.modifyPassword(mobileEncrypt, accountExist.getPassword(), StringUtils.upperCase(MD5Util.MD5(req.getPassword())), true);
if (StringUtils.isNotEmpty(req.getPassword())) {
String mobileEncrypt = AESUtil.encryptV0(req.getMobile());
Account accountExist = accountMapper.getByMobilePhone(mobileEncrypt);
if (accountExist == null) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "当前用户不存在");
}
if (StringUtils.isEmpty(accountExist.getPassword())) {
passwordService.modifyPassword(mobileEncrypt, accountExist.getPassword(), StringUtils.upperCase(MD5Util.MD5(req.getPassword())), true);
}
}
Map<String, Object> map = new HashMap(3);
map.put("id", req.getId());
map.put("modifiedId", doctorId);
map.put("modifiedTime", new Date());
doctorRoleMapper.deleteByDoctorId(map);
insertSaasRole(req, req.getId(), doctorId);
return 1;
}
......
......@@ -180,6 +180,12 @@
modified_id = #{modifiedId,jdbcType=BIGINT},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where doctor_id = #{id,jdbcType=BIGINT}
<if test="delRoleIdList != null and delRoleIdList.size() > 0">
and role_id not in
<foreach collection="delRoleIdList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</if>
</update>
<update id="deleteByRoleId" parameterType="java.util.Map">
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册