ZhjDatasSynServiceImpl.java 18.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
package com.pashanhoo.zhj.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pashanhoo.zhj.entity.RegBusBdcqzsdjxxDo;
import com.pashanhoo.zhj.entity.SynZhjInfoDo;
import com.pashanhoo.zhj.mapper.RegBusBdcqzsdjxxMapper;
import com.pashanhoo.zhj.mapper.SynZhjInfoMapper;
import com.pashanhoo.zhj.service.ZhjDatasSynService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 案卷基本信息 服务实现类
 * </p>
 *
 * @author
 * @since 2021-11-05
 */
@Service
public class ZhjDatasSynServiceImpl extends ServiceImpl<RegBusBdcqzsdjxxMapper, RegBusBdcqzsdjxxDo> implements ZhjDatasSynService {

    private static Logger logger = LoggerFactory.getLogger(ZhjDatasSynServiceImpl.class);
    @Autowired
    private SynZhjInfoMapper synZhjInfoMapper;
    @Autowired
    private RegBusBdcqzsdjxxMapper regBusBdcqzsdjxxMapper;
    //智慧局内网ip
    private String zhjurl="http://172.16.56.10:7050";
    //认证令牌
    private  String appkey="3cd832c411238faa1df46d532a21bfcd";
    private String appSecret="ee7612083f63c2ce0d016c2aefd0a8d2";

    public void send_bdcYwInfo() {
       List<SynZhjInfoDo> selectAllListInfo=synZhjInfoMapper.selectAllInfo();
       if(selectAllListInfo!=null && selectAllListInfo.size()>0){
           final List<RegBusBdcqzsdjxxDo> zsdjInfoList=regBusBdcqzsdjxxMapper.getZsdjInfoList(selectAllListInfo);
           if(zsdjInfoList!=null && zsdjInfoList.size()>0){
               String url=zhjurl+"/dclp/hzapi/token?appKey="+appkey+"&appSecret="+appSecret;
               Map map1=doGetForNew(url);
               if(map1!=null && (Integer)map1.get("code")==200){
                   final Map map2= (Map) map1.get("data");
                   final String token= (String) map2.get("token");
                   //组装宗地基本信息
                   new Thread(new Runnable() {
                       @Override
                       public void run() {
                           System.out.println("===============当前线程是:"+Thread.currentThread().getName());
                           synZdInfo(zsdjInfoList,token);
                       }
                   }).start();

                    //组装户信息
                   new Thread(new Runnable() {
                       @Override
                       public void run() {
                           System.out.println("===============当前线程是:"+Thread.currentThread().getName());
                           synHInfo(zsdjInfoList,token);
                       }
                   }).start();

                   //组装权属状态
                   new Thread(new Runnable() {
                       @Override
                       public void run() {
                           System.out.println("===============当前线程是:"+Thread.currentThread().getName());
                           synQSZTInfo(zsdjInfoList,token);
                       }
                   }).start();
               }
               }
           }
       }

    /**
     *根据业务通过swagger接口手动推送宗地基本信息
     * @param ywh
     * @param
     */
    public void synZdInfoByywh(String ywh){
        List<RegBusBdcqzsdjxxDo> zsdjInfoList =regBusBdcqzsdjxxMapper.getZsdjInfoListByYwh(ywh);
        if(zsdjInfoList!=null && zsdjInfoList.size()>0){
            String url=zhjurl+"/dclp/hzapi/token?appKey="+appkey+"&appSecret="+appSecret;
            Map map1=doGetForNew(url);
            if(map1!=null && (Integer)map1.get("code")==200){
                Map map2= (Map) map1.get("data");
                String token= (String) map2.get("token");
                synZdInfo(zsdjInfoList,token);
            }
        }
    }

    /**
     * 给智慧局推送宗地基本信息
     * @param zsdjInfoList
     * @param token
     */
    public void synZdInfo(List<RegBusBdcqzsdjxxDo> zsdjInfoList,String token)  {
        try{
            if(zsdjInfoList!=null && zsdjInfoList.size()>0){
                for (int i = 0; i < zsdjInfoList.size(); i++) {
                    RegBusBdcqzsdjxxDo busBdcqzsdjxxDo= zsdjInfoList.get(i);
                    List<Map> zdjglist = regBusBdcqzsdjxxMapper.getZdInfoByZddm(busBdcqzsdjxxDo);
                    if(zdjglist!=null && zdjglist.size()>0){
                        for (int j = 0; j < zdjglist.size(); j++) {
                            Map map=zdjglist.get(j);
                            StringBuilder params = new StringBuilder();
                            params.append("?").append("DJQDM=").append(map.get("DJQDM")).append("&")
                                    .append("DJQMC=").append(URLEncoder.encode((String) map.get("DJQMC"),"UTF-8")).append("&")
                                    .append("DJZQDM=").append(map.get("DJZQDM")).append("&")
                                    .append("DJZQMC=").append(URLEncoder.encode((String) map.get("DJZQMC"),"UTF-8")).append("&")
                                    .append("BDCDYH=").append(map.get("BDCDYH")).append("&")
                                    .append("ZL=").append(URLEncoder.encode((String) map.get("ZL"),"UTF-8")).append("&")
                                    .append("ZDMJ=").append(map.get("ZDMJ")).append("&")
                                    .append("YT=").append(URLEncoder.encode((String) map.get("YT"),"UTF-8"));
                            String url1=zhjurl+"/dclp/hzapi/ZDJGMS"+params.toString();
                            Integer code=doPostForNew(url1,"", token);
                            if(code==200){
                                synZhjInfoMapper.updatezdzt(busBdcqzsdjxxDo.getYwh());
                            }
                        }
                    }

                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }

    }
    /**
     * 根据业务通过swagger接口手动推送户信息
     * @param ywh
     * @param
     */
    public void synHInfoByYwh(String ywh){
        List<RegBusBdcqzsdjxxDo> zsdjInfoList =regBusBdcqzsdjxxMapper.getZsdjInfoListByYwh(ywh);
        if(zsdjInfoList!=null && zsdjInfoList.size()>0){
            String url=zhjurl+"/dclp/hzapi/token?appKey="+appkey+"&appSecret="+appSecret;
            Map map1=doGetForNew(url);
            if(map1!=null && (Integer)map1.get("code")==200){
                Map map2= (Map) map1.get("data");
                String token= (String) map2.get("token");
                synHInfo(zsdjInfoList,token);
            }
        }
    }
    /**
     * 给智慧局推送户基本信息
     * @param zsdjInfoList
     * @param token
     */
    public void synHInfo(List<RegBusBdcqzsdjxxDo> zsdjInfoList,String token){
        try{
            if(zsdjInfoList!=null && zsdjInfoList.size()>0){
                for (int i = 0; i < zsdjInfoList.size(); i++) {
                    RegBusBdcqzsdjxxDo busBdcqzsdjxxDo= zsdjInfoList.get(i);
                    List<Map> hlist = regBusBdcqzsdjxxMapper.getHQSInfoByZddm(busBdcqzsdjxxDo);
                    if(hlist!=null && hlist.size()>0){
                        for (int j = 0; j < hlist.size(); j++) {
                            Map map=hlist.get(j);
                            StringBuilder params = new StringBuilder();
                            params.append("?").append("BDCDYH=").append(map.get("BDCDYH")).append("&")
                                    .append("ZRZH=").append(map.get("ZRZH")).append("&")
                                    .append("CH=").append(map.get("CH")).append("&")
                                    .append("ZL=").append(URLEncoder.encode((String) map.get("ZL"),"UTF-8")).append("&")
                                    .append("SJCS=").append(map.get("SJCS")).append("&")
                                    .append("SHBW=").append(URLEncoder.encode((String) map.get("SHBW"),"UTF-8")).append("&")
                                    .append("HX=").append(map.get("HX")).append("&")
                                    .append("HXJG=").append(map.get("HXJG")).append("&")
                                    .append("FWYT1=").append(map.get("FWYT1")).append("&")
                                    .append("SCJZMJ=").append(map.get("SCJZMJ")).append("&")
                                    .append("SCTNJZMJ=").append(map.get("SCTNJZMJ")).append("&")
                                    .append("SCDXBFJZMJ=").append(map.get("SCDXBFJZMJ")).append("&")
                                    .append("FTTDMJ=").append(map.get("FTTDMJ")).append("&")
                                    .append("FWLX=").append(map.get("FWLX")).append("&")
                                    .append("FWXZ=").append(map.get("FWXZ")).append("&")
                                    .append("QLLX=").append(map.get("QLLX")).append("&")
                                    .append("DJLX=").append(map.get("DJLX")).append("&")
                                    .append("SYQMJ=").append(map.get("SYQMJ")).append("&")
                                    .append("SYQQSSJ=").append(map.get("SYQQSSJ")).append("&")
                                    .append("SYQJSSJ=").append(map.get("SYQJSSJ")).append("&")
                                    .append("BDCQZH=").append(URLEncoder.encode((String) map.get("BDCQZH"),"UTF-8")).append("&")
                                    .append("QXDM=").append(map.get("QXDM")).append("&")
                                    .append("DJSJ=").append(map.get("DJSJ")).append("&")
                                    .append("QSZT=").append(map.get("QSZT")).append("&")
                                    .append("ZT=").append(map.get("ZT"));

                            String url1=zhjurl+"/dclp/hzapi/HQSJGMS"+params.toString();
                            Integer code=doPostForNew(url1,"", token);
                            if(code==200){
                                synZhjInfoMapper.updatezdzt(busBdcqzsdjxxDo.getYwh());
                            }
                        }
                    }
                }
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }

    }

    /**
     * 给智慧局推送权属状态基本信息
     * @param ywh
     * @param
     */
    public void synQSZTInfoByYwh(String ywh){
        List<RegBusBdcqzsdjxxDo> zsdjInfoList =regBusBdcqzsdjxxMapper.getZsdjInfoListByYwh(ywh);
        if(zsdjInfoList!=null && zsdjInfoList.size()>0){
            String url=zhjurl+"/dclp/hzapi/token?appKey="+appkey+"&appSecret="+appSecret;
            Map map1=doGetForNew(url);
            if(map1!=null && (Integer)map1.get("code")==200){
                Map map2= (Map) map1.get("data");
                String token= (String) map2.get("token");
                synQSZTInfo(zsdjInfoList,token);
            }
        }
    }



    /**
     * 给智慧局推送权属状态基本信息
     * @param zsdjInfoList
     * @param token
     */
    public void synQSZTInfo(List<RegBusBdcqzsdjxxDo> zsdjInfoList,String token){
        if(zsdjInfoList!=null && zsdjInfoList.size()>0){
            for (int i = 0; i < zsdjInfoList.size(); i++) {
                RegBusBdcqzsdjxxDo busBdcqzsdjxxDo= zsdjInfoList.get(i);
                List<Map> qsztList = regBusBdcqzsdjxxMapper.getQSZTInfoByZddm(busBdcqzsdjxxDo);
                if(qsztList!=null && qsztList.size()>0){
                    for (int j = 0; j < qsztList.size(); j++) {
                        Map map=qsztList.get(j);
                        StringBuilder params = new StringBuilder();
                        params.append("?").append("BDCDYH=").append(map.get("BDCDYH")).append("&")
                                .append("DYQSZT=").append(map.get("DYQSZT")).append("&")
                                .append("YYQSZT=").append(map.get("YYQSZT")).append("&")
                                .append("CFQSZT=").append(map.get("CFQSZT")).append("&")
                                .append("YGQSZT=").append(map.get("YGQSZT"));
                        String url1=zhjurl+"/dclp/hzapi/QSZT"+params.toString();
                        Integer code=doPostForNew(url1,"", token);
                        if(code==200){
                            synZhjInfoMapper.updatezdzt(busBdcqzsdjxxDo.getYwh());
                        }
                    }
                }
            }
        }
    }

    public  Map doGetForNew(String url) {
        logger.info("http request url:" + url);
        BufferedReader in = null;
        String result = "";
        Map jsonObject=new HashMap();
        try{
            URL url1=new URL(url);
            HttpURLConnection conn= (HttpURLConnection) url1.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("accept","*/*");
            conn.setRequestProperty("connection","Keep-Alive");
            conn.setRequestProperty("Charset", "utf-8");
            conn.setDoInput(true);
            conn.setDoOutput(false);
            //x-qys-signature生成方式:Md5(AppToken + AppSecret + timestamp),获取32位小写值
            conn.connect();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
            jsonObject=JSONObject.parseObject(result,Map.class);
            logger.info("http request back:" + jsonObject);
        }catch (Exception ex){
            logger.info("发送 POST 请求出现异常!" + ex);
            ex.printStackTrace();
        }finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return jsonObject;
    }


    public  Integer doPostForNew(String url, String params,String token) {
        logger.info("http request url:" + url);
        logger.info("http request params:" + params);
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        Map jsonObject=new HashMap();
        Integer code=200;
        try{
            URL url1=new URL(url);
            HttpURLConnection conn= (HttpURLConnection) url1.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("accept","*/*");
            conn.setRequestProperty("connection","Keep-Alive");
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
            conn.setRequestProperty("X-Access-Token", token);
            out=new PrintWriter(new OutputStreamWriter(conn.getOutputStream(),"utf-8"));
            out.print(params);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
            jsonObject=JSONObject.parseObject(result,Map.class);
            logger.info("http request back:" + jsonObject);
            code= (Integer) jsonObject.get("code");
        }catch (Exception ex){
            logger.info("发送 POST 请求出现异常!" + ex);
            ex.printStackTrace();
            code=-1;
        }finally {
            try {
                if (out != null) {
                    out.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        return code;
    }
    @Override
    public void synQYBDCXX(String token) {
        List<Map> list=synZhjInfoMapper.getQyBdcxx();
        if(list!=null  && list.size()>0){
            for (int j = 0; j < list.size(); j++) {
                Map map=list.get(j);
                StringBuilder params = new StringBuilder();
                params.append("?").append("QLRMC=").append(map.get("BDCDYH")).append("&")
                        .append("QLRZJH=").append(map.get("QLRZJH")).append("&")
                        .append("BDCQZSH=").append(map.get("BDCQZSH")).append("&")
                        .append("BDCDYH=").append(map.get("BDCDYH")).append("&")
                        .append("DJSJ=").append(map.get("DJSJ")).append("&")
                        .append("YT=").append(map.get("YT")).append("&")
                        .append("ZL=").append(map.get("ZL")).append("&")
                        .append("MJ=").append(map.get("MJ")).append("&")
                        .append("SYQX=").append(map.get("SYQX")).append("&")
                        .append("DJJG=").append(map.get("DJJG"));
                String url1=zhjurl+"/dclp/hzapi/QYBDCXX"+params.toString();
                doPostForNew(url1,"", token);
            }
        }
    }

    @Override
    public void qymxFcDyxx(String token) {
        List<Map> list=synZhjInfoMapper.getQymxfcdyxx();
        if(list!=null  && list.size()>0){
            for (int j = 0; j < list.size(); j++) {
                Map map=list.get(j);
                StringBuilder params = new StringBuilder();
                params.append("?").append("DYQR=").append(map.get("DYQR")).append("&")
                        .append("DYQRZJH=").append(map.get("DYQRZJH")).append("&")
                        .append("BDCDJZMH=").append(map.get("BDCDJZMH")).append("&")
                        .append("BDCDYH=").append(map.get("BDCDYH")).append("&")
                        .append("QLLX=").append(map.get("QLLX")).append("&")
                        .append("DYR=").append(map.get("DYR")).append("&")
                        .append("DYDJSJ=").append(map.get("DYDJSJ"));
                String url1=zhjurl+"/dclp/hzapi/QYMXFCDYXX"+params.toString();
                doPostForNew(url1,"", token);
            }
        }
    }

    @Override
    public void synQyInfo() {
        String url=zhjurl+"/dclp/hzapi/token?appKey="+appkey+"&appSecret="+appSecret;
        Map map1=doGetForNew(url);
        if(map1!=null && (Integer)map1.get("code")==200){
            final Map map2= (Map) map1.get("data");
            final String token= (String) map2.get("token");
            //组装中小微企业基本信息
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("===============当前线程是:"+Thread.currentThread().getName());
                    synQYBDCXX(token);
                }
            }).start();

            //组装中小微企业抵押信息
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("===============当前线程是:"+Thread.currentThread().getName());
                    qymxFcDyxx(token);
                }
            }).start();

        }
    }


}