package com.ruoyi.ibs.task.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

import com.github.pagehelper.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.page.TableDataPageInfo;
import com.ruoyi.ibs.task.domain.dto.WorkRecordDTO;
import com.ruoyi.ibs.task.domain.entity.Alter;
import com.ruoyi.ibs.task.domain.entity.WorkRecord;
import com.ruoyi.ibs.task.domain.vo.AlterVO;
import com.ruoyi.ibs.task.domain.vo.WorkCompleteVO;
import com.ruoyi.ibs.task.domain.vo.WorkRecordVO;
import com.ruoyi.ibs.task.service.WorkRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

/**
 * 工作清单记录Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@Api(tags = "工作清单接口")
@RestController
@RequestMapping("/work/record")
public class WorkRecordController extends BaseController {

    @Resource
    private WorkRecordService workRecordService;

    /**
     * 查询我的工作清单
     */
    @GetMapping("/list")
    @Log(title = "工作台-查询我的工作清单")
    @ApiOperation("查询我的工作清单")
    public TableDataPageInfo<WorkRecordVO> list(WorkRecordDTO workRecordDTO) {
        Page<Object> page = startPage();
        List<WorkRecordVO> list = workRecordService.getWorkRecordList(workRecordDTO);
        return getDataTable(list, page);
    }

    /**
     * 批量提交更新工作清单记录
     */
    @PostMapping("/submit")
    @Log(title = "工作台-批量更新工作清单")
    @ApiOperation("批量更新工作清单")
    public AjaxResult batchSubmit(@Validated @RequestBody List<WorkRecord> workRecordList) {
        return toAjax(workRecordService.batchSubmitWorkRecord(workRecordList));
    }

    /**
     * 查询权限内用户工作清单完成情况
     */
    @GetMapping(value = "/complete/status")
    @Log(title = "工作台-查询工作清单完成情况")
    @ApiOperation("查询工作清单完成情况")
    public TableDataPageInfo<WorkCompleteVO> getCompleteStatus(WorkRecordDTO workRecordDTO) {
        return workRecordService.getCompleteStatus(workRecordDTO);
    }

    @GetMapping("/alter/types")
    @Log(title = "工作台-查询预警类型")
    @ApiOperation("查询预警类型")
    public AjaxResult getAlterTypes() {
        return AjaxResult.success(workRecordService.getAlterTypes());
    }

    /**
     * 查询预警信息
     */
    @GetMapping("/alter/list")
    @Log(title = "工作台-查询预警信息")
    @ApiOperation("查询预警信息")
    public TableDataPageInfo<AlterVO> alterList(@RequestParam String status, @RequestParam @NotBlank(message = "预警类型不能为空") String alterType) {
        Page<Object> page = startPage();
        List<AlterVO> list = workRecordService.getAlterList(status, alterType);
        return getDataTable(list, page);
    }

    @PostMapping("/alter/edit")
    @Log(title = "工作台-修改预警信息")
    @ApiOperation("修改预警信息")
    public AjaxResult editAlter(@RequestBody Alter alter) {
        return toAjax(workRecordService.updateAlter(alter));
    }

    @PostMapping("/read")
    @Log(title = "工作台-设置状态为已读")
    @ApiOperation("设置状态为已读")
    public AjaxResult readAlter(@RequestParam Long id) {
        return toAjax(workRecordService.updateReadTime(id));
    }

}
