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.dms.resourceLibrary.domain.ProjectResourceLibrary;
import com.microservices.dms.resourceLibrary.domain.vo.ProjectListVo;
import com.microservices.dms.resourceLibrary.domain.vo.TaskListVo;
import com.microservices.dms.resourceLibrary.domain.vo.UserActionDataVo;
import com.microservices.dms.resourceLibrary.service.ProjectResourceLibraryService;
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("/projectResourceLibrary/")
@RequiredArgsConstructor
public class ProjectResourceLibraryController extends BaseController {

    private final ProjectResourceLibraryService projectResourceLibraryService;

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

    @GetMapping("selectCodeCommitCondition")
    @ApiOperation(value = "查询用户提交")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectCodeCommitCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = projectResourceLibraryService.selectCodeCommitCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectForkCondition")
    @ApiOperation(value = "查询用户Fork")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectForkCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = projectResourceLibraryService.selectForkCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectIssueCondition")
    @ApiOperation(value = "查询用户Issue")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectIssueCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = projectResourceLibraryService.selectIssueCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectPRCondition")
    @ApiOperation(value = "查询用户PR")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectPRCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = projectResourceLibraryService.selectPRCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectPraisesCondition")
    @ApiOperation(value = "查询用户点赞")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemType", value = "类型(Project)", paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "itemId", value = "对象ID", paramType = "query", dataTypeClass = Integer.class),
    })
    public GenericsTableDataInfo<UserActionDataVo> selectPraisesCondition(UserActionDataVo taskJournals) {
        PageUtils.startPage();
        List<UserActionDataVo> userActionDataVos = projectResourceLibraryService.selectPraisesCondition(taskJournals);
        return PageUtils.toPage(userActionDataVos);
    }

    @GetMapping("selectProjectListCondition")
    @ApiOperation(value = "查询项目统计列表")
    public GenericsTableDataInfo<ProjectListVo> selectProjectListCondition(ProjectListVo projectListVo) {
        PageUtils.startPage();
        List<ProjectListVo> userActionDataVos = projectResourceLibraryService.selectProjectListCondition(projectListVo);
        return PageUtils.toPage(userActionDataVos);
    }

    @ApiOperation(value = "查询项目资源库-列表")
    @GetMapping(value = "/list")
    public TableDataInfo list(ProjectResourceLibrary projectResourceLibrary) {
        startPage();
        List<ProjectResourceLibrary> list = projectResourceLibraryService.selectProjectResourceLibraryList(projectResourceLibrary);
        return getDataTable(list);
    }


    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectResourceLibrary projectResourceLibrary) {
        List<ProjectResourceLibrary> list = projectResourceLibraryService.selectProjectResourceLibraryList(projectResourceLibrary);
        ExcelUtil<ProjectResourceLibrary> util = new ExcelUtil<ProjectResourceLibrary>(ProjectResourceLibrary.class);
        util.exportExcel(response, list, "数据");
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody ProjectResourceLibrary projectResourceLibrary) {
        return AjaxResult.success(projectResourceLibraryService.insertProjectResourceLibrary(projectResourceLibrary));
    }


    @PutMapping
    public AjaxResult edit(@RequestBody ProjectResourceLibrary projectResourceLibrary) {
        return AjaxResult.success(projectResourceLibraryService.updateProjectResourceLibrary(projectResourceLibrary));
    }

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


    @ApiOperation(value = "项目转换成果数")
    @GetMapping(value = "/getTotalConversionCount")
    public AjaxResult getTotalConversionCount() {
        return success(projectResourceLibraryService.getTotalConversionCount());
    }

    @ApiOperation(value = "项目公开数")
    @GetMapping(value = "/getPublicProjectCount")
    public AjaxResult getPublicProjectCount() {
        return success(projectResourceLibraryService.getPublicProjectCount());
    }

    @ApiOperation(value = "项目发布版本数")
    @GetMapping(value = "/getTotalReleaseCount")
    public AjaxResult getTotalReleaseCount() {
        return success(projectResourceLibraryService.getTotalReleaseCount());
    }

    @ApiOperation(value = "项目总数")
    @GetMapping(value = "/getTotalProjectCount")
    public AjaxResult getTotalProjectCount() {
        return success(projectResourceLibraryService.getTotalProjectCount());
    }


}
