|
|
@@ -6,14 +6,13 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.template.annotation.DESRespondSecret;
|
|
|
import com.template.annotation.PassToken;
|
|
|
import com.template.api.SmartFaceDiscernTestControllerAPI;
|
|
|
+import com.template.common.utils.Message2;
|
|
|
import com.template.common.utils.MultipartFileUtils;
|
|
|
import com.template.model.pojo.SmartDevice;
|
|
|
import com.template.model.pojo.SmartFaceDiscernTest;
|
|
|
+import com.template.model.pojo.SmartNotification;
|
|
|
import com.template.model.pojo.SmartUser;
|
|
|
-import com.template.services.SmartDeviceService;
|
|
|
-import com.template.services.SmartFaceDiscernTestService;
|
|
|
-import com.template.services.SmartUploadService;
|
|
|
-import com.template.services.SmartUserService;
|
|
|
+import com.template.services.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
@@ -24,11 +23,14 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.InputStreamReader;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
- * 前端控制器
|
|
|
+ * 前端控制器
|
|
|
* </p>
|
|
|
*
|
|
|
* @author ceshi
|
|
|
@@ -49,6 +51,9 @@ public class SmartFaceDiscernTestController implements SmartFaceDiscernTestContr
|
|
|
@Autowired
|
|
|
SmartUploadService smartUploadService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SmartNotificationService smartNotificationService;
|
|
|
+
|
|
|
@Override
|
|
|
@PassToken
|
|
|
@DESRespondSecret(validated = false)
|
|
|
@@ -61,62 +66,140 @@ public class SmartFaceDiscernTestController implements SmartFaceDiscernTestContr
|
|
|
responseStrBuilder.append(inputStr);
|
|
|
}
|
|
|
JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
|
|
|
-
|
|
|
+// System.out.println("jsonObject = " + jsonObject);
|
|
|
// 比对结果
|
|
|
Integer resultStatus = jsonObject.getInteger("resultStatus");
|
|
|
- if (0!=resultStatus) {
|
|
|
- JSONObject r = new JSONObject();
|
|
|
- r.put("message","Success");
|
|
|
- r.put("result",0);
|
|
|
- return r.toJSONString();
|
|
|
- }
|
|
|
+ if (1 == resultStatus) {
|
|
|
+
|
|
|
// 抓拍的照片 base64字符串
|
|
|
- String scenePhoto = jsonObject.getString("scenePhoto");
|
|
|
- System.out.println("scenePhoto = " + scenePhoto.substring(0,100));
|
|
|
+ String scenePhoto = jsonObject.getString("scenePhoto");
|
|
|
+ scenePhoto = "data:image/jpeg;base64," + scenePhoto;
|
|
|
+ System.out.println("scenePhoto = " + scenePhoto.substring(0, 100));
|
|
|
// base64转文件
|
|
|
- MultipartFile multipartFile = MultipartFileUtils.base64ToMultipartFile(scenePhoto);
|
|
|
+ MultipartFile multipartFile = MultipartFileUtils.base64ToMultipartFile(scenePhoto);
|
|
|
// 上传到cos桶,并生成图片地址
|
|
|
- String image = smartUploadService.upload(new MultipartFile[]{multipartFile});
|
|
|
-
|
|
|
- // 设备mac
|
|
|
- String mac = jsonObject.getString("mac");
|
|
|
- SmartDevice smartDevice = smartDeviceService.getNum(mac);
|
|
|
- String address="";
|
|
|
- String type="";
|
|
|
- if (ObjectUtils.isNotEmpty(smartDevice)) {
|
|
|
- // 地点
|
|
|
- address = smartDevice.getAddress();
|
|
|
+ String image = smartUploadService.upload(new MultipartFile[]{multipartFile});
|
|
|
+
|
|
|
+ // 设备sn
|
|
|
+ String sn = jsonObject.getString("sn");
|
|
|
+ SmartDevice smartDevice = smartDeviceService.getNum(sn);
|
|
|
+ String address = "";
|
|
|
+ String type = "";
|
|
|
+ if (ObjectUtils.isNotEmpty(smartDevice)) {
|
|
|
+ // 地点
|
|
|
+ address = smartDevice.getAddress();
|
|
|
// 类型
|
|
|
- type = smartDevice.getName();
|
|
|
- }
|
|
|
+ type = smartDevice.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+// 名字,学生会加班级[]
|
|
|
+ String name = jsonObject.getString("name");
|
|
|
+ System.out.println("name = " + name);
|
|
|
+ String[] split = name.split("\\[");
|
|
|
+ String s = split[0];
|
|
|
+ System.out.println("s = " + s);
|
|
|
+// 百胜门禁编号
|
|
|
+ String idNum = jsonObject.getString("idNum");
|
|
|
+ System.out.println("idNum = " + idNum);
|
|
|
+ SmartUser smartUser = smartUserService.getBsStudentNo(idNum);
|
|
|
+ Integer userId = 0;
|
|
|
+ if (ObjectUtils.isNotEmpty(smartUser)) {
|
|
|
+ userId = smartUser.getId();
|
|
|
+ } else {
|
|
|
+ userId = 0;
|
|
|
+ }
|
|
|
+ DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String dateTime = dateTimeFormatter1.format(LocalDateTime.now());
|
|
|
+
|
|
|
+ SmartFaceDiscernTest smartFaceDiscernTest = new SmartFaceDiscernTest();
|
|
|
+ smartFaceDiscernTest.setImage(image);
|
|
|
+ smartFaceDiscernTest.setName(s);
|
|
|
+ smartFaceDiscernTest.setLocation(address);
|
|
|
+ smartFaceDiscernTest.setType(type);
|
|
|
+ smartFaceDiscernTest.setUserId(userId);
|
|
|
+ smartFaceDiscernTest.setDateTime(dateTime);
|
|
|
+ smartFaceDiscernTest.setIdNum(idNum);
|
|
|
+ smartFaceDiscernTest.setSn(sn);
|
|
|
+ smartFaceDiscernTestService.save(smartFaceDiscernTest);
|
|
|
+
|
|
|
+ if (userId != 0) {
|
|
|
+
|
|
|
+// 通过学生id找到关联的家长affiliate,并找到公众号,如果openid为空则不传
|
|
|
+ List<SmartUser> userList = smartUserService.getAffiliateList(userId);
|
|
|
+ if (ObjectUtils.isNotEmpty(userList) && userList.size() > 0) {
|
|
|
+
|
|
|
+ for (SmartUser user : userList) {
|
|
|
+ String gzhOpenId = user.getGzhOpenId();
|
|
|
+ if (ObjectUtils.isNotEmpty(gzhOpenId)) {
|
|
|
+ String pushType = "";
|
|
|
+ if (type.contains("进校")) {
|
|
|
+ pushType = "进入大门";
|
|
|
+ } else if (type.contains("出校")) {
|
|
|
+ pushType = "离开大门";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 时间格式是 yyyy-MM-dd HH:mm:ss,当前时间格式有问题
|
|
|
+
|
|
|
+ LocalDateTime date = LocalDateTime.now();
|
|
|
+ String format = date.format(dateTimeFormatter1);
|
|
|
+
|
|
|
+ // 公众号信息推送
|
|
|
+ Message2.send(gzhOpenId, pushType, address, format);
|
|
|
+
|
|
|
+ SmartNotification smartNotification = new SmartNotification();
|
|
|
+ smartNotification.setUserId(smartUser.getId());
|
|
|
+ smartNotification.setUserName(smartUser.getName());
|
|
|
+ smartNotification.setTypeName(pushType);
|
|
|
+ smartNotification.setLocation(address);
|
|
|
+ smartNotification.setImage(image);
|
|
|
+ smartNotification.setDateTime(dateTime);
|
|
|
+ smartNotification.setType(2);
|
|
|
+
|
|
|
+ smartNotificationService.save(smartNotification);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-// 名字
|
|
|
- String name = jsonObject.getString("name");
|
|
|
-// 身份证号
|
|
|
- String idNum = jsonObject.getString("idNum");
|
|
|
- SmartUser user = smartUserService.getCard(idNum);
|
|
|
- Integer userId=0;
|
|
|
- if (ObjectUtils.isNotEmpty(user)) {
|
|
|
- userId = user.getId();
|
|
|
- }else {
|
|
|
- userId=0;
|
|
|
}
|
|
|
|
|
|
- SmartFaceDiscernTest smartFaceDiscernTest = new SmartFaceDiscernTest();
|
|
|
- smartFaceDiscernTest.setImage(image);
|
|
|
- smartFaceDiscernTest.setName(name);
|
|
|
- smartFaceDiscernTest.setLocation(address);
|
|
|
- smartFaceDiscernTest.setType(type);
|
|
|
- smartFaceDiscernTest.setUserId(userId);
|
|
|
- smartFaceDiscernTest.setDateTime(new Date());
|
|
|
- smartFaceDiscernTestService.save(smartFaceDiscernTest);
|
|
|
+ } catch (
|
|
|
+ Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ JSONObject r = new JSONObject();
|
|
|
+ r.put("message", "Success");
|
|
|
+ r.put("result", 0);
|
|
|
+ return r.toJSONString();
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject r = new JSONObject();
|
|
|
+ r.put("message", "Success");
|
|
|
+ r.put("result", 0);
|
|
|
+ return r.toJSONString();
|
|
|
+ }
|
|
|
|
|
|
- }catch (Exception e){
|
|
|
+ @Override
|
|
|
+ @PassToken
|
|
|
+ @DESRespondSecret(validated = false)
|
|
|
+ public String heartBeatAlive(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
|
|
|
+ StringBuilder responseStrBuilder = new StringBuilder();
|
|
|
+ String inputStr;
|
|
|
+ while ((inputStr = streamReader.readLine()) != null) {
|
|
|
+ responseStrBuilder.append(inputStr);
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseStrBuilder.toString());
|
|
|
+ System.out.println("jsonObject = " + jsonObject);
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
JSONObject r = new JSONObject();
|
|
|
- r.put("message","Success");
|
|
|
- r.put("result",0);
|
|
|
+ r.put("message", "Success");
|
|
|
+ r.put("result", 0);
|
|
|
return r.toJSONString();
|
|
|
}
|
|
|
|