package com.zcloud.safetyDutyList.web.tasklist;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.safetyDutyList.api.tasklist.TaskListServiceI;
import com.zcloud.safetyDutyList.dto.clientobject.tasklist.TaskListIssueCO;
import com.zcloud.safetyDutyList.dto.tasklist.TaskListIssuePageQry;
import com.zcloud.safetyDutyList.dto.tasklist.TaskListPageQry;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 清单下发记录控制器
 * <p>
 * 提供清单下发记录的查询接口，
 * 委托TaskListServiceI处理业务逻辑。
 */
@Api(tags = "清单下发记录")
@RequestMapping("/${application.gateway}/taskListIssue")
@RestController
@AllArgsConstructor
public class TaskListIssueController {
    private final TaskListServiceI taskListService;

    @ApiOperation("获取清单下发记录列表")
    @PostMapping("/list")
    public PageResponse<TaskListIssueCO> listPage(@Validated @RequestBody TaskListIssuePageQry qry) {
        return taskListService.listIssuePage(qry);
    }

    @ApiOperation("获取清单下发记录详情")
    @GetMapping("/{taskIssueId}")
    public SingleResponse<TaskListIssueCO> getByTaskIssueId(@PathVariable String taskIssueId) {
        return taskListService.getIssueByTaskIssueId(taskIssueId);
    }

    @ApiOperation("关闭任务 - 清单下发记录详情")
    @GetMapping("close/{taskIssueId}")
    public SingleResponse closeTaskIssueId(@PathVariable String taskIssueId) {
        return taskListService.close(taskIssueId);
    }

    @ApiOperation("统计执行者为指定用户的下发记录数量")
    @GetMapping("/countByExecuteUserId")
    public SingleResponse<Long> countByExecuteUserId(@RequestParam Long userId) {
        return taskListService.countIssueByExecuteUserId(userId);
    }
}
