测试定位打卡

  {
    "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;

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值