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;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
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
132
|
*/
@Override
@Transactional(rollbackFor = Exception.class)
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
133
134
135
|
public void delete(String[] ids) {
for (String id : ids) {
SyPersonnel syPersonnel = mongoTemplate.findOne(Query.query(Criteria.where("id").is(id)), SyPersonnel.class);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
136
|
syPersonnel.setStatus(1);
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
137
138
139
140
141
142
143
|
mongoTemplate.save(syPersonnel);
String fid = syPersonnel.getFid();
long personCountByFid = findPersonCountByFid(fid);
SyFeature syFeature = mongoTemplate.findOne(Query.query(Criteria.where("id").is(fid)), SyFeature.class);
syFeature.setCount((int) personCountByFid);
mongoTemplate.save(syFeature);
List<String> deployListByLibAndDeployType = deployService.getDeployListByLibAndDeployType(fid, 2);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
144
|
if (deployListByLibAndDeployType != null && deployListByLibAndDeployType.size() > 0) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
145
146
|
for (String s : deployListByLibAndDeployType) {
String key = s + "|" + fid;
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
147
148
149
150
151
152
153
154
155
156
|
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...
|
157
|
vehicleEngine.deleteDataFromDeployDb(map);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
158
159
160
161
162
163
|
}
}
@Override
public PageResult findPage(int fid, String name, int pageNum, int pageSize) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
164
|
ArrayList<PersonnelResultMsg> list = new ArrayList<>();
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
165
|
Criteria criteria = Criteria.where("status").is(0).and("fid").is(fid);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
166
|
if (!name.equals("")) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
167
|
criteria.and("name").regex(".*" + name + ".*");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
168
|
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
169
|
Criteria criteria1 = Criteria.where("status").is(0).and("fid").is(fid);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
170
|
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
171
|
if (!name.equals("")) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
172
|
criteria1.and("createDate").regex(".*" + name + ".*");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
173
|
}
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
174
|
criteria.orOperator(criteria1);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
175
|
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
176
177
|
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...
|
178
179
|
int size = result.size();
if (size > 0) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
180
181
|
for (SyPersonnel syPersonnel : result) {
String personnelId = syPersonnel.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
182
183
184
185
186
187
|
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...
|
188
|
return new PageResult<>((long) Math.ceil((double) count / pageSize), list);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
189
190
191
|
}
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
192
193
|
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...
|
194
195
196
197
|
}
@Override
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
198
199
|
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...
|
200
201
202
203
204
205
206
207
208
209
210
|
}
/**
* 上传人像到人像库
*
* @param uploadFiles
* @param featureId
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
211
|
public String uploadFiles(MultipartFile[] uploadFiles, String featureId) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
212
213
214
|
int count = 0;
SyFeature one = featureService.findOne(featureId);
System.out.println(one.getCreateDate());
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
215
|
List<String> deployListByLibAndDeployType = deployService.getDeployListByLibAndDeployType(featureId, 2);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
216
|
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
217
|
if (uploadFiles.length > 0) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
218
|
int len = uploadFiles.length;
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
219
|
for (MultipartFile multipartFile : uploadFiles) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
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...
|
242
243
|
String addId = add(syPersonnel);
String personnelId = syPersonnel.getId();
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
244
245
246
247
248
|
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...
|
249
250
251
|
for (String deployId : deployListByLibAndDeployType) {
String key1 = deployId + "|" + featureId;
redisTemplate.opsForHash().put(key1, personnelId, 0);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
252
253
|
}
redisTemplate.opsForHash().put("personUrl", personnelId, imageUrl);
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
254
|
String code = JSONObject.parseObject(s).getString("code");
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
255
|
if ("0".equals(code)) {
|
40c853a1
Liu Haoyu
去掉MySQL相关内容, 去掉my...
|
256
|
if (addId != null) {
|
c83b5b39
Liu Haoyu
项目创建, 集成spring-se...
|
257
258
259
260
261
262
263
264
265
266
267
268
|
count++;
}
}
}
Integer count1 = one.getCount();
one.setCount(count + count1);
featureService.updateCountById(one);
return "上传的文件共有" + len + ",成功上传的个数为: " + count;
}
return null;
}
}
|