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,