package com.huashe.park.application.web.controller.park;

import com.huashe.park.core.service.IParkAttendGroupUsrService;
import com.huashe.park.domain.entity.ParkAttendGroupUsr;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 考勤组人员Controller
 *
 * @author ruoyi
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/park/attendGroupUsr")
public class ParkAttendGroupUsrController extends BaseController {
    @Autowired
    private IParkAttendGroupUsrService parkAttendGroupUsrService;

    /**
     * 查询考勤组人员列表
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkAttendGroupUsr parkAttendGroupUsr) {
        startPage();
        List<ParkAttendGroupUsr> list = parkAttendGroupUsrService.selectParkAttendGroupUsrList(parkAttendGroupUsr);
        return getDataTable(list);
    }

    /**
     * 导出考勤组人员列表
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:export')")
    @Log(title = "考勤组人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkAttendGroupUsr parkAttendGroupUsr) {
        List<ParkAttendGroupUsr> list = parkAttendGroupUsrService.selectParkAttendGroupUsrList(parkAttendGroupUsr);
        ExcelUtil<ParkAttendGroupUsr> util = new ExcelUtil<ParkAttendGroupUsr>(ParkAttendGroupUsr.class);
        util.exportExcel(response, list, "考勤组人员数据");
    }

    /**
     * 获取考勤组人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(parkAttendGroupUsrService.selectParkAttendGroupUsrById(id));
    }

    /**
     * 新增考勤组人员
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:add')")
    @Log(title = "考勤组人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkAttendGroupUsr parkAttendGroupUsr) {
        return toAjax(parkAttendGroupUsrService.insertParkAttendGroupUsr(parkAttendGroupUsr));
    }

    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:add')")
    @Log(title = "批量添加考勤组人员", businessType = BusinessType.INSERT)
    @PostMapping("/addGroupUsr")
    public AjaxResult batchAddUsr(@RequestBody List<ParkAttendGroupUsr> parkAttendGroupUsr) {
        parkAttendGroupUsrService.insertParkAttendGroupUsrBatch(parkAttendGroupUsr);
        return success();
    }

    /**
     * 修改考勤组人员
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:edit')")
    @Log(title = "考勤组人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkAttendGroupUsr parkAttendGroupUsr) {
        return toAjax(parkAttendGroupUsrService.updateParkAttendGroupUsr(parkAttendGroupUsr));
    }

    /**
     * 删除考勤组人员
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroupUsr:remove')")
    @Log(title = "考勤组人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(parkAttendGroupUsrService.deleteParkAttendGroupUsrByIds(ids));
    }
}
