Commit 55a42a80 by lixinming

Merge branch 'master' of http://123.207.147.179:8888/node_server/zjnyxcxServer

# Conflicts:
#	src/biz/xcx/diKuai.ts
#	src/routers/admin.ts
parents 75350878 89c6a75a
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
"ws": "^5.2.2", "ws": "^5.2.2",
"xml2js": "^0.4.23" "xml2js": "^0.4.23"
}, },
"devDependencies": {},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
......
<config> <config>
<port>13281</port> <port>13281</port>
<mongodb> <mongodb>
<path>127.0.0.1</path> <path>192.168.0.105</path>
<port>27017</port> <port>27017</port>
<w>1</w> <w>1</w>
<!-- <dataBase>baseDB</dataBase> --> <!-- <dataBase>baseDB</dataBase> -->
......
/**
* 采收逻辑
*/
import { TABLENAME } from "../../config/dbEnum";
import { CaiShouConfig } from "../../config/eccParam";
import { PLANTTYPE, PURPOSE, ZHONGYANGTYPE } from "../../config/enum";
import { ERRORENUM } from "../../config/errorEnum";
import * as caishouData from "../../data/caishou";
import * as dikuaiData from "../../data/dikuai";
import * as zhongzhiData from "../../data/zhongzhi";
import { randomId, successResult } from "../../tools/system";
import { BizError } from "../../util/bizError";
import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
import moment = require("moment");
/**
* 添加采收
* @param reqUser
* @param param
* @returns
*/
export async function addCaiShou(reqUser, param) {
let funName = `添加采收`;
eccFormParam(funName, CaiShouConfig, param );
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
//修改种养
let zhongyangParam = {isEnd:0, plantType:param.plantType, dId:param.dId};
let zhongzhiList = await zhongzhiData.selectToParam(zhongyangParam);
let sizeCount = 0;
for (let i = 0; i < zhongzhiList.length; i++) {
let {dId, size} = zhongzhiList[i];
sizeCount += size;
}
//释放地块
let diKuaiInfo = await dikuaiData.selectOne({dId:param.dId});
diKuaiInfo.nullSize = diKuaiInfo.nullSize + sizeCount;
diKuaiInfo.useSize = diKuaiInfo.useSize - sizeCount;
await diKuaiInfo.save();
let csId = randomId(TABLENAME.采收);
//改变种植面积
await zhongzhiData.updateManyToParam({isEnd:0, plantType:param.plantType}, {isEnd:1, csId});
//添加采收记录
let addInfo = {
csId,
dIdList:param.dId,
plantType:param.plantType,
operationTime:param.operationTime,
weight:param.weight,
ct:new Date().valueOf(),
createUser:reqUser.userId
};
await caishouData.addData(addInfo)
return successResult();
}
/**
* 采收列表
* @param selectStr
* @param dId
* @param zhongYangType
* @param plantType
* @param operationTime
* @returns
*/
export async function caiShouList(zhongYangType:number, dId:string, plantType:number, operationTime:number, pageNumber) {
let funName = "采收列表";
eccEnumValue(funName, "zhongYangType", ZHONGYANGTYPE, zhongYangType);
let param:any = { plantType : {"$gte":zhongYangType, "$lt":zhongYangType+99} };
if (plantType) {
eccEnumValue(funName, "plantType", PLANTTYPE, plantType);
param.plantType = plantType;
}
if (dId) {
param.dIdList = {"$in":[dId]};
}
if (operationTime) {
let startMs = moment(operationTime).startOf("day").valueOf();
let endMs = moment(operationTime).endOf("day").valueOf();
param.operationTime = {"$gte":startMs, "$lte":endMs};
}
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code, purpose} = info;
diKuaiMap[dId] = {code, purpose};
});
let caishouList = await caishouData.findDataToParamToSortPage(param, {operationTime:-1}, pageNumber);
let dataCount = await caishouData.findDataToParamCouant(param);
let dataList = [];
caishouList.forEach(item => {
let {csId, plantType, dIdList, operationTime, weight, ct } = item;
let dIds = dIdList;
let didStr = "";
let purpose = "-";
dIds.forEach(dId => {
didStr += `${diKuaiMap[dId].code} `;
purpose = `${changeEnumValue(PURPOSE, diKuaiMap[dId].purpose)} `;
});
let operationTimeNum;
if (operationTime) operationTimeNum = operationTime;
else operationTimeNum = ct
dataList.push({
csId,
plantType:changeEnumValue(PLANTTYPE, plantType),
code:didStr || "-",
purpose,
operationTime:moment(operationTimeNum).format("YYYY-MM-DD"),
weight,
operationTimeNum,
ctTime:moment(ct).format("YYYY-MM-DD"),
});
});
dataList.sort( (a, b) => {
return b.operationTimeNum - a.operationTimeNum;
})
return {dataList, dataCount}
}
/**
* 采收回显
* @param csId
* @returns
*/
export async function caishouInfo(csId) {
let caishouInfo = await caishouData.findOne({csId});
let dataInfo = {
plantType:changeEnumValue(PLANTTYPE, caishouInfo.plantType),
code:caishouInfo.dIdList[0] || "",
operationTime:moment(caishouInfo.operationTime).format("YYYY-MM-DD"),
weight:caishouInfo.weight
};
return dataInfo;
}
/**
* 修改采收
* @param reqUser
* @param csId
* @param param
* @returns
*/
export async function updateCaiShou(reqUser, csId, param) {
let funName = `修改采收`;
eccFormParam(funName, CaiShouConfig, param );
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
if (!diKuaiMap[param.dId]) throw new BizError(ERRORENUM.地块不存在, param.dIdList);
let caiShouInfo = await caishouData.findOne({csId});
caiShouInfo.plantType = param.plantType; //种植种类【枚举】 PLANTTYPE
caiShouInfo.dIdList = param.dId;//地块id
caiShouInfo.weight = param.weight;//采收重量
caiShouInfo.operationTime = param.operationTime; //采收时间
await caiShouInfo.save();
return successResult();
}
/**
* 删除采收
* @param nzId
* @returns
*/
export async function deleteCaiShou(csId) {
let caishouInfo = await caishouData.findOne({csId});
if (!caishouInfo || !caishouInfo.csId) throw new BizError(ERRORENUM.数据不存在);
await caishouData.deleteData({csId});
return successResult();
}
...@@ -2,15 +2,16 @@ ...@@ -2,15 +2,16 @@
* 地块 * 地块
*/ */
import { TABLENAME } from "../config/dbEnum"; import moment = require("moment");
import { DiKuaiConfig, YangZhiChiConfig } from "../config/eccParam"; import { TABLENAME } from "../../config/dbEnum";
import { AREARANGE, PLANTTYPE, PLOTTYPE, PURPOSE, ZHONGYANGTYPE } from "../config/enum"; import { DiKuaiConfig, YangZhiChiConfig } from "../../config/eccParam";
import { ERRORENUM } from "../config/errorEnum"; import { AREARANGE, PLANTTYPE, PLOTTYPE, PURPOSE, ZHONGYANGTYPE } from "../../config/enum";
import * as dikuaiData from "../data/dikuai"; import { ERRORENUM } from "../../config/errorEnum";
import { randomId, successResult } from "../tools/system"; import * as dikuaiData from "../../data/dikuai";
import { BizError } from "../util/bizError"; import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../util/verificationEnum"; import { BizError } from "../../util/bizError";
import { eccFormParam } from "../util/verificationParam"; import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
/** /**
...@@ -60,8 +61,6 @@ export async function addDiKuai(reqUser, plotType, param) { ...@@ -60,8 +61,6 @@ export async function addDiKuai(reqUser, plotType, param) {
* @returns * @returns
*/ */
export async function diKuaiInfo(dId:String ) { export async function diKuaiInfo(dId:String ) {
let funName = "地块信息";
let dikuaiInfo = await dikuaiData.selectOne({dId}); let dikuaiInfo = await dikuaiData.selectOne({dId});
let dataInfo = { let dataInfo = {
size:dikuaiInfo.size, size:dikuaiInfo.size,
...@@ -76,7 +75,7 @@ export async function diKuaiInfo(dId:String ) { ...@@ -76,7 +75,7 @@ export async function diKuaiInfo(dId:String ) {
/** /**
* 地块列表 * 地块列表-暂无使用
* @param plotType * @param plotType
* @param selectStr * @param selectStr
* @param code * @param code
...@@ -111,28 +110,46 @@ export async function diKuaiList(plotType:number, selectStr:string, code:string, ...@@ -111,28 +110,46 @@ export async function diKuaiList(plotType:number, selectStr:string, code:string,
return {dataList} return {dataList}
} }
/** /**
* 地块列表分页 * 地块列表分页
* @param plotType * @param code 地块编号 string
* @param selectStr * @param area 地块区域 string
* @param code * @param purpose 地块用途 number
* @param purpose * @param pageNumber 页码
* @param area
* @returns * @returns
*
*/ */
export async function diKuaiListToPage(pageNumber) { export async function diKuaiListToPage(code, area, purpose, pageNumber) {
let funName = "地块列表";
let param:any = {};
if (code) {
param.code = { "$regex":code };
}
if (area) {
param.area = { "$regex":area };
}
if (purpose) {
eccEnumValue(funName, "purpose", PURPOSE, purpose);
param.purpose = purpose;
}
let diKuaiList = await dikuaiData.findDataToParamToPage({}, pageNumber); let diKuaiList = await dikuaiData.findDataToParamToSortPage(param, {ct:-1}, pageNumber);
let dataCount = await dikuaiData.findDataToParamCouant({});
let dataList = []; let dataList = [];
diKuaiList.forEach(item => { diKuaiList.forEach(item => {
let { size, dId, purpose, code, area, ct } = item; let { size, dId, plotType, purpose, code, area, ct } = item;
dataList.push({size,dId,type:changeEnumValue(PURPOSE, purpose),code,area, dataList.push({
size,
dId,
plotType:changeEnumValue(PLOTTYPE, plotType),
type:changeEnumValue(PURPOSE, purpose),
code,
area,
ct:moment(ct).format("YYYY-MM-DD")
}); });
}); });
return {dataList} return {dataList, dataCount}
} }
...@@ -183,7 +200,7 @@ export async function keXuanDiKuaiList(zhongYangType:number) { ...@@ -183,7 +200,7 @@ export async function keXuanDiKuaiList(zhongYangType:number) {
if (zhongYangType == ZHONGYANGTYPE.水产) purpose = PURPOSE.养殖; if (zhongYangType == ZHONGYANGTYPE.水产) purpose = PURPOSE.养殖;
else if (zhongYangType == ZHONGYANGTYPE.花卉 ||zhongYangType == ZHONGYANGTYPE.蔬菜 ) purpose = PURPOSE.菜田; else if (zhongYangType == ZHONGYANGTYPE.花卉 ||zhongYangType == ZHONGYANGTYPE.蔬菜 ) purpose = PURPOSE.菜田;
else if (zhongYangType == ZHONGYANGTYPE.粮食) purpose = PURPOSE.粮田; else if (zhongYangType == ZHONGYANGTYPE.粮食) purpose = PURPOSE.粮田;
param.nullSize = {"$gt":0}; // param.nullSize = {"$gt":0};
param.purpose = purpose; param.purpose = purpose;
} }
...@@ -203,7 +220,7 @@ export async function keXuanDiKuaiList(zhongYangType:number) { ...@@ -203,7 +220,7 @@ export async function keXuanDiKuaiList(zhongYangType:number) {
/** /**
* 当前采收地块列表 * 当前采收地块列表-暂无使用
* @returns * @returns
*/ */
export async function keCaiShouList(zhongYangType:number) { export async function keCaiShouList(zhongYangType:number) {
...@@ -226,7 +243,7 @@ export async function keCaiShouList(zhongYangType:number) { ...@@ -226,7 +243,7 @@ export async function keCaiShouList(zhongYangType:number) {
} }
/** /**
* 全部地块列表 * 全部地块列表-暂无使用
* @param plotType * @param plotType
* @param selectStr * @param selectStr
* @param code * @param code
...@@ -248,4 +265,5 @@ export async function allDiKuaiList(plotType:number ) { ...@@ -248,4 +265,5 @@ export async function allDiKuaiList(plotType:number ) {
}); });
return {dataList} return {dataList}
} }
\ No newline at end of file
import { TABLENAME } from "../../config/dbEnum";
import { CaiShouConfig, NongShiAdminConfig } from "../../config/eccParam";
import { NONGSHITYPE, PLANTTYPE, PURPOSE } from "../../config/enum";
import * as nongshiData from "../../data/nongshi";
import * as dikuaiData from "../../data/dikuai";
import { getMySqlMs, randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
import moment = require("moment");
import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../../config/errorEnum";
/**
* 添加农事
* @param reqUser
* @param param
* @returns
*/
export async function addNongShi(reqUser, param) {
let funName = `添加农事`;
eccFormParam(funName, NongShiAdminConfig, param );
eccEnumValue(funName, "nsType", NONGSHITYPE, param.nsType);
//确保添加时地块还在
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
if (!diKuaiMap[param.dIdList]) throw new BizError(ERRORENUM.地块不存在, param.dIdList);
let addInfo = {
nsId:randomId(TABLENAME.农事),
nsType:param.nsType,
dIdList:[param.dIdList],
operationTime:param.operationTime,
ct:new Date().valueOf()
};
await nongshiData.addData(addInfo)
return successResult();
}
/**
* 农事列表
* @param selectStr
* @param dId
* @param nsType
* @param operationTime
* @returns
*/
export async function nongShiList(nsType:number, dId:string, operationTime:number, pageNumber:number) {
let funName = "农事列表";
let param:any = {};
if (nsType) {
eccEnumValue(funName, "nsType", NONGSHITYPE, nsType);
param.nsType = nsType;
}
if (dId) {
param.dIdList = {"$in":dId};
}
if (operationTime) {
let startMs = moment(operationTime).startOf("day").valueOf();
let endMs = moment(operationTime).endOf("day").valueOf();
param.operationTime = {"$gte":startMs, "$lte":endMs};
}
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code, purpose} = info;
diKuaiMap[dId] = {code, purpose};
});
let nongShiList = await nongshiData.findDataToParamToSortPage(param, {operationTime:-1}, pageNumber);
let dataCount = await nongshiData.findDataToParamCouant({});
let dataList = [];
nongShiList.forEach(item => {
let {nsId, nsType, dIdList, operationTime } = item;
let dIds = dIdList;
let didStr = "";
let purpose = "";
dIds.forEach(dId => {
didStr += `${diKuaiMap[dId].code} `;
purpose += `${changeEnumValue(PURPOSE, diKuaiMap[dId].purpose)} `;
});
dataList.push({
nsId,
nsType:changeEnumValue(NONGSHITYPE, nsType),
// dIdList:didStr,
operationTime:moment(operationTime).format("YYYY-MM-DD"),
operationTimeNum:operationTime,
code:didStr,
purpose,
});
});
dataList.sort( (a, b) => {
return b.operationTimeNum - a.operationTimeNum;
})
return {dataList, dataCount}
}
/**
* 农事回显
* @param nzId
* @returns
*/
export async function nongShiInfo(nsId) {
let nongShiInfo = await nongshiData.findOne({nsId});
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code, purpose} = info;
diKuaiMap[dId] = {code, purpose};
});
let didStr = "";
let purpose = "";
nongShiInfo.dIdList.forEach(dId => {
didStr += `${diKuaiMap[dId].code} `;
purpose += `${changeEnumValue(PURPOSE, diKuaiMap[dId].purpose)} `;
});
let dataInfo = {
nsType:changeEnumValue(NONGSHITYPE, nongShiInfo.nsType),
operationTime:moment(nongShiInfo.operationTime).format("YYYY-MM-DD"),
code:didStr,
purpose
};
return dataInfo;
}
/**
* 修改农事
* @param reqUser
* @param nzId
* @param param
* @returns
*/
export async function updateNongShi(reqUser, nsId, param) {
let funName = `修改农事`;
eccFormParam(funName, NongShiAdminConfig, param );
eccEnumValue(funName, "nsType", NONGSHITYPE, param.nsType);
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code, purpose} = info;
diKuaiMap[dId] = {code, purpose};
});
if (!diKuaiMap[param.dIdList]) throw new BizError(ERRORENUM.地块不存在, param.dIdList);
let nongShiInfo = await nongshiData.findOne({nsId});
nongShiInfo.nsType = param.nsType;//农资类型
nongShiInfo.dIdList = param.dIdList;//地块id
nongShiInfo.operationTime = param.operationTime; //操作时间
await nongShiInfo.save();
return successResult();
}
/**
* 删除农事
* @param nzId
* @returns
*/
export async function deleteNongShi(nsId) {
let nongShiInfo = await nongshiData.findOne({nsId});
if (!nongShiInfo || !nongShiInfo.nsId) throw new BizError(ERRORENUM.数据不存在);
await nongshiData.deleteData({nsId});
return successResult();
}
/**
* 农资
*/
import moment = require("moment");
import { TABLENAME } from "../../config/dbEnum";
import { NongZiConfig } from "../../config/eccParam";
import { NONGZITYPE, PLANTTYPE, PURPOSE } from "../../config/enum";
import * as nongziData from "../../data/nongzi";
import * as dikuaiData from "../../data/dikuai";
import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../../config/errorEnum";
/**
* 添加农资
* @param reqUser
* @param param
* @returns
*/
export async function addNongZi(reqUser, param) {
let funName = `添加农资`;
eccFormParam(funName, NongZiConfig, param );
eccEnumValue(funName, "nzType", NONGZITYPE, param.nzType);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
//确保添加时地块还在
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
if (!diKuaiMap[param.dIdList]) throw new BizError(ERRORENUM.地块不存在, param.dIdList);
let addInfo = {
nzId:randomId(TABLENAME.农资),
nzType:param.nzType,
dIdList:[param.dIdList],
plantType:param.plantType,
count:param.count,
useTime:param.useTime,
ct:new Date().valueOf()
};
await nongziData.addData(addInfo)
return successResult();
}
/**
* 农资列表 暂无使用
* @param selectStr
* @param dId
* @param nzType
* @param useTime
* @returns
*/
export async function nongZiList(selectStr:string, dId:string, nzType:number, useTime:number) {
let funName = "农资列表";
let param:any = {};
if (nzType) {
eccEnumValue(funName, "nzType", NONGZITYPE, nzType);
param.nzType = nzType;
}
if (dId) {
param.dIdList = {"$in":dId};
}
if (useTime) {
let startMs = moment(useTime).startOf("day").valueOf();
let endMs = moment(useTime).endOf("day").valueOf();
param.useTime = {"$gte":startMs, "$lte":endMs};
}
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
let diKuaiList = await nongziData.selectToParam( param );
let dataList = [];
diKuaiList.forEach(item => {
let {nzType, dIdList, plantType, count, useTime } = item;
let didStr = "";
dIdList.forEach(dId => {
didStr += `${diKuaiMap[dId] || "-"}`;
})
dataList.push({
nzType:changeEnumValue(NONGZITYPE, nzType),
dIdList:didStr,
plantType:changeEnumValue(PLANTTYPE, plantType),
count,
useTime:moment(useTime).format("YYYY-MM-DD")
});
});
return {dataList};
}
/**
* 修改农资
* @param reqUser
* @param nzId
* @param param
* @returns
*/
export async function updateNongZi(reqUser, nzId, param) {
let funName = `修改农资`;
eccFormParam(funName, NongZiConfig, param);
eccEnumValue(funName, "nzType", NONGZITYPE, param.nzType);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
if (!diKuaiMap[param.dIdList]) throw new BizError(ERRORENUM.地块不存在, param.dIdList);
let nongZiInfo = await nongziData.findOne({nzId});
nongZiInfo.nzType = param.nzType;//农资类型
nongZiInfo.dIdList = param.dIdList;//地块id
nongZiInfo.plantType = param.plantType; //种植种类【枚举】 PLANTTYPE
nongZiInfo.count = param.count;//用量
nongZiInfo.useTime = param.useTime; //用时间
await nongZiInfo.save();
return successResult();
}
/**
* 农资回显
* @param nzId
* @returns
*/
export async function nongZiInfo(nzId) {
let nongZiInfo = await nongziData.findOne({nzId});
let dataInfo = {
nzType:nongZiInfo.nzType,//农资类型
// dIdList:didStr, //地块id
dIdList:nongZiInfo.dIdList[0],//地块id
plantType:nongZiInfo.plantType,//种植种类【枚举】 PLANTTYPE
count:nongZiInfo.count,//用量
useTime:nongZiInfo.useTime//时间
};
return {dataInfo}
}
/**
* 农资列表
* @param selectStr
* @param dId
* @param nzType
* @param useTime
* @returns
*/
export async function nongZiListToPage(nzType:number, dId:string, useTime:number, pageNumber:number) {
let funName = "农资列表";
let param:any = {};
if (nzType) {
eccEnumValue(funName, "nzType", NONGZITYPE, nzType);
param.nzType = nzType;
}
if (dId) {
param.dIdList = {"$in":dId};
}
if (useTime) {
let startMs = moment(useTime).startOf("day").valueOf();
let endMs = moment(useTime).endOf("day").valueOf();
param.useTime = {"$gte":startMs, "$lte":endMs};
}
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code, purpose} = info;
diKuaiMap[dId] = {code, purpose};
});
let nongziList = await nongziData.findDataToParamToSortPage( param, {useTime:-1}, pageNumber );
let dataCount = await nongziData.findDataToParamCouant(param);
let dataList = [];
nongziList.forEach(item => {
let {nzId, nzType, dIdList, plantType, count, useTime, ct } = item;
let didStr = "";
let area = "";
let purpose = "";
let size = "";
dIdList.forEach(dId => {
didStr += `${diKuaiMap[dId].code || "-"}`;
purpose = diKuaiMap[dId].purpose;
})
dataList.push({
nzId,
nzType:changeEnumValue(NONGZITYPE, nzType), //农资类型
dIdList:didStr, //地块id
plantType:changeEnumValue(PLANTTYPE, plantType), //种植种类【枚举】 PLANTTYPE
count, //用量
useTime:moment(useTime).format("YYYY-MM-DD"), //时间
ct:moment(ct).format("YYYY-MM-DD"), //创建时间
area, //所属区域
purpose:changeEnumValue(PURPOSE, purpose), //地块用途
size, //地块面积
});
});
return {dataList, dataCount}
}
/**
* 删除农资
* @param nzId
* @returns
*/
export async function deleteNongZi(nzId) {
let nongZiInfo = await nongziData.findOne({nzId});
if (!nongZiInfo || !nongZiInfo.nzId) throw new BizError(ERRORENUM.数据不存在);
await nongziData.deleteData({nzId});
return successResult();
}
/**
* 用户
*/
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 adminUserLogin(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.adminToken = token;
userInfo.adminTokenMs = new Date().valueOf();
await userInfo.save();
return {dataInfo:resultUserInfo};
}
/**
* 登出
* @param userInfo
*/
export async function adminUserLogout(reqUserInfo) {
let userInfo = await findUserInfoByUserId(reqUserInfo.userid);
userInfo.adminToken = getToken(userInfo.loginId);
userInfo.adminTokenMs = new Date().valueOf();
await userInfo.save();
return successResult();
}
/**
* 统计页产量统计
* @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() + 1;
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);
for (let i = 0; i < nongChanPin.length; i++) {
nongChanPin[i]["value"] = Math.ceil(nongChanPin[i]["value"] / 100)/100;
}
//农作物产量
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 年份,如 2025
* @param type 统计类型:1-年,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 {ct, weight} = info;
// let dataYear = moment(ct).year();
// let month = moment(ct).month();
// // 添加年份过滤
// 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);
// for (let i = 0; i < shuiChanPin.length; i++) {
// shuiChanPin[i]["value"] = Math.ceil(shuiChanPin[i]["value"] / 100) / 100;
// }
// // 水产品产量 - 添加年份过滤条件
// 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};
// }
/**
* 销售
*/
import { TABLENAME } from "../../config/dbEnum";
import { XiaoShouConfig } from "../../config/eccParam";
import { PLANTTYPE, XIAOSHOUQUXIANG } from "../../config/enum";
import * as xiaoshouData from "../../data/xiaoshou";
import * as dikuaiData from "../../data/dikuai";
import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
import moment = require("moment");
import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../../config/errorEnum";
/**
* 添加销售
* @param reqUser
* @param param
* @returns
*/
export async function addXiaoShou(reqUser, param) {
let funName = `添加销售`;
eccFormParam(funName, XiaoShouConfig, param );
eccEnumValue(funName, "quXiang", XIAOSHOUQUXIANG, param.quXiang);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
let addInfo = {
xsId:randomId(TABLENAME.销售),
quXiang:param.quXiang,
plantType:param.plantType,
operationTime:param.operationTime,
weight:param.weight,
ct:new Date().valueOf(),
createUser:reqUser.userId
};
await xiaoshouData.addData(addInfo)
return successResult();
}
/**
* 销售列表
* @param quXiang 销售去向
* @param plantType
* @param operationTime
* @returns
*/
export async function xiaoShouList(quXiang:number, plantType:number, operationTime:number, pageNumber:number) {
let funName = "销售列表";
let param:any = {};
if (plantType) {
eccEnumValue(funName, "plantType", PLANTTYPE, plantType);
param.plantType = plantType;
}
if (quXiang) {
eccEnumValue(funName, "quXiang", XIAOSHOUQUXIANG, quXiang);
param.quXiang = quXiang;
}
if (operationTime) {
let startMs = moment(operationTime).startOf("day").valueOf();
let endMs = moment(operationTime).endOf("day").valueOf();
param.operationTime = {"$gte":startMs, "$lte":endMs};
}
let xiaoShouData = await xiaoshouData.findDataToParamToSortPage(param, {operationTime:-1}, pageNumber);
let dataCount = await xiaoshouData.selectCountByParam(param);
let dataList = [];
xiaoShouData.forEach(item => {
let {xsId, plantType, quXiang, operationTime, weight } = item;
dataList.push({
xsId,
plantType:changeEnumValue(PLANTTYPE, plantType),
quXiang:changeEnumValue(XIAOSHOUQUXIANG, quXiang),
operationTime:moment(operationTime).format("YYYY-MM-DD"),
weight,
operationTimeNum:operationTime
});
});
dataList.sort( (a, b) => {
return b.operationTimeNum - a.operationTimeNum;
})
return {dataList, dataCount}
}
/**
* 修改销售
* @param reqUser
* @param nzId
* @param param
* @returns
*/
export async function updateXiaoShou(reqUser, xsId, param) {
let funName = `修改销售`;
eccFormParam(funName, XiaoShouConfig, param );
eccEnumValue(funName, "quXiang", XIAOSHOUQUXIANG, param.quXiang);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
let xiaoShouInfo = await xiaoshouData.selectOne({xsId});
xiaoShouInfo.plantType = param.plantType;//销售种类【枚举】 PLANTTYPE
xiaoShouInfo.quXiang = param.quXiang;//销售去向
xiaoShouInfo.operationTime = param.operationTime;//销售时间
xiaoShouInfo.weight = param.weight;//销售重量
await xiaoShouInfo.save();
return successResult();
}
/**
* 销售回显
* @param nzId
* @returns
*/
export async function xiaoShouInfo(xsId) {
let xiaoShouInfo = await xiaoshouData.selectOne({xsId});
let dataInfo = {
plantType:changeEnumValue(PLANTTYPE, xiaoShouInfo.plantType),//种植种类【枚举】 PLANTTYPE
quXiang:changeEnumValue(XIAOSHOUQUXIANG, xiaoShouInfo.quXiang),//销售去向
operationTime:moment(xiaoShouInfo.operationTime).format("YYYY-MM-DD"),//销售时间
weight:xiaoShouInfo.weight//销售重量
};
return dataInfo;
}
/**
* 删除销售
* @param nzId
* @returns
*/
export async function deleteXiaoShou(xsId) {
let xiaoShouInfo = await xiaoshouData.selectOne({xsId});
if (!xiaoShouInfo || !xiaoShouInfo.xsId) throw new BizError(ERRORENUM.数据不存在);
await xiaoshouData.deleteData({xsId});
return successResult();
}
...@@ -3,19 +3,19 @@ ...@@ -3,19 +3,19 @@
*/ */
import moment = require("moment"); import moment = require("moment");
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../../config/dbEnum";
import { DiKuaiConfig, ZhongYangConfig } from "../config/eccParam"; import { DiKuaiConfig, ZhongYangConfig } from "../../config/eccParam";
import { PLANTTYPE, PLOTTYPE, ZHONGYANGTYPE } from "../config/enum"; import { PLANTTYPE, PLOTTYPE, PURPOSE, ZHONGYANGTYPE } from "../../config/enum";
import * as zhongzhiData from "../data/zhongzhi"; import * as zhongzhiData from "../../data/zhongzhi";
import * as dikuaiData from "../data/dikuai"; import * as dikuaiData from "../../data/dikuai";
import { randomId, successResult } from "../tools/system"; import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../util/verificationEnum"; import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../util/verificationParam"; import { eccFormParam } from "../../util/verificationParam";
import { BizError } from "../util/bizError"; import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../../config/errorEnum";
/** /**
* 种养列表 * 种养列表-暂无使用
* @param plantType 种养类型 * @param plantType 种养类型
* @param selectStr * @param selectStr
* @returns * @returns
...@@ -41,32 +41,76 @@ export async function zhongYangDangQianList(zhongYangType:number, selectStr:stri ...@@ -41,32 +41,76 @@ export async function zhongYangDangQianList(zhongYangType:number, selectStr:stri
} }
export async function zhongYangDangQianListToPage(zhongYangType:number, selectStr:string, pageNumber) { /**
* 种养列表-分页
* @param zhongYangType 种养类型
* @param dId 使用地块
* @param plantTime 种养时间
* @param pageNumber
* @returns
*/
export async function zhongYangDangQianListToPage(zhongYangType:number, plantType:number, dId:number, plantTime:number, pageNumber:number) {
let funName = `当前种养列表`; let funName = `当前种养列表`;
let param:any = { }; let param:any = { plantType:{"$gte":zhongYangType, "$lt":zhongYangType+99} };
if (zhongYangType) { if (plantType) {
eccEnumValue(funName, 'zhongYangType', ZHONGYANGTYPE, zhongYangType); eccEnumValue(funName, "plantType", PLANTTYPE, plantType);
param.plantType = {"$gte":zhongYangType, "$lt":zhongYangType+99}; param.plantType = plantType;
} }
if (dId) {
param.dId = dId;
}
if (plantTime) {
let selectStartTime = moment(plantTime).startOf('day').valueOf();
let selectEndTime = moment(plantTime).endOf("day").valueOf();
// let selectStartTime = moment(plantTime).valueOf();
// let selectEndTime = moment(plantTime).valueOf();
param.plantTime = {"$gte":selectStartTime, "$lte":selectEndTime};
}
/**获取地块名称 */
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code, purpose} = info;
diKuaiMap[dId] = {code, purpose};
});
let zyList = await zhongzhiData.findDataToParamToPage( param, pageNumber ); let zyList = await zhongzhiData.findDataToParamToSortPage( param, {plantTime:-1}, pageNumber );
let dataCount = await zhongzhiData.findDataToParamCouant(param); let dataCount = await zhongzhiData.findDataToParamCouant(param);
let dataList = []; let dataList = [];
zyList.forEach(info => { zyList.forEach(info => {
let code = "-";
let purpose = "-";
if (diKuaiMap[info.dId]) {
code = diKuaiMap[info.dId].code;
purpose = changeEnumValue(PURPOSE, diKuaiMap[info.dId].purpose);
}
let addInfo = { let addInfo = {
zId : info.zId, zId : info.zId,
size : info.size, size : info.size,
plantType : info.plantType, plantType : changeEnumValue(PLANTTYPE, info.plantType),
dId : info.dId, code,
plantTime : info.plantTime plantTime:moment(info.plantTime).format("YYYY-MM-DD"),
purpose,
plantTimeNum:info.plantTime,
ctTime:moment(info.ct).format("YYYY-MM-DD"),
}; };
dataList.push(addInfo); dataList.push(addInfo);
}); });
dataList.sort( (a, b) => {
return b.plantTimeNum - a.plantTimeNum;
})
return {dataList, dataCount}; return {dataList, dataCount};
} }
/**
* 删除种养
* @param zId
* @returns
*/
export async function deleteZhongYang(zId) { export async function deleteZhongYang(zId) {
let zhongYangInfo = await zhongzhiData.selectOne({zId}); let zhongYangInfo = await zhongzhiData.selectOne({zId});
if (!zhongYangInfo || !zhongYangInfo.zId) throw new BizError(ERRORENUM.数据不存在); if (!zhongYangInfo || !zhongYangInfo.zId) throw new BizError(ERRORENUM.数据不存在);
...@@ -91,7 +135,7 @@ export async function addZhongYang(reqUser, param) { ...@@ -91,7 +135,7 @@ export async function addZhongYang(reqUser, param) {
//校验地块大小是否符合扣除 //校验地块大小是否符合扣除
let dkInfo = await dikuaiData.selectOne({dId:param.dId}); let dkInfo = await dikuaiData.selectOne({dId:param.dId});
if (!dkInfo || !dkInfo.dId) throw new BizError(ERRORENUM.地块不存在); if (!dkInfo || !dkInfo.dId) throw new BizError(ERRORENUM.地块不存在);
if (dkInfo.nullSize < param.size) throw new BizError(ERRORENUM.地块大小不足); if (dkInfo.size < param.size) throw new BizError(ERRORENUM.地块大小不足);
let addInfo = { let addInfo = {
zId:randomId(TABLENAME.种植表), zId:randomId(TABLENAME.种植表),
...@@ -114,6 +158,13 @@ export async function addZhongYang(reqUser, param) { ...@@ -114,6 +158,13 @@ export async function addZhongYang(reqUser, param) {
} }
/**
* 修改种养
* @param reqUser
* @param zId
* @param param
* @returns
*/
export async function updateZhongYang(reqUser, zId, param) { export async function updateZhongYang(reqUser, zId, param) {
let funName = `修改种养`; let funName = `修改种养`;
eccFormParam(funName, ZhongYangConfig, param); eccFormParam(funName, ZhongYangConfig, param);
...@@ -121,7 +172,7 @@ export async function updateZhongYang(reqUser, zId, param) { ...@@ -121,7 +172,7 @@ export async function updateZhongYang(reqUser, zId, param) {
let dkInfo = await dikuaiData.selectOne({dId:param.dId}); let dkInfo = await dikuaiData.selectOne({dId:param.dId});
if (!dkInfo || !dkInfo.dId) throw new BizError(ERRORENUM.地块不存在); if (!dkInfo || !dkInfo.dId) throw new BizError(ERRORENUM.地块不存在);
if (dkInfo.nullSize < param.size) throw new BizError(ERRORENUM.地块大小不足); if (dkInfo.size < param.size) throw new BizError(ERRORENUM.地块大小不足);
let zhongYangInfo = await zhongzhiData.selectOne({zId}); let zhongYangInfo = await zhongzhiData.selectOne({zId});
...@@ -136,6 +187,11 @@ export async function updateZhongYang(reqUser, zId, param) { ...@@ -136,6 +187,11 @@ export async function updateZhongYang(reqUser, zId, param) {
} }
/**
* 种养回显
* @param zId
* @returns
*/
export async function zhognYangInfo(zId) { export async function zhognYangInfo(zId) {
let dikuaiInfo = await zhongzhiData.selectOne({zId}); let dikuaiInfo = await zhongzhiData.selectOne({zId});
...@@ -151,7 +207,7 @@ export async function zhognYangInfo(zId) { ...@@ -151,7 +207,7 @@ export async function zhognYangInfo(zId) {
/** /**
* 种养记录 * 种养记录-暂无使用
* @param zhongYangType * @param zhongYangType
* @param selectStr * @param selectStr
* @param plantType * @param plantType
...@@ -171,9 +227,9 @@ export async function zhongYangJiLu(zhongYangType:number, selectStr:string, plan ...@@ -171,9 +227,9 @@ export async function zhongYangJiLu(zhongYangType:number, selectStr:string, plan
param.dId = dId; param.dId = dId;
} }
if (plantTime) { if (plantTime) {
let selectStartTime = moment(plantTime).startOf('month').valueOf(); let selectStartTime = moment(plantTime).startOf('day').valueOf();
let selectEndTime = moment(plantTime).endOf("month").valueOf(); let selectEndTime = moment(plantTime).endOf("day").valueOf();
param.plantTime = {"$gt":selectStartTime, "$lt":selectEndTime}; param.plantTime = {"$gte":selectStartTime, "$lte":selectEndTime};
} }
/**获取地块名称 */ /**获取地块名称 */
...@@ -196,4 +252,6 @@ export async function zhongYangJiLu(zhongYangType:number, selectStr:string, plan ...@@ -196,4 +252,6 @@ export async function zhongYangJiLu(zhongYangType:number, selectStr:string, plan
}); });
return {dataList}; return {dataList};
} }
\ No newline at end of file
...@@ -14,12 +14,11 @@ import { changeEnumValue } from "../util/verificationEnum"; ...@@ -14,12 +14,11 @@ import { changeEnumValue } from "../util/verificationEnum";
import { selectChanLiangOfMonth } from "../data/caishou"; import { selectChanLiangOfMonth } from "../data/caishou";
export async function getDataOut() { export async function getDataOut() {
let 种植总面积 = 0; let 种植总面积 = 0;
let 粮田面积 = 0; let 粮田面积 = 0;
let 菜田面积 = 0; let 菜田面积 = 0;
let 作物数量 = 0; isEnd: 0 let 作物数量 = 0;
let zhongZhiList = await zhongZhiTongJiCount({ isEnd: 0, plantType:{"$lt":PLANTTYPE.鲈鱼}}); let zhongZhiList = await zhongZhiTongJiCount({ isEnd: 0, plantType:{"$lt":PLANTTYPE.鲈鱼}});
let zhongZhiZuoWuList = []; //结果 let zhongZhiZuoWuList = []; //结果
...@@ -73,178 +72,479 @@ export async function getDataOut() { ...@@ -73,178 +72,479 @@ export async function getDataOut() {
}); });
let nongZiList = Object.values(农资情况Map); //结果 let nongZiList = Object.values(农资情况Map); //结果
// 获取今年的时间范围
const currentYear = moment().year();
const startOfYear = moment().startOf('year');
const endOfYear = moment().endOf('year');
// 获取近两个月的时间范围(只用于趋势图)
const startOfTwoMonthsAgo = moment().subtract(2, 'months');
const endOfCurrentMonth = moment();
// 1. 肥料用药情况趋势图(feiliaoyongyaoqingkuang)改为近两个月
let nongZiAllMonthList = await nongziData.selectToParam({}); let nongZiAllMonthList = await nongziData.selectToParam({});
let nongZiCountInfo = {};//肥料用药情况 let nongZiCountInfo = {};
nongZiCountInfo[NONGZITYPE.农药] = {}; nongZiCountInfo[NONGZITYPE.农药] = {};
nongZiCountInfo[NONGZITYPE.肥料] = {}; nongZiCountInfo[NONGZITYPE.肥料] = {};
// let lastMonthMs = moment().startOf('M').valueOf()
nongZiAllMonthList.forEach(info => { nongZiAllMonthList.forEach(info => {
let {useTime, count, nzType} = info; let { useTime, count, nzType } = info;
// if (useTime < lastMonthMs ) return const date = moment(useTime);
// 只保留近两个月内的数据(趋势图用)
if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
let keyNum = 1; let keyNum = 1;
switch (nzType) { switch (nzType) {
case NONGZITYPE.磷肥: case NONGZITYPE.磷肥:
case NONGZITYPE.水溶肥: case NONGZITYPE.水溶肥:
case NONGZITYPE.有机肥: case NONGZITYPE.有机肥:
case NONGZITYPE.复合肥:keyNum = NONGZITYPE.肥料; break; case NONGZITYPE.复合肥:
case NONGZITYPE.好力克: keyNum = NONGZITYPE.肥料; break;
case NONGZITYPE.好力克:
case NONGZITYPE.奥罗: case NONGZITYPE.奥罗:
case NONGZITYPE.银法利: case NONGZITYPE.银法利:
case NONGZITYPE.啶虫脒: case NONGZITYPE.啶虫脒:
case NONGZITYPE.龙克均: case NONGZITYPE.龙克均:
case NONGZITYPE.三令: case NONGZITYPE.三令:
case NONGZITYPE.追肥保果素:keyNum = NONGZITYPE.农药; break; case NONGZITYPE.追肥保果素:
keyNum = NONGZITYPE.农药; break;
} }
if (nongZiCountInfo[keyNum]) { if (nongZiCountInfo[keyNum]) {
let keyStr = getKey(useTime); let keyStr = date.format('YYMMDD');
if (!nongZiCountInfo[keyNum][keyStr]) nongZiCountInfo[keyNum][keyStr] = 0; if (!nongZiCountInfo[keyNum][keyStr]) nongZiCountInfo[keyNum][keyStr] = 0;
nongZiCountInfo[keyNum][keyStr] += count; nongZiCountInfo[keyNum][keyStr] += count;
}; }
}); });
let 肥料 = [];
// 收集所有有数据的日期(肥料和用药)
let allDatesSet = new Set();
Object.keys(nongZiCountInfo[NONGZITYPE.肥料] || {}).forEach(dateStr => allDatesSet.add(dateStr));
Object.keys(nongZiCountInfo[NONGZITYPE.农药] || {}).forEach(dateStr => allDatesSet.add(dateStr));
let sortedDates = Array.from(allDatesSet).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
let 肥料 = [];
let 用药 = []; let 用药 = [];
let allKeyList = getAllKey(new Date().valueOf()); for (let i = 0; i < sortedDates.length; i++) {
for (let i = 0; i < allKeyList.length; i++) { let key = sortedDates[i];
let key = allKeyList[i];
肥料.push({ 肥料.push({
key, key,
value:nongZiCountInfo[NONGZITYPE.肥料][key] || 0 value: nongZiCountInfo[NONGZITYPE.肥料][key] || 0
}); });
用药.push({ 用药.push({
key, key,
value:nongZiCountInfo[NONGZITYPE.农药][key] || 0 value: nongZiCountInfo[NONGZITYPE.农药][key] || 0
}); });
} }
let feiliaoyongyaoqingkuang = [ //结果 let feiliaoyongyaoqingkuang = [
{name:"肥料", data:肥料}, { name: "肥料", data: 肥料 },
{name:"用药", data:用药}, { name: "用药", data: 用药 },
]; ];
let nongShiCount = await nongshiData.selectCountByParam({}); //结果 // 2. 农事操作趋势图(nongShiList)改为近两个月,农事操作总数改为今年数据
let nongshiTyptList = await nongshiData.selectToParam({}); let nongshiTyptList = await nongshiData.selectToParam({});
let nongShiCount = 0; // 改为统计今年的农事操作数量
let 操作趋势 = {}; let 操作趋势 = {};
let nongShiList = [];//结果 let nongShiList = [];
nongshiTyptList.forEach(info => { nongshiTyptList.forEach(info => {
let {nsType, operationTime} = info; let { operationTime } = info;
let key = getKey(operationTime); const date = moment(operationTime);
// 统计今年的农事操作总数
if (date >= startOfYear && date <= endOfYear) {
nongShiCount += 1;
}
// 趋势图数据:只保留近两个月内的数据
if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
let key = date.format('YYMMDD');
if (!操作趋势[key]) 操作趋势[key] = 0; if (!操作趋势[key]) 操作趋势[key] = 0;
操作趋势[key] += 1;; 操作趋势[key] += 1;
}); });
for (let i= 0; i < allKeyList.length; i++) {
let key = allKeyList[i]; // 按日期排序
let nongShiDates = Object.keys(操作趋势).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
for (let i = 0; i < nongShiDates.length; i++) {
let key = nongShiDates[i];
nongShiList.push({ nongShiList.push({
key, key,
value:操作趋势[key] || 0 value: 操作趋势[key] || 0
}); });
} }
// 3. 作物产量趋势图(chanLiangList)改为近两个月,但汇总数据保持全年
let monthDBList = await caishouData.selectToParam({plantType:{"$lt":PLANTTYPE.鲈鱼}}); let monthDBList = await caishouData.selectToParam({ plantType: { "$lt": PLANTTYPE.鲈鱼 } });
let 作物产量Map = {}; let 作物产量Map = {};
let 今年产量总数 = 0; let 今年产量总数 = 0;
let 去年产量总数 = 0;
monthDBList.forEach(info => { monthDBList.forEach(info => {
let {ct, weight} = info; let { ct, weight } = info;
if (new Date(ct).getFullYear() == 2025) 今年产量总数 += weight; const date = moment(ct);
let key = getKey(ct)
// 汇总数据:全年统计
if (date.year() === currentYear) {
今年产量总数 += weight;
} else if (date.year() === currentYear - 1) {
去年产量总数 += weight;
}
// 趋势图数据:只保留近两个月内的数据
if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
let key = date.format('YYMMDD');
if (!作物产量Map[key]) 作物产量Map[key] = 0; if (!作物产量Map[key]) 作物产量Map[key] = 0;
作物产量Map[key] += weight; 作物产量Map[key] += weight;
}); });
// 按日期排序
let chanLiangDates = Object.keys(作物产量Map).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
let 今年 = []; let 今年 = [];
let 去年 = []; let 去年 = [];
for (let i = 0; i < chanLiangDates.length; i++) {
let key = chanLiangDates[i];
let 去年产量总数 = 0; let changeValue = 作物产量Map[key] ? Math.round(作物产量Map[key] / 1000 * 100) / 100 : 0;
for (let i =0 ; i < allKeyList.length; i++) { 今年.push({ key: key, value: changeValue });
let key = allKeyList[i]; 去年.push({ key: key, value: 0 }); // 若需去年数据请自行补充逻辑
let changeValue = 作物产量Map[key] ? Math.round(作物产量Map[key]/1000*100)/100 : 0;
今年.push({key: key, value:changeValue || 0 });
去年.push({key: key, value:0 });
} }
let chanLiangList = [ //结果 let chanLiangList = [
{name:"今年", data:今年}, { name: "今年", data: 今年 },
{name:"去年", data:去年}, { name: "去年", data: 去年 },
]; ];
let 产量年同比 = 0; // 4. 销售趋势图(lastMonthXiaoShouList)改为近两个月,销售总量改为今年数据
if (今年产量总数 && 去年产量总数) {
产量年同比 = Math.round((今年产量总数 - 去年产量总数)/ 去年产量总数*10000)/100
}
let chanLiangStatisList = [//结果
{key:"作物产量", value:Math.round(今年产量总数/1000*100)/100},
{key:"同比", value:产量年同比}
];
let xiaoshouStartMs = moment().subtract(1, "months").startOf('month').valueOf();
let xiaoshouEndMs = moment().startOf('month').valueOf();
let xiaoshouDBList = await xiaoshouData.selectToParam({}); let xiaoshouDBList = await xiaoshouData.selectToParam({});
let lastMonthXiaoShou = 0; // 改为统计今年的销售总量
let lastMonthXiaoShou = 0;
let lastMonthXiaoShouMap = {}; let lastMonthXiaoShouMap = {};
xiaoshouDBList.forEach(info => { xiaoshouDBList.forEach(info => {
let {operationTime, weight} = info; let { operationTime, weight } = info;
lastMonthXiaoShou += weight; const date = moment(operationTime);
let key = getKey(operationTime);
// 汇总数据:统计今年的销售总量
if (date >= startOfYear && date <= endOfYear) {
lastMonthXiaoShou += weight;
}
// 趋势图数据:只保留近两个月内的数据
if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
let key = date.format('YYMMDD');
if (!lastMonthXiaoShouMap[key]) lastMonthXiaoShouMap[key] = 0; if (!lastMonthXiaoShouMap[key]) lastMonthXiaoShouMap[key] = 0;
lastMonthXiaoShouMap[key] += weight; lastMonthXiaoShouMap[key] += weight;
}); });
// let lastMonthXiaoShouList = Object.values(lastMonthXiaoShouMap);//结果
// 按日期排序
let xiaoshouDates = Object.keys(lastMonthXiaoShouMap).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
let lastMonthXiaoShouList = []; let lastMonthXiaoShouList = [];
let allxiaoshouKeyList = getAllKey(new Date().valueOf()); for (let i = 0; i < xiaoshouDates.length; i++) {
for (let i = 0; i < allxiaoshouKeyList.length; i++) { let key = xiaoshouDates[i];
let key = allxiaoshouKeyList[i];
let value = lastMonthXiaoShouMap[key] || 0; let value = lastMonthXiaoShouMap[key] || 0;
lastMonthXiaoShouList.push({ lastMonthXiaoShouList.push({
key, key,
value:Math.round(value/1000*100)/100, value: Math.round(value / 1000 * 100) / 100,
}) });
}
// 产量统计(全年数据)- chanLiangStatisList[0].value 已经是今年数据,无需修改
let 产量年同比 = 0;
if (今年产量总数 && 去年产量总数) {
产量年同比 = Math.round((今年产量总数 - 去年产量总数)/ 去年产量总数*10000)/100
} }
let chanLiangStatisList = [//结果
{key:"作物产量", value:Math.round(今年产量总数/1000*100)/100},
{key:"同比", value:产量年同比}
];
// 返回结果
return { return {
zhongZhiZuoWuList, zhongZhiZuoWuList,
zhongZhiTypeList, zhongZhiTypeList,
nongZiList, nongZiList,
feiliaoyongyaoqingkuang, feiliaoyongyaoqingkuang,
nongShiList, nongShiList,
nongShiCount, nongShiCount, // 现在是今年的农事操作总数
chanLiangList, chanLiangList,
chanLiangStatisList, chanLiangStatisList, // 第一个值已经是今年作物产量
lastMonthXiaoShou:Math.round(lastMonthXiaoShou/1000*100)/100, lastMonthXiaoShou: Math.round(lastMonthXiaoShou / 1000 * 100) / 100, // 现在是今年的销售总量
lastMonthXiaoShouList lastMonthXiaoShouList
} };
} }
// export async function getDataOut() {
// let 种植总面积 = 0;
// let 粮田面积 = 0;
// let 菜田面积 = 0;
// let 作物数量 = 0;
// let zhongZhiList = await zhongZhiTongJiCount({ isEnd: 0, plantType:{"$lt":PLANTTYPE.鲈鱼}});
// let zhongZhiZuoWuList = []; //结果
// zhongZhiList.forEach(info => {
// let {_id, sizeCount} = info;
// 种植总面积 += sizeCount;
// if (_id == LIANGSHI.水稻 || _id == LIANGSHI.蚕豆) {
// 粮田面积 += sizeCount;
// } else if (_id < 100) {
// 菜田面积 += sizeCount;
// }
// if ( !(_id > 100 && _id < 200)) {
// 作物数量 += 1;
// zhongZhiZuoWuList.push({key:changeEnumValue(PLANTTYPE, _id), value:sizeCount});
// }
// });
// let diKuaiInfo = await diKuaiSizeCountByParam({plotType:PLOTTYPE.地块});
// let 地块使用率 = 0;
// if (diKuaiInfo.totalSize && diKuaiInfo.totalUseSize) {
// 地块使用率 = Math.round(diKuaiInfo.totalUseSize/diKuaiInfo.totalSize * 100);
// }
// let zhongZhiTypeList = [
// {key:"种植总面积", value:731},//种植总面积
// {key:"菜田面积", value:370},//菜田面积
// {key:"粮田面积", value:361},
// {key:"作物数量", value:作物数量},
// {key:"地块使用率", value:地块使用率},
// ]; //结果
// let 农资类型 = await nongziData.statisNongZiType();
// let 农资情况Map = {};
// 农资情况Map[NONGZITYPE.肥料] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.肥料), value:0, unit:"KG"};
// 农资情况Map[NONGZITYPE.农药] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.农药), value:0, unit:"G"};
// 农资情况Map[NONGZITYPE.药剂] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.药剂), value:0, unit:"ML"};
// 农资类型.forEach(info => {
// let {_id, count} = info;
// switch (_id) {
// case NONGZITYPE.磷肥:
// case NONGZITYPE.水溶肥:
// case NONGZITYPE.有机肥:
// case NONGZITYPE.复合肥:农资情况Map[NONGZITYPE.肥料].value += count;break;
// case NONGZITYPE.好力克:
// case NONGZITYPE.奥罗:
// case NONGZITYPE.银法利:
// case NONGZITYPE.啶虫脒:
// case NONGZITYPE.龙克均:
// case NONGZITYPE.三令: 农资情况Map[NONGZITYPE.药剂].value += count; break;
// case NONGZITYPE.追肥保果素:农资情况Map[NONGZITYPE.农药].value += count;break;
// }
// });
// let nongZiList = Object.values(农资情况Map); //结果
// // 获取近两个月的时间范围(只用于趋势图)
// const startOfTwoMonthsAgo = moment().subtract(2, 'months');
// const endOfCurrentMonth = moment();
// // 1. 肥料用药情况趋势图(feiliaoyongyaoqingkuang)改为近两个月
// let nongZiAllMonthList = await nongziData.selectToParam({});
// let nongZiCountInfo = {};
// nongZiCountInfo[NONGZITYPE.农药] = {};
// nongZiCountInfo[NONGZITYPE.肥料] = {};
// nongZiAllMonthList.forEach(info => {
// let { useTime, count, nzType } = info;
// const date = moment(useTime);
// // 只保留近两个月内的数据(趋势图用)
// if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
// let keyNum = 1;
// switch (nzType) {
// case NONGZITYPE.磷肥:
// case NONGZITYPE.水溶肥:
// case NONGZITYPE.有机肥:
// case NONGZITYPE.复合肥:
// keyNum = NONGZITYPE.肥料; break;
// case NONGZITYPE.好力克:
// case NONGZITYPE.奥罗:
// case NONGZITYPE.银法利:
// case NONGZITYPE.啶虫脒:
// case NONGZITYPE.龙克均:
// case NONGZITYPE.三令:
// case NONGZITYPE.追肥保果素:
// keyNum = NONGZITYPE.农药; break;
// }
// if (nongZiCountInfo[keyNum]) {
// let keyStr = date.format('YYMMDD');
// if (!nongZiCountInfo[keyNum][keyStr]) nongZiCountInfo[keyNum][keyStr] = 0;
// nongZiCountInfo[keyNum][keyStr] += count;
// }
// });
// // 收集所有有数据的日期(肥料和用药)
// let allDatesSet = new Set();
// Object.keys(nongZiCountInfo[NONGZITYPE.肥料] || {}).forEach(dateStr => allDatesSet.add(dateStr));
// Object.keys(nongZiCountInfo[NONGZITYPE.农药] || {}).forEach(dateStr => allDatesSet.add(dateStr));
// let sortedDates = Array.from(allDatesSet).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
// let 肥料 = [];
// let 用药 = [];
// for (let i = 0; i < sortedDates.length; i++) {
// let key = sortedDates[i];
// 肥料.push({
// key,
// value: nongZiCountInfo[NONGZITYPE.肥料][key] || 0
// });
// 用药.push({
// key,
// value: nongZiCountInfo[NONGZITYPE.农药][key] || 0
// });
// }
// let feiliaoyongyaoqingkuang = [
// { name: "肥料", data: 肥料 },
// { name: "用药", data: 用药 },
// ];
// // 2. 农事操作趋势图(nongShiList)改为近两个月
// let nongshiTyptList = await nongshiData.selectToParam({});
// let nongShiCount = await nongshiData.selectCountByParam({}); //结果
// let 操作趋势 = {};
// let nongShiList = [];
// nongshiTyptList.forEach(info => {
// let { operationTime } = info;
// const date = moment(operationTime);
// // 只保留近两个月内的数据(趋势图用)
// if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
// let key = date.format('YYMMDD');
// if (!操作趋势[key]) 操作趋势[key] = 0;
// 操作趋势[key] += 1;
// });
// // 按日期排序
// let nongShiDates = Object.keys(操作趋势).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
// for (let i = 0; i < nongShiDates.length; i++) {
// let key = nongShiDates[i];
// nongShiList.push({
// key,
// value: 操作趋势[key] || 0
// });
// }
// // 3. 作物产量趋势图(chanLiangList)改为近两个月,但汇总数据保持全年
// let monthDBList = await caishouData.selectToParam({ plantType: { "$lt": PLANTTYPE.鲈鱼 } });
// let 作物产量Map = {};
// let 今年产量总数 = 0;
// let 去年产量总数 = 0;
// monthDBList.forEach(info => {
// let { ct, weight } = info;
// const date = moment(ct);
// // 汇总数据:全年统计
// if (date.year() === 2025) {
// 今年产量总数 += weight;
// } else if (date.year() === 2024) {
// 去年产量总数 += weight;
// }
// // 趋势图数据:只保留近两个月内的数据
// if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
// let key = date.format('YYMMDD');
// if (!作物产量Map[key]) 作物产量Map[key] = 0;
// 作物产量Map[key] += weight;
// });
// // 按日期排序
// let chanLiangDates = Object.keys(作物产量Map).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
// let 今年 = [];
// let 去年 = [];
// for (let i = 0; i < chanLiangDates.length; i++) {
// let key = chanLiangDates[i];
// let changeValue = 作物产量Map[key] ? Math.round(作物产量Map[key] / 1000 * 100) / 100 : 0;
// 今年.push({ key: key, value: changeValue });
// 去年.push({ key: key, value: 0 }); // 若需去年数据请自行补充逻辑
// }
// let chanLiangList = [
// { name: "今年", data: 今年 },
// { name: "去年", data: 去年 },
// ];
// // 4. 销售趋势图(lastMonthXiaoShouList)改为近两个月
// let xiaoshouDBList = await xiaoshouData.selectToParam({});
// let lastMonthXiaoShou = 0;
// let lastMonthXiaoShouMap = {};
// xiaoshouDBList.forEach(info => {
// let { operationTime, weight } = info;
// const date = moment(operationTime);
// // 汇总数据:全年统计
// lastMonthXiaoShou += weight;
// // 趋势图数据:只保留近两个月内的数据
// if (date < startOfTwoMonthsAgo || date > endOfCurrentMonth) return;
// let key = date.format('YYMMDD');
// if (!lastMonthXiaoShouMap[key]) lastMonthXiaoShouMap[key] = 0;
// lastMonthXiaoShouMap[key] += weight;
// });
// // 按日期排序
// let xiaoshouDates = Object.keys(lastMonthXiaoShouMap).sort((a, b) => moment(a, 'YYMMDD').valueOf() - moment(b, 'YYMMDD').valueOf());
// let lastMonthXiaoShouList = [];
// for (let i = 0; i < xiaoshouDates.length; i++) {
// let key = xiaoshouDates[i];
// let value = lastMonthXiaoShouMap[key] || 0;
// lastMonthXiaoShouList.push({
// key,
// value: Math.round(value / 1000 * 100) / 100,
// });
// }
// // 产量统计(全年数据)
// let 产量年同比 = 0;
// if (今年产量总数 && 去年产量总数) {
// 产量年同比 = Math.round((今年产量总数 - 去年产量总数)/ 去年产量总数*10000)/100
// }
// let chanLiangStatisList = [//结果
// {key:"作物产量", value:Math.round(今年产量总数/1000*100)/100},
// {key:"同比", value:产量年同比}
// ];
// // 返回结果
// return {
// zhongZhiZuoWuList,
// zhongZhiTypeList,
// nongZiList,
// feiliaoyongyaoqingkuang,
// nongShiList,
// nongShiCount,
// chanLiangList,
// chanLiangStatisList,
// lastMonthXiaoShou: Math.round(lastMonthXiaoShou / 1000 * 100) / 100,
// lastMonthXiaoShouList
// };
// }
function getKey(timestamp) { function getKey(timestamp) {
const date = new Date(timestamp); const date = new Date(timestamp);
// 计算当前时间所在周期的周一(UTC时间) // 计算当前时间所在周期的周一(UTC时间)
const day = date.getUTCDay(); // 0(周日)到6(周六) const day = date.getUTCDay(); // 0(周日)到6(周六)
const diff = day === 0 ? 6 : day - 1; // 计算到上周一的差值 const diff = day === 0 ? 6 : day - 1; // 计算到上周一的差值
const start = new Date(date); const start = new Date(date);
start.setUTCDate(start.getUTCDate() - diff); // 回退到周一 start.setUTCDate(start.getUTCDate() - diff); // 回退到周一
start.setUTCHours(0, 0, 0, 0); // 设置为UTC零点 start.setUTCHours(0, 0, 0, 0); // 设置为UTC零点
// 计算周期结束时间(周日)
const end = new Date(start);
end.setUTCDate(end.getUTCDate() + 6); // 周一 + 6天 = 周日
end.setUTCHours(23, 59, 59, 999); // 设置为周日最后一刻(可选)
// 计算周期结束时间(周日)
return `${moment(start).format("M/D")}-${moment(end).format("M/D")}`; const end = new Date(start);
end.setUTCDate(end.getUTCDate() + 6); // 周一 + 6天 = 周日
end.setUTCHours(23, 59, 59, 999); // 设置为周日最后一刻(可选)
return `${moment(start).format("M/D")}-${moment(end).format("M/D")}`;
} }
function getAllKey(timestamp) { function getAllKey(timestamp) {
let cycles = []; let cycles = [];
for (let i = 7; i >=0 ; i--) { for (let i = 7; i >=0 ; i--) {
let ms = moment(timestamp).subtract(i*7, 'd').valueOf(); let ms = moment(timestamp).subtract(i*7, 'd').valueOf();
cycles.push(getKey(ms)) cycles.push(getKey(ms))
} }
return cycles; return cycles;
} }
export async function getGuiYuOut() { export async function getGuiYuOut() {
...@@ -269,8 +569,6 @@ export async function getGuiYuOut() { ...@@ -269,8 +569,6 @@ export async function getGuiYuOut() {
{key:"鱼苗养殖", value:`${count}万尾`}, {key:"鱼苗养殖", value:`${count}万尾`},
]; ];
let xiaoshouList = await xiaoshouData.selectToParam({plantType:{"$gt":100, "$lt":200}}); let xiaoshouList = await xiaoshouData.selectToParam({plantType:{"$gt":100, "$lt":200}});
let xsjl = []; let xsjl = [];
xiaoshouList.forEach(info => { xiaoshouList.forEach(info => {
......
/**
* 用户
*/
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 userAdminLogin(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.adminToken = token;
userInfo.adminTokenMs = new Date().valueOf();
await userInfo.save();
return {dataInfo:resultUserInfo};
}
/**
* 登出
* @param userInfo
*/
export async function userAdminLogout(reqUserInfo) {
let userInfo = await findUserInfoByUserId(reqUserInfo.userId);
userInfo.token = getToken(userInfo.loginId);
userInfo.tokenMs = new Date().valueOf();
await userInfo.save();
return successResult();
}
/**
* 登录
* @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
* @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);
for (let i = 0; i < nongChanPin.length; i++) {
nongChanPin[i]["value"] = Math.ceil(nongChanPin[i]["value"] / 100)/100;
}
//农作物产量
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 type
* @returns
*/
export async function homePageStatisXiaoShou() {
let thisYear = new Date().getFullYear();
//产量
let monthDBList = await selectXiaoShouOfMonth({plantType:{"$lt":PLANTTYPE.鲈鱼}});
let distinctMap = {};
let count = 0;
let lastYearCount = 0;
monthDBList.forEach(info => {
let {year, month, totalWeight} = info;
let strKey = `${year}-${month}`;
if (!distinctMap[strKey]) distinctMap[strKey] = {key:strKey, value:0};
distinctMap[strKey].value += totalWeight;
if (thisYear == year) count += totalWeight;
else if (year == (thisYear-1)) lastYearCount += totalWeight;
});
let xiaoShouList = Object.values(distinctMap);
let xiaoShouDBList = await selectXiaoShouOfzuoWu({plantType:{"$lt":PLANTTYPE.鲈鱼}});
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({plantType:{"$gte":PLANTTYPE.鲈鱼}});
let shuiChanDistinctMap = {};
let shuiChanCount = 0;
let suiChanLastYearCount = 0;
shuiChanMonthDBList.forEach(info => {
let {year, month, totalWeight} = info;
let strKey = `${year}-${month}`;
if (!shuiChanDistinctMap[strKey]) shuiChanDistinctMap[strKey] = {key:strKey, value:0};
shuiChanDistinctMap[strKey].value += totalWeight;
if (thisYear == year) shuiChanCount += totalWeight;
else if (year == (thisYear-1)) suiChanLastYearCount += totalWeight;
});
let suiChanxiaoShouList = Object.values(shuiChanDistinctMap);
let shuiChanXiaoShouDBList = await selectXiaoShouOfzuoWu({plantType:{"$gte":PLANTTYPE.鲈鱼}});
let shuiChanxiaoShou = [];
shuiChanXiaoShouDBList.forEach(info => {
let {_id, totalWeight} = info;
shuiChanxiaoShou.push({
key:changeEnumValue(PLANTTYPE, _id),
value:Math.ceil(totalWeight/10)/100
});
});
shuiChanxiaoShou.sort((a,b) =>{return b.value - a.value});
let dataInfo = {
zuoWu:{
count:Math.ceil(count/10)/100,
mom:Math.round( (count-lastYearCount)/lastYearCount * 1000 )/10,
xiaoShou:xiaoShouList,
zuoWu:xiaoShou
},
shuiChan:{
count:Math.ceil(shuiChanCount/10)/100,
mom:Math.round( (shuiChanCount-suiChanLastYearCount)/suiChanLastYearCount * 1000 )/10,
xiaoShou:suiChanxiaoShouList,
shuiChan:shuiChanxiaoShou
}
};
return {dataInfo};
}
/**
* 登录
* @param loginId
* @param pwd
* @returns
*/
export async function adminUserLogin(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.adminToken = token;
userInfo.adminTokenMs = new Date().valueOf();
await userInfo.save();
return {dataInfo:resultUserInfo};
}
/**
* 登出
* @param userInfo
*/
export async function adminUserLogout(reqUserInfo) {
let userInfo = await findUserInfoByUserId(reqUserInfo.userId);
userInfo.adminToken = getToken(userInfo.loginId);
userInfo.adminTokenMs = new Date().valueOf();
await userInfo.save();
return successResult();
}
\ No newline at end of file
/** /**
* 采收逻辑 * 小程序-采收逻辑
*/ */
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../../config/dbEnum";
import { CaiShouConfig } from "../config/eccParam"; import { CaiShouConfig } from "../../config/eccParam";
import { PLANTTYPE, ZHONGYANGTYPE } from "../config/enum"; import { PLANTTYPE, ZHONGYANGTYPE } from "../../config/enum";
import * as caishouData from "../data/caishou"; import * as caishouData from "../../data/caishou";
import * as dikuaiData from "../data/dikuai"; import * as dikuaiData from "../../data/dikuai";
import * as zhongzhiData from "../data/zhongzhi"; import * as zhongzhiData from "../../data/zhongzhi";
import { randomId, successResult } from "../tools/system"; import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../util/verificationEnum"; import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../util/verificationParam"; import { eccFormParam } from "../../util/verificationParam";
import moment = require("moment"); import moment = require("moment");
...@@ -47,7 +47,7 @@ export async function addCaiShou(reqUser, param) { ...@@ -47,7 +47,7 @@ export async function addCaiShou(reqUser, param) {
//添加采收记录 //添加采收记录
let addInfo = { let addInfo = {
csId, csId,
dIdList:param.dIdList, dIdList:param.dId,
plantType:param.plantType, plantType:param.plantType,
operationTime:param.operationTime, operationTime:param.operationTime,
weight:param.weight, weight:param.weight,
...@@ -83,9 +83,9 @@ export async function caiShouList(zhongYangType:number, selectStr:string, dId:st ...@@ -83,9 +83,9 @@ export async function caiShouList(zhongYangType:number, selectStr:string, dId:st
param.dIdList = {"$in":dId}; param.dIdList = {"$in":dId};
} }
if (operationTime) { if (operationTime) {
let startMs = moment(operationTime).startOf("month").valueOf(); let startMs = moment(operationTime).startOf("day").valueOf();
let endMs = moment(operationTime).endOf("month").valueOf(); let endMs = moment(operationTime).endOf("day").valueOf();
param.useTime = {"$gt":startMs, "$lt":endMs}; param.useTime = {"$gte":startMs, "$lte":endMs};
} }
let dikuaiList = await dikuaiData.selectToParam({}); let dikuaiList = await dikuaiData.selectToParam({});
...@@ -98,19 +98,28 @@ export async function caiShouList(zhongYangType:number, selectStr:string, dId:st ...@@ -98,19 +98,28 @@ export async function caiShouList(zhongYangType:number, selectStr:string, dId:st
let nongShiList = await caishouData.selectToParam(param); let nongShiList = await caishouData.selectToParam(param);
let dataList = []; let dataList = [];
nongShiList.forEach(item => { nongShiList.forEach(item => {
let {plantType, dIdList, operationTime, weight } = item; let {plantType, dIdList, operationTime, weight, ct } = item;
let dIds = dIdList; let dIds = dIdList;
let didStr = ""; let didStr = "";
dIds.forEach(dId => { dIds.forEach(dId => {
didStr += `${diKuaiMap[dId]} `; didStr += `${diKuaiMap[dId]} `;
}); });
let operationTimeNum;
if (operationTime) operationTimeNum = operationTime;
else operationTimeNum = ct
dataList.push({ dataList.push({
plantType:changeEnumValue(PLANTTYPE, plantType), plantType:changeEnumValue(PLANTTYPE, plantType),
dIdList:didStr, dIdList:didStr,
operationTime:moment(operationTime).format("YYYY-MM-DD"), operationTime:moment(operationTimeNum).format("YYYY-MM-DD"),
weight weight,
operationTimeNum
}); });
}); });
dataList.sort( (a, b) => {
return b.operationTimeNum - a.operationTimeNum;
})
return {dataList} return {dataList}
} }
\ No newline at end of file
/**
* 地块
*/
import moment = require("moment");
import { TABLENAME } from "../../config/dbEnum";
import { DiKuaiConfig, YangZhiChiConfig } from "../../config/eccParam";
import { AREARANGE, PLANTTYPE, PLOTTYPE, PURPOSE, ZHONGYANGTYPE } from "../../config/enum";
import { ERRORENUM } from "../../config/errorEnum";
import * as dikuaiData from "../../data/dikuai";
import { randomId, successResult } from "../../tools/system";
import { BizError } from "../../util/bizError";
import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
/**
* 添加地块
* @param reqUser
* @param plotType
* @param param
* @returns
*/
export async function addDiKuai(reqUser, plotType, param) {
let funName = `添加地块`;
eccEnumValue(funName, "plottype", PLOTTYPE, plotType);
let purpose = PURPOSE.养殖;
if (plotType == PLOTTYPE.地块) {
eccFormParam(funName+changeEnumValue(PLOTTYPE, plotType), DiKuaiConfig, param);
eccEnumValue(funName, "param=>type", PURPOSE, param.type);
purpose = param.type;
} else {
eccFormParam(funName+changeEnumValue(PLOTTYPE, plotType), YangZhiChiConfig, param);
}
let addInfo = {
dId:randomId(TABLENAME.地块表),
size:param.size,
useSize:0,//使用大小默认0
nullSize:param.size,//初始可使用大小为大小
code:param.code,
name:param.code, //地块名称
plotType,
purpose,//用途 【枚举】 PURPOSE
createUser:reqUser.userId,
ct:new Date().valueOf()
};
await dikuaiData.addData(addInfo);
return successResult();
}
/**
* 地块信息
* @param plotType
* @param selectStr
* @param code
* @param purpose
* @param area
* @returns
*/
export async function diKuaiInfo(dId:String ) {
let dikuaiInfo = await dikuaiData.selectOne({dId});
let dataInfo = {
size:dikuaiInfo.size,
dId:dikuaiInfo.dId,
type:dikuaiInfo.purpose,
purpose:changeEnumValue(PURPOSE, dikuaiInfo.purpose),
code:dikuaiInfo.code
};
return {dataInfo}
}
/**
* 地块列表
* @param plotType
* @param selectStr
* @param code
* @param purpose
* @param area
* @returns
*/
export async function diKuaiList(plotType:number, selectStr:string, code:string, purpose:number, area:number ) {
let funName = "地块列表";
eccEnumValue(funName, "plottype", PLOTTYPE, plotType);
let param:any = {plotType};
if (code) {
param.code = { "$regex":code };
}
if (purpose) {
eccEnumValue(funName, "purpose", PURPOSE, purpose);
param.purpose = purpose;
}
if (area) {
eccEnumValue(funName, "area", AREARANGE, area);
param.size = {"$lte": parseInt(AREARANGE[area].replace("<=", "")) };
}
let diKuaiList = await dikuaiData.selectToParam(param);
let dataList = [];
diKuaiList.forEach(item => {
let { size, dId, purpose, code } = item;
dataList.push({size,dId,type:changeEnumValue(PURPOSE, purpose),code});
});
return {dataList}
}
/**
* 地块列表分页-暂无使用
* @param code 地块编号 string
* @param area 地块区域 string
* @param purpose 地块用途 number
* @param pageNumber 页码
* @returns
*
*/
export async function diKuaiListToPage(code, area, purpose, pageNumber) {
let funName = "地块列表";
let param:any = {};
if (code) {
param.code = { "$regex":code };
}
if (area) {
param.area = { "$regex":area };
}
if (purpose) {
eccEnumValue(funName, "purpose", PURPOSE, purpose);
param.purpose = purpose;
}
let diKuaiList = await dikuaiData.findDataToParamToSortPage(param, {ct:-1}, pageNumber);
let dataCount = await dikuaiData.findDataToParamCouant({});
let dataList = [];
diKuaiList.forEach(item => {
let { size, dId, plotType, purpose, code, area, ct } = item;
dataList.push({
size,
dId,
plotType:changeEnumValue(PLOTTYPE, plotType),
type:changeEnumValue(PURPOSE, purpose),
code,
area,
ct:moment(ct).format("YYYY-MM-DD")
});
});
return {dataList, dataCount}
}
/**
* 修改地块信息
* @param reqUser
* @param plotType
* @param dId
* @param param
* @returns
*/
export async function updateDiKuai(reqUser, plotType, dId, param) {
let funName = `修改地块`;
eccEnumValue(funName, "plottype", PLOTTYPE, plotType);
let purpose = PURPOSE.养殖;
if (plotType == PLOTTYPE.地块) {
eccFormParam(funName+changeEnumValue(PLOTTYPE, plotType), DiKuaiConfig, param);
eccEnumValue(funName, "param=>type", PURPOSE, param.type);
purpose = param.type;
} else {
eccFormParam(funName+changeEnumValue(PLOTTYPE, plotType), YangZhiChiConfig, param);
}
let dInfo = await dikuaiData.selectOne({dId});
if (!dInfo || !dInfo.dId) throw new BizError(ERRORENUM.地块不存在);
dInfo.code = param.code,
dInfo.size = param.size,
dInfo.purpose = purpose;
await dInfo.save();
return successResult();
}
/**
* 当前可种植地块
* @returns
*/
export async function keXuanDiKuaiList(zhongYangType:number) {
let param:any = {};
if (zhongYangType) {
let purpose = 1;
if (zhongYangType == ZHONGYANGTYPE.水产) purpose = PURPOSE.养殖;
else if (zhongYangType == ZHONGYANGTYPE.花卉 ||zhongYangType == ZHONGYANGTYPE.蔬菜 ) purpose = PURPOSE.菜田;
else if (zhongYangType == ZHONGYANGTYPE.粮食) purpose = PURPOSE.粮田;
// param.nullSize = {"$gt":0};
param.purpose = purpose;
}
console.log("------>", JSON.stringify(param));
let dbList = await dikuaiData.selectToParam(param);
let dataList = [];
dbList.forEach(info => {
let {code, purpose, dId, size} = info;
dataList.push( {code, purpose:changeEnumValue(PURPOSE, purpose), dId, size});
});
return {dataList};
}
/**
* 当前采收地块列表
* @returns
*/
export async function keCaiShouList(zhongYangType:number) {
let purpose = 1;
if (zhongYangType == ZHONGYANGTYPE.水产) purpose = PURPOSE.养殖;
else if (zhongYangType == ZHONGYANGTYPE.花卉 ||zhongYangType == ZHONGYANGTYPE.蔬菜 ) purpose = PURPOSE.菜田;
else if (zhongYangType == ZHONGYANGTYPE.粮食) purpose = PURPOSE.粮田;
let param = {useSize:{"$gt":0}, purpose:purpose};
let dbList = await dikuaiData.selectToParam(param);
let dataList = [];
dbList.forEach(info => {
let {code, purpose, dId, size} = info;
dataList.push( {code, purpose:changeEnumValue(PURPOSE, purpose), dId, size});
});
return {dataList}
}
/**
* 全部地块列表
* @param plotType
* @param selectStr
* @param code
* @param purpose
* @param area
* @returns
*/
export async function allDiKuaiList(plotType:number ) {
let funName = "地块列表";
eccEnumValue(funName, "plottype", PLOTTYPE, plotType);
let param:any = {plotType};
let diKuaiList = await dikuaiData.selectToParam(param);
let dataList = [];
diKuaiList.forEach(item => {
let { size, dId, purpose, code } = item;
dataList.push({dId, code});
});
return {dataList}
}
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../../config/dbEnum";
import { CaiShouConfig, NongShiConfig } from "../config/eccParam"; import { CaiShouConfig, NongShiConfig } from "../../config/eccParam";
import { NONGSHITYPE, PLANTTYPE } from "../config/enum"; import { NONGSHITYPE, PLANTTYPE } from "../../config/enum";
import * as nongshiData from "../data/nongshi"; import * as nongshiData from "../../data/nongshi";
import * as dikuaiData from "../data/dikuai"; import * as dikuaiData from "../../data/dikuai";
import { getMySqlMs, randomId, successResult } from "../tools/system"; import { getMySqlMs, randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../util/verificationEnum"; import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../util/verificationParam"; import { eccFormParam } from "../../util/verificationParam";
import moment = require("moment"); import moment = require("moment");
import { BizError } from "../util/bizError"; import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../../config/errorEnum";
/** /**
* 添加农事 * 添加农事
...@@ -60,9 +60,9 @@ export async function nongShiList(selectStr:string, dId:string, nsType:number, o ...@@ -60,9 +60,9 @@ export async function nongShiList(selectStr:string, dId:string, nsType:number, o
param.dIdList = {"$in":dId}; param.dIdList = {"$in":dId};
} }
if (operationTime) { if (operationTime) {
let startMs = moment(operationTime).startOf("month").valueOf(); let startMs = moment(operationTime).startOf("day").valueOf();
let endMs = moment(operationTime).endOf("month").valueOf(); let endMs = moment(operationTime).endOf("day").valueOf();
param.operationTime = {"$gt":startMs, "$lt":endMs}; param.operationTime = {"$gte":startMs, "$lte":endMs};
} }
let dikuaiList = await dikuaiData.selectToParam({}); let dikuaiList = await dikuaiData.selectToParam({});
...@@ -83,9 +83,14 @@ export async function nongShiList(selectStr:string, dId:string, nsType:number, o ...@@ -83,9 +83,14 @@ export async function nongShiList(selectStr:string, dId:string, nsType:number, o
dataList.push({ dataList.push({
nsType:changeEnumValue(NONGSHITYPE, nsType), nsType:changeEnumValue(NONGSHITYPE, nsType),
dIdList:didStr, dIdList:didStr,
operationTime:moment(operationTime).format("YYYY-MM-DD") operationTime:moment(operationTime).format("YYYY-MM-DD"),
operationTimeNum:operationTime
}); });
}); });
dataList.sort( (a, b) => {
return b.operationTimeNum - a.operationTimeNum;
})
return {dataList} return {dataList}
} }
\ No newline at end of file
...@@ -3,16 +3,17 @@ ...@@ -3,16 +3,17 @@
*/ */
import moment = require("moment"); import moment = require("moment");
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../../config/dbEnum";
import { NongZiConfig } from "../config/eccParam"; import { NongZiConfig } from "../../config/eccParam";
import { NONGZITYPE, PLANTTYPE } from "../config/enum"; import { NONGZITYPE, PLANTTYPE, PURPOSE } from "../../config/enum";
import * as nongziData from "../data/nongzi"; import * as nongziData from "../../data/nongzi";
import * as dikuaiData from "../data/dikuai"; import * as dikuaiData from "../../data/dikuai";
import { randomId, successResult } from "../tools/system"; import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../util/verificationEnum"; import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../util/verificationParam"; import { eccFormParam } from "../../util/verificationParam";
import { BizError } from "../util/bizError"; import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../../config/errorEnum";
/** /**
* 添加农资 * 添加农资
...@@ -68,9 +69,9 @@ export async function nongZiList(selectStr:string, dId:string, nzType:number, us ...@@ -68,9 +69,9 @@ export async function nongZiList(selectStr:string, dId:string, nzType:number, us
param.dIdList = {"$in":dId}; param.dIdList = {"$in":dId};
} }
if (useTime) { if (useTime) {
let startMs = moment(useTime).startOf("month").valueOf(); let startMs = moment(useTime).startOf("day").valueOf();
let endMs = moment(useTime).endOf("month").valueOf(); let endMs = moment(useTime).endOf("day").valueOf();
param.useTime = {"$gt":startMs, "$lt":endMs}; param.useTime = {"$gte":startMs, "$lte":endMs};
} }
let dikuaiList = await dikuaiData.selectToParam({}); let dikuaiList = await dikuaiData.selectToParam({});
...@@ -94,17 +95,28 @@ export async function nongZiList(selectStr:string, dId:string, nzType:number, us ...@@ -94,17 +95,28 @@ export async function nongZiList(selectStr:string, dId:string, nzType:number, us
dIdList:didStr, dIdList:didStr,
plantType:changeEnumValue(PLANTTYPE, plantType), plantType:changeEnumValue(PLANTTYPE, plantType),
count, count,
useTime:moment(useTime).format("YYYY-MM-DD") useTime:moment(useTime).format("YYYY-MM-DD"),
useTimeNum:useTime
}); });
}); });
dataList.sort( (a, b) => {
return b.useTimeNum - a.useTimeNum;
})
return {dataList}; return {dataList};
} }
/**
export async function updateZhongYang(reqUser, nzId, param) { * 修改农资 暂无使用
let funName = `修改种养`; * @param reqUser
* @param nzId
* @param param
* @returns
*/
export async function updateNongZi(reqUser, nzId, param) {
let funName = `修改农资`;
eccFormParam(funName, NongZiConfig, param); eccFormParam(funName, NongZiConfig, param);
eccEnumValue(funName, "nzType", NONGZITYPE, param.nzType); eccEnumValue(funName, "nzType", NONGZITYPE, param.nzType);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType); eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
...@@ -133,12 +145,18 @@ export async function updateZhongYang(reqUser, nzId, param) { ...@@ -133,12 +145,18 @@ export async function updateZhongYang(reqUser, nzId, param) {
} }
export async function zhongYangInfo(nzId) { /**
* 农资回显 暂无使用
* @param nzId
* @returns
*/
export async function nongZiInfo(nzId) {
let nongZiInfo = await nongziData.findOne({nzId}); let nongZiInfo = await nongziData.findOne({nzId});
let dataInfo = { let dataInfo = {
nzType:nongZiInfo.nzType,//农资类型 nzType:nongZiInfo.nzType,//农资类型
dIdList:nongZiInfo.dIdList,//地块id // dIdList:didStr, //地块id
dIdList:nongZiInfo.dIdList[0],//地块id
plantType:nongZiInfo.plantType,//种植种类【枚举】 PLANTTYPE plantType:nongZiInfo.plantType,//种植种类【枚举】 PLANTTYPE
count:nongZiInfo.count,//用量 count:nongZiInfo.count,//用量
useTime:nongZiInfo.useTime//时间 useTime:nongZiInfo.useTime//时间
...@@ -147,22 +165,66 @@ export async function zhongYangInfo(nzId) { ...@@ -147,22 +165,66 @@ export async function zhongYangInfo(nzId) {
return {dataInfo} return {dataInfo}
} }
export async function zhongYangListToPage(page) {
let dbList = await nongziData.findDataToParamToPage({}, page); /**
* 农资列表 暂无使用
* @param selectStr
* @param dId
* @param nzType
* @param useTime
* @returns
*/
export async function nongZiListToPage(nzType:number, dId:string, useTime:number, pageNumber:number) {
let funName = "农资列表";
let param:any = {};
if (nzType) {
eccEnumValue(funName, "nzType", NONGZITYPE, nzType);
param.nzType = nzType;
}
if (dId) {
param.dIdList = {"$in":dId};
}
if (useTime) {
let startMs = moment(useTime).startOf("day").valueOf();
let endMs = moment(useTime).endOf("day").valueOf();
param.useTime = {"$gte":startMs, "$lte":endMs};
}
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
let nongziList = await nongziData.findDataToParamToSortPage( param, {useTime:-1}, pageNumber );
let dataCount = await nongziData.findDataToParamCouant({}); let dataCount = await nongziData.findDataToParamCouant({});
let dataList = []; let dataList = [];
nongziList.forEach(item => {
dbList.forEach(info => { let {nzId, nzType, dIdList, plantType, count, useTime, ct } = item;
dataList.push({ let didStr = "";
nzId:info.nzId, let area = "";
nzType:info.nzType,//农资类型 let purpose = "";
dIdList:info.dIdList,//地块id let size = "";
plantType:info.plantType,//种植种类【枚举】 PLANTTYPE dIdList.forEach(dId => {
count:info.count,//用量 didStr += `${diKuaiMap[dId] || "-"}`;
useTime:info.useTime//时间
}) })
dataList.push({
nzId,
nzType:changeEnumValue(NONGZITYPE, nzType), //农资类型
dIdList:didStr, //地块id
plantType:changeEnumValue(PLANTTYPE, plantType), //种植种类【枚举】 PLANTTYPE
count, //用量
useTime:moment(useTime).format("YYYY-MM-DD"), //时间
ct:moment(ct).format("YYYY-MM-DD"), //创建时间
area, //所属区域
purpose:changeEnumValue(PURPOSE, purpose), //地块用途
size, //地块面积
});
}); });
return {dataList, dataCount} return {dataList, dataCount}
} }
\ No newline at end of file
/**
* 用户
* 水产养殖和销售数量数据库默认单位-万尾
*/
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};
}
/** /**
* 销售 * 销售
*/ */
import { TABLENAME } from "../config/dbEnum"; import { TABLENAME } from "../../config/dbEnum";
import { XiaoShouConfig } from "../config/eccParam"; import { XiaoShouConfig } from "../../config/eccParam";
import { PLANTTYPE, XIAOSHOUQUXIANG } from "../config/enum"; import { PLANTTYPE, XIAOSHOUQUXIANG } from "../../config/enum";
import * as xiaoshouData from "../data/xiaoshou"; import * as xiaoshouData from "../../data/xiaoshou";
import { randomId, successResult } from "../tools/system"; import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../util/verificationEnum"; import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../util/verificationParam"; import { eccFormParam } from "../../util/verificationParam";
import moment = require("moment"); import moment = require("moment");
/** /**
...@@ -58,9 +58,9 @@ export async function xiaoShouList(selectStr:string, quXiang:string, plantType:n ...@@ -58,9 +58,9 @@ export async function xiaoShouList(selectStr:string, quXiang:string, plantType:n
param.quXiang = quXiang; param.quXiang = quXiang;
} }
if (operationTime) { if (operationTime) {
let startMs = moment(operationTime).startOf("month").valueOf(); let startMs = moment(operationTime).startOf("day").valueOf();
let endMs = moment(operationTime).endOf("month").valueOf(); let endMs = moment(operationTime).endOf("day").valueOf();
param.useTime = {"$gt":startMs, "$lt":endMs}; param.useTime = {"$gte":startMs, "$lte":endMs};
} }
let nongShiList = await xiaoshouData.selectToParam(param); let nongShiList = await xiaoshouData.selectToParam(param);
...@@ -72,9 +72,14 @@ export async function xiaoShouList(selectStr:string, quXiang:string, plantType:n ...@@ -72,9 +72,14 @@ export async function xiaoShouList(selectStr:string, quXiang:string, plantType:n
plantType:changeEnumValue(PLANTTYPE, plantType), plantType:changeEnumValue(PLANTTYPE, plantType),
quXiang:changeEnumValue(XIAOSHOUQUXIANG, quXiang), quXiang:changeEnumValue(XIAOSHOUQUXIANG, quXiang),
operationTime:moment(operationTime).format("YYYY-MM-DD"), operationTime:moment(operationTime).format("YYYY-MM-DD"),
weight weight,
operationTimeNum:operationTime
}); });
}); });
dataList.sort( (a, b) => {
return b.operationTimeNum - a.operationTimeNum;
})
return {dataList} return {dataList}
} }
\ No newline at end of file
/**
* 种养
*/
import moment = require("moment");
import { TABLENAME } from "../../config/dbEnum";
import { DiKuaiConfig, ZhongYangConfig } from "../../config/eccParam";
import { PLANTTYPE, PLOTTYPE, XIAOSHOUQUXIANG, ZHONGYANGTYPE } from "../../config/enum";
import * as zhongzhiData from "../../data/zhongzhi";
import * as xiaoshouData from "../../data/xiaoshou";
import * as dikuaiData from "../../data/dikuai";
import { randomId, successResult } from "../../tools/system";
import { changeEnumValue, eccEnumValue } from "../../util/verificationEnum";
import { eccFormParam } from "../../util/verificationParam";
import { BizError } from "../../util/bizError";
import { ERRORENUM } from "../../config/errorEnum";
/**
* 种养列表
* @param plantType 种养类型
* @param selectStr
* @returns
*/
export async function zhongYangDangQianList(zhongYangType:number, selectStr:string) {
let funName = `当前种养列表`;
eccEnumValue(funName, 'zhongYangType', ZHONGYANGTYPE, zhongYangType);
let param = {
plantType:{"$gte":zhongYangType, "$lt":zhongYangType+99},
isEnd:0
};
let zyList = await zhongzhiData.selectToParam( param );
let typeMap = {};
zyList.forEach(info => {
let {plantType} = info;
typeMap[plantType] = {value:plantType, key:changeEnumValue(PLANTTYPE, plantType)};
});
let dataList = Object.values(typeMap);
return {dataList};
}
/**
* 种养列表-分页 暂无使用
* @param zhongYangType
* @param selectStr
* @param pageNumber
* @returns
*/
export async function zhongYangDangQianListToPage(zhongYangType:number, selectStr:string, pageNumber) {
let funName = `当前种养列表`;
let param:any = { };
if (zhongYangType) {
eccEnumValue(funName, 'zhongYangType', ZHONGYANGTYPE, zhongYangType);
param.plantType = {"$gte":zhongYangType, "$lt":zhongYangType+99};
}
let zyList = await zhongzhiData.findDataToParamToSortPage( param, {plantTime:-1}, pageNumber );
let dataCount = await zhongzhiData.findDataToParamCouant(param);
let dataList = [];
zyList.forEach(info => {
let addInfo = {
zId : info.zId,
size : info.size,
plantType : info.plantType,
dId : info.dId,
plantTime : info.plantTime
};
dataList.push(addInfo);
});
return {dataList, dataCount};
}
/**
* 删除种养 暂无使用
* @param zId
* @returns
*/
export async function deleteZhongYang(zId) {
let zhongYangInfo = await zhongzhiData.selectOne({zId});
if (!zhongYangInfo || !zhongYangInfo.zId) throw new BizError(ERRORENUM.数据不存在);
await zhongzhiData.deleteData({zId});
return successResult();
}
/**
* 添加种养
* @param reqUser
* @param param
* @returns
*/
export async function addZhongYang(reqUser, param) {
let funName = `添加种养`;
eccFormParam(funName, ZhongYangConfig, param);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
//校验地块大小是否符合扣除
let dkInfo = await dikuaiData.selectOne({dId:param.dId});
if (!dkInfo || !dkInfo.dId) throw new BizError(ERRORENUM.地块不存在);
if (param.plantType < PLANTTYPE.鲈鱼 && param.plantType > PLANTTYPE.水稻 ) {
if (dkInfo.size < param.size) throw new BizError(ERRORENUM.地块大小不足);
}
let addInfo = {
zId:randomId(TABLENAME.种植表),
size:param.size,//种植大小
plantType:param.plantType,//
dId:param.dId,//地块id
plantTime:param.plantTime,//种植时间
uId:reqUser.userId,
isEnd:0,
ct:new Date().valueOf()
};
await zhongzhiData.addData(addInfo);
dkInfo.nullSize = dkInfo.size - param.size;
dkInfo.useSize = dkInfo.useSize + param.size;
await dkInfo.save();
return successResult();
}
/**
* 修改种养 暂无使用
* @param reqUser
* @param zId
* @param param
* @returns
*/
export async function updateZhongYang(reqUser, zId, param) {
let funName = `修改种养`;
eccFormParam(funName, ZhongYangConfig, param);
eccEnumValue(funName, "plantType", PLANTTYPE, param.plantType);
let dkInfo = await dikuaiData.selectOne({dId:param.dId});
if (!dkInfo || !dkInfo.dId) throw new BizError(ERRORENUM.地块不存在);
if (dkInfo.size < param.size) throw new BizError(ERRORENUM.地块大小不足);
let zhongYangInfo = await zhongzhiData.selectOne({zId});
zhongYangInfo.plantType = param.plantType;
zhongYangInfo.dId = param.dId;
zhongYangInfo.size = param.size;
zhongYangInfo.plantTime = param.plantTime;
await zhongYangInfo.save();
return successResult();
}
/**
* 种养回显 暂无使用
* @param zId
* @returns
*/
export async function zhognYangInfo(zId) {
let dikuaiInfo = await zhongzhiData.selectOne({zId});
let dataInfo = {
plantType:dikuaiInfo.plantType,//编号
dId:dikuaiInfo.dId,//地块id
size:dikuaiInfo.size,//地块大小
plantTime:dikuaiInfo.plantTime,//种植时间
};
return {dataInfo}
}
/**
* 种养记录
* @param zhongYangType
* @param selectStr
* @param plantType
* @param plantTime
* @param dId
* @returns
*/
export async function zhongYangJiLu(zhongYangType:number, selectStr:string, plantType:number, plantTime:number, dId:string) {
let funName = `种养记录`;
let param:any = { plantType:{"$gte":zhongYangType, "$lt":zhongYangType+99} };
if (plantType) {
eccEnumValue(funName, "plantType", PLANTTYPE, plantType);
param.plantType = plantType;
}
if (dId) {
param.dId = dId;
}
if (plantTime) {
let selectStartTime = moment(plantTime).startOf('day').valueOf();
let selectEndTime = moment(plantTime).endOf("day").valueOf();
param.plantTime = {"$gte":selectStartTime, "$lte":selectEndTime};
}
/**获取地块名称 */
let dikuaiList = await dikuaiData.selectToParam({});
let diKuaiMap = {};
dikuaiList.forEach(info => {
let {dId, code} = info;
diKuaiMap[dId] = code;
});
let dbList = await zhongzhiData.selectToParam(param);
let dataList = [];
dbList.forEach(info => {
dataList.push({
plantType:changeEnumValue(PLANTTYPE, info.plantType),
size:info.size,
code:diKuaiMap[info.dId],
plantTime:moment(info.plantTime).format("YYYY-MM-DD"),
plantTimeNum:info.plantTime
})
});
dataList.sort( (a, b) => {
return b.plantTimeNum - a.plantTimeNum;
})
return {dataList};
}
/** =================================供大屏使用==================================== */
/**
* 种养列表
* @param zhongYangType
* @returns
*/
// export async function zhongYangList(zhongYangType:number) {
// let funName = `当前种养列表`;
// let param:any = { };
// // let startTime = moment().subtract(1, 'month').startOf('month').valueOf();
// // let endTime = moment().subtract(1, 'month').endOf('month').valueOf();
// let startTime = moment().subtract(90, 'days').startOf('day').valueOf();
// let endTime = moment().endOf('day').valueOf();
// if (zhongYangType) {
// eccEnumValue(funName, 'zhongYangType', ZHONGYANGTYPE, zhongYangType);
// param.plantType = {"$gte":zhongYangType, "$lt":zhongYangType+99};
// param.isEnd = 0;
// param.plantTime = {"$gte":startTime, "$lte":endTime}
// }
// let zyList = await zhongzhiData.selectToParam(param);
// let dataInfo = {};
// zyList.forEach(info => {
// let addInfo = {
// size : info.size,
// plantType : changeEnumValue(PLANTTYPE, info.plantType),
// plantTime : moment(info.plantTime).format("YYYY-MM-DD"),
// };
// let plantType = changeEnumValue(PLANTTYPE, info.plantType);
// if (!dataInfo[plantType]) dataInfo[plantType] = [];
// dataInfo[plantType].push(addInfo);
// });
// let dataList = [];
// let unit = "亩";
// if (zhongYangType == ZHONGYANGTYPE.水产) unit = "万尾";
// for (let key in dataInfo) {
// let size = 0;
// let zhongyang = dataInfo[key];
// zhongyang.forEach(item => {
// size += item.size;
// });
// dataList.push({
// key:key,
// value:Math.round(size*100)/100,
// unit
// });
// }
// dataList.sort((a, b) => {
// return b.value - a.value;
// })
// return dataList.slice(0, 10);
// }
/**
* 种养列表
* @param zhongYangType
* @returns
*/
export async function zhongYangList(zhongYangType:number) {
let funName = `当前种养列表`;
let param:any = { };
// 根据种养类型设置不同的时间范围
let startTime, endTime;
if (zhongYangType === ZHONGYANGTYPE.水产) {
// 水产类型:获取近一年的数据
startTime = moment().subtract(1, 'year').startOf('day').valueOf();
endTime = moment().endOf('day').valueOf();
} else {
// 其他类型:保持原来的90天范围
startTime = moment().subtract(90, 'days').startOf('day').valueOf();
endTime = moment().endOf('day').valueOf();
}
if (zhongYangType) {
eccEnumValue(funName, 'zhongYangType', ZHONGYANGTYPE, zhongYangType);
param.plantType = {"$gte":zhongYangType, "$lt":zhongYangType+99};
param.isEnd = 0;
param.plantTime = {"$gte":startTime, "$lte":endTime}
}
let zyList = await zhongzhiData.selectToParam(param);
let dataInfo = {};
zyList.forEach(info => {
let addInfo = {
size : info.size,
plantType : changeEnumValue(PLANTTYPE, info.plantType),
plantTime : moment(info.plantTime).format("YYYY-MM-DD"),
};
let plantType = changeEnumValue(PLANTTYPE, info.plantType);
if (!dataInfo[plantType]) dataInfo[plantType] = [];
dataInfo[plantType].push(addInfo);
});
let dataList = [];
let unit = "亩";
if (zhongYangType == ZHONGYANGTYPE.水产) unit = "万尾";
for (let key in dataInfo) {
let size = 0;
let zhongyang = dataInfo[key];
zhongyang.forEach(item => {
size += item.size;
});
dataList.push({
key:key,
value:Math.round(size*100)/100,
unit
});
}
dataList.sort((a, b) => {
return b.value - a.value;
})
return dataList.slice(0, 10);
}
/**
* 鱼苗数据
* @returns
*/
export async function yuMiaoList() {
/**鱼苗销售记录 */
let param:any = {};
param.plantType = {"$gte":PLANTTYPE.鲈鱼, "$lt":PLANTTYPE.水稻};
// let lastMonth = moment().subtract(1, 'years').format('YYYY-MM-DD');
// let startMs = moment(lastMonth).startOf("day").valueOf();
// let endMs = moment(new Date()).endOf("day").valueOf();
// param.operationTime = {"$gte":startMs, "$lte":endMs};
let xiaoShouData = await xiaoshouData.selectToParam(param);
console.log(`xiaoShouData: ${JSON.stringify(xiaoShouData)}`);
xiaoShouData.sort( (a, b) => {
return b.operationTime - a.operationTime;
})
let xiaoShouList = [];
xiaoShouData.forEach(item => {
let {plantType, quXiang, operationTime, weight } = item;
xiaoShouList.push({
plantType:changeEnumValue(PLANTTYPE, plantType),
quXiang:changeEnumValue(XIAOSHOUQUXIANG, quXiang),
weight,
unit:"尾",
operationTime:moment(operationTime).format("YYYY-MM-DD"),
});
});
/**鱼苗养殖记录 */
let param2:any = {};
param2.plantType = {"$gte":PLANTTYPE.鲈鱼, "$lt":PLANTTYPE.水稻};
param2.isEnd = 0;
// param2.plantTime = {"$gte":startMs, "$lte":endMs};
let yangZhiData = await zhongzhiData.selectToParam(param2);
let yangZhiList = [];
yangZhiData.forEach(item => {
let {plantType, size, plantTime } = item;
yangZhiList.push({
plantType:changeEnumValue(PLANTTYPE, plantType),
size,
plantTime:moment(plantTime).format("YYYY-MM-DD"),
plantTimeNum:plantTime
});
});
yangZhiList.sort( (a, b) => {
return b.plantTimeNum - a.plantTimeNum;
})
/**各类鱼苗库存数量:养殖-销售 */
let kuCunData = calculateKuCun(yangZhiList, xiaoShouList);
let dataList = {
鱼苗销售记录:xiaoShouList,
鱼苗养殖记录:yangZhiList,
鱼苗库存数据:kuCunData
}
return dataList;
}
/**
* 计算各类鱼苗库存
* @param {Array} yangZhiList 养殖记录
* @param {Array} xiaoShouList 销售记录
* @returns {Array} 库存数据
*/
function calculateKuCun(yangZhiList, xiaoShouList) {
// 按鱼苗类型统计总养殖量
let yangZhiTotal = {};
yangZhiList.forEach(item => {
const type = item.plantType;
const size = parseFloat(item.size) || 0;
if (!yangZhiTotal[type]) {
yangZhiTotal[type] = 0;
}
yangZhiTotal[type] += size;
});
// 按鱼苗类型统计总销售量
let xiaoShouTotal = {};
xiaoShouList.forEach(item => {
const type = item.plantType;
const weight = parseFloat(item.weight) * 10000 || 0; //单位转换为万尾
if (!xiaoShouTotal[type]) {
xiaoShouTotal[type] = 0;
}
xiaoShouTotal[type] += weight;
});
// 计算库存并格式化结果
let kuCunList = [];
const allTypes = new Set([
...Object.keys(yangZhiTotal),
...Object.keys(xiaoShouTotal)
]);
allTypes.forEach(type => {
const yangZhi = yangZhiTotal[type] || 0;
const xiaoShou = xiaoShouTotal[type] || 0;
let kuCun = yangZhi - xiaoShou;
// 如果库存为负数,直接置零
if (kuCun < 0) {
kuCun = 0;
}
kuCunList.push({
plantType: type,
yangZhiTotal: yangZhi,
xiaoShouTotal: xiaoShou,
kuCun: kuCun,
unit: "万尾",
updateTime: moment().format("YYYY-MM-DD HH:mm:ss")
});
});
// 按库存量降序排列
kuCunList.sort((a, b) => b.kuCun - a.kuCun);
return kuCunList;
}
/**
* 统计页-农产品产量统计
* @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};
shuiChanDistinctMap[strKey].value += totalWeight;
shuiChanCount += totalWeight;
});
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;
shuiChanMap[plantType] += weight;
});
// 将map转换为数组
Object.keys(shuiChanMap).forEach(plantType => {
let weight = shuiChanMap[plantType];
shuiChan.push({
key: changeEnumValue(PLANTTYPE, parseInt(plantType)),
value: weight / 10000
});
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;
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 年份参数,用于筛选对应年份的数据
* @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};
shuiChanDistinctMap[strKey].value += totalWeight;
if (currentYear == year) shuiChanCount += totalWeight;
// 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;
shuiChanxiaoShou.push({
key: changeEnumValue(PLANTTYPE, _id),
value: Math.ceil(totalWeight/10)/100
});
});
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};
}
\ No newline at end of file
...@@ -30,7 +30,14 @@ export const NongZiConfig = { ...@@ -30,7 +30,14 @@ export const NongZiConfig = {
export const NongShiConfig = { export const NongShiConfig = {
nsType:{type:"Number" },//农事类型 nsType:{type:"Number" },//农事类型
dIdList:{type:"[String]" },//地块id dIdList:{type:"[String]" },//地块id
operationTime:{type:"Number"},//使用时间 operationTime:{type:"Number"},//操作时间
}
export const NongShiAdminConfig = {
nsType:{type:"Number" },//农事类型
dIdList:{type:"String" },//地块id
operationTime:{type:"Number"},//操作时间
} }
...@@ -38,7 +45,7 @@ export const CaiShouConfig = { ...@@ -38,7 +45,7 @@ export const CaiShouConfig = {
plantType:{type:"Number"}, //种植种类【枚举】 PLANTTYPE plantType:{type:"Number"}, //种植种类【枚举】 PLANTTYPE
dId:{type:"String" },//地块id dId:{type:"String" },//地块id
weight:{type:"Number"},//采收重量 weight:{type:"Number"},//采收重量
operationTime:{type:"Number"},//使用时间 operationTime:{type:"Number"},//采收时间
} }
......
...@@ -9,7 +9,6 @@ export enum PLOTTYPE { ...@@ -9,7 +9,6 @@ export enum PLOTTYPE {
} }
/** /**
* 用途 * 用途
*/ */
...@@ -20,6 +19,23 @@ export enum PURPOSE { ...@@ -20,6 +19,23 @@ export enum PURPOSE {
} }
/**
* 地块用途
*/
export enum DIKUAIPURPOSE {
菜田 = 1,
粮田 = 2,
}
/**
* 养殖用途
*/
export enum YANGZHIPURPOSE {
养殖 = 1000
}
/** /**
* 种养类型 * 种养类型
......
...@@ -51,6 +51,22 @@ export async function addManyData(param) { ...@@ -51,6 +51,22 @@ export async function addManyData(param) {
return await caishouModel.insertMany(param); return await caishouModel.insertMany(param);
} }
export async function findDataToParamToSortPage(param, sort, pageNumber) {
return await caishouModel.find(param).sort(sort).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamToPage(param, pageNumber) {
return await caishouModel.find(param).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamCouant(param) {
return await caishouModel.find(param).countDocuments();
}
export async function deleteData(param) {
return await caishouModel.deleteOne(param);
}
export async function selectChanLiangOfMonth(param) { export async function selectChanLiangOfMonth(param) {
return await caishouModel.aggregate([ return await caishouModel.aggregate([
......
...@@ -59,10 +59,18 @@ export async function selectToParam(param) { ...@@ -59,10 +59,18 @@ export async function selectToParam(param) {
return await dikuaiModel.find(param); return await dikuaiModel.find(param);
} }
export async function findDataToParamToSortPage(param, sort, pageNumber) {
return await dikuaiModel.find(param).sort(sort).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamToPage(param, pageNumber) { export async function findDataToParamToPage(param, pageNumber) {
return await dikuaiModel.find(param).skip((pageNumber-1)*10).limit(10); return await dikuaiModel.find(param).skip((pageNumber-1)*10).limit(10);
} }
export async function findDataToParamCouant(param) {
return await dikuaiModel.find(param).countDocuments();
}
export async function diKuaiSizeCount(param) { export async function diKuaiSizeCount(param) {
let list = await dikuaiModel.aggregate([ let list = await dikuaiModel.aggregate([
......
...@@ -57,6 +57,21 @@ export async function selectCountByParam(param) { ...@@ -57,6 +57,21 @@ export async function selectCountByParam(param) {
return await nongshiModel.find(param).countDocuments(); return await nongshiModel.find(param).countDocuments();
} }
export async function findDataToParamToSortPage(param, sort, pageNumber) {
return await nongshiModel.find(param).sort(sort).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamToPage(param, pageNumber) {
return await nongshiModel.find(param).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamCouant(param) {
return await nongshiModel.find(param).countDocuments();
}
export async function deleteData(param) {
return await nongshiModel.deleteOne(param);
}
export async function statisNongShiType() { export async function statisNongShiType() {
let list = await nongshiModel.aggregate([ let list = await nongshiModel.aggregate([
......
...@@ -54,20 +54,21 @@ export async function selectToParam(param) { ...@@ -54,20 +54,21 @@ export async function selectToParam(param) {
return await nongziModel.find(param); return await nongziModel.find(param);
} }
export async function findDataToParamCouant(param) {
return await nongziModel.find(param).countDocuments();
}
export async function deleteData(param) { export async function deleteData(param) {
return await nongziModel.deleteOne(param); return await nongziModel.deleteOne(param);
} }
export async function findDataToParamToSortPage(param, sort, pageNumber) {
return await nongziModel.find(param).sort(sort).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamToPage(param, pageNumber) { export async function findDataToParamToPage(param, pageNumber) {
return await nongziModel.find(param).skip((pageNumber-1)*10).limit(10); return await nongziModel.find(param).skip((pageNumber-1)*10).limit(10);
} }
export async function findDataToParamCouant(param) {
return await nongziModel.find(param).countDocuments();
}
export async function statisNongZiType() { export async function statisNongZiType() {
let list = await nongziModel.aggregate([ let list = await nongziModel.aggregate([
...@@ -82,7 +83,6 @@ export async function statisNongZiType() { ...@@ -82,7 +83,6 @@ export async function statisNongZiType() {
return list; return list;
} }
export async function statisNongZiTypeCountByTime() { export async function statisNongZiTypeCountByTime() {
let list = await nongziModel.aggregate([ let list = await nongziModel.aggregate([
{ {
...@@ -110,4 +110,5 @@ export async function statisNongZiTypeCountByTime() { ...@@ -110,4 +110,5 @@ export async function statisNongZiTypeCountByTime() {
]); ]);
return list; return list;
} }
\ No newline at end of file
...@@ -54,6 +54,21 @@ export async function selectToParam(param) { ...@@ -54,6 +54,21 @@ export async function selectToParam(param) {
return await xiaoshouModel.find(param); return await xiaoshouModel.find(param);
} }
export async function selectCountByParam(param) {
return await xiaoshouModel.find(param).countDocuments();
}
export async function findDataToParamToPage(param, pageNumber) {
return await xiaoshouModel.find(param).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamToSortPage(param, sort, pageNumber) {
return await xiaoshouModel.find(param).sort(sort).skip((pageNumber-1)*10).limit(10);
}
export async function deleteData(param) {
return await xiaoshouModel.deleteOne(param);
}
export async function selectXiaoShouOfMonth(param) { export async function selectXiaoShouOfMonth(param) {
return await xiaoshouModel.aggregate([ return await xiaoshouModel.aggregate([
......
/** /**
* * 种植
*
*/ */
import {Schema} from 'mongoose'; import {Schema} from 'mongoose';
...@@ -57,6 +56,10 @@ export async function selectToParam(param) { ...@@ -57,6 +56,10 @@ export async function selectToParam(param) {
return await zhongzhiModel.find(param); return await zhongzhiModel.find(param);
} }
export async function findDataToParamToSortPage(param, sort, pageNumber) {
return await zhongzhiModel.find(param).sort(sort).skip((pageNumber-1)*10).limit(10);
}
export async function findDataToParamToPage(param, pageNumber) { export async function findDataToParamToPage(param, pageNumber) {
return await zhongzhiModel.find(param).skip((pageNumber-1)*10).limit(10); return await zhongzhiModel.find(param).skip((pageNumber-1)*10).limit(10);
} }
...@@ -118,3 +121,74 @@ export async function zhongYangTongJiCount() { ...@@ -118,3 +121,74 @@ export async function zhongYangTongJiCount() {
return list; return list;
} }
/**
* 按年份统计种植面积
* @param year 年份,可选
* @returns 按种植类型分组的面积统计
*/
export async function zhongYangTongJiCountByYear(year?: number) {
// 构建基础查询条件
let matchCondition: any = { plantType: {"$gt": 100, "$lt": 200} };
// 如果传入了年份参数,添加时间过滤
if (year) {
const startTime = new Date(year, 0, 1).getTime(); // 年份开始时间戳
const endTime = new Date(year + 1, 0, 1).getTime(); // 年份结束时间戳
matchCondition.plantTime = {
"$gte": startTime,
"$lt": endTime
};
}
let list = await zhongzhiModel.aggregate([
{ $match: matchCondition },
{
"$group": {
_id: "$plantType",
sizeCount: {"$sum": "$size"}
}
}
]);
return list;
}
/**
* 按年份统计种植数量
* @param year 年份,可选
* @returns 按种植类型分组的数量统计
*/
export async function pingZhongCountByYear(year?: number) {
let matchCondition: any = {};
// 如果传入了年份参数,添加时间过滤
if (year) {
const startTime = new Date(year, 0, 1).getTime(); // 年份开始时间戳
const endTime = new Date(year + 1, 0, 1).getTime(); // 年份结束时间戳
matchCondition.plantTime = {
"$gte": startTime,
"$lt": endTime
};
}
let list = await zhongzhiModel.aggregate([
{ $match: matchCondition },
{
"$group": {
_id: "$plantType",
count: {"$sum": 1}
}
}
]);
return list;
}
...@@ -4,7 +4,7 @@ import { httpServer } from "./net/http_server"; ...@@ -4,7 +4,7 @@ import { httpServer } from "./net/http_server";
import { initDB } from "./db/dbInit"; import { initDB } from "./db/dbInit";
import { dataInit0516, dataInit, dataInit0508, yjDataInit0508, dataInit0522, dataInit0604, dataInit0609, dataInit0618, dataInit0817 } from "./biz/dataInt"; import { dataInit0516, dataInit, dataInit0508, yjDataInit0508, dataInit0522, dataInit0604, dataInit0609, dataInit0618, dataInit0817 } from "./biz/dataInt";
import { getDataOut, getGuiYuOut } from "./biz/dataOut"; import { getDataOut, getGuiYuOut } from "./biz/dataOut";
import { homePageStatisChanLiang } from "./biz/user"; import { homePageStatisChanLiangWithYear, homePageStatisXiaoShou } from "./biz/xcx/user";
import { getPwdMd5, md5PwdStr } from "./tools/system"; import { getPwdMd5, md5PwdStr } from "./tools/system";
async function lanuch() { async function lanuch() {
...@@ -17,7 +17,8 @@ async function lanuch() { ...@@ -17,7 +17,8 @@ async function lanuch() {
httpServer.createServer(systemConfig.port); httpServer.createServer(systemConfig.port);
console.log('This indicates that the server is started successfully.'); console.log('This indicates that the server is started successfully.');
// await homePageStatisChanLiang(1); // await homePageStatisXiaoShou(1, 2025);
// await homePageStatisChanLiangWithYear(2025, 1);
// await dataInit(); // await dataInit();
await getDataOut(); await getDataOut();
// await dataInit0508(); // await dataInit0508();
...@@ -29,7 +30,7 @@ async function lanuch() { ...@@ -29,7 +30,7 @@ async function lanuch() {
// await dataInit0618(); // await dataInit0618();
await dataInit0817(); await dataInit0817();
let checkPwd = getPwdMd5("18120935727", md5PwdStr("123456")) // let checkPwd = getPwdMd5("18120935727", md5PwdStr("123456"))
console.log(); console.log();
} }
......
...@@ -5,7 +5,7 @@ import compression = require('compression'); ...@@ -5,7 +5,7 @@ import compression = require('compression');
import { watch } from '../middleware/watch'; import { watch } from '../middleware/watch';
import { httpErrorHandler } from '../middleware/httpErrorHandler'; import { httpErrorHandler } from '../middleware/httpErrorHandler';
import * as path from "path"; import * as path from "path";
import * as fallback from 'express-history-api-fallback'; import fallback from 'express-history-api-fallback';
export class httpServer { export class httpServer {
static createServer(port:number) { static createServer(port:number) {
......
import * as asyncHandler from 'express-async-handler' import asyncHandler = require('express-async-handler');
import { eccReqParamater } from '../util/verificationParam'; import { eccReqParamater } from '../util/verificationParam';
import * as diKuaiBiz from '../biz/diKuai'; import * as diKuaiBiz from '../biz/admin/diKuai';
import * as userBiz from '../biz/user'; import * as userBiz from '../biz/admin/user';
import * as zhongYangBiz from '../biz/zhongYang'; import * as zhongYangBiz from '../biz/admin/zhongYang';
import * as nongziBiz from '../biz/nongzi'; import * as nongziBiz from '../biz/admin/nongzi';
import * as nongShiBiz from '../biz/nongShi'; import * as caishouBiz from '../biz/admin/caiShou';
import * as nongShiBiz from '../biz/admin/nongShi';
import * as publicRouters from './public'; import * as publicRouters from './public';
import * as caiShouBiz from '../biz/caiShou'; import * as xiaoShouBiz from '../biz/admin/xiaoShou';
import * as xiaoShouBiz from '../biz/xiaoShou';
import { checkAdminUserToken } from '../middleware/user'; import { checkAdminUserToken } from '../middleware/user';
import * as dataOutBiz from '../biz/dataOut'; import * as dataOutBiz from '../biz/dataOut';
...@@ -17,6 +17,7 @@ export function setRouter(httpServer){ ...@@ -17,6 +17,7 @@ export function setRouter(httpServer){
httpServer.post('/zjnt/xcxadmin/dikuai/update', checkAdminUserToken, asyncHandler(dikuai_update));//地块修改 '/zjnt/xcxadmin/dikuai/update' httpServer.post('/zjnt/xcxadmin/dikuai/update', checkAdminUserToken, asyncHandler(dikuai_update));//地块修改 '/zjnt/xcxadmin/dikuai/update'
httpServer.post('/zjnt/xcxadmin/dikuai/info', checkAdminUserToken, asyncHandler(dikuai_info));//地块回显 '/zjnt/xcxadmin/dikuai/info' httpServer.post('/zjnt/xcxadmin/dikuai/info', checkAdminUserToken, asyncHandler(dikuai_info));//地块回显 '/zjnt/xcxadmin/dikuai/info'
httpServer.post('/zjnt/xcxadmin/dikuai/list', checkAdminUserToken, asyncHandler(dikuai_list));//地块列表 '/zjnt/xcxadmin/dikuai/list' httpServer.post('/zjnt/xcxadmin/dikuai/list', checkAdminUserToken, asyncHandler(dikuai_list));//地块列表 '/zjnt/xcxadmin/dikuai/list'
httpServer.post('/zjnt/xcxadmin/dikuai/xuanze/list', checkAdminUserToken, asyncHandler(xuanze_dikuai_list));//下拉选择-使用地块
/**种养 */ /**种养 */
httpServer.post('/zjnt/xcxadmin/zhongyang/add', checkAdminUserToken, asyncHandler(zhongyang_add));//种养添加 '/zjnt/xcxadmin/zhongyang/add' httpServer.post('/zjnt/xcxadmin/zhongyang/add', checkAdminUserToken, asyncHandler(zhongyang_add));//种养添加 '/zjnt/xcxadmin/zhongyang/add'
...@@ -67,7 +68,7 @@ async function user_login(req, res) { ...@@ -67,7 +68,7 @@ async function user_login(req, res) {
} }
async function user_logout(req, res) { async function user_logout(req, res) {
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await userBiz.adminUserLogout(userInfo); let result = await userBiz.adminUserLogout(userInfo);
res.success(result); res.success(result);
} }
...@@ -79,7 +80,7 @@ async function dikuai_add(req, res) { ...@@ -79,7 +80,7 @@ async function dikuai_add(req, res) {
let reqConf = {plotType:'Number', param:'Object'}; let reqConf = {plotType:'Number', param:'Object'};
let { plotType, param } = eccReqParamater(reqConf, req.body); let { plotType, param } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await diKuaiBiz.addDiKuai(userInfo, plotType, param); let result = await diKuaiBiz.addDiKuai(userInfo, plotType, param);
res.success(result); res.success(result);
...@@ -89,7 +90,7 @@ async function dikuai_add(req, res) { ...@@ -89,7 +90,7 @@ async function dikuai_add(req, res) {
async function dikuai_update(req, res) { async function dikuai_update(req, res) {
let reqConf = {dId:'String', plotType:'Number', param:'Object'}; let reqConf = {dId:'String', plotType:'Number', param:'Object'};
let { dId, param, plotType } = eccReqParamater(reqConf, req.body); let { dId, param, plotType } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await diKuaiBiz.updateDiKuai(userInfo, plotType, dId, param); let result = await diKuaiBiz.updateDiKuai(userInfo, plotType, dId, param);
res.success(result); res.success(result);
...@@ -97,16 +98,24 @@ async function dikuai_update(req, res) { ...@@ -97,16 +98,24 @@ async function dikuai_update(req, res) {
async function dikuai_info(req, res) { async function dikuai_info(req, res) {
let reqConf = {dId:'Number'}; let reqConf = {dId:'String'};
let { dId } = eccReqParamater(reqConf, req.body); let { dId } = eccReqParamater(reqConf, req.body);
let result = await diKuaiBiz.diKuaiInfo(dId); let result = await diKuaiBiz.diKuaiInfo(dId);
res.success(result); res.success(result);
} }
async function dikuai_list(req, res) { async function dikuai_list(req, res) {
let reqConf = {pageNumber:'Number'}; let reqConf = {code:'String', area:'String', purpose:'Number', pageNumber:'Number'};
let { pageNumber } = eccReqParamater(reqConf, req.body); let { code, area, purpose, pageNumber } = eccReqParamater(reqConf, req.body, ["code", "area", "purpose"]);
let result = await diKuaiBiz.diKuaiListToPage(pageNumber); let result = await diKuaiBiz.diKuaiListToPage(code, area, purpose, pageNumber);
res.success(result);
}
async function xuanze_dikuai_list(req, res) {
const UserInfo = req.userInfo;
let reqConf = { zhongYangType:'Number'};
let { zhongYangType } = eccReqParamater(reqConf, req.body, ["zhongYangType"]);
let result = await diKuaiBiz.keXuanDiKuaiList(zhongYangType);
res.success(result); res.success(result);
} }
...@@ -116,7 +125,7 @@ async function dikuai_list(req, res) { ...@@ -116,7 +125,7 @@ async function dikuai_list(req, res) {
async function zhongyang_add(req, res) { async function zhongyang_add(req, res) {
let reqConf = {param:'Object'}; let reqConf = {param:'Object'};
let { param } = eccReqParamater(reqConf, req.body); let { param } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await zhongYangBiz.addZhongYang(userInfo, param); let result = await zhongYangBiz.addZhongYang(userInfo, param);
res.success(result); res.success(result);
...@@ -125,7 +134,7 @@ async function zhongyang_add(req, res) { ...@@ -125,7 +134,7 @@ async function zhongyang_add(req, res) {
async function zhongyang_update(req, res) { async function zhongyang_update(req, res) {
let reqConf = {param:'Object', zId:"String"}; let reqConf = {param:'Object', zId:"String"};
let { param, zId } = eccReqParamater(reqConf, req.body); let { param, zId } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await zhongYangBiz.updateZhongYang(userInfo, zId, param); let result = await zhongYangBiz.updateZhongYang(userInfo, zId, param);
res.success(result); res.success(result);
} }
...@@ -138,9 +147,9 @@ async function zhongyang_info(req, res) { ...@@ -138,9 +147,9 @@ async function zhongyang_info(req, res) {
} }
async function zhongyang_list(req, res) { async function zhongyang_list(req, res) {
let reqConf = {zhongYangType:"Number", selectStr:"String", page:"Number"}; let reqConf = {zhongYangType:"Number", plantType:"Number", dId:"String", plantTime:"Number", pageNumber:"Number"};
let { zhongYangType, selectStr, pageNumber } = eccReqParamater(reqConf, req.body, ["zhongYangType", "selectStr"]); let { zhongYangType, plantType, dId, plantTime, pageNumber } = eccReqParamater(reqConf, req.body, ["dId", "plantType", "zhongYangType", "plantTime"]);
let result = await zhongYangBiz.zhongYangDangQianListToPage(zhongYangType, selectStr, pageNumber); let result = await zhongYangBiz.zhongYangDangQianListToPage(zhongYangType, plantType, dId, plantTime, pageNumber);
res.success(result); res.success(result);
} }
...@@ -152,12 +161,11 @@ async function zhongyang_del(req, res) { ...@@ -152,12 +161,11 @@ async function zhongyang_del(req, res) {
} }
/**农资 */
async function nongzi_add(req, res) { async function nongzi_add(req, res) {
let reqConf = {param:'Object'}; let reqConf = {param:'Object'};
let { param } = eccReqParamater(reqConf, req.body); let { param } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await nongziBiz.addNongZi(userInfo, param); let result = await nongziBiz.addNongZi(userInfo, param);
res.success(result); res.success(result);
} }
...@@ -167,8 +175,8 @@ async function nongzi_add(req, res) { ...@@ -167,8 +175,8 @@ async function nongzi_add(req, res) {
async function nongzi_update(req, res) { async function nongzi_update(req, res) {
let reqConf = {param:'Object', nzId:"String"}; let reqConf = {param:'Object', nzId:"String"};
let { param, nzId} = eccReqParamater(reqConf, req.body); let { param, nzId} = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo; let userInfo = req.headers;
let result = await nongziBiz.updateZhongYang(userInfo, nzId, param); let result = await nongziBiz.updateNongZi(userInfo, nzId, param);
res.success(result); res.success(result);
} }
...@@ -177,127 +185,140 @@ async function nongzi_update(req, res) { ...@@ -177,127 +185,140 @@ async function nongzi_update(req, res) {
async function nongzi_info(req, res) { async function nongzi_info(req, res) {
let reqConf = {nzId:'String'}; let reqConf = {nzId:'String'};
let { nzId } = eccReqParamater(reqConf, req.body); let { nzId } = eccReqParamater(reqConf, req.body);
let result = await nongziBiz.zhongYangInfo(nzId); let result = await nongziBiz.nongZiInfo(nzId);
res.success(result); res.success(result);
} }
async function nongzi_list(req, res) { async function nongzi_list(req, res) {
let reqConf = {page:'Number'}; let reqConf = {nzType:'Number', dIdList:'Number', useTime:'Number', pageNumber:'Number'};
let { page } = eccReqParamater(reqConf, req.body); let { nzType, dIdList, useTime, pageNumber } = eccReqParamater(reqConf, req.body, ["nzType", "dIdList", "useTime"]);
let result = await nongziBiz.zhongYangListToPage(page); let result = await nongziBiz.nongZiListToPage(nzType, dIdList, useTime, pageNumber);
res.success(result); res.success(result);
} }
//todo
async function nongzi_del(req, res) { async function nongzi_del(req, res) {
let reqConf = {type:'Number'}; let reqConf = {nzId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { nzId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await nongziBiz.deleteNongZi(nzId);
res.success(result); res.success(result);
} }
//todo
async function nongshi_add(req, res) { async function nongshi_add(req, res) {
let reqConf = {type:'Number'}; let reqConf = {param:'Object'};
let { type } = eccReqParamater(reqConf, req.body); let { param } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let userInfo = req.headers;
res.success(result); let result = await nongShiBiz.addNongShi(userInfo, param);
res.success(result);
} }
async function nongshi_update(req, res) { async function nongshi_update(req, res) {
let reqConf = {type:'Number'}; let reqConf = {param:'Object', nsId:"String"};
let { type } = eccReqParamater(reqConf, req.body); let { param, nsId} = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let userInfo = req.headers;
res.success(result); let result = await nongShiBiz.updateNongShi(userInfo, nsId, param);
res.success(result);
} }
async function nongshi_info(req, res) { async function nongshi_info(req, res) {
let reqConf = {type:'Number'}; let reqConf = {nsId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { nsId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await nongShiBiz.nongShiInfo(nsId);
res.success(result); res.success(result);
} }
async function nongshi_list(req, res) { async function nongshi_list(req, res) {
let reqConf = {type:'Number'}; let reqConf = {nsType:'Number', dId:'String', operationTime:'Number', pageNumber:'Number'};
let { type } = eccReqParamater(reqConf, req.body); let { nsType, dId, operationTime, pageNumber } = eccReqParamater(reqConf, req.body, ["nsType", "dId", "operationTime"]);
let result = await userBiz.homePageStatisChanLiang(type); let result = await nongShiBiz.nongShiList(nsType, dId, operationTime, pageNumber);
res.success(result); res.success(result);
} }
async function nongshi_del(req, res) { async function nongshi_del(req, res) {
let reqConf = {type:'Number'}; let reqConf = {nsId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { nsId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await nongShiBiz.deleteNongShi(nsId);
res.success(result); res.success(result);
} }
async function caishou_add(req, res) { async function caishou_add(req, res) {
let reqConf = {type:'Number'}; let reqConf = {param: 'Object'};
let { type } = eccReqParamater(reqConf, req.body); const NotMustHaveKeys = [];
let result = await userBiz.homePageStatisChanLiang(type); let { param } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
res.success(result);
const UserInfo = req.userInfo;
let result = await caishouBiz.addCaiShou(UserInfo, param);
res.success(result);
} }
async function caishou_update(req, res) { async function caishou_update(req, res) {
let reqConf = {type:'Number'}; let reqConf = {param:'Object', csId:"String"};
let { type } = eccReqParamater(reqConf, req.body); let { param, csId} = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let userInfo = req.headers;
res.success(result); let result = await caishouBiz.updateCaiShou(userInfo, csId, param);
res.success(result);
} }
async function caishou_info(req, res) { async function caishou_info(req, res) {
let reqConf = {type:'Number'}; let reqConf = {csId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { csId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await caishouBiz.caishouInfo(csId);
res.success(result); res.success(result);
} }
async function caishou_list(req, res) { async function caishou_list(req, res) {
let reqConf = {type:'Number'}; let reqConf = {zhongYangType:'Number', dId:'String', plantType:'Number', operationTime:'Number', pageNumber:'Number'};
let { type } = eccReqParamater(reqConf, req.body); let { zhongYangType, dId, plantType, operationTime, pageNumber } = eccReqParamater(reqConf, req.body, ["dId", "plantType", "operationTime"]);
let result = await userBiz.homePageStatisChanLiang(type); let result = await caishouBiz.caiShouList(zhongYangType, dId, plantType, operationTime, pageNumber);
res.success(result); res.success(result);
} }
async function caishou_del(req, res) { async function caishou_del(req, res) {
let reqConf = {type:'Number'}; let reqConf = {csId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { csId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await caishouBiz.deleteCaiShou(csId);
res.success(result); res.success(result);
} }
async function xiaoshou_add(req, res) { async function xiaoshou_add(req, res) {
let reqConf = {type:'Number'}; let reqConf = {param: 'Object'};
let { type } = eccReqParamater(reqConf, req.body); let { param } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result); const UserInfo = req.userInfo;
let result = await xiaoShouBiz.addXiaoShou(UserInfo, param);
res.success(result);
} }
async function xiaoshou_update(req, res) { async function xiaoshou_update(req, res) {
let reqConf = {type:'Number'}; let reqConf = {param:'Object', xsId:"String"};
let { type } = eccReqParamater(reqConf, req.body); let { param, xsId} = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let userInfo = req.headers;
res.success(result); let result = await xiaoShouBiz.updateXiaoShou(userInfo, xsId, param);
res.success(result);
} }
async function xiaoshou_info(req, res) { async function xiaoshou_info(req, res) {
let reqConf = {type:'Number'}; let reqConf = {xsId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { xsId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await xiaoShouBiz.xiaoShouInfo(xsId);
res.success(result); res.success(result);
} }
async function xiaoshou_list(req, res) { async function xiaoshou_list(req, res) {
let reqConf = {type:'Number'}; let reqConf = {quXiang:'Number', plantType:'Number', operationTime:'Number', pageNumber:'Number'};
let { type } = eccReqParamater(reqConf, req.body); let { quXiang, plantType, operationTime, pageNumber } = eccReqParamater(reqConf, req.body, ["quXiang", "plantType", "operationTime"]);
let result = await userBiz.homePageStatisChanLiang(type); let result = await xiaoShouBiz.xiaoShouList(quXiang, plantType, operationTime, pageNumber);
res.success(result); res.success(result);
} }
async function xiaoshou_del(req, res) { async function xiaoshou_del(req, res) {
let reqConf = {type:'Number'}; let reqConf = {xsId:'String'};
let { type } = eccReqParamater(reqConf, req.body); let { xsId } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await xiaoShouBiz.deleteXiaoShou(xsId);
res.success(result); res.success(result);
} }
/** /**
* 公共资源路由 * 公共资源路由
*/ */
import * as asyncHandler from 'express-async-handler'; import asyncHandler = require('express-async-handler');
import * as enumConfig from '../config/enum'; import * as enumConfig from '../config/enum';
const config = { const config = {
"/zjnt/xcx/public/plottype":enumConfig.PLOTTYPE,//地块类型 "/zjnt/xcx/public/plottype":enumConfig.PLOTTYPE,//地块类型
"/zjnt/xcx/public/purpose":enumConfig.PURPOSE,//用途 "/zjnt/xcx/public/purpose":enumConfig.PURPOSE,//用途
"/zjnt/xcx/public/dikuaipurpose":enumConfig.DIKUAIPURPOSE,//地块用途
"/zjnt/xcx/public/yangzhipurpose":enumConfig.YANGZHIPURPOSE,//养殖用途
"/zjnt/xcx/public/planttype":enumConfig.PLANTTYPE,//种植种类 "/zjnt/xcx/public/planttype":enumConfig.PLANTTYPE,//种植种类
"/zjnt/xcx/public/arearange":enumConfig.AREARANGE,//面积范围 "/zjnt/xcx/public/arearange":enumConfig.AREARANGE,//面积范围
"/zjnt/xcx/public/nongzitype":enumConfig.NONGZITYPE,//农资类型 "/zjnt/xcx/public/nongzitype":enumConfig.NONGZITYPE,//农资类型
......
import * as asyncHandler from 'express-async-handler' import asyncHandler = require('express-async-handler');
import { eccReqParamater } from '../util/verificationParam'; import { eccReqParamater } from '../util/verificationParam';
import * as diKuaiBiz from '../biz/diKuai'; import * as diKuaiBiz from '../biz/xcx/diKuai';
import * as userBiz from '../biz/user'; import * as userBiz from '../biz/xcx/user';
import * as zhongYangBiz from '../biz/zhongYang'; import * as zhongYangBiz from '../biz/xcx/zhongYang';
import * as nongziBiz from '../biz/nongzi'; import * as nongziBiz from '../biz/xcx/nongzi';
import * as nongShiBiz from '../biz/nongShi'; import * as nongShiBiz from '../biz/xcx/nongShi';
import * as publicRouters from './public'; import * as publicRouters from './public';
import * as adminRouters from './admin'; import * as adminRouters from './admin';
import * as caiShouBiz from '../biz/caiShou'; import * as caiShouBiz from '../biz/xcx/caiShou';
import * as xiaoShouBiz from '../biz/xiaoShou'; import * as xiaoShouBiz from '../biz/xcx/xiaoShou';
import { checkUserToken } from '../middleware/user'; import { checkUserToken } from '../middleware/user';
import * as dataOutBiz from '../biz/dataOut'; import * as dataOutBiz from '../biz/dataOut';
...@@ -19,14 +19,14 @@ export function setRouter(httpServer){ ...@@ -19,14 +19,14 @@ export function setRouter(httpServer){
httpServer.post('/zjnt/xcx/dikuai/list', checkUserToken, asyncHandler(dikuai_list));//列表 httpServer.post('/zjnt/xcx/dikuai/list', checkUserToken, asyncHandler(dikuai_list));//列表
httpServer.post('/zjnt/xcx/dikuai/all', checkUserToken, asyncHandler(dikuai_all));//全部地块列表 httpServer.post('/zjnt/xcx/dikuai/all', checkUserToken, asyncHandler(dikuai_all));//全部地块列表
httpServer.post('/zjnt/xcx/dikuai/update', checkUserToken, asyncHandler(dikuai_update));//更新 httpServer.post('/zjnt/xcx/dikuai/update', checkUserToken, asyncHandler(dikuai_update));//更新
httpServer.post('/zjnt/xcx/dikuai/xuanze/list', checkUserToken, asyncHandler(xuanze_dikuai_list));//可用 httpServer.post('/zjnt/xcx/dikuai/xuanze/list', checkUserToken, asyncHandler(xuanze_dikuai_list));//下拉选择-使用地块
httpServer.post('/zjnt/xcx/dikuai/kecaishou/list', checkUserToken, asyncHandler(xuanze_kecaishou_list));//可采收 httpServer.post('/zjnt/xcx/dikuai/kecaishou/list', checkUserToken, asyncHandler(xuanze_kecaishou_list));//可采收
/**种养 */ /**种养 */
httpServer.post('/zjnt/xcx/zhongyang/dangqian/list', checkUserToken, asyncHandler(zhongyang_dangqian_list));//当前列表 httpServer.post('/zjnt/xcx/zhongyang/dangqian/list', checkUserToken, asyncHandler(zhongyang_dangqian_list));//当前列表
httpServer.post('/zjnt/xcx/zhongyang/jilu/list', checkUserToken, asyncHandler(zhongyang_jilu_list));//种养记录 httpServer.post('/zjnt/xcx/zhongyang/jilu/list', checkUserToken, asyncHandler(zhongyang_jilu_list));//种养记录
httpServer.post('/zjnt/xcx/zhongyang/add', checkUserToken, asyncHandler(zhongyang_add));//添加种养 httpServer.post('/zjnt/xcx/zhongyang/add', checkUserToken, asyncHandler(zhongyang_add));//添加种养
/**农资 */ /**农资 */
httpServer.post('/zjnt/xcx/nongzi/list', checkUserToken, asyncHandler(nongzi_list)); httpServer.post('/zjnt/xcx/nongzi/list', checkUserToken, asyncHandler(nongzi_list));
httpServer.post('/zjnt/xcx/nongzi/add', checkUserToken, asyncHandler(nongzi_add)); httpServer.post('/zjnt/xcx/nongzi/add', checkUserToken, asyncHandler(nongzi_add));
...@@ -55,9 +55,11 @@ export function setRouter(httpServer){ ...@@ -55,9 +55,11 @@ export function setRouter(httpServer){
httpServer.post('/zjnt/xcx/user/login', asyncHandler(user_login));//登录 httpServer.post('/zjnt/xcx/user/login', asyncHandler(user_login));//登录
httpServer.post('/zjnt/xcx/user/logout', checkUserToken, asyncHandler(user_logout));//登出 httpServer.post('/zjnt/xcx/user/logout', checkUserToken, asyncHandler(user_logout));//登出
/**大屏用 */
httpServer.post('/zjnt/xcx/dataout/zzzmj', asyncHandler(data_out));// httpServer.post('/zjnt/xcx/dataout/zzzmj', asyncHandler(data_out));//
httpServer.post('/zjnt/xcx/dataout/guiyu', asyncHandler(data_out_guiyu));// httpServer.post('/zjnt/xcx/dataout/guiyu', asyncHandler(data_out_guiyu));//鳜鱼
httpServer.post('/zjnt/xcx/dataout/zhongyang', asyncHandler(zhongyang_list));//种养列表
httpServer.post('/zjnt/xcx/dataout/yumiao', asyncHandler(yuMiao_list));//鱼苗销售列表
/**公用 */ /**公用 */
...@@ -79,14 +81,16 @@ async function data_out_guiyu(req, res) { ...@@ -79,14 +81,16 @@ async function data_out_guiyu(req, res) {
/**================================================================首页 */ /**================================================================首页 */
async function home_statis_chanliang(req, res) { async function home_statis_chanliang(req, res) {
let reqConf = {type:'Number'}; let reqConf = {type:'Number', year:'Number'};
let { type } = eccReqParamater(reqConf, req.body); let { type, year } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type); let result = await userBiz.homePageStatisChanLiang(year, type);
res.success(result); res.success(result);
} }
async function home_statis_xiaoshou(req, res) { async function home_statis_xiaoshou(req, res) {
let result = await userBiz.homePageStatisXiaoShou(); let reqConf = {year:'Number'};
let { year } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisXiaoShou(year);
res.success(result); res.success(result);
} }
...@@ -286,6 +290,26 @@ async function zhongyang_jilu_list(req, res) { ...@@ -286,6 +290,26 @@ async function zhongyang_jilu_list(req, res) {
res.success(result); res.success(result);
} }
async function zhongyang_list(req, res) {
let reqConf = {zhongYangType:"Number"};
const NotMustHaveKeys = [];
let { zhongYangType } = eccReqParamater(reqConf, req.body, NotMustHaveKeys);
const UserInfo = req.userInfo;
let result = await zhongYangBiz.zhongYangList(zhongYangType);
res.success(result);
}
async function yuMiao_list(req, res) {
const UserInfo = req.userInfo;
let result = await zhongYangBiz.yuMiaoList();
res.success(result);
}
/**================================================================地块 */ /**================================================================地块 */
async function dikuai_add(req, res) { async function dikuai_add(req, res) {
......
...@@ -4,9 +4,16 @@ ...@@ -4,9 +4,16 @@
"target": "es2017", "target": "es2017",
"sourceMap": true, "sourceMap": true,
"rootDir":"./src", "rootDir":"./src",
"outDir":"./out" "outDir":"./out",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"noImplicitAny": false,
"strictNullChecks": false,
"types": ["node"]
}, },
"exclude": [ "exclude": [
"node_modules" "node_modules",
"public"
] ]
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment