|  | @@ -4,6 +4,9 @@ import java.io.*;
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.net.URLEncoder;
 | 
	
		
			
				|  |  |  import java.nio.charset.StandardCharsets;
 | 
	
		
			
				|  |  | +import java.nio.file.Files;
 | 
	
		
			
				|  |  | +import java.nio.file.Path;
 | 
	
		
			
				|  |  | +import java.nio.file.Paths;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -11,21 +14,25 @@ import javax.servlet.ServletOutputStream;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletRequest;
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import cn.hutool.core.io.FileUtil;
 | 
	
		
			
				|  |  |  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.merge.LoopMergeStrategy;
 | 
	
		
			
				|  |  |  import com.alibaba.excel.write.metadata.WriteSheet;
 | 
	
		
			
				|  |  |  import com.alibaba.excel.write.metadata.fill.FillConfig;
 | 
	
		
			
				|  |  |  import com.alibaba.excel.write.metadata.fill.FillWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 | 
	
		
			
				|  |  | +import org.apache.poi.ss.usermodel.*;
 | 
	
		
			
				|  |  | +import org.apache.poi.ss.util.CellRangeAddress;
 | 
	
		
			
				|  |  | +import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 | 
	
		
			
				|  |  |  import org.jeecg.common.aspect.annotation.PermissionData;
 | 
	
		
			
				|  |  |  import org.jeecg.common.util.DateUtils;
 | 
	
		
			
				|  |  | -import org.jeecg.modules.baseCode.entity.BaseProductArchive;
 | 
	
		
			
				|  |  | -import org.jeecg.modules.baseCode.entity.BaseProductClass;
 | 
	
		
			
				|  |  | -import org.jeecg.modules.baseCode.entity.BaseShipArchive;
 | 
	
		
			
				|  |  | -import org.jeecg.modules.baseCode.entity.BaseTemplates;
 | 
	
		
			
				|  |  | +import org.jeecg.common.util.UUIDGenerator;
 | 
	
		
			
				|  |  | +import org.jeecg.modules.baseCode.entity.*;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.baseCode.service.*;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.cuspCode.entity.CuspCustomerProfile;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.cuspCode.entity.CuspSupplierProfile;
 | 
	
	
		
			
				|  | @@ -38,7 +45,9 @@ import org.jeecg.modules.saleCode.service.*;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.saleCode.util.EasyExcelUtil;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.saleCode.vo.SaleQuotationAlert;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.system.entity.SysUser;
 | 
	
		
			
				|  |  | +import org.jeecg.modules.system.service.ISysDictService;
 | 
	
		
			
				|  |  |  import org.jeecg.modules.system.service.ISysUserService;
 | 
	
		
			
				|  |  | +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;
 | 
	
	
		
			
				|  | @@ -106,6 +115,10 @@ public class SaleQuotationController {
 | 
	
		
			
				|  |  |      private IBaseShipArchiveService baseShipArchiveService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IBaseProductArchiveService baseProductArchiveService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private IBaseProjectArchiveService baseProjectArchiveService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ISysDictService sysDictService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Value(value = "${jeecg.path.upload}")
 | 
	
		
			
				|  |  |      private String uploadpath;
 | 
	
	
		
			
				|  | @@ -528,17 +541,8 @@ public class SaleQuotationController {
 | 
	
		
			
				|  |  |          List<SaleQuotationProduct> productList = saleQuotationProductService.selectByMainId(saleQuotation.getId());
 | 
	
		
			
				|  |  |          List<SaleQuotationShip> saleQuotationShipList = saleQuotationShipService.selectByMainId(saleQuotation.getId());
 | 
	
		
			
				|  |  |          if (templates != null) {
 | 
	
		
			
				|  |  | -            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
 | 
	
		
			
				|  |  | -            response.setCharacterEncoding("utf-8");
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | -                String fileName = URLEncoder.encode("销售报价单" + saleQuotation.getBillCode(), "UTF-8").replaceAll("\\+", "%20");
 | 
	
		
			
				|  |  | -                response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                String filePath = uploadpath + templates.getTemplateFile();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                //填写合同单号和模板, getOutputStream浏览器下载方法写在下方
 | 
	
		
			
				|  |  | -                ExcelWriter excelWriter = EasyExcel.write(this.getOutputStream(fileName, response)).withTemplate(filePath).build();
 | 
	
		
			
				|  |  | -                WriteSheet writeSheet = EasyExcel.writerSheet(0, "sheet1").build();
 | 
	
		
			
				|  |  |                  String productionClass = saleQuotation.getProductionClass();
 | 
	
		
			
				|  |  |                  if (StringUtils.isNotBlank(productionClass)) {
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -576,8 +580,11 @@ public class SaleQuotationController {
 | 
	
		
			
				|  |  |                      if (findProduct != null){
 | 
	
		
			
				|  |  |                          o.setUnit(findProduct.getMeasurementUnit());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                    if (o.getDiscount() != null && o.getDiscount().intValue() != 0){
 | 
	
		
			
				|  |  | +                        o.setDiscountText(String.valueOf(o.getDiscount()));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                saleQuotation.setOrderMoney(orderMoney);
 | 
	
		
			
				|  |  | +                saleQuotation.setOrderMoney(orderMoney.setScale(2));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  String shipname = "";
 | 
	
		
			
				|  |  |                  String imo = "";
 | 
	
	
		
			
				|  | @@ -596,7 +603,14 @@ public class SaleQuotationController {
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  saleQuotation.setShipName(shipname);
 | 
	
		
			
				|  |  |                  saleQuotation.setImo(imo);
 | 
	
		
			
				|  |  | -                saleQuotation.setContactsNo(saleQuotation.getQuotationProjectName());
 | 
	
		
			
				|  |  | +                // 项目名称
 | 
	
		
			
				|  |  | +                if (saleQuotation.getQuotationProject() != null){
 | 
	
		
			
				|  |  | +                    BaseProjectArchive projectArchive = baseProjectArchiveService.getById(saleQuotation.getQuotationProject());
 | 
	
		
			
				|  |  | +                    if (projectArchive != null){
 | 
	
		
			
				|  |  | +                        saleQuotation.setContactsNo(projectArchive.getName());
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |                  if(productList.size() > 0){
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      saleQuotation.setQualityGrade(productList.get(0).getQualityGrade());
 | 
	
	
		
			
				|  | @@ -609,11 +623,32 @@ public class SaleQuotationController {
 | 
	
		
			
				|  |  |                  SysUser sysUser = sysUserService.getUserByName(saleQuotation.getCreateBy());
 | 
	
		
			
				|  |  |                  saleQuotation.setSalesPhone(sysUser.getPhone());
 | 
	
		
			
				|  |  |                  saleQuotation.setSalesEmail(sysUser.getEmail());
 | 
	
		
			
				|  |  | -                // 组合填充时,因为多组填充的数据量不确定,需要在多组填充完之后另起一行
 | 
	
		
			
				|  |  | -                FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).forceNewRow(Boolean.TRUE).build();
 | 
	
		
			
				|  |  | -                excelWriter.fill(new FillWrapper(productList), fillConfig, writeSheet);
 | 
	
		
			
				|  |  | -                excelWriter.fill(saleQuotation, writeSheet);
 | 
	
		
			
				|  |  | -                excelWriter.finish();
 | 
	
		
			
				|  |  | +                // 查询数据字典
 | 
	
		
			
				|  |  | +                String paymentTermsText = sysDictService.queryDictTextByKey("customer_payment_terms", saleQuotation.getPaymentTerms());
 | 
	
		
			
				|  |  | +                String currencyText = sysDictService.queryDictTextByKey("currency", saleQuotation.getCurrency());
 | 
	
		
			
				|  |  | +                //String qualityGrade = sysDictService.queryDictTextByKey("quality_grade", saleQuotation.getQualityGrade());
 | 
	
		
			
				|  |  | +                saleQuotation.setPaymentTermsText(paymentTermsText);
 | 
	
		
			
				|  |  | +                saleQuotation.setCurrencyText(currencyText);
 | 
	
		
			
				|  |  | +                //saleQuotation.setQualityGrade(qualityGrade);
 | 
	
		
			
				|  |  | +                // 报价有效期
 | 
	
		
			
				|  |  | +                if (oConvertUtils.isNotEmpty(saleQuotation.getQuotationPeriodBegin()) && oConvertUtils.isNotEmpty(saleQuotation.getQuotationPeriodEnd())){
 | 
	
		
			
				|  |  | +                    saleQuotation.setQuotationPeriodText(String.valueOf(DateUtils.dateDiff('d', saleQuotation.getQuotationPeriodEnd(), saleQuotation.getQuotationPeriodBegin())));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                String templateFilePath = uploadpath + templates.getTemplateFile();
 | 
	
		
			
				|  |  | +                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(saleQuotation, writeSheet);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                List<String> noteList = new ArrayList<>();
 | 
	
		
			
				|  |  | +                productList.forEach(p->noteList.add(p.getNotes()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                ExcelExportUtils.excelInsertRowNotes(getOutputStream(saleQuotation.getBillCode()+".xlsx", response),
 | 
	
		
			
				|  |  | +                        tempFilePath, 21, noteList, 1, 3);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              } catch (Exception ex) {
 | 
	
		
			
				|  |  |                  ex.printStackTrace();
 |