|
@@ -1,8 +1,11 @@
|
|
|
package org.jeecg.modules.platCode.controller;
|
|
|
|
|
|
+import java.io.OutputStream;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
@@ -13,13 +16,26 @@ import java.util.HashMap;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.enums.WriteDirectionEnum;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillWrapper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.common.util.UUIDGenerator;
|
|
|
+import org.jeecg.modules.baseCode.entity.BaseTemplates;
|
|
|
+import org.jeecg.modules.baseCode.service.IBaseTemplatesService;
|
|
|
import org.jeecg.modules.baseCode.service.ISerialPatternService;
|
|
|
-import org.jeecg.modules.platCode.entity.PlatCommissionContract;
|
|
|
import org.jeecg.modules.platCode.entity.PlatCommissionOrder;
|
|
|
import org.jeecg.modules.platCode.service.IPlatCommissionContractService;
|
|
|
import org.jeecg.modules.saleCode.entity.SaleInvoice;
|
|
|
import org.jeecg.modules.saleCode.service.ISaleInvoiceService;
|
|
|
+import org.jeecg.modules.system.service.ISysDictService;
|
|
|
+import org.jeecg.modules.utils.ExcelExportUtils;
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
@@ -38,6 +54,7 @@ import org.jeecg.modules.platCode.service.IPlatCommissionOrderService;
|
|
|
import org.jeecg.modules.platCode.service.IPlatCommissionOrderProductService;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -68,6 +85,8 @@ public class PlatCommissionOrderController {
|
|
|
private IPlatCommissionOrderService platCommissionOrderService;
|
|
|
@Autowired
|
|
|
private IPlatCommissionOrderProductService platCommissionOrderProductService;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictService sysDictService;
|
|
|
|
|
|
@Autowired
|
|
|
private IPlatCommissionContractService platCommissionContractService;
|
|
@@ -75,7 +94,11 @@ public class PlatCommissionOrderController {
|
|
|
private ISerialPatternService serialPatternService;
|
|
|
@Autowired
|
|
|
private ISaleInvoiceService saleInvoiceService;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IBaseTemplatesService baseTemplatesService;
|
|
|
+
|
|
|
+ @Value(value = "${jeecg.path.upload}")
|
|
|
+ private String uploadpath;
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
*
|
|
@@ -537,6 +560,75 @@ public class PlatCommissionOrderController {
|
|
|
return mv;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 这是ExcelUtil.getOutputStream
|
|
|
+ * 这里就是将文件下载交给了浏览器
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception {
|
|
|
+ // 这里文件名如果涉及中文一定要使用URL编码,否则会乱码
|
|
|
+ String exportFileName = URLEncoder.encode(fileName + ExcelTypeEnum.XLSX.getValue(), StandardCharsets.UTF_8.toString());
|
|
|
+ response.setContentType("application/force-download");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + exportFileName);
|
|
|
+ return response.getOutputStream();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出excel
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportBillXls")
|
|
|
+ public void exportBillXls(HttpServletResponse response, PlatCommissionOrder saleOrder) throws Exception {
|
|
|
+ PlatCommissionOrder platCommissionOrder = platCommissionOrderService.getById(saleOrder.getId());
|
|
|
+ if(platCommissionOrder==null) {
|
|
|
+ throw new JeecgBootException("数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseTemplates templates = baseTemplatesService.getByTemplateType("佣金订单");
|
|
|
+ if(platCommissionOrder==null) {
|
|
|
+ throw new JeecgBootException("佣金订单导出模板不存在");
|
|
|
+ }
|
|
|
+ List<PlatCommissionOrderProduct> productList = platCommissionOrderProductService.selectByMainId(saleOrder.getId());
|
|
|
+
|
|
|
+ int rowNum = 1;
|
|
|
+ for(PlatCommissionOrderProduct o:productList){
|
|
|
+ o.setRowNumber(rowNum++);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String currencyText = sysDictService.queryDictTextByKey("currency", platCommissionOrder.getCurrency());
|
|
|
+ platCommissionOrder.setCurrencyText(currencyText);
|
|
|
+
|
|
|
+ platCommissionOrder.setBillDateText(DateUtils.date2Str(platCommissionOrder.getBillDate(), DateUtils.date_sdf.get()));
|
|
|
+
|
|
|
+ platCommissionOrder.setCommissionRateText(platCommissionOrder.getCommissionRate().doubleValue() + "%");
|
|
|
+
|
|
|
+ String templateFilePath = uploadpath + templates.getTemplateFile();//"/template/佣金订单.xlsx";
|
|
|
+ String tempFilePath = uploadpath + "/" + UUIDGenerator.generate() + ".xlsx";
|
|
|
+
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write(tempFilePath).withTemplate(templateFilePath).build()) {
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
+ FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).forceNewRow(Boolean.TRUE).build();
|
|
|
+ excelWriter.fill(new FillWrapper(productList), fillConfig, writeSheet);
|
|
|
+ excelWriter.fill(platCommissionOrder, writeSheet);
|
|
|
+ }
|
|
|
+ List<String> noteList = new ArrayList<>();
|
|
|
+// productList.forEach(p -> noteList.add(p.getNotes()));
|
|
|
+
|
|
|
+ ExcelExportUtils.excelInsertRowNotes(getOutputStream("OA - "+platCommissionOrder.getBillCode() + ".xlsx", response),
|
|
|
+ tempFilePath, 19, noteList, 1, 4);
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new JeecgBootException("数据异常:"+e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 通过excel导入数据
|
|
|
*
|