CompanyInvestigationController.java
12.4 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package com.project.demo.web;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.demo.domain.*;
import com.project.demo.mapper.AjaxJson;
import com.project.demo.service.InvestigateService;
import com.project.demo.service.InvestigateUserService;
import com.project.demo.service.TrackingRecordService;
import com.project.demo.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by bert on 2018/7/5.
*/
@Controller
@RequestMapping("investigate")
public class CompanyInvestigationController {
@Autowired
private InvestigateService investigateService;
@Autowired
private TrackingRecordService trackingRecordService;
@Autowired
private UsersService usersService;
@Autowired
private InvestigateUserService investigateUserService;
@RequestMapping(method = RequestMethod.GET)
public String findAll() {
return "/investigate/index";
}
@RequestMapping(value = "/investigateList",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String investigateList(final HttpSession session, final HttpServletRequest request){
Users currentUser = (Users) session.getAttribute("users");
final Map<String,Object> params = new HashMap<>();
DataTablePageUtil<Investigate> dataTable = new DataTablePageUtil<Investigate>(request);
PageHelper.startPage(dataTable.getPage_num(), dataTable.getPage_size());//分页
List<Investigate> investigates = investigateService.search();
PageInfo<Investigate> pageInfo = new PageInfo<>(investigates);
//封装数据给DataTables
dataTable.setDraw(dataTable.getDraw());
dataTable.setData(pageInfo.getList());
dataTable.setRecordsTotal((int)pageInfo.getTotal());
dataTable.setRecordsFiltered(dataTable.getRecordsTotal());
//返回数据到页面
String jsonObject = JSONObject.toJSONString(dataTable);
return jsonObject;
}
@RequestMapping(value = "/create")
public String create() {
return "/investigate/new";
}
// id companyName name job mobile personnelMatters finance information marketing administration customerManager managerMobile managerEmail
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String save(final HttpSession session, @RequestParam String companyName,@RequestParam String name,
@RequestParam String job,@RequestParam String mobile,@RequestParam String personnelMatters,
@RequestParam String finance, @RequestParam String information, @RequestParam String marketing,
@RequestParam String administration){
Users users = (Users)session.getAttribute("users");
Investigate investigate = new Investigate();
investigate.setCompanyName(companyName);
investigate.setName(name);
investigate.setJob(job);
investigate.setMobile(mobile);
investigate.setPersonnelMatters(personnelMatters);
investigate.setFinance(finance);
investigate.setInformation(information);
investigate.setMarketing(marketing);
investigate.setAdministration(administration);
investigate.setCustomerManager(users.getName());
investigate.setManagerMobile(users.getMobile());
// investigate.setManagerEmail(managerEmail);
investigate.setUserId(users.getId());
investigateService.save(investigate);
return "redirect:/investigate";
}
@RequestMapping(value = "/isExist",method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public Result isExist(Model model, @RequestParam String mobile){
Result result = new Result();
result.setMessage("<font color='green'>添加成功</font>");
result.setSuccess(true);
return result;
}
@RequestMapping(value = "/{companyId}/details", method = RequestMethod.GET)
public String showDetails(final HttpSession session, @PathVariable Integer companyId, Model model)
{
//通过companyId查询相关信息
Investigate investigate = investigateService.searchDetails(companyId);
model.addAttribute("customerManager", investigate.getCustomerManager());
model.addAttribute("managerMobile", investigate.getManagerMobile());
model.addAttribute("mobile", investigate.getMobile());
model.addAttribute("personnelMatters", investigate.getPersonnelMatters());//人事
model.addAttribute("finance", investigate.getFinance());
model.addAttribute("information", investigate.getInformation());
model.addAttribute("marking", investigate.getMarketing());
model.addAttribute("administration", investigate.getAdministration());
model.addAttribute("thisInvestigate", investigate);
model.addAttribute("name", investigate.getName());
final Map<String,Object> params = new HashMap<>();
params.put("comInvestigationId", companyId);
final Map<String,Object> params2 = new HashMap<>();
params2.put("comInvestigationId",companyId);
List<InvestigateUser> investigateUserList = investigateUserService.search(params);
investigateUserList.stream().forEach(d ->{
Users users = usersService.findById(d.getUsersId());
d.setName(users.getName());
d.setMobile(users.getMobile());
});
List<String> investigateUserListForShow = new ArrayList<>();
for (int i=0;i<investigateUserList.size();i++){
investigateUserListForShow.add(investigateUserList.get(i).getName());
investigateUserListForShow.add(investigateUserList.get(i).getMobile());
}
if (investigateUserListForShow.toString().contains("[")){
String listString = investigateUserListForShow.toString().replace("[","");
String listForShow = listString.replace("]","");
model.addAttribute("investigateUserList", listForShow);
}
return "/investigate/details";
}
//跟踪记录显示
@RequestMapping(value = "/projectContent",method = RequestMethod.POST)
@ResponseBody
public Investigate projectContent(HttpSession session , @RequestParam Integer investigateId){
Users currentUser = (Users) session.getAttribute("users");
Investigate investigate = investigateService.searchDetails(investigateId);
// ProjectsValue projectsValue = projectsValueService.findByProjectsId(projects.getId());
// projects.setProjectsValue(projectsValue);
return investigate;
}
//创建跟踪记录
@RequestMapping(value = "/addTracks",method = RequestMethod.POST)
@ResponseBody
public AjaxJson addTracks(HttpSession session , @RequestParam Integer investigateId, @RequestParam String investigateTracks){
AjaxJson ajaxJson = new AjaxJson();
Users currentUser = (Users) session.getAttribute("users");
InvestigateTrackingRecord trackingRecord = new InvestigateTrackingRecord();
trackingRecord.setInvestigateId(investigateId);
trackingRecord.setUsersId(currentUser.getId());
trackingRecord.setContent(investigateTracks);
System.out.println("trackingRecord:"+ trackingRecord.toString());
trackingRecordService.insertForInvestigate(trackingRecord);
ajaxJson.setCode(0);
ajaxJson.setMsg("添加成功");
return ajaxJson;
}
//已关联人员删除
@RequestMapping(value = "/salesList",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String salesList(final HttpSession session, final HttpServletRequest request,@RequestParam Integer investigateId){
Users currentUser = (Users) session.getAttribute("users");
final Map<String,Object> params = new HashMap<>();
DataTablePageUtil<InvestigateUser> dataTable = new DataTablePageUtil<InvestigateUser>(request);
System.out.println(dataTable.getPage_num()+"||"+dataTable.getPage_size());
params.put("comInvestigationId",investigateId);
List<InvestigateUser> investigateUserList = investigateUserService.search(params);
System.out.println("investigateUserList.size:"+investigateUserList.size()); //2
investigateUserList.stream().forEach(d ->{
System.out.println("userId:" + d.getUsersId());
Users users = usersService.findById(d.getUsersId());
d.setName(users.getName());
d.setMobile(users.getMobile());
});
PageInfo<InvestigateUser> pageInfo = new PageInfo<>(investigateUserList, 2);
dataTable.setDraw(dataTable.getDraw());
dataTable.setData(pageInfo.getList());
dataTable.setRecordsTotal((int)pageInfo.getTotal());
dataTable.setRecordsFiltered(dataTable.getRecordsTotal());
String jsonObject = JSONObject.toJSONString(dataTable);
return jsonObject;
}
//usersList
@RequestMapping(value = "/usersList",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String usersList(final HttpSession session, final HttpServletRequest request,@RequestParam Integer investigateId){
Users currentUser = (Users) session.getAttribute("users");
final Map<String,Object> params = new HashMap<>();
//获取当前项目关联的人员和创建人员
Integer createManId= investigateService.findById(investigateId).getUserId(); //创建人
Users createUsers = usersService.findById(createManId);
//找到粗了创建人跟已关联的
params.put("comInvestigationId", investigateId);
List<InvestigateUser> investigateUserList = investigateUserService.search(params);
List<String> mobiles = new ArrayList<>();
for(int i =0;i<investigateUserList.size();i++){
mobiles.add(usersService.findById(investigateUserList.get(i).getUsersId()).getMobile());
}
mobiles.add(createUsers.getMobile());
params.put("mobiles",mobiles);
DataTablePageUtil<Users> dataTable = new DataTablePageUtil<Users>(request);
PageHelper.startPage(dataTable.getPage_num(),dataTable.getPage_size());
List<Users> usersList = usersService.search(params);
PageInfo<Users> pageInfo = new PageInfo<>(usersList, 2);
//封装数据给DataTables
dataTable.setDraw(dataTable.getDraw());
dataTable.setData(pageInfo.getList());
dataTable.setRecordsTotal((int)pageInfo.getTotal());
dataTable.setRecordsFiltered(dataTable.getRecordsTotal());
//返回数据到页面
String jsonObject = JSONObject.toJSONString(dataTable);
return jsonObject;
}
@RequestMapping(value = "/addSales",method = RequestMethod.POST)
@ResponseBody
public AjaxJson addSales(HttpSession session , @RequestParam Integer investigateId, @RequestParam String mobiles){
AjaxJson ajaxJson = new AjaxJson();
String[] mobilesArray = mobiles.split(",");
Users users ;
InvestigateUser investigateUser = new InvestigateUser();
for (int i = 0; i<mobilesArray.length; i++){
users = usersService.findByMobile(mobilesArray[i]);
investigateUser.setUsersId(users.getId());
investigateUser.setComInvestigationId(investigateId);
investigateUserService.insert(investigateUser);
}
ajaxJson.setCode(0);
ajaxJson.setMsg("添加成功");
return ajaxJson;
}
@RequestMapping(value = "/removeSales",method = RequestMethod.POST)
@ResponseBody
public AjaxJson removeSales(HttpSession session , @RequestParam Integer investigateId, @RequestParam String mobiles){
String[] mobilesArray = mobiles.split(",");
AjaxJson ajaxJson = new AjaxJson();
Users users = new Users();
for (int i = 0; i<mobilesArray.length; i++) {
users = usersService.findByMobile(mobilesArray[i]);
investigateUserService.delete(users.getId(),investigateId);
}
ajaxJson.setCode(0);
ajaxJson.setMsg("删除成功");
return ajaxJson;
}
}