|
1 | 1 | /** |
2 | 2 | * Created by chriscai on 2015/1/15. |
3 | 3 | */ |
4 | | - |
5 | | - |
6 | 4 | var BusinessService = require('../../service/BusinessService'), |
7 | 5 | _ = require('underscore'), |
8 | 6 | StatisticsService = require('../../service/StatisticsService'); |
9 | 7 |
|
10 | | -var log4js = require('log4js'), |
| 8 | +var log4js = require('log4js'), |
11 | 9 | logger = log4js.getLogger(); |
12 | 10 |
|
13 | 11 | var StatisticsAction = { |
14 | 12 |
|
15 | 13 |
|
16 | | - index : function(param, req, res){ |
| 14 | + index: function(param, req, res) { |
17 | 15 | var params = req.query, |
18 | | - user = req.session.user; |
| 16 | + user = req.session.user; |
19 | 17 |
|
20 | | - var businessService = new BusinessService(); |
| 18 | + var businessService = new BusinessService(); |
21 | 19 |
|
22 | | - businessService.findBusinessByUser(user.loginName , function (err, item){ |
23 | | - res.render(param.tpl, { layout: false, user: user, index:'statistics' , statisticsTitle:param.statisticsTitle, items : item}); |
| 20 | + businessService.findBusinessByUser(user.loginName, function(err, item) { |
| 21 | + res.render(param.tpl, { |
| 22 | + layout: false, |
| 23 | + user: user, |
| 24 | + index: 'statistics', |
| 25 | + statisticsTitle: param.statisticsTitle, |
| 26 | + items: item |
| 27 | + }); |
24 | 28 | }); |
25 | 29 | }, |
26 | | - projectTotal : function(param, req, res){ |
| 30 | + projectTotal: function(param, req, res) { |
27 | 31 | var params = req.query, |
28 | | - user = req.session.user; |
| 32 | + user = req.session.user; |
29 | 33 |
|
30 | | - var businessService = new BusinessService(); |
| 34 | + var businessService = new BusinessService(); |
31 | 35 |
|
32 | | - businessService.findBusiness(function(err, items){ |
33 | | - res.render(param.tpl, { layout: false, user: user, index:'projectTotal' , statisticsTitle:param.statisticsTitle, items : items}); |
| 36 | + businessService.findBusiness(function(err, items) { |
| 37 | + res.render(param.tpl, { |
| 38 | + layout: false, |
| 39 | + user: user, |
| 40 | + index: 'projectTotal', |
| 41 | + statisticsTitle: param.statisticsTitle, |
| 42 | + items: items |
| 43 | + }); |
34 | 44 | }); |
35 | 45 |
|
36 | 46 | }, |
37 | | - queryByChart : function (param, req, res) { |
38 | | - var statisticsService = new StatisticsService(); |
39 | | - if(!param.projectId || isNaN(param.projectId) || !param.timeScope){ |
40 | | - res.json({ret:0 , msg:'success' , data : {} }); |
41 | | - return ; |
| 47 | + queryByChart: function(param, req, res) { |
| 48 | + var statisticsService = new StatisticsService(); |
| 49 | + if (!param.projectId || isNaN(param.projectId) || !param.timeScope) { |
| 50 | + res.json({ |
| 51 | + ret: 0, |
| 52 | + msg: 'success', |
| 53 | + data: {} |
| 54 | + }); |
| 55 | + return; |
42 | 56 | } |
43 | | - statisticsService.queryByChart({userName : param.user.loginName , projectId : param.projectId-0 , timeScope:param.timeScope-0 } , function (err, data){ |
44 | | - if(err){ |
45 | | - res.json({ret:-1, msg:"error"}); |
| 57 | + statisticsService.queryByChart({ |
| 58 | + userName: param.user.loginName, |
| 59 | + projectId: param.projectId - 0, |
| 60 | + timeScope: param.timeScope - 0 |
| 61 | + }, function(err, data) { |
| 62 | + if (err) { |
| 63 | + res.json({ |
| 64 | + ret: -1, |
| 65 | + msg: "error" |
| 66 | + }); |
46 | 67 | return; |
47 | 68 | } |
48 | 69 | res.json(data); |
49 | 70 | }); |
50 | 71 | }, |
51 | | - queryByChartForAdmin : function (param, req, res) { |
52 | | - var statisticsService = new StatisticsService(); |
53 | | - if(!param.projectId || isNaN(param.projectId) || !param.timeScope || param.user.role !=1 ){ |
54 | | - res.json({ret:0 , msg:'success' , data : {} }); |
55 | | - return ; |
| 72 | + queryByChartForAdmin: function(param, req, res) { |
| 73 | + var statisticsService = new StatisticsService(); |
| 74 | + if (!param.projectId || isNaN(param.projectId) || !param.timeScope || param.user.role != 1) { |
| 75 | + res.json({ |
| 76 | + ret: 0, |
| 77 | + msg: 'success', |
| 78 | + data: {} |
| 79 | + }); |
| 80 | + return; |
56 | 81 | } |
57 | 82 |
|
58 | | - statisticsService.queryByChart({ projectId : param.projectId-0 , timeScope:param.timeScope-0} , function (err, data){ |
59 | | - if(err){ |
60 | | - res.json({ret:-1, msg:"error"}); |
| 83 | + statisticsService.queryByChart({ |
| 84 | + projectId: param.projectId - 0, |
| 85 | + timeScope: param.timeScope - 0 |
| 86 | + }, function(err, data) { |
| 87 | + if (err) { |
| 88 | + res.json({ |
| 89 | + ret: -1, |
| 90 | + msg: "error" |
| 91 | + }); |
61 | 92 | return; |
62 | 93 | } |
63 | 94 | res.json(data); |
64 | 95 | return; |
65 | 96 | }); |
66 | 97 | }, |
67 | | - queryById:function (param , req, res ){ |
68 | | - var statisticsService = new StatisticsService(); |
69 | | - if(!req.query.projectId || isNaN(req.query.projectId) || !req.query.startDate){ |
70 | | - res.json({ret:0 , msg:'success' , data : {} }); |
71 | | - return ; |
| 98 | + queryById: function(param, req, res) { |
| 99 | + var statisticsService = new StatisticsService(); |
| 100 | + if (!req.query.projectId || isNaN(req.query.projectId) || !req.query.startDate) { |
| 101 | + res.json({ |
| 102 | + ret: 0, |
| 103 | + msg: 'success', |
| 104 | + data: {} |
| 105 | + }); |
| 106 | + return; |
72 | 107 | } |
73 | | - statisticsService.queryById({userName : param.user.loginName , projectId : req.query.projectId-0 , startDate : new Date(param.startDate - 0 ) } , function (err, data){ |
74 | | - if(err){ |
75 | | - res.json({ret:-1 , msg:'error' , data : {} }); |
76 | | - }else { |
77 | | - res.json({ret:0 , msg:'success' , data : data }); |
| 108 | + statisticsService.queryById({ |
| 109 | + userName: param.user.loginName, |
| 110 | + projectId: req.query.projectId - 0, |
| 111 | + startDate: new Date(param.startDate - 0) |
| 112 | + }, function(err, data) { |
| 113 | + if (err) { |
| 114 | + res.json({ |
| 115 | + ret: -1, |
| 116 | + msg: 'error', |
| 117 | + data: {} |
| 118 | + }); |
| 119 | + } else { |
| 120 | + res.json({ |
| 121 | + ret: 0, |
| 122 | + msg: 'success', |
| 123 | + data: data |
| 124 | + }); |
78 | 125 | } |
79 | 126 |
|
80 | 127 | }); |
|
0 commit comments