package com.microservices.dms.resourceLibrary.controller;

import com.microservices.common.core.utils.PageUtils;
import com.microservices.common.core.utils.poi.ExcelUtil;
import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.core.web.page.TableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.dms.resourceLibrary.domain.TaskResourceLibrary;
import com.microservices.dms.resourceLibrary.domain.vo.TaskListVo;
import com.microservices.dms.resourceLibrary.domain.vo.UserActionDataVo;
import com.microservices.dms.resourceLibrary.service.TaskResourceLibraryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "数据管理体系-任务资源库接口")
@RestController
@RequestMapping("/taskResourceLibrary")
@RequiredArgsConstructor
public class TaskResourceLibraryController extends BaseController {

    private final TaskResourceLibraryService taskResourceLibraryService;


    @GetMapping("/selectTaskJournalsCondition")
    @ApiOperation(value = "查询用户评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemType", value = "类型(任务：makerSpaceTask)", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = String.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectTaskJournalsCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectTaskJournalsCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectClickerCondition")
    @ApiOperation(value = "查询用户点击")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemType", value = "类型(任务：makerSpaceTask)", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = String.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectClickerCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectClickerCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectDownloaderCondition")
    @ApiOperation(value = "查询用户下载")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemType", value = "类型(任务：makerSpaceTask)", paramType = "query", dataTypeClass = String.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectDownloaderCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectDownloaderCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectVisitCondition")
    @ApiOperation(value = "查询用户点击")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemType", value = "类型(任务：makerSpaceTask)", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = String.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectVisitCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectVisitCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectPapersCondition")
    @ApiOperation(value = "查询用户交稿")
    public GenericsTableDataInfo<UserActionDataVo> selectPapersCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectPapersCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectWatcherCondition")
    @ApiOperation(value = "查询用户关注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemType", value = "类型(任务：MakerTask)", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = String.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectWatcherCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectWatcherCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectSearcherCondition")
    @ApiOperation(value = "查询用户搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemType", value = "类型(任务：makerSpaceTask)", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = String.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectSearcherCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = taskResourceLibraryService.selectSearcherCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectTaskListCondition")
    @ApiOperation(value = "查询任务列表")
    public GenericsTableDataInfo<TaskListVo> selectTaskListCondition(TaskListVo taskListVo) {
        PageUtils.startPage();
        List<TaskListVo> userActionDataVos = taskResourceLibraryService.selectTaskListCondition(taskListVo);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("/list")
    public TableDataInfo list(TaskResourceLibrary taskResourceLibrary) {
        startPage();
        List<TaskResourceLibrary> list = taskResourceLibraryService.selectTaskResourceLibraryList(taskResourceLibrary);
        return getDataTable(list);
    }


    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskResourceLibrary taskResourceLibrary) {
        List<TaskResourceLibrary> list = taskResourceLibraryService.selectTaskResourceLibraryList(taskResourceLibrary);
        ExcelUtil<TaskResourceLibrary> util = new ExcelUtil<TaskResourceLibrary>(TaskResourceLibrary.class);
        util.exportExcel(response, list, "数据");
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(taskResourceLibraryService.selectTaskResourceLibraryById(id));
    }


    @PostMapping
    public AjaxResult add(@RequestBody TaskResourceLibrary taskResourceLibrary) {
        return AjaxResult.success(taskResourceLibraryService.insertTaskResourceLibrary(taskResourceLibrary));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody TaskResourceLibrary taskResourceLibrary) {
        return AjaxResult.success(taskResourceLibraryService.updateTaskResourceLibrary(taskResourceLibrary));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(taskResourceLibraryService.deleteTaskResourceLibraryByIds(ids));
    }

    @GetMapping(value = "/getTotalTasks")
    @ApiOperation(value = "获取任务总数")
    public AjaxResult getTotalTasks() {
        return success(taskResourceLibraryService.getTotalTasks());
    }

    @GetMapping(value = "/getConvertedTaskAmount")
    @ApiOperation(value = "获取转换成果任务金额")
    public AjaxResult getConvertedTaskAmount() {
        return success(taskResourceLibraryService.getConvertedTaskAmount());
    }

    @GetMapping(value = "/getConvertedTasksCount")
    @ApiOperation(value = "获取任务转换成果数")
    public AjaxResult getConvertedTasksCount() {
        return success(taskResourceLibraryService.getConvertedTasksCount());
    }

    @GetMapping(value = "/getTaskAmount")
    @ApiOperation(value = "获取任务金额")
    public AjaxResult getTaskAmount() {
        return success(taskResourceLibraryService.getTaskAmount());
    }

    @GetMapping(value = "/getReviewTaskCount")
    @ApiOperation(value = "需评审任务数")
    public AjaxResult getReviewTaskCount() {
        return success(taskResourceLibraryService.getReviewTaskCount());
    }
}
