c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
1
2
3
4
5
|
package com.objecteye.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
6
7
8
9
|
import com.objecteye.entity.PageResult;
import com.objecteye.entity.PersonnelResultMsg;
import com.objecteye.entity.SyFeature;
import com.objecteye.entity.SyPersonnel;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
10
11
12
13
14
15
16
|
import com.objecteye.service.DeployService;
import com.objecteye.service.FeatureService;
import com.objecteye.service.PersonnelService;
import com.objecteye.utils.GlobalUtil;
import com.objecteye.utils.VehicleEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
17
18
19
|
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
|
68a67f36
Liu Haoyu
接口问题处理;
|
20
|
import org.springframework.data.mongodb.core.query.Update;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
21
22
|
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 服务实现层
*
* @author Administrator
*/
@Service
public class PersonnelServiceImpl implements PersonnelService {
@Autowired
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
43
44
45
46
47
48
49
|
private FeatureService featureService;
@Autowired
private VehicleEngine vehicleEngine;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private DeployService deployService;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
50
51
|
@Autowired
private MongoTemplate mongoTemplate;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
52
53
54
55
56
57
58
59
60
61
62
63
64
|
@Value("${picture.url}")
private String picIpAndPort;
@Value("${addUrlToDeployDb}")
private String addUrlToDeployDb;
/**
* 查询全部
*/
@Override
public List<SyPersonnel> findAll() {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
65
|
return mongoTemplate.find(Query.query(Criteria.where("status").is(0)), SyPersonnel.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
66
67
68
69
70
71
72
73
|
}
/**
* 按分页查询
*/
@Override
public PageResult findPage(int pageNum, int pageSize) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
74
75
76
77
|
List<SyPersonnel> syPersonnels = mongoTemplate
.find(Query.query(Criteria.where("status").is(0)).limit(pageSize).skip((pageNum - 1) * pageSize), SyPersonnel.class);
long count = mongoTemplate.count(Query.query(Criteria.where("status").is(0)), SyPersonnel.class);
return new PageResult<>((long) Math.ceil((double) count / pageSize), syPersonnels);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
78
79
80
81
82
|
}
/**
* 增加
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
83
84
|
*
* @return
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
85
86
87
|
*/
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
88
|
public String add(SyPersonnel personnel) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
89
90
91
92
93
|
String now = DateUtil.now();
personnel.setCreateDate(now);
personnel.setUpdateDate(now);
personnel.setStatus(0);
personnel.setConreason(null);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
94
95
|
personnel = mongoTemplate.insert(personnel);
return personnel.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
96
97
98
99
100
101
102
103
104
105
106
107
|
}
/**
* 修改
*/
@Override
public void update(SyPersonnel personnel) {
String now = DateUtil.now();
personnel.setStatus(0);
personnel.setUpdateDate(now);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
108
|
mongoTemplate.save(personnel);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
109
110
111
112
113
114
115
116
117
118
119
|
}
/**
* 根据ID获取实体
*
* @param id
* @return
*/
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
120
121
|
public SyPersonnel findOne(String id) {
return mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), SyPersonnel.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
122
123
124
125
126
|
}
/**
* 批量删除
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
127
128
|
*
* @param ids
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
129
130
131
|
*/
@Override
|
68a67f36
Liu Haoyu
接口问题处理;
|
132
|
public void delete(List<String> ids) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
133
134
|
for (String id : ids) {
SyPersonnel syPersonnel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), SyPersonnel.class);
|
68a67f36
Liu Haoyu
接口问题处理;
|
135
136
137
138
|
if (syPersonnel == null) {
continue;
}
mongoTemplate.updateMulti(Query.query(Criteria.where("id").is(id)), Update.update("status", 1), SyPersonnel.class);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
139
|
String fid = syPersonnel.getFid();
|
68a67f36
Liu Haoyu
接口问题处理;
|
140
141
|
int personCountByFid = (int) findPersonCountByFid(fid);
mongoTemplate.updateMulti(Query.query(Criteria.where("id").is(fid)), Update.update("count", personCountByFid), SyFeature.class);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
142
|
List<String> deployListByLibAndDeployType = deployService.getDeployListByLibAndDeployType(fid, 2);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
143
|
if (deployListByLibAndDeployType != null && deployListByLibAndDeployType.size() > 0) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
144
145
|
for (String s : deployListByLibAndDeployType) {
String key = s + "|" + fid;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
146
147
148
149
150
151
152
153
154
155
|
if (redisTemplate.opsForHash().hasKey(key, id)) {
redisTemplate.opsForHash().delete(key, id);
}
}
}
String imageUrl = syPersonnel.getImageUrl();
String key = id + "&" + fid + "&" + imageUrl;
HashMap<String, Object> map = new HashMap<>();
map.put("retrieveKey", key);
redisTemplate.opsForHash().delete("personUrl", id);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
156
|
vehicleEngine.deleteDataFromDeployDb(map);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
157
158
159
160
161
162
|
}
}
@Override
public PageResult findPage(int fid, String name, int pageNum, int pageSize) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
163
|
ArrayList<PersonnelResultMsg> list = new ArrayList<>();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
164
|
Criteria criteria = Criteria.where("status").is(0).and("fid").is(fid);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
165
|
if (!name.equals("")) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
166
|
criteria.and("name").regex(".*" + name + ".*");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
167
|
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
168
|
Criteria criteria1 = Criteria.where("status").is(0).and("fid").is(fid);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
169
|
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
170
|
if (!name.equals("")) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
171
|
criteria1.and("createDate").regex(".*" + name + ".*");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
172
|
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
173
|
criteria.orOperator(criteria1);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
174
|
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
175
176
|
List<SyPersonnel> result = mongoTemplate.find(Query.query(criteria).skip((pageNum - 1) * pageSize).limit(pageSize), SyPersonnel.class);
long count = mongoTemplate.count(Query.query(criteria), SyPersonnel.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
177
178
|
int size = result.size();
if (size > 0) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
179
180
|
for (SyPersonnel syPersonnel : result) {
String personnelId = syPersonnel.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
181
182
183
184
185
186
|
int alarmNum = 0;
PersonnelResultMsg personnelResultMsg = new PersonnelResultMsg(personnelId, syPersonnel.getName(), syPersonnel.getCreateDate(), syPersonnel.getConreason(), alarmNum, syPersonnel.getImageUrl(), syPersonnel.getIndentity());
list.add(personnelResultMsg);
}
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
187
|
return new PageResult<>((long) Math.ceil((double) count / pageSize), list);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
188
189
190
|
}
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
191
192
|
public long findPersonCountByFid(String fid) {
return mongoTemplate.count(Query.query(Criteria.where("status").is(0).and("fid").is(fid)), SyPersonnel.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
193
194
195
196
|
}
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
197
198
|
public List<SyPersonnel> findPersonIdByFid(String fid) {
return mongoTemplate.find(Query.query(Criteria.where("status").is(0).and("fid").is(fid)), SyPersonnel.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
199
200
201
202
203
204
205
206
207
208
|
}
/**
* 上传人像到人像库
*
* @param uploadFiles
* @param featureId
* @return
*/
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
209
|
public String uploadFiles(MultipartFile[] uploadFiles, String featureId) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
210
211
212
|
int count = 0;
SyFeature one = featureService.findOne(featureId);
System.out.println(one.getCreateDate());
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
213
|
List<String> deployListByLibAndDeployType = deployService.getDeployListByLibAndDeployType(featureId, 2);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
214
|
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
215
|
if (uploadFiles.length > 0) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
216
|
int len = uploadFiles.length;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
217
|
for (MultipartFile multipartFile : uploadFiles) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
String fileName = multipartFile.getOriginalFilename();
System.out.println(fileName);
fileName = fileName.replaceAll("\\\\", "/");
String personName = fileName.split("\\_")[0];
if (personName.contains("/")) {
String[] personNameArray = personName.split("/");
personName = personNameArray[personNameArray.length - 1];
}
String personIndentity = fileName.split("\\_")[1].split("\\.")[0];
String picPath = GlobalUtil.dbPath1() + File.separator + "picture" + File.separator + fileName;
String imageUrl = picIpAndPort + fileName;
File newFile = new File(picPath);
try {
multipartFile.transferTo(newFile);
} catch (IOException e) {
e.printStackTrace();
}
SyPersonnel syPersonnel = new SyPersonnel();
syPersonnel.setName(personName);
syPersonnel.setIndentity(personIndentity);
syPersonnel.setImageUrl(imageUrl);
syPersonnel.setFid(featureId);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
240
241
|
String addId = add(syPersonnel);
String personnelId = syPersonnel.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
242
243
244
245
246
|
String key = personnelId + "&" + featureId + "&" + imageUrl;
Map<String, Object> map = new HashMap<>(16);
map.put("TPXX", imageUrl);
map.put("retrieveKey", key);
String s = vehicleEngine.addUrlToDeployDb(map);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
247
248
249
|
for (String deployId : deployListByLibAndDeployType) {
String key1 = deployId + "|" + featureId;
redisTemplate.opsForHash().put(key1, personnelId, 0);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
250
251
|
}
redisTemplate.opsForHash().put("personUrl", personnelId, imageUrl);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
252
|
String code = JSONObject.parseObject(s).getString("code");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
253
|
if ("0".equals(code)) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
254
|
if (addId != null) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
255
256
257
258
259
260
261
262
263
264
265
266
|
count++;
}
}
}
Integer count1 = one.getCount();
one.setCount(count + count1);
featureService.updateCountById(one);
return "上传的文件共有" + len + ",成功上传的个数为: " + count;
}
return null;
}
}
|