|
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -71,7 +72,14 @@ public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI
|
|
|
@Autowired
|
|
@Autowired
|
|
|
SmartClassService smartClassService;
|
|
SmartClassService smartClassService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ SmartUploadService smartUploadService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ SmartNotificationService smartNotificationService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ SmartDeviceService smartDeviceService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@DESRespondSecret(validated = true)
|
|
@DESRespondSecret(validated = true)
|
|
@@ -144,12 +152,12 @@ public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI
|
|
|
vos.add(lastSevenDaysTrackVo);
|
|
vos.add(lastSevenDaysTrackVo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- List<SmartAttendance> attendances=smartAttendanceService.track(startTime,endTime,userId);
|
|
|
|
|
|
|
+ List<SmartAttendance> attendances = smartAttendanceService.track(startTime, endTime, userId);
|
|
|
// 获取班级名称
|
|
// 获取班级名称
|
|
|
SmartUser smartUser = smartUserService.getSmartById(userId);
|
|
SmartUser smartUser = smartUserService.getSmartById(userId);
|
|
|
SmartClass smartClass = smartClassService.getSmartClassById(smartUser.getSchoolClass());
|
|
SmartClass smartClass = smartClassService.getSmartClassById(smartUser.getSchoolClass());
|
|
|
String className = smartClass.getName();
|
|
String className = smartClass.getName();
|
|
|
- SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );
|
|
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
for (SmartAttendance attendance : attendances) {
|
|
for (SmartAttendance attendance : attendances) {
|
|
|
LastSevenDaysTrackVo lastSevenDaysTrackVo = new LastSevenDaysTrackVo();
|
|
LastSevenDaysTrackVo lastSevenDaysTrackVo = new LastSevenDaysTrackVo();
|
|
|
lastSevenDaysTrackVo.setName(attendance.getXwUserName());
|
|
lastSevenDaysTrackVo.setName(attendance.getXwUserName());
|
|
@@ -169,6 +177,176 @@ public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI
|
|
|
return CommonResult.ok(vos);
|
|
return CommonResult.ok(vos);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @PassToken
|
|
|
|
|
+ @DESRespondSecret(validated = false)
|
|
|
|
|
+ public String callBack(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());
|
|
|
|
|
+
|
|
|
|
|
+ DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+ // 比对时间
|
|
|
|
|
+ String time = jsonObject.getString("time");
|
|
|
|
|
+ logger.info("time = " + time);
|
|
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now().withHour(0).withSecond(0).withMinute(0);
|
|
|
|
|
+ LocalDateTime localDateTime2 = LocalDateTime.parse(time, dateTimeFormatter1);
|
|
|
|
|
+// 只获取当天的
|
|
|
|
|
+ if (localDateTime.isBefore(localDateTime2)) {
|
|
|
|
|
+// 比对结果
|
|
|
|
|
+ Integer resultStatus = jsonObject.getInteger("resultStatus");
|
|
|
|
|
+ if (1 == resultStatus) {
|
|
|
|
|
+
|
|
|
|
|
+ // 设备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();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// 名字,学生会加班级[]
|
|
|
|
|
+ String name = jsonObject.getString("name");
|
|
|
|
|
+ System.out.println("name = " + name);
|
|
|
|
|
+ String[] split = name.split("\\[");
|
|
|
|
|
+ String s = split[0];
|
|
|
|
|
+ logger.info("name = " + s);
|
|
|
|
|
+// 百胜门禁编号
|
|
|
|
|
+ String idNum = jsonObject.getString("idNum");
|
|
|
|
|
+ logger.info("idNum = " + idNum);
|
|
|
|
|
+ SmartUser smartUser = smartUserService.getBsStudentNo(idNum);
|
|
|
|
|
+ Integer userId = 0;
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(smartUser)) {
|
|
|
|
|
+ userId = smartUser.getId();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ userId = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ SmartFaceDiscern smartFaceDiscern = new SmartFaceDiscern();
|
|
|
|
|
+
|
|
|
|
|
+ smartFaceDiscern.setName(s);
|
|
|
|
|
+ smartFaceDiscern.setLocation(address);
|
|
|
|
|
+ smartFaceDiscern.setType(type);
|
|
|
|
|
+ smartFaceDiscern.setUserId(userId);
|
|
|
|
|
+ smartFaceDiscern.setDateTime(time);
|
|
|
|
|
+ smartFaceDiscern.setIdNum(idNum);
|
|
|
|
|
+ smartFaceDiscern.setSn(sn);
|
|
|
|
|
+ if (userId != 0) {
|
|
|
|
|
+ // 判断是否已经添加
|
|
|
|
|
+ LambdaQueryWrapper<SmartFaceDiscern> wrapperFD = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapperFD.eq(SmartFaceDiscern::getDateTime, smartFaceDiscern.getDateTime())
|
|
|
|
|
+ .eq(SmartFaceDiscern::getUserId, userId);
|
|
|
|
|
+ List<SmartFaceDiscern> list = smartFaceDiscernService.list(wrapperFD);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(list) && list.size() == 0) {
|
|
|
|
|
+ // 抓拍的照片 base64字符串
|
|
|
|
|
+ String scenePhoto = jsonObject.getString("scenePhoto");
|
|
|
|
|
+ scenePhoto = "data:image/jpeg;base64," + scenePhoto;
|
|
|
|
|
+ logger.info("scenePhoto =" + scenePhoto.substring(0, 50));
|
|
|
|
|
+// base64转文件
|
|
|
|
|
+ MultipartFile multipartFile = MultipartFileUtils.base64ToMultipartFile(scenePhoto);
|
|
|
|
|
+ String image="";
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 上传到cos桶,并生成图片地址
|
|
|
|
|
+ image = smartUploadService.upload(new MultipartFile[]{multipartFile});
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ logger.error("上传cos桶失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ smartFaceDiscern.setImage(image);
|
|
|
|
|
+ smartFaceDiscernService.save(smartFaceDiscern);
|
|
|
|
|
+
|
|
|
|
|
+// 通过学生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 = "离开大门";
|
|
|
|
|
+ }
|
|
|
|
|
+ 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(time);
|
|
|
|
|
+ smartNotification.setType(2);
|
|
|
|
|
+
|
|
|
|
|
+ smartNotificationService.save(smartNotification);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ smartFaceDiscern.setUserId(0);
|
|
|
|
|
+// 判断是否已经添加
|
|
|
|
|
+ LambdaQueryWrapper<SmartFaceDiscern> wrapperFD = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapperFD.eq(SmartFaceDiscern::getDateTime, time)
|
|
|
|
|
+ .eq(SmartFaceDiscern::getName, s)
|
|
|
|
|
+ .eq(SmartFaceDiscern::getType, type);
|
|
|
|
|
+ List<SmartFaceDiscern> list = smartFaceDiscernService.list(wrapperFD);
|
|
|
|
|
+
|
|
|
|
|
+ if (ObjectUtils.isEmpty(list) && list.size() == 0) {
|
|
|
|
|
+ // 抓拍的照片 base64字符串
|
|
|
|
|
+ String scenePhoto = jsonObject.getString("scenePhoto");
|
|
|
|
|
+ scenePhoto = "data:image/jpeg;base64," + scenePhoto;
|
|
|
|
|
+ logger.info("scenePhoto =" + scenePhoto.substring(0, 50));
|
|
|
|
|
+// base64转文件
|
|
|
|
|
+ MultipartFile multipartFile = MultipartFileUtils.base64ToMultipartFile(scenePhoto);
|
|
|
|
|
+ String image="";
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 上传到cos桶,并生成图片地址
|
|
|
|
|
+ image = smartUploadService.upload(new MultipartFile[]{multipartFile});
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ logger.error("上传cos桶失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ smartFaceDiscern.setImage(image);
|
|
|
|
|
+ smartFaceDiscernService.save(smartFaceDiscern);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } 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();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
public static JSONObject getDate(Integer date) {
|
|
public static JSONObject getDate(Integer date) {
|
|
@@ -188,10 +366,16 @@ public class SmartFaceDiscernController implements SmartFaceDiscernControllerAPI
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
- LocalDateTime end = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).plusDays(1);
|
|
|
|
|
- System.out.println("end = " + end);
|
|
|
|
|
- LocalDateTime satrt = end.minusDays(7);
|
|
|
|
|
- System.out.println("satrt = " + satrt);
|
|
|
|
|
|
|
+ LocalDateTime dateTime1 = LocalDateTime.of(2022, 8, 29, 12, 0, 0);
|
|
|
|
|
+ LocalDateTime dateTime2 = LocalDateTime.of(2022, 8, 30, 12, 0, 0);
|
|
|
|
|
+ LocalDateTime dateTime3 = LocalDateTime.of(2022, 8, 28, 12, 0, 0);
|
|
|
|
|
+
|
|
|
|
|
+ boolean isBefore = dateTime1.isBefore(dateTime2);
|
|
|
|
|
+ boolean isBefore2 = dateTime1.isBefore(dateTime3);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("dateTime1 is before dateTime2: " + isBefore);
|
|
|
|
|
+ System.out.println("dateTime1 is before dateTime2: " + isBefore2);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|