Explorar el Código

1.看板复制bug修改2.链接加密方式修改

chenw hace 7 años
padre
commit
25c8fdc7e8

+ 42 - 0
bi-core/src/main/java/com/usoftchina/bi/core/utils/EncryUtil.java

@@ -6,6 +6,8 @@ import org.springframework.stereotype.Component;
 public class EncryUtil {
 	//人员资料 密码  des加密默认key
 	private final static String key = "96878265";
+	//BI  报表编号  des加密默认key
+    private final static String BICODEKEY = "usoftChina-BI";
 	
 	/**
 	 * 获取加密工具类DesUtil
@@ -15,6 +17,16 @@ public class EncryUtil {
 	private static DesUtil getDesUtil() throws Exception{
 		return new DesUtil(key);
 	}
+
+    /**
+     * 获取加密工具类DesUtil
+     * @param encryKey
+     * @return
+     * @throws Exception
+     */
+    private static DesUtil getDesUtil(String encryKey) throws Exception{
+        return new DesUtil(encryKey);
+    }
 	
 	/**
 	 * 给密码加盐
@@ -66,4 +78,34 @@ public class EncryUtil {
 		return password;
 	}
 
+    /**
+     * 对message进行加密
+     * @return 加密后的密文
+     * @throws Exception
+     */
+    public static String encryptBiCode(String message){
+        try {
+            return getDesUtil(BICODEKEY).encrypt(message);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return message;
+    }
+
+    /**
+     * 对密码进行解密
+     * @param message 加密的message
+     * @return 解密后的message
+     * @throws Exception
+     */
+    public  static String decryptBiCode(String message){
+        try {
+            String desMessage = getDesUtil(BICODEKEY).decrypt(message);
+            return desMessage;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return message;
+    }
+
 }

+ 6 - 0
bi-server/src/main/java/com/usoftchina/bi/server/controller/dashboard/DashboardsController.java

@@ -137,6 +137,12 @@ public class DashboardsController {
         return dashboardsService.getSharedDashboard(data);
     }
 
+    /**
+     * 复制看板
+     * @param token
+     * @param dashboardCopyInfo
+     * @return
+     */
     @ApiOperation(value = "复制", notes = "复制", response = RepEntity.class)
     @CheckToken
     @PostMapping("/copyDashboard")

+ 40 - 7
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsService.java

@@ -1,6 +1,10 @@
 package com.usoftchina.bi.server.service.dashboard;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.usoftchina.bi.core.exception.MyException;
+import com.usoftchina.bi.core.utils.EncryUtil;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.dashboard.DashboardsMapper;
 import com.usoftchina.bi.server.dao.user.UserMapper;
@@ -19,7 +23,6 @@ import com.usoftchina.bi.server.model.vo.dataVo.DashboardCopyInfo;
 import com.usoftchina.bi.server.model.vo.dataVo.DashboardOrderInfo;
 import com.usoftchina.bi.server.service.chart.ChartsUtilService;
 import com.usoftchina.bi.core.utils.GetTokenDataUtil;
-import org.bouncycastle.util.encoders.UrlBase64;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -117,9 +120,11 @@ public class DashboardsService {
      * @param id
      */
     private void validCode(String code, int id) {
-        int count = dashboardsMapper.countBdCodeById(code, id);
-        if (count > 0) {
-            throw new MyException("编号" + code + "已存在");
+        if (!StringUtils.isEmpty(code)) {
+            int count = dashboardsMapper.countBdCodeById(code, id);
+            if (count > 0) {
+                throw new MyException("编号" + code + "已存在");
+            }
         }
     }
 
@@ -173,6 +178,7 @@ public class DashboardsService {
      * @return
      */
     public RepEntity getDashboardByCode(String code) {
+        code = validAndDes(code);
         Dashboards dashboard = dashboardsMapper.getDashboardByCode(code);
         if (ObjectUtils.isEmpty(dashboard)) {
             return new RepEntity(RepCode.DashboardNonExistent.getCode(), String.format(RepCode.DashboardNotExist.getMsg(), code), null);
@@ -184,6 +190,19 @@ public class DashboardsService {
         return new RepEntity(RepCode.success, dashboards);
     }
 
+    private String validAndDes(String code) {
+        String message = EncryUtil.decryptBiCode(code);
+        String[] params = message.split("&");
+        if (params.length == 2) {
+            if (System.currentTimeMillis() - Long.valueOf(params[1]) > 30000) {
+                throw new MyException("请求超时");
+            }
+            return params[0];
+        }else {
+            throw new MyException("请求参数个数错误");
+        }
+    }
+
     /**
      * 生成分享链接参数
      * @param shareReqBO
@@ -192,7 +211,7 @@ public class DashboardsService {
     public RepEntity shareDashBoard(ShareReqBO shareReqBO) {
         Long endTime = new Double(System.currentTimeMillis() + shareReqBO.getDelay() * 24 * 60 * 60 * 1000).longValue();
         String data = "id=" + shareReqBO.getId() + "&endTime=" + endTime;
-        String encodeData = new String(UrlBase64.encode(data.getBytes()));
+        String encodeData = new String(EncryUtil.encryptBiCode(data));
         return new RepEntity(RepCode.success, encodeData);
     }
 
@@ -202,7 +221,7 @@ public class DashboardsService {
      * @return
      */
     private Map<String, String> parseParams(String data) {
-        String decodeData = new String(UrlBase64.decode(data));
+        String decodeData = new String(EncryUtil.decryptBiCode(data));
         Map<String, String> map = new HashMap<>();
         int firstEndIndex = decodeData.indexOf("&");
         map.put("id", decodeData.substring(3, firstEndIndex));
@@ -287,24 +306,38 @@ public class DashboardsService {
         int dashboardId = dashboardCopyInfo.getDashboardId(),
              dataSourceId = dashboardCopyInfo.getDataSourceId();
         List<String> idList = new ArrayList<>();
+        Map<String, String> idMap = new HashMap<>();
         //复制图表
         String chartIds = dashboardsMapper.getChartIdsById(dashboardId);
         if (!StringUtils.isEmpty(chartIds)) {
             String[] idArray = chartIds.split(",");
             for (int i = 0, len = idArray.length; i < len; i++) {
                 ChartConfig chartConfig = chartsConfigMapper.getOneChart(Integer.valueOf(idArray[i]));
+                int oldChartId = chartConfig.getChartId();
                 chartConfig.setChartName(chartConfig.getChartName() + "_副本");
                 chartConfig.setCreateBy(userName);
                 chartConfig.setCreateId(userId);
                 chartConfig.setDataId(dataSourceId);
                 chartsConfigMapper.insertCharts(chartConfig);
-                idList.add(String.valueOf(chartConfig.getChartId()));
+                int newChartId = chartConfig.getChartId();
+                idMap.put(String.valueOf(oldChartId), String.valueOf(newChartId));
+                idList.add(String.valueOf(newChartId));
             }
         }
         //复制报表
         int dashboardCreatorId = dashboardsMapper.getCreateIdById(dashboardId);
         Dashboards dashboards = dashboardsMapper.getDashboards(dashboardCreatorId, dashboardId);
         dashboards.setBdName(dashboards.getBdName() + "_副本");
+        JSONArray jsonArray = JSON.parseArray(dashboards.getBdConfiguration());
+        for (int i = 0, len = jsonArray.size(); i < len; i++) {
+            JSONObject json = jsonArray.getJSONObject(i);
+            if (!"richText".equals(json.getString("viewType"))) {
+                String newId = idMap.get(json.getString("code"));
+                json.put("code", newId);
+                json.put("chartCode", newId);
+            }
+        }
+        dashboards.setBdConfiguration(JSON.toJSONString(jsonArray));
         dashboards.setCreateBy(userName);
         dashboards.setCreateId(userId);
         dashboards.setDemo(false);