|
@@ -14,6 +14,7 @@ import com.qmth.themis.business.entity.TBOrg;
|
|
import com.qmth.themis.business.entity.TBSession;
|
|
import com.qmth.themis.business.entity.TBSession;
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
import com.qmth.themis.business.entity.TBUserRole;
|
|
import com.qmth.themis.business.entity.TBUserRole;
|
|
|
|
+import com.qmth.themis.business.enums.FieldUniqueEnum;
|
|
import com.qmth.themis.business.enums.MqEnum;
|
|
import com.qmth.themis.business.enums.MqEnum;
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
import com.qmth.themis.business.enums.SystemOperationEnum;
|
|
import com.qmth.themis.business.enums.SystemOperationEnum;
|
|
@@ -39,6 +40,7 @@ import io.swagger.annotations.*;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -580,40 +582,56 @@ public class TBUserController {
|
|
if (Objects.isNull(mapParameter)) {
|
|
if (Objects.isNull(mapParameter)) {
|
|
throw new BusinessException(ExceptionResultEnum.USER_INFO_IS_NULL);
|
|
throw new BusinessException(ExceptionResultEnum.USER_INFO_IS_NULL);
|
|
}
|
|
}
|
|
- Gson gson = new Gson();
|
|
|
|
- TBUser tbUser = gson.fromJson(gson.toJson(mapParameter), TBUser.class);
|
|
|
|
- List<String> roleList = (List<String>) mapParameter.get("roles");
|
|
|
|
- Set<String> roleSet = null;
|
|
|
|
- if (Objects.nonNull(roleList) && roleList.size() > 0) {
|
|
|
|
- roleSet = new HashSet<>(roleList);
|
|
|
|
- }
|
|
|
|
- if (Objects.isNull(tbUser.getId())) {
|
|
|
|
- TBOrg tbOrg = (TBOrg) ServletUtil.getRequestOrg();
|
|
|
|
- tbUser.setId(Constants.idGen.next());
|
|
|
|
- if (Objects.nonNull(tbOrg)) {
|
|
|
|
- tbUser.setOrgId(tbOrg.getId());
|
|
|
|
|
|
+ TBUser tbUser = null;
|
|
|
|
+ try {
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
+ tbUser = gson.fromJson(gson.toJson(mapParameter), TBUser.class);
|
|
|
|
+ List<String> roleList = (List<String>) mapParameter.get("roles");
|
|
|
|
+ Set<String> roleSet = null;
|
|
|
|
+ if (Objects.nonNull(roleList) && roleList.size() > 0) {
|
|
|
|
+ roleSet = new HashSet<>(roleList);
|
|
}
|
|
}
|
|
- tbUser.setCreateId(tbUser.getId());
|
|
|
|
- if (Objects.nonNull(roleSet) && roleSet.size() > 0) {
|
|
|
|
- roleSet.forEach(s -> {
|
|
|
|
- TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), s);
|
|
|
|
- tbUserRoleService.save(tbUserRole);
|
|
|
|
- });
|
|
|
|
|
|
+ if (Objects.isNull(tbUser.getId())) {
|
|
|
|
+ TBOrg tbOrg = (TBOrg) ServletUtil.getRequestOrg();
|
|
|
|
+ tbUser.setId(Constants.idGen.next());
|
|
|
|
+ if (Objects.nonNull(tbOrg)) {
|
|
|
|
+ tbUser.setOrgId(tbOrg.getId());
|
|
|
|
+ }
|
|
|
|
+ tbUser.setCreateId(tbUser.getId());
|
|
|
|
+ if (Objects.nonNull(roleSet) && roleSet.size() > 0) {
|
|
|
|
+ TBUser finalTbUser = tbUser;
|
|
|
|
+ roleSet.forEach(s -> {
|
|
|
|
+ TBUserRole tbUserRole = new TBUserRole(finalTbUser.getId(), s);
|
|
|
|
+ tbUserRoleService.save(tbUserRole);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (Objects.nonNull(roleSet) && roleSet.size() > 0) {
|
|
|
|
+ QueryWrapper<TBUserRole> tbUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ tbUserRoleQueryWrapper.lambda().eq(TBUserRole::getUserId, tbUser.getId());
|
|
|
|
+ tbUserRoleService.remove(tbUserRoleQueryWrapper);
|
|
|
|
+ TBUser finalTbUser1 = tbUser;
|
|
|
|
+ roleSet.forEach(s -> {
|
|
|
|
+ TBUserRole tbUserRole = new TBUserRole(finalTbUser1.getId(), s);
|
|
|
|
+ tbUserRoleService.save(tbUserRole);
|
|
|
|
+ });
|
|
|
|
+ cacheService.removeAccountCache(tbUser.getId());
|
|
|
|
+ }
|
|
|
|
+ tbUser.setUpdateId(tbUser.getId());
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- if (Objects.nonNull(roleSet) && roleSet.size() > 0) {
|
|
|
|
- QueryWrapper<TBUserRole> tbUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
|
- tbUserRoleQueryWrapper.lambda().eq(TBUserRole::getUserId, tbUser.getId());
|
|
|
|
- tbUserRoleService.remove(tbUserRoleQueryWrapper);
|
|
|
|
- roleSet.forEach(s -> {
|
|
|
|
- TBUserRole tbUserRole = new TBUserRole(tbUser.getId(), s);
|
|
|
|
- tbUserRoleService.save(tbUserRole);
|
|
|
|
- });
|
|
|
|
- cacheService.removeAccountCache(tbUser.getId());
|
|
|
|
|
|
+ tbUserService.saveOrUpdate(tbUser);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
|
+ throw new BusinessException("机构id[" + tbUser.getLoginName() + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
|
|
|
|
+ } else if (e instanceof BusinessException) {
|
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ throw new RuntimeException(e);
|
|
}
|
|
}
|
|
- tbUser.setUpdateId(tbUser.getId());
|
|
|
|
}
|
|
}
|
|
- tbUserService.saveOrUpdate(tbUser);
|
|
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
}
|
|
}
|
|
|
|
|