|
@@ -3,8 +3,10 @@ package com.jpsoft.printing.modules.base.controller;
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.Page;
|
|
import com.jpsoft.printing.modules.base.entity.Account;
|
|
import com.jpsoft.printing.modules.base.entity.Account;
|
|
import com.jpsoft.printing.modules.base.entity.Customer;
|
|
import com.jpsoft.printing.modules.base.entity.Customer;
|
|
|
|
+import com.jpsoft.printing.modules.base.entity.Stock;
|
|
import com.jpsoft.printing.modules.base.service.AccountService;
|
|
import com.jpsoft.printing.modules.base.service.AccountService;
|
|
import com.jpsoft.printing.modules.base.service.CustomerService;
|
|
import com.jpsoft.printing.modules.base.service.CustomerService;
|
|
|
|
+import com.jpsoft.printing.modules.base.service.StockService;
|
|
import com.jpsoft.printing.modules.common.utils.PojoUtils;
|
|
import com.jpsoft.printing.modules.common.utils.PojoUtils;
|
|
import com.jpsoft.printing.modules.common.dto.Sort;
|
|
import com.jpsoft.printing.modules.common.dto.Sort;
|
|
import com.jpsoft.printing.modules.common.dto.MessageResult;
|
|
import com.jpsoft.printing.modules.common.dto.MessageResult;
|
|
@@ -14,13 +16,21 @@ import com.jpsoft.printing.modules.sys.service.SysLogService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
@@ -37,6 +47,8 @@ public class WorkController {
|
|
private WorkService workService;
|
|
private WorkService workService;
|
|
@Autowired
|
|
@Autowired
|
|
private AccountService accountService;
|
|
private AccountService accountService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private StockService stockService;
|
|
|
|
|
|
@ApiOperation(value="创建空记录")
|
|
@ApiOperation(value="创建空记录")
|
|
@GetMapping("create")
|
|
@GetMapping("create")
|
|
@@ -286,4 +298,147 @@ public class WorkController {
|
|
|
|
|
|
return msgResult;
|
|
return msgResult;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="细码单数据")
|
|
|
|
+ private Map dataXMD(String workId){
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+
|
|
|
|
+ Work work = workService.get(workId);
|
|
|
|
+ Customer customer = customerService.get(work.getCustomerId());
|
|
|
|
+
|
|
|
|
+ BigDecimal totalLength = new BigDecimal(0);
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
|
+ List<Stock> stockList = stockService.findList(workId);
|
|
|
|
+ for(int i=0; i<stockList.size(); i++){
|
|
|
|
+ Stock stock = stockList.get(i);
|
|
|
|
+ totalLength = totalLength.add(stock.getLength());
|
|
|
|
+
|
|
|
|
+ Map<String, Object> accMap = new HashMap<>();
|
|
|
|
+ accMap.put("sort", i+1);
|
|
|
|
+ accMap.put("number", stock.getStockNumber());
|
|
|
|
+ accMap.put("length", stock.getLength());
|
|
|
|
+ mapList.add(accMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ map.put("customer", customer.getCompany());
|
|
|
|
+ map.put("number", work.getNumber());
|
|
|
|
+ map.put("name", work.getName());
|
|
|
|
+ map.put("width", work.getWidth());
|
|
|
|
+ map.put("list", mapList);
|
|
|
|
+ map.put("totalCount", stockList.size());
|
|
|
|
+ map.put("totalLength", totalLength);
|
|
|
|
+
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="细码单")
|
|
|
|
+ @RequestMapping(value = "tableXMD",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult tableXMD(String workId){
|
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Map map = dataXMD(workId);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(map);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="细码单报表")
|
|
|
|
+ @RequestMapping(value = "tableXMDXls",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult tableXMDXls(String workId) throws Exception {
|
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Map map = dataXMD(workId);
|
|
|
|
+
|
|
|
|
+ String xlsPath = "static/xmd.xls";
|
|
|
|
+ ClassPathResource resource = new ClassPathResource(xlsPath);
|
|
|
|
+ Workbook wb = WorkbookFactory.create(resource.getInputStream());
|
|
|
|
+
|
|
|
|
+ //Excel
|
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
|
+ //样式
|
|
|
|
+ CellStyle style = wb.createCellStyle();
|
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
+ Font font = wb.createFont();
|
|
|
|
+ font.setFontHeightInPoints((short)10);
|
|
|
|
+ style.setFont(font);
|
|
|
|
+ //数据
|
|
|
|
+ Row rowTitle = sheet.getRow(1);
|
|
|
|
+ rowTitle.getCell(0).setCellValue("客户:" + map.get("customer").toString());
|
|
|
|
+ rowTitle.getCell(3).setCellValue("订单号:" + map.get("number").toString());
|
|
|
|
+ rowTitle.getCell(6).setCellValue("品名:" + map.get("name").toString());
|
|
|
|
+ rowTitle.getCell(9).setCellValue("幅宽:" + map.get("width").toString());
|
|
|
|
+ int rowNum = 2;
|
|
|
|
+
|
|
|
|
+ List<Map> list = (List<Map>)map.get("list");
|
|
|
|
+ for(int i=0; i<list.size(); i++) {
|
|
|
|
+ Map item = list.get(i);
|
|
|
|
+
|
|
|
|
+ Row row = null;
|
|
|
|
+ int remainder = i % 4;
|
|
|
|
+ if(remainder == 0) {
|
|
|
|
+ row = sheet.createRow(++rowNum);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ row = sheet.getRow(rowNum);
|
|
|
|
+ }
|
|
|
|
+ row.createCell(remainder * 3).setCellValue(item.get("sort").toString());
|
|
|
|
+ row.getCell(remainder * 3).setCellStyle(style);
|
|
|
|
+ row.createCell(remainder * 3 + 1).setCellValue(item.get("number").toString());
|
|
|
|
+ row.getCell(remainder * 3 + 1).setCellStyle(style);
|
|
|
|
+ row.createCell(remainder * 3 + 2).setCellValue(item.get("length").toString());
|
|
|
|
+ row.getCell(remainder * 3 + 2).setCellStyle(style);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rowNum++;
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 1));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 2, 3));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 4, 5));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 6, 7));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 8, 11));
|
|
|
|
+ Row rowBottom1 = sheet.createRow(rowNum);
|
|
|
|
+ rowBottom1.createCell(0).setCellValue("件数");
|
|
|
|
+ rowBottom1.getCell(0).setCellStyle(style);
|
|
|
|
+ rowBottom1.createCell(2).setCellValue("米数");
|
|
|
|
+ rowBottom1.getCell(2).setCellStyle(style);
|
|
|
|
+ rowBottom1.createCell(4).setCellValue("单价");
|
|
|
|
+ rowBottom1.getCell(4).setCellStyle(style);
|
|
|
|
+ rowBottom1.createCell(6).setCellValue("金额");
|
|
|
|
+ rowBottom1.getCell(6).setCellStyle(style);
|
|
|
|
+ rowBottom1.createCell(8).setCellValue("作欠款凭证");
|
|
|
|
+ rowBottom1.getCell(8).setCellStyle(style);
|
|
|
|
+
|
|
|
|
+ rowNum++;
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 0, 1));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 2, 3));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 4, 5));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 6, 7));
|
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNum, rowNum, 8, 11));
|
|
|
|
+ Row rowBottom2 = sheet.createRow(rowNum);
|
|
|
|
+ rowBottom2.createCell(0).setCellValue(map.get("totalCount").toString());
|
|
|
|
+ rowBottom2.getCell(0).setCellStyle(style);
|
|
|
|
+ rowBottom2.createCell(2).setCellValue(map.get("totalLength").toString());
|
|
|
|
+ rowBottom2.getCell(2).setCellStyle(style);
|
|
|
|
+
|
|
|
|
+ //保存到服务器,返回文件名
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
|
+ wb.write(output);
|
|
|
|
+ String fileName = "细码单(" + sdf.format(new Date()) + ").xls";
|
|
|
|
+ String name = "D:\\JpSoft\\Tomcat 8.5\\webapps\\printing-portal\\xls\\" + fileName;
|
|
|
|
+ File file = new File(name);
|
|
|
|
+ FileOutputStream file1 = new FileOutputStream(file);
|
|
|
|
+ wb.write(file1);
|
|
|
|
+ file1.close();
|
|
|
|
+ wb.close();
|
|
|
|
+ output.close();
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setMessage("报表生成完成。");
|
|
|
|
+ msgResult.setData("/printing-portal/xls/" + fileName);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
}
|
|
}
|