package com.dayou.controller;

import com.dayou.dto.AssetsSelectDTO;
import com.dayou.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.workflow.IWorkTaskRecordService;
import com.dayou.entity.WorkTaskRecord;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作流任务记录
 *
 * @author wucl
 * @since 2023-10-17
 */
@RestController
@RequestMapping("workTaskRecord")
@Slf4j
public class WorkTaskRecordController extends BaseController {
    @Autowired
    private IWorkTaskRecordService workTaskRecordService;

    /**
    * 工作流任务记录列表
    */
    @GetMapping("")
    public RestResponse<Page<WorkTaskRecord>> page(WorkTaskRecord workTaskRecord, Page page){
        Page<WorkTaskRecord> pages=workTaskRecordService.selectPage(page,workTaskRecord);
        return RestResponse.data(pages);
    }

    /**
     * 工作流任务记录详情
     */
    @GetMapping("/{id}")
    public RestResponse<WorkTaskRecord> detail(@PathVariable Long id){
        WorkTaskRecord xWorkTaskRecord =workTaskRecordService.detail(id);
        return RestResponse.data(xWorkTaskRecord);
     }

    /**
     * 工作流任务记录新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody WorkTaskRecord workTaskRecord) {
        Boolean ret = workTaskRecordService.add(workTaskRecord);
        return RestResponse.data(ret);
    }

    /**
     * 工作流任务记录更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody WorkTaskRecord workTaskRecord) {
        Boolean ret = workTaskRecordService.update(workTaskRecord);
        return RestResponse.data(ret);
    }

    /**
     * 工作流任务记录删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = workTaskRecordService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 获取实例节点上的任务信息
     * @param instanceId
     * @return
     */
    @GetMapping("/instance/{instanceId}")
    public RestResponse<List<WorkTaskRecordVO>> getInstanceTask(@PathVariable("instanceId") Long instanceId){
        List<WorkTaskRecordVO> ret = workTaskRecordService.getInstanceTask(instanceId);
        return RestResponse.data(ret);
    }

    /**
     * 大中型业务我的待办
     * @param todoVO
     * @param page
     * @param keyword
     * @return
     */
    @GetMapping("/major/todo")
    public RestResponse<Page<TaskTodoVO>> taskTodoPage(TaskTodoVO todoVO, Page page,String keyword){
        Page<TaskTodoVO> ret = workTaskRecordService.majorTaskTodoPage(todoVO,page,keyword);
        return RestResponse.data(ret);
    }

    /**
     * 大中型业务我的已办
     * @param doneVO
     * @param page
     * @return
     */
    @GetMapping("/major/done")
    public RestResponse<Page<MajorTaskDoneVO>> taskDonePage(MajorTaskDoneVO doneVO, Page page,String keyword){
        Page<MajorTaskDoneVO> ret = workTaskRecordService.majorTaskDonePage(doneVO,page,keyword);
        return RestResponse.data(ret);
    }

    /**
     * 个贷业务我的待办
     * @param todoVO
     * @param page
     * @param keyword
     * @return
     */
    @GetMapping("/personal/todo")
    public RestResponse<Page<PersonalTodoVO>> personalTodoPage(PersonalTodoVO todoVO, Page page, String keyword){
        Page<PersonalTodoVO> ret = workTaskRecordService.personalTodoPage(todoVO,page,keyword);
        return RestResponse.data(ret);
    }

    /**
     * 个贷业务我的已办
     * @param doneVO
     * @param page
     * @return
     */
    @GetMapping("/personal/done")
    public RestResponse<Page<PersonalTaskDoneVO>> personalTaskDonePage(PersonalTaskDoneVO doneVO, Page page, String keyword){
        Page<PersonalTaskDoneVO> ret = workTaskRecordService.personalTaskDonePage(doneVO,page,keyword);
        return RestResponse.data(ret);
    }

    /**
     * 综合首页大中型待办
     * @return
     */
    @GetMapping("/major/todo/simple")
    public RestResponse<List<TaskTodoVO>> majorTodoSimpleList(){
        List<TaskTodoVO> ret = workTaskRecordService.majorTodoSimpleList();
        return RestResponse.data(ret);
    }

    /**
     * 综合首页个贷待办
     * @return
     */
    @GetMapping("/personal/todo/simple")
    public RestResponse<List<PersonalTodoVO>> personalTodoSimpleList(){
        List<PersonalTodoVO> ret = workTaskRecordService.personalTodoSimpleList();
        return RestResponse.data(ret);
    }

    /**
     * 获取各业务待办总数
     * @return
     */
    @GetMapping("/todoNum")
    public RestResponse<List<BusinessTodoNum>> getTodoTotalNum(){
        List<BusinessTodoNum> totalNums = workTaskRecordService.getTodoTotalNum();
        return RestResponse.data(totalNums);
    }

    /**
     * 获取资产业务已办列表
     * @param assetsSelectDTO 查询dto
     * @param page 分页
     * @return RestResponse<List<AssetsTaskDoneVO>>
     */
    @GetMapping("/assets/getAssetsTaskDoneList")
    public RestResponse<Page<AssetsTaskDoneVO>> getAssetsTaskDoneList(AssetsSelectDTO assetsSelectDTO, Page page) {
        return RestResponse.data(workTaskRecordService.getAssetsTaskDoneList(assetsSelectDTO, page));
    }


    /**
     * 个贷业务我的待办(入库)
     * @param nodeCode
     * @return
     */
    @GetMapping("/personal/inRep/todo")
    public RestResponse<List<PersonalTodoVO>> personalInRepTodoList(String nodeCode,String clientName){
        List<PersonalTodoVO> ret = workTaskRecordService.personalInRepTodoList(nodeCode,clientName);
        return RestResponse.data(ret);
    }

    /**
     * 个贷业务我的待办(出库)
     * @param nodeCode
     * @return
     */
    @GetMapping("/personal/outRep/todo")
    public RestResponse<List<PersonalTodoVO>> personalOutRepTodoList(String nodeCode,String clientName){
        List<PersonalTodoVO> ret = workTaskRecordService.personalOutRepTodoList(nodeCode,clientName);
        return RestResponse.data(ret);
    }
}

