package com.staffing.web.controller.custom;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.staffing.common.annotation.Log;
import com.staffing.common.core.controller.BaseController;
import com.staffing.common.core.domain.AjaxResult;
import com.staffing.common.enums.BusinessType;
import com.staffing.custom.domain.StTaskSign;
import com.staffing.custom.service.IStTaskSignService;
import com.staffing.common.utils.poi.ExcelUtil;
import com.staffing.common.core.page.TableDataInfo;

/**
 * 签到Controller
 * 
 * @author staffing
 * @date 2024-08-27
 */
@RestController
@RequestMapping("/taskSign/sign")
public class StTaskSignController extends BaseController
{
    @Autowired
    private IStTaskSignService stTaskSignService;

    /**
     * 查询签到列表
     */
    @PreAuthorize("@ss.hasPermi('taskSign:sign:list')")
    @GetMapping("/list")
    public TableDataInfo list(StTaskSign stTaskSign)
    {
        startPage();
        List<StTaskSign> list = stTaskSignService.selectStTaskSignList(stTaskSign);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('taskSign:sign:list')")
    @GetMapping("/selectStTaskSignByTaskIds")
    public TableDataInfo selectStTaskSignByTaskIds(Long taskId)
    {
        startPage();
        List<StTaskSign> list = stTaskSignService.selectStTaskSignByTaskIds(taskId);
        return getDataTable(list);
    }

    /**
     * 导出签到列表
     */
    @PreAuthorize("@ss.hasPermi('taskSign:sign:export')")
    @Log(title = "签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StTaskSign stTaskSign)
    {
        List<StTaskSign> list = stTaskSignService.selectStTaskSignList(stTaskSign);
        for (StTaskSign taskSign : list) {
            if (taskSign.getStatus() == -1){
                taskSign.setStatusStr("未点名");
            }else if (taskSign.getStatus() == 0){
                taskSign.setStatusStr("未签到");
            }else {
                taskSign.setStatusStr("已签到");
            }

        }
        ExcelUtil<StTaskSign> util = new ExcelUtil<StTaskSign>(StTaskSign.class);
        util.exportExcel(response, list, "签到数据");
    }

    /**
     * 获取签到详细信息
     */
    @PreAuthorize("@ss.hasPermi('taskSign:sign:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stTaskSignService.selectStTaskSignById(id));
    }

    /**
     * 新增签到
     */
    @PreAuthorize("@ss.hasPermi('taskSign:sign:add')")
    @Log(title = "签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StTaskSign stTaskSign)
    {
        return toAjax(stTaskSignService.insertStTaskSign(stTaskSign));
    }

    /**
     * 修改签到
     */
    @PreAuthorize("@ss.hasPermi('taskSign:sign:edit')")
    @Log(title = "签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StTaskSign stTaskSign)
    {
        return toAjax(stTaskSignService.updateStTaskSign(stTaskSign));
    }

    /**
     * 删除签到
     */
    @PreAuthorize("@ss.hasPermi('taskSign:sign:remove')")
    @Log(title = "签到", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stTaskSignService.deleteStTaskSignByIds(ids));
    }
}
