package com.yanzhu.jh.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yanzhu.jh.project.domain.SurProjectAttendanceCfg;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.yanzhu.jh.project.domain.SurProjectAttendanceUser;
import com.yanzhu.jh.project.service.ISurProjectAttendanceUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考勤人员基本属性Controller
 * 
 * @author ruoyi
 * @date 2023-09-24
 */
@RestController
@RequestMapping("/project/attendanceWorker")
public class SurProjectAttendanceUserController extends BaseController
{
    @Autowired
    private ISurProjectAttendanceUserService surProjectAttendanceUserService;

    /**
     * 查询考勤人员基本属性列表
     */
    @PreAuthorize("@ss.hasPermi('project:attendanceWorker:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurProjectAttendanceUser surProjectAttendanceUser)
    {
        startPage();
        List<SurProjectAttendanceUser> list = surProjectAttendanceUserService.selectSurProjectAttendanceUserList(surProjectAttendanceUser);
        return getDataTable(list);
    }

    /**
     * 导出考勤人员基本属性列表
     */
    @PreAuthorize("@ss.hasPermi('project:attendanceWorker:export')")
    @Log(title = "考勤人员基本属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurProjectAttendanceUser surProjectAttendanceUser)
    {
        List<SurProjectAttendanceUser> list = surProjectAttendanceUserService.selectSurProjectAttendanceUserList(surProjectAttendanceUser);
        ExcelUtil<SurProjectAttendanceUser> util = new ExcelUtil<SurProjectAttendanceUser>(SurProjectAttendanceUser.class);
        util.exportExcel(response, list, "考勤人员基本属性数据");
    }

    /**
     * 获取考勤人员基本属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:attendanceWorker:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surProjectAttendanceUserService.selectSurProjectAttendanceUserById(id));
    }

    /**
     * 新增考勤人员基本属性
     */
    @PreAuthorize("@ss.hasPermi('project:attendanceWorker:add')")
    @Log(title = "考勤人员基本属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurProjectAttendanceUser surProjectAttendanceUser)
    {
        return toAjax(surProjectAttendanceUserService.insertSurProjectAttendanceUser(surProjectAttendanceUser));
    }

    /**
     * 修改考勤人员基本属性
     */
    @PreAuthorize("@ss.hasPermi('project:attendanceWorker:edit')")
    @Log(title = "考勤人员基本属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurProjectAttendanceUser surProjectAttendanceUser)
    {
        return toAjax(surProjectAttendanceUserService.updateSurProjectAttendanceUser(surProjectAttendanceUser));
    }

    /**
     * 删除考勤人员基本属性
     */
    @PreAuthorize("@ss.hasPermi('project:attendanceWorker:remove')")
    @Log(title = "考勤人员基本属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surProjectAttendanceUserService.deleteSurProjectAttendanceUserByIds(ids));
    }

    @PostMapping("/queryAttendanceData")
    public TableDataInfo queryAttendanceData(@RequestBody SurProjectAttendanceUser where){
        long cnt=surProjectAttendanceUserService.countAttendance(where);
        List<SurProjectAttendanceUser> list =surProjectAttendanceUserService.queryAttendanceData(where);
        TableDataInfo dataInfo=new TableDataInfo();
        dataInfo.setTotal(cnt);
        dataInfo.setRows(list);
        return dataInfo;
    }
}
