FileControl.java
5.55 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
package com.sincere.haikangface.control;
import com.alibaba.fastjson.JSON;
import com.sincere.haikangface.CMSServer;
import com.sincere.haikangface.async.SendUserAsync;
import com.sincere.haikangface.bean.StudentBean;
import com.sincere.haikangface.bean.face.PermissionBean;
import com.sincere.haikangface.dao.UserDao;
import com.sincere.haikangface.service.impl.BaseService;
import com.sincere.haikangface.utils.CompressPic;
import com.sincere.haikangface.utils.FileUtils;
import com.sincere.haikangface.xiananDao.SendRecordDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
@RestController
@Api("文件管理器")
@RequestMapping("file/*")
@Slf4j
public class FileControl {
@Autowired
SendUserAsync sendUserAsync;
@Autowired
SendRecordDao sendRecordDao;
@Autowired
UserDao userDao;
@Autowired
CMSServer cmsServer;
@Autowired
BaseService baseService;
@RequestMapping(value = "sendPermiss", method = RequestMethod.POST)
@ApiOperation("下发权限给设备")
public boolean sendPermiss(@RequestBody PermissionBean permissionBean) {
log.error("permissionBean:{}", JSON.toJSONString(permissionBean));
if (!StringUtils.isEmpty(permissionBean)) {
return sendUserAsync.sendPermiss(permissionBean, 1);
}
return false;
}
@RequestMapping(method = RequestMethod.POST, value = "uploadImg")
public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("card") String card
, @RequestParam("name") String name, @RequestParam("deviceId") String deviceId, @RequestParam("startTime") String startTime,
@RequestParam("endTime") String endTime, @RequestParam("validTimeEnabled") int validTimeEnabled, @RequestParam("userType") String userType) {
try {
if (!cmsServer.getIsDeviceOnline(deviceId)) {
log.warn("设备ID: {},设备不在线",deviceId);
return "0";
}
if(StringUtils.isEmpty(card)){
log.warn("卡号为空");
return "0";
}
String fileName = file.getOriginalFilename();//文件名
File outFile = new File(".//imgCom");
if (!outFile.exists()) outFile.mkdirs();
File dest = new File(outFile, fileName);
FileOutputStream fileOutputStream = new FileOutputStream(dest);
fileOutputStream.write(file.getBytes());
fileOutputStream.close();
String filePath = dest.getAbsolutePath();
long time = System.currentTimeMillis();
StudentBean studentBean = userDao.getStudentWithCard(card);
Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id();
String cardNum = Long.parseLong(baseService.getCard(card),16) + "";
if (new File(filePath.trim()).exists()) {
String targetPath = FileUtils.picPathComp + new File(filePath).getName();
try {
CompressPic.CompressPic(filePath, targetPath);
} catch (Exception e) {
e.printStackTrace();
}
try {
log.info("下发人脸,人脸路径:{},用户名:{},下发设备:{}",filePath,name,deviceId);
sendUserAsync.sendStuToHaiKang(filePath, targetPath,cardNum,startTime, endTime, validTimeEnabled, name, deviceId, userType,schoolId,card);
System.out.println("time:" + (System.currentTimeMillis() - time) / 1000);
return "1";
} catch (Exception e) {
e.printStackTrace();
return "0";
}
} else {
baseService.sendFail(cardNum, filePath, deviceId,"文件不存在", userType);
log.error("文件不存在:" + filePath);
}
} catch (Exception e) {
e.printStackTrace();
}
return "0";
}
@RequestMapping(value = "IsDeviceOnline", method = RequestMethod.GET)
@ApiOperation("判断设备是否在线")
public String IsDeviceOnline(@RequestParam("deviceId") String deviceId) {
return cmsServer.getIsDeviceOnline(deviceId) ? "1" : "0";
}
@RequestMapping(value = "DeleteCard", method = RequestMethod.GET)
@ApiOperation("删除人脸")
public String deleteCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) {
StudentBean studentBean = userDao.getStudentWithCard(card);
Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id();
cmsServer.deleteCard(deviceId, Long.parseLong(baseService.getCard(card), 16) + "",schoolId);
return "1";
}
@RequestMapping(value = "getCard", method = RequestMethod.GET)
@ApiOperation("获取设备人脸是否存在")
public String getCard(@RequestParam("deviceId") String deviceId, @RequestParam("card") String card) {
StudentBean studentBean = userDao.getStudentWithCard(card);
Integer schoolId = studentBean ==null ?null:studentBean.getSchool_id();
if (cmsServer.getFace(deviceId, Long.parseLong(baseService.getCard(card), 16) + "",schoolId)){
return "1";
}else{
return "0";
}
}
}