FileControl.java
4.19 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
package com.sincere.haikangface.control;
import com.sincere.haikangface.CMSServer;
import com.sincere.haikangface.async.SendUserAsync;
import com.sincere.haikangface.bean.face.SendFaceBean;
import com.sincere.haikangface.dao.UserDao;
import com.sincere.haikangface.utils.FileUtils;
import com.sincere.haikangface.utils.SendRecoderUtils;
import com.sincere.haikangface.xiananDao.SendRecordDao;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
@RestController
@Api("文件管理器")
@RequestMapping("file/*")
public class FileControl {
@Autowired
SendUserAsync sendUserAsync;
@Autowired
SendRecordDao sendRecordDao;
@Autowired
UserDao userDao;
@Autowired
CMSServer cmsServer;
SendRecoderUtils sendRecoderUtils;
@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 {
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());
String filePath = dest.getAbsolutePath();
FileUtils.getInstance().writeLogs("filePath:" + filePath + " card:" + card + " name:" + name + " deviceId:" + deviceId, FileUtils.sendUserInfo);
long time = System.currentTimeMillis();
// if (filePath.contains(".jpg")) filePath = filePath.replace(".jpg", ".png");
if (new File(filePath.trim()).exists()) {
String targetPath = FileUtils.picPathComp + new File(filePath).getName();
try {
int isPiliang = 0;//0:批量,1:单张
if (filePath.contains("face17e50")) {//批量发送
isPiliang = 0;
} else {//单图发送
isPiliang = 1;
}
sendUserAsync.sendStuToHaiKang(filePath, targetPath, Long.parseLong(getCard(card), 16) + "", startTime, endTime, validTimeEnabled, name, deviceId, userType, isPiliang);
System.out.println("time:" + (System.currentTimeMillis() - time) / 1000);
return "1";
} catch (Exception e) {
e.printStackTrace();
return "0";
}
} else {
if (null == sendRecoderUtils) sendRecoderUtils = new SendRecoderUtils();
sendRecoderUtils.sendFail(sendRecordDao, Long.parseLong(getCard(card), 16) + "", filePath, deviceId, userDao, "文件不存在", userType);
System.out.println("文件不存在:" + 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";
}
private String getCard(String card) {
if (card.length() == 8) {
int length = card.length();
String result = card.substring(length - 2, length) + card.substring(length - 4, length - 2) + card.substring(length - 6, length - 4)
+ card.substring(length - 8, length - 6);
return result;
} else {
System.out.println("卡号位数不对:" + card);
return "";
}
}
}