package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.PatentCell;
import cn.cslg.pas.common.model.QueryPatentVO;
import cn.cslg.pas.common.model.vo.PatentVO;
import cn.cslg.pas.common.model.vo.TaskVO;
import cn.cslg.pas.common.utils.FileUtils;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.domain.Patent;
import cn.cslg.pas.domain.ProjectField;
import cn.cslg.pas.domain.SystemDict;
import cn.cslg.pas.mapper.PatentMapper;
import cn.cslg.pas.service.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
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.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 任务 前端控制器
 * </p>
 *
 * @author 王岩
 * @since 2022-02-17
 */
@Tag(name = "外部调用接口")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/system")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class SystemController {

    private final SystemDictService systemDictService;
    private final PatentService patentService;
    private final PatentFieldService patentFieldService;
    private final UploadPatentBatchService uploadPatentBatchService;

    @PostMapping("dict")
    @Operation(summary = "根据类型获得字典")
    public String getPageList(@RequestBody List<String> dicts) {
        List<SystemDict> systemDictList = systemDictService.getSystemDictListByType(dicts);
//        Arrays.asList(Constants.ENTERPRISE_APPLICATION_SCENARIO)
        return Response.success(systemDictList);
    }

    @PostMapping("patentList")
    @Operation(summary = "专利列表")
    public String getList(@RequestBody QueryPatentVO params) {
        return Response.success(patentService.getPageListForRMS(params));
    }

    @PostMapping("getComPantentNos")
    @Operation(summary = "获得对比专利号")
    public String getComPantentNos(@RequestBody QueryPatentVO params) {
        return patentService.getComPantentNos(params);
    }

    @PostMapping("getConPantentNos")
    @Operation(summary = "获得条件过滤的专利号")
    public String getConPantentNos(@RequestBody QueryPatentVO params) {
        return patentService.getConPantentNos(params);
    }

    @PostMapping("getConPantents")
    @Operation(summary = "获得条件过滤的专利")
    public String getConPantents(@RequestBody QueryPatentVO params) {
        return patentService.getConPantents(params);
    }

    @PostMapping("getPatentDTOListForRMS")
    @Operation(summary = "获得所有对比文件详细信息")
    public String getPatentDTOListForRMS(@RequestBody PatentVO params) {
        return Response.success(patentService.getPatentDTOListForRMS(params));
    }

    @GetMapping("field/list")
    @Operation(summary = "自定义字段列表")
    public String getFieldList(Integer projectId) {
        return Response.success(patentFieldService.getPageList(projectId));
    }

    @PostMapping("/patentCellTODb")
    @Operation(summary = "专利上传到数据库")
    public String getPatentDTOListForRMS(@RequestBody PatentCell patentCell) throws ParseException {
        uploadPatentBatchService.dataToDBCell(patentCell);
        return Response.success();

    }
}

