schedule_controller.js 29 KB

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