mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 13:42:07 +08:00
资金管理购买记录、组织资金接口单元测试完善
This commit is contained in:
+1
-1
@@ -111,7 +111,7 @@ public interface PurchaseRecordMapper extends BaseMapperX<PurchaseRecordDO> {
|
|||||||
* 查询当日销售总额
|
* 查询当日销售总额
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
BigDecimal getTodaySales();
|
BigDecimal getTodaySales(@Param("endTime") LocalDateTime endTime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询销售记录
|
* 分页查询销售记录
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
package com.cf.imes.module.system.service.funds.organamount;
|
package com.cf.imes.module.system.service.funds.organamount;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
@@ -116,7 +117,7 @@ public class OrganAmountServiceImpl implements OrganAmountService {
|
|||||||
String dateStr = dateList.get(i);
|
String dateStr = dateList.get(i);
|
||||||
|
|
||||||
List<OrganAmountGroupByCreateTimeRespVO> organIncomeExpenseGroupByCreateTimeRespVOS = organIncomeExpenseGroupByCreateTimeRespMap.get(dateStr);
|
List<OrganAmountGroupByCreateTimeRespVO> organIncomeExpenseGroupByCreateTimeRespVOS = organIncomeExpenseGroupByCreateTimeRespMap.get(dateStr);
|
||||||
amountArr[i] = organIncomeExpenseGroupByCreateTimeRespVOS != null && !organIncomeExpenseGroupByCreateTimeRespVOS.isEmpty() ? organIncomeExpenseGroupByCreateTimeRespVOS.get(0).getAmount() : BigDecimal.ZERO;
|
amountArr[i] = CollUtil.isNotEmpty(organIncomeExpenseGroupByCreateTimeRespVOS) ? organIncomeExpenseGroupByCreateTimeRespVOS.get(0).getAmount() : BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
orgAmountSeriesItem.put("data", amountArr);
|
orgAmountSeriesItem.put("data", amountArr);
|
||||||
|
|||||||
+4
-5
@@ -183,6 +183,9 @@ public class PurchaseServiceImpl implements PurchaseService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createOrgInitProductPurchaseRecord(Long organId, List<OrganCreateProductPurchaseReqVO> productPurchaseReqVOS) {
|
public void createOrgInitProductPurchaseRecord(Long organId, List<OrganCreateProductPurchaseReqVO> productPurchaseReqVOS) {
|
||||||
|
if (CollUtil.isEmpty(productPurchaseReqVOS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (OrganCreateProductPurchaseReqVO purchaseReqVO : productPurchaseReqVOS) {
|
for (OrganCreateProductPurchaseReqVO purchaseReqVO : productPurchaseReqVOS) {
|
||||||
// 1、校验产品
|
// 1、校验产品
|
||||||
Long productId = purchaseReqVO.getProductId();
|
Long productId = purchaseReqVO.getProductId();
|
||||||
@@ -280,15 +283,11 @@ public class PurchaseServiceImpl implements PurchaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 7、新增
|
// 7、新增
|
||||||
if (CollUtil.isNotEmpty(createList)) {
|
|
||||||
createOrgInitProductPurchaseRecord(organId, createList);
|
createOrgInitProductPurchaseRecord(organId, createList);
|
||||||
}
|
|
||||||
|
|
||||||
// 8、删除
|
// 8、删除
|
||||||
if (CollUtil.isNotEmpty(deleteIdList)) {
|
|
||||||
purchaseRecordMapper.deleteByIds(deleteIdList);
|
purchaseRecordMapper.deleteByIds(deleteIdList);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PurchaseRecordDO> getOrgPurchaseList(Set<Long> organIds) {
|
public List<PurchaseRecordDO> getOrgPurchaseList(Set<Long> organIds) {
|
||||||
@@ -551,7 +550,7 @@ public class PurchaseServiceImpl implements PurchaseService {
|
|||||||
public ManageSalesTotalStatisticRespVO getSalesTotalStatistics() {
|
public ManageSalesTotalStatisticRespVO getSalesTotalStatistics() {
|
||||||
ManageSalesTotalStatisticRespVO respVO = new ManageSalesTotalStatisticRespVO();
|
ManageSalesTotalStatisticRespVO respVO = new ManageSalesTotalStatisticRespVO();
|
||||||
respVO.setSalesTotal(purchaseRecordMapper.getTotalSales().getAmount());
|
respVO.setSalesTotal(purchaseRecordMapper.getTotalSales().getAmount());
|
||||||
respVO.setSalesToday(purchaseRecordMapper.getTodaySales());
|
respVO.setSalesToday(purchaseRecordMapper.getTodaySales(LocalDateTime.now().plusDays(1)));
|
||||||
return respVO;
|
return respVO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@
|
|||||||
from purchase_record
|
from purchase_record
|
||||||
where deleted = false and initial != true
|
where deleted = false and initial != true
|
||||||
and create_time >= CURDATE()
|
and create_time >= CURDATE()
|
||||||
and create_time < CURDATE() + INTERVAL 1 DAY;
|
and create_time < #{endTime};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<sql id="dateCreate">
|
<sql id="dateCreate">
|
||||||
|
|||||||
+248
@@ -0,0 +1,248 @@
|
|||||||
|
package com.cf.imes.module.system.service.funds.organamount;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.enums.StatisticsUnit;
|
||||||
|
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||||
|
import com.cf.imes.framework.security.test.WithMockLoginUser;
|
||||||
|
import com.cf.imes.framework.test.core.ut.BaseDbAndRedisUnitTest;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.invoice.vo.InvoiceAmountRespVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.ManageAmountOverviewRespVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganFundsStatisticsReqVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganProductOverviewRespVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.TotalSalesAmountRespVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.purchase.vo.OrgEarliestPurchaseProductRespVO;
|
||||||
|
import com.cf.imes.module.system.dal.dataobject.funds.purchase.PurchaseRecordDO;
|
||||||
|
import com.cf.imes.module.system.dal.dataobject.incomeandexpense.IncomeExpenseDetailsDO;
|
||||||
|
import com.cf.imes.module.system.dal.mysql.incomeandexpense.IncomeExpenseDetailsMapper;
|
||||||
|
import com.cf.imes.module.system.service.funds.invoice.InvoiceService;
|
||||||
|
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
|
||||||
|
import com.cf.imes.module.system.service.organ.OrganService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.cf.imes.framework.test.core.util.RandomUtils.randomPojo;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2025/12/31 14:00
|
||||||
|
*/
|
||||||
|
@Import(OrganAmountServiceImpl.class)
|
||||||
|
public class OrganAmountServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||||
|
@Resource
|
||||||
|
IncomeExpenseDetailsMapper incomeExpenseDetailsMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OrganAmountServiceImpl organAmountService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private OrganService organService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private PurchaseService purchaseService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private InvoiceService invoiceService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockLoginUser(organId = 1L)
|
||||||
|
void testGetOrganProductOverview_notInitialPurchase() {
|
||||||
|
// ===== given =====
|
||||||
|
Long organId = SecurityFrameworkUtils.getUserOrganId();
|
||||||
|
|
||||||
|
PurchaseRecordDO record = new PurchaseRecordDO();
|
||||||
|
record.setEndTime(LocalDate.of(2025, 12, 31));
|
||||||
|
record.setInitial(false);
|
||||||
|
record.setPurchaseDuration(12);
|
||||||
|
record.setPurchaseDurationUnit(1);
|
||||||
|
|
||||||
|
OrgEarliestPurchaseProductRespVO resp = new OrgEarliestPurchaseProductRespVO(record);
|
||||||
|
|
||||||
|
when(purchaseService.getOrgEarliestProductDetail(organId))
|
||||||
|
.thenReturn(resp);
|
||||||
|
when(purchaseService.getInvoicingAmount(organId))
|
||||||
|
.thenReturn(new BigDecimal("100.50"));
|
||||||
|
|
||||||
|
// ===== when =====
|
||||||
|
OrganProductOverviewRespVO result = organAmountService.getOrganProductOverview();
|
||||||
|
|
||||||
|
// ===== then =====
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
assertEquals("2025-12-31 00:00:00", result.getProductEfficientDate());
|
||||||
|
assertEquals(12, result.getDuration());
|
||||||
|
assertEquals(1, result.getDurationUnit());
|
||||||
|
assertEquals(new BigDecimal("100.50"), result.getInvoiceableAmount());
|
||||||
|
|
||||||
|
verify(organService).validOrgan(organId);
|
||||||
|
verify(purchaseService).getOrgEarliestProductDetail(organId);
|
||||||
|
verify(purchaseService).getInvoicingAmount(organId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockLoginUser(organId = 1L)
|
||||||
|
void testGetOrganProductOverview_noOrgEarliestPurchaseProduct() {
|
||||||
|
// ===== given =====
|
||||||
|
Long organId = SecurityFrameworkUtils.getUserOrganId();
|
||||||
|
|
||||||
|
when(purchaseService.getOrgEarliestProductDetail(organId))
|
||||||
|
.thenReturn(null);
|
||||||
|
when(purchaseService.getInvoicingAmount(organId))
|
||||||
|
.thenReturn(new BigDecimal("100.50"));
|
||||||
|
|
||||||
|
// ===== when =====
|
||||||
|
OrganProductOverviewRespVO result = organAmountService.getOrganProductOverview();
|
||||||
|
|
||||||
|
// ===== then =====
|
||||||
|
assertNotNull(result);
|
||||||
|
|
||||||
|
assertNull(result.getProductEfficientDate());
|
||||||
|
assertNull(result.getDuration());
|
||||||
|
assertNull(result.getDurationUnit());
|
||||||
|
assertEquals(new BigDecimal("100.50"), result.getInvoiceableAmount());
|
||||||
|
|
||||||
|
verify(organService).validOrgan(organId);
|
||||||
|
verify(purchaseService).getOrgEarliestProductDetail(organId);
|
||||||
|
verify(purchaseService).getInvoicingAmount(organId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockLoginUser(organId = 1L)
|
||||||
|
void testGetOrganProductOverview_initialPurchase() {
|
||||||
|
Long organId = SecurityFrameworkUtils.getUserOrganId();
|
||||||
|
|
||||||
|
PurchaseRecordDO record = new PurchaseRecordDO();
|
||||||
|
record.setEndTime(LocalDate.of(2025, 1, 1));
|
||||||
|
record.setInitial(true);
|
||||||
|
|
||||||
|
OrgEarliestPurchaseProductRespVO resp = new OrgEarliestPurchaseProductRespVO(record);
|
||||||
|
|
||||||
|
when(purchaseService.getOrgEarliestProductDetail(organId))
|
||||||
|
.thenReturn(resp);
|
||||||
|
when(purchaseService.getInvoicingAmount(organId))
|
||||||
|
.thenReturn(BigDecimal.ZERO);
|
||||||
|
|
||||||
|
OrganProductOverviewRespVO result = organAmountService.getOrganProductOverview();
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertNull(result.getDuration());
|
||||||
|
assertNull(result.getDurationUnit());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetOrganAmountAll() {
|
||||||
|
// given
|
||||||
|
TotalSalesAmountRespVO totalSales = new TotalSalesAmountRespVO(new BigDecimal("9999.99"));
|
||||||
|
|
||||||
|
when(purchaseService.getTotalSales()).thenReturn(totalSales);
|
||||||
|
|
||||||
|
InvoiceAmountRespVO invoiceAmount = new InvoiceAmountRespVO();
|
||||||
|
invoiceAmount.setPendingInvoice(new BigDecimal("123.45"));
|
||||||
|
|
||||||
|
when(invoiceService.getManageInvoiceAmount())
|
||||||
|
.thenReturn(invoiceAmount);
|
||||||
|
|
||||||
|
// when
|
||||||
|
ManageAmountOverviewRespVO result = organAmountService.getOrganAmountAll();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(new BigDecimal("9999.99"), result.getTotalSalesAmount());
|
||||||
|
assertEquals(new BigDecimal("123.45"), result.getToExamineAmount());
|
||||||
|
|
||||||
|
verify(purchaseService).getTotalSales();
|
||||||
|
verify(invoiceService).getManageInvoiceAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithMockLoginUser(organId = 1L)
|
||||||
|
void should_return_consumption_trend_with_zero_filling() {
|
||||||
|
Long organId = SecurityFrameworkUtils.getUserOrganId();
|
||||||
|
|
||||||
|
OrganFundsStatisticsReqVO reqVO = new OrganFundsStatisticsReqVO();
|
||||||
|
reqVO.setUnit(StatisticsUnit.DAY.getValue());
|
||||||
|
reqVO.setCreateTime(new LocalDate[]{
|
||||||
|
LocalDate.now().minusDays(2),
|
||||||
|
LocalDate.now().plusDays(1)
|
||||||
|
});
|
||||||
|
|
||||||
|
IncomeExpenseDetailsDO pojo1 = randomPojo(IncomeExpenseDetailsDO.class, o -> {
|
||||||
|
o.setOrganId(organId);
|
||||||
|
o.setAmount(new BigDecimal("100"));
|
||||||
|
o.setCreateTime(LocalDateTime.now().minusDays(2));
|
||||||
|
});
|
||||||
|
IncomeExpenseDetailsDO pojo2 = randomPojo(IncomeExpenseDetailsDO.class, o -> {
|
||||||
|
o.setOrganId(organId);
|
||||||
|
o.setAmount(new BigDecimal("200"));
|
||||||
|
o.setCreateTime(LocalDateTime.now());
|
||||||
|
});
|
||||||
|
IncomeExpenseDetailsDO pojo3 = randomPojo(IncomeExpenseDetailsDO.class, o -> {
|
||||||
|
o.setAmount(new BigDecimal("200"));
|
||||||
|
o.setCreateTime(LocalDateTime.now());
|
||||||
|
});
|
||||||
|
|
||||||
|
incomeExpenseDetailsMapper.insert(pojo1);
|
||||||
|
incomeExpenseDetailsMapper.insert(pojo2);
|
||||||
|
incomeExpenseDetailsMapper.insert(pojo3);
|
||||||
|
|
||||||
|
// when query org
|
||||||
|
Map<String, Object> result =
|
||||||
|
organAmountService.getConsumptionTrend(reqVO, true);
|
||||||
|
|
||||||
|
// then
|
||||||
|
List<?> xAxis = (List<?>) result.get("dateList");
|
||||||
|
List<?> series = (List<?>) result.get("series");
|
||||||
|
|
||||||
|
assertEquals(4, xAxis.size());
|
||||||
|
|
||||||
|
Map<?, ?> seriesItem = (Map<?, ?>) series.get(0);
|
||||||
|
BigDecimal[] data = (BigDecimal[]) seriesItem.get("data");
|
||||||
|
|
||||||
|
assertArrayEquals(
|
||||||
|
new BigDecimal[]{
|
||||||
|
new BigDecimal("100.00"),
|
||||||
|
BigDecimal.ZERO,
|
||||||
|
new BigDecimal("200.00"),
|
||||||
|
BigDecimal.ZERO,
|
||||||
|
},
|
||||||
|
data
|
||||||
|
);
|
||||||
|
|
||||||
|
// when not query org
|
||||||
|
result = organAmountService.getConsumptionTrend(reqVO, false);
|
||||||
|
|
||||||
|
// then
|
||||||
|
xAxis = (List<?>) result.get("dateList");
|
||||||
|
series = (List<?>) result.get("series");
|
||||||
|
|
||||||
|
assertEquals(4, xAxis.size());
|
||||||
|
|
||||||
|
seriesItem = (Map<?, ?>) series.get(0);
|
||||||
|
data = (BigDecimal[]) seriesItem.get("data");
|
||||||
|
|
||||||
|
assertArrayEquals(
|
||||||
|
new BigDecimal[]{
|
||||||
|
new BigDecimal("100.00"),
|
||||||
|
BigDecimal.ZERO,
|
||||||
|
new BigDecimal("400.00"),
|
||||||
|
BigDecimal.ZERO,
|
||||||
|
},
|
||||||
|
data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1135
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user