|
|
@@ -2,15 +2,13 @@ package com.ruoyi.web.modules.industryservice.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
4
|
4
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
5
|
|
-import static org.mockito.ArgumentMatchers.eq;
|
|
6
|
5
|
import static org.mockito.ArgumentMatchers.any;
|
|
7
|
|
-import static org.mockito.ArgumentMatchers.anyList;
|
|
|
6
|
+import static org.mockito.ArgumentMatchers.anyInt;
|
|
|
7
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
8
|
8
|
import static org.mockito.Mockito.lenient;
|
|
9
|
9
|
import static org.mockito.Mockito.when;
|
|
10
|
10
|
|
|
11
|
11
|
import java.math.BigDecimal;
|
|
12
|
|
-import java.time.Year;
|
|
13
|
|
-import java.util.Arrays;
|
|
14
|
12
|
import java.util.Collections;
|
|
15
|
13
|
import org.junit.jupiter.api.DisplayName;
|
|
16
|
14
|
import org.junit.jupiter.api.Test;
|
|
|
@@ -19,11 +17,14 @@ import org.mockito.InjectMocks;
|
|
19
|
17
|
import org.mockito.Mock;
|
|
20
|
18
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
21
|
19
|
import com.ruoyi.common.exception.ServiceException;
|
|
22
|
|
-import com.ruoyi.web.modules.industryservice.BreedingIndustryTestSamples;
|
|
23
|
20
|
import com.ruoyi.web.modules.industryservice.domain.vo.BreedingIndustryDashboardVo;
|
|
24
|
21
|
import com.ruoyi.web.modules.industryservice.mapper.BreedingIndustryStatsMapper;
|
|
25
|
22
|
import com.ruoyi.web.modules.industryservice.support.BreedingIndustryPastureScope;
|
|
26
|
23
|
import com.ruoyi.web.modules.industryservice.support.BreedingIndustryRules;
|
|
|
24
|
+import com.ruoyi.web.modules.screen.domain.dto.HomeScreenHerdCowAgeSumDto;
|
|
|
25
|
+import com.ruoyi.web.modules.screen.domain.dto.HomeScreenHerdGenderSumDto;
|
|
|
26
|
+import com.ruoyi.web.modules.screen.domain.dto.HomeScreenStatPeriodDto;
|
|
|
27
|
+import com.ruoyi.web.modules.screen.domain.dto.HomeScreenYearMonthBullCowDto;
|
|
27
|
28
|
import com.ruoyi.web.modules.screen.mapper.HomeScreenStatsMapper;
|
|
28
|
29
|
|
|
29
|
30
|
@ExtendWith(MockitoExtension.class)
|
|
|
@@ -43,65 +44,81 @@ class BreedingIndustryDashboardServiceImplTest
|
|
43
|
44
|
private BreedingIndustryDashboardServiceImpl service;
|
|
44
|
45
|
|
|
45
|
46
|
@Test
|
|
46
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-002 可见牧场为空")
|
|
|
47
|
+ @DisplayName("ZCZX-YZCYSJ-UT-002 可见牧场为空仍返回填报趋势")
|
|
47
|
48
|
void ut002_emptyScope()
|
|
48
|
49
|
{
|
|
49
|
|
- int currentYear = Year.now().getValue();
|
|
50
|
50
|
stubGrassland();
|
|
51
|
|
- stubReportOverviewSums(currentYear, 100, 50, 20);
|
|
|
51
|
+ stubNoHerdReport();
|
|
52
|
52
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds()).thenReturn(Collections.emptyList());
|
|
53
|
53
|
BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
54
|
|
- assertEquals(100, vo.getOverview().getInventoryTotal());
|
|
55
|
|
- assertEquals(50, vo.getOverview().getAnnualOutbound());
|
|
56
|
|
- assertEquals(20, vo.getOverview().getPastureCount());
|
|
57
|
|
- assertEquals(3, vo.getOverview().getGrasslandCount());
|
|
58
|
|
- assertEquals(0, vo.getInventoryChange().getMonthlyTrend().size());
|
|
|
54
|
+ assertEquals(0, vo.getOverview().getInventoryTotal());
|
|
|
55
|
+ assertEquals(0, vo.getInventoryChange().getBullCount());
|
|
|
56
|
+ assertEquals(0, vo.getInventoryChange().getCowCount());
|
|
|
57
|
+ assertEquals(0, vo.getInventoryChange().getUnknownGenderCount());
|
|
|
58
|
+ assertEquals(12, vo.getInventoryChange().getMonthlyTrend().size());
|
|
|
59
|
+ assertEquals(4, vo.getAgeStructure().size());
|
|
59
|
60
|
}
|
|
60
|
61
|
|
|
61
|
62
|
@Test
|
|
62
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-028 产业总览三项与大屏填报口径一致")
|
|
63
|
|
- void ut028_overviewFromReportTables()
|
|
|
63
|
+ @DisplayName("ZCZX-YZCYSJ-UT-028 产业总览与存栏取自最近填报年月")
|
|
|
64
|
+ void ut028_overviewFromLatestReport()
|
|
64
|
65
|
{
|
|
65
|
|
- int currentYear = Year.now().getValue();
|
|
66
|
66
|
stubGrassland();
|
|
67
|
|
- stubReportOverviewSums(currentYear, 50000, 3200, 8988);
|
|
|
67
|
+ HomeScreenStatPeriodDto herd = period(2025, 12);
|
|
|
68
|
+ HomeScreenStatPeriodDto outbound = period(2026, 5);
|
|
|
69
|
+ when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriod()).thenReturn(herd);
|
|
|
70
|
+ when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriod()).thenReturn(outbound);
|
|
|
71
|
+ when(homeScreenStatsMapper.sumHerdInventoryYakTotalByStatYearMonth(2025, 12)).thenReturn(50000);
|
|
|
72
|
+ when(homeScreenStatsMapper.sumOutboundReportYakCountByStatYearMonth(2026, 5)).thenReturn(3200);
|
|
|
73
|
+ when(homeScreenStatsMapper.sumOutboundReportFarmerHouseholdCountByStatYearMonth(2026, 5)).thenReturn(8988);
|
|
|
74
|
+ stubHerdInventoryBlock(herd, 100, 200);
|
|
68
|
75
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
69
|
|
- .thenReturn(Collections.singletonList(BreedingIndustryTestSamples.PASTURE_P1));
|
|
70
|
|
- when(breedingIndustryStatsMapper.countPastureInScope(anyList())).thenReturn(12);
|
|
71
|
|
- when(breedingIndustryStatsMapper.countInventory(anyList())).thenReturn(3);
|
|
72
|
|
- when(breedingIndustryStatsMapper.countAnnualOutbound(anyList(), any(), any())).thenReturn(8);
|
|
73
|
|
- when(breedingIndustryStatsMapper.countWarningYak(anyList(), any(), any())).thenReturn(0);
|
|
74
|
|
- when(breedingIndustryStatsMapper.selectYakSnapshotsInScope(anyList()))
|
|
75
|
|
- .thenReturn(Collections.singletonList(BreedingIndustryTestSamples.normalBull()));
|
|
|
76
|
+ .thenReturn(Collections.singletonList(1L));
|
|
|
77
|
+ when(breedingIndustryStatsMapper.countWarningYak(any(), any(), any())).thenReturn(0);
|
|
76
|
78
|
|
|
77
|
79
|
BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
78
|
80
|
|
|
79
|
81
|
assertEquals(50000, vo.getOverview().getInventoryTotal());
|
|
80
|
82
|
assertEquals(3200, vo.getOverview().getAnnualOutbound());
|
|
81
|
83
|
assertEquals(8988, vo.getOverview().getPastureCount());
|
|
|
84
|
+ assertEquals(100, vo.getInventoryChange().getBullCount());
|
|
|
85
|
+ assertEquals(200, vo.getInventoryChange().getCowCount());
|
|
|
86
|
+ assertEquals(0, vo.getInventoryChange().getUnknownGenderCount());
|
|
|
87
|
+ assertEquals(12, vo.getInventoryChange().getMonthlyTrend().size());
|
|
|
88
|
+ assertEquals(4, vo.getAgeStructure().size());
|
|
82
|
89
|
}
|
|
83
|
90
|
|
|
84
|
91
|
@Test
|
|
85
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-009 公母未标=原存栏时点总量")
|
|
86
|
|
- void ut009_genderSum()
|
|
|
92
|
+ @DisplayName("ZCZX-YZCYSJ-UT-009 公母牛取自填报无未标注")
|
|
|
93
|
+ void ut009_genderFromReport()
|
|
87
|
94
|
{
|
|
88
|
|
- int currentYear = Year.now().getValue();
|
|
89
|
95
|
stubGrassland();
|
|
90
|
|
- stubReportOverviewSums(currentYear, 0, 0, 0);
|
|
|
96
|
+ HomeScreenStatPeriodDto herd = period(2026, 7);
|
|
|
97
|
+ when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriod()).thenReturn(herd);
|
|
|
98
|
+ when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriod()).thenReturn(null);
|
|
|
99
|
+ when(homeScreenStatsMapper.sumHerdInventoryYakTotalByStatYearMonth(2026, 7)).thenReturn(350);
|
|
|
100
|
+ HomeScreenHerdGenderSumDto gender = new HomeScreenHerdGenderSumDto();
|
|
|
101
|
+ gender.setBullTotal(120);
|
|
|
102
|
+ gender.setCowTotal(230);
|
|
|
103
|
+ gender.setYakTotal(350);
|
|
|
104
|
+ when(homeScreenStatsMapper.sumHerdInventoryGenderByStatYearMonth(2026, 7)).thenReturn(gender);
|
|
|
105
|
+ HomeScreenHerdCowAgeSumDto age = new HomeScreenHerdCowAgeSumDto();
|
|
|
106
|
+ age.setCowUnder1Count(10);
|
|
|
107
|
+ age.setCow13Count(20);
|
|
|
108
|
+ age.setCow312Count(30);
|
|
|
109
|
+ age.setCowOver12Count(40);
|
|
|
110
|
+ when(homeScreenStatsMapper.sumHerdInventoryCowAgeByStatYearMonth(2026, 7)).thenReturn(age);
|
|
|
111
|
+ when(homeScreenStatsMapper.selectHerdInventoryBullCowByYearMonthRange(anyInt(), anyInt()))
|
|
|
112
|
+ .thenReturn(Collections.emptyList());
|
|
91
|
113
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
92
|
|
- .thenReturn(Collections.singletonList(BreedingIndustryTestSamples.PASTURE_P1));
|
|
93
|
|
- when(breedingIndustryStatsMapper.countPastureInScope(anyList())).thenReturn(1);
|
|
94
|
|
- when(breedingIndustryStatsMapper.countInventory(anyList())).thenReturn(3);
|
|
95
|
|
- when(breedingIndustryStatsMapper.countAnnualOutbound(anyList(), any(), any())).thenReturn(0);
|
|
96
|
|
- when(breedingIndustryStatsMapper.countWarningYak(anyList(), any(), any())).thenReturn(0);
|
|
97
|
|
- when(breedingIndustryStatsMapper.selectYakSnapshotsInScope(anyList())).thenReturn(Arrays.asList(
|
|
98
|
|
- BreedingIndustryTestSamples.normalBull(),
|
|
99
|
|
- BreedingIndustryTestSamples.normalCow(),
|
|
100
|
|
- BreedingIndustryTestSamples.unknownGender()));
|
|
|
114
|
+ .thenReturn(Collections.singletonList(1L));
|
|
|
115
|
+ when(breedingIndustryStatsMapper.countWarningYak(any(), any(), any())).thenReturn(0);
|
|
|
116
|
+
|
|
101
|
117
|
BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
102
|
|
- assertEquals(1, vo.getInventoryChange().getBullCount());
|
|
103
|
|
- assertEquals(1, vo.getInventoryChange().getCowCount());
|
|
104
|
|
- assertEquals(1, vo.getInventoryChange().getUnknownGenderCount());
|
|
|
118
|
+
|
|
|
119
|
+ assertEquals(120, vo.getInventoryChange().getBullCount());
|
|
|
120
|
+ assertEquals(230, vo.getInventoryChange().getCowCount());
|
|
|
121
|
+ assertEquals(0, vo.getInventoryChange().getUnknownGenderCount());
|
|
105
|
122
|
}
|
|
106
|
123
|
|
|
107
|
124
|
@Test
|
|
|
@@ -114,6 +131,42 @@ class BreedingIndustryDashboardServiceImplTest
|
|
114
|
131
|
assertEquals(BreedingIndustryRules.MSG_LOAD_FAILED, ex.getMessage());
|
|
115
|
132
|
}
|
|
116
|
133
|
|
|
|
134
|
+ private static HomeScreenStatPeriodDto period(int year, int month)
|
|
|
135
|
+ {
|
|
|
136
|
+ HomeScreenStatPeriodDto dto = new HomeScreenStatPeriodDto();
|
|
|
137
|
+ dto.setStatYear(year);
|
|
|
138
|
+ dto.setStatMonth(month);
|
|
|
139
|
+ return dto;
|
|
|
140
|
+ }
|
|
|
141
|
+
|
|
|
142
|
+ private void stubNoHerdReport()
|
|
|
143
|
+ {
|
|
|
144
|
+ when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriod()).thenReturn(null);
|
|
|
145
|
+ when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriod()).thenReturn(null);
|
|
|
146
|
+ when(homeScreenStatsMapper.selectHerdInventoryBullCowByYearMonthRange(anyInt(), anyInt()))
|
|
|
147
|
+ .thenReturn(Collections.emptyList());
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
|
150
|
+ private void stubHerdInventoryBlock(HomeScreenStatPeriodDto herd, int bull, int cow)
|
|
|
151
|
+ {
|
|
|
152
|
+ HomeScreenHerdGenderSumDto gender = new HomeScreenHerdGenderSumDto();
|
|
|
153
|
+ gender.setBullTotal(bull);
|
|
|
154
|
+ gender.setCowTotal(cow);
|
|
|
155
|
+ gender.setYakTotal(bull + cow);
|
|
|
156
|
+ when(homeScreenStatsMapper.sumHerdInventoryGenderByStatYearMonth(
|
|
|
157
|
+ eq(herd.getStatYear()), eq(herd.getStatMonth()))).thenReturn(gender);
|
|
|
158
|
+ HomeScreenHerdCowAgeSumDto age = new HomeScreenHerdCowAgeSumDto();
|
|
|
159
|
+ when(homeScreenStatsMapper.sumHerdInventoryCowAgeByStatYearMonth(
|
|
|
160
|
+ eq(herd.getStatYear()), eq(herd.getStatMonth()))).thenReturn(age);
|
|
|
161
|
+ HomeScreenYearMonthBullCowDto row = new HomeScreenYearMonthBullCowDto();
|
|
|
162
|
+ row.setStatYear(herd.getStatYear());
|
|
|
163
|
+ row.setStatMonth(herd.getStatMonth());
|
|
|
164
|
+ row.setBullCount(bull);
|
|
|
165
|
+ row.setCowCount(cow);
|
|
|
166
|
+ when(homeScreenStatsMapper.selectHerdInventoryBullCowByYearMonthRange(anyInt(), anyInt()))
|
|
|
167
|
+ .thenReturn(Collections.singletonList(row));
|
|
|
168
|
+ }
|
|
|
169
|
+
|
|
117
|
170
|
private void stubGrassland()
|
|
118
|
171
|
{
|
|
119
|
172
|
when(breedingIndustryStatsMapper.countGrassland()).thenReturn(3);
|
|
|
@@ -122,14 +175,4 @@ class BreedingIndustryDashboardServiceImplTest
|
|
122
|
175
|
when(breedingIndustryStatsMapper.countInUseGrassland(any())).thenReturn(1);
|
|
123
|
176
|
when(breedingIndustryStatsMapper.selectDegradationGroupCounts()).thenReturn(Collections.emptyList());
|
|
124
|
177
|
}
|
|
125
|
|
-
|
|
126
|
|
- private void stubReportOverviewSums(int currentYear, int inventory, int outbound, int farmerHousehold)
|
|
127
|
|
- {
|
|
128
|
|
- lenient().when(homeScreenStatsMapper.sumHerdInventoryYakTotalByStatYear(eq(currentYear - 1)))
|
|
129
|
|
- .thenReturn(inventory);
|
|
130
|
|
- lenient().when(homeScreenStatsMapper.sumOutboundReportYakCountByStatYear(eq(currentYear)))
|
|
131
|
|
- .thenReturn(outbound);
|
|
132
|
|
- lenient().when(homeScreenStatsMapper.sumOutboundReportFarmerHouseholdCountByStatYear(eq(currentYear)))
|
|
133
|
|
- .thenReturn(farmerHousehold);
|
|
134
|
|
- }
|
|
135
|
178
|
}
|