Browse Source

权限设置

chenw 6 years ago
parent
commit
68001139ad

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

@@ -0,0 +1,55 @@
+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.UserPowerInfo;
+import com.usoftchina.bi.server.service.user.UserPowerService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 用户权限设置
+ * @Author chenwei
+ * @Date 2019-05-13
+ */
+@RestController
+@Api(description = "用户权限模块相关接口")
+@RequestMapping("/user/power")
+public class UserPowerController {
+
+    @Autowired
+    private UserPowerService userPowerService;
+
+    /**
+     * 新增用户(组)权限
+     * @param userPowerInfo
+     * @return
+     */
+    @PostMapping("/save")
+    @CheckToken
+    @ApiOperation(value = "新增用户(组)报表权限", notes = "新增用户(组)报表权限", response = RepEntity.class)
+    public RepEntity save(@RequestHeader String token, @RequestBody UserPowerInfo userPowerInfo){
+        userPowerService.save(userPowerInfo);
+        return new RepEntity(RepCode.success);
+    }
+
+    @GetMapping("/read/{type}/{id}")
+    @CheckToken
+    @ApiOperation(value = "获取用户(组)报表权限", notes = "获取用户(组)报表权限", response = RepEntity.class)
+    public RepEntity read(@RequestHeader String token, @PathVariable("type") int type, @PathVariable("id") int id) {
+        userPowerService.read(type, id);
+        return new RepEntity(RepCode.success);
+    }
+
+    @PostMapping("/delete")
+    @CheckToken
+    @ApiOperation(value = "删除用户(组)报表权限", notes = "删除用户(组)报表权限", response = RepEntity.class)
+    public RepEntity delete(@RequestHeader String token, @RequestBody UserPowerInfo userPowerInfo){
+        userPowerService.delete(userPowerInfo);
+        return new RepEntity(RepCode.success);
+    }
+
+}

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

@@ -0,0 +1,58 @@
+package com.usoftchina.bi.server.dao.user;
+
+import com.usoftchina.bi.server.model.vo.configVo.UserPowerInfo;
+import org.apache.ibatis.annotations.*;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @Author chenwei
+ * @Date 2019-05-13
+ */
+@Mapper
+@Repository
+public interface UserPowerMapper {
+
+    @Insert( "<script>"
+            + "INSERT INTO BI_POWER_USERS(BPU_ID, BPU_DASHBOARDID, BPU_USERID, BPU_USERGROUPID) VALUES("
+            + "#{id,jdbcType=INTEGER}, #{dashboardId,jdbcType=INTEGER}, "
+            + "<choose>"
+            +   "<if test=\"type == 0\">"
+            +       "NULL, #{bizId, jdbcType=INTEGER}"
+            +   "</if>"
+            +   "<otherwise>"
+            +       "#{bizId, jdbcType=INTEGER}, NULL"
+            +   "</otherwise>"
+            + "</choose>"
+            + ")"
+            + "</script>")
+    @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_POWER_USERS_SEQ.NEXTVAL FROM DUAL",keyColumn = "id")
+    void insert(UserPowerInfo userPowerInfo);
+
+    @Delete(  "<script>"
+            + "DELETE FROM BI_POWER_USERS WHERE BPU_DASHBOARDID = #{dashboardId, jdbcType=INTEGER} "
+            + "<choose>"
+            +   "<if test=\"type == 0\">"
+            +       "AND BPU_USERGROUPID = #{bizId, jdbcType=INTEGER}"
+            +   "</if>"
+            +   "<otherwise>"
+            +       "AND BPU_USERID = #{bizId, jdbcType=INTEGER}"
+            +   "</otherwise>"
+            + "</choose>"
+            + "</script>")
+    void delete(UserPowerInfo userPowerInfo);
+
+    @Select(  "<script>"
+            + "SELECT ID,BD_NAME,CASE NVL(BPU_ID, '1') WHEN 1 THEN 'false' ELSE 'true' END CHECKED "
+            + "FROM BI_DASHBOARDS LEFT JOIN BI_POWER_USERS ON BPU_DASHBOARDID = ID WHERE CREATE_ID = #{userId, jdbcType=INTEGER} "
+            + "<choose>"
+            +   "<if test=\"type == 0\">"
+            +       " AND BPU_USERGROUPID = #{id,jdbcType=INTEGER}"
+            +    "</if>"
+            +   "<otherwise>"
+            +       " AND BPU_USERID = #{id,jdbcType=INTEGER}"
+            +   "</otherwise>"
+            + "</choose>"
+            + "</script>")
+    void selectDashBoards(@Param("type") int type, @Param("id") int id, @Param("userId") int userId);
+
+}

+ 62 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/UserPowerInfo.java

@@ -0,0 +1,62 @@
+package com.usoftchina.bi.server.model.vo.configVo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * 用户权限设置传输对象DTO
+ * @Author chenwei
+ * @Date 2019-05-13
+ */
+@ApiModel("用户(组)权限设置传输对象")
+public class UserPowerInfo 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 int dashboardId;
+
+    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 int getType() {
+        return type;
+    }
+
+    public void setType(int type) {
+        this.type = type;
+    }
+
+    public int getDashboardId() {
+        return dashboardId;
+    }
+
+    public void setDashboardId(int dashboardId) {
+        this.dashboardId = dashboardId;
+    }
+}

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

@@ -0,0 +1,44 @@
+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.UserPowerInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Author chenwei
+ * @Date 2019-05-13
+ */
+@Service
+public class UserPowerService {
+
+    @Autowired
+    private UserPowerMapper userPowerMapper;
+
+    /**
+     * 新增用户(组)权限
+     * @param userPowerInfo
+     */
+    public void save(UserPowerInfo userPowerInfo){
+        userPowerMapper.insert(userPowerInfo);
+    }
+
+    /**
+     * 获取用户(组)所拥有的权限
+     * @param type
+     * @param id
+     */
+    public void read(int type, int id){
+        userPowerMapper.selectDashBoards(type, id, BaseContextHolder.getUserId());
+    }
+
+    /**
+     * 删除用户(组)权限
+     * @param userPowerInfo
+     */
+    public void delete(UserPowerInfo userPowerInfo){
+        userPowerMapper.delete(userPowerInfo);
+    }
+
+}

+ 82 - 0
bi-server/src/main/resources/application-N_MALATA_ZZ.properties

@@ -0,0 +1,82 @@
+#数据连接池:据说阿里的最好
+spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
+
+#数据库驱动
+spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
+#数据库连接地址
+#默认数据源
+spring.datasource.url=jdbc:oracle:thin:@117.25.180.218:1521:orcl
+spring.datasource.username=N_MALATA_ZZ_ZS
+spring.datasource.password=select!#%*(
+
+spring.jackson.date-format=yyyy-MM-dd
+spring.jackson.time-zone=GMT+8
+
+#线上环境
+#spring.datasource.url=jdbc:oracle:thin:@218.18.115.198:1523:orcl
+#spring.datasource.username=BI_ADMIN
+#spring.datasource.password=admin
+
+
+#slave.datasource.names=UAS,UAS_DEV,YITOA_DATACENTER,N_USOFTSYS
+#//UAS标准版
+#slave.datasource.UAS.driver-class-name=oracle.jdbc.driver.OracleDriver
+#slave.datasource.UAS.url=jdbc:oracle:thin:@218.17.158.219:1521:orcl
+#slave.datasource.UAS.username=UAS
+#slave.datasource.UAS.password=select!#%*(
+#
+#//研发
+#slave.datasource.UAS_DEV.driver-class-name=oracle.jdbc.driver.OracleDriver
+#slave.datasource.UAS_DEV.url=jdbc:oracle:thin:@218.17.158.219:1521:orcl
+#slave.datasource.UAS_DEV.username=UAS_DEV
+#slave.datasource.UAS_DEV.password=select!#%*(
+#
+#//英唐资料中心
+#slave.datasource.YITOA_DATACENTER.driver-class-name=oracle.jdbc.driver.OracleDriver
+#slave.datasource.YITOA_DATACENTER.url=jdbc:oracle:thin:@10.1.1.168:1521:orcl
+#slave.datasource.YITOA_DATACENTER.username=YITOA_DATACENTER
+#slave.datasource.YITOA_DATACENTER.password=select!#%*(
+#
+#//优软科技
+#slave.datasource.N_USOFTSYS.driver-class-name=oracle.jdbc.driver.OracleDriver
+#slave.datasource.N_USOFTSYS.url=jdbc:oracle:thin:@10.1.1.168:1521:orcl
+#slave.datasource.N_USOFTSYS.username=N_USOFTSYS
+#slave.datasource.N_USOFTSYS.password=select!#%*(
+#
+#//
+#slave.datasource.N_WILIC.driver-class-name=oracle.jdbc.driver.OracleDriver
+#slave.datasource.N_WILIC.url=jdbc:oracle:thin:@218.18.115.198:1521:orcl
+#slave.datasource.N_WILIC.username=N_WILIC
+#slave.datasource.N_WILIC.password=select!#%*(
+
+
+
+spring.jpa.database=oracle
+
+#最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止
+spring.datasource.max-idle=10
+#最大等待值
+spring.datasource.max-wait=10000
+#最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请。
+spring.datasource.min-idle=5
+#连接池启动时的初始值
+spring.datasource.initial-size=5
+
+# 分页配置
+pagehelper-helper-dialect=mysql
+pagehelper-reasonable=true
+pagehelper-support-methods-arguments=true
+pagehelper-params=count=countSql
+
+#mybatis.typeAliasesPackage=com.usoftchina.bi.server.model.po
+#mybatis.config-locations=classpath:mybatis-config.xml
+#mybatis.mapperLocations=classpath:config/dao/*.xml
+mybatis.configuration.callSettersOnNulls=true
+
+
+server.port=8011
+server.servlet.context-path=/BI
+#server.session.timeout=10
+server.tomcat.uri-encoding=UTF-8
+#debug=true
+#logging.level.com.usoftchina.bi.server=debug