package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.BMainThreeSupervisionEnforc;
import cn.cecep.talroad.domain.BMainThreeSupervisionEnforcRecord;
import cn.cecep.talroad.mapper.BMainThreeSupervisionEnforcMapper;
import cn.cecep.talroad.service.IBMainThreeSupervisionEnforcService;
import cn.cecep.talroad.util.HttpUtils;
import cn.cecep.talroad.vo.BMainThreeSupervisionEnforcVo;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;




/**
 * 三监联动执法信息Service业务层处理
 *
 * @author szhpt
 * @date 2023-03-29*/
@Service
public class BMainThreeSupervisionEnforcServiceImpl extends ServiceImpl<BMainThreeSupervisionEnforcMapper,BMainThreeSupervisionEnforc> implements IBMainThreeSupervisionEnforcService
{
    @Autowired
    private BMainThreeSupervisionEnforcMapper bMainThreeSupervisionEnforcMapper;

    @Value("${url.threeSupervision}")
    private String url;

    /**
     * 查询三监联动执法信息列表
     *
     * @param bMainThreeSupervisionEnforc 三监联动执法信息
     * @return 三监联动执法信息
     */
    @Override
    public List<BMainThreeSupervisionEnforc> selectBMainThreeSupervisionEnforcList(BMainThreeSupervisionEnforc bMainThreeSupervisionEnforc)
    {
        return bMainThreeSupervisionEnforcMapper.selectBMainThreeSupervisionEnforcList(bMainThreeSupervisionEnforc);
    }

    @Override
    public BMainThreeSupervisionEnforcVo selectById(String taskId) {
        BMainThreeSupervisionEnforcVo supervisionEnforcVo = bMainThreeSupervisionEnforcMapper.selectTaskById(taskId);

        List<BMainThreeSupervisionEnforcRecord> recordList = supervisionEnforcVo.getRecordList();

        Set<String> receivingDeptNames = new HashSet<>();

        List<BMainThreeSupervisionEnforcRecord> distinctRecordList = recordList.stream()
                .filter(x -> receivingDeptNames.add(x.getHandleDeptName()))
                .collect(Collectors.toList());
        supervisionEnforcVo.setReceivingDeptList(distinctRecordList);

        return supervisionEnforcVo;
    }

    @Override
    public Object xianheGet(Map data,String token) {
        return HttpUtils.post("https://air.aepic.net:12015/qyzhgk/sjldTask/GetTaskAccountPage", data,token);

    }

    @Override
    public Object xianheGetInfo(String taskId, String authorization) {
        return HttpUtils.get("https://air.aepic.net:12015/qyzhgk/sjldTask/GetTaskInfo?taskId="+taskId, authorization);
    }

    public Object xianheGetTaskAccount(Map data,String token) {
        return HttpUtils.post("https://air.aepic.net:12015/qyzhgk/jgzfDataTask/taskAccount", data,token);

    }

    @Override
    public Object xianheGetTaskInfo(String taskId, String authorization) {
        return HttpUtils.get("https://air.aepic.net:12015/qyzhgk/jgzfDataTask/getTaskInfo?taskId="+taskId, authorization);
    }
    @Override
    public Object xianheGetCityCodeList(String pid, String authorization) {
        return HttpUtils.get("https://air.aepic.net:12015/qyzhgk/syscitycode/GetCityCodeList?pid="+pid, authorization);
    }

    @Override
    public Object xianheGetCheckTaskAccount(Map data, String authorization) {
        return HttpUtils.post("https://air.aepic.net:12015/qyzhgk/jgzfDataTask/checkTaskAccount", data,authorization);
    }

    @Override
    public Object xianheGetAllUrl(String url, String method, String param, String authorization) {
        if("get".equals(method)){
            log.warn("url:"+this.url+url);
            log.warn("urlAll:"+this.url+url+(param==null?"":param));
            ResponseEntity<String> stringResponseEntity = HttpUtils.get(this.url + url + (param == null ? "" : param), authorization);
            log.warn("结果："+stringResponseEntity);
            return stringResponseEntity;
        }
        else if("post".equals(method)){
            log.warn("url:"+this.url+url);
            log.warn("urlAll:"+this.url+url+"??param:"+(param==null?"":param));
            Map map = JSON.parseObject(param, Map.class);
            String stringResponseEntity =HttpUtils.post(this.url+url,map, authorization);
            log.warn("结果："+stringResponseEntity);
            return stringResponseEntity;
        }
        return null;
    }

}
