hanchaolong недель назад: 2
Родитель
Сommit
5a5bcd3d2e

+ 17 - 1
jd-logistics-modules/jd-logistics-system/pom.xml

@@ -112,7 +112,23 @@
             <artifactId>okhttp</artifactId>
         </dependency>
 
-
+        <!-- easyexcel -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+            <version>4.0.3</version>
+            <!-- 排除 EasyExcel 自带的 POI 依赖,使用项目统一的 POI 版本 -->
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.poi</groupId>
+                    <artifactId>poi-ooxml</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.poi</groupId>
+                    <artifactId>poi</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
 
     <build>

+ 53 - 5
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/controller/BizWaybillOrderController.java

@@ -8,19 +8,28 @@ import com.ruoyi.common.core.web.page.TableDataInfo;
 import com.ruoyi.common.log.annotation.Log;
 import com.ruoyi.common.log.enums.BusinessType;
 import com.ruoyi.common.security.annotation.RequiresPermissions;
+import com.ruoyi.common.security.utils.SecurityUtils;
+import com.ruoyi.logistics.constant.JDDictConstants;
 import com.ruoyi.logistics.domain.BizWaybillOrder;
+import com.ruoyi.logistics.domain.SysDeptRate;
 import com.ruoyi.logistics.domain.dto.JDOrderDTO;
+import com.ruoyi.logistics.handler.JDOrderDynamicTemplateHandler;
 import com.ruoyi.logistics.service.IBizWaybillOrderService;
-import com.ruoyi.logistics.service.LogisticsOrderService;
-import com.ruoyi.system.domain.dto.DeptImportDTO;
+import com.ruoyi.logistics.service.impl.SysDeptRateServiceImpl;
+import com.ruoyi.system.api.domain.SysDictData;
+import com.ruoyi.system.api.model.LoginUser;
+import com.ruoyi.system.service.ISysDictTypeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.List;
 import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * PC-运单管理
@@ -36,6 +45,12 @@ public class BizWaybillOrderController extends BaseController
     @Autowired
     private IBizWaybillOrderService bizWaybillOrderService;
 
+    @Autowired
+    private SysDeptRateServiceImpl sysDeptRateService;
+
+    @Autowired
+    private ISysDictTypeService dictTypeService;
+
     /**
      * 查询运单管理列表
      */
@@ -198,9 +213,42 @@ public class BizWaybillOrderController extends BaseController
     @GetMapping("/importTemplate")
     public void importTemplate(HttpServletResponse response, @RequestParam("orderType") Integer orderType) throws IOException {
         if (1 == orderType) {
-            ExcelUtil<JDOrderDTO> util = new ExcelUtil<JDOrderDTO>(JDOrderDTO.class);
-            util.importTemplateExcel(response, "订单数据");
+            List<String> productCodes = getProductCodeList(); // 从数据库获取产品类型
+            List<String> goodsNames = getGoodsNameList(); // 物品名称
+            JDOrderDynamicTemplateHandler handler = new JDOrderDynamicTemplateHandler();
+            handler.exportDynamicTemplate(response, productCodes, goodsNames);
+        }
+    }
+
+    /**
+     * 获取产品类型下拉列表
+     */
+    private List<String> getProductCodeList() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+
+        SysDeptRate sysDeptRate = new SysDeptRate();
+        sysDeptRate.setDeptId(loginUser.getSysUser().getDeptId());
+        sysDeptRate.setCompanyType("1");
+        List<SysDeptRate> sysDeptRates = sysDeptRateService.selectSysDeptRateList(sysDeptRate);
+        List<String> productNames = new ArrayList<>();
+        for (SysDeptRate item : sysDeptRates) {
+            if (JDDictConstants.PRODUCT_CODE_ED_M_0001.equals(item.getProductType())) {
+                productNames.add("京东标快");
+            } else if (JDDictConstants.PRODUCT_CODE_ED_M_0002.equals(item.getProductType())) {
+                productNames.add("京东特快");
+            } else if (JDDictConstants.PRODUCT_CODE_FR_M_0004.equals(item.getProductType())) {
+                productNames.add("特快重货");
+            }
         }
+        return productNames;
+    }
+
+    /**
+     * 获取物品下拉列表
+     */
+    private List<String> getGoodsNameList() {
+        List<SysDictData> dict = dictTypeService.selectDictDataByType("jd_goods_type");
+        return dict.stream().map(SysDictData::getDictLabel).collect(Collectors.toList());
     }
 
 }

+ 47 - 24
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/domain/dto/JDOrderDTO.java

@@ -1,5 +1,10 @@
 package com.ruoyi.logistics.domain.dto;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.format.DateTimeFormat;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.core.annotation.Excel;
 
@@ -10,15 +15,19 @@ import java.util.Date;
 /**
  * 批量下单 DTO 对象
  */
+@HeadRowHeight(20)
+@ExcelIgnoreUnannotated
 public class JDOrderDTO implements Serializable {
     private static final long serialVersionUID = 1L;
 
     /** 寄件人姓名 */
-    @Excel(name = "寄件人姓名")
+    @ExcelProperty(value = "寄件人姓名", order = 0)
+    @ColumnWidth(15)
     private String senderName;
 
     /** 寄件人电话 */
-    @Excel(name = "寄件人电话")
+    @ExcelProperty(value = "寄件人电话", order = 1)
+    @ColumnWidth(15)
     private String senderPhone;
 
     /** 寄件省 */
@@ -31,15 +40,18 @@ public class JDOrderDTO implements Serializable {
     private String senderCounty;
 
     /** 寄件详细地址 */
-    @Excel(name = "寄件详细地址")
+    @ExcelProperty(value = "寄件详细地址", order = 2)
+    @ColumnWidth(30)
     private String senderAddress;
 
     /** 收件人姓名 */
-    @Excel(name = "收件人姓名")
+    @ExcelProperty(value = "收件人姓名", order = 3)
+    @ColumnWidth(15)
     private String receiverName;
 
     /** 收件人电话 */
-    @Excel(name = "收件人电话")
+    @ExcelProperty(value = "收件人电话", order = 4)
+    @ColumnWidth(15)
     private String receiverPhone;
 
     /** 收件省 */
@@ -52,40 +64,48 @@ public class JDOrderDTO implements Serializable {
     private String receiverCounty;
 
     /** 收件详细地址 */
-    @Excel(name = "收件详细地址")
+    @ExcelProperty(value = "收件详细地址", order = 5)
+    @ColumnWidth(30)
     private String receiverAddress;
 
     /** 物品名称 */
-    @Excel(name = "物品名称")
+    @ExcelProperty(value = "物品名称", order = 6)
+    @ColumnWidth(15)
     private String goodsName;
 
     /** 物品重量 */
-    @Excel(name = "物品重量", cellType = Excel.ColumnType.NUMERIC)
+    @ExcelProperty(value = "物品重量", order = 7)
+    @ColumnWidth(15)
     private BigDecimal goodsWeight;
 
     /** 物品体积 */
-    @Excel(name = "物品体积", cellType = Excel.ColumnType.NUMERIC)
+    @ExcelProperty(value = "物品体积", order = 8)
+    @ColumnWidth(15)
     private BigDecimal goodsVolume;
 
     /** 物品数量 */
-    @Excel(name = "物品数量", cellType = Excel.ColumnType.NUMERIC)
+    @ExcelProperty(value = "物品数量", order = 9)
+    @ColumnWidth(15)
     private Long goodsQty;
 
     /** 取件类型 */
     private Integer pickupType;
 
     /** 上门取件开始时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @Excel(name = "上门取件开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
-    private Date sendStartTime;
+//    @DateTimeFormat("yyyy-MM-dd HH:00:00")
+    @ExcelProperty(value = "上门取件开始时间", order = 10, format = "TEXT")
+    @ColumnWidth(30)
+    private String sendStartTime;
 
     /** 上门取件结束时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @Excel(name = "上门取件结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
-    private Date sendEndTime;
+//    @DateTimeFormat("yyyy-MM-dd HH:00:00")
+    @ExcelProperty(value = "上门取件结束时间", order = 11, format = "TEXT")
+    @ColumnWidth(30)
+    private String sendEndTime;
 
     /** 产品类型 */
-    @Excel(name = "产品类型", combo = {"京东标快", "京东特快", "特快重货"})
+    @ExcelProperty(value = "产品类型", order = 12)
+    @ColumnWidth(15)
     private String productCode;
 
     /** 增值服务 */
@@ -95,15 +115,18 @@ public class JDOrderDTO implements Serializable {
     private String remark;
 
     /** 包装服务 */
-    @Excel(name = "包装服务", combo = {"是", "否"})
+    @ExcelProperty(value = "包装服务", order = 13)
+    @ColumnWidth(15)
     private String isPack;
 
     /** 保价金额 */
-    @Excel(name = "保价金额", cellType = Excel.ColumnType.NUMERIC)
+    @ExcelProperty(value = "保价金额", order = 14)
+    @ColumnWidth(15)
     private BigDecimal guaranteeMoney;
 
     /** 签单返还 */
-    @Excel(name = "签单返还", combo = {"是", "否"})
+    @ExcelProperty(value = "签单返还", order = 15)
+    @ColumnWidth(15)
     private String isReceiptCollect;
 
     public String getSenderName() {
@@ -242,19 +265,19 @@ public class JDOrderDTO implements Serializable {
         this.pickupType = pickupType;
     }
 
-    public Date getSendStartTime() {
+    public String getSendStartTime() {
         return sendStartTime;
     }
 
-    public void setSendStartTime(Date sendStartTime) {
+    public void setSendStartTime(String sendStartTime) {
         this.sendStartTime = sendStartTime;
     }
 
-    public Date getSendEndTime() {
+    public String getSendEndTime() {
         return sendEndTime;
     }
 
-    public void setSendEndTime(Date sendEndTime) {
+    public void setSendEndTime(String sendEndTime) {
         this.sendEndTime = sendEndTime;
     }
 

+ 5 - 5
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/BizWaybillOrderServiceImpl.java

@@ -487,9 +487,9 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
         if (dto.getSendStartTime() == null || dto.getSendEndTime() == null) {
             throw new ServiceException("数据异常!上门取件开始时间和结束时间不能为空");
         }
-        if (dto.getSendStartTime().after(dto.getSendEndTime())) {
-            throw new ServiceException("数据异常!上门取件开始时间不能晚于结束时间");
-        }
+//        if (dto.getSendStartTime().after(dto.getSendEndTime())) {
+//            throw new ServiceException("数据异常!上门取件开始时间不能晚于结束时间");
+//        }
         
         // 校验产品类型
         if (StringUtils.isBlank(dto.getProductCode())) {
@@ -531,8 +531,8 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
         bizWaybillOrder.setGoodsQty(dto.getGoodsQty());
         
         // 取件时间
-        bizWaybillOrder.setSendStartTime(dto.getSendStartTime());
-        bizWaybillOrder.setSendEndTime(dto.getSendEndTime());
+        bizWaybillOrder.setSendStartTime(DateUtils.parseDate(dto.getSendStartTime()));
+        bizWaybillOrder.setSendEndTime(DateUtils.parseDate(dto.getSendEndTime()));
         
         // 产品信息和增值服务
         bizWaybillOrder.setProductCode(dto.getProductCode());