/**
 * 用户
 * 水产养殖和销售数量数据库默认单位-万尾
 */


import { ERRORENUM } from "../../config/errorEnum";
import { findUserInfoByLoginId, findUserInfoByUserId } from "../../data/users";
import * as caishouData from "../../data/caishou";
import { getPwdMd5, getToken, successResult } from "../../tools/system";
import { BizError } from "../../util/bizError";
import * as diKuaiData from "../../data/dikuai";
import * as zhongZhiData from "../../data/zhongzhi";
import { selectChanLiangOfMonth, selectChanLiangOfzuoWu } from "../../data/caishou";
import { changeEnumValue } from "../../util/verificationEnum";
import { PLANTTYPE, PLOTTYPE } from "../../config/enum";
import { selectXiaoShouOfMonth, selectXiaoShouOfzuoWu } from "../../data/xiaoshou";
import moment = require("moment");


/**
 * 登录
 * @param loginId 
 * @param pwd 
 * @returns 
 */
export async function userLogin(loginId:string, pwd:string) {
    let userInfo:any = await findUserInfoByLoginId(loginId);
    if (!userInfo || !userInfo.userId) throw new BizError(ERRORENUM.账号不存在, loginId);

    let checkPwd = getPwdMd5(loginId, pwd); 
    if (userInfo.pwd != checkPwd) throw new BizError(ERRORENUM.密码错误);

    let token = getToken(loginId);
    
    let resultUserInfo = {
        loginId:userInfo.loginId,
        name: userInfo.name,
        userId:userInfo.userId,
        token:token,
    };

    userInfo.token = token;
    userInfo.tokenMs = new Date().valueOf();

    await userInfo.save();
    
    return {dataInfo:resultUserInfo};
}



/**
 * 登出
 * @param userInfo 
 */
export async function userLogout(reqUserInfo) {
    let userInfo = await findUserInfoByUserId(reqUserInfo.userId);

    userInfo.token = getToken(userInfo.loginId);
    userInfo.tokenMs = new Date().valueOf();

    await userInfo.save();

    return successResult(); 
}



/**
 * 首页
 * @param userInfo 
 * @returns 
 */
export async function homePageChongHai(userInfo) {
    // let param = {
    //     state:SOLVESTATE.待解决,//待解决
    // };
    // let visitCount = await visitData.findDataCount(param);

    // let enterpriseCount = await findEnterpriseCountByParam({RAS:RAS.续存});
    // let industryCount = await statisIndustryEnterprise();

    return {dataInfo:{title:"当前无虫害预警", state:0}};
}


/**
 * 首页 顶部
 * @param userInfo 
 * @returns 
 */
export async function homePageTop(userInfo) {

    return {dataInfo:{
        name:userInfo.name,
        title:userInfo.position
    }};
}


/**
 * 首页-统计页 顶部
 * @param userInfo 
 * @returns 
 */
export async function homePageStatisTop(userInfo) {
    //面积
    let {totalSize, totalUseSize} = await diKuaiData.diKuaiSizeCount({plotType:PLOTTYPE.地块});
    let rate = Math.ceil(totalUseSize/totalSize*10000)/100;
    if (totalSize && totalUseSize) {
        Math.round(totalUseSize/totalSize*100);
    }

    //品种
    let zhongZhiTypeList = await zhongZhiData.pingZhongCount({ isEnd: 0 , plantType:{"$lt":PLANTTYPE.鲈鱼}});

    let dataInfo = {
        diKuaiCount : totalSize,
        zhongYangCount : totalUseSize,
        zhongYangPinZhong : zhongZhiTypeList.length,
        shiYongLv:rate,
    };

    return {dataInfo};
}



/**
 * 首页-统计页 底部
 * @param userInfo 
 * @returns 
 */
export async function homePageStatisBottom(userInfo) {

    let dataInfo = {
        congYe : 0,
        zhuanYe : 0,
        chanYeZhuTi : 0,
    };

    return {dataInfo};
}


/**
 * 统计页-农产品产量统计
 * @param type 统计类型：1-年，2-季度，3-月
 * @returns 
 */
// export async function homePageStatisChanLiang(type:number) {
//     //产量 时间分
//     let zuoWuMonthDBList = await caishouData.selectToParam({plantType:{"$lt":PLANTTYPE.鲈鱼}});
//     let zuoWuDistinctMap = {};
//     let zuoWuCount = 0;

//     let map1 = {};
//     zuoWuMonthDBList.forEach(info => {
//         let {ct, weight} = info;
        
//         let year = moment(ct).year();
//         let month = moment(ct).month();
//         if (!map1[''+year+''+month]) map1[''+year+''+month] = {month, year, totalWeight:0}
//         map1[''+year+''+month].totalWeight += weight;
//     })

//     let list1 =  Object.values(map1);
//     list1.forEach(info => {
//         let {year, month, totalWeight}:any = info;
        
//         let strKey:any = "";
//         if (type == 1) {//年
//             strKey = year;
//         } else if (type == 2) {//季度
//             let quarter = 1;
//             if (month >= 10) quarter = 4;
//             else if (month >= 7) quarter = 3;
//             else if (month >= 4) quarter = 2;
//             strKey = `${year}-${quarter}`;
//         } else {//月
//             strKey = `${year}-${month}`;
//         }

//         if (!zuoWuDistinctMap[strKey]) zuoWuDistinctMap[strKey] = {key:strKey, value:0};
//         zuoWuDistinctMap[strKey].value += totalWeight;

//         zuoWuCount += totalWeight;
//     });
//     let nongChanPin = Object.values(zuoWuDistinctMap);

//     for (let i = 0; i < nongChanPin.length; i++) {
//         nongChanPin[i]["value"] =  Math.ceil(nongChanPin[i]["value"] / 10)/100;
//     }
//     //农作物产量
//     let zuoWuDBList = await selectChanLiangOfzuoWu({plantType:{"$lt":PLANTTYPE.鲈鱼}});
//     let zuoWu = [];
//     zuoWuDBList.forEach(info => {
//         let {_id, totalWeight} = info;
//         zuoWu.push({
//             key:changeEnumValue(PLANTTYPE, _id),
//             value:totalWeight/1000
//         });
//     });
//     zuoWu.sort((a,b) =>{return b.value - a.value});


//     //产量 
//     let shuiChanMonthDBList = await selectChanLiangOfMonth({plantType:{"$gte":PLANTTYPE.鲈鱼}});
//     let shuiChanDistinctMap = {};
//     let shuiChanCount = 0;
//     shuiChanMonthDBList.forEach(info => {
//         let {year, month, totalWeight} = info;
        
//         let strKey = "";
//         if (type == 1) {//年
//             strKey = year;
//         } else if (type == 2) {//季度
//             let quarter = 1;
//             if (month >= 10) quarter = 4;
//             else if (month >= 7) quarter = 3;
//             else if (month >= 4) quarter = 2;
//             strKey = `${year}-${quarter}`;
//         } else {//月
//             strKey = `${year}-${month}`;
//         }

//         if (!shuiChanDistinctMap[strKey]) shuiChanDistinctMap[strKey] = {key:strKey, value:0};
//         shuiChanDistinctMap[strKey].value += totalWeight;

//         shuiChanCount += totalWeight;
//     });
//     let shuiChanPin = Object.values(shuiChanDistinctMap);

//     //农作物产量
//     let shuiChanDBList = await selectChanLiangOfzuoWu({plantType:{"$gte":PLANTTYPE.鲈鱼}});
//     let shuiChan = [];
//     shuiChanDBList.forEach(info => {
//         let {_id, totalWeight} = info;
//         shuiChan.push({
//             key:changeEnumValue(PLANTTYPE, _id),
//             value:totalWeight/10000
//         });
//     });
//     shuiChan.sort((a,b) =>{return b.value - a.value});

    
//     let shuiChanZhognYang = [];
//     let shuiChanZhognYangCount = 0;
//     let zhognYangDBList = await zhongZhiData.zhongYangTongJiCount();
//     zhognYangDBList.forEach(info => {
//         let {_id, sizeCount} = info;
//         shuiChanZhognYang.push({
//             key:changeEnumValue(PLANTTYPE, _id),
//             value:sizeCount
//         });
//         shuiChanZhognYangCount += sizeCount;
//     });

//     let dataInfo = {
//         zuoWu:{
//             count:Math.ceil(zuoWuCount/10)/100,
//             nongChanPin,
//             zuoWu:zuoWu,
//         },
//         shuiChan:{
//             count:Math.ceil(shuiChanCount/100)/100,
//             shuiChanPin,
//             shuiChan,
//         },
//         shuiChanZhognYang:{
//             shuiChanZhognYangList:shuiChanZhognYang,
//             count:shuiChanZhognYangCount,
//         }
       
//     };

//     return {dataInfo};
// }


/**
 * 统计页-农产品产量统计
 * @param year 年份参数，用于筛选对应年份的数据
 * @param type 统计类型：2-季度，3-月
 * @returns 
 */
export async function homePageStatisChanLiang(year: number, type: number) {
    // 产量 时间分
    let zuoWuMonthDBList = await caishouData.selectToParam({plantType: {"$lt": PLANTTYPE.鲈鱼}});
    let zuoWuDistinctMap = {};
    let zuoWuCount = 0;

    let map1 = {};
    zuoWuMonthDBList.forEach(info => {
        let {operationTime, weight} = info;  // 使用operationTime而不是ct
        let dataYear = 0;
        let month = 0;
        if (operationTime) {
            dataYear = moment(operationTime).year();
            month = moment(operationTime).month()+1;
        }
        // 只处理指定年份的数据
        if (dataYear !== year) return;
        
        if (!map1['' + dataYear + '' + month]) map1['' + dataYear + '' + month] = {month, year: dataYear, totalWeight: 0}
        map1['' + dataYear + '' + month].totalWeight += weight;
    })

    let list1 = Object.values(map1);
    list1.forEach(info => {
        let {year: dataYear, month, totalWeight}: any = info;
        
        let strKey: any = "";
        if (type == 2) {//季度
            let quarter = "第一季度";
            if (month >= 10) quarter = "第四季度";
            else if (month >= 7) quarter = "第三季度";
            else if (month >= 4) quarter = "第二季度";
            // strKey = `${dataYear}-${quarter}`;
            strKey = `${quarter}`;
        } else {//月
            strKey = `${dataYear}-${month}`;
        }

        if (!zuoWuDistinctMap[strKey]) zuoWuDistinctMap[strKey] = {key: strKey, value: 0};
        zuoWuDistinctMap[strKey].value += totalWeight;

        zuoWuCount += totalWeight;
    });
    let nongChanPin = Object.values(zuoWuDistinctMap);

    for (let i = 0; i < nongChanPin.length; i++) {
        nongChanPin[i]["value"] = Math.ceil(nongChanPin[i]["value"] / 10) / 100;
    }
    
    // 农作物产量 - 需要根据年份筛选
    let zuoWuDBList = await selectChanLiangOfzuoWu({plantType: {"$lt": PLANTTYPE.鲈鱼}});
    let zuoWu = [];
    let zuoWuTotalWeight = 0;
    
    // 注意：这里需要重新查询原始数据来按年份筛选
    let zuoWuRawData = await caishouData.selectToParam({plantType: {"$lt": PLANTTYPE.鲈鱼}});
    let zuoWuMap = {};
    
    zuoWuRawData.forEach(info => {
        let {plantType, weight, operationTime} = info;
        let dataYear = 0;
        if (operationTime) dataYear = moment(operationTime).year();
        
        // 只处理指定年份的数据
        if (dataYear !== year) return;
        
        if (!zuoWuMap[plantType]) zuoWuMap[plantType] = 0;
        zuoWuMap[plantType] += weight;
    });
    
    // 将map转换为数组
    Object.keys(zuoWuMap).forEach(plantType => {
        let weight = zuoWuMap[plantType];
        zuoWu.push({
            key: changeEnumValue(PLANTTYPE, parseInt(plantType)),
            value: weight / 1000
        });
        zuoWuTotalWeight += weight;
    });
    
    zuoWu.sort((a, b) => {
        return b.value - a.value
    });

    // 产量 
    let shuiChanMonthDBList = await selectChanLiangOfMonth({plantType: {"$gte": PLANTTYPE.鲈鱼}});
    let shuiChanDistinctMap = {};
    let shuiChanCount = 0;
    shuiChanMonthDBList.forEach(info => {
        let {year: dataYear, month, totalWeight} = info;
        // 只处理指定年份的数据
        if (dataYear !== year) return;
        
        let strKey = `${dataYear}-${month}`;
        if (type == 2) {//季度
            let quarter = "第一季度";
            if (month >= 10) quarter = "第四季度";
            else if (month >= 7) quarter = "第三季度";
            else if (month >= 4) quarter = "第二季度";
            // strKey = `${dataYear}-${quarter}`;
            strKey = `${quarter}`;
        } else {//月
            strKey = `${dataYear}-${month}`;
        }

        if (!shuiChanDistinctMap[strKey]) shuiChanDistinctMap[strKey] = {key: strKey, value: 0};
        // 水产单位转换：万尾 → 尾
        let weightInTail = totalWeight * 10000;
        shuiChanDistinctMap[strKey].value += weightInTail;

        shuiChanCount += weightInTail;
    });
    let shuiChanPin = Object.values(shuiChanDistinctMap);

    // 水产品产量 - 需要根据年份筛选
    let shuiChanDBList = await selectChanLiangOfzuoWu({plantType: {"$gte": PLANTTYPE.鲈鱼}});
    let shuiChan = [];
    let shuiChanTotalWeight = 0;
    
    // 注意：这里也需要重新查询原始数据来按年份筛选
    let shuiChanRawData = await caishouData.selectToParam({plantType: {"$gte": PLANTTYPE.鲈鱼}});
    let shuiChanMap = {};
    
    shuiChanRawData.forEach(info => {
        let {plantType, weight, operationTime} = info;
        let dataYear = 0;
        if (operationTime) dataYear = moment(operationTime).year();
        
        // 只处理指定年份的数据
        if (dataYear !== year) return;
        
        if (!shuiChanMap[plantType]) shuiChanMap[plantType] = 0;
        // 水产单位转换：万尾 → 尾
        let weightInTail = weight * 10000;
        shuiChanMap[plantType] += weightInTail;
    });
    
    // 将map转换为数组
    Object.keys(shuiChanMap).forEach(plantType => {
        let weight = shuiChanMap[plantType];
        shuiChan.push({
            key: changeEnumValue(PLANTTYPE, parseInt(plantType)),
            value: weight,
        });
        shuiChanTotalWeight += weight;
    });
    
    shuiChan.sort((a, b) => {
        return b.value - a.value
    });

    
    let shuiChanZhognYang = [];
    let shuiChanZhognYangCount = 0;
    
    // 使用带年份筛选的方法
    let zhognYangDBList = await zhongZhiData.zhongYangTongJiCountByYear(year);
    zhognYangDBList.forEach(info => {
        let {_id, sizeCount} = info;
        // 水产单位转换：万尾 → 尾
        let weightInTail = sizeCount * 10000;
        shuiChanZhognYang.push({
            key: changeEnumValue(PLANTTYPE, _id),
            value: weightInTail
        });
        shuiChanZhognYangCount += weightInTail;
    });

    let dataInfo = {
        zuoWu: {
            count: Math.ceil(zuoWuCount / 10) / 100, //农产品产量总数
            nongChanPin, //农产品产量趋势
            zuoWu: zuoWu, //农产品产量分类
        },
        shuiChan: {
            count: Math.ceil(shuiChanCount / 100) / 100, //水产品产量总数
            shuiChanPin, //水产品产量
            shuiChan, //水产品产量分类
        },
        shuiChanZhognYang: {
            shuiChanZhognYangList: shuiChanZhognYang,
            count: shuiChanZhognYangCount,
        }
       
    };

    return {dataInfo};
}


/**
 * 统计页销售量统计
 * @param year 年份参数，用于筛选对应年份的数据
 * @returns 
 */
export async function homePageStatisXiaoShou(year?: number) {
    // 构建查询条件，添加年份过滤
    let currentYear = year || moment().year();
    let startOfYear = moment().year(currentYear).startOf('year').valueOf();
    let endOfYear = moment().year(currentYear).endOf('year').valueOf();
    
    let timeFilter = {
        operationTime: {
            "$gte": startOfYear,
            "$lte": endOfYear
        }
    };

    // 农作物销售查询参数
    let nonzuowuParam = {
        ...timeFilter,
        plantType: {"$lt": PLANTTYPE.鲈鱼}
    };

    // 水产品销售查询参数
    let shuichanParam = {
        ...timeFilter,
        plantType: {"$gte": PLANTTYPE.鲈鱼}
    };

    // 农作物销售量统计
    let monthDBList = await selectXiaoShouOfMonth(nonzuowuParam);
    let distinctMap = {};
    let count = 0;
    // let lastYearCount = 0;
    
    monthDBList.forEach(info => {
        let {year, month, totalWeight} = info;
        
        let strKey = `${year}-${month}`;
        // if (type == 2) {//季度
        //     let quarter = "第一季度";
        //     if (month >= 10) quarter = "第四季度";
        //     else if (month >= 7) quarter = "第三季度";
        //     else if (month >= 4) quarter = "第二季度";
        //     // strKey = `${year}-${quarter}`;
        //     strKey = `${quarter}`;
        // } else {//月
        //     strKey = `${year}-${month}`;
        // }

        if (!distinctMap[strKey]) distinctMap[strKey] = {key:strKey, value:0};
        distinctMap[strKey].value += totalWeight;

        if (currentYear == year) count += totalWeight;
        // else if (year == (currentYear-1)) lastYearCount += totalWeight;
    });

    let xiaoShouList = Object.values(distinctMap);

    let xiaoShouDBList = await selectXiaoShouOfzuoWu(nonzuowuParam);
    let xiaoShou = [];
    xiaoShouDBList.forEach(info => {
        let {_id, totalWeight} = info;
        xiaoShou.push({
            key: changeEnumValue(PLANTTYPE, _id),
            value: Math.ceil(totalWeight/10)/100
        });
    });
    xiaoShou.sort((a,b) => {return b.value - a.value});

    for (let i = 0; i < xiaoShouList.length; i++) {
        xiaoShouList[i]["value"] = Math.ceil(xiaoShouList[i]["value"] / 10)/100;
    }

    // 水产品销售量统计
    let shuiChanMonthDBList = await selectXiaoShouOfMonth(shuichanParam);
    let shuiChanDistinctMap = {};
    let shuiChanCount = 0;
    // let suiChanLastYearCount = 0;
    
    shuiChanMonthDBList.forEach(info => {
        let {year, month, totalWeight} = info;
        
        let strKey = `${year}-${month}`;
        // if (type == 2) {//季度
        //     let quarter = "第一季度";
        //     if (month >= 10) quarter = "第四季度";
        //     else if (month >= 7) quarter = "第三季度";
        //     else if (month >= 4) quarter = "第二季度";
        //     // strKey = `${year}-${quarter}`;
        //     strKey = `${quarter}`;
        // } else {//月
        //     strKey = `${year}-${month}`;
        // }

        if (!shuiChanDistinctMap[strKey]) shuiChanDistinctMap[strKey] = {key:strKey, value:0};
        // 水产单位转换：万尾 → 尾
        let weightInTail = totalWeight * 10000;
        shuiChanDistinctMap[strKey].value += weightInTail;

        if (currentYear == year) shuiChanCount += weightInTail;
        // else if (year == (currentYear-1)) suiChanLastYearCount += totalWeight;
    });

    let suiChanxiaoShouList = Object.values(shuiChanDistinctMap);

    let shuiChanXiaoShouDBList = await selectXiaoShouOfzuoWu(shuichanParam);
    let shuiChanxiaoShou = [];
    shuiChanXiaoShouDBList.forEach(info => {
        let {_id, totalWeight} = info;
        // 水产单位转换：万尾 → 尾
        let weightInTail = totalWeight * 10000;
        shuiChanxiaoShou.push({
            key: changeEnumValue(PLANTTYPE, _id),
            value: weightInTail
        });
    });
    shuiChanxiaoShou.sort((a,b) => {return b.value - a.value});
    
    let dataInfo = {
        zuoWu: { //农产品销售
            count: Math.ceil(count/10)/100,
            // mom: lastYearCount > 0 ? Math.round((count - lastYearCount) / lastYearCount * 1000) / 10 : 0,
            xiaoShou: xiaoShouList, //
            zuoWu: xiaoShou
        },
        shuiChan: { //水产销售
            count: Math.ceil(shuiChanCount/10)/100,
            // mom: suiChanLastYearCount > 0 ? Math.round((shuiChanCount - suiChanLastYearCount) / suiChanLastYearCount * 1000) / 10 : 0,
            xiaoShou: suiChanxiaoShouList,
            shuiChan: shuiChanxiaoShou
        }
    };

    return {dataInfo};
}


/**
 * 统计页产量统计
 * @param year 年份，如 2025
 * @param type 统计类型：1-年，2-季度，3-月
 * @returns 
 */
export async function homePageStatisChanLiangWithYear(year: number, type: number) {
    // 产量 时间分 - 农作物
    let zuoWuMonthDBList = await caishouData.selectToParam({plantType: {"$lt": PLANTTYPE.鲈鱼}});
    let zuoWuDistinctMap = {};
    let zuoWuCount = 0;

    let map1 = {};
    zuoWuMonthDBList.forEach(info => {
        let {ct, weight} = info;
        
        let dataYear = 0;
        let month = 0;
        if (ct) {
            dataYear = moment(ct).year();
            month = moment(ct).month() + 1;
        }

        // 添加年份过滤
        if (year && dataYear !== year) {
            return;
        }
        
        if (!map1[''+dataYear+''+month]) {
            map1[''+dataYear+''+month] = {month, year: dataYear, totalWeight: 0};
        }
        map1[''+dataYear+''+month].totalWeight += weight;
    });

    let list1 = Object.values(map1);
    list1.forEach(info => {
        let {year: dataYear, month, totalWeight}: any = info;
        
        let strKey: any = "";
        if (type == 1) { // 年
            strKey = dataYear;
        } else if (type == 2) { // 季度
            let quarter = 1;
            if (month >= 10) quarter = 4;
            else if (month >= 7) quarter = 3;
            else if (month >= 4) quarter = 2;
            strKey = `${dataYear}-${quarter}`;
        } else { // 月
            strKey = `${dataYear}-${month}`;
        }

        if (!zuoWuDistinctMap[strKey]) {
            zuoWuDistinctMap[strKey] = {key: strKey, value: 0};
        }
        zuoWuDistinctMap[strKey].value += totalWeight;
        zuoWuCount += totalWeight;
    });
    
    let nongChanPin = Object.values(zuoWuDistinctMap);
    for (let i = 0; i < nongChanPin.length; i++) {
        nongChanPin[i]["value"] = Math.ceil(nongChanPin[i]["value"] / 10) / 100;
    }
    
    // 农作物产量 - 添加年份过滤
    let zuoWuDBList = await selectChanLiangOfzuoWu({
        plantType: {"$lt": PLANTTYPE.鲈鱼},
        ...(year && {year: year})
    });
    let zuoWu = [];
    zuoWuDBList.forEach(info => {
        let {_id, totalWeight} = info;
        zuoWu.push({
            key: changeEnumValue(PLANTTYPE, _id),
            value: totalWeight / 1000
        });
    });
    zuoWu.sort((a, b) => {return b.value - a.value});

    // 产量 - 水产品
    let shuiChanMonthDBList = await selectChanLiangOfMonth({plantType: {"$gte": PLANTTYPE.鲈鱼}});
    let shuiChanDistinctMap = {};
    let shuiChanCount = 0;
    
    shuiChanMonthDBList.forEach(info => {
        let {year: dataYear, month, totalWeight} = info;
        
        // 添加年份过滤
        if (year && dataYear !== year) {
            return;
        }
        
        let strKey = "";
        if (type == 1) { // 年
            strKey = dataYear;
        } else if (type == 2) { // 季度
            let quarter = 1;
            if (month >= 10) quarter = 4;
            else if (month >= 7) quarter = 3;
            else if (month >= 4) quarter = 2;
            strKey = `${dataYear}-${quarter}`;
        } else { // 月
            strKey = `${dataYear}-${month}`;
        }

        if (!shuiChanDistinctMap[strKey]) {
            shuiChanDistinctMap[strKey] = {key: strKey, value: 0};
        }
        shuiChanDistinctMap[strKey].value += totalWeight;
        shuiChanCount += totalWeight;
    });
    
    let shuiChanPin = Object.values(shuiChanDistinctMap);

    // 水产品产量 - 添加年份过滤
    let shuiChanDBList = await selectChanLiangOfzuoWu({
        plantType: {"$gte": PLANTTYPE.鲈鱼},
        ...(year && {year: year})
    });
    let shuiChan = [];
    shuiChanDBList.forEach(info => {
        let {_id, totalWeight} = info;
        shuiChan.push({
            key: changeEnumValue(PLANTTYPE, _id),
            value: totalWeight / 10000
        });
    });
    shuiChan.sort((a, b) => {return b.value - a.value});
    
    // 水产品种植统计 - 使用新的年份过滤方法
    let shuiChanZhognYang = [];
    let shuiChanZhognYangCount = 0;
    let zhognYangDBList = await zhongZhiData.zhongYangTongJiCountByYear(year);
    zhognYangDBList.forEach(info => {
        let {_id, sizeCount} = info;
        shuiChanZhognYang.push({
            key: changeEnumValue(PLANTTYPE, _id),
            value: sizeCount
        });
        shuiChanZhognYangCount += sizeCount;
    });

    let dataInfo = {
        zuoWu: {
            count: Math.ceil(zuoWuCount / 10) / 100,
            nongChanPin,
            zuoWu: zuoWu,
        },
        shuiChan: {
            count: Math.ceil(shuiChanCount / 100) / 100,
            shuiChanPin,
            shuiChan,
        },
        shuiChanZhognYang: {
            shuiChanZhognYangList: shuiChanZhognYang,
            count: shuiChanZhognYangCount,
        }
    };

    return {dataInfo};
}








