24282 1 жил өмнө
parent
commit
8e837befa5

+ 10 - 0
sd-business/src/main/java/com/sd/business/controller/in/PurchaseWarehousingController.java

@@ -25,4 +25,14 @@ public class PurchaseWarehousingController {
         return purchaseWarehousingService.getPage(dto);
     }
 
+
+    /**
+     * 采购入库excel导出
+     */
+    @PostMapping("/exportExcel")
+    public void exportExcel(@RequestBody PurchaseWarehousingDto dto) {
+        purchaseWarehousingService.exportExcel(dto);
+    }
+
+
 }

+ 1 - 0
sd-business/src/main/java/com/sd/business/entity/excel/enums/ExcelTypeEnum.java

@@ -9,6 +9,7 @@ public enum ExcelTypeEnum {
 
     DOCUMENT_BY_ORDER(1, "订单对账单"),
     STATISTICS_DOCUMENT_BY_ORDER(2, "订单对账报表"),
+    PURCHASE_WAREHOUSING(3, "采购入库明细"),
     ;
 
     private final Integer type;

+ 68 - 12
sd-business/src/main/java/com/sd/business/entity/in/vo/PurchaseWarehousingVo.java

@@ -1,5 +1,8 @@
 package com.sd.business.entity.in.vo;
 
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -9,54 +12,107 @@ import java.util.Date;
 @Getter
 @Setter
 public class PurchaseWarehousingVo {
+
     /**
-     * 入库时间
+     * 序号
      */
-    private Date outboundTime;
+    @ExcelProperty(value = "序号")
+    private Integer serialNumber;
 
     /**
-     * 采购单号
+     * 入库时间
      */
-    private String purchaseCode;
+    @ColumnWidth(20)
+    @ExcelProperty(value = "入库日期")
+    private Date outboundTime;
 
     /**
      * 入库单号
      */
+    @ColumnWidth(20)
+    @ExcelProperty(value = "入库单号")
     private String outboundCode;
 
     /**
-     * 仓库名称
+     * 供应商名称
      */
-    private String warehouseName;
+    @ColumnWidth(30)
+    @ExcelProperty(value = "供应商名称")
+    private String supplierName;
 
     /**
-     * 供应商名称
+     * 采购单号
      */
-    private String supplierName;
+    @ColumnWidth(20)
+    @ExcelProperty(value = "采购合同编号")
+    private String purchaseCode;
 
     /**
      * 品号
      */
+    @ColumnWidth(20)
+    @ExcelProperty(value = "物料品号")
     private String bomSpecCode;
 
     /**
      * 品名
      */
+    @ColumnWidth(30)
+    @ExcelProperty(value = "物料名称")
     private String bomSpecName;
 
     /**
-     * 入库数量
+     * 单位
      */
-    private BigDecimal outboundQuantity;
+    @ColumnWidth(15)
+    @ExcelProperty(value = "计量单位")
+    private String bomSpecUnit;
 
     /**
-     * 单位
+     * 入库类型
      */
-    private String bomSpecUnit;
+    @ColumnWidth(15)
+    @ExcelProperty(value = "入库类型")
+    private String incomingType;
+
+    /**
+     * 仓库名称
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "仓库类别")
+    private String warehouseName;
+
+    /**
+     * 入库数量
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "入库数量")
+    private BigDecimal outboundQuantity;
 
     /**
      * 含税单价
      */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "采购单价(含税)")
     private BigDecimal outboundUnitPrice;
 
+    /**
+     * 入库金额
+     */
+    @ColumnWidth(15)
+    @ExcelProperty(value = "入库金额")
+    private BigDecimal total;
+
+    public String getIncomingType() {
+        return "采购入库";
+    }
+
+    public BigDecimal getOutboundUnitPrice() {
+        return ObjectUtil.defaultIfNull(outboundUnitPrice, BigDecimal.ZERO);
+    }
+
+    public BigDecimal getTotal() {
+        return outboundQuantity.multiply(getOutboundUnitPrice());
+    }
+
 }

+ 4 - 0
sd-business/src/main/java/com/sd/business/mapper/in/PurchaseWarehousingServiceMapper.java

@@ -5,8 +5,12 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.in.vo.PurchaseWarehousingVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 public interface PurchaseWarehousingServiceMapper {
 
     Page<PurchaseWarehousingVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<Object> wrapper);
 
+    List<PurchaseWarehousingVo> getList(@Param("ew") IWrapper<Object> wrapper);
+
 }

+ 6 - 0
sd-business/src/main/java/com/sd/business/service/in/PurchaseWarehousingService.java

@@ -11,4 +11,10 @@ public interface PurchaseWarehousingService {
      */
     Page<PurchaseWarehousingVo> getPage(PurchaseWarehousingDto dto);
 
+
+    /**
+     * 采购入库excel导出
+     */
+    void exportExcel(PurchaseWarehousingDto dto);
+
 }

+ 33 - 2
sd-business/src/main/java/com/sd/business/service/in/impl/PurchaseWarehousingServiceImpl.java

@@ -1,8 +1,10 @@
 package com.sd.business.service.in.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.bom.po.BomSpec;
+import com.sd.business.entity.excel.enums.ExcelTypeEnum;
 import com.sd.business.entity.in.dto.PurchaseWarehousingDto;
 import com.sd.business.entity.in.emums.InDetailTypeEnum;
 import com.sd.business.entity.in.emums.InOutTypeEnum;
@@ -11,10 +13,15 @@ import com.sd.business.entity.in.vo.PurchaseWarehousingVo;
 import com.sd.business.entity.purchase.po.Purchase;
 import com.sd.business.entity.supplier.po.Supplier;
 import com.sd.business.mapper.in.PurchaseWarehousingServiceMapper;
+import com.sd.business.service.excel.ExcelGenerateLogService;
 import com.sd.business.service.in.PurchaseWarehousingService;
+import com.sd.business.strategy.impl.DefaultExportStrategy;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
 
 @Service
 public class PurchaseWarehousingServiceImpl implements PurchaseWarehousingService {
@@ -22,9 +29,34 @@ public class PurchaseWarehousingServiceImpl implements PurchaseWarehousingServic
     @Resource
     private PurchaseWarehousingServiceMapper purchaseWarehousingServiceMapper;
 
+    @Autowired
+    private ExcelGenerateLogService excelGenerateLogService;
+
     @Override
     public Page<PurchaseWarehousingVo> getPage(PurchaseWarehousingDto dto) {
+        return purchaseWarehousingServiceMapper.getPage(dto.getPage(), getWrapper(dto));
+    }
+
+    @Override
+    public void exportExcel(PurchaseWarehousingDto dto) {
+        DefaultExportStrategy<PurchaseWarehousingVo> defaultExportStrategy = new DefaultExportStrategy<>(
+                () -> getList(dto), PurchaseWarehousingVo.class, "采购入库");
+
+        excelGenerateLogService.generateExcel(ExcelTypeEnum.PURCHASE_WAREHOUSING, defaultExportStrategy,
+                DateUtil.formatDate(new Date()) + " 采购入库数据");
+    }
+
+    private List<PurchaseWarehousingVo> getList(PurchaseWarehousingDto dto) {
+        List<PurchaseWarehousingVo> list = purchaseWarehousingServiceMapper.getList(getWrapper(dto));
+        for (int i = 0; i < list.size(); i++) {
+            PurchaseWarehousingVo purchaseWarehousingVo = list.get(i);
+            purchaseWarehousingVo.setSerialNumber(i + 1);
+        }
 
+        return list;
+    }
+
+    private IWrapper<Object> getWrapper(PurchaseWarehousingDto dto) {
         IWrapper<Object> wrapper = IWrapper.getWrapper();
         wrapper.eq("ios", InOutStorage::getType, InOutTypeEnum.IN.getKey());
         wrapper.eq("ios", InOutStorage::getDetailType, InDetailTypeEnum.PURCHASE.getKey());
@@ -34,8 +66,7 @@ public class PurchaseWarehousingServiceImpl implements PurchaseWarehousingServic
         wrapper.like("bs", BomSpec::getName, dto.getBomSpecName());
         wrapper.ge("ios", InOutStorage::getCreateTime, dto.getBeginTime());
         wrapper.le("ios", InOutStorage::getCreateTime, dto.getEndTime());
-
-        return purchaseWarehousingServiceMapper.getPage(dto.getPage(), wrapper);
+        return wrapper;
     }
 
 }

+ 46 - 0
sd-business/src/main/java/com/sd/business/strategy/impl/DefaultExportStrategy.java

@@ -0,0 +1,46 @@
+package com.sd.business.strategy.impl;
+
+import cn.hutool.core.io.IoUtil;
+import com.alibaba.excel.EasyExcel;
+import com.sd.business.strategy.ExcelExportStrategy;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.function.Supplier;
+
+public class DefaultExportStrategy<T> implements ExcelExportStrategy<List<T>> {
+
+    private final Class<T> aClass;
+
+    private final Supplier<List<T>> supplier;
+
+    private final String sheetName;
+
+    public DefaultExportStrategy(Supplier<List<T>> supplier, Class<T> aClass, String sheetName) {
+        this.supplier = supplier;
+        this.aClass = aClass;
+        this.sheetName = sheetName;
+    }
+
+    @Override
+    public List<T> getData() {
+        return supplier.get();
+    }
+
+    @Override
+    public InputStream getInputStream(List<T> data) {
+
+        ByteArrayOutputStream os = null;
+
+        try {
+            os = new ByteArrayOutputStream();
+            EasyExcel.write(os, aClass).sheet(sheetName).doWrite(data);
+            return new ByteArrayInputStream(os.toByteArray());
+        } finally {
+            IoUtil.close(os);
+        }
+
+    }
+}

+ 9 - 1
sd-business/src/main/resources/mapper/in/PurchaseWarehousingServiceMapper.xml

@@ -3,6 +3,14 @@
 <mapper namespace="com.sd.business.mapper.in.PurchaseWarehousingServiceMapper">
 
     <select id="getPage" resultType="com.sd.business.entity.in.vo.PurchaseWarehousingVo">
+        <include refid="select"/>
+    </select>
+
+    <select id="getList" resultType="com.sd.business.entity.in.vo.PurchaseWarehousingVo">
+        <include refid="select"/>
+    </select>
+
+    <sql id="select">
         select ios.create_time outboundTime,
                p.code          purchaseCode,
                ios.code        outboundCode,
@@ -21,6 +29,6 @@
                  left join bom_spec bs on iosb.bom_spec_id = bs.id
                  left join bom b on bs.bom_id = b.id
             ${ew.customSqlSegment}
-    </select>
+    </sql>
 
 </mapper>

+ 2 - 1
sd-business/src/main/resources/mapper/order/OrderMapper.xml

@@ -51,7 +51,8 @@
                o.update_time,
                d.name departmentName,
                o.flow_id,
-               o.flow_status
+               o.flow_status,
+               o.statement_of_account_id
         from order_info o
                  left join department d on d.id = o.department_id
             ${ew.customSqlSegment}