Browse Source

岗位管理添加租户概念

jichaobo 2 years ago
parent
commit
88a552ea50

+ 1 - 0
service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysPostController.java

@@ -61,6 +61,7 @@ public class SysPostController extends BaseController
         {
             return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
         }
+        post.setTenantId(SecurityUtils.getTenantId());
         post.setCreateBy(SecurityUtils.getUsername());
         return toAjax(postService.insertPost(post));
     }

+ 14 - 0
service-system/service-system-biz/src/main/java/com/usky/system/domain/SysPost.java

@@ -33,6 +33,20 @@ public class SysPost extends BaseEntity
     /** 状态(0正常 1停用) */
     private String status;
 
+    /** 租户ID */
+    private Integer tenantId;
+
+    public Integer getTenantId()
+    {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId)
+    {
+        this.tenantId = tenantId;
+    }
+
+
     /** 用户是否存在此岗位标识 默认不存在 */
     @TableField(exist = false)
     private boolean flag = false;

+ 2 - 2
service-system/service-system-biz/src/main/java/com/usky/system/mapper/SysPostMapper.java

@@ -92,7 +92,7 @@ public interface SysPostMapper extends CrudMapper<SysPost>
      * @param postName 岗位名称
      * @return 结果
      */
-    public SysPost checkPostNameUnique(String postName);
+    public SysPost checkPostNameUnique(String postName,Integer tenantId);
 
     /**
      * 校验岗位编码
@@ -100,5 +100,5 @@ public interface SysPostMapper extends CrudMapper<SysPost>
      * @param postCode 岗位编码
      * @return 结果
      */
-    public SysPost checkPostCodeUnique(String postCode);
+    public SysPost checkPostCodeUnique(String postCode,Integer tenantId);
 }

+ 4 - 2
service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysPostServiceImpl.java

@@ -2,6 +2,7 @@ package com.usky.system.service.impl;
 
 
 
+import com.ruoyi.common.security.utils.SecurityUtils;
 import com.usky.common.core.exception.BusinessException;
 import com.usky.common.mvc.base.AbstractCrudService;
 import com.usky.system.domain.SysPost;
@@ -38,6 +39,7 @@ public class SysPostServiceImpl extends AbstractCrudService<SysPostMapper, SysPo
     @Override
     public List<SysPost> selectPostList(SysPost post)
     {
+        post.setTenantId(SecurityUtils.getTenantId());
         return postMapper.selectPostList(post);
     }
 
@@ -86,7 +88,7 @@ public class SysPostServiceImpl extends AbstractCrudService<SysPostMapper, SysPo
     public String checkPostNameUnique(SysPost post)
     {
         Long postId = Objects.isNull(post.getPostId()) ? -1L : post.getPostId();
-        SysPost info = postMapper.checkPostNameUnique(post.getPostName());
+        SysPost info = postMapper.checkPostNameUnique(post.getPostName(),SecurityUtils.getTenantId());
         if (Objects.nonNull(info) && info.getPostId().longValue() != postId.longValue())
         {
             return UserConstants.NOT_UNIQUE;
@@ -104,7 +106,7 @@ public class SysPostServiceImpl extends AbstractCrudService<SysPostMapper, SysPo
     public String checkPostCodeUnique(SysPost post)
     {
         Long postId = Objects.isNull(post.getPostId()) ? -1L : post.getPostId();
-        SysPost info = postMapper.checkPostCodeUnique(post.getPostCode());
+        SysPost info = postMapper.checkPostCodeUnique(post.getPostCode(),SecurityUtils.getTenantId());
         if (Objects.nonNull(info) && info.getPostId().longValue() != postId.longValue())
         {
             return UserConstants.NOT_UNIQUE;

+ 16 - 2
service-system/service-system-biz/src/main/resources/mapper/system/SysPostMapper.xml

@@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="updateBy"      column="update_by"     />
 		<result property="updateTime"    column="update_time"   />
 		<result property="remark"        column="remark"        />
+		<result property="tenantId"        column="tenant_id"        />
 	</resultMap>
 	
 	<sql id="selectPostVo">
@@ -31,6 +32,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="status != null and status != ''">
 				AND status = #{status}
 			</if>
+			<if test="tenantId != null and tenantId != '' and tenantId !=0">
+				AND tenant_id = #{tenantId}
+			</if>
 			<if test="postName != null and postName != ''">
 				AND post_name like concat('%', #{postName}, '%')
 			</if>
@@ -64,12 +68,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<select id="checkPostNameUnique" parameterType="String" resultMap="SysPostResult">
 		<include refid="selectPostVo"/>
-		 where post_name=#{postName} limit 1
+		 where post_name=#{postName}
+		<if test="tenantId != null and tenantId != '' and tenantId !=0">
+			AND tenant_id = #{tenantId}
+		</if>
+		 limit 1
 	</select>
 	
 	<select id="checkPostCodeUnique" parameterType="String" resultMap="SysPostResult">
 		<include refid="selectPostVo"/>
-		 where post_code=#{postCode} limit 1
+		 where post_code=#{postCode}
+		<if test="tenantId != null and tenantId != '' and tenantId !=0">
+			AND tenant_id = #{tenantId}
+		</if>
+		  limit 1
 	</select>
 	
 	<update id="updatePost" parameterType="com.usky.system.domain.SysPost">
@@ -95,6 +107,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="status != null and status != ''">status,</if>
  			<if test="remark != null and remark != ''">remark,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
+			<if test="tenantId != null and tenantId != '' and tenantId !=0">tenant_id,</if>
  			create_time
  		)values(
  			<if test="postId != null and postId != 0">#{postId},</if>
@@ -104,6 +117,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="status != null and status != ''">#{status},</if>
  			<if test="remark != null and remark != ''">#{remark},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
+			<if test="tenantId != null and tenantId != '' and tenantId !=0">#{tenantId},</if>
  			sysdate()
  		)
 	</insert>