|
@@ -18,9 +18,70 @@ const installationDao = new InstallationDao();
|
|
|
import GljDao from "../../std_glj_lib/models/gljModel";
|
|
|
const stdGljDao = new GljDao();
|
|
|
import stdgljutil from "../../../public/cache/std_glj_type_util";
|
|
|
-
|
|
|
+const stdGLJItemModel = mongoose.model('std_glj_lib_gljList');
|
|
|
var rationItemDAO = function(){};
|
|
|
|
|
|
+// 处理部颁数据
|
|
|
+rationItemDAO.prototype.handleBBData = async function (rationLibID, gljLibID) {
|
|
|
+ const rations = await rationItemModel.find({ rationRepId: rationLibID }, '-_id code ID rationGljList').lean();
|
|
|
+ const gljs = await stdGLJItemModel.find({ repositoryId: gljLibID, 'component.0': {$exists: true} }, '-_id ID component').lean();
|
|
|
+ const gljIDMap = {};
|
|
|
+ gljs.forEach(glj => gljIDMap[glj.ID] = glj);
|
|
|
+ const updateData = [];
|
|
|
+ const errorRange = 0.004;
|
|
|
+ for (const ration of rations) {
|
|
|
+ if (!ration.rationGljList) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const componentAmtMap = {};
|
|
|
+ for (const rGLJ of ration.rationGljList) {
|
|
|
+ const stdGLJ = gljIDMap[rGLJ.gljId];
|
|
|
+ if (!stdGLJ) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (const c of stdGLJ.component) {
|
|
|
+ const amt = c.consumeAmt * rGLJ.consumeAmt;
|
|
|
+ if (componentAmtMap[c.ID]) {
|
|
|
+ componentAmtMap[c.ID] += amt;
|
|
|
+ } else {
|
|
|
+ componentAmtMap[c.ID] = amt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const newRationGljList = [];
|
|
|
+ let isChanged = false;
|
|
|
+ for (let i = 0; i < ration.rationGljList.length; i++) {
|
|
|
+ const rGLJ = ration.rationGljList[i];
|
|
|
+ if (componentAmtMap[rGLJ.gljId]) {
|
|
|
+ isChanged = true;
|
|
|
+ const diff = scMathUtil.roundTo(rGLJ.consumeAmt - componentAmtMap[rGLJ.gljId], -3);
|
|
|
+ if (diff > errorRange || diff < -errorRange) {
|
|
|
+ // 扣减
|
|
|
+ rGLJ.consumeAmt = diff;
|
|
|
+ if (diff < 0) {
|
|
|
+ console.log(`ration.code`);
|
|
|
+ console.log(ration.code);
|
|
|
+ }
|
|
|
+ newRationGljList.push(rGLJ);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ newRationGljList.push(rGLJ);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isChanged) {
|
|
|
+ updateData.push({
|
|
|
+ updateOne: {
|
|
|
+ filter: { ID: ration.ID },
|
|
|
+ update: { rationGljList: newRationGljList }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (updateData.length) {
|
|
|
+ await rationItemModel.bulkWrite(updateData);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
/* rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID) {
|
|
|
// coe-list
|
|
|
const coeIDMap = {};
|