24282 1 жил өмнө
parent
commit
b60bf6ef62

+ 10 - 10
sd-business/src/main/java/com/sd/business/controller/statement/StatementOfAccountController.java

@@ -12,7 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import javax.servlet.http.HttpServletResponse;
+import java.util.Collections;
 import java.util.List;
 
 
@@ -92,7 +92,7 @@ public class StatementOfAccountController {
      */
     @PostMapping("/getDocumentBySku")
     public List<DocumentBySkuVo> getDocumentBySku(@RequestBody BaseSelectDto dto) {
-        return statementOfAccountService.getDocumentBySku(dto.getId());
+        return statementOfAccountService.getDocumentBySku(Collections.singletonList(dto.getId()));
     }
 
     /**
@@ -100,7 +100,7 @@ public class StatementOfAccountController {
      */
     @PostMapping("/getDocumentByBom")
     public List<DocumentByBomVo> getDocumentByBom(@RequestBody BaseSelectDto dto) {
-        return statementOfAccountService.getDocumentByBom(dto.getId());
+        return statementOfAccountService.getDocumentByBom(Collections.singletonList(dto.getId()));
     }
 
     /**
@@ -108,7 +108,7 @@ public class StatementOfAccountController {
      */
     @PostMapping("/getDocumentByOrder")
     public List<DocumentByOrderVo> getDocumentByOrder(@RequestBody BaseSelectDto dto) {
-        return statementOfAccountService.getDocumentByOrder(dto.getId());
+        return statementOfAccountService.getDocumentByOrder(Collections.singletonList(dto.getId()));
     }
 
     /**
@@ -116,8 +116,8 @@ public class StatementOfAccountController {
      */
     @NonInterception
     @GetMapping("/exportDocumentBySku")
-    public void exportDocumentBySku(HttpServletResponse response, BaseSelectDto dto) {
-        statementOfAccountService.exportDocumentBySku(response, dto.getId());
+    public void exportDocumentBySku(BaseSelectDto dto) {
+        statementOfAccountService.export(dto.getId(), 1);
     }
 
     /**
@@ -125,8 +125,8 @@ public class StatementOfAccountController {
      */
     @NonInterception
     @GetMapping("/exportDocumentByBom")
-    public void exportDocumentByBom(HttpServletResponse response, BaseSelectDto dto) {
-        statementOfAccountService.exportDocumentByBom(response, dto.getId());
+    public void exportDocumentByBom(BaseSelectDto dto) {
+        statementOfAccountService.export(dto.getId(), 2);
     }
 
     /**
@@ -134,8 +134,8 @@ public class StatementOfAccountController {
      */
     @NonInterception
     @GetMapping("/exportDocumentByOrder")
-    public void exportDocumentByOrder(HttpServletResponse response, BaseSelectDto dto) {
-        statementOfAccountService.exportDocumentByOrder(response, dto.getId());
+    public void exportDocumentByOrder(BaseSelectDto dto) {
+        statementOfAccountService.export(dto.getId(), 3);
     }
 
 }

+ 31 - 2
sd-business/src/main/java/com/sd/business/controller/statement/StatementOfAccountMergeController.java

@@ -1,8 +1,12 @@
 package com.sd.business.controller.statement;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.sd.business.entity.statement.dto.GetDocumentDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountMergePageDto;
-import com.sd.business.entity.statement.vo.StatementOfAccountVo;
+import com.sd.business.entity.statement.vo.DocumentByBomVo;
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
+import com.sd.business.entity.statement.vo.DocumentBySkuVo;
+import com.sd.business.entity.statement.vo.StatementOfAccountMergePageVo;
 import com.sd.business.service.statement.StatementOfAccountMergeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
@@ -11,6 +15,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -31,9 +37,32 @@ public class StatementOfAccountMergeController {
      * 对账报表分页
      */
     @PostMapping("/page")
-    public Page<StatementOfAccountVo> page(@Validated @RequestBody StatementOfAccountMergePageDto dto) {
+    public Page<StatementOfAccountMergePageVo> page(@Validated @RequestBody StatementOfAccountMergePageDto dto) {
         return statementOfAccountMergeService.getPage(dto);
     }
 
+    /**
+     * sku对账
+     */
+    @PostMapping("/getDocumentBySku")
+    public List<DocumentBySkuVo> getDocumentBySku(@RequestBody GetDocumentDto dto) {
+        return statementOfAccountMergeService.getDocumentBySku(dto);
+    }
+
+    /**
+     * bom对账
+     */
+    @PostMapping("/getDocumentByBom")
+    public List<DocumentByBomVo> getDocumentByBom(@RequestBody GetDocumentDto dto) {
+        return statementOfAccountMergeService.getDocumentByBom(dto);
+    }
+
+    /**
+     * 订单对账
+     */
+    @PostMapping("/getDocumentByOrder")
+    public List<DocumentByOrderVo> getDocumentByOrder(@RequestBody GetDocumentDto dto) {
+        return statementOfAccountMergeService.getDocumentByOrder(dto);
+    }
 
 }

+ 18 - 0
sd-business/src/main/java/com/sd/business/entity/statement/dto/GetDocumentDto.java

@@ -0,0 +1,18 @@
+package com.sd.business.entity.statement.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotBlank;
+
+@Getter
+@Setter
+public class GetDocumentDto {
+
+    /**
+     * 对账单id集合
+     */
+    @NotBlank(message = "对账单id集合不能为空")
+    private String idGroupConcat;
+
+}

+ 47 - 0
sd-business/src/main/java/com/sd/business/entity/statement/vo/StatementOfAccountMergePageVo.java

@@ -0,0 +1,47 @@
+package com.sd.business.entity.statement.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class StatementOfAccountMergePageVo {
+
+    /**
+     * 维度
+     */
+    private String dimensionality;
+
+    /**
+     * 事业部id
+     */
+    private Long departmentId;
+
+    /**
+     * 事业部名称
+     */
+    private String departmentName;
+
+    /**
+     * 对账单id集合
+     */
+    private String idGroupConcat;
+
+    /**
+     * 对账金额
+     */
+    private BigDecimal reconcilingAmount;
+
+    /**
+     * 对账单数量
+     */
+    private Integer quantityOfStatement;
+
+    /**
+     * 合同数量
+     */
+    private Integer orderQuantity;
+
+}

+ 22 - 0
sd-business/src/main/java/com/sd/business/service/statement/StatementOfAccountExportService.java

@@ -0,0 +1,22 @@
+package com.sd.business.service.statement;
+
+import java.util.List;
+
+public interface StatementOfAccountExportService {
+
+    /**
+     * 导出sku对账单
+     */
+    void exportDocumentBySku(List<Long> idList, String departmentName, String beginDate, String endDate);
+
+    /**
+     * 导出bom对账单
+     */
+    void exportDocumentByBom(List<Long> idList, String departmentName, String beginDate, String endDate);
+
+    /**
+     * 导出订单对账单
+     */
+    void exportDocumentByOrder(List<Long> idList, String departmentName, String beginDate, String endDate);
+
+}

+ 22 - 2
sd-business/src/main/java/com/sd/business/service/statement/StatementOfAccountMergeService.java

@@ -1,8 +1,14 @@
 package com.sd.business.service.statement;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.sd.business.entity.statement.dto.GetDocumentDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountMergePageDto;
-import com.sd.business.entity.statement.vo.StatementOfAccountVo;
+import com.sd.business.entity.statement.vo.DocumentByBomVo;
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
+import com.sd.business.entity.statement.vo.DocumentBySkuVo;
+import com.sd.business.entity.statement.vo.StatementOfAccountMergePageVo;
+
+import java.util.List;
 
 /**
  * <p>
@@ -17,7 +23,21 @@ public interface StatementOfAccountMergeService {
     /**
      * 对账报表分页
      */
-    Page<StatementOfAccountVo> getPage(StatementOfAccountMergePageDto dto);
+    Page<StatementOfAccountMergePageVo> getPage(StatementOfAccountMergePageDto dto);
 
+    /**
+     * sku对账
+     */
+    List<DocumentBySkuVo> getDocumentBySku(GetDocumentDto dto);
+
+    /**
+     * bom对账
+     */
+    List<DocumentByBomVo> getDocumentByBom(GetDocumentDto dto);
+
+    /**
+     * 订单对账
+     */
+    List<DocumentByOrderVo> getDocumentByOrder(GetDocumentDto dto);
 
 }

+ 8 - 16
sd-business/src/main/java/com/sd/business/service/statement/StatementOfAccountService.java

@@ -8,7 +8,6 @@ import com.sd.business.entity.statement.dto.StatementOfAccountSelectDto;
 import com.sd.business.entity.statement.po.StatementOfAccount;
 import com.sd.business.entity.statement.vo.*;
 
-import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 
@@ -55,31 +54,24 @@ public interface StatementOfAccountService extends BaseService<StatementOfAccoun
     /**
      * sku对账
      */
-    List<DocumentBySkuVo> getDocumentBySku(Long statementOfAccountId);
+    List<DocumentBySkuVo> getDocumentBySku(List<Long> statementOfAccountId);
 
     /**
      * bom对账
      */
-    List<DocumentByBomVo> getDocumentByBom(Long statementOfAccountId);
+    List<DocumentByBomVo> getDocumentByBom(List<Long> statementOfAccountId);
 
     /**
      * 订单对账
      */
-    List<DocumentByOrderVo> getDocumentByOrder(Long statementOfAccountId);
+    List<DocumentByOrderVo> getDocumentByOrder(List<Long> statementOfAccountId);
 
     /**
-     * 导出sku对账单
+     * 导出
+     *
+     * @param id   对账单id
+     * @param type 1sku 2bom 3订单
      */
-    void exportDocumentBySku(HttpServletResponse response, Long id);
-
-    /**
-     * 导出bom对账单
-     */
-    void exportDocumentByBom(HttpServletResponse response, Long id);
-
-    /**
-     * 导出订单对账单
-     */
-    void exportDocumentByOrder(HttpServletResponse response, Long id);
+    void export(Long id, int type);
 
 }

+ 115 - 0
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountExportServiceImpl.java

@@ -0,0 +1,115 @@
+package com.sd.business.service.statement.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.sd.business.entity.statement.bo.ExportDocumentByOrderBo;
+import com.sd.business.entity.statement.vo.DocumentByBomVo;
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
+import com.sd.business.entity.statement.vo.DocumentBySkuVo;
+import com.sd.business.service.statement.StatementOfAccountExportService;
+import com.sd.business.service.statement.StatementOfAccountService;
+import com.sd.framework.util.StreamUtil;
+import com.sd.framework.util.TemplateExcelUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class StatementOfAccountExportServiceImpl implements StatementOfAccountExportService {
+
+    @Autowired
+    private HttpServletResponse response;
+
+    @Autowired
+    private StatementOfAccountService statementOfAccountService;
+
+    @Override
+    public void exportDocumentBySku(List<Long> idList, String departmentName, String beginDate, String endDate) {
+
+        List<DocumentBySkuVo> list = statementOfAccountService.getDocumentBySku(idList);
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("department", StrUtil.isBlank(departmentName) ? StringPool.EMPTY : departmentName + StringPool.DASH);
+        map.put("beginDate", beginDate);
+        map.put("endDate", endDate);
+        map.put("totalQuantity", StreamUtil.bigDecimalAdd(list, DocumentBySkuVo::getQuantity));
+        map.put("totalSubtotal", StreamUtil.bigDecimalAdd(list, DocumentBySkuVo::getSubtotal));
+
+        TemplateExcelUtil.writeBrowser("skuDocument.xlsx", "sku对账单", response, list, map);
+    }
+
+    @Override
+    public void exportDocumentByBom(List<Long> idList, String departmentName, String beginDate, String endDate) {
+
+        List<DocumentByBomVo> list = statementOfAccountService.getDocumentByBom(idList);
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("department", StrUtil.isBlank(departmentName) ? StringPool.EMPTY : departmentName + StringPool.DASH);
+        map.put("beginDate", beginDate);
+        map.put("endDate", endDate);
+        map.put("totalSubtotal", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getSubtotal));
+        map.put("totalLaserLogoSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getLaserLogoSummary));
+        map.put("totalLaserMitochondrialSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getLaserMitochondrialSummary));
+        map.put("totalLssueFeeSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getLssueFeeSummary));
+        map.put("totalDeliveryMaterialsFeeSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getDeliveryMaterialsFeeSummary));
+        map.put("totalPackingLaborSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getPackingLaborSummary));
+
+        TemplateExcelUtil.writeBrowser("bomDocument.xlsx", "bom对账单", response, list, map);
+    }
+
+    @Override
+    public void exportDocumentByOrder(List<Long> idList, String departmentName, String beginDate, String endDate) {
+
+        List<DocumentByOrderVo> list = statementOfAccountService.getDocumentByOrder(idList);
+
+        BigDecimal all = BigDecimal.ZERO;
+
+        List<ExportDocumentByOrderBo> exportDocumentByOrderBos = new ArrayList<>();
+        for (DocumentByOrderVo documentByOrderVo : list) {
+            List<DocumentByOrderVo.SkuSpec> skuSpecList = documentByOrderVo.getSkuSpecList();
+            for (DocumentByOrderVo.SkuSpec skuSpec : skuSpecList) {
+                List<DocumentByOrderVo.BomSpec> bomSpecList = skuSpec.getBomSpecList();
+                for (DocumentByOrderVo.BomSpec bomSpec : bomSpecList) {
+                    ExportDocumentByOrderBo exportDocumentByOrderBo = ExportDocumentByOrderBo.builder()
+                            .wlnCreateTime(documentByOrderVo.getWlnCreateTime())
+                            .code(documentByOrderVo.getCode())
+                            .wlnCode(documentByOrderVo.getWlnCode())
+                            .skuSpecCode(skuSpec.getSkuSpecCode())
+                            .skuSpecName(skuSpec.getSkuSpecName())
+                            .quantity(skuSpec.getQuantity())
+                            .unitPrice(skuSpec.getUnitPrice())
+                            .subtotal(skuSpec.getSubtotal())
+                            .total(skuSpec.getTotal())
+                            .bomSpecCode(bomSpec.getBomSpecCode())
+                            .bomSpecName(bomSpec.getBomSpecName())
+                            .bomQuantity(bomSpec.getQuantity())
+                            .bomUnitPrice(bomSpec.getUnitPrice())
+                            .laserLogoSummary(bomSpec.getLaserLogoSummary())
+                            .laserMitochondrialSummary(bomSpec.getLaserMitochondrialSummary())
+                            .lssueFeeSummary(bomSpec.getLssueFeeSummary())
+                            .deliveryMaterialsFeeSummary(bomSpec.getDeliveryMaterialsFeeSummary())
+                            .packingLaborSummary(bomSpec.getPackingLaborSummary())
+                            .build();
+                    exportDocumentByOrderBos.add(exportDocumentByOrderBo);
+                }
+                all = all.add(skuSpec.getTotal());
+            }
+        }
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("department", StrUtil.isBlank(departmentName) ? StringPool.EMPTY : departmentName + StringPool.DASH);
+        map.put("beginDate", beginDate);
+        map.put("endDate", endDate);
+        map.put("all", all);
+
+        TemplateExcelUtil.writeBrowser("orderDocument.xlsx", "订单对账单",
+                new DocumentByOrderExcelCellMergeStrategy(list), response, exportDocumentByOrderBos, map);
+    }
+
+}

+ 145 - 6
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountMergeServiceImpl.java

@@ -1,12 +1,36 @@
 package com.sd.business.service.statement.impl;
 
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Assert;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.PageUtils;
+import com.sd.business.entity.order.po.OrderInfo;
+import com.sd.business.entity.statement.dto.GetDocumentDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountMergePageDto;
-import com.sd.business.entity.statement.vo.StatementOfAccountVo;
+import com.sd.business.entity.statement.po.StatementOfAccount;
+import com.sd.business.entity.statement.vo.DocumentByBomVo;
+import com.sd.business.entity.statement.vo.DocumentByOrderVo;
+import com.sd.business.entity.statement.vo.DocumentBySkuVo;
+import com.sd.business.entity.statement.vo.StatementOfAccountMergePageVo;
+import com.sd.business.service.department.DepartmentService;
+import com.sd.business.service.order.OrderService;
 import com.sd.business.service.statement.StatementOfAccountMergeService;
+import com.sd.business.service.statement.StatementOfAccountService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -19,31 +43,146 @@ import org.springframework.stereotype.Service;
 @Service
 public class StatementOfAccountMergeServiceImpl implements StatementOfAccountMergeService {
 
+    @Autowired
+    private StatementOfAccountService statementOfAccountService;
+
+    @Autowired
+    private DepartmentService departmentService;
+
+    @Autowired
+    private OrderService orderService;
+
 
     @Override
-    public Page<StatementOfAccountVo> getPage(StatementOfAccountMergePageDto dto) {
+    public Page<StatementOfAccountMergePageVo> getPage(StatementOfAccountMergePageDto dto) {
 
+        QueryWrapper<StatementOfAccount> wrapper = Wrappers.query();
+
+        wrapper.eq(ObjectUtil.isNotNull(dto.getDepartmentId()), "department_id", dto.getDepartmentId());
+        wrapper.groupBy("department_id");
+        wrapper.orderByDesc("dimensionality");
 
         switch (dto.getType()) {
+            // 月度
             case 1:
-
+                wrapper.select("department_id AS departmentId",
+                        "GROUP_CONCAT(id) AS idGroupConcat",
+                        "DATE_FORMAT(time_period,'%Y/%m月') AS dimensionality");
+                wrapper.groupBy("dimensionality");
                 break;
+
+            // 季度
             case 2:
+                wrapper.select("department_id AS departmentId", "GROUP_CONCAT(id) AS idGroupConcat",
+                        "DATE_FORMAT(time_period,'%Y/%m月') AS dimensionality",
+                        "CONCAT(YEAR(time_period),'/第',QUARTER(time_period),'季度') AS dimensionality");
 
+                wrapper.groupBy("dimensionality");
                 break;
-            case 3:
 
+            // 年度
+            case 3:
+                wrapper.select("department_id AS departmentId", "GROUP_CONCAT(id) AS idGroupConcat",
+                        "DATE_FORMAT(time_period,'%Y/%m月') AS dimensionality",
+                        "YEAR(time_period) AS dimensionality");
+                wrapper.groupBy("dimensionality");
                 break;
-            case 4:
 
+            // 自定义
+            case 4:
+                wrapper.select("department_id AS departmentId", "GROUP_CONCAT(id) AS idGroupConcat",
+                        "DATE_FORMAT(time_period,'%Y/%m月') AS dimensionality");
+                wrapper.ge(ObjectUtil.isNotNull(dto.getBeginTime()), "time_period", dto.getBeginTime());
+                wrapper.le(ObjectUtil.isNotNull(dto.getEndTime()), "time_period", dto.getEndTime());
                 break;
+
             default:
                 throw new ServiceException("未知对账类型");
         }
 
+        Page<Map<String, Object>> mapPage = statementOfAccountService.pageMaps(dto.getPage(), wrapper);
+        Page<StatementOfAccountMergePageVo> page = PageUtils.copyPage(mapPage, StatementOfAccountMergePageVo.class);
+        List<StatementOfAccountMergePageVo> records = page.getRecords();
+        if (records.size() == 0) {
+            return page;
+        }
+
+        departmentService.attributeAssign(records, StatementOfAccountMergePageVo::getDepartmentId,
+                (item, department) -> item.setDepartmentName(department.getName()));
+
+        // 对账单id列表
+        List<Long> statementOfAccountIdList = records.stream()
+                .map(StatementOfAccountMergePageVo::getIdGroupConcat)
+                .flatMap(item -> Arrays.stream(item.split(",")))
+                .map(Convert::toLong)
+                .distinct()
+                .collect(Collectors.toList());
+
+        Map<Long, List<OrderInfo>> map = orderService.mapKGroup(OrderInfo::getStatementOfAccountId,
+                q -> q.in(OrderInfo::getStatementOfAccountId, statementOfAccountIdList));
+
+        for (StatementOfAccountMergePageVo record : records) {
+
+            if (dto.getType().equals(4)) {
+                String beginTime = dto.getBeginTime() == null ? StringPool.EMPTY : DateUtil.formatDate(dto.getBeginTime());
+                String endTime = dto.getEndTime() == null ? StringPool.EMPTY : DateUtil.formatDate(dto.getEndTime());
+                record.setDimensionality(beginTime + StringPool.DASH + endTime);
+            }
+
+            String[] tempStatementOfAccountIdList = record.getIdGroupConcat().split(",");
+
+            record.setReconcilingAmount(BigDecimal.ZERO);
+            record.setOrderQuantity(0);
+            record.setQuantityOfStatement(tempStatementOfAccountIdList.length);
+
+            for (String statementOfAccountIdStr : tempStatementOfAccountIdList) {
+                Long statementOfAccountId = Convert.toLong(statementOfAccountIdStr);
+                List<OrderInfo> tempOrderInfoList = map.get(statementOfAccountId);
 
-        return null;
+                if (ObjectUtil.isEmpty(tempOrderInfoList)) {
+                    continue;
+                }
+
+                BigDecimal reconcilingAmount = tempOrderInfoList.stream()
+                        .map(OrderInfo::getTotalAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+
+                record.setOrderQuantity(record.getOrderQuantity() + tempOrderInfoList.size());
+                record.setReconcilingAmount(record.getReconcilingAmount().add(reconcilingAmount));
+            }
+
+        }
+
+        return page;
     }
 
+    @Override
+    public List<DocumentBySkuVo> getDocumentBySku(GetDocumentDto dto) {
+        return statementOfAccountService.getDocumentBySku(getIdList(dto));
+    }
+
+    @Override
+    public List<DocumentByBomVo> getDocumentByBom(GetDocumentDto dto) {
+        return statementOfAccountService.getDocumentByBom(getIdList(dto));
+    }
+
+    @Override
+    public List<DocumentByOrderVo> getDocumentByOrder(GetDocumentDto dto) {
+        return statementOfAccountService.getDocumentByOrder(getIdList(dto));
+    }
+
+    private List<Long> getIdList(GetDocumentDto dto) {
+
+        String idGroupConcat = dto.getIdGroupConcat();
+
+        List<Long> idList = Arrays.stream(idGroupConcat.split(","))
+                .map(Convert::toLong)
+                .distinct()
+                .filter(Objects::nonNull)
+                .collect(Collectors.toList());
+
+        Assert.notEmpty(idList, "对账单id集合不能为空");
+
+        return idList;
+    }
 
 }

+ 38 - 114
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountServiceImpl.java

@@ -11,12 +11,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.file.entity.FileInfoVo;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.ruoyi.common.core.domain.BaseIdPo;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.department.po.Department;
 import com.sd.business.entity.order.po.OrderInfo;
 import com.sd.business.entity.order.po.OrderSku;
 import com.sd.business.entity.order.po.OrderSkuBom;
-import com.sd.business.entity.statement.bo.ExportDocumentByOrderBo;
 import com.sd.business.entity.statement.dto.FileUploadDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountDto;
 import com.sd.business.entity.statement.dto.StatementOfAccountSelectDto;
@@ -29,16 +29,14 @@ import com.sd.business.service.order.OrderService;
 import com.sd.business.service.order.OrderSkuBomService;
 import com.sd.business.service.order.OrderSkuService;
 import com.sd.business.service.sku.SkuSpecService;
+import com.sd.business.service.statement.StatementOfAccountExportService;
 import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.business.util.CodeEnum;
 import com.sd.framework.util.Assert;
-import com.sd.framework.util.StreamUtil;
-import com.sd.framework.util.TemplateExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.function.Function;
@@ -74,6 +72,9 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     @Autowired
     private BomSpecService bomSpecService;
 
+    @Autowired
+    private StatementOfAccountExportService statementOfAccountExportService;
+
     @Override
     public Page<StatementOfAccountVo> getPage(StatementOfAccountSelectDto dto) {
 
@@ -214,10 +215,10 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     }
 
     @Override
-    public List<DocumentBySkuVo> getDocumentBySku(Long statementOfAccountId) {
+    public List<DocumentBySkuVo> getDocumentBySku(List<Long> statementOfAccountIdList) {
 
         // 获取订单id列表
-        List<Long> orderIdList = getOrderIdList(statementOfAccountId);
+        List<Long> orderIdList = getOrderIdList(statementOfAccountIdList);
 
         if (orderIdList.size() == 0) {
             return Collections.emptyList();
@@ -266,10 +267,10 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     }
 
     @Override
-    public List<DocumentByBomVo> getDocumentByBom(Long statementOfAccountId) {
+    public List<DocumentByBomVo> getDocumentByBom(List<Long> statementOfAccountIdList) {
 
         // 获取订单id列表
-        List<Long> orderIdList = getOrderIdList(statementOfAccountId);
+        List<Long> orderIdList = getOrderIdList(statementOfAccountIdList);
 
         if (orderIdList.size() == 0) {
             return Collections.emptyList();
@@ -368,10 +369,10 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     }
 
     @Override
-    public List<DocumentByOrderVo> getDocumentByOrder(Long statementOfAccountId) {
+    public List<DocumentByOrderVo> getDocumentByOrder(List<Long> statementOfAccountId) {
 
-        Assert.notNull(statementOfAccountId, "对账单id不能为空");
-        List<OrderInfo> orderList = orderService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, statementOfAccountId));
+        Assert.notEmpty(statementOfAccountId, "对账单id不能为空");
+        List<OrderInfo> orderList = orderService.list(q -> q.in(OrderInfo::getStatementOfAccountId, statementOfAccountId));
         if (orderList.size() == 0) {
             return Collections.emptyList();
         }
@@ -412,118 +413,42 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     }
 
     @Override
-    public void exportDocumentBySku(HttpServletResponse response, Long id) {
+    public void export(Long id, int type) {
 
         StatementOfAccount statementOfAccount = getById(id);
         Assert.notNull(statementOfAccount, "没有找到对账单");
-        Department department = departmentService.getById(statementOfAccount.getDepartmentId());
-        Assert.notNull(department, "没有找到事业部");
-
-        List<DocumentBySkuVo> list = getDocumentBySku(id);
-
-        Date timePeriod = statementOfAccount.getTimePeriod();
-        String timePeriodStr = timePeriod != null ? DateUtil.formatDate(timePeriod) : StringPool.EMPTY;
-
-        Map<String, Object> map = new HashMap<>();
-        map.put("department", department.getName() + " - ");
-        map.put("beginDate", timePeriodStr);
-        map.put("endDate", timePeriodStr);
-        map.put("totalQuantity", StreamUtil.bigDecimalAdd(list, DocumentBySkuVo::getQuantity));
-        map.put("totalSubtotal", StreamUtil.bigDecimalAdd(list, DocumentBySkuVo::getSubtotal));
 
-        TemplateExcelUtil.writeBrowser("skuDocument.xlsx", "sku对账单", response, list, map);
-    }
-
-    @Override
-    public void exportDocumentByBom(HttpServletResponse response, Long id) {
-
-        StatementOfAccount statementOfAccount = getById(id);
-        Assert.notNull(statementOfAccount, "没有找到对账单");
         Department department = departmentService.getById(statementOfAccount.getDepartmentId());
         Assert.notNull(department, "没有找到事业部");
 
-        List<DocumentByBomVo> list = getDocumentByBom(id);
-
         Date timePeriod = statementOfAccount.getTimePeriod();
-        String timePeriodStr = timePeriod != null ? DateUtil.formatDate(timePeriod) : StringPool.EMPTY;
-
-        Map<String, Object> map = new HashMap<>();
-        map.put("department", department.getName() + " - ");
-        map.put("beginDate", timePeriodStr);
-        map.put("endDate", timePeriodStr);
-        map.put("totalSubtotal", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getSubtotal));
-        map.put("totalLaserLogoSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getLaserLogoSummary));
-        map.put("totalLaserMitochondrialSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getLaserMitochondrialSummary));
-        map.put("totalLssueFeeSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getLssueFeeSummary));
-        map.put("totalDeliveryMaterialsFeeSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getDeliveryMaterialsFeeSummary));
-        map.put("totalPackingLaborSummary", StreamUtil.bigDecimalAdd(list, DocumentByBomVo::getPackingLaborSummary));
-
-        TemplateExcelUtil.writeBrowser("bomDocument.xlsx", "bom对账单", response, list, map);
-    }
-
-    @Override
-    public void exportDocumentByOrder(HttpServletResponse response, Long id) {
-
-        StatementOfAccount statementOfAccount = getById(id);
-        Assert.notNull(statementOfAccount, "没有找到对账单");
-        Department department = departmentService.getById(statementOfAccount.getDepartmentId());
-        Assert.notNull(department, "没有找到事业部");
-
-        List<DocumentByOrderVo> list = getDocumentByOrder(id);
-
-        BigDecimal all = BigDecimal.ZERO;
-
-        List<ExportDocumentByOrderBo> exportDocumentByOrderBos = new ArrayList<>();
-        for (DocumentByOrderVo documentByOrderVo : list) {
-            List<DocumentByOrderVo.SkuSpec> skuSpecList = documentByOrderVo.getSkuSpecList();
-            for (DocumentByOrderVo.SkuSpec skuSpec : skuSpecList) {
-                List<DocumentByOrderVo.BomSpec> bomSpecList = skuSpec.getBomSpecList();
-                for (DocumentByOrderVo.BomSpec bomSpec : bomSpecList) {
-                    ExportDocumentByOrderBo exportDocumentByOrderBo = ExportDocumentByOrderBo.builder()
-                            .wlnCreateTime(documentByOrderVo.getWlnCreateTime())
-                            .code(documentByOrderVo.getCode())
-                            .wlnCode(documentByOrderVo.getWlnCode())
-                            .skuSpecCode(skuSpec.getSkuSpecCode())
-                            .skuSpecName(skuSpec.getSkuSpecName())
-                            .quantity(skuSpec.getQuantity())
-                            .unitPrice(skuSpec.getUnitPrice())
-                            .subtotal(skuSpec.getSubtotal())
-                            .total(skuSpec.getTotal())
-                            .bomSpecCode(bomSpec.getBomSpecCode())
-                            .bomSpecName(bomSpec.getBomSpecName())
-                            .bomQuantity(bomSpec.getQuantity())
-                            .bomUnitPrice(bomSpec.getUnitPrice())
-                            .laserLogoSummary(bomSpec.getLaserLogoSummary())
-                            .laserMitochondrialSummary(bomSpec.getLaserMitochondrialSummary())
-                            .lssueFeeSummary(bomSpec.getLssueFeeSummary())
-                            .deliveryMaterialsFeeSummary(bomSpec.getDeliveryMaterialsFeeSummary())
-                            .packingLaborSummary(bomSpec.getPackingLaborSummary())
-                            .build();
-                    exportDocumentByOrderBos.add(exportDocumentByOrderBo);
-                }
-                all = all.add(skuSpec.getTotal());
-            }
+        String date = timePeriod != null ? DateUtil.formatDate(timePeriod) : StringPool.EMPTY;
+        String departmentName = department.getName();
+
+        List<Long> idList = Collections.singletonList(id);
+
+        switch (type) {
+            case 1:
+                statementOfAccountExportService.exportDocumentBySku(idList, departmentName, date, date);
+                break;
+            case 2:
+                statementOfAccountExportService.exportDocumentByBom(idList, departmentName, date, date);
+                break;
+            case 3:
+                statementOfAccountExportService.exportDocumentByOrder(idList, departmentName, date, date);
+                break;
+            default:
+                throw new ServiceException("未知对账单类型");
         }
 
-        Date timePeriod = statementOfAccount.getTimePeriod();
-        String timePeriodStr = timePeriod != null ? DateUtil.formatDate(timePeriod) : StringPool.EMPTY;
-
-        Map<String, Object> map = new HashMap<>();
-        map.put("department", department.getName() + " - ");
-        map.put("beginDate", timePeriodStr);
-        map.put("endDate", timePeriodStr);
-        map.put("all", all);
-
-        TemplateExcelUtil.writeBrowser("orderDocument.xlsx", "订单对账单",
-                new DocumentByOrderExcelCellMergeStrategy(list), response, exportDocumentByOrderBos, map);
     }
 
     /**
      * 根据对账单id获取对账订单id列表
      */
-    private List<Long> getOrderIdList(Long statementOfAccountId) {
-        Assert.notNull(statementOfAccountId, "对账单id不能为空");
-        List<OrderInfo> orderList = orderService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, statementOfAccountId));
+    private List<Long> getOrderIdList(List<Long> statementOfAccountIdList) {
+        Assert.notEmpty(statementOfAccountIdList, "对账单id不能为空");
+        List<OrderInfo> orderList = orderService.list(q -> q.in(OrderInfo::getStatementOfAccountId, statementOfAccountIdList));
         return orderList.stream().map(BaseIdPo::getId).collect(Collectors.toList());
     }
 
@@ -544,8 +469,7 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
                                 .add(item.getDeliveryMaterialsFee())
                                 .add(item.getPackingLabor())
                                 .add(item.getPackagingMaterialCost()))
-                        .build()
-                )
+                        .build())
                 .peek(item -> item.setSubtotal(item.getQuantity().multiply(item.getUnitPrice())))
                 .peek(item -> item.setTotal(item.getSubtotal()))
                 .collect(Collectors.toList());
@@ -576,10 +500,10 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
                         .lssueFeeSummary(item.getLssueFee())
                         .deliveryMaterialsFeeSummary(item.getDeliveryMaterialsFee())
                         .packingLaborSummary(item.getPackingLabor())
-                        .build()
-                ).collect(Collectors.toList());
+                        .build())
+                .collect(Collectors.toList());
 
-        Map<Long, BigDecimal> collect = bomSpecList.stream().collect(
+        Map<Long, BigDecimal> map = bomSpecList.stream().collect(
                 Collectors.toMap(DocumentByOrderVo.BomSpec::getOrderSkuId, DocumentByOrderVo.BomSpec::getQuantity));
 
         List<OrderSkuBom> orderSkuBomList = orderSkuBomService.list(q -> q.in(OrderSkuBom::getOrderId, orderIdList));
@@ -591,7 +515,7 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
                         .quantity(item.getQuantity())
                         .unitPrice(item.getUnitPrice())
                         .build())
-                .peek(item -> item.setQuantity(collect.get(item.getOrderSkuId()).multiply(item.getQuantity())))
+                .peek(item -> item.setQuantity(map.get(item.getOrderSkuId()).multiply(item.getQuantity())))
                 .collect(Collectors.toList());
 
         bomSpecList.addAll(packBomSpecList);