123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- /**
- * Created by chen on 2017/6/29.
- */
- let mongoose = require("mongoose")
- let ration_glj_facade = require('../facade/ration_glj_facade')
- const EngineeringLibModel = require("../../users/models/engineering_lib_model");
- let logger = require("../../../logs/log_helper").logger;
- const { COMPILATION, COMPLEMENTARY_LIB } = require('../../../public/common_constants');
- module.exports={
- createRationGLJ:createRationGLJ,
- testGetQuantify:testGetQuantify,
- getGLJData:getGLJData,
- getGLJDataPaging: getGLJDataPaging,
- getGLJDataByCodes:getGLJDataByCodes,
- addGLJ:addGLJ,
- replaceGLJ:replaceGLJ,
- mReplaceGLJ:mReplaceGLJ,
- updateRationGLJByEdit:updateRationGLJByEdit,
- getGLJClass:getGLJClass
- }
- function createRationGLJ() {
- let gls = mongoose.model('ration_glj');
- gls.create({'GLJID':1,'basePrice':23.23,'name':"testgls"},function(err, gls){
- console.log(gls)
- })
- }
- //测试获取消耗量:
- async function testGetQuantify() {
- var condition = {
- projectID:99,
- projectGLJIDList:[60,61,62]
- }
- try{
- let result = await ration_glj_facade.getQuantityByProjectGLJ(condition);
- console.log(result)
- }catch (err){
- console.log(err);
- }
- }
- async function getGLJDataByCodes(req,res){
- let result={
- error:0
- }
- try {
- let data = req.body.data;
- data = JSON.parse(data);
- let datas= await ration_glj_facade.getGLJDataByCodes(data,req.session.sessionCompilation);
- result.data=datas;
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- }
- res.json(result);
- }
- async function getGLJDataPaging(req, res) {
- let result={
- error:0
- };
- let { condition } = JSON.parse(req.body.data);
- try {
- const compilationId = req.session.sessionCompilation._id;
- const userID = req.session.sessionUser.id;
- let libData = null;
- if (condition.gljLibID !== COMPLEMENTARY_LIB) {
- condition.gljLibID = +condition.gljLibID;
- }
- if (condition.initLibs) {
- libData = await ration_glj_facade.getLibOptionsForCompilation(compilationId);
- libData.push({ name: '补充工料机', gljLibId: COMPLEMENTARY_LIB });
- if (condition.gljLibID) { // 替换人材机初始化会触发此条件(初始化库且定位了库)
- const orgDefalutLib = libData.find(lib => lib.isDefault);
- const newDefaultLib = libData.find(lib => lib.gljLibId === condition.gljLibID);
- if (orgDefalutLib && newDefaultLib) {
- orgDefalutLib.isDefault = false;
- newDefaultLib.isDefault = true;
- }
- }
- }
- if (!condition.gljLibID && libData) {
- condition.gljLibID = (libData.find(lib => lib.isDefault) || {}).gljLibId;
- }
- const info = condition.gljLibID === COMPLEMENTARY_LIB
- ? { gljLibId: null, userID, compilationId }
- : { gljLibId: condition.gljLibID, userID: null, compilationId: null };
- result.data = await ration_glj_facade.getGLJDataPaging(info, condition);
- if (req.session.sessionCompilation.priceProperties) {
- result.data.priceProperties = req.session.sessionCompilation.priceProperties
- }
- result.data.libData = libData;
- res.json(result);
- } catch (err) {
- logger.err(err);
- result.error=1;
- result.message = err.message;
- res.json(result);
- }
- }
- /* async function getGLJData(req, res) {
- let result={
- error:0
- }
- try {
- let info = await ration_glj_facade.getLibInfo(req);
- ration_glj_facade.getGLJData(info,function (err,datas) {
- if(err){
- result.error=1;
- result.message = err.message;
- }else {
- //多单价字段
- if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
- result.datas = datas;
- }
- res.json(result);
- });
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- res.json(result);
- }
- } */
- async function getGLJData(req, res) {
- let result={
- error:0
- }
- try {
- let libData = null;
- let { engineerID, gljLibId, isInitial } = req.params;
- if (gljLibId !== COMPLEMENTARY_LIB) {
- gljLibId = +gljLibId;
- }
- isInitial = JSON.parse(isInitial);
- if (!gljLibId || isInitial) { // 替换人材机的话,可能存在gljLibID,但是是初始化的操作
- libData = engineerID === COMPILATION
- ? await ration_glj_facade.getLibOptionsForCompilation(req.session.sessionCompilation._id)
- : await ration_glj_facade.getLibOptions(engineerID);
- libData.push({ name: '补充工料机', gljLibId: COMPLEMENTARY_LIB });
- if (gljLibId) { // 替换人材机初始化会触发此条件
- const orgDefalutLib = libData.find(lib => lib.isDefault);
- const newDefaultLib = libData.find(lib => lib.gljLibId === gljLibId);
- if (orgDefalutLib && newDefaultLib) {
- orgDefalutLib.isDefault = false;
- newDefaultLib.isDefault = true;
- }
- }
- }
- let skipGLJ = gljLibId === 0;
- if (!gljLibId && libData) {
- gljLibId = (libData.find(lib => lib.isDefault) || {}).gljLibId;
- }
- const info = gljLibId === COMPLEMENTARY_LIB
- ? { gljLibId: null, userID: req.session.sessionUser.id, compilationId: req.session.sessionCompilation._id }
- : { gljLibId, userID: null, compilationId: null };
- info.skipGLJ = skipGLJ;
- ration_glj_facade.getGLJData(info,function (err,datas) {
- if(err){
- result.error=1;
- result.message = err.message;
- }else {
- //多单价字段
- if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
- result.datas = datas;
- result.datas.libData = libData;
- }
- res.json(result);
- });
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- res.json(result);
- }
- }
- async function addGLJ(req, res){
- let result={
- error:0
- }
- try {
- let data = req.body.data;
- data = JSON.parse(data);
- let datas= await ration_glj_facade.addGLJ(data,req.session.sessionCompilation);
- result.data=datas;
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- }
- res.json(result);
- }
- async function replaceGLJ(req, res){
- let result={
- error:0
- }
- try {
- let data = req.body.data;
- data = JSON.parse(data);
- let rdata= await ration_glj_facade.replaceGLJ(data,req.session.sessionCompilation);
- result.data=rdata;
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- }
- res.json(result);
- }
- async function mReplaceGLJ(req, res){
- let result={
- error:0
- }
- try {
- let data = req.body.data;
- data = JSON.parse(data);
- let mresult= await ration_glj_facade.mReplaceGLJ(data,req.session.sessionCompilation);
- result.data=mresult;
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- }
- res.json(result);
- }
- async function updateRationGLJByEdit(req, res) {
- let result={
- error:0
- }
- try {
- let data = req.body.data;
- data = JSON.parse(data);
- let uresult= await ration_glj_facade.updateRationGLJByEdit(data);
- result.data=uresult;
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- }
- res.json(result);
- }
- async function getGLJClass(req, res) {
- let result={
- error:0
- }
- try {
- let data = req.body.data;
- data = JSON.parse(data);
- let info = await ration_glj_facade.getLibInfo(req);
- let tresult= await ration_glj_facade.getGLJClass(info,data);
- result.data=tresult;
- }catch (err){
- logger.err(err);
- result.error=1;
- result.message = err.message;
- }
- res.json(result);
- }
|