package com.ruoyi.ibs.task.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.ibs.task.domain.dto.WorkRecordDTO;
import com.ruoyi.ibs.task.domain.dto.WorkTemplateDTO;
import com.ruoyi.ibs.task.domain.entity.WorkRecord;
import com.ruoyi.ibs.task.domain.entity.WorkTemplate;
import com.ruoyi.ibs.task.domain.vo.WorkRecordVO;
import com.ruoyi.ibs.task.domain.vo.WorkTemplateVO;
import com.ruoyi.ibs.task.service.WorkRecordService;
import com.ruoyi.ibs.task.service.WorkTemplateService;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.service.ISysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 工作清单模板Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@Api(tags = "工作清单模板接口")
@RestController
@RequestMapping("/work/template")
public class WorkTemplateController extends BaseController {

    @Resource
    private WorkTemplateService workTemplateService;
    @Resource
    private ISysPostService sysPostService;

    /**
     * 查询工作清单模板列表
     */
    @GetMapping("/list")
    @Log(title = "工作台-查询工作清单模板列表")
    @ApiOperation("查询工作清单模板列表")
    public TableDataPageInfo<WorkTemplateVO> list(WorkTemplateDTO workTemplateDTO) {
        return workTemplateService.getWorkTemplateList(workTemplateDTO);
    }

    /**
     * 新增工作清单模板
     */
    @PostMapping(value = "/insert")
    @Log(title = "工作台-新增工作清单模板")
    @ApiOperation("新增工作清单模板")
    public AjaxResult insert(@Validated @RequestBody WorkTemplate workTemplate) {
        return toAjax(workTemplateService.insertWorkTemplate(workTemplate));
    }

    /**
     * 修改工作清单模板
     */
    @PostMapping(value = "/edit")
    @Log(title = "工作台-修改工作清单模板")
    @ApiOperation("修改工作清单模板")
    public AjaxResult edit(@Validated @RequestBody WorkTemplate workTemplate) {
        return toAjax(workTemplateService.updateWorkTemplate(workTemplate));
    }

    /**
     * 删除工作清单模板
     */
    @PostMapping("/delete")
    @Log(title = "工作台-删除工作清单模板")
    @ApiOperation("删除工作清单模板")
    public AjaxResult remove(@RequestBody Long[] ids) {
        return toAjax(workTemplateService.deleteWorkTemplateByIds(ids));
    }

}
