Commit 8d51c512 by lixinming

no message

parent 065d5b49
...@@ -102,7 +102,7 @@ export async function caiShouList(zhongYangType:number, selectStr:string, dId:st ...@@ -102,7 +102,7 @@ export async function caiShouList(zhongYangType:number, selectStr:string, dId:st
let dIds = dIdList; let dIds = dIdList;
let didStr = ""; let didStr = "";
dIds.forEach(dId => { dIds.forEach(dId => {
didStr += `${dId} `; didStr += `${diKuaiMap[dId]} `;
}); });
dataList.push({ dataList.push({
plantType:changeEnumValue(PLANTTYPE, plantType), plantType:changeEnumValue(PLANTTYPE, plantType),
......
...@@ -13,10 +13,18 @@ import * as nongshiData from "../data/nongshi"; ...@@ -13,10 +13,18 @@ import * as nongshiData from "../data/nongshi";
import * as nongziData from "../data/nongzi"; import * as nongziData from "../data/nongzi";
import { changeEnumValue } from "../util/verificationEnum"; import { changeEnumValue } from "../util/verificationEnum";
const md5 = require("md5"); const md5 = require("md5");
const xlsx = require('node-xlsx');
const path = require('path');
const fs = require('fs');
export async function dataInit() { export async function dataInit() {
// return;
// let list = [
// {name:"吴肖", loginId:"17274689187", userId:randomId("17274689187"), pwd:getPwdMd5("17274689187", md5PwdStr("123456")), position:"测试", phone:"17274689187" },
// {name:"李欣鸣", loginId:"18711017326", userId:randomId("18711017326"), pwd:getPwdMd5("18711017326", md5PwdStr("123456")), position:"测试", phone:"18711017326" },
// {name:"李颖", loginId:"17638538121", userId:randomId("17638538121"), pwd:getPwdMd5("17638538121", md5PwdStr("123456")), position:"测试", phone:"17638538121" },
// {name:"吴肖琴", loginId:"15007949519", userId:randomId("15007949519"), pwd:getPwdMd5("15007949519", md5PwdStr("123456")), position:"测试", phone:"15007949519" },
// ]
// let list = [ // let list = [
// {name:"孙伟锋", loginId:"13501917073", userId:randomId("13501917073"), pwd:getPwdMd5("13501917073", md5PwdStr("917073")), position:"总经理、支部书记", phone:"13501917073" }, // {name:"孙伟锋", loginId:"13501917073", userId:randomId("13501917073"), pwd:getPwdMd5("13501917073", md5PwdStr("917073")), position:"总经理、支部书记", phone:"13501917073" },
// {name:"奚准", loginId:"13681774690", userId:randomId("13681774690"), pwd:getPwdMd5("13681774690", md5PwdStr("774690")), position:"委员、副总经理", phone:"13681774690" }, // {name:"奚准", loginId:"13681774690", userId:randomId("13681774690"), pwd:getPwdMd5("13681774690", md5PwdStr("774690")), position:"委员、副总经理", phone:"13681774690" },
...@@ -39,7 +47,7 @@ export async function dataInit() { ...@@ -39,7 +47,7 @@ export async function dataInit() {
// {name:"奚晓萍", loginId:"13816746319", userId:randomId("13816746319"), pwd:getPwdMd5("13816746319", md5PwdStr("746319")), position:"林业养护", phone:"13816746319" }, // {name:"奚晓萍", loginId:"13816746319", userId:randomId("13816746319"), pwd:getPwdMd5("13816746319", md5PwdStr("746319")), position:"林业养护", phone:"13816746319" },
// ]; // ];
// await usersData.createManyUser(list); // await usersData.createManyUser(list);
// return
const Now = new Date().valueOf(); const Now = new Date().valueOf();
...@@ -648,3 +656,1276 @@ export async function yjDataInit0508() { ...@@ -648,3 +656,1276 @@ export async function yjDataInit0508() {
// console.log(); // console.log();
} }
function getExcel(filePath) {
const workSheetsFromFile = xlsx.parse(filePath);
let sheetMap = {};
let sheetList = [];
for (let i = 0; i < workSheetsFromFile.length; i++) {
let sheetInfo = workSheetsFromFile[i];
sheetMap[sheetInfo.name] = sheetInfo.data;
sheetList.push(sheetInfo);
}
return {sheetMap, sheetList}
}
export async function dataInit0516() {
const Now = new Date().valueOf();
//导入地块数据
let diKuaiList =[
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.5, useSize:0, size:8.5, area:"A区域", name:"A-11#", code:"A-11#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:11.3, useSize:0, size:11.3, area:"A区域", name:"A-9#", code:"A-9#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:13.3, useSize:0, size:13.3, area:"A区域", name:"A-10#", code:"A-10#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:10.4, useSize:0, size:10.4, area:"A区域", name:"A-8#", code:"A-8#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.3, useSize:0, size:8.3, area:"A区域", name:"A-7#", code:"A-7#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:9.5, useSize:0, size:9.5, area:"A区域", name:"A-6#", code:"A-6#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:11.9, useSize:0, size:11.9, area:"A区域", name:"A-5#", code:"A-5#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:22, useSize:0, size:22, area:"A区域", name:"A-1#", code:"A-1#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:14.9, useSize:0, size:14.9, area:"A区域", name:"A-2#", code:"A-2#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:22.7, useSize:0, size:22.7, area:"A区域", name:"A-3#", code:"A-3#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:26.9, useSize:0, size:26.9, area:"A区域", name:"A-4#", code:"A-4#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.2, useSize:0, size:8.2, area:"B区域", name:"B-1#", code:"B-1#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:5.8, useSize:0, size:5.8, area:"B区域", name:"B-2#", code:"B-2#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:5.2, useSize:0, size:5.2, area:"B区域", name:"B-3#", code:"B-3#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:2.8, useSize:0, size:2.8, area:"B区域", name:"B-14#", code:"B-14#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:6.5, useSize:0, size:6.5, area:"B区域", name:"B-10#", code:"B-10#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:10, useSize:0, size:10, area:"B区域", name:"B-4#", code:"B-4#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:10, useSize:0, size:10, area:"B区域", name:"B-5#", code:"B-5#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:3.4, useSize:0, size:3.4, area:"B区域", name:"B-9#", code:"B-9#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:3.4, useSize:0, size:3.4, area:"B区域", name:"B-8#", code:"B-8#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:3, useSize:0, size:3, area:"B区域", name:"B-7#", code:"B-7#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:3, useSize:0, size:3, area:"B区域", name:"B-6#", code:"B-6#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:4.1, useSize:0, size:4.15, area:"B区域", name:"B-11#", code:"B-11#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:4.1, useSize:0, size:4.1, area:"B区域", name:"B-12#", code:"B-12#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.1, useSize:0, size:8.1, area:"B区域", name:"B-13#", code:"B-13#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:3.6, useSize:0, size:3.6, area:"B区域", name:"B-15#", code:"B-15#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:2.5, useSize:0, size:2.5, area:"B区域", name:"B-16#", code:"B-16#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:13.6, useSize:0, size:13.6, area:"C区域", name:"C-3#", code:"C-3#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.2, useSize:0, size:8.2, area:"C区域", name:"C-2#", code:"C-2#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.5, useSize:0, size:8.5, area:"C区域", name:"C-1#", code:"C-1#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:10.4, useSize:0, size:10.4, area:"D区域", name:"D-1#", code:"D-1#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:8.7, useSize:0, size:8.7, area:"D区域", name:"D-2#", code:"D-2#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:6.2, useSize:0, size:6.2, area:"D区域", name:"D-A-02#", code:"D-A-02#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:5.2, useSize:0, size:5.2, area:"D区域", name:"D-A-03#", code:"D-A-03#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:10.4, useSize:0, size:10.4, area:"D区域", name:"D-B-01#", code:"D-B-01#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:3.4, useSize:0, size:3.4, area:"D区域", name:"D-B-02#", code:"D-B-02#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:6.2, useSize:0, size:6.2, area:"D区域", name:"D-C-01#", code:"D-C-01#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:6.2, useSize:0, size:6.2, area:"D区域", name:"D-C-02#", code:"D-C-02#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:6.6, useSize:0, size:6.6, area:"D区域", name:"D-C-03#", code:"D-C-03#"},
{ dId:randomId(TABLENAME.地块表), ct : Now, createUser:"admin", purpose:PURPOSE.菜田, plotType:PLOTTYPE.地块, nullSize:6.6, useSize:0, size:6.6, area:"D区域", name:"D-C-04#", code:"D-C-04#"},
//养殖池
{ dId:randomId(TABLENAME.地块表), ct : Now, creatUser:"admin", purpose:PURPOSE.养殖, plotType:PLOTTYPE.养殖池, nullSize:100, useSize:0, size:100, area:"A区域", name:"A-01#", code:"A-01#"},
];
let 校验面积Map = {};
let diKuaiMap = {}
diKuaiList.forEach(info => {
diKuaiMap[info.name] = info.dId;
校验面积Map[info.code] = info.size;
});
await dikuaiData.addManyData(diKuaiList);
let filePath = path.join(__dirname.substring(0,__dirname.indexOf("out")), "res", "导入数据0516.xlsx" );
let {sheetMap} = getExcel(filePath);
let 种植 = sheetMap["种植"];
let 采收 = sheetMap["采收"];
let 农资 = sheetMap["农资"];
let 农事 = sheetMap["农事"];
let 销售 = sheetMap["销售"];
let zhongzhiDataList = [];
for (let i= 1; i < 种植.length; i++) {
let subList = 种植[i];
if (!i) {
return
}
let name = subList[0];
let dk = subList[2];
let size = subList[3];
let time = subList[4];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk])return
zhongzhiDataList.push({code:dk, dId:diKuaiMap[dk], zId:randomId(TABLENAME.种植表), size:parseFloat(size), plantType:PLANTTYPE[name], plantTime:ms ,uId:"admin", isEnd:0});
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
else {
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
}
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
//校验种植面积
let 校验种养map = {};
let 种养面积 = {};
let countMap= {};
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, plantType} = zhongzhiDataList[i];
if (!种养面积[code]) 种养面积[code] = 0;
种养面积[code] += size;
if (!countMap[`${code}_${plantType}`]) countMap[`${code}_${plantType}`] = 0;
countMap[`${code}_${plantType}`] += 1;
}
for (let code in 种养面积) {
let size = 种养面积[code];
if (校验面积Map[code].size < size) console.log(code, "种植面积", size ,"大于", 校验面积Map[code].size);
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, zId, plantType} = zhongzhiDataList[i];
if (!校验面积Map[code]) console.log("codeId不对", code);
校验种养map[`${code}_${plantType}`] = zId;
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
let caiShouList = [];
采收.forEach((subList, index) => {
if (!index) {
return
}
let name = subList[0];
let dk = subList[2];
let weight = subList[3];
let time = subList[5];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk])return
let csId = randomId("cs");
let dIdList = [diKuaiMap[dk]];
caiShouList.push({csId, dIdList, weight:parseFloat(weight), code:dk, dId:diKuaiMap[dk], plantType:PLANTTYPE[name], createUser:"admin", ct:ms });
});
let addCaiShouList = [];
let 映射Map = {};
for (let i= 0; i < caiShouList.length; i++) {
let {code, plantType} = caiShouList[i];
if (!校验种养map[`${code}_${plantType}`]) console.log(code, "种类:", changeEnumValue(SHUCAI, plantType) ,"无效");
else {
addCaiShouList.push(caiShouList[i]);
映射Map[`${code}_${plantType}`] = 校验种养map[`${code}_${plantType}`];
}
}
for (let i= 0; i < addCaiShouList.length; i++) {
let {dIdList, size, code, plantType, csId} = addCaiShouList[i];
let zId = 映射Map[`${code}_${plantType}`];
let zhongzhiInfo = await zhongzhiData.selectOne({zId, isEnd:0});
if (zhongzhiInfo) {
zhongzhiInfo.csId = csId;
countMap[`${code}_${plantType}`] -= 1;
if (countMap[`${code}_${plantType}`] <= 0) {
zhongzhiInfo.isEnd = 1;
}
await zhongzhiInfo.save();
let diKuaiInfo = await dikuaiData.selectOne({code});
if (!diKuaiInfo) console.log("锚点2 地块不存在", code);
else {
diKuaiInfo.nullSize = diKuaiInfo.nullSize + zhongzhiInfo.size;
diKuaiInfo.useSize = diKuaiInfo.useSize - zhongzhiInfo.size;
}
await diKuaiInfo.save();
}
await caishouData.addData(addCaiShouList[i]);
}
let xiaoshouList = [];
销售.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let weight = subList[2];
let time = subList[4];
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
xiaoshouList.push({
xsId:randomId(TABLENAME.销售),
plantType:PLANTTYPE[name],
quXiang:XIAOSHOUQUXIANG.田头销售,
weight:parseFloat(weight),
operationTime:new Date(time).valueOf(),
ct:Now,
createUser:"admin"})
});
await xiaoshouData.addManyData(xiaoshouList);
let nongshi = [];
农事.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let time = subList[3];
if (!NONGSHITYPE[name]) console.log(name, "名称不在NONGSHITYPE枚举范围")
if (!diKuaiMap[dk])return
if (dk == "所有种植地块") {
let allList = [];
if (subList[1] == "A区") {
allList = [, "A-11#", "A-9#", "A-10#", "A-8#", "A-7#", "A-6#", "A-5#", "A-1#", "A-2#", "A-3#", "A-4#"];
}else {
allList = [
"B-1#", "B-2#", "B-3#", "B-14#", "B-10#", "B-4#", "B-5#", "B-9#", "B-8#", "B-7#", "B-6#", "B-11#", "B-12#", "B-13#", "B-15#", "B-16#",
]
}
allList.forEach(element => {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[element]],
operationTime:new Date(time).valueOf(), ct:Now
})
});
} else {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[dk]],
operationTime:new Date(time).valueOf(), ct:Now
})
}
});
await nongshiData.addManyData(nongshi);
let nongziList = [];
农资.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let count = subList[4];
let plName = subList[3];
let time = subList[6];
if (!NONGZITYPE[name]) console.log(name, "名称a不在枚举范围")
if (!diKuaiMap[dk]) return
if (!PLANTTYPE[plName]) console.log(plName, "作物名称不在枚举范围")
nongziList.push({
nzId:randomId(TABLENAME.农资),
nzType:NONGZITYPE[name],
dIdList:[diKuaiMap[dk]],
plantType:PLANTTYPE[plName],
count:parseFloat(count),
useTime:new Date(time).valueOf(),
ct:Now
});
});
await nongziData.addManyData(nongziList);
console.log("数据导入成功");
}
export async function dataInit0522() {
let Now = new Date().valueOf();
let diKuaiList = await dikuaiData.selectToParam({});
let 校验面积Map = {};
let diKuaiMap = {}
diKuaiList.forEach(info => {
diKuaiMap[info.name] = info.dId;
校验面积Map[info.code] = info.size;
});
let filePath = path.join(__dirname.substring(0,__dirname.indexOf("out")), "res", "导入数据0522.xlsx" );
let {sheetMap} = getExcel(filePath);
let 种植 = sheetMap["种植"];
let 采收 = sheetMap["采收"];
let 农资 = sheetMap["农资"];
let 农事 = sheetMap["农事"];
let 销售 = sheetMap["销售"];
let zhongzhiDataList = [];
for (let i= 1; i < 种植.length; i++) {
let subList = 种植[i];
if (!i) {
return
}
let name = subList[0];
let dk = subList[2];
let size = subList[3];
let time = subList[4];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk]) return;
zhongzhiDataList.push({code:dk, dId:diKuaiMap[dk], zId:randomId(TABLENAME.种植表), size:parseFloat(size), plantType:PLANTTYPE[name], plantTime:ms ,uId:"admin", isEnd:0});
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
else {
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
}
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
//校验种植面积
let 校验种养map = {};
let 种养面积 = {};
let countMap= {};
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, plantType} = zhongzhiDataList[i];
if (!种养面积[code]) 种养面积[code] = 0;
种养面积[code] += size;
if (!countMap[`${code}_${plantType}`]) countMap[`${code}_${plantType}`] = 0;
countMap[`${code}_${plantType}`] += 1;
}
for (let code in 种养面积) {
let size = 种养面积[code];
if (校验面积Map[code].size < size) console.log(code, "种植面积", size ,"大于", 校验面积Map[code].size);
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, zId, plantType} = zhongzhiDataList[i];
if (!校验面积Map[code]) console.log("codeId不对", code);
校验种养map[`${code}_${plantType}`] = zId;
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
console.log()
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
let caiShouList = [];
采收.forEach((subList, index) => {
if (!index) {
return
}
let name = subList[0];
let dk = subList[2];
let weight = subList[3];
let time = subList[5];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk])return
let csId = randomId("cs");
let dIdList = [diKuaiMap[dk]];
caiShouList.push({csId, dIdList, weight:parseFloat(weight), code:dk, dId:diKuaiMap[dk], plantType:PLANTTYPE[name], createUser:"admin", ct:ms });
});
let addCaiShouList = [];
let notChangeCaiShouList = [];
let 映射Map = {};
for (let i= 0; i < caiShouList.length; i++) {
let {code, plantType} = caiShouList[i];
if (!校验种养map[`${code}_${plantType}`]) {
console.log(code, "种类:", changeEnumValue(SHUCAI, plantType) ,"无效");
notChangeCaiShouList.push(caiShouList[i]);
}
else {
addCaiShouList.push(caiShouList[i]);
映射Map[`${code}_${plantType}`] = 校验种养map[`${code}_${plantType}`];
}
}
caishouData.addManyData(notChangeCaiShouList);
for (let i= 0; i < addCaiShouList.length; i++) {
let {dIdList, size, code, plantType, csId} = addCaiShouList[i];
let zId = 映射Map[`${code}_${plantType}`];
let zhongzhiInfo = await zhongzhiData.selectOne({zId, isEnd:0});
if (zhongzhiInfo) {
zhongzhiInfo.csId = csId;
countMap[`${code}_${plantType}`] -= 1;
if (countMap[`${code}_${plantType}`] <= 0) {
zhongzhiInfo.isEnd = 1;
}
await zhongzhiInfo.save();
let diKuaiInfo = await dikuaiData.selectOne({code});
if (!diKuaiInfo) console.log("锚点2 地块不存在", code);
else {
diKuaiInfo.nullSize = diKuaiInfo.nullSize + zhongzhiInfo.size;
diKuaiInfo.useSize = diKuaiInfo.useSize - zhongzhiInfo.size;
console.log()
}
await diKuaiInfo.save();
}
await caishouData.addData(addCaiShouList[i]);
}
let xiaoshouList = [];
销售.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let weight = subList[2];
let time = subList[4];
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
xiaoshouList.push({
xsId:randomId(TABLENAME.销售),
plantType:PLANTTYPE[name],
quXiang:XIAOSHOUQUXIANG.田头销售,
weight:parseFloat(weight),
operationTime:new Date(time).valueOf(),
ct:Now,
createUser:"admin"})
});
await xiaoshouData.addManyData(xiaoshouList);
let nongshi = [];
农事.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let time = subList[3];
if (!NONGSHITYPE[name]) console.log(name, "名称不在NONGSHITYPE枚举范围")
if (!diKuaiMap[dk])return
if (dk == "所有种植地块") {
let allList = [];
if (subList[1] == "A区") {
allList = [, "A-11#", "A-9#", "A-10#", "A-8#", "A-7#", "A-6#", "A-5#", "A-1#", "A-2#", "A-3#", "A-4#"];
}else {
allList = [
"B-1#", "B-2#", "B-3#", "B-14#", "B-10#", "B-4#", "B-5#", "B-9#", "B-8#", "B-7#", "B-6#", "B-11#", "B-12#", "B-13#", "B-15#", "B-16#",
]
}
allList.forEach(element => {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[element]],
operationTime:new Date(time).valueOf(), ct:Now
})
});
} else {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[dk]],
operationTime:new Date(time).valueOf(), ct:Now
})
}
});
await nongshiData.addManyData(nongshi);
let nongziList = [];
农资.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let count = subList[4];
let plName = subList[3];
let time = subList[6];
if (!NONGZITYPE[name]) console.log(name, "名称a不在枚举范围")
if (!diKuaiMap[dk]) return
if (!PLANTTYPE[plName]) console.log(plName, "作物名称不在枚举范围")
nongziList.push({
nzId:randomId(TABLENAME.农资),
nzType:NONGZITYPE[name],
dIdList:[diKuaiMap[dk]],
plantType:PLANTTYPE[plName],
count:parseFloat(count),
useTime:new Date(time).valueOf(),
ct:Now
});
});
await nongziData.addManyData(nongziList);
console.log("数据导入成功");
}
export async function dataInit0604() {
let Now = new Date().valueOf();
let diKuaiList = await dikuaiData.selectToParam({});
let 校验面积Map = {};
let diKuaiMap = {}
diKuaiList.forEach(info => {
diKuaiMap[info.name] = info.dId;
校验面积Map[info.code] = info.size;
});
let filePath = path.join(__dirname.substring(0,__dirname.indexOf("out")), "res", "导入数据0604.xlsx" );
let {sheetMap} = getExcel(filePath);
let 种植 = sheetMap["种植"];
let 采收 = sheetMap["采收"];
let 农资 = sheetMap["农资"];
let 农事 = sheetMap["农事"];
let 销售 = sheetMap["销售"];
let zhongzhiDataList = [];
for (let i= 1; i < 种植.length; i++) {
let subList = 种植[i];
if (!i) {
continue
}
let name = subList[0];
let dk = subList[2];
let size = subList[3];
let time = subList[4];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk]) continue;
zhongzhiDataList.push({code:dk, dId:diKuaiMap[dk], zId:randomId(TABLENAME.种植表), size:parseFloat(size), plantType:PLANTTYPE[name], plantTime:ms ,uId:"admin", isEnd:0});
}
console.log()
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
else {
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
}
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
//校验种植面积
let 校验种养map = {};
let 种养面积 = {};
let countMap= {};
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, plantType} = zhongzhiDataList[i];
if (!种养面积[code]) 种养面积[code] = 0;
种养面积[code] += size;
if (!countMap[`${code}_${plantType}`]) countMap[`${code}_${plantType}`] = 0;
countMap[`${code}_${plantType}`] += 1;
}
for (let code in 种养面积) {
let size = 种养面积[code];
if (校验面积Map[code].size < size) console.log(code, "种植面积", size ,"大于", 校验面积Map[code].size);
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, zId, plantType} = zhongzhiDataList[i];
if (!校验面积Map[code]) console.log("codeId不对", code);
校验种养map[`${code}_${plantType}`] = zId;
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
console.log()
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
let caiShouList = [];
采收.forEach((subList, index) => {
if (!index) {
return
}
let name = subList[0];
let dk = subList[2];
let weight = subList[3];
let time = subList[5];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk])return
let csId = randomId("cs");
let dIdList = [diKuaiMap[dk]];
caiShouList.push({csId, dIdList, weight:parseFloat(weight), code:dk, dId:diKuaiMap[dk], plantType:PLANTTYPE[name], createUser:"admin", ct:ms });
});
let addCaiShouList = [];
let notChangeCaiShouList = [];
let 映射Map = {};
for (let i= 0; i < caiShouList.length; i++) {
let {code, plantType} = caiShouList[i];
if (!校验种养map[`${code}_${plantType}`]) {
console.log(code, "种类:", changeEnumValue(SHUCAI, plantType) ,"无效");
notChangeCaiShouList.push(caiShouList[i]);
}
else {
addCaiShouList.push(caiShouList[i]);
映射Map[`${code}_${plantType}`] = 校验种养map[`${code}_${plantType}`];
}
}
caishouData.addManyData(notChangeCaiShouList);
for (let i= 0; i < addCaiShouList.length; i++) {
let {dIdList, size, code, plantType, csId} = addCaiShouList[i];
let zId = 映射Map[`${code}_${plantType}`];
let zhongzhiInfo = await zhongzhiData.selectOne({zId, isEnd:0});
if (zhongzhiInfo) {
zhongzhiInfo.csId = csId;
countMap[`${code}_${plantType}`] -= 1;
if (countMap[`${code}_${plantType}`] <= 0) {
zhongzhiInfo.isEnd = 1;
}
await zhongzhiInfo.save();
let diKuaiInfo = await dikuaiData.selectOne({code});
if (!diKuaiInfo) console.log("锚点2 地块不存在", code);
else {
diKuaiInfo.nullSize = diKuaiInfo.nullSize + zhongzhiInfo.size;
diKuaiInfo.useSize = diKuaiInfo.useSize - zhongzhiInfo.size;
console.log()
}
await diKuaiInfo.save();
}
await caishouData.addData(addCaiShouList[i]);
}
let xiaoshouList = [];
销售.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let weight = subList[2];
let time = subList[4];
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
xiaoshouList.push({
xsId:randomId(TABLENAME.销售),
plantType:PLANTTYPE[name],
quXiang:XIAOSHOUQUXIANG.田头销售,
weight:parseFloat(weight),
operationTime:new Date(time).valueOf(),
ct:Now,
createUser:"admin"})
});
await xiaoshouData.addManyData(xiaoshouList);
let nongshi = [];
农事.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let time = subList[3];
if (!NONGSHITYPE[name]) console.log(name, "名称不在NONGSHITYPE枚举范围")
if (!diKuaiMap[dk])return
if (dk == "所有种植地块") {
let allList = [];
if (subList[1] == "A区") {
allList = [, "A-11#", "A-9#", "A-10#", "A-8#", "A-7#", "A-6#", "A-5#", "A-1#", "A-2#", "A-3#", "A-4#"];
}else {
allList = [
"B-1#", "B-2#", "B-3#", "B-14#", "B-10#", "B-4#", "B-5#", "B-9#", "B-8#", "B-7#", "B-6#", "B-11#", "B-12#", "B-13#", "B-15#", "B-16#",
]
}
allList.forEach(element => {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[element]],
operationTime:new Date(time).valueOf(), ct:Now
})
});
} else {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[dk]],
operationTime:new Date(time).valueOf(), ct:Now
})
}
});
await nongshiData.addManyData(nongshi);
let nongziList = [];
农资.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let count = subList[4];
let plName = subList[3];
let time = subList[6];
if (!NONGZITYPE[name]) console.log(name, "名称a不在枚举范围")
if (!diKuaiMap[dk]) return
if (!PLANTTYPE[plName]) console.log(plName, "作物名称不在枚举范围")
nongziList.push({
nzId:randomId(TABLENAME.农资),
nzType:NONGZITYPE[name],
dIdList:[diKuaiMap[dk]],
plantType:PLANTTYPE[plName],
count:parseFloat(count),
useTime:new Date(time).valueOf(),
ct:Now
});
});
await nongziData.addManyData(nongziList);
console.log("数据导入成功");
}
export async function dataInit0609() {
let Now = new Date().valueOf();
let diKuaiList = await dikuaiData.selectToParam({});
let 校验面积Map = {};
let diKuaiMap = {}
diKuaiList.forEach(info => {
diKuaiMap[info.name] = info.dId;
校验面积Map[info.code] = info.size;
});
let filePath = path.join(__dirname.substring(0,__dirname.indexOf("out")), "res", "导入数据0609.xlsx" );
let {sheetMap} = getExcel(filePath);
let 种植 = sheetMap["种植"];
let 采收 = sheetMap["采收"];
let 农资 = sheetMap["农资"];
let 农事 = sheetMap["农事"];
let 销售 = sheetMap["销售"];
let zhongzhiDataList = [];
for (let i= 1; i < 种植.length; i++) {
let subList = 种植[i];
if (!i) {
continue
}
let name = subList[0];
let dk = subList[2];
let size = subList[3];
let time = subList[4];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk]) continue;
zhongzhiDataList.push({code:dk, dId:diKuaiMap[dk], zId:randomId(TABLENAME.种植表), size:parseFloat(size), plantType:PLANTTYPE[name], plantTime:ms ,uId:"admin", isEnd:0});
}
console.log()
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
else {
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
}
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
//校验种植面积
let 校验种养map = {};
let 种养面积 = {};
let countMap= {};
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, plantType} = zhongzhiDataList[i];
if (!种养面积[code]) 种养面积[code] = 0;
种养面积[code] += size;
if (!countMap[`${code}_${plantType}`]) countMap[`${code}_${plantType}`] = 0;
countMap[`${code}_${plantType}`] += 1;
}
for (let code in 种养面积) {
let size = 种养面积[code];
if (校验面积Map[code].size < size) console.log(code, "种植面积", size ,"大于", 校验面积Map[code].size);
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, zId, plantType} = zhongzhiDataList[i];
if (!校验面积Map[code]) console.log("codeId不对", code);
校验种养map[`${code}_${plantType}`] = zId;
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
console.log()
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
let caiShouList = [];
采收.forEach((subList, index) => {
if (!index) {
return
}
let name = subList[0];
let dk = subList[2];
let weight = subList[3];
let time = subList[5];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk])return
let csId = randomId("cs");
let dIdList = [diKuaiMap[dk]];
caiShouList.push({csId, dIdList, weight:parseFloat(weight), code:dk, dId:diKuaiMap[dk], plantType:PLANTTYPE[name], createUser:"admin", ct:ms });
});
let addCaiShouList = [];
let notChangeCaiShouList = [];
let 映射Map = {};
for (let i= 0; i < caiShouList.length; i++) {
let {code, plantType} = caiShouList[i];
if (!校验种养map[`${code}_${plantType}`]) {
console.log(code, "种类:", changeEnumValue(SHUCAI, plantType) ,"无效");
notChangeCaiShouList.push(caiShouList[i]);
}
else {
addCaiShouList.push(caiShouList[i]);
映射Map[`${code}_${plantType}`] = 校验种养map[`${code}_${plantType}`];
}
}
caishouData.addManyData(notChangeCaiShouList);
for (let i= 0; i < addCaiShouList.length; i++) {
let {dIdList, size, code, plantType, csId} = addCaiShouList[i];
let zId = 映射Map[`${code}_${plantType}`];
let zhongzhiInfo = await zhongzhiData.selectOne({zId, isEnd:0});
if (zhongzhiInfo) {
zhongzhiInfo.csId = csId;
countMap[`${code}_${plantType}`] -= 1;
if (countMap[`${code}_${plantType}`] <= 0) {
zhongzhiInfo.isEnd = 1;
}
await zhongzhiInfo.save();
let diKuaiInfo = await dikuaiData.selectOne({code});
if (!diKuaiInfo) console.log("锚点2 地块不存在", code);
else {
diKuaiInfo.nullSize = diKuaiInfo.nullSize + zhongzhiInfo.size;
diKuaiInfo.useSize = diKuaiInfo.useSize - zhongzhiInfo.size;
console.log()
}
await diKuaiInfo.save();
}
await caishouData.addData(addCaiShouList[i]);
}
let xiaoshouList = [];
销售.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let weight = subList[2];
let time = subList[4];
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
xiaoshouList.push({
xsId:randomId(TABLENAME.销售),
plantType:PLANTTYPE[name],
quXiang:XIAOSHOUQUXIANG.田头销售,
weight:parseFloat(weight),
operationTime:new Date(time).valueOf(),
ct:Now,
createUser:"admin"})
});
await xiaoshouData.addManyData(xiaoshouList);
let nongshi = [];
农事.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let time = subList[3];
if (!NONGSHITYPE[name]) console.log(name, "名称不在NONGSHITYPE枚举范围")
if (!diKuaiMap[dk])return
if (dk == "所有种植地块") {
let allList = [];
if (subList[1] == "A区") {
allList = [, "A-11#", "A-9#", "A-10#", "A-8#", "A-7#", "A-6#", "A-5#", "A-1#", "A-2#", "A-3#", "A-4#"];
}else {
allList = [
"B-1#", "B-2#", "B-3#", "B-14#", "B-10#", "B-4#", "B-5#", "B-9#", "B-8#", "B-7#", "B-6#", "B-11#", "B-12#", "B-13#", "B-15#", "B-16#",
]
}
allList.forEach(element => {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[element]],
operationTime:new Date(time).valueOf(), ct:Now
})
});
} else {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[dk]],
operationTime:new Date(time).valueOf(), ct:Now
})
}
});
await nongshiData.addManyData(nongshi);
let nongziList = [];
农资.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let count = subList[4];
let plName = subList[3];
let time = subList[6];
if (!NONGZITYPE[name]) console.log(name, "名称a不在枚举范围")
if (!diKuaiMap[dk]) return
if (!PLANTTYPE[plName]) console.log(plName, "作物名称不在枚举范围")
nongziList.push({
nzId:randomId(TABLENAME.农资),
nzType:NONGZITYPE[name],
dIdList:[diKuaiMap[dk]],
plantType:PLANTTYPE[plName],
count:parseFloat(count),
useTime:new Date(time).valueOf(),
ct:Now
});
});
await nongziData.addManyData(nongziList);
console.log("数据导入成功");
}
export async function dataInit0618() {
return
let Now = new Date().valueOf();
let diKuaiList = await dikuaiData.selectToParam({});
let 校验面积Map = {};
let diKuaiMap = {}
diKuaiList.forEach(info => {
diKuaiMap[info.name] = info.dId;
校验面积Map[info.code] = info.size;
});
let filePath = path.join(__dirname.substring(0,__dirname.indexOf("out")), "res", "导入数据0618.xlsx" );
let {sheetMap} = getExcel(filePath);
let 种植 = sheetMap["种植"];
let 采收 = sheetMap["采收"];
let 农资 = sheetMap["农资"];
let 农事 = sheetMap["农事"];
let 销售 = sheetMap["销售"];
let zhongzhiDataList = [];
for (let i= 1; i < 种植.length; i++) {
let subList = 种植[i];
if (!i) {
continue
}
let name = subList[0];
let dk = subList[2];
let size = subList[3];
let time = subList[4];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk]) continue;
zhongzhiDataList.push({code:dk, dId:diKuaiMap[dk], zId:randomId(TABLENAME.种植表), size:parseFloat(size), plantType:PLANTTYPE[name], plantTime:ms ,uId:"admin", isEnd:0});
}
console.log()
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
else {
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
}
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
//校验种植面积
let 校验种养map = {};
let 种养面积 = {};
let countMap= {};
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, plantType} = zhongzhiDataList[i];
if (!种养面积[code]) 种养面积[code] = 0;
种养面积[code] += size;
if (!countMap[`${code}_${plantType}`]) countMap[`${code}_${plantType}`] = 0;
countMap[`${code}_${plantType}`] += 1;
}
for (let code in 种养面积) {
let size = 种养面积[code];
if (校验面积Map[code].size < size) console.log(code, "种植面积", size ,"大于", 校验面积Map[code].size);
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {code, size, zId, plantType} = zhongzhiDataList[i];
if (!校验面积Map[code]) console.log("codeId不对", code);
校验种养map[`${code}_${plantType}`] = zId;
}
for (let i= 0; i < zhongzhiDataList.length; i++) {
let {dId, size, code} = zhongzhiDataList[i];
let diKuaiInfo = await dikuaiData.selectOne({dId});
if (!diKuaiInfo) {
console.log("锚点1 地块不存在", dId, code);
}
diKuaiInfo.nullSize = diKuaiInfo.size - size;
diKuaiInfo.useSize = diKuaiInfo.useSize + size;
console.log()
await diKuaiInfo.save();
await zhongzhiData.addData(zhongzhiDataList[i]);
}
let caiShouList = [];
采收.forEach((subList, index) => {
if (!index) {
return
}
let name = subList[0];
let dk = subList[2];
let weight = subList[3];
let time = subList[5];
let ms = new Date(time).valueOf();
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
if (!diKuaiMap[dk])return
let csId = randomId("cs");
let dIdList = [diKuaiMap[dk]];
caiShouList.push({csId, dIdList, weight:parseFloat(weight), code:dk, dId:diKuaiMap[dk], plantType:PLANTTYPE[name], createUser:"admin", ct:ms });
});
let addCaiShouList = [];
let notChangeCaiShouList = [];
let 映射Map = {};
for (let i= 0; i < caiShouList.length; i++) {
let {code, plantType} = caiShouList[i];
if (!校验种养map[`${code}_${plantType}`]) {
console.log(code, "种类:", changeEnumValue(SHUCAI, plantType) ,"无效");
notChangeCaiShouList.push(caiShouList[i]);
}
else {
addCaiShouList.push(caiShouList[i]);
映射Map[`${code}_${plantType}`] = 校验种养map[`${code}_${plantType}`];
}
}
caishouData.addManyData(notChangeCaiShouList);
for (let i= 0; i < addCaiShouList.length; i++) {
let {dIdList, size, code, plantType, csId} = addCaiShouList[i];
let zId = 映射Map[`${code}_${plantType}`];
let zhongzhiInfo = await zhongzhiData.selectOne({zId, isEnd:0});
if (zhongzhiInfo) {
zhongzhiInfo.csId = csId;
countMap[`${code}_${plantType}`] -= 1;
if (countMap[`${code}_${plantType}`] <= 0) {
zhongzhiInfo.isEnd = 1;
}
await zhongzhiInfo.save();
let diKuaiInfo = await dikuaiData.selectOne({code});
if (!diKuaiInfo) console.log("锚点2 地块不存在", code);
else {
diKuaiInfo.nullSize = diKuaiInfo.nullSize + zhongzhiInfo.size;
diKuaiInfo.useSize = diKuaiInfo.useSize - zhongzhiInfo.size;
console.log()
}
await diKuaiInfo.save();
}
await caishouData.addData(addCaiShouList[i]);
}
let xiaoshouList = [];
销售.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let weight = subList[2];
let time = subList[4];
if (!PLANTTYPE[name]) console.log(name, "名称不在枚举范围")
xiaoshouList.push({
xsId:randomId(TABLENAME.销售),
plantType:PLANTTYPE[name],
quXiang:XIAOSHOUQUXIANG.田头销售,
weight:parseFloat(weight),
operationTime:new Date(time).valueOf(),
ct:Now,
createUser:"admin"})
});
await xiaoshouData.addManyData(xiaoshouList);
let nongshi = [];
农事.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let time = subList[3];
if (!NONGSHITYPE[name]) console.log(name, "名称不在NONGSHITYPE枚举范围")
if (!diKuaiMap[dk])return
if (dk == "所有种植地块") {
let allList = [];
if (subList[1] == "A区") {
allList = [, "A-11#", "A-9#", "A-10#", "A-8#", "A-7#", "A-6#", "A-5#", "A-1#", "A-2#", "A-3#", "A-4#"];
}else {
allList = [
"B-1#", "B-2#", "B-3#", "B-14#", "B-10#", "B-4#", "B-5#", "B-9#", "B-8#", "B-7#", "B-6#", "B-11#", "B-12#", "B-13#", "B-15#", "B-16#",
]
}
allList.forEach(element => {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[element]],
operationTime:new Date(time).valueOf(), ct:Now
})
});
} else {
nongshi.push({
nsId:randomId(TABLENAME.农事),
nsType:NONGSHITYPE.灌溉,
dIdList:[diKuaiMap[dk]],
operationTime:new Date(time).valueOf(), ct:Now
})
}
});
await nongshiData.addManyData(nongshi);
let nongziList = [];
农资.forEach((subList, index) => {
if (!index) return;
let name = subList[0];
let dk = subList[2];
let count = subList[4];
let plName = subList[3];
let time = subList[6];
if (!NONGZITYPE[name]) console.log(name, "名称a不在枚举范围")
if (!diKuaiMap[dk]) return
if (!PLANTTYPE[plName]) console.log(plName, "作物名称不在枚举范围")
nongziList.push({
nzId:randomId(TABLENAME.农资),
nzType:NONGZITYPE[name],
dIdList:[diKuaiMap[dk]],
plantType:PLANTTYPE[plName],
count:parseFloat(count),
useTime:new Date(time).valueOf(),
ct:Now
});
});
await nongziData.addManyData(nongziList);
console.log("数据导入成功");
}
...@@ -5,20 +5,23 @@ ...@@ -5,20 +5,23 @@
import moment = require("moment"); import moment = require("moment");
import { LIANGSHI, NONGZITYPE, PLANTTYPE, PLOTTYPE, XIAOSHOUQUXIANG } from "../config/enum"; import { LIANGSHI, NONGZITYPE, PLANTTYPE, PLOTTYPE, XIAOSHOUQUXIANG } from "../config/enum";
import { diKuaiSizeCountByParam } from "../data/dikuai"; import { diKuaiSizeCountByParam } from "../data/dikuai";
import { statisNongZiType, statisNongZiTypeCountByTime } from "../data/nongzi"; import * as nongziData from "../data/nongzi";
import { zhongYangTongJiCount, zhongZhiTongJiCount } from "../data/zhongzhi" import { zhongYangTongJiCount, zhongZhiTongJiCount } from "../data/zhongzhi"
import * as nongshiData from "../data/nongshi" import * as nongshiData from "../data/nongshi"
import * as xiaoshouData from "../data/xiaoshou" import * as xiaoshouData from "../data/xiaoshou"
import * as caishouData from "../data/caishou"
import { changeEnumValue } from "../util/verificationEnum"; 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; let 作物数量 = 0; isEnd: 0
let zhongZhiList = await zhongZhiTongJiCount(); let zhongZhiList = await zhongZhiTongJiCount({ isEnd: 0, plantType:{"$lt":PLANTTYPE.鲈鱼}});
let zhongZhiZuoWuList = []; //结果 let zhongZhiZuoWuList = []; //结果
zhongZhiList.forEach(info => { zhongZhiList.forEach(info => {
let {_id, sizeCount} = info; let {_id, sizeCount} = info;
...@@ -40,43 +43,70 @@ export async function getDataOut() { ...@@ -40,43 +43,70 @@ export async function getDataOut() {
地块使用率 = Math.round(diKuaiInfo.totalUseSize/diKuaiInfo.totalSize * 100); 地块使用率 = Math.round(diKuaiInfo.totalUseSize/diKuaiInfo.totalSize * 100);
} }
let zhongZhiTypeList = [ let zhongZhiTypeList = [
{key:"种植总面积", value:种植总面积}, {key:"种植总面积", value:731},//种植总面积
{key:"菜田面积", value:菜田面积}, {key:"菜田面积", value:370},//菜田面积
{key:"粮田面积", value:粮田面积}, {key:"粮田面积", value:361},
{key:"作物数量", value:作物数量}, {key:"作物数量", value:作物数量},
{key:"地块使用率", value:地块使用率}, {key:"地块使用率", value:地块使用率},
]; //结果 ]; //结果
let 农资类型 = await statisNongZiType(); let 农资类型 = await nongziData.statisNongZiType();
let 农资情况Map = {}; let 农资情况Map = {};
农资情况Map[NONGZITYPE.肥料] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.肥料), value:0}; 农资情况Map[NONGZITYPE.肥料] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.肥料), value:0, unit:"KG"};
农资情况Map[NONGZITYPE.农药] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.农药), value:0}; 农资情况Map[NONGZITYPE.农药] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.农药), value:0, unit:"G"};
农资情况Map[NONGZITYPE.其他] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.其他), value:0}; 农资情况Map[NONGZITYPE.药剂] = {key:changeEnumValue(NONGZITYPE, NONGZITYPE.药剂), value:0, unit:"ML"};
农资类型.forEach(info => { 农资类型.forEach(info => {
let {_id, count} = info; let {_id, count} = info;
if (农资情况Map[_id]) 农资情况Map[_id].value = count; 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); //结果 let nongZiList = Object.values(农资情况Map); //结果
let nongZiAllMonthList = await statisNongZiTypeCountByTime();
let nongZiAllMonthList = await nongziData.selectToParam({});
let nongZiCountInfo = {};//肥料用药情况 let nongZiCountInfo = {};//肥料用药情况
nongZiCountInfo[NONGZITYPE.农药] = {}; nongZiCountInfo[NONGZITYPE.农药] = {};
nongZiCountInfo[NONGZITYPE.肥料] = {}; nongZiCountInfo[NONGZITYPE.肥料] = {};
// nongZiAllMonthList = [ // let lastMonthMs = moment().startOf('M').valueOf()
// { "totalWeight" : 15, "year" : 2025, "month" : 1, "nzType" : 2 },
// { "totalWeight" : 23, "year" : 2025, "month" : 2, "nzType" : 1 },
// { "totalWeight" : 10, "year" : 2025, "month" : 3, "nzType" : 1 },
// ]
nongZiAllMonthList.forEach(info => { nongZiAllMonthList.forEach(info => {
let {year, month, nzType, totalWeight} = info; let {useTime, count, nzType} = info;
if (nongZiCountInfo[nzType]) { // if (useTime < lastMonthMs ) return
nongZiCountInfo[nzType][`${year}-${month}`] = totalWeight; 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 = getKey(useTime);
if (!nongZiCountInfo[keyNum][keyStr]) nongZiCountInfo[keyNum][keyStr] = 0;
nongZiCountInfo[keyNum][keyStr] += count;
}; };
}); });
let 肥料 = []; let 肥料 = [];
let 用药 = []; let 用药 = [];
for (let i = 9; i >= 0; i--) { let allKeyList = getAllKey(new Date().valueOf());
let key = moment().subtract(i, 'months').format("YYYY-M"); for (let i = 0; i < allKeyList.length; i++) {
let key = allKeyList[i];
肥料.push({ 肥料.push({
key, key,
value:nongZiCountInfo[NONGZITYPE.肥料][key] || 0 value:nongZiCountInfo[NONGZITYPE.肥料][key] || 0
...@@ -92,15 +122,18 @@ export async function getDataOut() { ...@@ -92,15 +122,18 @@ export async function getDataOut() {
]; ];
let nongShiCount = await nongshiData.selectCountByParam({}); //结果 let nongShiCount = await nongshiData.selectCountByParam({}); //结果
let nongshiTyptList = await nongshiData.statisNongShiType(); let nongshiTyptList = await nongshiData.selectToParam({});
let 操作趋势 = {}; let 操作趋势 = {};
let nongShiList = [];//结果 let nongShiList = [];//结果
nongshiTyptList.forEach(info => { nongshiTyptList.forEach(info => {
let {year, month, count} = info; let {nsType, operationTime} = info;
操作趋势[`${year}-${month}`] = count; let key = getKey(operationTime);
if (!操作趋势[key]) 操作趋势[key] = 0;
操作趋势[key] += 1;;
}); });
for (let i = 9; i >= 0; i--) { for (let i= 0; i < allKeyList.length; i++) {
let key = moment().subtract(i, 'months').format("YYYY-M"); let key = allKeyList[i];
nongShiList.push({ nongShiList.push({
key, key,
value:操作趋势[key] || 0 value:操作趋势[key] || 0
...@@ -108,30 +141,27 @@ export async function getDataOut() { ...@@ -108,30 +141,27 @@ export async function getDataOut() {
} }
let monthDBList = await selectChanLiangOfMonth(); let monthDBList = await caishouData.selectToParam({plantType:{"$lt":PLANTTYPE.鲈鱼}});
let 作物产量Map = {}; let 作物产量Map = {};
let 今年产量总数 = 0;
monthDBList.forEach(info => { monthDBList.forEach(info => {
let {year, month, totalWeight} = info; let {ct, weight} = info;
if (new Date(ct).getFullYear() == 2025) 今年产量总数 += weight;
let key = `${year}-${month}`; let key = getKey(ct)
if (!作物产量Map[key]) 作物产量Map[key] = 0; if (!作物产量Map[key]) 作物产量Map[key] = 0;
作物产量Map[key] += totalWeight; 作物产量Map[key] += weight;
}); });
let 今年 = []; let 今年 = [];
let 去年 = []; let 去年 = [];
let thisYear = new Date().getFullYear();
let lastYear = thisYear - 1;
let 今年产量总数 = 0;
let 去年产量总数 = 0; let 去年产量总数 = 0;
for (let i =1; i <=12; i++) { for (let i =0 ; i < allKeyList.length; i++) {
let thisYearItem = 作物产量Map[`${thisYear}-${i}`] || 0; let key = allKeyList[i];
let lastYearItem = 作物产量Map[`${lastYear}-${i}`] || 0; let changeValue = 作物产量Map[key] ? Math.round(作物产量Map[key]/1000*100)/100 : 0;
今年.push({key: `${thisYear}-${i}`, value:thisYearItem }); 今年.push({key: key, value:changeValue || 0 });
去年.push({key: `${lastYear}-${i}`, value:lastYearItem }); 去年.push({key: key, value:0 });
今年产量总数 += thisYearItem;
去年产量总数 += lastYearItem;
} }
let chanLiangList = [ //结果 let chanLiangList = [ //结果
{name:"今年", data:今年}, {name:"今年", data:今年},
...@@ -143,26 +173,36 @@ export async function getDataOut() { ...@@ -143,26 +173,36 @@ export async function getDataOut() {
产量年同比 = Math.round((今年产量总数 - 去年产量总数)/ 去年产量总数*10000)/100 产量年同比 = Math.round((今年产量总数 - 去年产量总数)/ 去年产量总数*10000)/100
} }
let chanLiangStatisList = [//结果 let chanLiangStatisList = [//结果
{key:"作物产量", value:今年产量总数}, {key:"作物产量", value:Math.round(今年产量总数/1000*100)/100},
{key:"同比", value:产量年同比} {key:"同比", value:产量年同比}
]; ];
let xiaoshouStartMs = moment().subtract(1, "months").startOf('month').valueOf(); let xiaoshouStartMs = moment().subtract(1, "months").startOf('month').valueOf();
let xiaoshouEndMs = moment().startOf('month').valueOf(); let xiaoshouEndMs = moment().startOf('month').valueOf();
let xiaoshouDBList = await xiaoshouData.selectToParam({operationTime:{"$gt":xiaoshouStartMs, "$lt":xiaoshouEndMs }}); 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; lastMonthXiaoShou += weight;
let key = moment(operationTime).format("MM-DD"); let key = getKey(operationTime);
let dayKey = moment(operationTime).format("DD"); if (!lastMonthXiaoShouMap[key]) lastMonthXiaoShouMap[key] = 0;
if (!lastMonthXiaoShouMap[key]) lastMonthXiaoShouMap[key] = {key:dayKey, value:0}; lastMonthXiaoShouMap[key] += weight;
lastMonthXiaoShouMap[key].value += weight;
}); });
let lastMonthXiaoShouList = Object.values(lastMonthXiaoShouMap);//结果 // let lastMonthXiaoShouList = Object.values(lastMonthXiaoShouMap);//结果
let lastMonthXiaoShouList = [];
let allxiaoshouKeyList = getAllKey(new Date().valueOf());
for (let i = 0; i < allxiaoshouKeyList.length; i++) {
let key = allxiaoshouKeyList[i];
let value = lastMonthXiaoShouMap[key] || 0;
lastMonthXiaoShouList.push({
key,
value:Math.round(value/1000*100)/100,
})
}
return { return {
zhongZhiZuoWuList, zhongZhiZuoWuList,
zhongZhiTypeList, zhongZhiTypeList,
...@@ -172,12 +212,39 @@ export async function getDataOut() { ...@@ -172,12 +212,39 @@ export async function getDataOut() {
nongShiCount, nongShiCount,
chanLiangList, chanLiangList,
chanLiangStatisList, chanLiangStatisList,
lastMonthXiaoShou, lastMonthXiaoShou:Math.round(lastMonthXiaoShou/1000*100)/100,
lastMonthXiaoShouList lastMonthXiaoShouList
} }
} }
function getKey(timestamp) {
const date = new Date(timestamp);
// 计算当前时间所在周期的周一(UTC时间)
const day = date.getUTCDay(); // 0(周日)到6(周六)
const diff = day === 0 ? 6 : day - 1; // 计算到上周一的差值
const start = new Date(date);
start.setUTCDate(start.getUTCDate() - diff); // 回退到周一
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")}`;
}
function getAllKey(timestamp) {
let cycles = [];
for (let i = 7; i >=0 ; i--) {
let ms = moment(timestamp).subtract(i*7, 'd').valueOf();
cycles.push(getKey(ms))
}
return cycles;
}
export async function getGuiYuOut() { export async function getGuiYuOut() {
let zhongZhiList = await zhongYangTongJiCount(); let zhongZhiList = await zhongYangTongJiCount();
...@@ -197,8 +264,8 @@ export async function getGuiYuOut() { ...@@ -197,8 +264,8 @@ export async function getGuiYuOut() {
}); });
let scyz = [ let scyz = [
{key:"养殖面积", value:'0亩'}, // {key:"养殖面积", value:'0亩'},
{key:"鱼苗养殖", value:`${count/10000}亿`}, {key:"鱼苗养殖", value:`${count}万尾`},
]; ];
...@@ -224,7 +291,7 @@ export async function getGuiYuOut() { ...@@ -224,7 +291,7 @@ export async function getGuiYuOut() {
if (kcMap[key] > 0) { if (kcMap[key] > 0) {
kcjlData.push({ kcjlData.push({
key:changeEnumValue(PLANTTYPE, parseInt(key)), key:changeEnumValue(PLANTTYPE, parseInt(key)),
value:`${kcMap[key]}尾` value:`${Math.ceil(kcMap[key]/1000000)*100}尾`
}) })
} }
} }
......
...@@ -111,6 +111,28 @@ export async function diKuaiList(plotType:number, selectStr:string, code:string, ...@@ -111,6 +111,28 @@ export async function diKuaiList(plotType:number, selectStr:string, code:string,
return {dataList} return {dataList}
} }
/**
* 地块列表分页
* @param plotType
* @param selectStr
* @param code
* @param purpose
* @param area
* @returns
*/
export async function diKuaiListToPage(pageNumber) {
let diKuaiList = await dikuaiData.findDataToParamToPage({}, pageNumber);
let dataList = [];
diKuaiList.forEach(item => {
let { size, dId, purpose, code } = item;
dataList.push({size,dId,type:changeEnumValue(PURPOSE, purpose),code});
});
return {dataList}
}
/** /**
* 修改地块信息 * 修改地块信息
......
...@@ -99,4 +99,70 @@ export async function nongZiList(selectStr:string, dId:string, nzType:number, us ...@@ -99,4 +99,70 @@ export async function nongZiList(selectStr:string, dId:string, nzType:number, us
}); });
return {dataList}; return {dataList};
}
export async function updateZhongYang(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();
}
export async function zhongYangInfo(nzId) {
let nongZiInfo = await nongziData.findOne({nzId});
let dataInfo = {
nzType:nongZiInfo.nzType,//农资类型
dIdList:nongZiInfo.dIdList,//地块id
plantType:nongZiInfo.plantType,//种植种类【枚举】 PLANTTYPE
count:nongZiInfo.count,//用量
useTime:nongZiInfo.useTime//时间
};
return {dataInfo}
}
export async function zhongYangListToPage(page) {
let dbList = await nongziData.findDataToParamToPage({}, page);
let dataCount = await nongziData.findDataToParamCouant({});
let dataList = [];
dbList.forEach(info => {
dataList.push({
nzId:info.nzId,
nzType:info.nzType,//农资类型
dIdList:info.dIdList,//地块id
plantType:info.plantType,//种植种类【枚举】 PLANTTYPE
count:info.count,//用量
useTime:info.useTime//时间
})
});
return {dataList, dataCount}
} }
\ No newline at end of file
...@@ -5,14 +5,64 @@ ...@@ -5,14 +5,64 @@
import { ERRORENUM } from "../config/errorEnum"; import { ERRORENUM } from "../config/errorEnum";
import { findUserInfoByLoginId, findUserInfoByUserId } from "../data/users"; import { findUserInfoByLoginId, findUserInfoByUserId } from "../data/users";
import * as caishouData from "../data/caishou";
import { getPwdMd5, getToken, successResult } from "../tools/system"; import { getPwdMd5, getToken, successResult } from "../tools/system";
import { BizError } from "../util/bizError"; import { BizError } from "../util/bizError";
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 { selectChanLiangOfMonth, selectChanLiangOfzuoWu } from "../data/caishou"; import { selectChanLiangOfMonth, selectChanLiangOfzuoWu } from "../data/caishou";
import { changeEnumValue } from "../util/verificationEnum"; import { changeEnumValue } from "../util/verificationEnum";
import { PLANTTYPE } from "../config/enum"; import { PLANTTYPE, PLOTTYPE } from "../config/enum";
import { selectXiaoShouOfMonth, selectXiaoShouOfzuoWu } from "../data/xiaoshou"; 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();
}
/** /**
...@@ -63,6 +113,7 @@ export async function userLogout(reqUserInfo) { ...@@ -63,6 +113,7 @@ export async function userLogout(reqUserInfo) {
} }
/** /**
* 首页 * 首页
* @param userInfo * @param userInfo
...@@ -102,14 +153,14 @@ export async function homePageTop(userInfo) { ...@@ -102,14 +153,14 @@ export async function homePageTop(userInfo) {
*/ */
export async function homePageStatisTop(userInfo) { export async function homePageStatisTop(userInfo) {
//面积 //面积
let {totalSize, totalUseSize} = await diKuaiData.diKuaiSizeCount(); let {totalSize, totalUseSize} = await diKuaiData.diKuaiSizeCount({plotType:PLOTTYPE.地块});
let rate = 0; let rate = Math.ceil(totalUseSize/totalSize*10000)/100;
if (totalSize && totalUseSize) { if (totalSize && totalUseSize) {
Math.round(totalUseSize/totalSize*100); Math.round(totalUseSize/totalSize*100);
} }
//品种 //品种
let zhongZhiTypeList = await zhongZhiData.pingZhongCount(); let zhongZhiTypeList = await zhongZhiData.pingZhongCount({ isEnd: 0 , plantType:{"$lt":PLANTTYPE.鲈鱼}});
let dataInfo = { let dataInfo = {
diKuaiCount : totalSize, diKuaiCount : totalSize,
...@@ -149,13 +200,25 @@ export async function homePageStatisBottom(userInfo) { ...@@ -149,13 +200,25 @@ export async function homePageStatisBottom(userInfo) {
export async function homePageStatisChanLiang(type:number) { export async function homePageStatisChanLiang(type:number) {
//产量 时间分 //产量 时间分
let monthDBList = await selectChanLiangOfMonth(); let zuoWuMonthDBList = await caishouData.selectToParam({plantType:{"$lt":PLANTTYPE.鲈鱼}});
let distinctMap = {}; let zuoWuDistinctMap = {};
let count = 0; let zuoWuCount = 0;
monthDBList.forEach(info => {
let {year, month, totalWeight} = info; let map1 = {};
zuoWuMonthDBList.forEach(info => {
let {ct, weight} = info;
let strKey = ""; 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) {//年 if (type == 1) {//年
strKey = year; strKey = year;
} else if (type == 2) {//季度 } else if (type == 2) {//季度
...@@ -163,39 +226,113 @@ export async function homePageStatisChanLiang(type:number) { ...@@ -163,39 +226,113 @@ export async function homePageStatisChanLiang(type:number) {
if (month >= 10) quarter = 4; if (month >= 10) quarter = 4;
else if (month >= 7) quarter = 3; else if (month >= 7) quarter = 3;
else if (month >= 4) quarter = 2; else if (month >= 4) quarter = 2;
strKey = `${year}_${quarter}`; strKey = `${year}-${quarter}`;
} else {//月 } else {//月
strKey = `${year}_${month}`; strKey = `${year}-${month}`;
} }
if (!distinctMap[strKey]) distinctMap[strKey] = {key:strKey, value:0}; if (!zuoWuDistinctMap[strKey]) zuoWuDistinctMap[strKey] = {key:strKey, value:0};
distinctMap[strKey].value += totalWeight; zuoWuDistinctMap[strKey].value += totalWeight;
count += totalWeight; zuoWuCount += totalWeight;
}); });
let nongChanPin = Object.values(distinctMap); 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(); let zuoWuDBList = await selectChanLiangOfzuoWu({plantType:{"$lt":PLANTTYPE.鲈鱼}});
let zuoWu = []; let zuoWu = [];
zuoWuDBList.forEach(info => { zuoWuDBList.forEach(info => {
let {_id, totalWeight} = info; let {_id, totalWeight} = info;
zuoWu.push({ zuoWu.push({
key:changeEnumValue(PLANTTYPE, _id), key:changeEnumValue(PLANTTYPE, _id),
value:totalWeight 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 = { let dataInfo = {
count, zuoWu:{
nongChanPin, count:Math.ceil(zuoWuCount/10)/100,
zuoWu:zuoWu, nongChanPin,
zuoWu:zuoWu,
},
shuiChan:{
count:Math.ceil(shuiChanCount/100)/100,
shuiChanPin,
shuiChan,
},
shuiChanZhognYang:{
shuiChanZhognYangList:shuiChanZhognYang,
count:shuiChanZhognYangCount,
}
}; };
return {dataInfo}; return {dataInfo};
} }
/** /**
* 统计页销售量统计 * 统计页销售量统计
* @param type * @param type
...@@ -204,14 +341,14 @@ export async function homePageStatisChanLiang(type:number) { ...@@ -204,14 +341,14 @@ export async function homePageStatisChanLiang(type:number) {
export async function homePageStatisXiaoShou() { export async function homePageStatisXiaoShou() {
let thisYear = new Date().getFullYear(); let thisYear = new Date().getFullYear();
//产量 //产量
let monthDBList = await selectXiaoShouOfMonth(); let monthDBList = await selectXiaoShouOfMonth({plantType:{"$lt":PLANTTYPE.鲈鱼}});
let distinctMap = {}; let distinctMap = {};
let count = 0; let count = 0;
let lastYearCount = 0; let lastYearCount = 0;
monthDBList.forEach(info => { monthDBList.forEach(info => {
let {year, month, totalWeight} = info; let {year, month, totalWeight} = info;
let strKey = `${year}_${month}`; let strKey = `${year}-${month}`;
if (!distinctMap[strKey]) distinctMap[strKey] = {key:strKey, value:0}; if (!distinctMap[strKey]) distinctMap[strKey] = {key:strKey, value:0};
distinctMap[strKey].value += totalWeight; distinctMap[strKey].value += totalWeight;
...@@ -222,25 +359,117 @@ export async function homePageStatisXiaoShou() { ...@@ -222,25 +359,117 @@ export async function homePageStatisXiaoShou() {
let xiaoShouList = Object.values(distinctMap); let xiaoShouList = Object.values(distinctMap);
let xiaoShouDBList = await selectXiaoShouOfzuoWu(); let xiaoShouDBList = await selectXiaoShouOfzuoWu({plantType:{"$lt":PLANTTYPE.鲈鱼}});
let xiaoShou = []; let xiaoShou = [];
xiaoShouDBList.forEach(info => { xiaoShouDBList.forEach(info => {
let {_id, totalWeight} = info; let {_id, totalWeight} = info;
xiaoShou.push({ xiaoShou.push({
key:changeEnumValue(PLANTTYPE, _id), key:changeEnumValue(PLANTTYPE, _id),
value:totalWeight 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 = { let dataInfo = {
count,// zuoWu:{
mom:Math.round( (count-lastYearCount)/lastYearCount * 1000 )/10, count:Math.ceil(count/10)/100,
xiaoShou:xiaoShouList, mom:Math.round( (count-lastYearCount)/lastYearCount * 1000 )/10,
zuoWu:xiaoShou 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}; 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
...@@ -41,6 +41,42 @@ export async function zhongYangDangQianList(zhongYangType:number, selectStr:stri ...@@ -41,6 +41,42 @@ export async function zhongYangDangQianList(zhongYangType:number, selectStr:stri
} }
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.findDataToParamToPage( param, 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};
}
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 reqUser
...@@ -78,6 +114,42 @@ export async function addZhongYang(reqUser, param) { ...@@ -78,6 +114,42 @@ export async function addZhongYang(reqUser, param) {
} }
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.nullSize < 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();
}
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 zhongYangType
......
...@@ -69,7 +69,16 @@ export enum SHUCAI { ...@@ -69,7 +69,16 @@ export enum SHUCAI {
红薯叶, 红薯叶,
樱桃萝卜, 樱桃萝卜,
菠菜, 菠菜,
豆苗 豆苗,
马齿苋,
小白菜,
青甘蓝,
丝瓜,
空心菜,
白萝卜,
油麦菜,
长茼蒿,
叶菜
} }
...@@ -161,6 +170,15 @@ export enum PLANTTYPE { ...@@ -161,6 +170,15 @@ export enum PLANTTYPE {
樱桃萝卜, 樱桃萝卜,
菠菜, 菠菜,
豆苗, 豆苗,
马齿苋,
小白菜,
青甘蓝,
丝瓜,
空心菜,
白萝卜,
油麦菜,
长茼蒿,
叶菜,
鲈鱼 = 101, 鲈鱼 = 101,
鳜鱼, 鳜鱼,
鲢鱼, 鲢鱼,
...@@ -208,6 +226,13 @@ export enum NONGZITYPE { ...@@ -208,6 +226,13 @@ export enum NONGZITYPE {
银法利, 银法利,
农药, 农药,
其他, 其他,
奥罗,
三令,
磷肥,
好力克,
啶虫脒,
龙克均,
药剂
} }
......
...@@ -16,7 +16,8 @@ export enum ERRORENUM { ...@@ -16,7 +16,8 @@ export enum ERRORENUM {
密码错误, 密码错误,
非法登录, 非法登录,
身份验证过期, 身份验证过期,
地块大小不足 地块大小不足,
数据不存在
} }
/** /**
......
...@@ -52,8 +52,9 @@ export async function addManyData(param) { ...@@ -52,8 +52,9 @@ export async function addManyData(param) {
} }
export async function selectChanLiangOfMonth() { export async function selectChanLiangOfMonth(param) {
return await caishouModel.aggregate([ return await caishouModel.aggregate([
{ $match: param },
{ {
$group: { $group: {
_id: { _id: {
...@@ -77,8 +78,9 @@ export async function selectChanLiangOfMonth() { ...@@ -77,8 +78,9 @@ export async function selectChanLiangOfMonth() {
]); ]);
} }
export async function selectChanLiangOfzuoWu() { export async function selectChanLiangOfzuoWu(param) {
return await caishouModel.aggregate([ return await caishouModel.aggregate([
{ $match: param },
{ {
$group: { $group: {
_id:"$plantType", _id:"$plantType",
......
...@@ -59,9 +59,14 @@ export async function selectToParam(param) { ...@@ -59,9 +59,14 @@ export async function selectToParam(param) {
return await dikuaiModel.find(param); return await dikuaiModel.find(param);
} }
export async function findDataToParamToPage(param, pageNumber) {
return await dikuaiModel.find(param).skip((pageNumber-1)*10).limit(10);
}
export async function diKuaiSizeCount() { export async function diKuaiSizeCount(param) {
let list = await dikuaiModel.aggregate([ let list = await dikuaiModel.aggregate([
{ $match: param },
{ {
"$group":{ "$group":{
_id:null, _id:null,
......
...@@ -54,6 +54,20 @@ export async function selectToParam(param) { ...@@ -54,6 +54,20 @@ 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) {
return await nongziModel.deleteOne(param);
}
export async function findDataToParamToPage(param, pageNumber) {
return await nongziModel.find(param).skip((pageNumber-1)*10).limit(10);
}
export async function statisNongZiType() { export async function statisNongZiType() {
let list = await nongziModel.aggregate([ let list = await nongziModel.aggregate([
......
...@@ -13,6 +13,8 @@ const userSchema = new Schema({ ...@@ -13,6 +13,8 @@ const userSchema = new Schema({
token:String, token:String,
tokenMs:Number, tokenMs:Number,
position:String,//职务 position:String,//职务
adminToken:String,
adminTokenMs:Number,
}); });
var userModel; var userModel;
......
...@@ -55,8 +55,9 @@ export async function selectToParam(param) { ...@@ -55,8 +55,9 @@ export async function selectToParam(param) {
} }
export async function selectXiaoShouOfMonth() { export async function selectXiaoShouOfMonth(param) {
return await xiaoshouModel.aggregate([ return await xiaoshouModel.aggregate([
{ $match: param },
{ {
$group: { $group: {
_id: { _id: {
...@@ -80,8 +81,9 @@ export async function selectXiaoShouOfMonth() { ...@@ -80,8 +81,9 @@ export async function selectXiaoShouOfMonth() {
]); ]);
} }
export async function selectXiaoShouOfzuoWu() { export async function selectXiaoShouOfzuoWu(param) {
return await xiaoshouModel.aggregate([ return await xiaoshouModel.aggregate([
{ $match: param },
{ {
$group: { $group: {
_id:"$plantType", _id:"$plantType",
......
...@@ -57,13 +57,26 @@ export async function selectToParam(param) { ...@@ -57,13 +57,26 @@ export async function selectToParam(param) {
return await zhongzhiModel.find(param); return await zhongzhiModel.find(param);
} }
export async function findDataToParamToPage(param, pageNumber) {
return await zhongzhiModel.find(param).skip((pageNumber-1)*10).limit(10);
}
export async function updateManyToParam(param, updateInfo) { export async function updateManyToParam(param, updateInfo) {
return await zhongzhiModel.updateMany(param, {"$set":updateInfo}); return await zhongzhiModel.updateMany(param, {"$set":updateInfo});
} }
export async function pingZhongCount() { export async function findDataToParamCouant(param) {
return await zhongzhiModel.find(param).countDocuments();
}
export async function deleteData(param) {
return await zhongzhiModel.deleteOne(param);
}
export async function pingZhongCount(param) {
let list = await zhongzhiModel.aggregate([ let list = await zhongzhiModel.aggregate([
{ $match: { isEnd: 0 } }, { $match: param },
{ {
"$group":{ "$group":{
_id:"$plantType", _id:"$plantType",
...@@ -76,9 +89,9 @@ export async function pingZhongCount() { ...@@ -76,9 +89,9 @@ export async function pingZhongCount() {
} }
export async function zhongZhiTongJiCount() { export async function zhongZhiTongJiCount(param) {
let list = await zhongzhiModel.aggregate([ let list = await zhongzhiModel.aggregate([
{ $match: { isEnd: 0 } }, { $match: param },
{ {
"$group":{ "$group":{
_id:"$plantType", _id:"$plantType",
......
...@@ -2,22 +2,34 @@ ...@@ -2,22 +2,34 @@
import { initConfig, systemConfig } from "./config/serverConfig"; import { initConfig, systemConfig } from "./config/serverConfig";
import { httpServer } from "./net/http_server"; import { httpServer } from "./net/http_server";
import { initDB } from "./db/dbInit"; import { initDB } from "./db/dbInit";
import { dataInit, dataInit0508, yjDataInit0508 } from "./biz/dataInt"; import { dataInit0516, dataInit, dataInit0508, yjDataInit0508, dataInit0522, dataInit0604, dataInit0609, dataInit0618 } from "./biz/dataInt";
import { getGuiYuOut } from "./biz/dataOut"; import { getDataOut, getGuiYuOut } from "./biz/dataOut";
import { homePageStatisChanLiang } from "./biz/user";
import { getPwdMd5, md5PwdStr } from "./tools/system";
async function lanuch() { async function lanuch() {
/**初始化配置解析 */ /**初始化配置解析 */
await initConfig(); await initConfig();
/**初始化数据库 */ /**初始化数据库 */
await initDB(); await initDB();
/**创建http服务 */ /**创建http服务 */
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 dataInit(); // await dataInit();
await getDataOut();
// await dataInit0508();
// await dataInit0508(); // await dataInit0508();
// await yjDataInit0508(); // await yjDataInit0508();
// await dataInit0516();
// await dataInit0522();
// await dataInit0604();
// await dataInit0618();
let checkPwd = getPwdMd5("18120935727", md5PwdStr("123456"))
console.log();
} }
lanuch(); lanuch();
\ No newline at end of file
...@@ -5,7 +5,7 @@ import { BizError } from "../util/bizError"; ...@@ -5,7 +5,7 @@ import { BizError } from "../util/bizError";
/** /**
* 管委会小程序中间件 * 小程序中间件
* @param req * @param req
* @param res * @param res
* @param next * @param next
...@@ -32,3 +32,33 @@ export async function checkUserToken(req, res, next) { ...@@ -32,3 +32,33 @@ export async function checkUserToken(req, res, next) {
next(); next();
} }
/**
* 管理后台中间件
* @param req
* @param res
* @param next
* @returns
*/
export async function checkAdminUserToken(req, res, next) {
console.log(req.originalUrl, JSON.stringify(req.body));
if (!req.headers) req.headers = {};
const reqToken = req.headers.token;
const userId = req.headers.userid || "";
if (!userId) return next(new BizError(ERRORENUM.身份验证失败, `userId:${userId} token:${reqToken}`));
let userInfo = await findUserInfoByUserId(userId);
if (!userInfo) return next(new BizError(ERRORENUM.非法登录, `userId:${userId} token:${reqToken}`));
if (userInfo.adminToken != reqToken ) return next(new BizError(ERRORENUM.身份验证过期, `userId:${userId} token:${reqToken}`));
req.userInfo = {
userId:userInfo.userId,
name:userInfo.name,
position:userInfo.position
}
next();
}
import * as asyncHandler from 'express-async-handler'
import { eccReqParamater } from '../util/verificationParam';
import * as diKuaiBiz from '../biz/diKuai';
import * as userBiz from '../biz/user';
import * as zhongYangBiz from '../biz/zhongYang';
import * as nongziBiz from '../biz/nongzi';
import * as nongShiBiz from '../biz/nongShi';
import * as publicRouters from './public';
import * as caiShouBiz from '../biz/caiShou';
import * as xiaoShouBiz from '../biz/xiaoShou';
import { checkAdminUserToken } from '../middleware/user';
import * as dataOutBiz from '../biz/dataOut';
export function setRouter(httpServer){
/**地块 */
httpServer.post('/zjnt/xcxadmin/dikuai/add', checkAdminUserToken, asyncHandler(dikuai_add));//地块添加 '/zjnt/xcxadmin/dikuai/add'
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/list', checkAdminUserToken, asyncHandler(dikuai_list));//地块列表 '/zjnt/xcxadmin/dikuai/list'
/**种养 */
httpServer.post('/zjnt/xcxadmin/zhongyang/add', checkAdminUserToken, asyncHandler(zhongyang_add));//种养添加 '/zjnt/xcxadmin/zhongyang/add'
httpServer.post('/zjnt/xcxadmin/zhongyang/update', checkAdminUserToken, asyncHandler(zhongyang_update));//种养修改 '/zjnt/xcxadmin/zhongyang/update'
httpServer.post('/zjnt/xcxadmin/zhongyang/info', checkAdminUserToken, asyncHandler(zhongyang_info));//种养回显 '/zjnt/xcxadmin/zhongyang/info'
httpServer.post('/zjnt/xcxadmin/zhongyang/list', checkAdminUserToken, asyncHandler(zhongyang_list));//种养列表 '/zjnt/xcxadmin/zhongyang/list'
httpServer.post('/zjnt/xcxadmin/zhongyang/del', checkAdminUserToken, asyncHandler(zhongyang_del));//种养删除 '/zjnt/xcxadmin/zhongyang/del'
/**农资 */
httpServer.post('/zjnt/xcxadmin/nongzi/add', checkAdminUserToken, asyncHandler(nongzi_add));//农资添加 '/zjnt/xcxadmin/nongzi/add'
httpServer.post('/zjnt/xcxadmin/nongzi/update', checkAdminUserToken, asyncHandler(nongzi_update));//农资修改 '/zjnt/xcxadmin/nongzi/update'
httpServer.post('/zjnt/xcxadmin/nongzi/info', checkAdminUserToken, asyncHandler(nongzi_info));//农资回显 '/zjnt/xcxadmin/nongzi/info'
httpServer.post('/zjnt/xcxadmin/nongzi/list', checkAdminUserToken, asyncHandler(nongzi_list));//农资列表 '/zjnt/xcxadmin/nongzi/list'
httpServer.post('/zjnt/xcxadmin/nongzi/del', checkAdminUserToken, asyncHandler(nongzi_del));//农资删除 '/zjnt/xcxadmin/nongzi/del'
/**农事 */
httpServer.post('/zjnt/xcxadmin/nongshi/add', checkAdminUserToken, asyncHandler(nongshi_add));//农事添加 '/zjnt/xcxadmin/nongshi/add'
httpServer.post('/zjnt/xcxadmin/nongshi/update', checkAdminUserToken, asyncHandler(nongshi_update));//农事修改 '/zjnt/xcxadmin/nongshi/update'
httpServer.post('/zjnt/xcxadmin/nongshi/info', checkAdminUserToken, asyncHandler(nongshi_info));//农事回显 '/zjnt/xcxadmin/nongshi/info'
httpServer.post('/zjnt/xcxadmin/nongshi/list', checkAdminUserToken, asyncHandler(nongshi_list));//农事列表 '/zjnt/xcxadmin/nongshi/list'
httpServer.post('/zjnt/xcxadmin/nongshi/del', checkAdminUserToken, asyncHandler(nongshi_del));//农事删除 '/zjnt/xcxadmin/nongshi/del'
/**采收 */
httpServer.post('/zjnt/xcxadmin/caishou/add', checkAdminUserToken, asyncHandler(caishou_add));//采收添加 '/zjnt/xcxadmin/caishou/add'
httpServer.post('/zjnt/xcxadmin/caishou/update', checkAdminUserToken, asyncHandler(caishou_update));//采收修改 '/zjnt/xcxadmin/caishou/update'
httpServer.post('/zjnt/xcxadmin/caishou/info', checkAdminUserToken, asyncHandler(caishou_info));//采收回显 '/zjnt/xcxadmin/caishou/info'
httpServer.post('/zjnt/xcxadmin/caishou/list', checkAdminUserToken, asyncHandler(caishou_list));//采收列表 '/zjnt/xcxadmin/caishou/list'
httpServer.post('/zjnt/xcxadmin/caishou/del', checkAdminUserToken, asyncHandler(caishou_del));//采收删除 '/zjnt/xcxadmin/caishou/del'
/**销售 */
httpServer.post('/zjnt/xcxadmin/xiaoshou/add', checkAdminUserToken, asyncHandler(xiaoshou_add));//销售添加 '/zjnt/xcxadmin/xiaoshou/add'
httpServer.post('/zjnt/xcxadmin/xiaoshou/update', checkAdminUserToken, asyncHandler(xiaoshou_update));//销售修改 '/zjnt/xcxadmin/xiaoshou/update'
httpServer.post('/zjnt/xcxadmin/xiaoshou/info', checkAdminUserToken, asyncHandler(xiaoshou_info));//销售回显 '/zjnt/xcxadmin/xiaoshou/info'
httpServer.post('/zjnt/xcxadmin/xiaoshou/list', checkAdminUserToken, asyncHandler(xiaoshou_list));//销售列表 '/zjnt/xcxadmin/xiaoshou/list'
httpServer.post('/zjnt/xcxadmin/xiaoshou/del', checkAdminUserToken, asyncHandler(xiaoshou_del));//销售删除 '/zjnt/xcxadmin/xiaoshou/del'
/**登录登出 */
httpServer.post('/zjnt/xcxadmin/user/login', asyncHandler(user_login));//登录 '/zjnt/xcxadmin/user/login'
httpServer.post('/zjnt/xcxadmin/user/logout', checkAdminUserToken, asyncHandler(user_logout));//登出 '/zjnt/xcxadmin/user/logout'
}
async function user_login(req, res) {
let reqConf = {loginId:"String", pwd:"String"};
let { loginId, pwd } = eccReqParamater(reqConf, req.body);
let result = await userBiz.adminUserLogin(loginId, pwd);
res.success(result);
}
async function user_logout(req, res) {
let userInfo = req.headers.userInfo;
let result = await userBiz.adminUserLogout(userInfo);
res.success(result);
}
/** 地块 */
async function dikuai_add(req, res) {
let reqConf = {plotType:'Number', param:'Object'};
let { plotType, param } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo;
let result = await diKuaiBiz.addDiKuai(userInfo, plotType, param);
res.success(result);
}
async function dikuai_update(req, res) {
let reqConf = {dId:'String', plotType:'Number', param:'Object'};
let { dId, param, plotType } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo;
let result = await diKuaiBiz.updateDiKuai(userInfo, plotType, dId, param);
res.success(result);
}
async function dikuai_info(req, res) {
let reqConf = {dId:'Number'};
let { dId } = eccReqParamater(reqConf, req.body);
let result = await diKuaiBiz.diKuaiInfo(dId);
res.success(result);
}
async function dikuai_list(req, res) {
let reqConf = {pageNumber:'Number'};
let { pageNumber } = eccReqParamater(reqConf, req.body);
let result = await diKuaiBiz.diKuaiListToPage(pageNumber);
res.success(result);
}
/** 种养*/
async function zhongyang_add(req, res) {
let reqConf = {param:'Object'};
let { param } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo;
let result = await zhongYangBiz.addZhongYang(userInfo, param);
res.success(result);
}
async function zhongyang_update(req, res) {
let reqConf = {param:'Object', zId:"String"};
let { param, zId } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo;
let result = await zhongYangBiz.updateZhongYang(userInfo, zId, param);
res.success(result);
}
async function zhongyang_info(req, res) {
let reqConf = {zId:'String'};
let { zId } = eccReqParamater(reqConf, req.body);
let result = await zhongYangBiz.zhognYangInfo(zId);
res.success(result);
}
async function zhongyang_list(req, res) {
let reqConf = {zhongYangType:"Number", selectStr:"String", page:"Number"};
let { zhongYangType, selectStr, pageNumber } = eccReqParamater(reqConf, req.body, ["zhongYangType", "selectStr"]);
let result = await zhongYangBiz.zhongYangDangQianListToPage(zhongYangType, selectStr, pageNumber);
res.success(result);
}
async function zhongyang_del(req, res) {
let reqConf = {zId:'String'};
let { zId } = eccReqParamater(reqConf, req.body);
let result = await zhongYangBiz.deleteZhongYang(zId);
res.success(result);
}
async function nongzi_add(req, res) {
let reqConf = {param:'Object'};
let { param } = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo;
let result = await nongziBiz.addNongZi(userInfo, param);
res.success(result);
}
async function nongzi_update(req, res) {
let reqConf = {param:'Object', nzId:"String"};
let { param, nzId} = eccReqParamater(reqConf, req.body);
let userInfo = req.headers.userInfo;
let result = await nongziBiz.updateZhongYang(userInfo, nzId, param);
res.success(result);
}
async function nongzi_info(req, res) {
let reqConf = {nzId:'String'};
let { nzId } = eccReqParamater(reqConf, req.body);
let result = await nongziBiz.zhongYangInfo(nzId);
res.success(result);
}
async function nongzi_list(req, res) {
let reqConf = {page:'Number'};
let { page } = eccReqParamater(reqConf, req.body);
let result = await nongziBiz.zhongYangListToPage(page);
res.success(result);
}
//todo
async function nongzi_del(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function nongshi_add(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function nongshi_update(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function nongshi_info(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function nongshi_list(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function nongshi_del(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function caishou_add(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function caishou_update(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function caishou_info(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function caishou_list(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function caishou_del(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function xiaoshou_add(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function xiaoshou_update(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function xiaoshou_info(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function xiaoshou_list(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
async function xiaoshou_del(req, res) {
let reqConf = {type:'Number'};
let { type } = eccReqParamater(reqConf, req.body);
let result = await userBiz.homePageStatisChanLiang(type);
res.success(result);
}
...@@ -6,6 +6,7 @@ import * as zhongYangBiz from '../biz/zhongYang'; ...@@ -6,6 +6,7 @@ import * as zhongYangBiz from '../biz/zhongYang';
import * as nongziBiz from '../biz/nongzi'; import * as nongziBiz from '../biz/nongzi';
import * as nongShiBiz from '../biz/nongShi'; import * as nongShiBiz from '../biz/nongShi';
import * as publicRouters from './public'; import * as publicRouters from './public';
import * as adminRouters from './admin';
import * as caiShouBiz from '../biz/caiShou'; import * as caiShouBiz from '../biz/caiShou';
import * as xiaoShouBiz from '../biz/xiaoShou'; import * as xiaoShouBiz from '../biz/xiaoShou';
import { checkUserToken } from '../middleware/user'; import { checkUserToken } from '../middleware/user';
...@@ -61,6 +62,8 @@ export function setRouter(httpServer){ ...@@ -61,6 +62,8 @@ export function setRouter(httpServer){
/**公用 */ /**公用 */
publicRouters.setRouter(httpServer); publicRouters.setRouter(httpServer);
/**管理后台 */
adminRouters.setRouter(httpServer);
} }
async function data_out(req, res) { async function data_out(req, res) {
......
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