package com.fs.company.controller.qw;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.qw.domain.QwWorkTask;
import com.fs.qw.param.QwWorkTaskListParam;
import com.fs.qw.service.IQwWorkTaskService;
import com.fs.qw.vo.QwWorkTaskListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 企微任务看板Controller
 *
 * @author fs
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/qw/QwWorkTask")
public class QwWorkTaskController extends BaseController
{
    @Autowired
    private IQwWorkTaskService qwWorkTaskService;
    @Autowired
    private TokenService tokenService;
    /**
     * 查询企微任务看板列表
     */
    @PreAuthorize("@ss.hasPermi('qw:QwWorkTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwWorkTaskListParam qwWorkTask)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        qwWorkTask.setCompanyId(loginUser.getCompany().getCompanyId());
        qwWorkTask.setCompanyUserId(loginUser.getUser().getUserId());
        List<QwWorkTaskListVO> list = qwWorkTaskService.selectQwWorkTaskListVO(qwWorkTask);
        return getDataTable(list);
    }

    /**
     * 导出企微任务看板列表
     */
    @PreAuthorize("@ss.hasPermi('qw:QwWorkTask:export')")
    @Log(title = "企微任务看板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwWorkTask qwWorkTask)
    {
        List<QwWorkTask> list = qwWorkTaskService.selectQwWorkTaskList(qwWorkTask);
        ExcelUtil<QwWorkTask> util = new ExcelUtil<QwWorkTask>(QwWorkTask.class);
        return util.exportExcel(list, "企微任务看板数据");
    }

    /**
     * 获取企微任务看板详细信息
     */
    @PreAuthorize("@ss.hasPermi('qw:QwWorkTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwWorkTaskService.selectQwWorkTaskById(id));
    }

    /**
     * 新增企微任务看板
     */
    @PreAuthorize("@ss.hasPermi('qw:QwWorkTask:add')")
    @Log(title = "企微任务看板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwWorkTask qwWorkTask)
    {
        return toAjax(qwWorkTaskService.insertQwWorkTask(qwWorkTask));
    }

    /**
     * 修改企微任务看板
     */
    @PreAuthorize("@ss.hasPermi('qw:QwWorkTask:edit')")
    @Log(title = "企微任务看板处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwWorkTask qwWorkTask)
    {
        QwWorkTask task = new QwWorkTask();
        task.setId(qwWorkTask.getId());
        task.setRemark(qwWorkTask.getRemark());
        task.setStatus(1);
        task.setUpdateTime(new Date());
        return toAjax(qwWorkTaskService.updateQwWorkTask(task));
    }

    /**
     * 删除企微任务看板
     */
    @PreAuthorize("@ss.hasPermi('qw:QwWorkTask:remove')")
    @Log(title = "企微任务看板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwWorkTaskService.deleteQwWorkTaskByIds(ids));
    }
}
