ration_glj_controller.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. * Created by chen on 2017/6/29.
  3. */
  4. let mongoose = require("mongoose")
  5. let ration_glj_facade = require('../facade/ration_glj_facade')
  6. let logger = require("../../../logs/log_helper").logger;
  7. const { COMPLEMENTARY_LIB, COMPILATION } = require ('../../../public/common_constants');
  8. module.exports={
  9. createRationGLJ:createRationGLJ,
  10. testGetQuantify:testGetQuantify,
  11. getGLJData:getGLJData,
  12. getGLJDataByCodes:getGLJDataByCodes,
  13. addGLJ:addGLJ,
  14. replaceGLJ:replaceGLJ,
  15. mReplaceGLJ:mReplaceGLJ,
  16. updateRationGLJByEdit:updateRationGLJByEdit,
  17. getGLJClass:getGLJClass,
  18. deleteRationGLJ:deleteRationGLJ,
  19. updateProportion:updateProportion
  20. }
  21. function createRationGLJ() {
  22. let gls = mongoose.model('ration_glj');
  23. gls.create({'GLJID':1,'basePrice':23.23,'name':"testgls"},function(err, gls){
  24. console.log(gls)
  25. })
  26. }
  27. //测试获取消耗量:
  28. async function testGetQuantify() {
  29. var condition = {
  30. projectID:99,
  31. projectGLJIDList:[60,61,62]
  32. }
  33. try{
  34. let result = await ration_glj_facade.getQuantityByProjectGLJ(condition);
  35. console.log(result)
  36. }catch (err){
  37. console.log(err);
  38. }
  39. }
  40. async function getGLJDataByCodes(req,res){
  41. let result={
  42. error:0
  43. }
  44. try {
  45. let data = req.body.data;
  46. data = JSON.parse(data);
  47. let datas= await ration_glj_facade.getGLJDataByCodes(data,req.session.sessionCompilation);
  48. result.data=datas;
  49. }catch (err){
  50. logger.err(err);
  51. result.error=1;
  52. result.message = err.message;
  53. }
  54. res.json(result);
  55. }
  56. async function getGLJData(req, res) {
  57. let result={
  58. error:0
  59. }
  60. try {
  61. let libData = null;
  62. let { engineerID, gljLibId, isInitial } = req.params;
  63. if (gljLibId !== COMPLEMENTARY_LIB) {
  64. gljLibId = +gljLibId;
  65. }
  66. isInitial = JSON.parse(isInitial);
  67. if (!gljLibId || isInitial) { // 替换人材机的话,可能存在gljLibID,但是是初始化的操作
  68. libData = engineerID === COMPILATION
  69. ? await ration_glj_facade.getLibOptionsForCompilation(req.session.sessionCompilation._id)
  70. : await ration_glj_facade.getLibOptions(engineerID);
  71. libData.push({ name: '补充工料机', gljLibId: COMPLEMENTARY_LIB });
  72. if (gljLibId) { // 替换人材机初始化会触发此条件
  73. const orgDefalutLib = libData.find(lib => lib.isDefault);
  74. const newDefaultLib = libData.find(lib => lib.gljLibId === gljLibId);
  75. if (orgDefalutLib && newDefaultLib) {
  76. orgDefalutLib.isDefault = false;
  77. newDefaultLib.isDefault = true;
  78. }
  79. }
  80. }
  81. if (!gljLibId && libData) {
  82. gljLibId = (libData.find(lib => lib.isDefault) || {}).gljLibId;
  83. }
  84. const info = gljLibId === COMPLEMENTARY_LIB
  85. ? { gljLibId: null, userID: req.session.sessionUser.id, compilationId: req.session.sessionCompilation._id }
  86. : { gljLibId, userID: null, compilationId: null };
  87. ration_glj_facade.getGLJData(info,function (err,datas) {
  88. if(err){
  89. result.error=1;
  90. result.message = err.message;
  91. }else {
  92. //多单价字段
  93. if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
  94. result.datas = datas;
  95. result.datas.libData = libData;
  96. }
  97. res.json(result);
  98. });
  99. }catch (err){
  100. logger.err(err);
  101. result.error=1;
  102. result.message = err.message;
  103. res.json(result);
  104. }
  105. }
  106. /* async function getGLJData(req, res) {
  107. let result={
  108. error:0
  109. }
  110. try {
  111. let info = await ration_glj_facade.getLibInfo(req);
  112. ration_glj_facade.getGLJData(info,function (err,datas) {
  113. if(err){
  114. result.error=1;
  115. result.message = err.message;
  116. }else {
  117. //多单价字段
  118. if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
  119. result.datas = datas;
  120. }
  121. res.json(result);
  122. });
  123. }catch (err){
  124. logger.err(err);
  125. result.error=1;
  126. result.message = err.message;
  127. res.json(result);
  128. }
  129. } */
  130. async function addGLJ(req, res){
  131. let result={
  132. error:0
  133. }
  134. try {
  135. let data = req.body.data;
  136. data = JSON.parse(data);
  137. let datas= await ration_glj_facade.addGLJ(data,req.session.sessionCompilation);
  138. result.data=datas;
  139. }catch (err){
  140. logger.err(err);
  141. result.error=1;
  142. result.message = err.message;
  143. }
  144. res.json(result);
  145. }
  146. async function deleteRationGLJ (req,res) {
  147. let result={
  148. error:0
  149. }
  150. try {
  151. let data = req.body.data;
  152. data = JSON.parse(data);
  153. let datas= await ration_glj_facade.deleteRationGLJ(data);
  154. result.data=datas;
  155. }catch (err){
  156. logger.err(err);
  157. result.error=1;
  158. result.message = err.message;
  159. }
  160. res.json(result);
  161. }
  162. async function updateProportion(req, res) {
  163. try {
  164. const data = JSON.parse(req.body.data);
  165. const rst = await ration_glj_facade.updateProportion(data.proportionList, data.projectID, data.rationID);
  166. res.json({ error: 0, data: rst, message: 'success' });
  167. } catch (err) {
  168. res.json({ error: 1, data: null, message: err.message });
  169. }
  170. }
  171. async function replaceGLJ(req, res){
  172. let result={
  173. error:0
  174. }
  175. try {
  176. let data = req.body.data;
  177. data = JSON.parse(data);
  178. let rdata= await ration_glj_facade.replaceGLJ(data,req.session.sessionCompilation);
  179. result.data=rdata;
  180. }catch (err){
  181. logger.err(err);
  182. result.error=1;
  183. result.message = err.message;
  184. }
  185. res.json(result);
  186. }
  187. async function mReplaceGLJ(req, res){
  188. let result={
  189. error:0
  190. }
  191. try {
  192. let data = req.body.data;
  193. data = JSON.parse(data);
  194. let mresult= await ration_glj_facade.mReplaceGLJ(data,req.session.sessionCompilation);
  195. result.data=mresult;
  196. }catch (err){
  197. logger.err(err);
  198. result.error=1;
  199. result.message = err.message;
  200. }
  201. res.json(result);
  202. }
  203. async function updateRationGLJByEdit(req, res) {
  204. let result={
  205. error:0
  206. }
  207. try {
  208. let data = req.body.data;
  209. data = JSON.parse(data);
  210. let uresult= await ration_glj_facade.updateRationGLJByEdit(data);
  211. result.data=uresult;
  212. }catch (err){
  213. logger.err(err);
  214. result.error=1;
  215. result.message = err.message;
  216. }
  217. res.json(result);
  218. }
  219. async function getGLJClass(req, res) {
  220. let result={
  221. error:0
  222. }
  223. try {
  224. let data = req.body.data;
  225. data = JSON.parse(data);
  226. let info = await ration_glj_facade.getLibInfo(req);
  227. let tresult= await ration_glj_facade.getGLJClass(info,data);
  228. result.data=tresult;
  229. }catch (err){
  230. logger.err(err);
  231. result.error=1;
  232. result.message = err.message;
  233. }
  234. res.json(result);
  235. }