Kaynağa Gözat

权限设置批量功能

chenw 7 yıl önce
ebeveyn
işleme
7ba24c6119

+ 17 - 0
bi-server/src/main/java/com/usoftchina/bi/server/controller/user/UserPowerController.java

@@ -3,6 +3,7 @@ package com.usoftchina.bi.server.controller.user;
 import com.usoftchina.bi.core.base.RepCode;
 import com.usoftchina.bi.core.base.RepEntity;
 import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
+import com.usoftchina.bi.server.model.vo.configVo.BatchUserPowerInfo;
 import com.usoftchina.bi.server.model.vo.configVo.UserPowerInfo;
 import com.usoftchina.bi.server.service.user.UserPowerService;
 import io.swagger.annotations.Api;
@@ -51,4 +52,20 @@ public class UserPowerController {
         return new RepEntity(RepCode.success);
     }
 
+    @PostMapping("/batchAdd")
+    @CheckToken
+    @ApiOperation(value = "批量新增用户(组)报表权限", notes = "批量新增用户(组)报表权限", response = RepEntity.class)
+    public RepEntity batchAdd(@RequestHeader String token, @RequestBody BatchUserPowerInfo batchUserPowerInfo){
+        userPowerService.batchAdd(batchUserPowerInfo);
+        return new RepEntity(RepCode.success);
+    }
+
+    @PostMapping("/batchDelete")
+    @CheckToken
+    @ApiOperation(value = "批量删除用户(组)报表权限", notes = "批量删除用户(组)报表权限", response = RepEntity.class)
+    public RepEntity batchDelete(@RequestHeader String token, @RequestBody BatchUserPowerInfo batchUserPowerInfo){
+        userPowerService.batchDelete(batchUserPowerInfo);
+        return new RepEntity(RepCode.success);
+    }
+
 }

+ 26 - 0
bi-server/src/main/java/com/usoftchina/bi/server/dao/user/UserPowerMapper.java

@@ -58,4 +58,30 @@ public interface UserPowerMapper {
             + "</script>")
     List<DashboardPowerDTO> selectDashBoards(@Param("type") int type, @Param("id") int id, @Param("userId") int userId);
 
+    @Delete("DELETE FROM BI_POWER_USERS WHERE BPU_USERGROUPID = #{id} AND BPU_DASHBOARDID IN (${ids})")
+    void deleteByUserGroupId(@Param("ids") String ids, @Param("id") int id);
+
+    @Delete("DELETE FROM BI_POWER_USERS WHERE BPU_USERID = #{id} AND BPU_DASHBOARDID IN (${ids})")
+    void deleteByUserId(@Param("ids") String ids, @Param("id") int id);
+
+    @Insert("<script>"
+            + "INSERT INTO BI_POWER_USERS(BPU_ID, BPU_DASHBOARDID, BPU_USERGROUPID) "
+            + "SELECT BI_POWER_USERS_SEQ.NEXTVAL, M.* FROM ("
+            + "<foreach collection=\"array\" item=\"id\" open=\"\" close=\"\" separator=\"UNION ALL\">"
+            +   "SELECT #{id},#{userGroupId} FROM DUAL"
+            + "</foreach>"
+            + ")M "
+            + "</script>")
+    void insertByUserGroupId(@Param("array") String[] ids, @Param("userGroupId") int id);
+
+    @Insert("<script>"
+            + "INSERT INTO BI_POWER_USERS(BPU_ID, BPU_DASHBOARDID, BPU_USERID) "
+            + "SELECT BI_POWER_USERS_SEQ.NEXTVAL, M.* FROM ("
+            + "<foreach collection=\"array\" item=\"id\" open=\"\" close=\"\" separator=\"UNION ALL\">"
+            +   "SELECT #{id},#{userId} FROM DUAL"
+            + "</foreach>"
+            + ")M "
+            + "</script>")
+    void insertByUserId(@Param("array") String[] ids, @Param("userId") int id);
+
 }

+ 59 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/BatchUserPowerInfo.java

@@ -0,0 +1,59 @@
+package com.usoftchina.bi.server.model.vo.configVo;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Author chenwei
+ * @Date 2019-05-17
+ */
+public class BatchUserPowerInfo implements Serializable {
+
+    /**
+     * 数据库权限记录id,插入语句使用
+     */
+    @ApiModelProperty(value = "数据库权限记录id,前端不用传")
+    private int id;
+
+    @ApiModelProperty(value = "多个用户ID或用户组ID,中间用逗号隔开")
+    private int bizId;
+
+    @ApiModelProperty(value = "标识用户/用户组;0:用户组,1:用户")
+    private int type;
+
+    @ApiModelProperty(value = "报表ID")
+    private String dashboardIds;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getBizId() {
+        return bizId;
+    }
+
+    public void setBizId(int bizId) {
+        this.bizId = bizId;
+    }
+
+    public String getDashboardIds() {
+        return dashboardIds;
+    }
+
+    public void setDashboardIds(String dashboardIds) {
+        this.dashboardIds = dashboardIds;
+    }
+
+    public int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
+}

+ 24 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/user/UserPowerService.java

@@ -2,6 +2,7 @@ package com.usoftchina.bi.server.service.user;
 
 import com.usoftchina.bi.core.base.BaseContextHolder;
 import com.usoftchina.bi.server.dao.user.UserPowerMapper;
+import com.usoftchina.bi.server.model.vo.configVo.BatchUserPowerInfo;
 import com.usoftchina.bi.server.model.vo.configVo.UserPowerInfo;
 import com.usoftchina.bi.server.model.vo.dataVo.DashboardPowerDTO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,4 +45,27 @@ public class UserPowerService {
         userPowerMapper.delete(userPowerInfo);
     }
 
+    /**
+     * 批量更新权限
+     * @param batchUserPowerInfo
+     */
+    public void batchAdd(BatchUserPowerInfo batchUserPowerInfo) {
+        String[] ids = batchUserPowerInfo.getDashboardIds().split(",");
+        if (batchUserPowerInfo.getType() == 0) {
+            userPowerMapper.deleteByUserGroupId(batchUserPowerInfo.getDashboardIds(),batchUserPowerInfo.getBizId());
+            userPowerMapper.insertByUserGroupId(ids, batchUserPowerInfo.getBizId());
+        }else {
+            userPowerMapper.deleteByUserId(batchUserPowerInfo.getDashboardIds(), batchUserPowerInfo.getBizId());
+            userPowerMapper.insertByUserId(ids, batchUserPowerInfo.getBizId());
+        }
+    }
+
+    public void batchDelete(BatchUserPowerInfo batchUserPowerInfo){
+        if (batchUserPowerInfo.getType() == 0) {
+            userPowerMapper.deleteByUserGroupId(batchUserPowerInfo.getDashboardIds(),batchUserPowerInfo.getBizId());
+        }else {
+            userPowerMapper.deleteByUserId(batchUserPowerInfo.getDashboardIds(), batchUserPowerInfo.getBizId());
+        }
+    }
+
 }