|
@@ -7,12 +7,8 @@ import java.math.BigDecimal;
|
|
|
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;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -29,6 +25,7 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.jeecg.common.aspect.annotation.PermissionData;
|
|
|
import org.jeecg.common.system.vo.DictModel;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
+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;
|
|
@@ -41,6 +38,7 @@ import org.jeecg.modules.storeCode.service.IStoreSaleOutService;
|
|
|
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;
|
|
@@ -632,16 +630,25 @@ public class SaleDeliveryController {
|
|
|
exportByDeliver("随货发票", saleDelivery.getId(), response);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出签单
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/exportSignBillXls")
|
|
|
+ public void exportSignBillXls(HttpServletResponse response, SaleDelivery saleDelivery) throws Exception {
|
|
|
+ exportByDeliver("签单", saleDelivery.getId(), response);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 导出唛头
|
|
|
*
|
|
|
*/
|
|
|
@RequestMapping(value = "/exportShippingBillXls")
|
|
|
- public void exportShippingBillXls(HttpServletResponse response, SaleDelivery saleDelivery) throws Exception {
|
|
|
- exportByDeliver("唛头", saleDelivery.getId(), response);
|
|
|
- }
|
|
|
+ public void exportShippingBillXls(HttpServletResponse response, SaleDelivery saleDelivery1) throws Exception {
|
|
|
+
|
|
|
+ String templateName = "唛头";
|
|
|
+ String id=saleDelivery1.getId();
|
|
|
|
|
|
- private void exportByDeliver(String templateName, String id, HttpServletResponse response){
|
|
|
BaseTemplates templates = baseTemplatesService.getByTemplateType(templateName);
|
|
|
SaleDelivery saleDelivery = saleDeliveryService.getById(id);
|
|
|
List<SaleDeliveryDetails> deliveryDetailsList = saleDeliveryDetailsService.selectByMainId(id);
|
|
@@ -696,6 +703,8 @@ public class SaleDeliveryController {
|
|
|
SaleOrder saleOrder = saleOrderService.getOne(orderLambdaQueryWrapper);
|
|
|
if (saleOrder != null){
|
|
|
saleDelivery.setPaymentTerms(saleOrder.getPaymentTerms());
|
|
|
+ saleDelivery.setOrderNumber(saleOrder.getCustomerOrder());
|
|
|
+ saleDelivery.setAgreementTerms(saleOrder.getAgreementTerms());
|
|
|
}
|
|
|
}
|
|
|
// 查询数据字典
|
|
@@ -787,6 +796,174 @@ public class SaleDeliveryController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void exportByDeliver(String templateName, String id, HttpServletResponse response){
|
|
|
+ BaseTemplates templates = baseTemplatesService.getByTemplateType(templateName);
|
|
|
+ SaleDelivery saleDelivery = saleDeliveryService.getById(id);
|
|
|
+ List<SaleDeliveryDetails> deliveryDetailsList = saleDeliveryDetailsService.selectByMainId(id);
|
|
|
+ List<SaleDeliveryShip> deliveryShipList = saleDeliveryShipService.selectByMainId(id);
|
|
|
+
|
|
|
+
|
|
|
+ if (templates != null) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ String productionClass = saleDelivery.getProductionClass();
|
|
|
+ if (StringUtils.isNotBlank(productionClass)) {
|
|
|
+
|
|
|
+ BaseProductClass classEnt = baseProductClassService.getById(productionClass);
|
|
|
+ if (classEnt != null) {
|
|
|
+ saleDelivery.setProductionClass(classEnt.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String getQuotationCustomer = saleDelivery.getCustomer();
|
|
|
+ if (StringUtils.isNotBlank(getQuotationCustomer)) {
|
|
|
+
|
|
|
+ CuspCustomerProfile classEnt = cuspCustomerProfileService.getById(getQuotationCustomer);
|
|
|
+ if (classEnt != null) {
|
|
|
+ saleDelivery.setCustomerAddress(classEnt.getRegisterAddress());
|
|
|
+ saleDelivery.setContacts(classEnt.getContacts());
|
|
|
+ saleDelivery.setPhone(classEnt.getPhone());
|
|
|
+ saleDelivery.setEmail(classEnt.getEmail());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取计产品档案
|
|
|
+ List<BaseProductArchive> productArchiveList = new ArrayList<>();
|
|
|
+ if (oConvertUtils.listIsNotEmpty(deliveryDetailsList)){
|
|
|
+ LambdaQueryWrapper<BaseProductArchive> productWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productWrapper.in(BaseProductArchive::getId, deliveryDetailsList.stream().map(SaleDeliveryDetails::getProductId).collect(Collectors.toList()));
|
|
|
+ productArchiveList = baseProductArchiveService.list(productWrapper);
|
|
|
+ }
|
|
|
+ // 获取销售订单行
|
|
|
+ List<SaleOrderProduct> saleOrderProductList = new ArrayList<>();
|
|
|
+ if (oConvertUtils.listIsNotEmpty(deliveryDetailsList)){
|
|
|
+ LambdaQueryWrapper<SaleOrderProduct> productWrapper = new LambdaQueryWrapper<>();
|
|
|
+ productWrapper.in(SaleOrderProduct::getId, deliveryDetailsList.stream().map(SaleDeliveryDetails::getSourceId).collect(Collectors.toList()));
|
|
|
+ saleOrderProductList = saleOrderProductService.list(productWrapper);
|
|
|
+ }
|
|
|
+ // 获取销售订单
|
|
|
+ if (oConvertUtils.isNotEmpty(saleDelivery.getSourceCode())){
|
|
|
+ LambdaQueryWrapper<SaleOrder> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper.eq(SaleOrder::getBillCode, saleDelivery.getSourceCode());
|
|
|
+ SaleOrder saleOrder = saleOrderService.getOne(orderLambdaQueryWrapper);
|
|
|
+ if (saleOrder != null){
|
|
|
+ saleDelivery.setPaymentTerms(saleOrder.getPaymentTerms());
|
|
|
+ saleDelivery.setOrderNumber(saleOrder.getCustomerOrder());
|
|
|
+ saleDelivery.setAgreementTerms(saleOrder.getAgreementTerms());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 查询数据字典
|
|
|
+ String currencyText = sysDictService.queryDictTextByKey("currency", saleDelivery.getCurrency());
|
|
|
+ saleDelivery.setCurrencyText(currencyText);
|
|
|
+ String paymentTermsText = sysDictService.queryDictTextByKey("customer_payment_terms", saleDelivery.getPaymentTerms());
|
|
|
+ saleDelivery.setPaymentTermsText(paymentTermsText);
|
|
|
+ List<DictModel> unitDictList = sysDictService.queryDictItemsByCode("measurement_unit");
|
|
|
+
|
|
|
+ // 产品设置
|
|
|
+ int rowNum = 1;
|
|
|
+ BigDecimal deliverMoney = BigDecimal.ZERO;
|
|
|
+ for(SaleDeliveryDetails o:deliveryDetailsList){
|
|
|
+ BigDecimal amount = o.getMoney() == null ? BigDecimal.ZERO: o.getMoney();
|
|
|
+ deliverMoney = deliverMoney.add(amount);
|
|
|
+ o.setRowNumber(rowNum++);
|
|
|
+ if (o.getDeliveryTime() != null){
|
|
|
+ o.setDeliverDateText(DateUtils.date2Str(o.getDeliveryTime(), DateUtils.date_sdf.get()));
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseProductArchive findProduct = productArchiveList.stream().filter(e->e.getId().equals(o.getProductId())).findFirst().orElse(null);
|
|
|
+ if (findProduct != null){
|
|
|
+ o.setUnit(findProduct.getMeasurementUnit());
|
|
|
+ if (findProduct.getMeasurementUnit() != null){
|
|
|
+ DictModel findDict = unitDictList.stream().filter(d->d.getValue().equals(findProduct.getMeasurementUnit())).findFirst().orElse(null);
|
|
|
+ if (findDict != null){
|
|
|
+ o.setUnit(findDict.getText());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SaleOrderProduct saleOrderProduct = saleOrderProductList.stream().filter(e->e.getId().equals(o.getSourceId())).findFirst().orElse(null);
|
|
|
+ if (saleOrderProduct != null){
|
|
|
+ if (oConvertUtils.isNotEmpty(saleOrderProduct.getDiscount()) && saleOrderProduct.getDiscount().intValue() != 0){
|
|
|
+ o.setDiscountText(saleOrderProduct.getDiscount().intValue()+"%");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ deliverMoney = deliverMoney.setScale(2);
|
|
|
+ saleDelivery.setDeliveryMoney(deliverMoney);
|
|
|
+
|
|
|
+ String shipname = "";
|
|
|
+ String imo = "";
|
|
|
+
|
|
|
+ if(oConvertUtils.listIsNotEmpty(deliveryShipList)){
|
|
|
+
|
|
|
+ shipname = deliveryShipList.stream().map(SaleDeliveryShip::getShipName).distinct().collect(Collectors.joining());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<BaseShipArchive> shipArchiveLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ shipArchiveLambdaQueryWrapper.in(BaseShipArchive::getId,deliveryShipList.stream().map(SaleDeliveryShip::getShipId).collect(Collectors.joining()));
|
|
|
+ List<BaseShipArchive> baseShipArchiveList = baseShipArchiveService.list(shipArchiveLambdaQueryWrapper);
|
|
|
+
|
|
|
+ if(oConvertUtils.listIsNotEmpty(baseShipArchiveList)){
|
|
|
+ imo = baseShipArchiveList.stream().map(BaseShipArchive::getImo).distinct().collect(Collectors.joining());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saleDelivery.setShipName(shipname);
|
|
|
+ saleDelivery.setImo(imo);
|
|
|
+ // 项目名称
|
|
|
+ if (saleDelivery.getProject() != null){
|
|
|
+ BaseProjectArchive projectArchive = baseProjectArchiveService.getById(saleDelivery.getProject());
|
|
|
+ if (projectArchive != null){
|
|
|
+ saleDelivery.setContactsNo(projectArchive.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(deliveryDetailsList.size() > 0){
|
|
|
+
|
|
|
+ saleDelivery.setQualityGrade(deliveryDetailsList.get(0).getQualityGrade());
|
|
|
+ }
|
|
|
+ //
|
|
|
+ saleDelivery.setBillDateText(DateUtils.date2Str(saleDelivery.getDeliveryDate(), DateUtils.date_sdf.get()));
|
|
|
+
|
|
|
+ // 账期
|
|
|
+ saleDelivery.setDueDateText(saleDelivery.getBillDateText());
|
|
|
+ if (oConvertUtils.isNotEmpty(paymentTermsText)){
|
|
|
+ if (paymentTermsText.indexOf(" ")>-1){
|
|
|
+ String[] split = paymentTermsText.split(" ");
|
|
|
+ if (oConvertUtils.getInt(split[0], 0)>0) {
|
|
|
+ saleDelivery.setDueDateText(DateUtils.date2Str(DateUtils.dateAdd(saleDelivery.getDeliveryDate(), Calendar.DATE, Integer.parseInt(split[0])), DateUtils.date_sdf.get()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 制单人信息
|
|
|
+ SysUser sysUser = sysUserService.getUserByName(saleDelivery.getCreateBy());
|
|
|
+ saleDelivery.setSalesPhone(sysUser.getPhone());
|
|
|
+ saleDelivery.setSalesEmail(sysUser.getEmail());
|
|
|
+
|
|
|
+ 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(deliveryDetailsList), fillConfig, writeSheet);
|
|
|
+ excelWriter.fill(saleDelivery, writeSheet);
|
|
|
+ }
|
|
|
+ List<String> noteList = new ArrayList<>();
|
|
|
+ deliveryDetailsList.forEach(p->noteList.add(p.getNotes()));
|
|
|
+
|
|
|
+ int startIndex = 18;
|
|
|
+ if ("随货发票".equals(templateName)){
|
|
|
+ startIndex = 19;
|
|
|
+ }
|
|
|
+ ExcelExportUtils.excelInsertRowNotes(getOutputStream(saleDelivery.getBillCode()+".xlsx", response),
|
|
|
+ tempFilePath, startIndex, noteList, 2, 4);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 这是ExcelUtil.getOutputStream
|
|
|
* 这里就是将文件下载交给了浏览器
|