|
@@ -4,20 +4,31 @@ import java.io.UnsupportedEncodingException;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.jeecg.common.aspect.annotation.PermissionData;
|
|
|
import org.jeecg.modules.baseCode.entity.BaseExchangeRate;
|
|
|
+import org.jeecg.modules.baseCode.entity.BaseTemplates;
|
|
|
import org.jeecg.modules.baseCode.service.IBaseExchangeRateService;
|
|
|
+import org.jeecg.modules.baseCode.service.IBaseTemplatesService;
|
|
|
import org.jeecg.modules.baseCode.service.ISerialPatternService;
|
|
|
import org.jeecg.modules.purCode.service.IPurPurchaseQuotationProductService;
|
|
|
import org.jeecg.modules.purCode.vo.SupplierQuotationDetails;
|
|
|
import org.jeecg.modules.saleCode.vo.SaleInquiryFormAlert;
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
+import org.jeecg.modules.system.service.ISysUserService;
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
@@ -38,6 +49,7 @@ import org.jeecg.modules.purCode.service.IPurInquiryFormShipService;
|
|
|
import org.jeecg.modules.purCode.service.IPurInquiryFormProductService;
|
|
|
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;
|
|
@@ -76,6 +88,13 @@ public class PurInquiryFormController {
|
|
|
private IPurPurchaseQuotationProductService purPurchaseInquiryProductService;
|
|
|
@Autowired
|
|
|
private IBaseExchangeRateService baseExchangeRateService;
|
|
|
+ @Autowired
|
|
|
+ private IBaseTemplatesService baseTemplatesService;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService sysUserService;
|
|
|
+
|
|
|
+ @Value(value = "${jeecg.path.upload}")
|
|
|
+ private String uploadpath;
|
|
|
|
|
|
/**
|
|
|
* 分页列表查询
|
|
@@ -657,4 +676,53 @@ public class PurInquiryFormController {
|
|
|
return Result.OK("文件导入失败!");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出供应商询价单
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/exportInquiryXls")
|
|
|
+ public void exportInquiryXls(String id, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+
|
|
|
+ BaseTemplates templates = baseTemplatesService.getByTemplateType("采购询价");
|
|
|
+ PurInquiryForm purInquiryForm = purInquiryFormService.getById(id);
|
|
|
+ LambdaQueryWrapper<PurInquiryFormProduct> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(PurInquiryFormProduct::getHeadId, id);
|
|
|
+ List<PurInquiryFormProduct> productList = purInquiryFormProductService.list(queryWrapper);
|
|
|
+ if (templates != null){
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ try {
|
|
|
+ String fileName = URLEncoder.encode("采购询价单" + purInquiryForm.getBillCode(), "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
+
|
|
|
+ String filePath = uploadpath + templates.getTemplateFile();
|
|
|
+
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(filePath).build()) {
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
+ // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行,然后下面的数据往后移动。默认 是false,会直接使用下一行,如果没有则创建。
|
|
|
+ // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了,所以慎用
|
|
|
+ // 简单的说 如果你的模板有list,且list不是最后一行,下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
|
|
|
+ // 如果数据量大 list不是最后一行 参照下一个
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
+ excelWriter.fill(productList, fillConfig, writeSheet);
|
|
|
+ Map<String, Object> map = BeanUtil.beanToMap(purInquiryForm);
|
|
|
+ // 制单人信息
|
|
|
+ SysUser sysUser = sysUserService.getUserByName(purInquiryForm.getCreateBy());
|
|
|
+ map.put("purchaseman", sysUser.getRealname());
|
|
|
+ map.put("purchasePhone", sysUser.getPhone());
|
|
|
+ map.put("purchaseEmail", sysUser.getEmail());
|
|
|
+
|
|
|
+ excelWriter.fill(map, writeSheet);
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|