源方法
package com.mfexpress.financial.accounting.payment.executor;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.mfexpress.common.domain.dto.erp.ErpNcOfficeSimpleDTO;
import com.mfexpress.component.response.PagePagination;
import com.mfexpress.component.response.Result;
import com.mfexpress.component.utils.util.ResultDataUtils;
import com.mfexpress.financial.accounting.BaseExe;
import com.mfexpress.financial.accounting.data.dto.payment.AccountingPaymentPageDTO;
import com.mfexpress.financial.accounting.data.dto.supplier.SupplierDTO;
import com.mfexpress.financial.accounting.data.qry.payment.PaymentOrderDomainQry;
import com.mfexpress.financial.accounting.data.qry.writeOff.CorporatePaymentDocQry;
import com.mfexpress.financial.accounting.voucher.vo.CorporatePaymentDocVO;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static com.mfexpress.financial.accounting.util.Util.formatConversionDay;
/**
* @author :
* @date : 2022/11/29 12:11
*/
@Component
public class CorporatePaymentDocPageExe extends BaseExe {
public PagePagination<CorporatePaymentDocVO> executor(CorporatePaymentDocQry corporatePaymentDocQry) {
//查询主体信息
PaymentOrderDomainQry paymentOrderDomainQry = getPaymentOrderDomainQry(corporatePaymentDocQry);
Result<PagePagination<AccountingPaymentPageDTO>> resultPage = accountingPaymentAggregateRootApi.paymentOrderList(paymentOrderDomainQry);
PagePagination<AccountingPaymentPageDTO> dtoPage = ResultDataUtils.getInstance(resultPage).getDataOrException();
List<AccountingPaymentPageDTO> accountingPaymentPageDTOList = dtoPage.getList();
List<Long> supplierIdList = new ArrayList<>();
List<Integer> erpOfficeIdList = new ArrayList<>();
accountingPaymentPageDTOList.forEach(accountingPaymentPageDTO -> {
supplierIdList.add(accountingPaymentPageDTO.getSupplierId());
erpOfficeIdList.add(accountingPaymentPageDTO.getCompanyId());
});
Map<Long, SupplierDTO> supplierMap = getSupplierMap(supplierIdList);
Map<Integer, ErpNcOfficeSimpleDTO> erpOfficeIdMap = getErpOfficeMap(erpOfficeIdList);
//处理返回值
List<CorporatePaymentDocVO> corporatePaymentDocResultList = new LinkedList<>();
for (AccountingPaymentPageDTO corporatePaymentDocDTO : accountingPaymentPageDTOList) {
SupplierDTO supplier = supplierMap.get(corporatePaymentDocDTO.getSupplierId());
ErpNcOfficeSimpleDTO erpOffice = erpOfficeIdMap.get(corporatePaymentDocDTO.getCompanyId());
String payerNme = erpOffice == null ? "" : erpOffice.getName();
String insuranceCompanyName = supplier == null ? "" : supplier.getName();
CorporatePaymentDocVO corporatePaymentDocVO = CorporatePaymentDocVO.builder()
.accountingPaymentId(corporatePaymentDocDTO.getAccountingPaymentId() == null ? "" : corporatePaymentDocDTO.getAccountingPaymentId().toString())
.accountingPaymentNo(corporatePaymentDocDTO.getAccountingPaymentNo() == null ? "" : corporatePaymentDocDTO.getAccountingPaymentNo())
.ncCorporateNo(corporatePaymentDocDTO.getNcCorporateNo() == null ? "" : corporatePaymentDocDTO.getNcCorporateNo())
.oaCorporateNo(corporatePaymentDocDTO.getOaCorporateNo() == null ? "" : corporatePaymentDocDTO.getOaCorporateNo())
.taxIncludedPremium(corporatePaymentDocDTO.getTaxIncludedPremium() == null ? new BigDecimal("0.00") : corporatePaymentDocDTO.getTaxIncludedPremium())
.applicationDate(corporatePaymentDocDTO.getApplicationDate() == null ? "" : corporatePaymentDocDTO.getApplicationDate())
.paymentStatus(corporatePaymentDocDTO.getPaymentStatus() == null ? 0 : corporatePaymentDocDTO.getPaymentStatus())
.paymentStatusDescribe(corporatePaymentDocDTO.getPaymentStatusDescribe())
.writeOffStatus(corporatePaymentDocDTO.getWriteOffStatus() == null ? 0 : corporatePaymentDocDTO.getWriteOffStatus())
.writeOffStatusDescribe(corporatePaymentDocDTO.getWriteOffStatusDescribe())
.ncWriteOffDocNo(corporatePaymentDocDTO.getNcWriteOffDocNo() == null ? "" : corporatePaymentDocDTO.getNcWriteOffDocNo())
.oaWriteOffDocNo(corporatePaymentDocDTO.getOaWriteOffDocNo() == null ? "" : corporatePaymentDocDTO.getOaWriteOffDocNo())
.payer(payerNme)
.insuranceCompany(insuranceCompanyName)
.applicant(corporatePaymentDocDTO.getApplicant() == null ? "" : corporatePaymentDocDTO.getApplicant())
.build();
corporatePaymentDocResultList.add(corporatePaymentDocVO);
}
PagePagination<CorporatePaymentDocVO> voPage = new PagePagination<>();
BeanUtil.copyProperties(dtoPage, voPage);
voPage.setList(corporatePaymentDocResultList);
return voPage;
}
protected PaymentOrderDomainQry getPaymentOrderDomainQry(CorporatePaymentDocQry corporatePaymentDocQry) {
PaymentOrderDomainQry paymentOrderDomainQry = BeanUtil.toBean(corporatePaymentDocQry, PaymentOrderDomainQry.class, CopyOptions.create());
paymentOrderDomainQry.setSupplierId(corporatePaymentDocQry.getSupplierId());
paymentOrderDomainQry.setErpOfficeId(corporatePaymentDocQry.getPayer());
paymentOrderDomainQry.setApplicationDate(formatConversionDay(corporatePaymentDocQry.getApplicationDate()));
return paymentOrderDomainQry;
}
}
父类
package com.mfexpress.financial.accounting;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hx.erp.assets.api.domain.AssetCarsAggregateRootApi;
import com.hx.erp.assets.data.dto.AssetCarsInfoDTO;
import com.mfexpress.common.domain.api.ErpOfficeAggregateRootApi;
import com.mfexpress.common.domain.dto.erp.ErpHeadOfficeSimpleDTO;
import com.mfexpress.common.domain.dto.erp.ErpIdListLevelQryCmd;
import com.mfexpress.common.domain.dto.erp.ErpNameQryDTO;
import com.mfexpress.common.domain.dto.erp.ErpNcOfficeSimpleDTO;
import com.mfexpress.component.response.Result;
import com.mfexpress.component.utils.util.ResultDataUtils;
import com.mfexpress.financial.accounting.api.domain.*;
import com.mfexpress.financial.accounting.data.dto.nc.DataTransmissionCreateDTO;
import com.mfexpress.financial.accounting.data.dto.nc.DataTransmissionDTO;
import com.mfexpress.financial.accounting.data.dto.nc.NcErpOfficeInfoDTO;
import com.mfexpress.financial.accounting.data.dto.supplier.SupplierDTO;
import com.mfexpress.financial.accounting.data.dto.writeOff.CreateWriteOffDTO;
import com.mfexpress.financial.accounting.insurance.dto.ApplyPolicyDTO;
import com.mfexpress.financial.accounting.insurance.dto.InsuranceApplyIdsQry;
import com.mfexpress.financial.accounting.insurance.dto.InsurancePolicyDTO;
import com.mfexpress.financial.accounting.insurance.dto.InsurancePolicyIdsQry;
import com.mfexpress.financial.accounting.insurance.feign.BCPolicyFeign;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author :
* @date : 2022/12/4 14:07
*/
@Slf4j
public class BaseExe {
@Resource
private SupplierAggregateRootApi supplierAggregateRootApi;
@Resource
private ErpOfficeAggregateRootApi erpOfficeAggregateRootApi;
@Resource
private AssetCarsAggregateRootApi assetCarsAggregateRootApi;
@Resource
private BCPolicyFeign bcPolicyFeign;
@Resource
protected AccountingWriteOffAggregateRootApi accountingWriteOffAggregateRootApi;
@Resource
protected AccountingIndentAggregateRootApi accountingIndentAggregateRootApi;
@Resource
protected AccountingPaymentAggregateRootApi accountingPaymentAggregateRootApi;
@Resource
protected RedInformationAggregateRootApi redInformationAggregateRootApi;
/**
* 供应商(保险公司)
*/
protected Map<Long, SupplierDTO> getSupplierMap(List<Long> supplierIdList) {
Map<Long, SupplierDTO> supplierMap = new HashMap<>(supplierIdList.size());
if (CollectionUtil.isEmpty(supplierIdList)) {
return supplierMap;
}
List<Long> supplierDistinct = supplierIdList.stream().distinct().collect(Collectors.toList());
Result<List<SupplierDTO>> supplierResult = supplierAggregateRootApi.getSupplierBySupplierIdList(supplierDistinct);
List<SupplierDTO> supplierDTOList = ResultDataUtils.getInstance(supplierResult).getDataOrException();
if (CollectionUtil.isNotEmpty(supplierDTOList)) {
supplierMap = supplierDTOList.stream().collect(Collectors.toMap(SupplierDTO::getSupplierId, Function.identity(), (key1, key2) -> key1));
}
return supplierMap;
}
/**
* 通过总公司idList获取NC组织列表
*
* @param erpOfficeIdList 总公司id
* @return NC组织列表
*/
protected Map<Integer, ErpNcOfficeSimpleDTO> getErpOfficeMap(List<Integer> erpOfficeIdList) {
if (CollectionUtil.isEmpty(erpOfficeIdList)) {
return new HashMap<>(1);
}
List<Integer> erpOfficeDistinct = erpOfficeIdList.stream().distinct().collect(Collectors.toList());
Result<List<ErpNcOfficeSimpleDTO>> officeResult = erpOfficeAggregateRootApi.getErpNcOfficeSimpleDTOListByHeadOfficeIdList(erpOfficeDistinct);
List<ErpNcOfficeSimpleDTO> officeList = ResultDataUtils.getInstance(officeResult).getDataOrException();
if (CollectionUtil.isEmpty(officeList)) {
return new HashMap<>(1);
}
return officeList.stream()
.collect(Collectors.toMap(
ErpNcOfficeSimpleDTO::getHeadOfficeId, Function.identity(), (key1, key2) -> key1));
}
}
测试类
package com.mfexpress.financial.accounting.payment.executor;
import com.mfexpress.common.domain.api.ErpOfficeAggregateRootApi;
import com.mfexpress.common.domain.dto.erp.ErpNcOfficeSimpleDTO;
import com.mfexpress.component.response.PagePagination;
import com.mfexpress.component.response.Result;
import com.mfexpress.financial.accounting.MfFinancialAccountingApplication;
import com.mfexpress.financial.accounting.api.domain.AccountingPaymentAggregateRootApi;
import com.mfexpress.financial.accounting.api.domain.SupplierAggregateRootApi;
import com.mfexpress.financial.accounting.data.dto.payment.AccountingPaymentPageDTO;
import com.mfexpress.financial.accounting.data.dto.supplier.SupplierDTO;
import com.mfexpress.financial.accounting.data.qry.payment.PaymentOrderDomainQry;
import com.mfexpress.financial.accounting.data.qry.writeOff.CorporatePaymentDocQry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
/**
* @author :
* @date : 2022/12/30 14:30
*/
//运行环境
@ActiveProfiles("dev2m1")
//启动类
@SpringBootTest(classes = MfFinancialAccountingApplication.class)
@RunWith(MockitoJUnitRunner.class)
public class CorporatePaymentDocPageExeTest {
@InjectMocks
private CorporatePaymentDocPageExe corporatePaymentDocPageExe;
@Mock
private AccountingPaymentAggregateRootApi accountingPaymentAggregateRootApi;
@Mock
private SupplierAggregateRootApi supplierAggregateRootApi;
@Mock
private ErpOfficeAggregateRootApi erpOfficeAggregateRootApi;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
when(accountingPaymentAggregateRootApi.paymentOrderList(any(PaymentOrderDomainQry.class)))
.thenReturn(Result.getInstance(
PagePagination.getInstance(
Collections.singletonList(
AccountingPaymentPageDTO.builder()
.erpOfficeId(1)
.supplierId(1L)
.accountingPaymentId(1L)
.accountingPaymentNo("")
.ncCorporateNo("")
.oaCorporateNo("")
.taxIncludedPremium(new BigDecimal("0.00"))
.applicationDate("")
.paymentStatus(1)
.writeOffStatus(1)
.ncWriteOffDocNo("")
.oaWriteOffDocNo("")
.applicant("")
.build()))));
when(supplierAggregateRootApi.getSupplierBySupplierIdList(any(List.class)))
.thenReturn(Result.getInstance(
Collections.singletonList(
SupplierDTO.builder()
.supplierId(1L)
.name("")
.build())));
when(erpOfficeAggregateRootApi.getErpNcOfficeSimpleDTOListByHeadOfficeIdList(any(List.class)))
.thenReturn(Result.getInstance(
Collections.singletonList(
ErpNcOfficeSimpleDTO.builder()
.headOfficeId(1)
.name("")
.build())));
}
@Test
public void testExecutor() {
// Setup
final CorporatePaymentDocQry corporatePaymentDocQry = new CorporatePaymentDocQry();
corporatePaymentDocQry.setAccountingPaymentNo("accountingPaymentNo");
corporatePaymentDocQry.setNcCorporateNo("ncCorporateNo");
corporatePaymentDocQry.setOaCorporateNo("oaCorporateNo");
corporatePaymentDocQry.setNcWriteOffDocNo("ncWriteOffDocNo");
corporatePaymentDocQry.setPayer(0);
corporatePaymentDocQry.setOaWriteOffDocNo("oaWriteOffDocNo");
corporatePaymentDocQry.setSupplierId(0L);
corporatePaymentDocQry.setApplicant("applicant");
corporatePaymentDocQry.setApplicationDate(
Collections.singletonList(new GregorianCalendar(2020, Calendar.JANUARY, 1).getTime()));
corporatePaymentDocQry.setPaymentStatus(0);
corporatePaymentDocQry.setWriteOffStatus(0);
corporatePaymentDocPageExe.executor(
corporatePaymentDocQry);
}
@Test
public void testGetPaymentOrderDomainQry() {
// Setup
final CorporatePaymentDocQry corporatePaymentDocQry = new CorporatePaymentDocQry();
corporatePaymentDocQry.setAccountingPaymentNo("accountingPaymentNo");
corporatePaymentDocQry.setNcCorporateNo("ncCorporateNo");
corporatePaymentDocQry.setOaCorporateNo("oaCorporateNo");
corporatePaymentDocQry.setNcWriteOffDocNo("ncWriteOffDocNo");
corporatePaymentDocQry.setPayer(0);
corporatePaymentDocQry.setOaWriteOffDocNo("oaWriteOffDocNo");
corporatePaymentDocQry.setSupplierId(0L);
corporatePaymentDocQry.setApplicant("applicant");
corporatePaymentDocQry.setApplicationDate(
Collections.singletonList(new GregorianCalendar(2020, Calendar.JANUARY, 1).getTime()));
corporatePaymentDocQry.setPaymentStatus(0);
corporatePaymentDocQry.setWriteOffStatus(0);
final PaymentOrderDomainQry expectedResult = new PaymentOrderDomainQry();
expectedResult.setAccountingPaymentNo("accountingPaymentNo");
expectedResult.setNcCorporateNo("ncCorporateNo");
expectedResult.setOaCorporateNo("oaCorporateNo");
expectedResult.setNcWriteOffDocNo("ncWriteOffDocNo");
expectedResult.setOaWriteOffDocNo("oaWriteOffDocNo");
expectedResult.setApplicant("applicant");
expectedResult.setApplicationDate(Collections.singletonList("value"));
expectedResult.setPaymentStatus(0);
expectedResult.setWriteOffStatus(0);
expectedResult.setSupplierId(0L);
expectedResult.setErpOfficeId(0);
// Run the test
final PaymentOrderDomainQry result = corporatePaymentDocPageExe.getPaymentOrderDomainQry(
corporatePaymentDocQry);
// Verify the results
assertEquals(expectedResult, result);
}
}