package com.ruoyi.web.modules.screen.controller;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenDashboardVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenCooperativeDevelopmentListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenFamilyRanchListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenFarmerHouseholdListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenImbalanceWarningListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenIndustryOverviewVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenLargeLivestockFarmerListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenLivestockOwnershipHouseholdListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenPerCapitaIncomeListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenYakHerdInventoryListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenBreedingEntityQuantityListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenYakInventoryOutboundListItemVo;
import com.ruoyi.web.modules.screen.domain.vo.HomeScreenYakOutboundReportListItemVo;
import com.ruoyi.web.modules.screen.service.IHomeScreenService;

/**
 * DP-SY-API-001～020
 */
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@DisplayName("大屏首页 HTTP 接口 MockMvc")
class HomeScreenControllerApiTest
{

    @Mock
    private IHomeScreenService homeScreenService;

    @InjectMocks
    private HomeScreenController controller;

    private MockMvc mockMvc;

    @BeforeEach
    void setUp()
    {
        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
        loginAsAllPermissions();
    }

    @AfterEach
    void tearDown()
    {
        SecurityContextHolder.clearContext();
        PageHelper.clearPage();
    }

    @Test
    @DisplayName("DP-SY-API-001 GET dashboard 有数据")
    void api001_dashboard() throws Exception
    {
        when(homeScreenService.loadDashboard("2026")).thenReturn(sampleDashboard());
        mockMvc.perform(get("/bigScreen/home/dashboard").param("statYear", "2026"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.data.statYear").value(2026))
                .andExpect(jsonPath("$.data.industryOverview.inventoryTotal").value(10));
    }

    @Test
    @DisplayName("DP-SY-API-019 statYear 回显")
    void api019_statYearEcho() throws Exception
    {
        HomeScreenDashboardVo vo = sampleDashboard();
        vo.setStatYear(2025);
        when(homeScreenService.loadDashboard("2025")).thenReturn(vo);
        mockMvc.perform(get("/bigScreen/home/dashboard").param("statYear", "2025"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.data.statYear").value(2025));
    }

    @Test
    @DisplayName("DP-SY-API-023 GET standards 分页")
    void api023_standards() throws Exception
    {
        when(homeScreenService.listStandards(eq("2026"), eq("BREEDING_MGMT")))
                .thenReturn(Collections.emptyList());
        mockMvc.perform(get("/bigScreen/home/standards")
                        .param("statYear", "2026")
                        .param("category", "BREEDING_MGMT")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200));
    }

    @Test
    @DisplayName("DP-SY-API-038 GET townMapMarkers 地图标注")
    void api024_townMapMarkers() throws Exception
    {
        when(homeScreenService.loadTownMapMarkers("2026")).thenReturn(sampleTownMap());
        mockMvc.perform(get("/bigScreen/home/townMapMarkers").param("statYear", "2026"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.data.herdStatYear").value(2026))
                .andExpect(jsonPath("$.data.herdStatMonth").value(12))
                .andExpect(jsonPath("$.data.outboundStatYear").value(2026))
                .andExpect(jsonPath("$.data.outboundStatMonth").value(5))
                .andExpect(jsonPath("$.data.markers[0].townDeptId").value(101))
                .andExpect(jsonPath("$.data.markers[0].townName").value("巴青乡"))
                .andExpect(jsonPath("$.data.markers[0].yakInventoryCount").value(21587))
                .andExpect(jsonPath("$.data.markers[0].yakOutboundCount").value(1523));
    }

    @Test
    @DisplayName("DP-SY-API-039 GET grassLivestockImbalanceWarnings 分页明细")
    void api039_grassLivestockImbalanceWarnings() throws Exception
    {
        HomeScreenImbalanceWarningListItemVo item = new HomeScreenImbalanceWarningListItemVo();
        item.setStatYear(2026);
        item.setStatMonth(3);
        item.setTownName("巴青镇");
        item.setVillageName("某村");
        item.setSubjectName("某某牧场");
        item.setSubjectType("家庭牧场");
        item.setSubjectTypeCode("family_ranch");
        item.setApprovedCarryingCapacity(new BigDecimal("100"));
        item.setYearEndStockSheepUnit(new BigDecimal("120"));
        item.setIsGrassBalanced("否");
        when(homeScreenService.listGrassLivestockImbalanceWarnings(eq(2026), eq(3), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/grassLivestockImbalanceWarnings")
                        .param("statYear", "2026")
                        .param("statMonth", "3")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].statYear").value(2026))
                .andExpect(jsonPath("$.rows[0].subjectType").value("家庭牧场"))
                .andExpect(jsonPath("$.rows[0].isGrassBalanced").value("否"));
    }

    @Test
    @DisplayName("DP-SY-API-040 GET perCapitaIncomes 人均收入明细")
    void api040_perCapitaIncomes() throws Exception
    {
        HomeScreenPerCapitaIncomeListItemVo item = new HomeScreenPerCapitaIncomeListItemVo();
        item.setStatYear(2026);
        item.setRuralDisposableIncome(new BigDecimal("22190"));
        item.setIncomeIncrease(new BigDecimal("1460"));
        item.setIncomeGrowthRate(new BigDecimal("7.04"));
        item.setPovertyNetIncome(new BigDecimal("9800"));
        when(homeScreenService.listPerCapitaIncomes(eq(2026))).thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/perCapitaIncomes")
                        .param("statYear", "2026")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].statYear").value(2026))
                .andExpect(jsonPath("$.rows[0].ruralDisposableIncome").value(22190))
                .andExpect(jsonPath("$.rows[0].incomeIncrease").value(1460))
                .andExpect(jsonPath("$.rows[0].incomeGrowthRate").value(7.04))
                .andExpect(jsonPath("$.rows[0].povertyNetIncome").value(9800));
    }

    @Test
    @DisplayName("DP-SY-API-041 GET farmerHouseholds 农牧户明细")
    void api041_farmerHouseholds() throws Exception
    {
        HomeScreenFarmerHouseholdListItemVo item = new HomeScreenFarmerHouseholdListItemVo();
        item.setId(1L);
        item.setStatYear(2026);
        item.setStatMonth(3);
        item.setTownDeptId(101L);
        item.setTownName("巴青镇");
        item.setVillageDeptId(201L);
        item.setVillageName("某村");
        item.setHouseholdCount(10);
        item.setPopulationCount(30);
        item.setPastureContractArea(new BigDecimal("100.5"));
        when(homeScreenService.listFarmerHouseholds(eq(2026), eq(3), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/farmerHouseholds")
                        .param("statYear", "2026")
                        .param("statMonth", "3")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].statYear").value(2026))
                .andExpect(jsonPath("$.rows[0].statMonth").value(3))
                .andExpect(jsonPath("$.rows[0].townName").value("巴青镇"))
                .andExpect(jsonPath("$.rows[0].villageName").value("某村"))
                .andExpect(jsonPath("$.rows[0].householdCount").value(10))
                .andExpect(jsonPath("$.rows[0].pastureContractArea").value(100.5));
    }

    @Test
    @DisplayName("DP-SY-API-042 GET cooperativeDevelopments 合作社明细")
    void api042_cooperativeDevelopments() throws Exception
    {
        HomeScreenCooperativeDevelopmentListItemVo item = new HomeScreenCooperativeDevelopmentListItemVo();
        item.setId(2L);
        item.setStatYear(2026);
        item.setStatMonth(4);
        item.setTownName("巴青镇");
        item.setVillageName("某村");
        item.setCooperativeName("示范合作社");
        when(homeScreenService.listCooperativeDevelopments(eq(2026), eq(4), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/cooperativeDevelopments")
                        .param("statYear", "2026")
                        .param("statMonth", "4")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].cooperativeName").value("示范合作社"))
                .andExpect(jsonPath("$.rows[0].statYear").value(2026))
                .andExpect(jsonPath("$.rows[0].statMonth").value(4));
    }

    @Test
    @DisplayName("DP-SY-API-043 GET familyRanches 家庭牧场明细")
    void api043_familyRanches() throws Exception
    {
        HomeScreenFamilyRanchListItemVo item = new HomeScreenFamilyRanchListItemVo();
        item.setId(3L);
        item.setStatYear(2026);
        item.setStatMonth(5);
        item.setTownName("巴青镇");
        item.setEnterpriseName("某某牧场");
        when(homeScreenService.listFamilyRanches(eq(2026), eq(5), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/familyRanches")
                        .param("statYear", "2026")
                        .param("statMonth", "5")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].enterpriseName").value("某某牧场"))
                .andExpect(jsonPath("$.rows[0].statMonth").value(5));
    }

    @Test
    @DisplayName("DP-SY-API-044 GET largeLivestockFarmers 养殖大户明细")
    void api044_largeLivestockFarmers() throws Exception
    {
        HomeScreenLargeLivestockFarmerListItemVo item = new HomeScreenLargeLivestockFarmerListItemVo();
        item.setId(4L);
        item.setStatYear(2026);
        item.setStatMonth(6);
        item.setTownName("巴青镇");
        item.setEnterpriseName("某某养殖大户");
        when(homeScreenService.listLargeLivestockFarmers(eq(2026), eq(6), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/largeLivestockFarmers")
                        .param("statYear", "2026")
                        .param("statMonth", "6")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].enterpriseName").value("某某养殖大户"))
                .andExpect(jsonPath("$.rows[0].statYear").value(2026));
    }

    @Test
    @DisplayName("DP-SY-API-045 GET yakOutboundReports 牦牛出栏明细")
    void api045_yakOutboundReports() throws Exception
    {
        HomeScreenYakOutboundReportListItemVo item = new HomeScreenYakOutboundReportListItemVo();
        item.setId(5L);
        item.setStatYear(2026);
        item.setStatMonth(7);
        item.setYakOutboundCount(88);
        item.setSelfConsumptionCattleCount(10);
        when(homeScreenService.listYakOutboundReports(eq(2026), eq(7), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/yakOutboundReports")
                        .param("statYear", "2026")
                        .param("statMonth", "7")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].yakOutboundCount").value(88))
                .andExpect(jsonPath("$.rows[0].selfConsumptionCattleCount").value(10));
    }

    @Test
    @DisplayName("DP-SY-API-046 GET yakHerdInventories 牦牛存栏明细")
    void api046_yakHerdInventories() throws Exception
    {
        HomeScreenYakHerdInventoryListItemVo item = new HomeScreenYakHerdInventoryListItemVo();
        item.setId(6L);
        item.setStatYear(2026);
        item.setStatMonth(8);
        item.setYakTotal(1000);
        item.setBullTotal(400);
        when(homeScreenService.listYakHerdInventories(eq(2026), eq(8), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/yakHerdInventories")
                        .param("statYear", "2026")
                        .param("statMonth", "8")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].yakTotal").value(1000))
                .andExpect(jsonPath("$.rows[0].bullTotal").value(400));
    }

    @Test
    @DisplayName("DP-SY-API-047 GET livestockOwnershipHouseholds 有无畜户明细")
    void api047_livestockOwnershipHouseholds() throws Exception
    {
        HomeScreenLivestockOwnershipHouseholdListItemVo item =
                new HomeScreenLivestockOwnershipHouseholdListItemVo();
        item.setId(7L);
        item.setStatYear(2026);
        item.setStatMonth(9);
        item.setWithLivestockHouseholdCount(50);
        item.setWithoutLivestockHouseholdCount(5);
        when(homeScreenService.listLivestockOwnershipHouseholds(eq(2026), eq(9), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/livestockOwnershipHouseholds")
                        .param("statYear", "2026")
                        .param("statMonth", "9")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].withLivestockHouseholdCount").value(50))
                .andExpect(jsonPath("$.rows[0].withoutLivestockHouseholdCount").value(5));
    }

    @Test
    @DisplayName("DP-SY-API-048 GET yakInventoryOutbounds 牦牛存出栏情况明细")
    void api048_yakInventoryOutbounds() throws Exception
    {
        HomeScreenYakInventoryOutboundListItemVo item = new HomeScreenYakInventoryOutboundListItemVo();
        item.setStatYear(2026);
        item.setStatMonth(6);
        item.setTownName("巴青镇");
        item.setVillageName("某村");
        item.setYakTotal(1200);
        item.setYakOutboundCount(80);
        when(homeScreenService.listYakInventoryOutbounds(eq(2026), eq(6), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/yakInventoryOutbounds")
                        .param("statYear", "2026")
                        .param("statMonth", "6")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].yakTotal").value(1200))
                .andExpect(jsonPath("$.rows[0].yakOutboundCount").value(80))
                .andExpect(jsonPath("$.rows[0].townName").value("巴青镇"));
    }

    @Test
    @DisplayName("DP-SY-API-049 GET breedingEntityQuantities 养殖主体数量明细")
    void api049_breedingEntityQuantities() throws Exception
    {
        HomeScreenBreedingEntityQuantityListItemVo item = new HomeScreenBreedingEntityQuantityListItemVo();
        item.setStatYear(2026);
        item.setStatMonth(5);
        item.setTownName("巴青镇");
        item.setVillageName("某村");
        item.setFarmerHouseholdCount(120);
        item.setCooperativeCount(3);
        item.setFamilyRanchCount(2);
        item.setLargeLivestockFarmerCount(5);
        when(homeScreenService.listBreedingEntityQuantities(eq(2026), eq(5), eq(101L), eq(201L)))
                .thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/breedingEntityQuantities")
                        .param("statYear", "2026")
                        .param("statMonth", "5")
                        .param("townDeptId", "101")
                        .param("villageDeptId", "201")
                        .param("pageNum", "1")
                        .param("pageSize", "10"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.rows[0].farmerHouseholdCount").value(120))
                .andExpect(jsonPath("$.rows[0].cooperativeCount").value(3))
                .andExpect(jsonPath("$.rows[0].familyRanchCount").value(2))
                .andExpect(jsonPath("$.rows[0].largeLivestockFarmerCount").value(5));
    }

    @Test
    @DisplayName("DP-SY-API-050 GET townOptions 乡镇列表")
    void api050_townOptions() throws Exception
    {
        java.util.Map<String, Object> item = new java.util.LinkedHashMap<>();
        item.put("deptId", 101L);
        item.put("deptName", "巴青镇");
        item.put("orderNum", 20);
        when(homeScreenService.listTownOptions()).thenReturn(Collections.singletonList(item));
        mockMvc.perform(get("/bigScreen/home/townOptions"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.data[0].deptId").value(101))
                .andExpect(jsonPath("$.data[0].deptName").value("巴青镇"));
    }

    @Test
    @DisplayName("DP-SY-API-051 GET villageTree 村树")
    void api051_villageTree() throws Exception
    {
        com.ruoyi.common.core.domain.TreeSelect root = new com.ruoyi.common.core.domain.TreeSelect();
        root.setId(100L);
        root.setLabel("巴青县");
        com.ruoyi.common.core.domain.TreeSelect town = new com.ruoyi.common.core.domain.TreeSelect();
        town.setId(101L);
        town.setLabel("巴青镇");
        root.setChildren(Collections.singletonList(town));
        when(homeScreenService.listVillageTree()).thenReturn(Collections.singletonList(root));
        mockMvc.perform(get("/bigScreen/home/villageTree"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.code").value(200))
                .andExpect(jsonPath("$.data[0].id").value(100))
                .andExpect(jsonPath("$.data[0].label").value("巴青县"))
                .andExpect(jsonPath("$.data[0].children[0].id").value(101));
    }

    private static com.ruoyi.web.modules.screen.domain.vo.HomeScreenTownMapVo sampleTownMap()
    {
        com.ruoyi.web.modules.screen.domain.vo.HomeScreenTownMapMarkerVo marker =
                new com.ruoyi.web.modules.screen.domain.vo.HomeScreenTownMapMarkerVo();
        marker.setTownDeptId(101L);
        marker.setTownName("巴青乡");
        marker.setYakInventoryCount(21587);
        marker.setYakOutboundCount(1523);
        com.ruoyi.web.modules.screen.domain.vo.HomeScreenTownMapVo vo =
                new com.ruoyi.web.modules.screen.domain.vo.HomeScreenTownMapVo();
        vo.setHerdStatYear(2026);
        vo.setHerdStatMonth(12);
        vo.setOutboundStatYear(2026);
        vo.setOutboundStatMonth(5);
        vo.setMarkers(Collections.singletonList(marker));
        return vo;
    }

    private static HomeScreenDashboardVo sampleDashboard()
    {
        HomeScreenDashboardVo vo = new HomeScreenDashboardVo();
        vo.setStatYear(2026);
        vo.setStatDate("2026-05-20");
        vo.setAvailableYears(Arrays.asList(2026, 2025));

        HomeScreenIndustryOverviewVo overview = new HomeScreenIndustryOverviewVo();
        overview.setInventoryTotal(10);
        overview.setAnnualOutbound(2);
        overview.setPastureCount(1);
        overview.setGrasslandAreaMu(new BigDecimal("100.00"));
        vo.setIndustryOverview(overview);

        vo.setAgeStructure(new ArrayList<>());
        vo.setHerdInventoryStructure(new ArrayList<>());
        vo.setYakInventoryStructure(new ArrayList<>());
        vo.setLivestockOutboundStructure(new ArrayList<>());
        vo.setSelfConsumption(new com.ruoyi.web.modules.screen.domain.vo.HomeScreenSelfConsumptionVo());
        vo.setFamilyRanchFinance(new com.ruoyi.web.modules.screen.domain.vo.HomeScreenEnterpriseFinanceVo());
        vo.setLargeLivestockFarmerFinance(new com.ruoyi.web.modules.screen.domain.vo.HomeScreenEnterpriseFinanceVo());
        vo.setCooperativeBusinessModel(new ArrayList<>());
        // vo.setFarmerHouseholdClassification(new ArrayList<>());
        vo.setTownSubsidyTotals(new ArrayList<>());
        vo.setPerCapitaIncomeTrend(new ArrayList<>());
        return vo;
    }

    private static void loginAsAllPermissions()
    {
        SysUser u = new SysUser();
        u.setUserId(1L);
        u.setUserName("tester");
        u.setPassword("x");
        Set<String> perms = new HashSet<>();
        perms.add(Constants.ALL_PERMISSION);
        LoginUser lu = new LoginUser(1L, 100L, u, perms);
        UsernamePasswordAuthenticationToken auth =
                new UsernamePasswordAuthenticationToken(lu, "", lu.getAuthorities());
        SecurityContextHolder.getContext().setAuthentication(auth);
    }
}
