{ "id": 16, "check_grand": null, "warn_grand": null, "status": 0, "rail_name": "测试打卡", "rail_contain": 120.66764032547655,30.764092330951797|120.66892242138567,30.764511798223253|120.66924965088549,30.763350192070362|120.66811239426318,30.762898452558346|120.66767787640276,30.763963263731313|120.66764032547655,30.764092330951797 "rail_remark": null, "update_time": "2023-09-20T01:16:57.000+0000", "create_time": "2023-09-20T01:16:57.000+0000" } ] /** * 新增考勤记录对象 attendance_record */ //@PreAuthorize("@ss.hasPermi('record:record:add')") @Log(title = "考勤记录对象 attendance_record", businessType = BusinessType.INSERT) @PostMapping @ApiOperation("新增考勤记录对象 经纬度打卡 签到签到!!!!!") public AjaxResult add(@RequestBody AttendanceRecorddto AttendanceRecorddto) { int i = attendanceRecordService.insertAttendanceRecord(AttendanceRecorddto); if (i==1){ return AjaxResult.success("用户已成功打卡",i); }else { return AjaxResult.error("打卡失败不在打卡范围内",i); } } /** * 判断是否达到站点电子围栏内 */ public boolean isInPolygon(String electronicFence, Double lon, Double lat) { //获取电子围栏 String[] split = electronicFence.split("\\|"); ArrayList<Point2D.Double> placeInnerList = new ArrayList<>(); for (int i = 0; i < split.length; i++) { String positionItem = split[i]; String[] positionSplit1s = positionItem.split(","); if (positionSplit1s.length != 2) { continue; } placeInnerList.add(new Point2D.Double(Double.valueOf(positionSplit1s[0]), Double.valueOf(positionSplit1s[1]))); } Point2D.Double selfPosition = new Point2D.Double(lon, lat); GeneralPath generalPath = genGeneralPath(placeInnerList); boolean contains = generalPath.contains(selfPosition); return contains; } //是否在面内 public static GeneralPath genGeneralPath(ArrayList<Point2D.Double> points) { GeneralPath path = new GeneralPath(); if (points.size() < 3) { return null; } path.moveTo((float) points.get(0).getX(), (float) points.get(0).getY()); for (Iterator<Point2D.Double> it = points.iterator(); it.hasNext(); ) { Point2D.Double point = (Point2D.Double) it.next(); path.lineTo((float) point.getX(), (float) point.getY()); } path.closePath(); return path; } /** * 新增考勤记录对象 attendance_record * * @return 结果 */ @Override public int insertAttendanceRecord(AttendanceRecorddto AttendanceRecorddto) { int i = 0; AttendanceRecorddto.setCreateTime(DateUtils.getNowDate()); //设置打卡时间 AttendanceRecorddto.setSignInTime(DateUtils.getNowDate()); //当前登录用户 Long userId = SecurityUtils.getLoginUser().getUserId(); SysUser sysUser = sysUserMapper.selectUserById(userId); AttendanceRecorddto.setUserTureName(sysUser.getUserTrueName()); List<UserRecord> userRecords = SysPostMapper.selectUserByUserTrueName(sysUser.getUserTrueName()); AttendanceRecorddto.setPostId(userRecords.get(0).getPostId()); AttendanceRecorddto.setUserId(userId); AttendanceRecorddto.setStatus(0l); //精度 double userLatitude = AttendanceRecorddto.getUserLatitude(); // - --- 30.763973 // - --- 120.668891 log.info("---纬度 {}", userLatitude); //纬度 double userLongitude = AttendanceRecorddto.getUserLongitude(); log.info("---经度 {}", userLongitude); String electronicFence = "120.66764032547655,30.764092330951797|120.66892242138567,30.764511798223253|120.66924965088549,30.763350192070362|120.66811239426318,30.762898452558346|120.66767787640276,30.763963263731313|120.66764032547655,30.764092330951797"; // boolean isWithinCheckInRadius = isInPolygon(userLongitude,userLatitude,partitionLocation); boolean isWithinCheckInRadius = isInPolygon(electronicFence, userLongitude, userLatitude); if (isWithinCheckInRadius) { System.out.println("用户已成功打卡!"); i = attendanceRecordMapper.insertAttendanceRecord(AttendanceRecorddto); } else { System.out.println("用户不在打卡范围内,打卡失败!"); } return i; }