KPIJsonController.java
7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.tianbo.controller.json;
import com.tianbo.common.ModelAndPage;
import com.tianbo.controller.base.BaseController;
import com.tianbo.model.TKpiCargoWaybill;
import com.tianbo.model.TKpiCargoWaybillExample;
import com.tianbo.model.TKpiCargoWaybillExample.Criteria;
import com.tianbo.service.KPICargoBillServcie;
import com.tianbo.util.dao.Page;
import com.tianbo.util.dao.Totals;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
@Controller
@RequestMapping("/kpi")
public class KPIJsonController extends BaseController{
@Autowired
KPICargoBillServcie kpiService;
/**
* 查找所用用户控制器方法
* @return
* @throws Exception
*/
@RequestMapping(value = "list.json",method = RequestMethod.POST)
@RequiresRoles("admin")
@ResponseBody
public ModelAndPage kpiList(@ModelAttribute Page frontPage, @ModelAttribute TKpiCargoWaybill kpi) throws Exception{
if(frontPage.getBegin()>=0){
defaultDataStart = frontPage.getBegin();
}
if (frontPage.getLength()>0){
defaultPerPage = frontPage.getLength();
}
//example
//调用mapper类中的selectByExample方法,如果传入类型为null,则表示无条件查找
TKpiCargoWaybillExample example = new TKpiCargoWaybillExample();
Criteria criteria = example.createCriteria();
Criteria criteria2= example.createCriteria();
Criteria criteria3= example.createCriteria();
Criteria criteria4= example.createCriteria();
//根据国内国际搜索
if (checkPropertyNull(kpi.getDomint())){
criteria.andDomintEqualTo(kpi.getDomint());
criteria2.andDomintEqualTo(kpi.getDomint());
criteria3.andDomintEqualTo(kpi.getDomint());
criteria4.andDomintEqualTo(kpi.getDomint());
}
//根据运单前缀,前缀有主单的情况是三位前缀,分单的情况是主单号
if(checkPropertyNull(kpi.getWaybillpre())){
criteria.andWaybillpreEqualTo(kpi.getWaybillpre());
criteria2.andWaybillpreEqualTo(kpi.getWaybillpre());
criteria3.andWaybillpreEqualTo(kpi.getWaybillpre());
criteria4.andWaybillpreEqualTo(kpi.getWaybillpre());
}
//根据运单类型
if(checkPropertyNull(kpi.getWaybilltype())){
criteria.andWaybilltypeEqualTo(kpi.getWaybilltype());
criteria2.andWaybilltypeEqualTo(kpi.getWaybilltype());
criteria3.andWaybilltypeEqualTo(kpi.getWaybilltype());
criteria4.andWaybilltypeEqualTo(kpi.getWaybilltype());
}
//根据代理人id
if(checkPropertyNull(kpi.getAgentid())){
criteria.andAgentidEqualTo(kpi.getAgentid());
criteria2.andAgentidEqualTo(kpi.getAgentid());
criteria3.andAgentidEqualTo(kpi.getAgentid());
criteria4.andAgentidEqualTo(kpi.getAgentid());
}
//根据货主
if(checkPropertyNull(kpi.getShprname())){
criteria.andShprnameEqualTo(kpi.getShprname());
criteria2.andAgentidEqualTo(kpi.getAgentid());
criteria3.andAgentidEqualTo(kpi.getAgentid());
criteria4.andAgentidEqualTo(kpi.getAgentid());
}
//根据货物id
if(checkPropertyNull(kpi.getProductid())){
criteria.andProductidEqualTo(kpi.getProductid());
criteria2.andAgentidEqualTo(kpi.getAgentid());
criteria3.andAgentidEqualTo(kpi.getAgentid());
criteria4.andAgentidEqualTo(kpi.getAgentid());
}
//根据货物名称
if(checkPropertyNull(kpi.getProductname())){
criteria.andProductnameEqualTo(kpi.getProductname());
criteria2.andProductnameEqualTo(kpi.getProductname());
criteria3.andProductnameEqualTo(kpi.getProductname());
criteria4.andProductnameEqualTo(kpi.getProductname());
}
//根据进口
if(checkPropertyNull(kpi.getImp())){
criteria.andImpEqualTo(kpi.getImp());
criteria2.andImpEqualTo(kpi.getImp());
criteria3.andImpEqualTo(kpi.getImp());
criteria4.andImpEqualTo(kpi.getImp());
}
//根据出口
if(checkPropertyNull(kpi.getExp())){
criteria.andExpEqualTo(kpi.getExp());
criteria2.andExpEqualTo(kpi.getExp());
criteria3.andExpEqualTo(kpi.getExp());
criteria4.andExpEqualTo(kpi.getExp());
}
//根据时间段-年
if(kpi.getCuryear()!=null&&kpi.getEndyear()!=null){
criteria.andCuryearBetween(kpi.getCuryear(),kpi.getEndyear());
criteria2.andCuryearBetween(kpi.getCuryear(),kpi.getEndyear());
criteria3.andCuryearBetween(kpi.getCuryear(),kpi.getEndyear());
criteria4.andCuryearBetween(kpi.getCuryear(),kpi.getEndyear());
}
//根据时间段-月
if(kpi.getCurmonth()!=null&&kpi.getEndmonth()!=null){
criteria.andCurmonthBetween(kpi.getCurmonth(),kpi.getEndmonth());
criteria2.andCurmonthBetween(kpi.getCurmonth(),kpi.getEndmonth());
criteria3.andCurmonthBetween(kpi.getCurmonth(),kpi.getEndmonth());
criteria4.andCurmonthBetween(kpi.getCurmonth(),kpi.getEndmonth());
}
//根据时间段-日
if(kpi.getCurweek()!=null&&kpi.getEndweek()!=null){
criteria.andCurweekBetween(kpi.getCurweek(),kpi.getEndweek());
criteria2.andCurweekBetween(kpi.getCurweek(),kpi.getEndweek());
criteria3.andCurweekBetween(kpi.getCurweek(),kpi.getEndweek());
criteria4.andCurweekBetween(kpi.getCurweek(),kpi.getEndweek());
}
//根据承运人搜索
if (checkPropertyNull(kpi.getAirline1())){
String carrier = kpi.getAirline1();
criteria.andAirline1EqualTo(carrier);
criteria2.andAirline2EqualTo(carrier);
criteria3.andAirline3EqualTo(carrier);
criteria4.andAirline4EqualTo(carrier);
example.or(criteria2);
example.or(criteria3);
example.or(criteria4);
}
//example.setOrderByClause("user_id"); //设置order 字段
//没加入分页前的搜索总数据数
int count = kpiService.countByExample(example);
BigDecimal weight = kpiService.sumWeightByExample(example);
BigDecimal pcs= kpiService.sumPcsByExample(example);
BigDecimal vol= kpiService.sumVolByExample(example);
BigDecimal hbillqty= kpiService.sumHbillqtyByExample(example);
Totals totals = new Totals(weight,pcs,vol,hbillqty);
Page page = new Page(defaultDataStart,defaultPerPage);
page.setCount(count);
example.setPage(page); //oracle 用这个
List<TKpiCargoWaybill> kpilist = kpiService.selectByExample(example);
ModelAndPage<TKpiCargoWaybill> modelAndPage = new ModelAndPage(kpilist,page,totals);
return modelAndPage;
}
}