|
|
@@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
5
|
5
|
import static org.mockito.ArgumentMatchers.any;
|
|
6
|
6
|
import static org.mockito.ArgumentMatchers.anyInt;
|
|
7
|
7
|
import static org.mockito.ArgumentMatchers.eq;
|
|
8
|
|
-import static org.mockito.Mockito.lenient;
|
|
9
|
8
|
import static org.mockito.Mockito.when;
|
|
10
|
9
|
|
|
11
|
10
|
import java.math.BigDecimal;
|
|
|
@@ -21,11 +20,12 @@ import com.ruoyi.web.modules.industryservice.domain.vo.BreedingIndustryDashboard
|
|
21
|
20
|
import com.ruoyi.web.modules.industryservice.mapper.BreedingIndustryStatsMapper;
|
|
22
|
21
|
import com.ruoyi.web.modules.industryservice.support.BreedingIndustryPastureScope;
|
|
23
|
22
|
import com.ruoyi.web.modules.industryservice.support.BreedingIndustryRules;
|
|
24
|
|
-import com.ruoyi.web.modules.screen.domain.dto.HomeScreenHerdCowAgeSumDto;
|
|
|
23
|
+import com.ruoyi.web.modules.screen.domain.dto.HomeScreenHerdGenderMonthDto;
|
|
25
|
24
|
import com.ruoyi.web.modules.screen.domain.dto.HomeScreenHerdGenderSumDto;
|
|
|
25
|
+import com.ruoyi.web.modules.screen.domain.dto.HomeScreenHerdYakStructureSumDto;
|
|
26
|
26
|
import com.ruoyi.web.modules.screen.domain.dto.HomeScreenStatPeriodDto;
|
|
27
|
|
-import com.ruoyi.web.modules.screen.domain.dto.HomeScreenYearMonthBullCowDto;
|
|
28
|
27
|
import com.ruoyi.web.modules.screen.mapper.HomeScreenStatsMapper;
|
|
|
28
|
+import com.ruoyi.web.modules.screen.support.HomeScreenSupport;
|
|
29
|
29
|
|
|
30
|
30
|
@ExtendWith(MockitoExtension.class)
|
|
31
|
31
|
@DisplayName("BreedingIndustryDashboardServiceImpl")
|
|
|
@@ -44,79 +44,98 @@ class BreedingIndustryDashboardServiceImplTest
|
|
44
|
44
|
private BreedingIndustryDashboardServiceImpl service;
|
|
45
|
45
|
|
|
46
|
46
|
@Test
|
|
47
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-002 可见牧场为空仍返回填报趋势")
|
|
|
47
|
+ @DisplayName("ZCZX-YZCYSJ-UT-002 可见牧场为空仍返回填报口径")
|
|
48
|
48
|
void ut002_emptyScope()
|
|
49
|
49
|
{
|
|
50
|
50
|
stubGrassland();
|
|
51
|
|
- stubNoHerdReport();
|
|
|
51
|
+ stubNoHerdReport(2026);
|
|
52
|
52
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds()).thenReturn(Collections.emptyList());
|
|
53
|
|
- BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
|
53
|
+ BreedingIndustryDashboardVo vo = service.loadDashboard(false, "2026");
|
|
|
54
|
+ assertEquals(2026, vo.getStatYear());
|
|
54
|
55
|
assertEquals(0, vo.getOverview().getInventoryTotal());
|
|
55
|
56
|
assertEquals(0, vo.getInventoryChange().getBullCount());
|
|
56
|
57
|
assertEquals(0, vo.getInventoryChange().getCowCount());
|
|
57
|
58
|
assertEquals(0, vo.getInventoryChange().getUnknownGenderCount());
|
|
58
|
|
- assertEquals(12, vo.getInventoryChange().getMonthlyTrend().size());
|
|
59
|
|
- assertEquals(2, vo.getAgeStructure().size());
|
|
|
59
|
+ assertEquals(0, vo.getInventoryChange().getMonthlyTrend().size());
|
|
|
60
|
+ assertEquals(3, vo.getYakInventoryStructure().size());
|
|
|
61
|
+ assertEquals(HomeScreenSupport.YAK_CAT_BULL, vo.getYakInventoryStructure().get(0).getCategoryCode());
|
|
60
|
62
|
}
|
|
61
|
63
|
|
|
62
|
64
|
@Test
|
|
63
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-028 产业总览与存栏取自最近填报年月")
|
|
64
|
|
- void ut028_overviewFromLatestReport()
|
|
|
65
|
+ @DisplayName("ZCZX-YZCYSJ-UT-028 产业总览与存栏取自所选年最大填报月")
|
|
|
66
|
+ void ut028_overviewFromYearMaxMonth()
|
|
65
|
67
|
{
|
|
66
|
68
|
stubGrassland();
|
|
67
|
|
- HomeScreenStatPeriodDto herd = period(2025, 12);
|
|
|
69
|
+ HomeScreenStatPeriodDto herd = period(2026, 7);
|
|
68
|
70
|
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);
|
|
|
71
|
+ HomeScreenStatPeriodDto farmer = period(2026, 6);
|
|
|
72
|
+ when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriodByYear(2026)).thenReturn(herd);
|
|
|
73
|
+ when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriodByYear(2026)).thenReturn(outbound);
|
|
|
74
|
+ when(homeScreenStatsMapper.selectLatestFarmerHouseholdStatPeriodByYear(2026)).thenReturn(farmer);
|
|
|
75
|
+ when(homeScreenStatsMapper.sumHerdInventoryYakTotalByStatYearMonth(2026, 7)).thenReturn(50000);
|
|
72
|
76
|
when(homeScreenStatsMapper.sumOutboundReportYakCountByStatYearMonth(2026, 5)).thenReturn(3200);
|
|
73
|
|
- when(homeScreenStatsMapper.sumOutboundReportFarmerHouseholdCountByStatYearMonth(2026, 5)).thenReturn(8988);
|
|
|
77
|
+ when(homeScreenStatsMapper.sumFarmerHouseholdCountByStatYearMonth(2026, 6)).thenReturn(8988);
|
|
|
78
|
+ when(homeScreenStatsMapper.sumFarmerHouseholdPastureContractAreaByStatYearMonth(2026, 6))
|
|
|
79
|
+ .thenReturn(new BigDecimal("12500.50"));
|
|
74
|
80
|
stubHerdInventoryBlock(herd, 100, 200);
|
|
75
|
81
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
76
|
82
|
.thenReturn(Collections.singletonList(1L));
|
|
77
|
83
|
when(breedingIndustryStatsMapper.countWarningYak(any(), any(), any())).thenReturn(0);
|
|
78
|
84
|
|
|
79
|
|
- BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
|
85
|
+ BreedingIndustryDashboardVo vo = service.loadDashboard(false, "2026");
|
|
80
|
86
|
|
|
81
|
87
|
assertEquals(50000, vo.getOverview().getInventoryTotal());
|
|
82
|
88
|
assertEquals(3200, vo.getOverview().getAnnualOutbound());
|
|
83
|
89
|
assertEquals(8988, vo.getOverview().getPastureCount());
|
|
|
90
|
+ assertEquals(new BigDecimal("12500.50"), vo.getOverview().getGrasslandAreaMu());
|
|
84
|
91
|
assertEquals(100, vo.getInventoryChange().getBullCount());
|
|
85
|
92
|
assertEquals(200, vo.getInventoryChange().getCowCount());
|
|
86
|
93
|
assertEquals(0, vo.getInventoryChange().getUnknownGenderCount());
|
|
87
|
|
- assertEquals(12, vo.getInventoryChange().getMonthlyTrend().size());
|
|
88
|
|
- assertEquals(2, vo.getAgeStructure().size());
|
|
|
94
|
+ assertEquals(7, vo.getInventoryChange().getMonthlyTrend().size());
|
|
|
95
|
+ assertEquals(3, vo.getYakInventoryStructure().size());
|
|
89
|
96
|
}
|
|
90
|
97
|
|
|
91
|
98
|
@Test
|
|
92
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-009 公母牛取自填报无未标注")
|
|
93
|
|
- void ut009_genderFromReport()
|
|
|
99
|
+ @DisplayName("ZCZX-YZCYSJ-UT-009 公母牛取自填报;存栏结构与大屏一致")
|
|
|
100
|
+ void ut009_genderAndYakStructureFromReport()
|
|
94
|
101
|
{
|
|
95
|
102
|
stubGrassland();
|
|
96
|
103
|
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);
|
|
|
104
|
+ when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriodByYear(2026)).thenReturn(herd);
|
|
|
105
|
+ when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriodByYear(2026)).thenReturn(null);
|
|
|
106
|
+ when(homeScreenStatsMapper.selectLatestFarmerHouseholdStatPeriodByYear(2026)).thenReturn(null);
|
|
|
107
|
+ when(homeScreenStatsMapper.sumHerdInventoryYakTotalByStatYearMonth(2026, 7)).thenReturn(360);
|
|
100
|
108
|
HomeScreenHerdGenderSumDto gender = new HomeScreenHerdGenderSumDto();
|
|
101
|
109
|
gender.setBullTotal(120);
|
|
102
|
110
|
gender.setCowTotal(230);
|
|
103
|
|
- gender.setYakTotal(350);
|
|
|
111
|
+ gender.setYakTotal(360);
|
|
104
|
112
|
when(homeScreenStatsMapper.sumHerdInventoryGenderByStatYearMonth(2026, 7)).thenReturn(gender);
|
|
105
|
|
- HomeScreenHerdCowAgeSumDto age = new HomeScreenHerdCowAgeSumDto();
|
|
106
|
|
- age.setCowYoungCount(40);
|
|
107
|
|
- age.setCowAdultCount(60);
|
|
108
|
|
- when(homeScreenStatsMapper.sumHerdInventoryCowAgeByStatYearMonth(2026, 7)).thenReturn(age);
|
|
109
|
|
- when(homeScreenStatsMapper.selectHerdInventoryBullCowByYearMonthRange(anyInt(), anyInt()))
|
|
|
113
|
+ HomeScreenHerdYakStructureSumDto structure = new HomeScreenHerdYakStructureSumDto();
|
|
|
114
|
+ structure.setBreedingBullCount(50);
|
|
|
115
|
+ structure.setBullCastratedCount(70);
|
|
|
116
|
+ structure.setCowYoungCount(80);
|
|
|
117
|
+ structure.setCowAdultCount(150);
|
|
|
118
|
+ structure.setInsuredYakCount(10);
|
|
|
119
|
+ when(homeScreenStatsMapper.sumHerdInventoryYakStructureByStatYearMonth(2026, 7)).thenReturn(structure);
|
|
|
120
|
+ when(homeScreenStatsMapper.selectHerdInventoryBullCowByMonth(2026))
|
|
110
|
121
|
.thenReturn(Collections.emptyList());
|
|
111
|
122
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
112
|
123
|
.thenReturn(Collections.singletonList(1L));
|
|
113
|
124
|
when(breedingIndustryStatsMapper.countWarningYak(any(), any(), any())).thenReturn(0);
|
|
114
|
125
|
|
|
115
|
|
- BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
|
126
|
+ BreedingIndustryDashboardVo vo = service.loadDashboard(false, "2026");
|
|
116
|
127
|
|
|
117
|
128
|
assertEquals(120, vo.getInventoryChange().getBullCount());
|
|
118
|
129
|
assertEquals(230, vo.getInventoryChange().getCowCount());
|
|
119
|
|
- assertEquals(0, vo.getInventoryChange().getUnknownGenderCount());
|
|
|
130
|
+ assertEquals(10, vo.getInventoryChange().getUnknownGenderCount());
|
|
|
131
|
+ assertEquals(0, vo.getInventoryChange().getMonthlyTrend().size());
|
|
|
132
|
+ assertEquals(HomeScreenSupport.YAK_CAT_BULL, vo.getYakInventoryStructure().get(0).getCategoryCode());
|
|
|
133
|
+ assertEquals(120, vo.getYakInventoryStructure().get(0).getCount());
|
|
|
134
|
+ assertEquals(HomeScreenSupport.YAK_CAT_COW, vo.getYakInventoryStructure().get(1).getCategoryCode());
|
|
|
135
|
+ assertEquals(230, vo.getYakInventoryStructure().get(1).getCount());
|
|
|
136
|
+ assertEquals(10, vo.getYakInventoryStructure().get(2).getCount());
|
|
|
137
|
+ assertEquals("种公牛", vo.getYakInventoryStructure().get(0).getDetails().get(0).getDetailLabel());
|
|
|
138
|
+ assertEquals(50, vo.getYakInventoryStructure().get(0).getDetails().get(0).getCount());
|
|
120
|
139
|
}
|
|
121
|
140
|
|
|
122
|
141
|
@Test
|
|
|
@@ -125,7 +144,7 @@ class BreedingIndustryDashboardServiceImplTest
|
|
125
|
144
|
{
|
|
126
|
145
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
127
|
146
|
.thenThrow(new RuntimeException("db"));
|
|
128
|
|
- ServiceException ex = assertThrows(ServiceException.class, () -> service.loadDashboard(false));
|
|
|
147
|
+ ServiceException ex = assertThrows(ServiceException.class, () -> service.loadDashboard(false, "2026"));
|
|
129
|
148
|
assertEquals(BreedingIndustryRules.MSG_LOAD_FAILED, ex.getMessage());
|
|
130
|
149
|
}
|
|
131
|
150
|
|
|
|
@@ -137,11 +156,12 @@ class BreedingIndustryDashboardServiceImplTest
|
|
137
|
156
|
return dto;
|
|
138
|
157
|
}
|
|
139
|
158
|
|
|
140
|
|
- private void stubNoHerdReport()
|
|
|
159
|
+ private void stubNoHerdReport(int year)
|
|
141
|
160
|
{
|
|
142
|
|
- when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriod()).thenReturn(null);
|
|
143
|
|
- when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriod()).thenReturn(null);
|
|
144
|
|
- when(homeScreenStatsMapper.selectHerdInventoryBullCowByYearMonthRange(anyInt(), anyInt()))
|
|
|
161
|
+ when(homeScreenStatsMapper.selectLatestHerdInventoryStatPeriodByYear(year)).thenReturn(null);
|
|
|
162
|
+ when(homeScreenStatsMapper.selectLatestOutboundReportStatPeriodByYear(year)).thenReturn(null);
|
|
|
163
|
+ when(homeScreenStatsMapper.selectLatestFarmerHouseholdStatPeriodByYear(year)).thenReturn(null);
|
|
|
164
|
+ when(homeScreenStatsMapper.selectHerdInventoryBullCowByMonth(year))
|
|
145
|
165
|
.thenReturn(Collections.emptyList());
|
|
146
|
166
|
}
|
|
147
|
167
|
|
|
|
@@ -153,22 +173,20 @@ class BreedingIndustryDashboardServiceImplTest
|
|
153
|
173
|
gender.setYakTotal(bull + cow);
|
|
154
|
174
|
when(homeScreenStatsMapper.sumHerdInventoryGenderByStatYearMonth(
|
|
155
|
175
|
eq(herd.getStatYear()), eq(herd.getStatMonth()))).thenReturn(gender);
|
|
156
|
|
- HomeScreenHerdCowAgeSumDto age = new HomeScreenHerdCowAgeSumDto();
|
|
157
|
|
- when(homeScreenStatsMapper.sumHerdInventoryCowAgeByStatYearMonth(
|
|
158
|
|
- eq(herd.getStatYear()), eq(herd.getStatMonth()))).thenReturn(age);
|
|
159
|
|
- HomeScreenYearMonthBullCowDto row = new HomeScreenYearMonthBullCowDto();
|
|
160
|
|
- row.setStatYear(herd.getStatYear());
|
|
161
|
|
- row.setStatMonth(herd.getStatMonth());
|
|
|
176
|
+ when(homeScreenStatsMapper.sumHerdInventoryYakStructureByStatYearMonth(
|
|
|
177
|
+ eq(herd.getStatYear()), eq(herd.getStatMonth())))
|
|
|
178
|
+ .thenReturn(new HomeScreenHerdYakStructureSumDto());
|
|
|
179
|
+ HomeScreenHerdGenderMonthDto row = new HomeScreenHerdGenderMonthDto();
|
|
|
180
|
+ row.setMonth(herd.getStatMonth());
|
|
162
|
181
|
row.setBullCount(bull);
|
|
163
|
182
|
row.setCowCount(cow);
|
|
164
|
|
- when(homeScreenStatsMapper.selectHerdInventoryBullCowByYearMonthRange(anyInt(), anyInt()))
|
|
|
183
|
+ when(homeScreenStatsMapper.selectHerdInventoryBullCowByMonth(anyInt()))
|
|
165
|
184
|
.thenReturn(Collections.singletonList(row));
|
|
166
|
185
|
}
|
|
167
|
186
|
|
|
168
|
187
|
private void stubGrassland()
|
|
169
|
188
|
{
|
|
170
|
189
|
when(breedingIndustryStatsMapper.countGrassland()).thenReturn(3);
|
|
171
|
|
- when(breedingIndustryStatsMapper.sumGrasslandAreaMu()).thenReturn(new BigDecimal("100.00"));
|
|
172
|
190
|
when(breedingIndustryStatsMapper.countAvailableGrassland()).thenReturn(2);
|
|
173
|
191
|
when(breedingIndustryStatsMapper.countInUseGrassland(any())).thenReturn(1);
|
|
174
|
192
|
when(breedingIndustryStatsMapper.selectDegradationGroupCounts()).thenReturn(Collections.emptyList());
|