HzInfoController.java
8.9 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package com.agent.controller.system;
import com.agent.entity.agent.HZSHIPPERINFORMATIONEntity;
import com.agent.service.system.HzInfoService;
import com.agent.util.HttpJsonMsg;
import com.agent.vo.ResponseModel;
import com.agent.vo.agent.HZSHIPPERINFORMATIONVo;
import com.framework.core.Servlets;
import com.framework.util.StringUtils;
import com.plugin.easyui.DataGrid;
import com.plugin.easyui.EasyPage;
import org.apache.commons.collections.CollectionUtils;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @Auther: shenhl
* @Date: 2019/4/17 09:55
*/
@RequestMapping(value = "/hzinfo")
@Controller
public class HzInfoController {
private static final Logger logger = LoggerFactory.getLogger(HzInfoController.class);
@Resource
private HzInfoService hzInfoService;
@RequestMapping(value = "/list")
public String list(){
return "system/user/hzinfo";
}
@RequestMapping(value = "/choosetHz")
public String selectHz(){
return "hz/hzinfo";
}
@RequestMapping(value = "/add")
public String add(){
return "system/user/hzinfo_add";
}
/**
* 分页查询
* @param request
* @param pageForm
* @return
*/
@RequestMapping(value = "/grid.json")
@ResponseBody
public DataGrid<HZSHIPPERINFORMATIONVo> grid(HttpServletRequest request, EasyPage<HZSHIPPERINFORMATIONEntity> pageForm) {
Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
// searchParams.put("LIKE_phone","17600319854");
pageForm.setSearchParams(searchParams);
pageForm.parseData(hzInfoService.getPage(pageForm));
DataGrid<HZSHIPPERINFORMATIONEntity> hzshipperinformationEntityDataGrid = pageForm.getData();
List<HZSHIPPERINFORMATIONVo>rows = new ArrayList<>();
if (CollectionUtils.isNotEmpty(hzshipperinformationEntityDataGrid.getRows())){
for (HZSHIPPERINFORMATIONEntity hz: hzshipperinformationEntityDataGrid.getRows()){
HZSHIPPERINFORMATIONVo hzvo = new HZSHIPPERINFORMATIONVo();
hzvo.setId(hz.getId());
hzvo.setForShort(hz.getFor_short());
hzvo.setFullName(hz.getFull_name());
hzvo.setContacts(hz.getContacts());
if ("1".equals(hz.getThe_shipper_type())){
hzvo.setTheShipperType("发货人");
}else if ("2".equals(hz.getThe_shipper_type())){
hzvo.setTheShipperType("订舱代理");
}else {
hzvo.setTheShipperType("操作代理");
}
hzvo.setPhone(hz.getPhone());
hzvo.setDeleteFlag(hz.getDelete_flag());
rows.add(hzvo);
}
}
DataGrid<HZSHIPPERINFORMATIONVo> vos = new DataGrid<>();
vos.setRows(rows);
vos.setTotal(hzshipperinformationEntityDataGrid.getTotal());
return vos;
}
/**
* 添加
* @param hz
* @param request
* @return
*/
@RequestMapping("/save")
@ResponseBody
public ResponseModel save(HZSHIPPERINFORMATIONEntity hz, HttpServletRequest request){
ResponseModel model = new ResponseModel();
//获取对象值
String forshort = request.getParameter("forshort");
String fullname = request.getParameter("fullname");
//发货人
String one = request.getParameter("one");
//订舱代理
String two = request.getParameter("two");
//操作代理
String three = request.getParameter("three");
String contacts = request.getParameter("contacts");
String phone = request.getParameter("phone");
List<String> list = new ArrayList<>();
if (!StringUtils.isBlank(one)){
list.add(one);
}
if (!StringUtils.isBlank(two)){
list.add(two);
}
if (!StringUtils.isBlank(three)){
list.add(three);
}
for (String type: list){
switch (type) {
case "1":
if (hzInfoService.forShortShipperType(forshort, "1") == 0) {
HZSHIPPERINFORMATIONEntity hzshipperinformationEntity = new HZSHIPPERINFORMATIONEntity();
hzshipperinformationEntity.setFor_short(forshort);
hzshipperinformationEntity.setFull_name(fullname);
hzshipperinformationEntity.setThe_shipper_type("1");
hzshipperinformationEntity.setContacts(contacts);
hzshipperinformationEntity.setPhone(phone);
hzshipperinformationEntity.setDelete_flag("1");
hzInfoService.save(hzshipperinformationEntity);
model.setStatus(200);
continue;
}else {
model.setStatus(201);
break;
}
case "2":
if (hzInfoService.forShortShipperType(forshort, "2") == 0) {
HZSHIPPERINFORMATIONEntity hzshipperinformationEntity = new HZSHIPPERINFORMATIONEntity();
hzshipperinformationEntity.setFor_short(forshort);
hzshipperinformationEntity.setFull_name(fullname);
hzshipperinformationEntity.setThe_shipper_type("2");
hzshipperinformationEntity.setContacts(contacts);
hzshipperinformationEntity.setPhone(phone);
hzshipperinformationEntity.setDelete_flag("1");
hzInfoService.save(hzshipperinformationEntity);
model.setStatus(200);
continue;
}else {
model.setStatus(201);
break;
}
case "3":
if (hzInfoService.forShortShipperType(forshort, "3") == 0) {
HZSHIPPERINFORMATIONEntity hzshipperinformationEntity = new HZSHIPPERINFORMATIONEntity();
hzshipperinformationEntity.setFor_short(forshort);
hzshipperinformationEntity.setFull_name(fullname);
hzshipperinformationEntity.setThe_shipper_type("3");
hzshipperinformationEntity.setContacts(contacts);
hzshipperinformationEntity.setPhone(phone);
hzshipperinformationEntity.setDelete_flag("1");
hzInfoService.save(hzshipperinformationEntity);
model.setStatus(200);
continue;
}else {
model.setStatus(201);
break;
}
}
}
return model;
}
/**
* 删除
*
* @param ids
* @return
*/
@RequestMapping(value = "/delete", method = { RequestMethod.POST })
@ResponseBody
public ResponseModel delete(String ids) {
ResponseModel model = new ResponseModel();
try {
hzInfoService.deletes(ids);
model.setStatus(200);
model.setMsg(HttpJsonMsg.SUCCESS);
} catch (Exception e) {
model.setStatus(500);
model.setMsg(HttpJsonMsg.ERROR);
logger.error("系统异常 >>", e);
}
return model;
}
@RequestMapping(value = {"/edit" }, method = {RequestMethod.GET })
public String edit(Long id, Model model) {
if (id != null) {
HZSHIPPERINFORMATIONEntity hz = hzInfoService.findOne(id);
model.addAttribute("entity", hz);
}
return "system/user/hzinfo_edit";
}
/**
* 修改
* @param hz
* @param request
* @return
*/
@RequestMapping(value = "/update")
@ResponseBody
public ResponseModel update(HZSHIPPERINFORMATIONEntity hz, HttpServletRequest request){
ResponseModel responseModel = new ResponseModel();
if (hzInfoService.forShortShipperType(hz.getFor_short(), hz.getThe_shipper_type())==0){
hz.setDelete_flag("1");
int update = hzInfoService.update(hz);
if (update>0){
responseModel.setStatus(200);
}else {
responseModel.setStatus(202);
}
}else {
responseModel.setStatus(201);
}
return responseModel;
}
}