package cn.cslg.report.controller;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.vo.CompareFilesVO;
import cn.cslg.report.common.model.vo.PatentVO;
import cn.cslg.report.common.model.vo.TaskVO;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.Report;
import cn.cslg.report.entity.Task;
import cn.cslg.report.entity.asso.SyneryCode;
import cn.cslg.report.service.business.CompareFilesService;
import cn.cslg.report.service.business.ReportService;
import cn.cslg.report.service.business.TaskService;
import cn.cslg.report.service.business.asso.SyneryCodeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


@SuppressWarnings({"all"})
@Tag(name = "外部人员调用接口")
@RestController
@RequestMapping(Constants.REPORT_API + "/outSiders")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})

public class OutSidersController {
    private final SyneryCodeService syneryCodeService;
    private final TaskService taskService;
    private final ReportService reportService;
    @RequestMapping(value = "/getTaskByCode", method = RequestMethod.GET)
    @Operation(summary = "根据code码获得任务信息")
    public String getTaskByCode(String code) throws IOException {
        //根据code码获得taskId
        LambdaQueryWrapper<SyneryCode> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SyneryCode::getCode, code);
        List<SyneryCode> syneryCodes = syneryCodeService.list(queryWrapper);
        if (syneryCodes.size() != 0) {
            SyneryCode syneryCode = syneryCodes.get(0);
            //根据taskId获得task信息
            Task task = taskService.getById(syneryCode.getTaskId());
            Report report =reportService.getById(task.getReportId());
            task.setReportType(report.getType());
            return Response.success(task);
        }
        return Response.error("code码输入错误");
    }

    @RequestMapping(value = "/getTaskByCo", method = RequestMethod.GET)
    @Operation(summary = "根据code码获得任务")
    public String getTas() throws IOException {
        String str = "用户表<user><123>";
        String parStr = "\\<([^}]*)\\>";
        Pattern pattern = Pattern.compile(parStr);
        Matcher matcher = pattern.matcher(str);
        List<String> list =new ArrayList<>();
        while(matcher.find()){
       String a = str .substring(0, matcher.start());list.add(matcher.group());
            System.out.println(matcher.group()+":"+a);
        }
        return Response.error("code码输入错误");
    }
}