24282 преди 1 година
родител
ревизия
a9be8cce22

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

@@ -10,6 +10,7 @@ import com.sd.business.entity.statement.dto.StatementOfAccountSelectDto;
 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.ReconciliationDetailVo;
 import com.sd.business.entity.statement.vo.StatementOfAccountVo;
 import com.sd.business.entity.statement.vo.StatementOrderClassifyTotalCountVo;
 import com.sd.business.service.statement.StatementOfAccountService;
@@ -51,7 +52,7 @@ public class StatementOfAccountController {
      * 对账单明细
      */
     @PostMapping("/detail")
-    public StatementOfAccountVo detail(@RequestBody BaseSelectDto dto) {
+    public List<ReconciliationDetailVo> detail(@RequestBody BaseSelectDto dto) {
         return statementOfAccountService.detail(dto.getId());
     }
 

+ 6 - 0
sd-business/src/main/java/com/sd/business/mapper/statement/StatementOfAccountMapper.java

@@ -1,7 +1,11 @@
 package com.sd.business.mapper.statement;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.sd.business.entity.statement.po.StatementOfAccount;
+import com.sd.business.entity.statement.vo.StatementOfAccountVo;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -13,4 +17,6 @@ import com.sd.business.entity.statement.po.StatementOfAccount;
  */
 public interface StatementOfAccountMapper extends BaseMapper<StatementOfAccount> {
 
+    Page<StatementOfAccountVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<StatementOfAccount> wrapper);
+
 }

+ 2 - 1
sd-business/src/main/java/com/sd/business/service/statement/StatementOfAccountService.java

@@ -10,6 +10,7 @@ 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.ReconciliationDetailVo;
 import com.sd.business.entity.statement.vo.StatementOfAccountVo;
 import com.sd.business.entity.statement.vo.StatementOrderClassifyTotalCountVo;
 
@@ -34,7 +35,7 @@ public interface StatementOfAccountService extends BaseService<StatementOfAccoun
     /**
      * 对账单明细
      */
-    StatementOfAccountVo detail(Long id);
+    List<ReconciliationDetailVo> detail(Long id);
 
     /**
      * 对账单新增

+ 72 - 15
sd-business/src/main/java/com/sd/business/service/statement/impl/StatementOfAccountServiceImpl.java

@@ -1,15 +1,19 @@
 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.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.file.entity.FileInfoVo;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.ruoyi.common.constant.StatusConstant;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.framework.config.ThreadPoolConfig;
 import com.sd.business.entity.bom.bo.BomSpecBo;
 import com.sd.business.entity.department.po.Department;
@@ -26,6 +30,7 @@ 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.ReconciliationDetailVo;
 import com.sd.business.entity.statement.vo.StatementOfAccountVo;
 import com.sd.business.entity.statement.vo.StatementOrderClassifyTotalCountVo;
 import com.sd.business.mapper.statement.StatementOfAccountMapper;
@@ -41,7 +46,6 @@ import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.business.strategy.impl.DocumentByOrderExcelExportStrategy;
 import com.sd.business.util.code.CodeEnum;
 import com.sd.framework.util.Assert;
-import com.sd.framework.util.sql.Sql;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.security.core.context.SecurityContext;
@@ -109,27 +113,80 @@ public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccoun
     @Override
     public Page<StatementOfAccountVo> getPage(StatementOfAccountSelectDto dto) {
 
-        Page<StatementOfAccountVo> page = Sql.create(StatementOfAccountVo.class)
-                .selectAll(StatementOfAccount.class)
-                .from(StatementOfAccount.class)
-                .orderByDesc(StatementOfAccount::getId)
-                .page(dto);
+        IWrapper<StatementOfAccount> wrapper = getWrapper();
+        wrapper.like("soa", StatementOfAccount::getCode, dto.getCode());
+        wrapper.eq("soa", StatementOfAccount::getDepartmentId, dto.getDepartmentId());
+        wrapper.eq("soa", StatementOfAccount::getCheckStatus, dto.getCheckStatus());
+        wrapper.ge("soa", StatementOfAccount::getTimePeriod, dto.getBeginTime());
+        wrapper.le("soa", StatementOfAccount::getTimePeriod, dto.getEndTime());
+        wrapper.orderByDesc("soa", StatementOfAccount::getCode);
+
+        Page<StatementOfAccountVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
+        List<StatementOfAccountVo> records = page.getRecords();
+        if (records.isEmpty()) {
+            return page;
+        }
+
+        // 查询对账单和转帐凭证
+        List<Long> idList = records.stream().map(BaseIdPo::getId).collect(Collectors.toList());
+        Map<Long, List<FileInfoVo>> receiptFileMap = ObsFileUtil.getFileMap(idList, 1);
+        Map<Long, List<FileInfoVo>> proofFileMap = ObsFileUtil.getFileMap(idList, 2);
+
+        Map<Long, Map<String, Object>> map = orderInfoService.listMaps(Wrappers.<OrderInfo>query()
+                        .select(
+                                "statement_of_account_id as statementOfAccountId",
+                                "sum(total_amount) as amount",
+                                "count(0) as orderNum"
+                        )
+                        .in("statement_of_account_id", idList)
+                        .groupBy("statement_of_account_id")
+                )
+                .stream()
+                .collect(Collectors.toMap(
+                        item -> Convert.toLong(item.get("statementOfAccountId")),
+                        Function.identity()
+                ));
+
+        for (StatementOfAccountVo record : records) {
+            record.setReceiptFileList(receiptFileMap.getOrDefault(record.getId(), Collections.emptyList()));
+            record.setProofFileList(proofFileMap.getOrDefault(record.getId(), Collections.emptyList()));
+            Map<String, Object> tempMap = map.get(record.getId());
+            if (tempMap == null) {
+                record.setOrderNum(0);
+                record.setAmount(BigDecimal.ZERO);
+            } else {
+                record.setOrderNum(Convert.toInt(tempMap.get("orderNum"), 0));
+                record.setAmount(Convert.toBigDecimal(tempMap.get("amount"), BigDecimal.ZERO));
+            }
+        }
 
         return page;
     }
 
     @Override
-    public StatementOfAccountVo detail(Long id) {
-
-        StatementOfAccountVo vo = Sql.create(StatementOfAccountVo.class)
-                .selectAll(StatementOfAccount.class)
-                .from(StatementOfAccount.class)
-                .eq(StatementOfAccount::getId, id)
-                .one();
+    public List<ReconciliationDetailVo> detail(Long id) {
+        List<OrderInfo> orderInfoList = orderInfoService.list(q -> q.eq(OrderInfo::getStatementOfAccountId, id));
+
+        List<ReconciliationDetailVo> result = orderInfoList.stream().map(item -> ReconciliationDetailVo.builder()
+                .orderId(item.getId())
+                .departmentId(item.getDepartmentId())
+                .orderCode(item.getCode())
+                .totalAmount(item.getTotalAmount())
+                .productTotalAmount(item.getProductTotalAmount())
+                .customProcessingFee(item.getCustomProcessingFee())
+                .lssueFee(item.getLssueFee())
+                .deliveryMaterialsFee(item.getDeliveryMaterialsFee())
+                .packingLabor(item.getPackingLabor())
+                .packagingMaterialCost(item.getPackagingMaterialCost())
+                .managementFee(item.getManagementFee())
+                .build()
+        ).collect(Collectors.toList());
 
-        Assert.notNull(vo, "未知数据");
+        departmentService.attributeAssign(result, ReconciliationDetailVo::getDepartmentId, (item, department) -> {
+            item.setDepartmentName(department.getName());
+        });
 
-        return vo;
+        return result;
     }
 
     @Transactional(rollbackFor = Exception.class)

+ 13 - 0
sd-business/src/main/resources/mapper/statement/StatementOfAccountMapper.xml

@@ -2,4 +2,17 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.sd.business.mapper.statement.StatementOfAccountMapper">
 
+    <select id="getPage" resultType="com.sd.business.entity.statement.vo.StatementOfAccountVo">
+        select soa.id,
+               soa.code,
+               soa.department_id,
+               soa.time_period,
+               soa.check_status,
+               soa.create_time,
+               d.name departmentName
+        from statement_of_account soa
+                 left join department d on d.id = soa.department_id
+            ${ew.customSqlSegment}
+    </select>
+    
 </mapper>