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

import com.huashe.common.domain.AjaxResult;
import com.huashe.park.core.service.IParkAttendGroupService;
import com.huashe.park.domain.entity.ParkAttendGroup;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
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/attendGroup")
public class ParkAttendGroupController extends BaseController {
    @Autowired
    private IParkAttendGroupService parkAttendGroupService;

    /**
     * 查询考勤组列表
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkAttendGroup parkAttendGroup) {
        startPage();
        List<ParkAttendGroup> list = parkAttendGroupService.selectParkAttendGroupList(parkAttendGroup);
        return getDataTable(list);
    }

    /**
     * 导出考勤组列表
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroup:export')")
    @Log(title = "考勤组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkAttendGroup parkAttendGroup) {
        List<ParkAttendGroup> list = parkAttendGroupService.selectParkAttendGroupList(parkAttendGroup);
        ExcelUtil<ParkAttendGroup> util = new ExcelUtil<ParkAttendGroup>(ParkAttendGroup.class);
        util.exportExcel(response, list, "考勤组数据");
    }

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

    /**
     * 新增考勤组
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroup:add')")
    @Log(title = "考勤组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkAttendGroup parkAttendGroup) {
        return toAjax(parkAttendGroupService.insertParkAttendGroup(parkAttendGroup));
    }

    /**
     * 修改考勤组
     */
    @PreAuthorize("@ss.hasPermi('park:attendGroup:edit')")
    @Log(title = "考勤组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkAttendGroup parkAttendGroup) {
        return toAjax(parkAttendGroupService.updateParkAttendGroup(parkAttendGroup));
    }

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