PersonnelServiceImpl.java
11.8 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package com.objecteye.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.objecteye.entity.*;
import com.objecteye.mapper.SyFeatureMapper;
import com.objecteye.mapper.SyPersonnelMapper;
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;
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
private SyPersonnelMapper personnelMapper;
@Autowired
private SyFeatureMapper syFeatureMapper;
@Autowired
private FeatureService featureService;
@Autowired
private VehicleEngine vehicleEngine;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private DeployService deployService;
@Value("${picture.url}")
private String picIpAndPort;
@Value("${addUrlToDeployDb}")
private String addUrlToDeployDb;
/**
* 查询全部
*/
@Override
public List<SyPersonnel> findAll() {
SyPersonnelExample example = new SyPersonnelExample();
SyPersonnelExample.Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo(0);
return personnelMapper.selectByExample(example);
}
/**
* 按分页查询
*/
@Override
public PageResult findPage(int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
SyPersonnelExample example = new SyPersonnelExample();
SyPersonnelExample.Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo(0);
Page<SyPersonnel> page = (Page<SyPersonnel>) personnelMapper.selectByExample(example);
return new PageResult(page.getPages(), page.getResult());
}
/**
* 增加
*/
@Override
public int add(SyPersonnel personnel) {
String now = DateUtil.now();
personnel.setCreateDate(now);
personnel.setUpdateDate(now);
personnel.setStatus(0);
personnel.setConreason(null);
return personnelMapper.insert(personnel);
}
/**
* 修改
*/
@Override
public void update(SyPersonnel personnel) {
String now = DateUtil.now();
personnel.setStatus(0);
personnel.setUpdateDate(now);
personnelMapper.updateByPrimaryKey(personnel);
}
/**
* 根据ID获取实体
*
* @param id
* @return
*/
@Override
public SyPersonnel findOne(int id) {
return personnelMapper.selectByPrimaryKey(id);
}
/**
* 批量删除
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(int[] ids) {
for (int id : ids) {
SyPersonnel syPersonnel = personnelMapper.selectByPrimaryKey(id);
syPersonnel.setStatus(1);
personnelMapper.updateByPrimaryKey(syPersonnel);
Integer fid = syPersonnel.getFid();
Integer personCountByFid = findPersonCountByFid(fid);
SyFeature syFeature = syFeatureMapper.selectByPrimaryKey(fid);
syFeature.setCount(personCountByFid);
syFeatureMapper.updateByPrimaryKeySelective(syFeature);
List<Integer> deployListByLibAndDeployType = deployService.getDeployListByLibAndDeployType(fid, 2);
if (deployListByLibAndDeployType != null && deployListByLibAndDeployType.size() > 0) {
for (int i = 0; i < deployListByLibAndDeployType.size(); i++) {
String key = deployListByLibAndDeployType.get(i) + "|" + fid;
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);
String s = vehicleEngine.deleteDataFromDeployDb(map);
System.out.println("删除");
}
}
@Override
public PageResult findPage(int fid, String name, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
ArrayList<PersonnelResultMsg> list = new ArrayList<>();
SyPersonnelExample example = new SyPersonnelExample();
SyPersonnelExample.Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo(0);
criteria.andFidEqualTo(fid);
/*if (name != null && name.length() > 0) {
criteria.andNameLike("%" + name + "%");
}*/
if (!name.equals("")) {
criteria.andNameLike("%" + name + "%");
}
SyPersonnelExample.Criteria criteria1 = example.createCriteria();
criteria1.andStatusEqualTo(0);
criteria1.andFidEqualTo(fid);
/*if (name != null && name.length() > 0) {
criteria1.andCreateDateLike("%" + name + "%");
}*/
if (!name.equals("")) {
criteria1.andCreateDateLike("%" + name + "%");
}
example.or(criteria1);
Page<SyPersonnel> page = (Page<SyPersonnel>) personnelMapper.selectByExample(example);
List<SyPersonnel> result = page.getResult();
int size = result.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
SyPersonnel syPersonnel = result.get(i);
Integer personnelId = syPersonnel.getId();
int alarmNum = 0;
PersonnelResultMsg personnelResultMsg = new PersonnelResultMsg(personnelId, syPersonnel.getName(), syPersonnel.getCreateDate(), syPersonnel.getConreason(), alarmNum, syPersonnel.getImageUrl(), syPersonnel.getIndentity());
list.add(personnelResultMsg);
}
}
return new PageResult<PersonnelResultMsg>(page.getPages(), list);
}
@Override
public PageResult findPageByNameOCard(SyPersonnel personnel, int pageNum, int pageSize) {
PageHelper.startPage(pageNum, pageSize);
ArrayList<PersonnelResultMsg> list = new ArrayList<>();
SyPersonnelExample example = new SyPersonnelExample();
SyPersonnelExample.Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo(0);
String name = personnel.getName();
if (name != null && name.length() > 0) {
criteria.andNameLike("%" + name + "%");
}
String indentity = personnel.getIndentity();
if (indentity != null && indentity.length() > 0) {
criteria.andIndentityLike("%" + indentity + "%");
}
Page<SyPersonnel> page = (Page<SyPersonnel>) personnelMapper.selectByExample(example);
return new PageResult(page.getPages(), page.getResult());
}
@Override
public List<Map<String, Object>> findByImage(float similarity, MultipartFile file, int featureId) {
return null;
}
@Override
public Integer findPersonCountByFid(int fid) {
SyPersonnelExample syPersonnelExample = new SyPersonnelExample();
SyPersonnelExample.Criteria criteria = syPersonnelExample.createCriteria();
criteria.andStatusEqualTo(0);
criteria.andFidEqualTo(fid);
int count = personnelMapper.countByExample(syPersonnelExample);
return count;
}
@Override
public List<SyPersonnel> findPersonIdByFid(int fid) {
SyPersonnelExample syPersonnelExample = new SyPersonnelExample();
SyPersonnelExample.Criteria criteria = syPersonnelExample.createCriteria();
criteria.andStatusEqualTo(0);
criteria.andFidEqualTo(fid);
return personnelMapper.selectByExample(syPersonnelExample);
}
/**
* 上传人像到人像库
*
* @param uploadFiles
* @param featureId
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public String uploadFiles(MultipartFile[] uploadFiles, int featureId) {
int count = 0;
SyFeature one = featureService.findOne(featureId);
System.out.println(one.getCreateDate());
List<Integer> deployListByLibAndDeployType = deployService.getDeployListByLibAndDeployType(featureId, 2);
if (uploadFiles.length > 0 && one != null) {
int len = uploadFiles.length;
for (int i = 0; i < len; i++) {
MultipartFile multipartFile = uploadFiles[i];
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);
int add = add(syPersonnel);
Integer personnelId = syPersonnel.getId();
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);
if (deployListByLibAndDeployType.size() > 0) {
for (int j = 0; j < deployListByLibAndDeployType.size(); j++) {
Integer deployId = deployListByLibAndDeployType.get(j);
String key1 = deployId + "|" + featureId;
redisTemplate.opsForHash().put(key1, personnelId, 0);
}
}
redisTemplate.opsForHash().put("personUrl", personnelId, imageUrl);
System.out.println("请求返回:" + s);
String code = JSONObject.parseObject(s).getString("code");
//ResponseParam responseParam = JSON.parseObject(s, ResponseParam.class);
//String code = responseParam.getCode();
if ("0".equals(code)) {
if (add > 0) {
count++;
}
}
}
Integer count1 = one.getCount();
one.setCount(count + count1);
featureService.updateCountById(one);
return "上传的文件共有" + len + ",成功上传的个数为: " + count;
}
return null;
}
}