package cn.cslg.report.service.business;

import cn.cslg.report.common.core.base.Constants;
import cn.cslg.report.common.model.vo.PatentVO;
import cn.cslg.report.common.utils.LogExceptionUtil;
import cn.cslg.report.common.utils.Response;
import cn.cslg.report.entity.SysDictItem;
import cn.cslg.report.entity.asso.AssoTaskPersonel;
import cn.cslg.report.mapper.AssoTaskPersonelMapper;
import cn.cslg.report.mapper.SystemDictItemMapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.sql.Wrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class AssoTaskPersonelService extends ServiceImpl<AssoTaskPersonelMapper, AssoTaskPersonel> {
   public final  AssoTaskPersonelMapper assoTaskPersonelMapper ;
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    @Value("${PCSUrl}")
    private String PCSUrl;
    @Value("${PASUrl}")
    private String PASUrl;
    public  void test(){}
    public String deleAssoTaskPersonel(Integer reportId) throws IOException{
        AssoTaskPersonel assoTaskPersonel =new AssoTaskPersonel();
        LambdaQueryWrapper<AssoTaskPersonel> wrappers =new LambdaQueryWrapper();
        wrappers.eq(AssoTaskPersonel::getReportId,reportId);
         this.remove(wrappers);
        return Response.success();
    }
    public String pagination(int personelId , int  state, int taskId,int location)throws IOException{

        List<String> patentNumber = assoTaskPersonelMapper.getPatentNumber(personelId, state, taskId);
   Map<String,Object> map =new HashMap<>();
   map.put("patentNos",patentNumber);
   map.put("startNumber",location);
        JSONObject json = new JSONObject(map);
           RequestBody requestBody =RequestBody.create(JSON,String.valueOf(json));
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(PASUrl + "/api/v2/patent/getPagination")
                .post(requestBody)
                .build();
        return Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();

    }






}
