package cn.cslg.report.controller;


import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.*;
import cn.cslg.report.common.model.delete.PatentList;
import cn.cslg.report.common.model.delete.Patents;
import cn.cslg.report.common.model.vo.*;
import cn.cslg.report.common.utils.DataUtils;
import cn.cslg.report.common.utils.DateUtils;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.common.utils.StringUtils;
import cn.cslg.report.entity.*;
import cn.cslg.report.entity.asso.AssoRecordsFeature;
import cn.cslg.report.service.BaseService;
import cn.cslg.report.service.OutInterfaceService;
import cn.cslg.report.service.business.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.poi.hssf.record.Record;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Tag(name = "任务管理")
@RestController
@RequestMapping(Constants.REPORT_API + "/task")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})

public class TaskController {

    private final TaskService taskService;
    private final BaseService baseService;

    @RequestMapping(value = "/deleteTask", method = RequestMethod.POST)
    @Operation(summary = "删除任务")
    public String deleteTask(Integer id) {
        return taskService.deleteTask(id);
    }

    @RequestMapping(value = "/updateTask", method = RequestMethod.POST)
    @Operation(summary = "修改任务")
    public String updateTask(@RequestBody Task task) {
        return taskService.updateTask(task);
    }

    @RequestMapping(value = "/queryPageList", method = RequestMethod.POST)
    @Operation(summary = "分页查询任务列表")
    public String queryPageList(@RequestBody TaskVO taskVO) {
        return taskService.queryPageList(taskVO);
    }

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    @Operation(summary = "获取所有任务")
    public String getAllTask() {
        return taskService.getAllTask();
    }

    @RequestMapping(value = "/addTask", method = RequestMethod.POST)
    @Operation(summary = "新增审核任务")
    public String addTask( TaskVO taskVO,List<MultipartFile> file) throws ParseException, IOException {
        return taskService.addTask(taskVO,file);
    }

    @RequestMapping(value = "/auditTask", method = RequestMethod.POST)
    @Operation(summary = "审核任务")
    public String auditTask(@RequestBody AuditTaskVO auditTaskVO) throws ParseException, IOException {
        return taskService.auditTask(auditTaskVO);
    }

//    @RequestMapping(value = "/test", method = RequestMethod.GET)
//    @Operation(summary = "测试")
//    public String test(String text1, String text2) throws ParseException, IOException {
//        float a = DataUtils.getSimilarityRatio(text1, text2);
//        return Response.success("相似度" + a);
//    }

    @RequestMapping(value = "/addAssTask", method = RequestMethod.POST)
    @Operation(summary = "添加分配任务")
    public String addAssTask(@RequestBody AssignTaskVO assignTaskVO) throws ParseException, IOException {
        return taskService.addAssTask(assignTaskVO);
    }

    @RequestMapping(value = "/reTaskPatents", method = RequestMethod.POST)
    @Operation(summary = "返回任务专利清单")
    public String reTaskPatents(@RequestBody TaskVO taskVO) throws ParseException, IOException {
        return taskService.reTaskPatents(taskVO);
    }

    @RequestMapping(value = "/import", method = RequestMethod.GET)
    @Operation(summary = "导入")
    public String importPatent(MultipartFile file, Integer reportId) throws ParseException, IOException {
        //解析file装载数据
        TaskParams taskParams = baseService.getImportPatentTaskParamsBro(file, reportId);
        return Response.success();
    }
}
