schedule_controller.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/7/2
  7. * @version
  8. */
  9. const moment = require('moment');
  10. const reviseStatus = require('../const/audit').revise.status;
  11. const measureType = require('../const/tender').measureType;
  12. const scheduleConst = require('../const/schedule');
  13. const billsPosConvert = require('../lib/bills_pos_convert');
  14. const _ = require('lodash');
  15. module.exports = app => {
  16. class ScheduleController extends app.BaseController {
  17. async _getSelectedLedgerList(ctx) {
  18. const scheduleLedgerList = await ctx.service.scheduleLedger.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  19. return _.map(scheduleLedgerList, 'ledger_id');
  20. }
  21. async _getLastPlanMonth(ctx) {
  22. const lastMonth = await ctx.service.scheduleMonth.getLastPlanMonth();
  23. return lastMonth && lastMonth[0] && lastMonth[0].yearmonth ? lastMonth[0].yearmonth : null;
  24. }
  25. async _getLastReviseStatus(ctx) {
  26. const lastRevise = await ctx.service.ledgerRevise.getLastestRevise(ctx.tender.id);
  27. return (lastRevise && lastRevise.status !== reviseStatus.checked) || false;
  28. }
  29. async _checkScheduleCanModify(ctx) {
  30. if (await this._getLastReviseStatus(ctx)) {
  31. throw '台账修订中,请勿修改提交进度数据';
  32. }
  33. }
  34. async index(ctx) {
  35. try {
  36. const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
  37. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
  38. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['yearmonth', 'asc']] });
  39. // 汇总并统计前几个计划月总计划额
  40. for (const i in scheduleStage) {
  41. let nowIndex = 0;
  42. let lastIndex = 0;
  43. if (i > 0) {
  44. nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
  45. lastIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i - 1].yearmonth }) + 1;
  46. } else {
  47. nowIndex = _.findIndex(scheduleMonth, { yearmonth: scheduleStage[i].yearmonth }) + 1;
  48. }
  49. // 获取新计划月数组
  50. const newSm = scheduleMonth.slice(lastIndex, nowIndex);
  51. scheduleStage[i].plan_tp = _.sumBy(newSm, 'plan_tp');
  52. }
  53. const renderData = {
  54. schedule,
  55. scheduleMonth,
  56. scheduleStage,
  57. tender: ctx.tender.data,
  58. tenderMenu: this.menu.tenderMenu,
  59. planMonth: await this._getLastPlanMonth(ctx),
  60. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  61. preUrl: '/tender/' + ctx.tender.id,
  62. revising: await this._getLastReviseStatus(ctx),
  63. };
  64. await this.layout('schedule/index.ejs', renderData, 'schedule/modal.ejs');
  65. } catch (err) {
  66. this.log(err);
  67. ctx.redirect(this.menu.menu.dashboard.url);
  68. }
  69. }
  70. async ledger(ctx) {
  71. const tender = ctx.tender;
  72. const schedule = await ctx.service.schedule.getDataByCondition({ tid: ctx.tender.id });
  73. const scheduleLedgerList = await this._getSelectedLedgerList(ctx);
  74. const allSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  75. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
  76. const hadDataLidList = [];
  77. for (const sl of scheduleLedgerList) {
  78. const info = _.find(allSlmList, function(item) {
  79. return item.lid === sl && ((item.plan_tp !== null && item.plan_tp !== 0) ||
  80. (item.plan_gcl !== null && item.plan_gcl !== 0) ||
  81. (item.sj_tp !== null && item.sj_tp !== 0) ||
  82. (item.sj_gcl !== null && item.sj_gcl !== 0));
  83. });
  84. if (info) {
  85. hadDataLidList.push(info.lid);
  86. }
  87. }
  88. const renderData = {
  89. schedule,
  90. tender: tender.data,
  91. tenderInfo: tender.info,
  92. measureType,
  93. scheduleLedgerList,
  94. hadDataLidList,
  95. scheduleStage,
  96. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.ledger),
  97. revising: await this._getLastReviseStatus(ctx),
  98. };
  99. await this.layout('schedule/ledger.ejs', renderData, 'schedule/modal.ejs');
  100. }
  101. async plan(ctx) {
  102. const tender = ctx.tender;
  103. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  104. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  105. const renderData = {
  106. tender: tender.data,
  107. tenderInfo: tender.info,
  108. schedule,
  109. scheduleMonth,
  110. planMonth: await this._getLastPlanMonth(ctx),
  111. measureType,
  112. mode: scheduleConst.plan_mode,
  113. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  114. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.plan),
  115. revising: await this._getLastReviseStatus(ctx),
  116. };
  117. await this.layout('schedule/plan.ejs', renderData, 'schedule/plan_modal.ejs');
  118. }
  119. async stageTp(ctx) {
  120. const tender = ctx.tender;
  121. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  122. const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData,
  123. scheduleMonth, stageOrderList, scheduleStage, curScheduleStage } = await this._getStageAndPlanData(ctx);
  124. const renderData = {
  125. tender: tender.data,
  126. tenderInfo: tender.info,
  127. schedule,
  128. scheduleMonth,
  129. measureType,
  130. stageOrderList,
  131. scheduleStage,
  132. curScheduleStage,
  133. slmList,
  134. nextSlmList,
  135. endSlmList,
  136. yearSlmList,
  137. curYearStageData,
  138. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  139. revising: await this._getLastReviseStatus(ctx),
  140. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageTp),
  141. };
  142. await this.layout('schedule/stage_tp.ejs', renderData, 'schedule/stage_tp_modal.ejs');
  143. }
  144. async stageGcl(ctx) {
  145. const tender = ctx.tender;
  146. const schedule = await ctx.service.schedule.getDataByCondition({ tid: tender.id });
  147. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  148. // const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['order', 'desc']] });
  149. const gclScheduleMonth = _.orderBy(_.filter(scheduleMonth, { stage_gcl_used: 1 }), ['yearmonth'], ['desc']);
  150. const curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(gclScheduleMonth, 'yearmonth') : null;
  151. const renderData = {
  152. tender: tender.data,
  153. tenderInfo: tender.info,
  154. schedule,
  155. scheduleMonth,
  156. measureType,
  157. // scheduleStage,
  158. curScheduleMonth,
  159. gclScheduleMonth,
  160. scheduleLedgerList: await this._getSelectedLedgerList(ctx),
  161. revising: await this._getLastReviseStatus(ctx),
  162. jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.schedule.stageGcl),
  163. };
  164. await this.layout('schedule/stage_gcl.ejs', renderData, 'schedule/stage_gcl_modal.ejs');
  165. }
  166. /**
  167. * 获取金额模式下台账数据(Ajax)
  168. *
  169. * @param ctx
  170. * @return {Promise<void>}
  171. */
  172. async loadTpLedgerData(ctx) {
  173. try {
  174. const ledgerData = await this._getStageLedgerData(ctx, ctx.params.order);
  175. const postData = { ledgerData };
  176. const data = JSON.parse(ctx.request.body.data);
  177. if (data.filter && data.filter === 'gcl') {
  178. const { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData } = await this._getStageAndPlanData(ctx);
  179. _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData });
  180. }
  181. ctx.body = { err: 0, msg: '', data: postData };
  182. } catch (err) {
  183. this.log(err);
  184. ctx.body = { err: 1, msg: err.toString(), data: [] };
  185. }
  186. }
  187. /**
  188. * 获取工程量模式下台账数据(Ajax)
  189. *
  190. * @param ctx
  191. * @return {Promise<void>}
  192. */
  193. async loadGclLedgerData(ctx) {
  194. try {
  195. const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  196. const postData = { ledgerData };
  197. const { slmList, nextSlmList, endSlmList, yearSlmList } = await this._getGclAndPlanData(ctx);
  198. _.assignIn(postData, { slmList, nextSlmList, endSlmList, yearSlmList });
  199. ctx.body = { err: 0, msg: '', data: postData };
  200. } catch (err) {
  201. this.log(err);
  202. ctx.body = { err: 1, msg: err.toString(), data: [] };
  203. }
  204. }
  205. /**
  206. * 获取所有期下台账数据(Ajax)
  207. *
  208. * @param ctx
  209. * @return {Promise<void>}
  210. */
  211. async _getAllStageLedgerData(ctx) {
  212. let ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  213. const stageList = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
  214. if (stageList.length > 0) {
  215. const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
  216. for (const d of dgnData) {
  217. const l = ctx.app._.find(ledgerData, { id: d.id });
  218. ctx.app._.assignIn(l, d);
  219. }
  220. for (const s of stageList) {
  221. const stageInfo = await ctx.service.stage.getDataByCondition({
  222. tid: ctx.tender.id,
  223. order: s.order,
  224. });
  225. // let preStageData;
  226. // 当前操作人查看最新数据,其他人查看历史数据
  227. const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
  228. // // 查询截止上期数据
  229. // if (stageInfo.order > 1) {
  230. // preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
  231. // } else {
  232. // preStageData = [];
  233. // }
  234. this.ctx.helper.assignRelaData(ledgerData, [
  235. { data: curStageData, fields: ['contract_tp', 'qc_tp'], prefix: s.order + '_', relaId: 'lid' },
  236. // { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: s.order + '_pre_', relaId: 'lid' },
  237. ]);
  238. }
  239. ledgerData = await this._addFinalStageData(ctx, ledgerData);
  240. }
  241. return ledgerData;
  242. }
  243. async _getStageLedgerData(ctx, stageOrder) {
  244. let ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  245. const dgnData = await ctx.service.stageBillsDgn.getDgnData(ctx.tender.id);
  246. for (const d of dgnData) {
  247. const l = ctx.app._.find(ledgerData, { id: d.id });
  248. ctx.app._.assignIn(l, d);
  249. }
  250. const stageInfo = await ctx.service.stage.getDataByCondition({
  251. tid: ctx.tender.id,
  252. order: stageOrder,
  253. });
  254. let preStageData;
  255. // 当前操作人查看最新数据,其他人查看历史数据
  256. const curStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, stageInfo.id);
  257. // 查询截止上期数据
  258. if (stageInfo.order > 1) {
  259. preStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, stageInfo.order - 1);
  260. } else {
  261. preStageData = [];
  262. }
  263. this.ctx.helper.assignRelaData(ledgerData, [
  264. { data: curStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: '', relaId: 'lid' },
  265. { data: preStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_', relaId: 'lid' },
  266. ]);
  267. // 获取进度最新期的数据
  268. ledgerData = await this._addFinalStageData(ctx, ledgerData);
  269. return ledgerData;
  270. }
  271. /**
  272. * 添加最新一期的进度期下期数据到台账数据中(Ajax)
  273. *
  274. * @param ctx
  275. * @return {Promise<void>}
  276. */
  277. async _addFinalStageData(ctx, ledgerData) {
  278. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: ctx.tender.id }, orders: [['order', 'desc']] });
  279. if (scheduleStage && scheduleStage.length > 0) {
  280. let prefinalStageData;
  281. const finalStageInfo = await ctx.service.stage.getDataByCondition({
  282. tid: ctx.tender.id,
  283. order: scheduleStage[0].order,
  284. });
  285. const finalStageData = await ctx.service.stageBills.getLastestStageData(ctx.tender.id, finalStageInfo.id);
  286. if (finalStageInfo.order > 1) {
  287. prefinalStageData = await ctx.service.stageBillsFinal.getFinalData(ctx.tender.data, finalStageInfo.order - 1);
  288. } else {
  289. prefinalStageData = [];
  290. }
  291. this.ctx.helper.assignRelaData(ledgerData, [
  292. { data: finalStageData, fields: ['contract_qty', 'contract_expr', 'contract_tp', 'qc_qty', 'qc_tp', 'postil'], prefix: 'final_', relaId: 'lid' },
  293. { data: prefinalStageData, fields: ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'used'], prefix: 'pre_final_', relaId: 'lid' },
  294. ]);
  295. }
  296. return ledgerData;
  297. }
  298. /**
  299. * 获取本期下台账计量和计划数据(Ajax)
  300. *
  301. * @param ctx
  302. * @return {Promise<void>}
  303. */
  304. async _getStageAndPlanData(ctx) {
  305. const tender = ctx.tender;
  306. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  307. const stageOrderList = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 's_time', 'order'], where: { tid: tender.id } });
  308. const scheduleStage = await ctx.service.scheduleStage.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'desc']] });
  309. let curScheduleStage = scheduleStage.length > 0 ? _.maxBy(scheduleStage, 'yearmonth') : null;
  310. if (ctx.params.order && scheduleStage.length > 0) {
  311. curScheduleStage = _.find(scheduleStage, { order: parseInt(ctx.params.order) });
  312. }
  313. let slmList = [];
  314. let nextSlmList = [];
  315. let endSlmList = [];
  316. let yearSlmList = [];
  317. let curYearStageData = [];
  318. if (curScheduleStage) {
  319. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  320. const nowScheduleStage = _.findIndex(newSM, { yearmonth: curScheduleStage.yearmonth });
  321. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleStage.yearmonth } });
  322. const nextScheduleStage = nowScheduleStage >= 0 && nowScheduleStage + 1 <= newSM.length - 1 ? newSM[nowScheduleStage + 1] : null;
  323. if (nextScheduleStage) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleStage.yearmonth } });
  324. if (nowScheduleStage === 0) {
  325. endSlmList = slmList;
  326. } else if (nowScheduleStage > 0) {
  327. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleStage + 1), 'yearmonth');
  328. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  329. }
  330. const yearConllection = _.map(_.filter(newSM, function(item) {
  331. return item.yearmonth.indexOf(curScheduleStage.yearmonth.split('-')[0]) !== -1;
  332. }), 'yearmonth');
  333. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  334. // 获取本年完成计量数据
  335. const curStage = _.find(stageOrderList, { order: curScheduleStage.order });
  336. const stageList = _.filter(stageOrderList, function(item) {
  337. return item.s_time.indexOf(curStage.s_time.split('-')[0]) !== -1;
  338. });
  339. // const newSS = _.sortBy(scheduleStage, 'yearmonth');
  340. // const stageIdList = _.map(_.filter(stageList, function(item) {
  341. // return _.find(newSS, { order: item.order });
  342. // }), 'id');
  343. const stageIdList = _.map(stageList, 'id');
  344. curYearStageData = await ctx.service.stageBills.getStagesData(tender.id, stageIdList.join(','));
  345. }
  346. return { slmList, nextSlmList, endSlmList, yearSlmList, curYearStageData, scheduleMonth, stageOrderList, scheduleStage, curScheduleStage };
  347. }
  348. /**
  349. * 获取工程量模式汇总下台账的计划数据(Ajax)
  350. *
  351. * @param ctx
  352. * @return {Promise<void>}
  353. */
  354. async _getGclAndPlanData(ctx) {
  355. const tender = ctx.tender;
  356. const scheduleMonth = await ctx.service.scheduleMonth.getAllDataByCondition({ where: { tid: tender.id }, orders: [['yearmonth', 'asc']] });
  357. let curScheduleMonth = scheduleMonth.length > 0 ? _.maxBy(scheduleMonth, 'order') : null;
  358. const gclScheduleMonth = _.filter(scheduleMonth, { stage_gcl_used: 1 });
  359. if (ctx.params.order && gclScheduleMonth.length > 0) {
  360. curScheduleMonth = _.find(gclScheduleMonth, { id: parseInt(ctx.params.order) });
  361. }
  362. let slmList = [];
  363. let nextSlmList = [];
  364. let endSlmList = [];
  365. let yearSlmList = [];
  366. if (curScheduleMonth) {
  367. const newSM = _.sortBy(scheduleMonth, 'yearmonth');
  368. const nowScheduleMonth = _.findIndex(newSM, { yearmonth: curScheduleMonth.yearmonth });
  369. slmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: curScheduleMonth.yearmonth } });
  370. const nextScheduleMonth = nowScheduleMonth >= 0 && nowScheduleMonth + 1 <= newSM.length - 1 ? newSM[nowScheduleMonth + 1] : null;
  371. if (nextScheduleMonth) nextSlmList = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: tender.id, yearmonth: nextScheduleMonth.yearmonth } });
  372. if (nowScheduleMonth === 0) {
  373. endSlmList = slmList;
  374. } else if (nowScheduleMonth > 0) {
  375. const endYearmonthCollection = _.map(_.take(newSM, nowScheduleMonth + 1), 'yearmonth');
  376. endSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, endYearmonthCollection);
  377. }
  378. const yearConllection = _.map(_.filter(newSM, function(item) {
  379. return item.yearmonth.indexOf(curScheduleMonth.yearmonth.split('-')[0]) !== -1;
  380. }), 'yearmonth');
  381. yearSlmList = await ctx.service.scheduleLedgerMonth.getConllectionList(tender.id, yearConllection);
  382. }
  383. return { slmList, nextSlmList, endSlmList, yearSlmList, scheduleMonth, curScheduleMonth };
  384. }
  385. /**
  386. * 获取台账数据(Ajax)
  387. *
  388. * @param ctx
  389. * @return {Promise<void>}
  390. */
  391. async loadLedgerData(ctx) {
  392. try {
  393. // const ledgerData = await ctx.service.ledger.getData(ctx.tender.id);
  394. const ledgerData = await this._getAllStageLedgerData(ctx);
  395. // const posData = ctx.tender.data.measure_type === measureType.tz.value
  396. // ? await ctx.service.pos.getPosData({ tid: ctx.tender.id }) : [];
  397. // const convert = new billsPosConvert(ctx);
  398. // convert.loadData(ledgerData, posData, []);
  399. // const result = await convert.convert();
  400. const scheduleLedgerMonthData = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  401. const scheduleLedgerHistoryData = await ctx.service.scheduleLedgerHistory.getAllDataByCondition({ where: { tid: ctx.tender.id } });
  402. ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData, slh: scheduleLedgerHistoryData } };
  403. } catch (err) {
  404. this.log(err);
  405. ctx.body = { err: 1, msg: err.toString(), data: [] };
  406. }
  407. }
  408. /**
  409. * 台账选中提交(Ajax)
  410. *
  411. * @param ctx
  412. * @return {Promise<void>}
  413. */
  414. async saveLedger(ctx) {
  415. try {
  416. await this._checkScheduleCanModify(ctx);
  417. const data = JSON.parse(ctx.request.body.data);
  418. const result = await ctx.service.scheduleLedger.saveLedger(data);
  419. ctx.body = { err: 0, msg: '', data: result };
  420. } catch (err) {
  421. this.log(err);
  422. ctx.body = { err: 1, msg: err.toString(), data: [] };
  423. }
  424. }
  425. /**
  426. * 计划进度计算方式提交(Ajax)
  427. *
  428. * @param ctx
  429. * @return {Promise<void>}
  430. */
  431. async savePlan(ctx) {
  432. try {
  433. await this._checkScheduleCanModify(ctx);
  434. const data = JSON.parse(ctx.request.body.data);
  435. const responseData = {
  436. err: 0,
  437. msg: '',
  438. data: {},
  439. };
  440. switch (data.type) {
  441. case 'mode':
  442. responseData.data = await ctx.service.schedule.saveMode(data.postData);
  443. break;
  444. case 'addmonth':
  445. responseData.data = await ctx.service.scheduleMonth.add(data.postData);
  446. break;
  447. case 'delmonth':
  448. responseData.data = await ctx.service.scheduleMonth.del(data.postData);
  449. break;
  450. case 'ledger_edit':
  451. responseData.data = await ctx.service.scheduleLedgerMonth.save(data.postData);
  452. break;
  453. case 'ledger_paste':
  454. responseData.data = await ctx.service.scheduleLedgerMonth.saveDatas(data.postData);
  455. break;
  456. default: throw '参数有误';
  457. }
  458. ctx.body = responseData;
  459. } catch (err) {
  460. this.log(err);
  461. ctx.body = { err: 1, msg: err.toString(), data: null };
  462. }
  463. }
  464. /**
  465. * 计量进度金额模式计算方式提交(Ajax)
  466. *
  467. * @param ctx
  468. * @return {Promise<void>}
  469. */
  470. async saveStageTp(ctx) {
  471. try {
  472. await this._checkScheduleCanModify(ctx);
  473. const data = JSON.parse(ctx.request.body.data);
  474. const responseData = {
  475. err: 0,
  476. msg: '',
  477. data: {},
  478. };
  479. switch (data.type) {
  480. case 'add_stage':
  481. responseData.data = await ctx.service.scheduleStage.add(data.postData);
  482. break;
  483. case 'del_stage':
  484. responseData.data = await ctx.service.scheduleStage.del(data.postData);
  485. break;
  486. case 'reload_stage':
  487. responseData.data = await ctx.service.scheduleStage.changeOrder(data.postData);
  488. break;
  489. case 'update_tp':
  490. responseData.data = await ctx.service.scheduleStage.updateOneTp(data.postData);
  491. break;
  492. default: throw '参数有误';
  493. }
  494. ctx.body = responseData;
  495. } catch (err) {
  496. this.log(err);
  497. ctx.body = { err: 1, msg: err.toString(), data: null };
  498. }
  499. }
  500. /**
  501. * 计量进度工程量模式计算方式提交(Ajax)
  502. *
  503. * @param ctx
  504. * @return {Promise<void>}
  505. */
  506. async saveStageGcl(ctx) {
  507. try {
  508. await this._checkScheduleCanModify(ctx);
  509. const data = JSON.parse(ctx.request.body.data);
  510. const responseData = {
  511. err: 0,
  512. msg: '',
  513. data: {},
  514. };
  515. switch (data.type) {
  516. case 'add_stage':
  517. responseData.data = await ctx.service.scheduleMonth.addStageUsed(data.postData);
  518. break;
  519. case 'del_stage':
  520. responseData.data = await ctx.service.scheduleMonth.delStageUsed(data.postData);
  521. break;
  522. case 'ledger_edit':
  523. responseData.data = await ctx.service.scheduleLedgerMonth.saveSj(data.postData);
  524. break;
  525. case 'ledger_paste':
  526. responseData.data = await ctx.service.scheduleLedgerMonth.saveSjDatas(data.postData);
  527. break;
  528. default: throw '参数有误';
  529. }
  530. ctx.body = responseData;
  531. } catch (err) {
  532. this.log(err);
  533. ctx.body = { err: 1, msg: err.toString(), data: null };
  534. }
  535. }
  536. }
  537. return ScheduleController;
  538. };