|
|
@@ -7,6 +7,8 @@ import java.util.Map;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.commons.lang.ArrayUtils;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@@ -26,6 +28,8 @@ import com.uas.report.service.PrintService;
|
|
|
@RequestMapping("/print")
|
|
|
public class PrintController {
|
|
|
|
|
|
+ private static Logger logger = Logger.getLogger(PrintController.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private PrintService printService;
|
|
|
|
|
|
@@ -48,14 +52,15 @@ public class PrintController {
|
|
|
String message = "";
|
|
|
if (StringUtils.isEmpty(reportName)) {
|
|
|
message = "报表名称无效!";
|
|
|
- System.out.println(message);
|
|
|
+ logger.error(message);
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
- System.out.println("\n开始打印报表: " + reportName + "...");
|
|
|
+ logger.info("开始打印报表: " + reportName);
|
|
|
byte[] results = printService.print(reportName, whereCondition, otherParameters);
|
|
|
- if (results == null || results.length < 1) {
|
|
|
+ if (ArrayUtils.isEmpty(results)) {
|
|
|
message = "报表 " + reportName + " 打印失败!";
|
|
|
+ logger.error(message);
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
@@ -67,49 +72,28 @@ public class PrintController {
|
|
|
outputStream.flush();
|
|
|
outputStream.close();
|
|
|
} catch (IOException e) {
|
|
|
- System.out.println("连接被关闭!");
|
|
|
+ logger.error("连接被关闭!");
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
message = "报表 " + reportName + " 打印完成!";
|
|
|
- System.out.println(message);
|
|
|
+ logger.info(message);
|
|
|
return message;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 测试打印
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@RequestMapping("/test")
|
|
|
@ResponseBody
|
|
|
public String testPrint(HttpServletResponse response) {
|
|
|
String reportName = "Purchase";
|
|
|
- String whereCondition = "where pu_code = 'MP160800017'";
|
|
|
+ String whereCondition = "where pu_code = 'MP160800017' and pd_qty > 1000";
|
|
|
Map<String, Object> otherParameters = new HashMap<>();
|
|
|
otherParameters.put("OTHER_PARAMETER_1", "天气真好!");
|
|
|
-
|
|
|
- String message = "";
|
|
|
- if (StringUtils.isEmpty(reportName)) {
|
|
|
- message = "报表名称无效!";
|
|
|
- System.out.println(message);
|
|
|
- return message;
|
|
|
- }
|
|
|
-
|
|
|
- System.out.println("\n开始打印报表: " + reportName + "...");
|
|
|
- byte[] results = printService.print(reportName, whereCondition, otherParameters);
|
|
|
- if (results == null || results.length < 1) {
|
|
|
- message = "报表 " + reportName + " 打印失败!";
|
|
|
- return message;
|
|
|
- }
|
|
|
-
|
|
|
- OutputStream outputStream = null;
|
|
|
- try {
|
|
|
- response.setContentType("application/pdf");
|
|
|
- outputStream = response.getOutputStream();
|
|
|
- outputStream.write(results);
|
|
|
- outputStream.flush();
|
|
|
- outputStream.close();
|
|
|
- } catch (IOException e) {
|
|
|
- System.out.println("连接被关闭!");
|
|
|
- }
|
|
|
-
|
|
|
- message = "报表 " + reportName + " 打印完成!";
|
|
|
- System.out.println(message);
|
|
|
- return message;
|
|
|
+ return print(reportName, whereCondition, otherParameters, response);
|
|
|
}
|
|
|
}
|