|
|
@@ -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);
|