Commit 82b13adbd7b6a3dc526489b18fe528585a0d283c
1 parent
e47a3274
Exists in
master
增加个人报表接口
Showing
4 changed files
with
63 additions
and
17 deletions
Show diff stats
app/controller/project.js
| ... | ... | @@ -39,6 +39,24 @@ class ProjectController extends Controller { |
| 39 | 39 | }; |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | + async user_analysis() { | |
| 43 | + const ctx = this.ctx; | |
| 44 | + const param = qs.parse(this.ctx.query); | |
| 45 | + const date = param.date; | |
| 46 | + const id = param.id; | |
| 47 | + try { | |
| 48 | + const result = await ctx.service.project.user_analysis(id, date); | |
| 49 | + this.ctx.body = { | |
| 50 | + result, | |
| 51 | + success: true, | |
| 52 | + }; | |
| 53 | + } catch (error) { | |
| 54 | + this.ctx.body = { | |
| 55 | + success: false, | |
| 56 | + error, | |
| 57 | + }; | |
| 58 | + } | |
| 59 | + } | |
| 42 | 60 | async analysis() { |
| 43 | 61 | const ctx = this.ctx; |
| 44 | 62 | const param = qs.parse(this.ctx.query); | ... | ... |
app/router.js
| ... | ... | @@ -37,6 +37,7 @@ module.exports = app => { |
| 37 | 37 | router.put('/contract', controller.contract.update); |
| 38 | 38 | router.post('/contract/delete', controller.contract.remove); |
| 39 | 39 | // 项目管理 |
| 40 | + router.get('/project/analysis/user', controller.project.user_analysis); | |
| 40 | 41 | router.get('/project/analysis', controller.project.analysis); |
| 41 | 42 | router.get('/project/list', controller.project.list); |
| 42 | 43 | router.get('/project/:id', controller.project.info); | ... | ... |
app/service/contract.js
| ... | ... | @@ -6,10 +6,10 @@ const objToQuery = require('../util/common').objToQuery; |
| 6 | 6 | |
| 7 | 7 | class ContractService extends Service { |
| 8 | 8 | async analysis(data) { |
| 9 | - const where = objToQuery(data); | |
| 9 | + const where = objToQuery(data, 'contract'); | |
| 10 | 10 | const sql = ` |
| 11 | - select * from contract | |
| 12 | - ${where !== '' ? `where ${where}` : ''} | |
| 11 | + select contract.*, user.name as manager_name from contract, user where contract.manager_id = user.id | |
| 12 | + ${where !== '' ? `and ${where}` : ''} | |
| 13 | 13 | `; |
| 14 | 14 | console.log(sql); |
| 15 | 15 | const result = await this.app.mysql.query(sql); | ... | ... |
app/service/project.js
| ... | ... | @@ -5,6 +5,30 @@ const objExclude = require('../util/common').objExclude; |
| 5 | 5 | const moment = require('moment'); |
| 6 | 6 | |
| 7 | 7 | class ProjectService extends Service { |
| 8 | + async user_analysis(id, date) { | |
| 9 | + const sql = ` | |
| 10 | + select pj.*, user.name as manager_name from ( | |
| 11 | + select a.*,b.p_value, b.p_other_expenses,b.p_invoice from | |
| 12 | + ( | |
| 13 | + select | |
| 14 | + project.number, project.name, project.manager_id, project.create_time, contract.value as s_value, contract.other_expenses as s_other_expenses, contract.invoice as s_invoice | |
| 15 | + from project, contract where project.sale_contract_id = contract.id | |
| 16 | + ) a | |
| 17 | + left join | |
| 18 | + ( | |
| 19 | + select | |
| 20 | + project.number, project.name, project.manager_id, project.create_time, contract.value as p_value, contract.other_expenses as p_other_expenses, contract.invoice as p_invoice | |
| 21 | + from project, contract where project.purchase_contract_id = contract.id | |
| 22 | + ) b | |
| 23 | + on a.number = b.number | |
| 24 | + ) pj, user | |
| 25 | + where pj.manager_id = user.id | |
| 26 | + and pj.manager_id = ? | |
| 27 | + ${date !== undefined && date !== null ? ` and pj.create_time like '%${date}%'` : ''} | |
| 28 | + `; | |
| 29 | + const result = await this.app.mysql.query(sql, [ id ]); | |
| 30 | + return result; | |
| 31 | + } | |
| 8 | 32 | async analysis(date) { |
| 9 | 33 | // const sql = ` |
| 10 | 34 | // select |
| ... | ... | @@ -20,20 +44,23 @@ class ProjectService extends Service { |
| 20 | 44 | // where project.sale_contract_id = s_contract.id and project.purchase_contract_id = p_contract.id |
| 21 | 45 | // `; |
| 22 | 46 | const sql = ` |
| 23 | - select a.*,b.p_value, b.p_other_expenses,b.p_invoice from | |
| 24 | - ( | |
| 25 | - select | |
| 26 | - project.number, project.name, project.create_time, 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, project.create_time, 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 | - ${date !== undefined && date !== null ? ` where a.create_time like '%${date}%'` : ''} | |
| 47 | + select pj.*, user.name as manager_name from ( | |
| 48 | + select a.*,b.p_value, b.p_other_expenses,b.p_invoice from | |
| 49 | + ( | |
| 50 | + select | |
| 51 | + project.number, project.name, project.manager_id, project.create_time, contract.value as s_value, contract.other_expenses as s_other_expenses, contract.invoice as s_invoice | |
| 52 | + from project, contract where project.sale_contract_id = contract.id | |
| 53 | + ) a | |
| 54 | + left join | |
| 55 | + ( | |
| 56 | + select | |
| 57 | + project.number, project.name, project.manager_id, project.create_time, contract.value as p_value, contract.other_expenses as p_other_expenses, contract.invoice as p_invoice | |
| 58 | + from project, contract where project.purchase_contract_id = contract.id | |
| 59 | + ) b | |
| 60 | + on a.number = b.number | |
| 61 | + ) pj, user | |
| 62 | + where pj.manager_id = user.id | |
| 63 | + ${date !== undefined && date !== null ? ` and pj.create_time like '%${date}%'` : ''} | |
| 37 | 64 | `; |
| 38 | 65 | const result = await this.app.mysql.query(sql); |
| 39 | 66 | return result; | ... | ... |