tender_param.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class TenderParam extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局context
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'tender_param';
  20. }
  21. async updateCalcValue(data) {
  22. const transaction = await this.db.beginTransaction();
  23. try {
  24. const condition = {
  25. lib_id: parseInt(data.lib_id),
  26. node_id: data.node_id,
  27. code: data.code
  28. };
  29. if (condition.lib_id < 0 || condition.node_id < 0) {
  30. throw '提交数据错误';
  31. }
  32. const updateData = {
  33. calc_value: parseFloat(data.value),
  34. };
  35. await transaction.update(this.tableName, updateData, {where: condition});
  36. // to do 计算
  37. await transaction.commit();
  38. return true;
  39. } catch (err) {
  40. await transaction.rollback();
  41. throw err;
  42. }
  43. }
  44. async resetCalcValue(data) {
  45. try {
  46. const condition = {
  47. lib_id: parseInt(data.lib_id),
  48. node_id: data.node_id,
  49. code: data.code,
  50. };
  51. if (condition.lib_id < 0 || condition.node_id < 0) {
  52. throw '提交数据错误';
  53. }
  54. const param = await this.getDataByCondition(condition);
  55. data.value = param.match_value;
  56. await this.updateCalcValue(data);
  57. return true;
  58. } catch (err) {
  59. throw err;
  60. }
  61. }
  62. };
  63. return TenderParam;
  64. };