sub_project.js 27 KB

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