package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.vo.LoginVO;
import cn.cslg.report.common.model.vo.PatentVO;
import cn.cslg.report.common.model.vo.PersonnelVO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.service.BaseService;
import cn.cslg.report.service.OutInterfaceService;
import cn.cslg.report.service.business.SystemDictItemService;
import cn.dev33.satoken.stp.StpUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author 沈永艺
 * @date 2022-10-31
 * @description 基础功能 Controller 层
 */

@Tag(name = "基础功能")
@RestController
@RequestMapping(Constants.REPORT_API)
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class BaseController {
    private final BaseService baseService;
    private final SystemDictItemService systemDictItemService;
    private final OutInterfaceService outInterfaceService;

    @PostMapping("/login")
    @Operation(summary = "登录")
    public String login(@RequestBody LoginVO loginVO) throws IOException {
        return baseService.login(loginVO);
    }

    @PostMapping("/logout")
    @Operation(summary = "登出")
    public String logout() {
        StpUtil.logout();
        return Response.success(true);
    }

    @GetMapping("/verifyCode")
    @Operation(summary = "生成验证码")
    public String verifyCode() {
        return baseService.verifyCode();
    }

    @GetMapping("/getUserInfo")
    @Operation(summary = "获取用户信息")
    public String getUserInfo() {
        return baseService.getUserInfo();
    }

    @GetMapping("/getDictMessage")
    @Operation(summary = "获取PCS字典项信息")
    public String getDictMessage() {
        return baseService.getDictMessage();
    }

    @GetMapping("/getPermissionList")
    @Operation(summary = "获取权限列表")
    public String getPermissionList(String code) {
        return baseService.getPermissionList(code);
    }

    @GetMapping("/getAllDepartment")
    @Operation(summary = "获取所有部门")
    public String getAllDepartment() {
        return baseService.getAllDepartment();
    }

    @GetMapping("/getPartDepartment")
    @Operation(summary = "获取部分部门")
    public String getPartDepartment() {
        return baseService.getPartDepartment();
    }

    @GetMapping("/getAllPersonnel")
    @Operation(summary = "获取所有人员")
    public String getAllPersonnel() {
        return baseService.getAllPersonnel();
    }

    @PostMapping("/getPartPersonnel")
    @Operation(summary = "分页查询人员")
    public String getPartPersonnel(@RequestBody PersonnelVO personnelVO) {
        return baseService.getPartPersonnel(personnelVO);
    }
    @GetMapping("/getPartPersonnelID")
    @Operation(summary = "根据人员id查人员")
    public String getAllPersonnelId (Integer ID)throws IOException {
        return baseService.getPartPersonnelID(ID);
    }

    @GetMapping("/getAllClient")
    @Operation(summary = "获取所有客户")
    public String getAllClient() {
        return baseService.getAllClient();
    }

    @GetMapping("/getPartClient")
    @Operation(summary = "获取部分客户")
    public String getPartClient() {
        return baseService.getPartClient();
    }
    @GetMapping("/getSystemDicItem")
    @Operation(summary = "获取本系统字典项")
    public String getSystemDicItem() {
        return  systemDictItemService.getSystemKey();
    }


    @GetMapping("/getPatentByPatentNo")
    @Operation(summary = "根据专利号获得专利")
    @Parameters(value = {
            @Parameter(name = "patentNo",description = "专利号",required = true),

    })
    public String getPatentByPatentNo(String patentNo) throws IOException {
        return  outInterfaceService.getPatentFromPAS(patentNo);
    }

    @GetMapping("/getPatentNos")
    @Operation(summary = "根据专题库Id获得专利")
    @Parameters(value = {
            @Parameter(name = "projectId",description = "专题库Id",required = true),

    })
    public String getPatentNos(Integer projectId) throws IOException {
        return  outInterfaceService.getPatentNos(projectId);
    }

    @GetMapping("/getDictsFromPAS")
    @Operation(summary = "获得PAS场景信息")

    public String getDictsFromPAS() throws IOException {
        return  outInterfaceService.getDictsFromPAS();

    }


    @PostMapping("/getPatentFromPAS")
    @Operation(summary = "根据报告Id查询对比文件（分页）")
    public String getPatentNos(@RequestBody PatentVO patentVO) throws IOException {
        return  outInterfaceService.getPatentFromPAS(patentVO,0);
    }

    @PostMapping("/getComPatentNos")
    @Operation(summary = "根据报告Id获得对比专利号")
    public String getComPatentNos(@RequestBody PatentVO patentVO) throws IOException {
        return  outInterfaceService.getComPatentNos(patentVO);
    }



}
