Commit 5b2253e681005fa153baa740c90155f4451fafa5
1 parent
cd137547
Exists in
master
增加合同分析接口
Showing
3 changed files
with
27 additions
and
0 deletions
Show diff stats
app/controller/contract.js
| @@ -39,6 +39,22 @@ class ContractController extends Controller { | @@ -39,6 +39,22 @@ class ContractController extends Controller { | ||
| 39 | }; | 39 | }; |
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | + async analysis() { | ||
| 43 | + const ctx = this.ctx; | ||
| 44 | + const param = qs.parse(this.ctx.query); | ||
| 45 | + try { | ||
| 46 | + const result = await ctx.service.contract.analysis(param); | ||
| 47 | + this.ctx.body = { | ||
| 48 | + result, | ||
| 49 | + success: true, | ||
| 50 | + }; | ||
| 51 | + } catch (error) { | ||
| 52 | + this.ctx.body = { | ||
| 53 | + success: false, | ||
| 54 | + error, | ||
| 55 | + }; | ||
| 56 | + } | ||
| 57 | + } | ||
| 42 | async add() { | 58 | async add() { |
| 43 | const ctx = this.ctx; | 59 | const ctx = this.ctx; |
| 44 | const id = uuid.v4(); | 60 | const id = uuid.v4(); |
app/router.js
| @@ -27,6 +27,7 @@ module.exports = app => { | @@ -27,6 +27,7 @@ module.exports = app => { | ||
| 27 | router.put('/customer', controller.customer.update); | 27 | router.put('/customer', controller.customer.update); |
| 28 | router.post('/customer/delete', controller.customer.remove); | 28 | router.post('/customer/delete', controller.customer.remove); |
| 29 | // 合同管理 | 29 | // 合同管理 |
| 30 | + router.get('/contract/analysis', controller.contract.analysis); | ||
| 30 | router.get('/contract/list', controller.contract.list); | 31 | router.get('/contract/list', controller.contract.list); |
| 31 | router.get('/contract/:id', controller.contract.info); | 32 | router.get('/contract/:id', controller.contract.info); |
| 32 | router.post('/contract', controller.contract.add); | 33 | router.post('/contract', controller.contract.add); |
app/service/contract.js
| @@ -5,6 +5,16 @@ const objExclude = require('../util/common').objExclude; | @@ -5,6 +5,16 @@ const objExclude = require('../util/common').objExclude; | ||
| 5 | const objToQuery = require('../util/common').objToQuery; | 5 | const objToQuery = require('../util/common').objToQuery; |
| 6 | 6 | ||
| 7 | class ContractService extends Service { | 7 | class ContractService extends Service { |
| 8 | + async analysis(data) { | ||
| 9 | + const where = objToQuery(data); | ||
| 10 | + const sql = ` | ||
| 11 | + select * from contract | ||
| 12 | + ${where !== '' ? `where ${where}` : ''} | ||
| 13 | + `; | ||
| 14 | + console.log(sql); | ||
| 15 | + const result = await this.app.mysql.query(sql); | ||
| 16 | + return result; | ||
| 17 | + } | ||
| 8 | async count() { | 18 | async count() { |
| 9 | const result = await this.app.mysql.query('select count(*) as total from contract'); | 19 | const result = await this.app.mysql.query('select count(*) as total from contract'); |
| 10 | return result; | 20 | return result; |