package com.unis.module.coding.controller.admin.task;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.unis.framework.common.pojo.CommonResult;
import com.unis.module.coding.controller.admin.task.vo.*;
import com.unis.module.coding.service.task.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static com.unis.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - app 任务列表")
@RestController
@RequestMapping("/delivery/task")
@Validated
public class TaskController {

    @Resource
    private TaskService taskService;

    @PostMapping("/getTaskList")
    @Operation(summary = "获取我的任务列表")
    public CommonResult<IPage<TaskRespVO>> getTaskList(@Valid @RequestBody TaskPageReqVO pageReqVO) {
        return success(taskService.getTaskList(pageReqVO));
    }

    @PostMapping("/getAllStoreroomList")
    @Operation(summary = "获取存粮人可以选择的交收库列表(存粮人)")
    public CommonResult<IPage<TaskRespVO>> getAllStoreroomList(@Valid @RequestBody TaskPageReqVO pageReqVO) {
        pageReqVO.setListType(TaskPageReqVO.LIST_TYPE_TASK3);
        return success(taskService.getAllStoreroomList(pageReqVO));
    }

    @PostMapping("/getMyStoreroomList")
    @Operation(summary = "获取存粮人选择的交收库列表(存粮人)")
    public CommonResult<IPage<TaskRespVO>> getMyStoreroomList(@Valid @RequestBody TaskPageReqVO pageReqVO) {
        return success(taskService.getMyStoreroomList(pageReqVO));
    }

    @PostMapping("/getTasks")
    @Operation(summary = "领取/核验任务(多个):参数:kqIds列表,hyState:核验状态(0:待查验,1:查验通过,2:查验不通过3:核验中)")
    public CommonResult<Boolean> getTasks(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getTasks(reqVO));
    }

    @PostMapping("/getStoreroom")
    @Operation(summary = "选择交收库(存粮人)")
    public CommonResult<Boolean> getStoreroom(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getStoreroom(reqVO));
    }

    @PostMapping("/getCaxxByKqId")
    @Operation(summary = "获取仓房列表信息(根据库区id 查询仓房列表-不分页)")
    public CommonResult<List<TaskCaxxRespVO>> getCaxxByKqId(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getCaxxByKqId(reqVO));
    }

    @PostMapping("/getCaxxByKqIdForClr")
    @Operation(summary = "存粮人获取仓房列表信息(根据库区id 查询仓房列表-不分页)(存粮人)")
    public CommonResult<List<TaskCaxxRespVO>> getCaxxByKqIdForClr(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getCaxxByKqIdForClr(reqVO));
    }

    @PostMapping("/getKqxxByKqId")
    @Operation(summary = "获取库区信息(根据库区id)")
    public CommonResult<TaskKqxxRespVO> getKqxxByKqId(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getKqxxByKqId(reqVO));
    }

    @PostMapping("/getCwxxByKqId")
    @Operation(summary = "获取财务信息(根据库区id)")
    public CommonResult<TaskCwxxRespVO> getCwxxByKqId(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getCwxxByKqId(reqVO));
    }

    @PostMapping("/getDkxxByKqId")
    @Operation(summary = "获取打卡信息(根据库区id&userId)")
    public CommonResult<TaskDkxxRespVO> getDkxxByKqId(@RequestBody TaskPageReqVO reqVO) {
        return success(taskService.getDkxxByKqId(reqVO));
    }

    @PostMapping("/setDkxxByKqId")
    @Operation(summary = "打卡(传 id 是变更(传图片),不传 id 是新增")
    public CommonResult<TaskDkxxRespVO> setDkxxByKqId(@RequestBody TaskDkxxSaveVO saveVO) {
        return success(taskService.setDkxxByKqId(saveVO));
    }

    @GetMapping("/getHwkByCfId")
    @Operation(summary = "根据仓房获得[货位卡]信息")
    @Parameter(name = "cfId", description = "仓房id", required = true, example = "1024")
    public CommonResult<TaskHwkRespVO> getHwkByCfId(@RequestParam("cfId") Long cfId) {
        return success(taskService.getHwkByCfId(cfId));
    }

    @GetMapping("/getSyxxByCfId")
    @Operation(summary = "根据仓房获得[损益信息]信息")
    @Parameter(name = "cfId", description = "仓房id", required = true, example = "1024")
    public CommonResult<TaskSyxxRespVO> getSyxxByCfId(@RequestParam("cfId") Long cfId) {
        return success(taskService.getSyxxByCfId(cfId));
    }

    @GetMapping("/getLqjcxxByCfId")
    @Operation(summary = "根据仓房获得[粮情检测]信息")
    @Parameter(name = "cfId", description = "仓房id", required = true, example = "1024")
    public CommonResult<TaskLqjcxxRespVO> getLqjcxxByCfId(@RequestParam("cfId") Long cfId) {
        return success(taskService.getLqjcxxByCfId(cfId));
    }

    @PostMapping("/getCrkxxByCfId")
    @Operation(summary = "根据仓房获得[出入库]信息列表")
    public CommonResult<IPage<TaskCrkxxRespVO>> getCrkxxByCfId(@RequestBody TaskPageReqVO pageReqVO) {
        return success(taskService.getCrkxxByCfId(pageReqVO));
    }

    @PostMapping("/getZjxxByCfId")
    @Operation(summary = "根据仓房获得[质检]信息列表")
    public CommonResult<IPage<TaskZjxxRespVO>> getZjxxByCfId(@RequestBody TaskPageReqVO pageReqVO) {
        return success(taskService.getZjxxByCfId(pageReqVO));
    }
}