|
@@ -1,17 +1,33 @@
|
|
|
package com.sd.business.service.statement.impl;
|
|
|
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
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.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.sd.business.entity.order.po.OrderInfo;
|
|
|
+import com.sd.business.entity.statement.dto.FileUploadDto;
|
|
|
import com.sd.business.entity.statement.dto.StatementOfAccountDto;
|
|
|
import com.sd.business.entity.statement.dto.StatementOfAccountSelectDto;
|
|
|
import com.sd.business.entity.statement.po.StatementOfAccount;
|
|
|
+import com.sd.business.entity.statement.vo.ReconciliationDetailVo;
|
|
|
import com.sd.business.entity.statement.vo.StatementOfAccountVo;
|
|
|
import com.sd.business.mapper.statement.StatementOfAccountMapper;
|
|
|
+import com.sd.business.service.department.DepartmentService;
|
|
|
+import com.sd.business.service.order.OrderService;
|
|
|
import com.sd.business.service.statement.StatementOfAccountService;
|
|
|
+import com.sd.business.util.CodeEnum;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -24,34 +40,143 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class StatementOfAccountServiceImpl extends ServiceImpl<StatementOfAccountMapper, StatementOfAccount> implements StatementOfAccountService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrderService orderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DepartmentService departmentService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<StatementOfAccountVo> getPage(StatementOfAccountSelectDto dto) {
|
|
|
+
|
|
|
IWrapper<StatementOfAccount> wrapper = getWrapper();
|
|
|
+ wrapper.eq("soa", StatementOfAccount::getDepartmentId, dto.getDepartmentId());
|
|
|
+ wrapper.like("soa", StatementOfAccount::getCode, dto.getCode());
|
|
|
+ wrapper.ge("soa", StatementOfAccount::getCreateTime, dto.getBeginTime());
|
|
|
+ wrapper.le("soa", StatementOfAccount::getCreateTime, dto.getEndTime());
|
|
|
wrapper.orderByDesc("soa", StatementOfAccount::getId);
|
|
|
+
|
|
|
Page<StatementOfAccountVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ List<StatementOfAccountVo> records = page.getRecords();
|
|
|
+ if (records.size() == 0) {
|
|
|
+ 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);
|
|
|
+
|
|
|
+ List<String> orderIdList = records.stream()
|
|
|
+ .map(StatementOfAccount::getOrderIdJoin)
|
|
|
+ .filter(StrUtil::isNotBlank)
|
|
|
+ .flatMap(item -> Arrays.stream(item.split(",")))
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, String> orderIdCodeMap;
|
|
|
+ if (orderIdList.size() == 0) {
|
|
|
+ orderIdCodeMap = orderService.mapKV(BaseIdPo::getId, OrderInfo::getCode,
|
|
|
+ q -> q.select(BaseIdPo::getId, OrderInfo::getCode).in(BaseIdPo::getId, orderIdList));
|
|
|
+ } else {
|
|
|
+ orderIdCodeMap = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ for (StatementOfAccountVo record : records) {
|
|
|
+ record.setReceiptFileList(receiptFileMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
+ record.setProofFileList(proofFileMap.getOrDefault(record.getId(), Collections.emptyList()));
|
|
|
+
|
|
|
+ String orderIdJoin = record.getOrderIdJoin();
|
|
|
+ StringJoiner codeJoiner = new StringJoiner(",");
|
|
|
+ int orderNum = 0;
|
|
|
+ for (String orderId : orderIdJoin.split(",")) {
|
|
|
+ if (StrUtil.isBlank(orderId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String orderCode = orderIdCodeMap.get(Convert.toLong(orderId));
|
|
|
+ if (StrUtil.isBlank(orderCode)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ codeJoiner.add(orderCode);
|
|
|
+ orderNum++;
|
|
|
+ }
|
|
|
+ record.setOrderCodeJoin(codeJoiner.toString());
|
|
|
+ record.setOrderNum(orderNum);
|
|
|
+ }
|
|
|
+
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public StatementOfAccountVo detail(Long id) {
|
|
|
+ public List<ReconciliationDetailVo> detail(Long id) {
|
|
|
StatementOfAccount StatementOfAccount = this.getById(id);
|
|
|
- StatementOfAccountVo result = BeanUtil.toBean(StatementOfAccount, StatementOfAccountVo.class);
|
|
|
+ String orderIdJoin = StatementOfAccount.getOrderIdJoin();
|
|
|
+
|
|
|
+ List<ReconciliationDetailVo> result = Arrays.stream(orderIdJoin.split(","))
|
|
|
+ .map(Convert::toLong)
|
|
|
+ .filter(ObjectUtil::isNotNull)
|
|
|
+ .distinct()
|
|
|
+ .map(item -> ReconciliationDetailVo.builder().orderId(item).build())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ orderService.attributeAssign(result, ReconciliationDetailVo::getOrderId, (item, order) -> {
|
|
|
+ item.setDepartmentId(order.getDepartmentId());
|
|
|
+ item.setOrderCode(order.getCode());
|
|
|
+ item.setTotalAmount(order.getTotalAmount());
|
|
|
+ item.setProductTotalAmount(order.getProductTotalAmount());
|
|
|
+ item.setCustomProcessingFee(order.getCustomProcessingFee());
|
|
|
+ item.setLssueFee(order.getLssueFee());
|
|
|
+ item.setDeliveryMaterialsFee(order.getDeliveryMaterialsFee());
|
|
|
+ item.setPackingLabor(order.getPackingLabor());
|
|
|
+ item.setPackagingMaterialCost(order.getPackagingMaterialCost());
|
|
|
+ });
|
|
|
+
|
|
|
+ result = result.stream().filter(item -> ObjectUtil.isNotEmpty(item.getOrderCode())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ departmentService.attributeAssign(result, ReconciliationDetailVo::getDepartmentId, (item, department) -> {
|
|
|
+ item.setDepartmentName(department.getName());
|
|
|
+ });
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void add(StatementOfAccountDto statementOfAccountDto) {
|
|
|
+
|
|
|
+ String orderIdJoin = statementOfAccountDto.getOrderIdList()
|
|
|
+ .stream()
|
|
|
+ .map(Convert::toStr)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ statementOfAccountDto.setCode(CodeEnum.STATEMENT_OF_ACCOUNT_CODE.getCode());
|
|
|
+ statementOfAccountDto.setType(1);
|
|
|
+ statementOfAccountDto.setOrderIdJoin(orderIdJoin);
|
|
|
this.save(statementOfAccountDto);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void edit(StatementOfAccountDto statementOfAccountDto) {
|
|
|
+
|
|
|
+ String orderIdJoin = statementOfAccountDto.getOrderIdList()
|
|
|
+ .stream()
|
|
|
+ .map(Convert::toStr)
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ statementOfAccountDto.setOrderIdJoin(orderIdJoin);
|
|
|
+
|
|
|
this.updateById(statementOfAccountDto);
|
|
|
}
|
|
|
|
|
|
+ @DSTransactional
|
|
|
@Override
|
|
|
public void delete(Long id) {
|
|
|
this.removeById(id);
|
|
|
+ ObsFileUtil.removeFile(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void editFile(FileUploadDto dto, int type) {
|
|
|
+ ObsFileUtil.editFile(dto.getFileList(), dto.getId(), type);
|
|
|
}
|
|
|
|
|
|
}
|