package com.boman.web.core.controller;

import com.boman.common.core.web.controller.BaseController;
import com.boman.domain.dto.AjaxResult;
import com.boman.domain.TableDataInfo;
import com.boman.common.log.annotation.Log;
import com.boman.common.log.enums.BusinessType;
import com.boman.web.core.domain.AttendanceSet;
import com.boman.web.core.service.attendance.set.IAttendanceSetService;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 考勤设置Controller
 * 
 * @author ruoyi
 * @date 2021-06-04
 */
@RestController
@RequestMapping("/attendance/set")
public class AttendanceSetController extends BaseController
{
    @Autowired
    private IAttendanceSetService attendanceSetService;

    /**
     * 查询考勤设置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AttendanceSet attendanceSet)
    {
        startPage();
        List<AttendanceSet> list = attendanceSetService.selectAttendanceSetList(attendanceSet);
        return getDataTable(list);
    }


    /**
     * 获取考勤设置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(attendanceSetService.selectAttendanceSetById(id));
    }

    /**
     * 新增考勤设置
     */
    @Log(title = "考勤设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AttendanceSet attendanceSet)
    {
        return toAjax(attendanceSetService.insertAttendanceSet(attendanceSet));
    }

    /**
     * 修改考勤设置
     */
    @Log(title = "考勤设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AttendanceSet attendanceSet)
    {
        return toAjax(attendanceSetService.updateAttendanceSet(attendanceSet));
    }

    /**
     * 删除考勤设置
     */
    @Log(title = "考勤设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(attendanceSetService.deleteAttendanceSetByIds(ids));
    }


    /**
     * 功能描述: 根据传入的经纬度计算是否在设置的范围之内
     *
     * @param mLatitude  mLatitude
     * @param mLongitude mLongitude
     * @return com.boman.domain.dto.AjaxResult
     */
    @GetMapping("/distanceMeter")
    public AjaxResult getDistanceMeter(double mLatitude, double mLongitude) {
        GlobalCoordinates globalCoordinates = new GlobalCoordinates(mLatitude, mLongitude);
        return attendanceSetService.getDistanceMeter(globalCoordinates);
    }
}
