Browse Source

看板token校验,获取数据修改

chenw 7 years ago
parent
commit
90c9db7cae

+ 2 - 1
bi-core/src/main/java/com/usoftchina/bi/core/base/RepCode.java

@@ -3,7 +3,7 @@ package com.usoftchina.bi.core.base;
 public enum  RepCode {
     success(200,"成功"),
     warn(-1,"请求失败,请重新尝试连接"),
-    Null(-100,"数据为空"),
+    Null(100,"数据为空"),
     nullAxis(-101,"x轴或y轴为空"),
     erro(-110,"参数错误"),
     nullTableName(-120,"表名为空"),
@@ -16,6 +16,7 @@ public enum  RepCode {
     NoAuthority(-503, "无此权限"),
     ToMach(1, "数据过大"),
     UserIn(-504, "用户已存在"),
+    DashboardNotExist(-505, "编号为%s的看板不存在"),
     SqlWarn(-506, "只能使用查询语句"),
     DataSourceNull(-507, "数据源切换失败"),
     ChartNonExistent(-508, "图表不存在"),

+ 2 - 3
bi-server/src/main/java/com/usoftchina/bi/server/controller/chart/ShowChartsController.java

@@ -109,10 +109,9 @@ public class ShowChartsController {
     展示列数据(数据源)
      */
     @ApiOperation(value = "展示数据源列数据", notes = "展示数据源列数据", response = RepEntity.class)
-    @CheckToken
     @PostMapping("/getScreenByBaseId")
-    public RepEntity getScreenByBaseId(@RequestHeader String token,@RequestBody ColumnScreenInfo body){
-        return columnScreenService.getScreenByBaseId(body, token);
+    public RepEntity getScreenByBaseId(@RequestBody ColumnScreenInfo body){
+        return columnScreenService.getScreenByBaseId(body);
     }
 
     /*

+ 1 - 2
bi-server/src/main/java/com/usoftchina/bi/server/controller/dashboard/DashboardsController.java

@@ -80,7 +80,6 @@ public class DashboardsController {
      * @return
      */
     @ApiOperation(value = "单个看板", notes = "查看单个看板(通过看板编号)", response = RepEntity.class)
-    @CheckToken
     @GetMapping("/getDashboardByCode")
     public RepEntity getDashboardByCode(@RequestParam("code") String code){
         return dashboardsService.getDashboardByCode(code);
@@ -111,7 +110,7 @@ public class DashboardsController {
      */
     @ApiOperation(value = "看板生成图表", notes = "看板生成图表", response = RepEntity.class)
     @PostMapping("/showChartsInDash")
-    public RepEntity showChartsInDash(@RequestHeader String token, @RequestBody ChartsToDashInfo body) throws SQLException {
+    public RepEntity showChartsInDash(@RequestHeader(required = false) String token, @RequestBody ChartsToDashInfo body) throws SQLException {
         return dashboardsToChartsUtilService.getChartsInDash(body, token);
     }
 

+ 2 - 1
bi-server/src/main/java/com/usoftchina/bi/server/dao/dashboard/DashboardsMapper.java

@@ -123,7 +123,8 @@ public interface DashboardsMapper {
     })
     Dashboards getDashboards(@Param("userId") int userId, @Param("id") int id);
 
-    @Select("SELECT * FROM BI_DASHBOARDS WHERE BD_CODE = #{code}")
+    @Select("SELECT id, bd_note as bdNote, bd_name as bdName, CONFIGURATION as bdConfiguration, CREATE_BY as createBy, create_id as createId, CREATE_DATE as createDate, BD_THUMBNAIL as thumbnail, relation_columns as relationColumns, filters, demo, bd_code FROM BI_DASHBOARDS WHERE BD_CODE = #{code}")
+    @ResultMap("DashBoardsResultMap")
     Dashboards getDashboardByCode(String code);
 
     /*

+ 5 - 0
bi-server/src/main/java/com/usoftchina/bi/server/dao/user/UserMapper.java

@@ -82,6 +82,11 @@ public interface UserMapper {
             "from bi_users")
     List<User> getUserList();
 
+    @Select("select BU_ID as id, BU_NAME as name, BU_DEPARTMENT as department, BU_POST as post, BU_ROLE as role," +
+            "user_name as userName, pass_word as passWord, create_date as createDate " +
+            "from bi_users where bu_id = #{id}")
+    User getUserById(@Param("id") int id);
+
     /*
     匹配用户20个
      */

+ 15 - 5
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/ChartsToDashInfo.java

@@ -2,14 +2,24 @@ package com.usoftchina.bi.server.model.vo.configVo;
 
 import com.usoftchina.bi.server.model.bo.Screen;
 import com.usoftchina.bi.core.base.TestPage;
+import org.omg.CORBA.PRIVATE_MEMBER;
 
 import java.util.List;
 
 public class ChartsToDashInfo {
-    private int dashCreateId;
+    private int chartId;
+    private int dashboardCreatorId;
     private List<Screen> filters;
     private TestPage testPage;
 
+    public int getDashboardCreatorId() {
+        return dashboardCreatorId;
+    }
+
+    public void setDashboardCreatorId(int dashboardCreatorId) {
+        this.dashboardCreatorId = dashboardCreatorId;
+    }
+
     public TestPage getTestPage() {
         return testPage;
     }
@@ -18,12 +28,12 @@ public class ChartsToDashInfo {
         this.testPage = testPage;
     }
 
-    public int getDashCreateId() {
-        return dashCreateId;
+    public int getChartId() {
+        return chartId;
     }
 
-    public void setDashCreateId(int dashCreateId) {
-        this.dashCreateId = dashCreateId;
+    public void setChartId(int chartId) {
+        this.chartId = chartId;
     }
 
     public List<Screen> getFilters() {

+ 9 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/LoginInfo.java

@@ -19,4 +19,13 @@ public class LoginInfo {
     public void setPassWord(String passWord) {
         this.passWord = passWord;
     }
+
+    public LoginInfo() {
+    }
+
+    public LoginInfo(String userName, String passWord) {
+
+        this.userName = userName;
+        this.passWord = passWord;
+    }
 }

+ 4 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsService.java

@@ -23,6 +23,7 @@ import org.bouncycastle.util.encoders.UrlBase64Encoder;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
 
 import java.util.*;
@@ -170,6 +171,9 @@ public class DashboardsService {
      */
     public RepEntity getDashboardByCode(String code) {
         Dashboards dashboard = dashboardsMapper.getDashboardByCode(code);
+        if (ObjectUtils.isEmpty(dashboard)) {
+            return new RepEntity(RepCode.DashboardNonExistent.getCode(), String.format(RepCode.DashboardNotExist.getMsg(), code), null);
+        }
         Dashboards dashboards = dashboardsMapper.getDashboards(dashboard.getCreateId(), dashboard.getId());
         if (dashboards == null){
             return new RepEntity(RepCode.DashboardNonExistent);

+ 21 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsToChartsUtilService.java

@@ -7,13 +7,19 @@ import com.usoftchina.bi.server.model.po.ChartsConfigToDash;
 import com.usoftchina.bi.core.base.RepCode;
 import com.usoftchina.bi.core.base.RepEntity;
 import com.usoftchina.bi.core.base.TestPage;
+import com.usoftchina.bi.server.model.po.TokenData;
+import com.usoftchina.bi.server.model.po.User;
 import com.usoftchina.bi.server.model.vo.configVo.*;
 import com.usoftchina.bi.server.service.chart.*;
+import com.usoftchina.bi.server.service.user.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 import java.sql.SQLException;
 import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 /*
 看板中调用生成图表
@@ -36,11 +42,25 @@ public class DashboardsToChartsUtilService {
     ShowPopulationService showPopulationService;
     @Autowired
     ShowScatterService showScatterService;
+    @Autowired
+    private UserService userService;
 
     private int chartId;
 
+    private Lock lock = new ReentrantLock();
+
     public RepEntity getChartsInDash(ChartsToDashInfo chartsToDashInfo, String token) throws SQLException {
-        chartId = chartsToDashInfo.getDashCreateId();
+        if (StringUtils.isEmpty(token)) {
+            User user = userService.getUserById(chartsToDashInfo.getDashboardCreatorId()).getData();
+            LoginInfo loginInfo = new LoginInfo(user.getUserName(), user.getPassWord());
+            token = userService.login(loginInfo).getData().getToken();
+        }
+        lock.lock();
+        try {
+            chartId = chartsToDashInfo.getChartId();
+        } finally {
+            lock.unlock();
+        }
         //拿到图表配置
         ChartsConfigToDash chartsConfigToDash = chartsConfigMapper.getChartConfigToDash(chartId);
         if (chartsConfigToDash == null || "".equals(chartsConfigToDash)){

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/ColumnScreenService.java

@@ -64,7 +64,7 @@ public class ColumnScreenService {
     /*
     通过数据源ID获取列的值
      */
-    public RepEntity getScreenByBaseId(ColumnScreenInfo columnScreenInfo, String token){
+    public RepEntity getScreenByBaseId(ColumnScreenInfo columnScreenInfo){
         //取表名
         int connectId = columnScreenInfo.getId();
         String tableName = chartsConfigMapper.getTableNameByBase(connectId);

+ 5 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/user/UserService.java

@@ -29,7 +29,7 @@ public class UserService {
     @Autowired
     ObjectMapper objectMapper;
 
-    public RepEntity login(LoginInfo loginInfo){
+    public RepEntity<TokenData> login(LoginInfo loginInfo){
         String userName = loginInfo.getUserName();
         String pws = loginInfo.getPassWord();
 
@@ -114,6 +114,10 @@ public class UserService {
         return new RepEntity(RepCode.success, userList);
     }
 
+    public RepEntity<User> getUserById(int id){
+        return new RepEntity<User>(RepCode.success, userMapper.getUserById(id));
+    }
+
     /*
     查询匹配用户
      */