sub_project.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const rootId = '-1';
  10. const imType = require('../const/tender').imType;
  11. const defaultFunRela = {
  12. banOver: true,
  13. hintOver: true,
  14. banMinusChangeBills: true,
  15. minusNoValue: true,
  16. lockPayExpr: false,
  17. showMinusCol: true,
  18. imType: imType.zl.value,
  19. needGcl: false,
  20. };
  21. const funSet = require('../const/fun_set');
  22. const defaultFunSet = funSet.defaultInfo;
  23. const pageShowConst = require('../const/page_show').defaultSetting;
  24. module.exports = app => {
  25. class SubProject extends app.BaseService {
  26. /**
  27. * 构造函数
  28. *
  29. * @param {Object} ctx - egg全局变量
  30. * @param {String} tableName - 表名
  31. * @return {void}
  32. */
  33. constructor(ctx) {
  34. super(ctx);
  35. this.tableName = 'sub_project';
  36. }
  37. /**
  38. * 数据规则
  39. *
  40. * @param {String} scene - 场景
  41. * @return {Object} - 返回数据规则
  42. */
  43. rule(scene) {
  44. let rule = {};
  45. switch (scene) {
  46. case 'fun':
  47. rule = {
  48. imType: {type: 'enum', values: [imType.tz.value, imType.zl.value, imType.bb.value, imType.bw.value], required: true},
  49. banOver: {type: 'bool', required: true,},
  50. hintOver: {type: 'bool', required: true,},
  51. banMinusChangeBills: {type: 'bool', required: true,},
  52. minusNoValue: {type: 'bool', required: true,},
  53. lockPayExpr: {type: 'bool', required: true,},
  54. showMinusCol: {type: 'bool', required: true,},
  55. };
  56. break;
  57. default:
  58. break;
  59. }
  60. return rule;
  61. }
  62. async getSubProject(pid, uid, admin, filterFolder = false) {
  63. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  64. const permission = await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
  65. result = result.filter(x => {
  66. if (x.is_folder) return !filterFolder;
  67. if (admin) return true;
  68. const pb = permission.find(y => { return x.id === y.spid});
  69. if (!pb) return false;
  70. x.user_permission = pb;
  71. return x.user_permission.budget_permission.length > 0 || x.user_permission.file_permission.length > 0 || x.user_permission.manage_permission.length > 0;
  72. });
  73. return result;
  74. }
  75. _filterEmptyFolder(data) {
  76. data.sort((a, b) => { return b.tree_level - a.tree_level});
  77. const result = [];
  78. for (const d of data) {
  79. if (!d.is_folder) result.push(d);
  80. if (result.find(x => { return x.tree_pid === d.id; })) result.push(d);
  81. }
  82. return result;
  83. }
  84. async getBudgetProject(pid, uid, admin) {
  85. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  86. const adminPermission = this.ctx.service.subProjPermission.adminPermission;
  87. const permission = admin ? [] : await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
  88. result = result.filter(x => {
  89. if (!x.is_folder && !x.budget_id) return false;
  90. if (x.is_folder) return true;
  91. if (admin) {
  92. x.permission = adminPermission.budget_permission;
  93. x.manage_permission = adminPermission.manage_permission;
  94. return true;
  95. } else {
  96. const pb = permission.find(y => { return x.id === y.spid});
  97. if (!pb) return false;
  98. x.permission = pb.budget_permission;
  99. x.manage_permission = pb.manage_permission;
  100. return x.permission.length > 0;
  101. }
  102. });
  103. return this._filterEmptyFolder(result);
  104. }
  105. async getFileProject(pid, uid, admin) {
  106. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  107. const adminPermission = this.ctx.service.subProjPermission.adminPermission;
  108. const permission = await this.ctx.service.subProjPermission.getUserPermission(pid, uid);
  109. result = result.filter(x => {
  110. if (!x.is_folder && !x.management) return false;
  111. if (x.is_folder) return true;
  112. if (admin) {
  113. x.permission = adminPermission.file_permission;
  114. x.manage_permission = adminPermission.manage_permission;
  115. return true;
  116. } else {
  117. const pb = permission.find(y => { return x.id === y.spid});
  118. if (!pb) return false;
  119. x.permission = pb.file_permission;
  120. x.manage_permission = pb.manage_permission;
  121. return x.permission.length > 0;
  122. }
  123. });
  124. return this._filterEmptyFolder(result);
  125. }
  126. async getLastChild(tree_pid) {
  127. const result = await this.getAllDataByCondition({ where: { tree_pid, project_id: this.ctx.session.sessionProject.id }, orders: [['tree_order', 'desc']], limit: 1, offset: 0 });
  128. return result[0];
  129. }
  130. async getPosterityData(id){
  131. const result = [];
  132. let cur = await this.getAllDataByCondition({ where: { tree_pid: id, project_id: this.ctx.session.sessionProject.id } });
  133. let iLevel = 1;
  134. while (cur.length > 0 && iLevel < 6) {
  135. result.push(...cur);
  136. cur = await this.getAllDataByCondition({ where: { tree_pid: cur.map(x => { return x.id })} });
  137. iLevel += 1;
  138. }
  139. return result;
  140. }
  141. async getStepNode(node, step) {
  142. const tree_order = [];
  143. while(step) {
  144. tree_order.push(node.tree_order + step);
  145. if (step > 0) {
  146. step = step - 1;
  147. } else {
  148. step = step + 1;
  149. }
  150. }
  151. return await this.getAllDataByCondition({ where: { tree_pid: node.tree_pid, tree_order, project_id: this.ctx.session.sessionProject.id }, orders: [['tree_order', 'asc']]});
  152. }
  153. async addFolder(data) {
  154. const parent = await this.getDataById(data.tree_pid);
  155. if (parent && !parent.is_folder) throw '添加数据结构错误';
  156. const lastChild = await this.getLastChild(parent ? parent.id : rootId);
  157. const conn = await this.db.beginTransaction();
  158. try {
  159. // 获取当前用户信息
  160. const sessionUser = this.ctx.session.sessionUser;
  161. // 获取当前项目信息
  162. const sessionProject = this.ctx.session.sessionProject;
  163. const insertData = {
  164. id: this.uuid.v4(), project_id: sessionProject.id, user_id: sessionUser.accountId,
  165. tree_pid: data.tree_pid,
  166. tree_level: parent ? parent.tree_level + 1 : 1,
  167. tree_order: lastChild ? lastChild.tree_order + 1 : 1,
  168. name: data.name, is_folder: 1,
  169. };
  170. const operate = await conn.insert(this.tableName, insertData);
  171. if (operate.affectedRows === 0) throw '新增文件夹失败';
  172. await conn.commit();
  173. return await this.getSubProject(sessionProject.id, sessionUser.accountId, sessionUser.is_admin);
  174. } catch (error) {
  175. await conn.rollback();
  176. throw error;
  177. }
  178. }
  179. async addSubProject(data) {
  180. const parent = await this.getDataById(data.tree_pid);
  181. if (parent && !parent.is_folder) throw '添加数据结构错误';
  182. const lastChild = await this.getLastChild(parent ? parent.id : rootId);
  183. const conn = await this.db.beginTransaction();
  184. try {
  185. // 获取当前用户信息
  186. const sessionUser = this.ctx.session.sessionUser;
  187. // 获取当前项目信息
  188. const sessionProject = this.ctx.session.sessionProject;
  189. const insertData = {
  190. id: this.uuid.v4(), project_id: sessionProject.id, user_id: sessionUser.accountId,
  191. tree_pid: data.tree_pid,
  192. tree_level: parent ? parent.tree_level + 1 : 1,
  193. tree_order: lastChild ? lastChild.tree_order + 1 : 1,
  194. name: data.name, is_folder: 0,
  195. };
  196. const operate = await conn.insert(this.tableName, insertData);
  197. // todo 根据节点新增时的其他操作
  198. if (operate.affectedRows === 0) throw '新增文件夹失败';
  199. await conn.commit();
  200. return await this.getSubProject(sessionProject.id, sessionUser.accountId, sessionUser.is_admin);
  201. } catch (error) {
  202. await conn.rollback();
  203. throw error;
  204. }
  205. }
  206. async dragTo(data) {
  207. const dragNode = await this.getDataById(data.drag_id);
  208. const dropNode = await this.getDataById(data.drop_id);
  209. if (!dragNode || !dropNode || !dropNode.is_folder) throw '拖拽数据结构错误';
  210. const lastChild = await this.getLastChild(dropNode.id);
  211. const posterity = await this.getPosterityData(dragNode.id);
  212. const conn = await this.db.beginTransaction();
  213. try {
  214. const updateData = {
  215. id: dragNode.id, tree_pid: dropNode.id, tree_level: dropNode.tree_level + 1,
  216. tree_order: lastChild ? lastChild.tree_order + 1 : 1,
  217. };
  218. await conn.update(this.tableName, updateData);
  219. if (dragNode.tree_level !== dropNode.tree_level + 1 && posterity.length > 0) {
  220. const posterityUpdateData = posterity.map(x => {
  221. return { id: x.id, tree_level: dropNode.tree_level + 1 - dragNode.tree_level + x.tree_level }
  222. });
  223. await conn.updateRows(this.tableName, posterityUpdateData);
  224. }
  225. // 升级原来的后项的order
  226. await conn.query(`UPDATE ${this.tableName} SET tree_order = tree_order-1 WHERE tree_pid = ? AND tree_order > ?`, [dragNode.tree_pid, dragNode.tree_order]);
  227. await conn.commit();
  228. } catch (error) {
  229. await conn.rollback();
  230. throw error;
  231. }
  232. return await this.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin);
  233. }
  234. async _siblingMove(node, step) {
  235. const stepNode = await this.getStepNode(node, step);
  236. const conn = await this.db.beginTransaction();
  237. try {
  238. const updateData = [];
  239. updateData.push({ id: node.id, tree_order: node.tree_order + step });
  240. for (const sn of stepNode) {
  241. updateData.push({ id: node.id, tree_order: step > 0 ? sn.tree_order - 1 : sn.tree_order + 1 });
  242. }
  243. await conn.updateRows(this.tableName, updateData);
  244. await conn.commit();
  245. } catch (error) {
  246. await conn.rollback();
  247. throw error;
  248. }
  249. }
  250. async _siblingMoveForce(node, step) {
  251. const sibling = await this.getAllDataByCondition({ where: { tree_pid: node.tree_pid, project_id: this.ctx.session.sessionProject.id }, orders: [['tree_order', 'asc']] });
  252. const nodeIndex = sibling.findIndex(x => { return x.id === node.id });
  253. if (nodeIndex + step < 0) throw '移动数据结构错误';
  254. if (nodeIndex + step > sibling.length - 1) throw '移动数据结构错误';
  255. const conn = await this.db.beginTransaction();
  256. try {
  257. const updateData = [];
  258. updateData.push({ id: node.id, tree_order: sibling[nodeIndex + step].tree_order });
  259. while(step) {
  260. const stepNode = sibling[nodeIndex + step];
  261. if (step > 0) {
  262. updateData.push({ id: stepNode.id, tree_order: sibling[nodeIndex + step - 1].tree_order });
  263. step = step - 1;
  264. } else {
  265. updateData.push({ id: stepNode.id, tree_order: sibling[nodeIndex + step + 1].tree_order});
  266. step = step + 1;
  267. }
  268. }
  269. await conn.updateRows(this.tableName, updateData);
  270. await conn.commit();
  271. } catch (error) {
  272. await conn.rollback();
  273. throw error;
  274. }
  275. }
  276. async _topMove(node) {
  277. const lastChild = await this.getLastChild(rootId);
  278. const posterity = await this.getPosterityData(node.id);
  279. const conn = await this.db.beginTransaction();
  280. try {
  281. const updateData = { id: node.id, tree_pid: rootId, tree_level: 1, tree_order: lastChild ? lastChild.tree_order + 1 : 1 };
  282. await conn.update(this.tableName, updateData);
  283. if (node.tree_level !== 1 && posterity.length > 0) {
  284. const posterityUpdateData = posterity.map(x => {
  285. return { id: x.id, tree_level: x.tree_level - node.tree_level + 1 }
  286. });
  287. await conn.updateRows(this.tableName, posterityUpdateData);
  288. }
  289. // 升级原来的后项的order
  290. await conn.query(`UPDATE ${this.tableName} SET tree_order = tree_order-1 WHERE tree_pid = ? AND tree_order > ?`, [node.tree_pid, node.tree_order]);
  291. await conn.commit();
  292. } catch (error) {
  293. await conn.rollback();
  294. throw error;
  295. }
  296. }
  297. async move(data) {
  298. const node = await this.getDataById(data.id);
  299. if (!node) throw '移动数据结构错误';
  300. switch(data.type) {
  301. case 'up': await this._siblingMoveForce(node, -1); break;
  302. case 'down': await this._siblingMoveForce(node, 1); break;
  303. case 'top': await this._topMove(node); break;
  304. default: throw '未知移动类型';
  305. }
  306. return await this.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin);
  307. }
  308. async del(id) {
  309. const node = await this.getDataById(id);
  310. if (!node) throw '删除的数据不存在';
  311. const posterity = await this.getPosterityData(node.id);
  312. const updateData = [
  313. { id: node.id, is_delete: 1 },
  314. ];
  315. posterity.forEach(x => {
  316. updateData.push({ id: x.id, is_delete: 1});
  317. });
  318. await this.db.updateRows(this.tableName, updateData);
  319. return await this.getSubProject(this.ctx.session.sessionProject.id, this.ctx.session.sessionUser.accountId, this.ctx.session.sessionUser.is_admin);
  320. }
  321. async save(data) {
  322. const result = await this.db.update(this.tableName, data);
  323. if (result.affectedRows > 0) {
  324. return data;
  325. } else {
  326. throw '更新数据失败';
  327. }
  328. }
  329. async setBudgetStd(data) {
  330. const subProject = await this.getDataById(data.id);
  331. const budgetStd = await this.ctx.service.budgetStd.getDataById(data.std_id);
  332. if (!budgetStd) throw '选择的概算标准不存在,请刷新页面重试';
  333. const conn = await this.db.beginTransaction();
  334. try {
  335. const budget_id = await this.ctx.service.budget.add(conn, {
  336. pid: subProject.project_id, user_id: subProject.user_id, rela_tender: subProject.rela_tender
  337. }, budgetStd);
  338. const updateData = { id: data.id, std_id: budgetStd.id, std_name: budgetStd.name, budget_id };
  339. await conn.update(this.tableName, updateData);
  340. await conn.commit();
  341. return updateData;
  342. } catch (error) {
  343. await conn.rollback();
  344. throw error;
  345. }
  346. }
  347. async setRelaTender(data) {
  348. const subProject = await this.getDataById(data.id);
  349. const orgRelaTenderId = subProject.rela_tender.split(',');
  350. const conn = await this.db.beginTransaction();
  351. try {
  352. await conn.update(this.tableName, data);
  353. await conn.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender: data.rela_tender });
  354. const relaTenderId = data.rela_tender.split(',');
  355. const removeTenderId = orgRelaTenderId.filter(x => { return relaTenderId.indexOf(x) < 0});
  356. const addTenderId = relaTenderId.filter(x => { return orgRelaTenderId.indexOf(x) < 0});
  357. if (removeTenderId.length > 0) await conn.update(this.ctx.service.tender.tableName, { spid: '' }, { where: { id: removeTenderId }});
  358. if (addTenderId.length > 0) await conn.update(this.ctx.service.tender.tableName, { spid: data.id }, { where: { id: addTenderId }});
  359. await conn.commit();
  360. return data;
  361. } catch (error) {
  362. await conn.rollback();
  363. throw error;
  364. }
  365. }
  366. async addRelaTender(transaction, spid, tid) {
  367. if (!transaction) throw '未定义事务';
  368. const subProject = await this.getDataById(spid);
  369. if (!subProject) throw '所属项目不存在';
  370. const rela = subProject.rela_tender.split(',');
  371. if (rela.indexOf(tid + '') >= 0) return;
  372. rela.push(tid + '');
  373. const rela_tender = rela.join(',');
  374. await transaction.update(this.tableName, { id: spid, rela_tender});
  375. await transaction.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender});
  376. }
  377. async removeRelaTender(transaction, spid, tid) {
  378. if (!transaction) throw '未定义事务';
  379. const subProject = await this.getDataById(spid);
  380. if (!subProject) throw '所属项目不存在';
  381. const rela = subProject.rela_tender.split(',');
  382. if (rela.indexOf(tid + '') < 0) return;
  383. const rela_tender = rela.filter(x => { return x === tid + ''}).join(',');
  384. await transaction.update(this.tableName, { id: spid, rela_tender});
  385. await transaction.update(this.ctx.service.budget.tableName, { id: subProject.budget_id, rela_tender});
  386. }
  387. async setManagement(data) {
  388. const subProject = await this.getDataById(data.id);
  389. if (subProject.management === data.management) return data;
  390. const users = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { project_id: subProject.project_id, company: data.management }});
  391. const orgMember = await this.ctx.service.subProjPermission.getAllDataByCondition({ where: { spid: subProject.id } });
  392. const dm = [], um = [], im = [];
  393. const template = await this.ctx.service.filingTemplateList.getDataById(data.filingTemplate);
  394. if (!template) throw '选择的文件类别不存在';
  395. const templateFiling = await this.ctx.service.filingTemplate.getAllDataByCondition({
  396. where: { temp_id: template.id, is_fixed: 1 },
  397. });
  398. const filing_type = this.ctx.service.filing.analysisFilingType(templateFiling).map(x => { return x.value; }).join(','), file_permission = '1,2';
  399. for (const u of users) {
  400. const nm = orgMember.find(x => { return u.id === x.uid; });
  401. if (nm) {
  402. if (!nm.file_permission) um.push({ id: nm.id, file_permission, filing_type });
  403. } else {
  404. im.push({ id: this.uuid.v4(), spid: subProject.id, pid: subProject.project_id, uid: u.id, file_permission, filing_type });
  405. }
  406. }
  407. const conn = await this.db.beginTransaction();
  408. try {
  409. await conn.update(this.tableName, { id: subProject.id, management: data.management, filing_template_id: template.id, filing_template_name: template.name });
  410. await this.ctx.service.filing.initFiling(subProject.id, data.filingTemplate, conn);
  411. if (dm.length > 0) await conn.delete(this.ctx.service.subProjPermission.tableName, { id: dm });
  412. if (um.length > 0) await conn.updateRows(this.ctx.service.subProjPermission.tableName, um);
  413. if (im.length > 0) await conn.insert(this.ctx.service.subProjPermission.tableName, im);
  414. await conn.commit();
  415. return data;
  416. } catch (error) {
  417. await conn.rollback();
  418. throw error;
  419. }
  420. }
  421. async refreshManagementPermission(data) {
  422. const subProject = await this.getDataById(data.id);
  423. const users = await this.ctx.service.projectAccount.getAllDataByCondition({ where: { project_id: subProject.project_id, company: subProject.management }});
  424. const orgMember = await this.ctx.service.subProjPermission.getAllDataByCondition({ where: { spid: subProject.id } });
  425. const dm = [], um = [], im = [];
  426. const filing_type = this.ctx.service.filing.allFilingType.join(','), file_permission = '1,2';
  427. for (const u of users) {
  428. const nm = orgMember.find(x => { return u.id === x.uid; });
  429. if (nm) {
  430. if (!nm.file_permission) um.push({ id: nm.id, file_permission, filing_type });
  431. } else {
  432. im.push({ id: this.uuid.v4(), spid: subProject.id, pid: subProject.project_id, uid: u.id, file_permission, filing_type });
  433. }
  434. }
  435. const conn = await this.db.beginTransaction();
  436. try {
  437. if (dm.length > 0) await conn.delete(this.ctx.service.subProjPermission.tableName, { id: dm });
  438. if (um.length > 0) await conn.updateRows(this.ctx.service.subProjPermission.tableName, um);
  439. if (im.length > 0) await conn.insert(this.ctx.service.subProjPermission.tableName, im);
  440. await conn.commit();
  441. return { dm: dm.length, um: um.length, im: im.length };
  442. } catch (error) {
  443. await conn.rollback();
  444. throw error;
  445. }
  446. }
  447. // 合同管理获取项目列表
  448. async getSubProjectByContract(pid, uid, admin, filterFolder = false) {
  449. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  450. if (admin) return this._filterEmptyFolder(result);
  451. const permission = await this.ctx.service.contractAudit.getAllDataByCondition({ where: { uid } });
  452. result = result.filter(x => {
  453. if (x.is_folder) return !filterFolder;
  454. const pb = permission.find(y => { return x.id === y.spid; });
  455. if (!pb) return false;
  456. return true;
  457. });
  458. return this._filterEmptyFolder(result);
  459. }
  460. async getSubProjectByTender(pid, tenders, filterFolder = false) {
  461. if (tenders.length === 0) return [];
  462. const spids = this._.uniq(this._.map(tenders, 'spid'));
  463. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  464. result = result.filter(x => {
  465. if (x.is_folder) return !filterFolder;
  466. if (!x.rela_tender) return false;
  467. return this._.includes(spids, x.id);
  468. });
  469. return this._filterEmptyFolder(result);
  470. }
  471. // 合同管理获取项目列表
  472. async getSubProjectByFinancial(pid, uid, admin, filterFolder = false) {
  473. let result = await this.getAllDataByCondition({ where: { project_id: pid, is_delete: 0 } });
  474. if (admin) return this._filterEmptyFolder(result);
  475. const permission = await this.ctx.service.financialAudit.getAllDataByCondition({ where: { uid } });
  476. result = result.filter(x => {
  477. if (x.is_folder) return !filterFolder;
  478. const pb = permission.find(y => { return x.id === y.spid; });
  479. if (!pb) return false;
  480. return true;
  481. });
  482. return this._filterEmptyFolder(result);
  483. }
  484. async getFileReference(subProject) {
  485. return await this.db.query(`SELECT id, name FROM zh_file_reference_list`);
  486. };
  487. getPageShow(page_show) {
  488. const info = page_show ? JSON.parse(page_show) : {};
  489. for (const pi in pageShowConst) {
  490. info[pi] = info[pi] === undefined ? pageShowConst[pi] : parseInt(info[pi]);
  491. this.ctx.helper._.defaults(info[pi], pageShowConst[pi]);
  492. }
  493. return info;
  494. }
  495. async updatePageshow(id) {
  496. const result = await this.db.update(this.tableName, {
  497. id, page_show: JSON.stringify(this.ctx.session.sessionProject.page_show),
  498. });
  499. return result.affectedRows === 1;
  500. }
  501. /**
  502. * 功能设置
  503. * @param id
  504. * @returns {Promise<null>}
  505. */
  506. getFunRela(subProject) {
  507. const result = subProject.fun_rela ? JSON.parse(subProject.fun_rela) : {};
  508. this.ctx.helper._.defaults(result, defaultFunRela);
  509. return result;
  510. }
  511. async updateFunRela(id, data) {
  512. const result = await this.db.update(this.tableName, {
  513. id: id, fun_rela: JSON.stringify({
  514. banOver: data.banOver, hintOver: data.hintOver, banMinusChangeBills: data.banMinusChangeBills,
  515. imType: data.imType, needGcl: data.needGcl, minusNoValue: data.minusNoValue,
  516. lockPayExpr: data.lockPayExpr, showMinusCol: data.showMinusCol,
  517. }),
  518. });
  519. return result.affectedRows === 1;
  520. }
  521. getFunSet(fun_set = null) {
  522. const result = fun_set ? JSON.parse(fun_set) : {};
  523. this.ctx.helper._.defaults(result, defaultFunSet);
  524. return result;
  525. }
  526. async updateFunSet(id, funSet) {
  527. const result = await this.db.update(this.tableName, {
  528. id, fun_set: JSON.stringify(funSet),
  529. });
  530. return result.affectedRows === 1;
  531. }
  532. }
  533. return SubProject;
  534. };