package com.dcsoft.system.kq.controller;

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

import com.dcsoft.common.security.utils.SecurityUtils;
import com.dcsoft.system.face.domain.FaceStudent;
import com.dcsoft.system.kq.domain.KqAdjust;
import com.dcsoft.system.kq.service.IKqAdjustService;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;

import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 出勤调整Controller
 *
 * @author nichun
 * @date 2023-06-09
 */
@RestController
@RequestMapping("/kqAdjust")
public class KqAdjustController extends BaseController
{
    @Autowired
    private IKqAdjustService kqAdjustService;

    /**
     * 查询出勤调整列表
     */
    @RequiresPermissions("kq:adjust:list")
    @GetMapping("/list")
    public TableDataInfo list(KqAdjust kqAdjust)
    {
        startPage();
        List<KqAdjust> list = kqAdjustService.selectKqAdjustList(kqAdjust);
        return getDataTable(list);
    }

    /**
     * 导出出勤调整列表
     */
    @RequiresPermissions("kq:adjust:export")
    @Log(title = "出勤调整", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KqAdjust kqAdjust)
    {
        List<KqAdjust> list = kqAdjustService.selectKqAdjustList(kqAdjust);
        ExcelUtil<KqAdjust> util = new ExcelUtil<KqAdjust>(KqAdjust.class);
        util.exportExcel(response, list, "出勤调整数据");
    }

    @Log(title = "人员信息", businessType = BusinessType.IMPORT)
    @RequiresPermissions("kq:adjust:import")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<KqAdjust> util = new ExcelUtil<KqAdjust>(KqAdjust.class);
        List<KqAdjust> userList = util.importExcel(file.getInputStream());
        String operName = SecurityUtils.getUsername();
        String message = kqAdjustService.importkqAdjust(userList, updateSupport, operName);
        return success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<KqAdjust> util = new ExcelUtil<KqAdjust>(KqAdjust.class);
        util.importTemplateExcel(response, "出勤调整数据");
    }




    /**
     * 获取出勤调整详细信息
     */
    @RequiresPermissions("kq:adjust:query")
    @GetMapping(value = "/{adjustId}")
    public AjaxResult getInfo(@PathVariable("adjustId") Long adjustId)
    {
        return success(kqAdjustService.selectKqAdjustByAdjustId(adjustId));
    }

    /**
     * 新增出勤调整
     */
    @RequiresPermissions("kq:adjust:add")
    @Log(title = "出勤调整", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KqAdjust kqAdjust)
    {
        return toAjax(kqAdjustService.insertKqAdjust(kqAdjust));
    }

    /**
     * 修改出勤调整
     */
    @RequiresPermissions("kq:adjust:edit")
    @Log(title = "出勤调整", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KqAdjust kqAdjust)
    {
        return toAjax(kqAdjustService.updateKqAdjust(kqAdjust));
    }

    /**
     * 删除出勤调整
     */
    @RequiresPermissions("kq:adjust:remove")
    @Log(title = "出勤调整", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adjustIds}")
    public AjaxResult remove(@PathVariable Long[] adjustIds)
    {
        return toAjax(kqAdjustService.deleteKqAdjustByAdjustIds(adjustIds));
    }
}
