chenw 7 سال پیش
والد
کامیت
fa0121fca3

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

@@ -7,6 +7,7 @@ import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
 import com.usoftchina.bi.server.model.vo.configVo.ChangeOrderInfo;
 import com.usoftchina.bi.server.model.vo.configVo.ChartsToDashInfo;
 import com.usoftchina.bi.server.model.vo.configVo.DashboardsInfo;
+import com.usoftchina.bi.server.model.vo.dataVo.DashboardCopyInfo;
 import com.usoftchina.bi.server.service.dashboard.DashboardsService;
 import com.usoftchina.bi.server.service.dashboard.DashboardsToChartsUtilService;
 import io.swagger.annotations.Api;
@@ -135,4 +136,11 @@ public class DashboardsController {
     public RepEntity getSharedDashboard(@RequestParam("data") String data) {
         return dashboardsService.getSharedDashboard(data);
     }
+
+    @ApiOperation(value = "复制", notes = "复制", response = RepEntity.class)
+    @CheckToken
+    @PostMapping("/copyDashboard")
+    public RepEntity copy(@RequestHeader String token, @RequestBody DashboardCopyInfo dashboardCopyInfo){
+        return dashboardsService.copy(token, dashboardCopyInfo);
+    }
 }

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ChartsConfigMapper.java

@@ -19,8 +19,8 @@ public interface ChartsConfigMapper {
 
     @Insert("insert into bi_charts(id,CHART_NAME,CHART_TYPE,BD_DATA_ID,CHART_CONFIG,GROUP_BY,ACCESS_AUTHORITY,UPDATE_AUTHORITY,BC_CHARTS_GROUP,CHART_DESCRIBES,BC_CHART_STYLE," +
             "create_by,create_date, bc_charts_option, create_id, BC_FETCHCONFIG) " +
-            "VALUES (#{chartId},#{chartName},#{chartType}, #{dataId}, #{chartConfig}, #{groupBy}, #{accessAuthority}, #{updateAuthority}, #{chartsGroup}," +
-            "#{describes},#{style}, #{createBy},to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'),  #{chartOption}, #{createId}, #{fetchConfig})" )
+            "VALUES (#{chartId,jdbcType=INTEGER},#{chartName,jdbcType=VARCHAR},#{chartType,jdbcType=VARCHAR}, #{dataId,jdbcType=INTEGER}, #{chartConfig,jdbcType=VARCHAR}, #{groupBy,jdbcType=VARCHAR}, #{accessAuthority,jdbcType=VARCHAR}, #{updateAuthority,jdbcType=VARCHAR}, #{chartsGroup,jdbcType=INTEGER}," +
+            "#{describes,jdbcType=VARCHAR},#{style,jdbcType=VARCHAR}, #{createBy,jdbcType=VARCHAR},to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'),  #{chartOption,jdbcType=VARCHAR}, #{createId,jdbcType=INTEGER}, #{fetchConfig,jdbcType=VARCHAR})" )
 //    @Options(useGeneratedKeys=false, keyProperty = "chartId",keyColumn = "id")
     @SelectKey(before=true,keyProperty="chartId",resultType=Integer.class,statement="SELECT bi_charts_sequence.nextval from dual",keyColumn = "id")
     void insertCharts(ChartConfig chartConfig);

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

@@ -19,8 +19,8 @@ public interface DashboardsMapper {
      */
     @Insert("insert into " +
             "bi_dashboards(id, bd_name,bd_note,CONFIGURATION,create_by, filters, create_date, BD_THUMBNAIL,relation_columns, create_id, bd_code)" +
-            "values(#{id}, #{bdName},#{bdNote},#{bdConfiguration},#{createBy}, #{filters}, " +
-            "to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'), #{thumbnail},#{relationColumns}, #{createId}, #{bdCode})")
+            "values(#{id,jdbcType=INTEGER}, #{bdName,jdbcType=VARCHAR},#{bdNote,jdbcType=VARCHAR},#{bdConfiguration,jdbcType=VARCHAR},#{createBy,jdbcType=VARCHAR}, #{filters,jdbcType=VARCHAR}, " +
+            "to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'), #{thumbnail,jdbcType=VARCHAR},#{relationColumns,jdbcType=VARCHAR}, #{createId,jdbcType=INTEGER}, #{bdCode,jdbcType=VARCHAR})")
     @SelectKey(before=true,keyProperty="id",resultType=Integer.class,statement="SELECT BI_DASHBOARDS_SEQUENCE.nextval from dual",keyColumn = "id")
     void setDashboards(Dashboards dashboards);
 

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/dao/dataSource/DataConnectorMapper.java

@@ -117,7 +117,7 @@ public interface DataConnectorMapper {
             "<if test=\"dataTag != null\"> , data_tag = #{dataTag} </if>" +
             "<if test=\"loadObject != null\"> , LOAD_OBJECT = #{loadObject} </if>" +
             "<if test=\"columnConfig != null\"> , columns_config = #{columnConfig} </if>" +
-            "<if test=\"dbConfig != null\"> , DB_CONFIG = #{dbConfig} </if>" +
+            "<if test=\"dbConId != null\"> , DB_CONFIG = #{dbConId} </if>" +
             "<if test=\"usedNumber != null\"> , used_number = #{usedNumber} </if>" +
             "<if test=\"createBy != null\"> , create_by = #{createBy} </if>" +
             "<if test=\"type != null\"> , con_TYPE = #{type} </if>" +

+ 29 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/dataVo/DashboardCopyInfo.java

@@ -0,0 +1,29 @@
+package com.usoftchina.bi.server.model.vo.dataVo;
+
+import java.io.Serializable;
+
+/**
+ * @Author chenwei
+ * @Date 2019-04-09
+ */
+public class DashboardCopyInfo implements Serializable {
+
+    private int dashboardId;
+    private int dataSourceId;
+
+    public int getDashboardId() {
+        return dashboardId;
+    }
+
+    public void setDashboardId(int dashboardId) {
+        this.dashboardId = dashboardId;
+    }
+
+    public int getDataSourceId() {
+        return dataSourceId;
+    }
+
+    public void setDataSourceId(int dataSourceId) {
+        this.dataSourceId = dataSourceId;
+    }
+}

+ 46 - 3
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsService.java

@@ -1,28 +1,29 @@
 package com.usoftchina.bi.server.service.dashboard;
 
 import com.usoftchina.bi.core.exception.MyException;
-import com.usoftchina.bi.core.utils.EncryUtil;
-import com.usoftchina.bi.core.utils.JsonUtils;
+import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.dashboard.DashboardsMapper;
 import com.usoftchina.bi.server.dao.user.UserMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.github.pagehelper.PageInfo;
 import com.usoftchina.bi.server.model.bo.DashOrder;
 import com.usoftchina.bi.server.model.bo.ShareReqBO;
+import com.usoftchina.bi.server.model.po.ChartConfig;
 import com.usoftchina.bi.server.model.po.Dashboards;
 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.vo.configVo.ChangeOrderInfo;
 import com.usoftchina.bi.server.model.vo.configVo.DashboardsInfo;
+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.bouncycastle.util.encoders.UrlBase64Encoder;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
 
@@ -38,6 +39,8 @@ public class DashboardsService {
     UserMapper userMapper;
     @Autowired
     ChartsUtilService chartsUtilService;
+    @Autowired
+    private ChartsConfigMapper chartsConfigMapper;
 
     /*
     保存看板
@@ -270,4 +273,44 @@ public class DashboardsService {
         dashboardOrderInfo.setGroupNames(groupNames);
         return new RepEntity(RepCode.success, dashboardOrderInfo);
     }
+
+    /**
+     * 复制看板
+     * @param dashboardCopyInfo
+     * @return
+     */
+    @Transactional
+    public RepEntity copy(String token, DashboardCopyInfo dashboardCopyInfo) {
+        Map<String, String> resultMap = GetTokenDataUtil.getTokenData(token);
+        int userId = Integer.parseInt(resultMap.get("id"));
+        String userName = resultMap.get("name");
+        int dashboardId = dashboardCopyInfo.getDashboardId(),
+             dataSourceId = dashboardCopyInfo.getDataSourceId();
+        List<String> idList = new ArrayList<>();
+        //复制图表
+        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]));
+                chartConfig.setCreateBy(userName);
+                chartConfig.setCreateId(userId);
+                chartConfig.setDataId(dataSourceId);
+                chartsConfigMapper.insertCharts(chartConfig);
+                idList.add(String.valueOf(chartConfig.getChartId()));
+            }
+        }
+        //复制报表
+        int dashboardCreatorId = dashboardsMapper.getCreateIdById(dashboardId);
+        Dashboards dashboards = dashboardsMapper.getDashboards(dashboardCreatorId, dashboardId);
+        dashboards.setCreateBy(userName);
+        dashboards.setCreateId(userId);
+        dashboards.setDemo(false);
+        dashboards.setBdCode("");
+        dashboardsMapper.setDashboards(dashboards);
+        String[] ids = String.join(",", idList).split(",");
+        dashboardsMapper.saveDashboardChartRelation(dashboards.getId(), ids);
+        return new RepEntity(RepCode.success, dashboards.getId());
+    }
+
 }