Browse Source

箱单/随货发票导出

fenghaifu 3 tháng trước cách đây
mục cha
commit
2e9aef57c7

+ 1 - 1
srm-module-code/src/main/java/org/jeecg/modules/baseCode/controller/BaseProductArchiveController.java

@@ -60,7 +60,7 @@ public class BaseProductArchiveController extends JeecgController<BaseProductArc
                                                            HttpServletRequest req) {
         QueryWrapper<BaseProductArchive> queryWrapper = QueryGenerator.initQueryWrapper(baseProductArchive, req.getParameterMap());
         Page<BaseProductArchive> page = new Page<BaseProductArchive>(pageNo, pageSize);
-        queryWrapper.orderByDesc("create_time");
+        queryWrapper.orderByDesc("create_time").orderByDesc("code");
         IPage<BaseProductArchive> pageList = baseProductArchiveService.page(page, queryWrapper);
         return Result.OK(pageList);
     }

+ 212 - 5
srm-module-code/src/main/java/org/jeecg/modules/saleCode/controller/SaleDeliveryController.java

@@ -1,8 +1,12 @@
 package org.jeecg.modules.saleCode.controller;
 
+import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.io.IOException;
+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;
@@ -13,14 +17,28 @@ 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 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.service.ISerialPatternService;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.baseCode.entity.*;
+import org.jeecg.modules.baseCode.service.*;
+import org.jeecg.modules.cuspCode.entity.CuspCustomerProfile;
+import org.jeecg.modules.cuspCode.service.ICuspCustomerProfileService;
 import org.jeecg.modules.saleCode.entity.*;
-import org.jeecg.modules.saleCode.service.ISaleInvoiceService;
+import org.jeecg.modules.saleCode.service.*;
 import org.jeecg.modules.saleCode.vo.SaleDeliveryAlert;
 import org.jeecg.modules.storeCode.entity.StoreSaleOut;
 import org.jeecg.modules.storeCode.service.IStoreSaleOutService;
+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;
@@ -33,11 +51,9 @@ import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.system.query.QueryRuleEnum;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.saleCode.vo.SaleDeliveryPage;
-import org.jeecg.modules.saleCode.service.ISaleDeliveryService;
-import org.jeecg.modules.saleCode.service.ISaleDeliveryShipService;
-import org.jeecg.modules.saleCode.service.ISaleDeliveryDetailsService;
 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 +92,27 @@ public class SaleDeliveryController {
     private ISerialPatternService serialPatternService;
     @Autowired
     private IStoreSaleOutService storeSaleOutService;
+    @Autowired
+    private IBaseTemplatesService baseTemplatesService;
+    @Autowired
+    private ISysUserService sysUserService;
+    @Autowired
+    private IBaseProductClassService baseProductClassService;
+    @Autowired
+    private ICuspCustomerProfileService cuspCustomerProfileService;
+    @Autowired
+    private IBaseShipArchiveService baseShipArchiveService;
+    @Autowired
+    private IBaseProductArchiveService baseProductArchiveService;
+    @Autowired
+    private IBaseProjectArchiveService baseProjectArchiveService;
+    @Autowired
+    private ISaleOrderProductService saleOrderProductService;
+    @Autowired
+    private ISaleOrderService saleOrderService;
+
+    @Value(value = "${jeecg.path.upload}")
+    private String uploadpath;
 
     /**
      * 分页列表查询
@@ -556,5 +593,175 @@ public class SaleDeliveryController {
         }
         return Result.OK("文件导入失败!");
     }
+    /**
+     * 导出箱单
+     *
+     */
+    @RequestMapping(value = "/exportDeliverBillXls")
+    public void exportDeliverBillXls(HttpServletResponse response, SaleDelivery saleDelivery) throws Exception {
+        exportByDeliver("箱单", saleDelivery.getId(), response);
+    }
+
+    /**
+     * 导出随货发票
+     *
+     */
+    @RequestMapping(value = "/exportInvoiceBillXls")
+    public void exportInvoiceBillXls(HttpServletResponse response, SaleDelivery saleDelivery) throws Exception {
+        exportByDeliver("随货发票", saleDelivery.getId(), response);
+    }
+
+    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) {
+            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+            response.setCharacterEncoding("utf-8");
+            try {
+                String fileName = URLEncoder.encode(saleDelivery.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 = 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.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());
+                    }
+                }
+
+                // 产品设置
+                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());
+                    }
+                    SaleOrderProduct saleOrderProduct = saleOrderProductList.stream().filter(e->e.getId().equals(o.getSourceId())).findFirst().orElse(null);
+                    if (saleOrderProduct != null){
+                        if (oConvertUtils.isNotEmpty(saleOrderProduct.getDiscount())){
+                            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()));
+
+
+                // 制单人信息
+                SysUser sysUser = sysUserService.getUserByName(saleDelivery.getCreateBy());
+                saleDelivery.setSalesPhone(sysUser.getPhone());
+                saleDelivery.setSalesEmail(sysUser.getEmail());
+                // 组合填充时,因为多组填充的数据量不确定,需要在多组填充完之后另起一行
+                FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).forceNewRow(Boolean.TRUE).build();
+                excelWriter.fill(new FillWrapper(deliveryDetailsList), fillConfig, writeSheet);
+                excelWriter.fill(saleDelivery, writeSheet);
+                excelWriter.finish();
+
+            } catch (Exception ex) {
+                ex.printStackTrace();
+            }
+
+        }
+    }
+
+    /**
+     * 这是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();
+    }
 
 }

+ 31 - 4
srm-module-code/src/main/java/org/jeecg/modules/saleCode/entity/SaleDelivery.java

@@ -2,11 +2,10 @@ package org.jeecg.modules.saleCode.entity;
 
 import java.io.Serializable;
 import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
 import java.util.Date;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableLogic;
+
+import com.baomidou.mybatisplus.annotation.*;
 import org.jeecg.common.constant.ProvinceCityArea;
 import org.jeecg.common.util.SpringContextUtils;
 import lombok.Data;
@@ -203,4 +202,32 @@ public class SaleDelivery implements Serializable {
     @Excel(name = "包装详情(packingDetails)", width = 15)
     @ApiModelProperty(value = "包装详情(packingDetails)")
     private String packingDetails;
+
+
+    //导出字段使用
+    @TableField(exist = false)
+    private String salesPhone;
+    @TableField(exist = false)
+    private String salesEmail;
+
+    @TableField(exist = false)
+    private String contactsNo;
+    @TableField(exist = false)
+    private String contacts;
+    @TableField(exist = false)
+    private String phone;
+    @TableField(exist = false)
+    private String email;
+    @TableField(exist = false)
+    private String shipName;
+    @TableField(exist = false)
+    private String imo;
+    @TableField(exist = false)
+    private String qualityGrade;
+    @TableField(exist = false)
+    private String billDateText;
+    @TableField(exist = false)
+    private BigDecimal deliveryMoney;
+    @TableField(exist = false)
+    private String paymentTerms;
 }

+ 13 - 4
srm-module-code/src/main/java/org/jeecg/modules/saleCode/entity/SaleDeliveryDetails.java

@@ -1,10 +1,8 @@
 package org.jeecg.modules.saleCode.entity;
 
 import java.io.Serializable;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.TableLogic;
+
+import com.baomidou.mybatisplus.annotation.*;
 import org.jeecg.common.constant.ProvinceCityArea;
 import org.jeecg.common.util.SpringContextUtils;
 import lombok.Data;
@@ -151,4 +149,15 @@ public class SaleDeliveryDetails implements Serializable {
     @ApiModelProperty(value = "备注(notes)")
     private String notes;
     private String sourceId;
+
+
+    // 导出用
+    @TableField(exist = false)
+    private Integer rowNumber;
+    @TableField(exist = false)
+    private String deliverDateText;
+    @TableField(exist = false)
+    private String discountText;
+    @TableField(exist = false)
+    private String unit;
 }