给用户/角色/模块关系表增加租户字段

This commit is contained in:
季圣华
2021-11-05 21:50:09 +08:00
parent 69742cf392
commit c469520641
8 changed files with 180 additions and 59 deletions

View File

@@ -317,7 +317,7 @@ public class UserController {
ExceptionConstants.USER_OVER_LIMIT_FAILED_MSG);
} else {
UserEx ue= JSONObject.parseObject(obj.toJSONString(), UserEx.class);
userService.addUserAndOrgUserRel(ue);
userService.addUserAndOrgUserRel(ue, request);
}
return result;
}
@@ -332,10 +332,10 @@ public class UserController {
*/
@PutMapping("/updateUser")
@ResponseBody
public Object updateUser(@RequestBody JSONObject obj)throws Exception{
public Object updateUser(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception{
JSONObject result = ExceptionConstants.standardSuccess();
UserEx ue= JSONObject.parseObject(obj.toJSONString(), UserEx.class);
userService.updateUserAndOrgUserRel(ue);
userService.updateUserAndOrgUserRel(ue, request);
return result;
}

View File

@@ -11,6 +11,8 @@ public class UserBusiness {
private String btnStr;
private Long tenantId;
private String deleteFlag;
public Long getId() {
@@ -53,6 +55,14 @@ public class UserBusiness {
this.btnStr = btnStr == null ? null : btnStr.trim();
}
public Long getTenantId() {
return tenantId;
}
public void setTenantId(Long tenantId) {
this.tenantId = tenantId;
}
public String getDeleteFlag() {
return deleteFlag;
}

View File

@@ -444,6 +444,66 @@ public class UserBusinessExample {
return (Criteria) this;
}
public Criteria andTenantIdIsNull() {
addCriterion("tenant_id is null");
return (Criteria) this;
}
public Criteria andTenantIdIsNotNull() {
addCriterion("tenant_id is not null");
return (Criteria) this;
}
public Criteria andTenantIdEqualTo(Long value) {
addCriterion("tenant_id =", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdNotEqualTo(Long value) {
addCriterion("tenant_id <>", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdGreaterThan(Long value) {
addCriterion("tenant_id >", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdGreaterThanOrEqualTo(Long value) {
addCriterion("tenant_id >=", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdLessThan(Long value) {
addCriterion("tenant_id <", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdLessThanOrEqualTo(Long value) {
addCriterion("tenant_id <=", value, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdIn(List<Long> values) {
addCriterion("tenant_id in", values, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdNotIn(List<Long> values) {
addCriterion("tenant_id not in", values, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdBetween(Long value1, Long value2) {
addCriterion("tenant_id between", value1, value2, "tenantId");
return (Criteria) this;
}
public Criteria andTenantIdNotBetween(Long value1, Long value2) {
addCriterion("tenant_id not between", value1, value2, "tenantId");
return (Criteria) this;
}
public Criteria andDeleteFlagIsNull() {
addCriterion("delete_flag is null");
return (Criteria) this;

View File

@@ -411,7 +411,7 @@ public class UserService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addUserAndOrgUserRel(UserEx ue) throws Exception{
public void addUserAndOrgUserRel(UserEx ue, HttpServletRequest request) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
@@ -436,7 +436,7 @@ public class UserService {
ubObj.put("type", "UserRole");
ubObj.put("keyid", userId);
ubObj.put("value", "[" + ue.getRoleId() + "]");
userBusinessService.insertUserBusiness(ubObj, null);
userBusinessService.insertUserBusiness(ubObj, request);
}
if(ue.getOrgaId()==null){
//如果没有选择机构,就不建机构和用户的关联关系
@@ -522,7 +522,8 @@ public class UserService {
JSONArray ubArr = new JSONArray();
ubArr.add(manageRoleId);
ubObj.put("value", ubArr.toString());
userBusinessService.insertUserBusiness(ubObj, ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
ubObj.put("tenantId", ue.getId());
userBusinessService.insertUserBusiness(ubObj, null);
//创建租户信息
JSONObject tenantObj = new JSONObject();
tenantObj.put("tenantId", ue.getId());
@@ -551,7 +552,7 @@ public class UserService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateUserAndOrgUserRel(UserEx ue) throws Exception{
public void updateUserAndOrgUserRel(UserEx ue, HttpServletRequest request) throws Exception{
if(BusinessConstants.DEFAULT_MANAGER.equals(ue.getLoginName())) {
throw new BusinessRunTimeException(ExceptionConstants.USER_NAME_LIMIT_USE_CODE,
ExceptionConstants.USER_NAME_LIMIT_USE_MSG);
@@ -583,9 +584,9 @@ public class UserService {
Long ubId = userBusinessService.checkIsValueExist("UserRole", ue.getId().toString());
if(ubId!=null) {
ubObj.put("id", ubId);
userBusinessService.updateUserBusiness(ubObj, null);
userBusinessService.updateUserBusiness(ubObj, request);
} else {
userBusinessService.insertUserBusiness(ubObj, null);
userBusinessService.insertUserBusiness(ubObj, request);
}
}
if (ue.getOrgaId() == null) {

View File

@@ -11,6 +11,7 @@ import com.jsh.erp.service.functions.FunctionService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -68,6 +69,14 @@ public class UserBusinessService {
UserBusiness userBusiness = JSONObject.parseObject(obj.toJSONString(), UserBusiness.class);
int result=0;
try{
String token = "";
if(request!=null) {
token = request.getHeader("X-Access-Token");
Long tenantId = Tools.getTenantIdByToken(token);
if(tenantId!=0L) {
userBusiness.setTenantId(tenantId);
}
}
String value = userBusiness.getValue();
String newValue = value.replaceAll(",","\\]\\[");
userBusiness.setValue(newValue);
@@ -138,6 +147,19 @@ public class UserBusinessService {
return list;
}
public List<UserBusiness> getListBy(String keyId, String type)throws Exception{
List<UserBusiness> list=null;
try{
UserBusinessExample example = new UserBusinessExample();
example.createCriteria().andKeyIdEqualTo(keyId).andTypeEqualTo(type)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
list= userBusinessMapper.selectByExample(example);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}
public String getUBValueByTypeAndKeyId(String type, String keyId) throws Exception {
String ubValue = "";
List<UserBusiness> ubList = getBasicData(keyId, type);

View File

@@ -7,6 +7,7 @@
<result column="key_id" jdbcType="VARCHAR" property="keyId" />
<result column="value" jdbcType="VARCHAR" property="value" />
<result column="btn_str" jdbcType="VARCHAR" property="btnStr" />
<result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
<result column="delete_flag" jdbcType="VARCHAR" property="deleteFlag" />
</resultMap>
<sql id="Example_Where_Clause">
@@ -68,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, type, key_id, value, btn_str, delete_flag
id, type, key_id, value, btn_str, tenant_id, delete_flag
</sql>
<select id="selectByExample" parameterType="com.jsh.erp.datasource.entities.UserBusinessExample" resultMap="BaseResultMap">
select
@@ -102,11 +103,11 @@
</delete>
<insert id="insert" parameterType="com.jsh.erp.datasource.entities.UserBusiness">
insert into jsh_user_business (id, type, key_id,
value, btn_str, delete_flag
)
value, btn_str, tenant_id,
delete_flag)
values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{keyId,jdbcType=VARCHAR},
#{value,jdbcType=VARCHAR}, #{btnStr,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=VARCHAR}
)
#{value,jdbcType=VARCHAR}, #{btnStr,jdbcType=VARCHAR}, #{tenantId,jdbcType=BIGINT},
#{deleteFlag,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.jsh.erp.datasource.entities.UserBusiness">
insert into jsh_user_business
@@ -126,6 +127,9 @@
<if test="btnStr != null">
btn_str,
</if>
<if test="tenantId != null">
tenant_id,
</if>
<if test="deleteFlag != null">
delete_flag,
</if>
@@ -146,6 +150,9 @@
<if test="btnStr != null">
#{btnStr,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
#{tenantId,jdbcType=BIGINT},
</if>
<if test="deleteFlag != null">
#{deleteFlag,jdbcType=VARCHAR},
</if>
@@ -175,6 +182,9 @@
<if test="record.btnStr != null">
btn_str = #{record.btnStr,jdbcType=VARCHAR},
</if>
<if test="record.tenantId != null">
tenant_id = #{record.tenantId,jdbcType=BIGINT},
</if>
<if test="record.deleteFlag != null">
delete_flag = #{record.deleteFlag,jdbcType=VARCHAR},
</if>
@@ -190,6 +200,7 @@
key_id = #{record.keyId,jdbcType=VARCHAR},
value = #{record.value,jdbcType=VARCHAR},
btn_str = #{record.btnStr,jdbcType=VARCHAR},
tenant_id = #{record.tenantId,jdbcType=BIGINT},
delete_flag = #{record.deleteFlag,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@@ -210,6 +221,9 @@
<if test="btnStr != null">
btn_str = #{btnStr,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId,jdbcType=BIGINT},
</if>
<if test="deleteFlag != null">
delete_flag = #{deleteFlag,jdbcType=VARCHAR},
</if>
@@ -222,6 +236,7 @@
key_id = #{keyId,jdbcType=VARCHAR},
value = #{value,jdbcType=VARCHAR},
btn_str = #{btnStr,jdbcType=VARCHAR},
tenant_id = #{tenantId,jdbcType=BIGINT},
delete_flag = #{deleteFlag,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>