|
|
@@ -21,12 +21,17 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import com.alibaba.druid.pool.DruidDataSource;
|
|
|
import com.alibaba.druid.pool.DruidDataSourceFactory;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.uas.report.core.exception.SystemError;
|
|
|
import com.uas.report.service.PrintService;
|
|
|
import com.uas.report.util.ContextUtils;
|
|
|
import com.uas.report.util.ReportConstants;
|
|
|
|
|
|
+import net.sf.jasperreports.engine.JRBand;
|
|
|
+import net.sf.jasperreports.engine.JRElement;
|
|
|
import net.sf.jasperreports.engine.JRException;
|
|
|
+import net.sf.jasperreports.engine.JRSection;
|
|
|
+import net.sf.jasperreports.engine.JRTextField;
|
|
|
import net.sf.jasperreports.engine.JasperCompileManager;
|
|
|
import net.sf.jasperreports.engine.JasperExportManager;
|
|
|
import net.sf.jasperreports.engine.JasperFillManager;
|
|
|
@@ -54,7 +59,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
private static Logger logger = Logger.getLogger(PrintService.class);
|
|
|
|
|
|
@Override
|
|
|
- public byte[] export(String userName, String reportName, String whereCondition, Map<String, Object> otherParameters,
|
|
|
+ public byte[] export(String userName, String reportName, String whereCondition, String otherParameters,
|
|
|
String exportFileType) {
|
|
|
Map<String, Object> result = print(userName, reportName, whereCondition, otherParameters, exportFileType, null);
|
|
|
if (!CollectionUtils.isEmpty(result)) {
|
|
|
@@ -65,7 +70,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> preview(String userName, String reportName, String whereCondition,
|
|
|
- Map<String, Object> otherParameters, Integer pageIndex) {
|
|
|
+ String otherParameters, Integer pageIndex) {
|
|
|
return print(userName, reportName, whereCondition, otherParameters, null, pageIndex);
|
|
|
}
|
|
|
|
|
|
@@ -80,8 +85,8 @@ public class PrintServiceImpl implements PrintService {
|
|
|
* @param pageIndex
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, Object> print(String userName, String reportName, String whereCondition,
|
|
|
- Map<String, Object> otherParameters, String exportFileType, Integer pageIndex) {
|
|
|
+ private Map<String, Object> print(String userName, String reportName, String whereCondition, String otherParameters,
|
|
|
+ String exportFileType, Integer pageIndex) {
|
|
|
String message = "";
|
|
|
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(reportName)) {
|
|
|
message = "参数错误";
|
|
|
@@ -131,8 +136,10 @@ public class PrintServiceImpl implements PrintService {
|
|
|
if (!StringUtils.isEmpty(whereCondition)) {
|
|
|
parameters.put(ReportConstants.PARAMETER_WHERE_CONDITION, whereCondition);
|
|
|
}
|
|
|
- if (!CollectionUtils.isEmpty(otherParameters)) {
|
|
|
- parameters.putAll(otherParameters);
|
|
|
+
|
|
|
+ // 不为空,并且去除空格后的长度大于2(不为{})
|
|
|
+ if (!StringUtils.isEmpty(otherParameters) && otherParameters.replace(" ", "").length() > 2) {
|
|
|
+ parameters.putAll(JSONObject.parseObject(otherParameters));
|
|
|
}
|
|
|
|
|
|
Connection connection = null;
|
|
|
@@ -198,7 +205,7 @@ public class PrintServiceImpl implements PrintService {
|
|
|
result.put("pageSize", jasperPrint.getPages().size());
|
|
|
return result;
|
|
|
} else {
|
|
|
- message = "exportFileType 和 pageSize 不能同时为空!";
|
|
|
+ message = "exportFileType 和 pageIndex 不能同时为空!";
|
|
|
logger.error(message);
|
|
|
throw new SystemError(message);
|
|
|
}
|
|
|
@@ -371,5 +378,14 @@ public class PrintServiceImpl implements PrintService {
|
|
|
jasperDesign.setLeftMargin(0);
|
|
|
jasperDesign.setBottomMargin(0);
|
|
|
jasperDesign.setRightMargin(0);
|
|
|
+
|
|
|
+ // 设置DetailBand中的元素高度不动态调整
|
|
|
+ JRSection detailSection = jasperDesign.getDetailSection();
|
|
|
+ JRBand[] bands = detailSection.getBands();
|
|
|
+ JRElement[] elements = bands[0].getElements();
|
|
|
+ for (JRElement element : elements) {
|
|
|
+ JRTextField textField = (JRTextField) element;
|
|
|
+ textField.setStretchWithOverflow(false);
|
|
|
+ }
|
|
|
}
|
|
|
}
|