FileControl.java
7.61 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
package com.example.dahua.control;
import com.example.dahua.MyTask;
import com.example.dahua.async.SendUserInfoTask;
import com.example.dahua.attendance.Attendance;
import com.example.dahua.bean.AttendanceBean;
import com.example.dahua.bean.TeacherBean;
import com.example.dahua.bean.UploadImg;
import com.example.dahua.dao.UserDao;
import com.example.dahua.lib.ToolKits;
import com.example.dahua.module.GateModule;
import com.example.dahua.service.UserService;
import com.sun.jna.Memory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
@RestController
@Api("文件管理器")
@RequestMapping(value = "file/*", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class FileControl {
@Autowired
UserService userService;
@Autowired
SendUserInfoTask sendUserInfoTask;
@Autowired
UserDao userDao;
@RequestMapping(method = RequestMethod.POST, value = "uploadImg")
public String uploadImg(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode,
@RequestParam("clint_type") String clint_type, @RequestParam("userType") int userType) {
System.out.println("schoolId:" + schoolId + " studentCode:" + studentCode);
String fileName = file.getOriginalFilename();//文件名
File outFile = new File("C://imgCom");
if (!outFile.exists()) outFile.mkdirs();
try {
File dest = new File(outFile, fileName);
FileOutputStream fileOutputStream = new FileOutputStream(dest);
fileOutputStream.write(file.getBytes());
fileOutputStream.close();
userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type, userType, "");
return "1";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "0";
}
@RequestMapping(method = RequestMethod.POST, value = "uploadImgToDev")
public String uploadImgToDev(@RequestParam("file") MultipartFile file, @RequestParam("schoolId") String schoolId, @RequestParam("studentCode") String studentCode,
@RequestParam("clint_type") String clint_type, @RequestParam("userType") int userType, @RequestParam("devid") String devid) {
String fileName = file.getOriginalFilename();//文件名
File outFile = new File("C://imgCom");
if (!outFile.exists()) outFile.mkdirs();
try {
File dest = new File(outFile, fileName);
FileOutputStream fileOutputStream = new FileOutputStream(dest);
fileOutputStream.write(file.getBytes());
fileOutputStream.close();
userService.uploadImgAndUserInfo(dest.getAbsolutePath(), schoolId, studentCode, clint_type, userType, devid);
return "1";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "0";
}
@RequestMapping(value = "deleteFace", method = RequestMethod.GET)
@ApiOperation("删除人脸")
public void deleteFace(@RequestParam("cardNum") String cardNum, @RequestParam("deviceId") String deviceId) {
sendUserInfoTask.deleteFace(cardNum, deviceId);
}
@RequestMapping(value = "imgsSend", method = RequestMethod.GET)
@ApiOperation(value = "照片下放")
public boolean imgsSend(@RequestParam("schoolId") String schoolId, @RequestParam("type") int type) {
userService.sendUserInfos(schoolId, "22", type);
return true;
}
@RequestMapping(value = "findCard", method = RequestMethod.GET)
@ApiOperation(value = "查询设备卡信息")
public boolean findCard(@RequestParam("cardNum") String cardNum, @RequestParam("deviceId") String deviceId) {
boolean fincard = GateModule.findCard(cardNum, MyTask.lLongMap.get(deviceId));
System.out.println("fincard:" + fincard + MyTask.lLongMap.get(deviceId));
return true;
}
@RequestMapping(value = "addCard", method = RequestMethod.GET)
@ApiOperation(value = "下发卡信息")
public int addCard(@RequestParam("schoolId") String schoolId, @RequestParam("targPath") String targPath) {
File file = new File(targPath);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
File imgFile = files[i];
String num = imgFile.getName().split("\\.")[0];
TeacherBean teacherBean = userDao.getTeacher(schoolId, num);
List<AttendanceBean> attendanceBeans = userDao.selectDeviceWithschool_id("22", schoolId);
for (int j = 0; j < attendanceBeans.size(); j++) {
AttendanceBean attendanceBean = attendanceBeans.get(j);
int addCard = GateModule.insertCard(cardNo(teacherBean.getTeacher_num()), teacherBean.getUser_id(), teacherBean.getName(),
"123456", 1, 1, 1, 1, 1,
"2020-01-01 00:00:00", "2040-01-01 12:00:00", MyTask.lLongMap.get(attendanceBean.getClint_id()));
Memory memory = ToolKits.readPictureFile(imgFile.getAbsolutePath());
GateModule.addFaceInfo(teacherBean.getUser_id(), memory, MyTask.lLongMap.get(attendanceBean.getClint_id()));
userDao.saveRecordNo(teacherBean.getUser_id(), addCard, teacherBean.getName(), attendanceBean.getClint_id());
System.out.println("teacherBean:" + teacherBean.toString() + " clientid:" + attendanceBean.getClint_id());
}
}
return 1;
}
@RequestMapping(value = "deleteCard", method = RequestMethod.GET)
@ApiOperation(value = "删除卡信息")
public boolean deleteCard(@RequestParam("recordNum") int recordNum, @RequestParam("deviceId") String deviceId) {
boolean deleteCard = GateModule.deleteCard(recordNum, MyTask.lLongMap.get(deviceId));
System.out.println("addCard:" + deleteCard + "----" + MyTask.lLongMap.get(deviceId));
return deleteCard;
}
@RequestMapping(value = "clearCard", method = RequestMethod.GET)
@ApiOperation(value = "清空卡信息")
public boolean clearCard(@RequestParam("deviceId") String deviceId) {
boolean clearCard = GateModule.clearCard(MyTask.lLongMap.get(deviceId));
System.out.println("addCard:" + clearCard + "----" + MyTask.lLongMap.get(deviceId));
return clearCard;
}
@RequestMapping(value = "clearFaceInfo", method = RequestMethod.GET)
@ApiOperation(value = "清空人脸信息")
public boolean clearFaceInfo(@RequestParam("deviceId") String deviceId) {
boolean clearCard = GateModule.clearFaceInfo(MyTask.lLongMap.get(deviceId));
System.out.println("addCard:" + clearCard + "----" + MyTask.lLongMap.get(deviceId));
return clearCard;
}
public String cardNo(String cardDex) {
String cardR = "";
int length = cardDex.length();
if (length != 8) {
System.out.println("卡号格式不正确:" + cardDex);
return cardDex;
}
while (length > 0) {
length -= 2;
cardR += cardDex.substring(length, length + 2);
}
return cardR;
}
}