package com.dcsoft.system.kq.controller;


import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.web.page.TableDataInfo;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.system.kq.domain.KqGroup;
import com.dcsoft.system.kq.service.IKqGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 考勤组Controller
 *
 * @author dcsoft
 * @date 2023-01-05
 */
@RestController
@RequestMapping("/kqGroup")
public class KqGroupController extends BaseController
{
    @Autowired
    private IKqGroupService kqGroupService;

    /**
     * 查询考勤组列表
     */
    @RequiresPermissions("kq:group:list")
    @GetMapping("/list")
    public TableDataInfo list(KqGroup kqGroup)
    {
        startPage();
        List<KqGroup> list = kqGroupService.selectKqGroupList(kqGroup);
        return getDataTable(list);
    }

    /**
     * 查询考勤组列表
     */
    @GetMapping("/tree")
    public TableDataInfo tree(KqGroup kqGroup)
    {
        List<KqGroup> list = kqGroupService.selectKqGroupList(kqGroup);
        return getDataTable(list);
    }

    /**
     * 导出考勤组列表
     */
    @RequiresPermissions("kq:group:export")
    @Log(title = "考勤组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KqGroup kqGroup)
    {
        List<KqGroup> list = kqGroupService.selectKqGroupList(kqGroup);
        ExcelUtil<KqGroup> util = new ExcelUtil<KqGroup>(KqGroup.class);
        util.exportExcel(response, list, "考勤组数据");
    }

    /**
     * 获取考勤组详细信息
     */
    @RequiresPermissions("kq:group:query")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(kqGroupService.selectKqGroupByGroupId(groupId));
    }

    /**
     * 新增考勤组
     */
    @RequiresPermissions("kq:group:add")
    @Log(title = "考勤组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KqGroup kqGroup)
    {
        return toAjax(kqGroupService.insertKqGroup(kqGroup));
    }

    /**
     * 修改考勤组
     */
    @RequiresPermissions("kq:group:edit")
    @Log(title = "考勤组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KqGroup kqGroup)
    {
        return toAjax(kqGroupService.updateKqGroup(kqGroup));
    }

    /**
     * 删除考勤组
     */
    @RequiresPermissions("kq:group:remove")
    @Log(title = "考勤组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(kqGroupService.deleteKqGroupByGroupIds(groupIds));
    }
}
