Commit 3fd676197301511b9de5f89da7bda7d0a51393bd
1 parent
b53cae26
Exists in
master
增加报表方法
Showing
6 changed files
with
50 additions
and
18 deletions
Show diff stats
app/controller/project.js
| ... | ... | @@ -39,6 +39,21 @@ class ProjectController extends Controller { |
| 39 | 39 | }; |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | + async analysis() { | |
| 43 | + const ctx = this.ctx; | |
| 44 | + try { | |
| 45 | + const result = await ctx.service.project.analysis(); | |
| 46 | + this.ctx.body = { | |
| 47 | + result, | |
| 48 | + success: true, | |
| 49 | + }; | |
| 50 | + } catch (error) { | |
| 51 | + this.ctx.body = { | |
| 52 | + success: false, | |
| 53 | + error, | |
| 54 | + }; | |
| 55 | + } | |
| 56 | + } | |
| 42 | 57 | async add() { |
| 43 | 58 | const ctx = this.ctx; |
| 44 | 59 | const id = uuid.v4(); | ... | ... |
app/router.js
| ... | ... | @@ -33,6 +33,7 @@ module.exports = app => { |
| 33 | 33 | router.put('/contract', controller.contract.update); |
| 34 | 34 | router.post('/contract/delete', controller.contract.remove); |
| 35 | 35 | // 项目管理 |
| 36 | + router.get('/project/analysis', controller.project.analysis); | |
| 36 | 37 | router.get('/project/list', controller.project.list); |
| 37 | 38 | router.get('/project/:id', controller.project.info); |
| 38 | 39 | router.post('/project', controller.project.add); | ... | ... |
app/service/project.js
| ... | ... | @@ -5,6 +5,38 @@ const objExclude = require('../util/common').objExclude; |
| 5 | 5 | const moment = require('moment'); |
| 6 | 6 | |
| 7 | 7 | class ProjectService extends Service { |
| 8 | + async analysis() { | |
| 9 | + // const sql = ` | |
| 10 | + // select | |
| 11 | + // project.number, | |
| 12 | + // project.name, | |
| 13 | + // s_contract.value as s_value, | |
| 14 | + // s_contract.other_expenses as s_other_expenses, | |
| 15 | + // s_contract.invoice as s_invoice, | |
| 16 | + // p_contract.value as p_value, | |
| 17 | + // p_contract.other_expenses as p_other_expenses, | |
| 18 | + // p_contract.invoice as p_invoice | |
| 19 | + // from project, contract as s_contract, contract as p_contract | |
| 20 | + // where project.sale_contract_id = s_contract.id and project.purchase_contract_id = p_contract.id | |
| 21 | + // `; | |
| 22 | + const sql = ` | |
| 23 | + select a.*,b.p_value, b.p_other_expenses,b.p_invoice from | |
| 24 | + ( | |
| 25 | + select | |
| 26 | + project.number, project.name, contract.value as s_value, contract.other_expenses as s_other_expenses, contract.invoice as s_invoice | |
| 27 | + from project, contract where project.sale_contract_id = contract.id | |
| 28 | + ) a | |
| 29 | + left join | |
| 30 | + ( | |
| 31 | + select | |
| 32 | + project.number, project.name, contract.value as p_value, contract.other_expenses as p_other_expenses, contract.invoice as p_invoice | |
| 33 | + from project, contract where project.purchase_contract_id = contract.id | |
| 34 | + ) b | |
| 35 | + on a.number = b.number | |
| 36 | + `; | |
| 37 | + const result = await this.app.mysql.query(sql); | |
| 38 | + return result; | |
| 39 | + } | |
| 8 | 40 | async count() { |
| 9 | 41 | const result = await this.app.mysql.query('select count(*) as total from project'); |
| 10 | 42 | return result; | ... | ... |
app/service/statistic.js
| ... | ... | @@ -17,22 +17,6 @@ class StatisticService extends Service { |
| 17 | 17 | `); |
| 18 | 18 | return result && result.length > 0 ? result[0] : {}; |
| 19 | 19 | } |
| 20 | - async projectAnalysis() { | |
| 21 | - const result = await this.app.mysql.query(` | |
| 22 | - select | |
| 23 | - project.number, | |
| 24 | - project.name, | |
| 25 | - s_contract.value as s_value, | |
| 26 | - s_contract.other_expenses as s_other_expenses, | |
| 27 | - s_contract.invoice as s_invoice, | |
| 28 | - p_contract.value as p_value, | |
| 29 | - p_contract.other_expenses as p_other_expenses, | |
| 30 | - p_contract.invoice as p_invoice | |
| 31 | - from project, contract as s_contract, contract as p_contract | |
| 32 | - where project.sale_contract_id = s_contract.id and project.purchase_contract_id = p_contract.id | |
| 33 | - `); | |
| 34 | - return result; | |
| 35 | - } | |
| 36 | 20 | } |
| 37 | 21 | |
| 38 | 22 | module.exports = StatisticService; | ... | ... |
config/config.default.js
package.json
| ... | ... | @@ -27,7 +27,7 @@ |
| 27 | 27 | "scripts": { |
| 28 | 28 | "start": "egg-scripts start --daemon --title=egg-server-sf-erp-server", |
| 29 | 29 | "stop": "egg-scripts stop --title=egg-server-sf-erp-server", |
| 30 | - "dev": "egg-bin dev", | |
| 30 | + "dev": "egg-bin dev --host 0.0.0.0", | |
| 31 | 31 | "debug": "egg-bin debug", |
| 32 | 32 | "test": "npm run lint -- --fix && npm run test-local", |
| 33 | 33 | "test-local": "egg-bin test", | ... | ... |