Browse Source

支持报表跨数据库打印

guq 7 years ago
parent
commit
1b8b37c457

+ 1 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -37,6 +37,7 @@ public enum BizExceptionCode implements BaseExceptionCode {
     BIZ_BANNED(79313, "只能禁用已开启的单据"),
     BIZ_ENABLE(79314, "只能开启已禁用的单据"),
     BIZ_NULLCALLER(79315, "该单据的定义不存在"),
+    BIZ_REPORT_NOCALLER(79316, "报表配置不存在"),
 
     NO_OPRATIONDATA(79400,"无可操作单据"),
     NULL_DATA(23232,"无数据"),

+ 10 - 0
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/po/JasperResult.java

@@ -9,10 +9,13 @@ import java.io.Serializable;
 public class JasperResult implements Serializable{
 
     private String printurl;
+
     private String reportName;
     private String title;
     private String whereCondition;
     private String printtype;
+    //数据库名称
+    private String userName;
 
     public String getPrinttype() {
         return printtype;
@@ -53,4 +56,11 @@ public class JasperResult implements Serializable{
     public void setWhereCondition(String whereCondition) {
         this.whereCondition = whereCondition;
     }
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
 }

+ 7 - 1
applications/commons/commons-server/src/main/java/com/usoftchina/saas/commons/service/impl/JasperReportServiceImpl.java

@@ -1,6 +1,7 @@
 package com.usoftchina.saas.commons.service.impl;
 
 import com.usoftchina.saas.commons.dto.DocBaseDTO;
+import com.usoftchina.saas.commons.exception.BizExceptionCode;
 import com.usoftchina.saas.commons.mapper.SysprintsetMapper;
 import com.usoftchina.saas.commons.po.Configs;
 import com.usoftchina.saas.commons.po.JasperResult;
@@ -27,6 +28,7 @@ import java.util.List;
 public class JasperReportServiceImpl implements JasperReportService{
 
     private static final String PRINTURLCODE = "printUrl";
+    private static final String USERNAME = "dataBase";
 
     @Autowired
     private SysprintsetMapper sysprintsetMapper;
@@ -56,11 +58,14 @@ public class JasperReportServiceImpl implements JasperReportService{
             printSet = sysprintsetMapper.selectSetByReportName(caller, reportName, companyId);
         }
         if (StringUtils.isEmpty(printSet)) {
-            return null;
+            throw new BizException(BizExceptionCode.BIZ_REPORT_NOCALLER);
         }
         //取打印地址
         Configs config = configsService.getConfigByCode(PRINTURLCODE);
         String printUrl = null != config ? config.getData() : "";
+        //取数据库名称
+        Configs db_config = configsService.getConfigByCode(USERNAME);
+        String db_username = null != db_config ? db_config.getData() : "";
         //打印限制 TODO
         //打印前执行方法
         if (!StringUtils.isEmpty(printSet.getHandlermethod())) {
@@ -85,6 +90,7 @@ public class JasperReportServiceImpl implements JasperReportService{
         result.setPrinturl(printUrl);
         result.setWhereCondition(condition);
         result.setPrinttype(StringUtils.isEmpty(printSet.getPrinttype()) ? "" : printSet.getPrinttype());
+        result.setUserName(db_username);
         return result;
 
     }

+ 3 - 2
frontend/saas-web/app/view/core/form/FormPanelController.js

@@ -446,10 +446,11 @@ Ext.define('saas.view.core.form.FormPanelController', {
                 printtype = data.printtype,
                 reportName = data.reportName,
                 title = data.title,
+                userName = data.userName,
                 whereCondition = data.whereCondition,
                 companyId = saas.util.BaseUtil.getCurrentUser().companyId;
-    
-                var url = printurl + '?' + 'reportName=' + reportName + '&' + 'companyId=' + companyId + '&whereCondition=' + whereCondition
+                var url = printurl + '?' + 'reportName=' + reportName + '&' + 'companyId=' + companyId + '&whereCondition=' + whereCondition +
+                userName ? '&userName=' + userName : "";
     
                 window.open(url);
             }).catch(function(res) {