InvokeHelper.java 32.3 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 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
package com.huaheng.api.jindie;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.gson.JsonObject;
import com.huaheng.api.jindie.domain.allocate.Allocate;
import com.huaheng.api.jindie.domain.login.Login;
import com.huaheng.api.jindie.domain.position.Position;
import com.huaheng.api.jindie.domain.purchase.PurchaseBatchSave;
import com.huaheng.api.jindie.domain.purchase.PurchasePush;
import com.huaheng.api.jindie.domain.purchase.PurchasePushData;
import com.huaheng.api.jindie.domain.purchase.PurchaseSelect;
import com.huaheng.api.jindie.domain.purchaseReturn.PurchaseReturnSave;
import com.huaheng.api.jindie.domain.result.Results;
import com.huaheng.api.jindie.domain.uri.JinDieApiUri;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.system.config.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;


import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DateFormat;
import java.util.*;

@Service
public class InvokeHelper {

    @Autowired
    private ReceiptHeaderService receiptHeaderService;
    @Autowired
    private ReceiptDetailService receiptDetailService;
    @Autowired
    private ShipmentHeaderService shipmentHeaderService;
    @Autowired
    private ShipmentDetailService shipmentDetailService;
    @Autowired
    private LocationService locationService;
    @Autowired
    private IConfigService configService;

    public static String POST_K3CloudURL = "http://219.137.250.36:8999/K3Cloud/";

    // Cookie 值
    // private static String CookieVal = null;

    // HttpURLConnection
    public  HttpURLConnection initUrlConn(String url, JSONObject paras)
            throws Exception {
        System.out.println(paras.toString());
        URL postUrl = new URL(POST_K3CloudURL.concat(url));
        HttpURLConnection connection = (HttpURLConnection) postUrl
                .openConnection();
        String jindieCookie = configService.selectConfigByKey("jindieCookie");
        connection.setRequestProperty("Cookie", jindieCookie);
        if (!connection.getDoOutput()) {
            connection.setDoOutput(true);
        }
        connection.setRequestMethod("POST");
        connection.setUseCaches(false);
        connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("Content-Type", "application/json");
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.writeBytes(paras.toString());
        out.flush();
        out.close();
        return connection;
    }

    /**
     * 采购入库单操作
     * @throws Exception
     */

    // 收料通知单下推采购入库单
    @Transactional(rollbackFor = Exception.class)
    public void push(String billCode) throws Exception {
        PurchasePush purchasePush=new PurchasePush();
        PurchasePushData purchasePushData=new PurchasePushData();
        List<String> list=new ArrayList<>();
        list.add(billCode);
        purchasePushData.setNumbers(list);
        purchasePushData.setTargetOrgId(0);
        purchasePushData.setTargetFormId("STK_InStock");
        purchasePushData.setIsEnableDefaultRule("true");
        purchasePush.setData(purchasePushData);
        purchasePush.setFormid("PUR_ReceiveBill");
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Results.ResultDTO.ResponseStatusDTO.SuccessEntitys successEntity = Invoke(JinDieApiUri.PURCHASE_PUSH.getApiUri(), jsonObject);
        Integer id = successEntity.getId();
        String number = successEntity.getNumber();
        Integer dIndex = successEntity.getDIndex();
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, billCode));
        receiptHeader.setUserDef1(id.toString());
        receiptHeader.setUserDef2(number);
        receiptHeaderService.updateById(receiptHeader);
    }

    // 采购入库单查询
    @Transactional(rollbackFor = Exception.class)
    public void select(String billCode) throws Exception {
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, billCode));
        List<ReceiptDetail> receiptDetails = receiptDetailService.list(new LambdaQueryWrapper<ReceiptDetail>().eq(ReceiptDetail::getReferCode, billCode));
        if(StringUtils.isNotEmpty(receiptHeader.getUserDef1())&&StringUtils.isNotEmpty(receiptHeader.getUserDef2())){
            PurchaseSelect purchaseSelect=new PurchaseSelect();
            Map map=new HashMap();
            purchaseSelect.setFormId("STK_InStock");
            purchaseSelect.setFieldKeys("FInStockEntry_FEntryID,FMATERIALID.FNUMBER");
            purchaseSelect.setFilterString("FBILLNO="+"'"+receiptHeader.getUserDef2()+"'");
            map.put("data",purchaseSelect);
            JSONObject jsonObject = (JSONObject) JSONObject.toJSON(map);
            purchaseSelectInvoke(JinDieApiUri.PURCHASE_SELECT.getApiUri(), jsonObject,receiptDetails);
        }
    }

    // 采购入库单保存
    public void save(String billCode) throws Exception {
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, billCode));
        List<ReceiptDetail> receiptDetails = receiptDetailService.list(new LambdaQueryWrapper<ReceiptDetail>().eq(ReceiptDetail::getReferCode, billCode));

        PurchaseBatchSave purchaseBatchSave = newInstancePurchaseBatchSave();

        List<PurchaseBatchSave.DataDTO.ModelDTO.FInStockEntryDTO> fInStockEntryDTOList=new ArrayList<>();

        purchaseBatchSave.setFormid("STK_InStock");
        purchaseBatchSave.getData().getModel().setFId(receiptHeader.getUserDef1());

        receiptDetails.forEach((receiptDetail)->{
            if(StringUtils.isNotEmpty(receiptHeader.getUserDef1())&&StringUtils.isNotEmpty(receiptHeader.getUserDef2())&&StringUtils.isNotEmpty(receiptDetail.getUserDef1())){
                PurchaseBatchSave.DataDTO.ModelDTO.FInStockEntryDTO fInStockEntryDTO = new PurchaseBatchSave.DataDTO.ModelDTO.FInStockEntryDTO();
                fInStockEntryDTO.setFEntryID(receiptDetail.getUserDef1());
                fInStockEntryDTO.setFRealQty(receiptDetail.getTotalQty());
                fInStockEntryDTOList.add(fInStockEntryDTO);
                purchaseBatchSave.getData().getModel().setFInStockEntry(fInStockEntryDTOList);
            }
        });
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchaseBatchSave);
        Invoke(JinDieApiUri.PURCHASE_SAVE.getApiUri(), jsonObject);
        System.out.println("Save:"+"单号"+billCode+"成功!");
    }

    // 采购入库单提交
    public void submit(String billCode) throws Exception {
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, billCode));
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("STK_InStock");
        PurchasePushData purchasePushData = new PurchasePushData();
        purchasePush.setData(purchasePushData);
        purchasePush.getData().setIds(receiptHeader.getUserDef1());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.PURCHASE_SUBMIT.getApiUri(), jsonObject);
        System.out.println("Submit:"+"单号"+billCode+"成功!");
    }

    // 采购入库单审核
    public void audit(String  billCode) throws Exception {
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, billCode));
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("STK_InStock");
        PurchasePushData purchasePushData = new PurchasePushData();
        purchasePush.setData(purchasePushData);
        purchasePush.getData().setIds(receiptHeader.getUserDef1());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.PURCHASE_AUDIT.getApiUri(), jsonObject);
        System.out.println("Audit:"+"单号"+billCode+"成功!");
    }

    //delete删除回传数据
    public void delete(String billCode) throws Exception {
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("STK_InStock");
        List<String> list=new ArrayList();
        list.add(billCode);
        PurchasePushData purchasePushData=new PurchasePushData();
        purchasePushData.setNumbers(list);
        purchasePush.setData(purchasePushData);
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.DELETE_RETURN.getApiUri(), jsonObject);
        System.out.println("Delete:"+"单号"+billCode+"成功!");
    }

    /**
     * 直接调拨单操作
     * @throws Exception
     */

    /**
     * 直接调拨单保存
     * @param code  WMS自己单据编号
     * @param FSrcStockId   调出仓库编码
     * @param FDestStockId    调入仓库编码
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public void allocateSave(String code,String FSrcStockId,String FDestStockId) throws Exception {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, code));
        List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>().eq(ShipmentDetail::getShipmentCode, code));

        Allocate allocate = newInstanceAllocateBatchSave();

        allocate.setFormid("STK_TransferDirect");
        allocate.getData().getModel().getF_aro_Base().setFstaffnumber("006034_GW000039_100069");
        allocate.getData().getModel().setFDate(DateUtils.parseDateToStr("yyyy-MM-dd",new Date()));

        ArrayList<Allocate.DataDTO.ModelDTO.FBillEntryDTO> fBillEntryDTOS=new ArrayList<>();

        shipmentDetails.forEach((shipmentDetail -> {
            Allocate.DataDTO.ModelDTO.FBillEntryDTO fBillEntryDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO();
            newInstanceAllocateBatchSave2(fBillEntryDTO);
            fBillEntryDTO.getFMaterialId().setFNumber(shipmentDetail.getMaterialCode());
            fBillEntryDTO.setFQty(shipmentDetail.getShipQty());
            fBillEntryDTO.getFLot().setFNumber(shipmentDetail.getBatch());
            fBillEntryDTO.getFSrcStockId().setFNumber(FSrcStockId);
            fBillEntryDTO.getFDestStockId().setFNumber(FDestStockId);
            try {
                String s1 = position_select(FSrcStockId);
                bindFsrcStockLocIdData(s1,fBillEntryDTO);
                String s2 = position_select(FDestStockId);
                bindFDestStockLocIdData(s2,fBillEntryDTO);
            } catch (Exception e) {
                e.printStackTrace();
            }

            fBillEntryDTOS.add(fBillEntryDTO);
            allocate.getData().getModel().setFBillEntry(fBillEntryDTOS);
        }));
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(allocate);
        Results.ResultDTO.ResponseStatusDTO.SuccessEntitys invoke = Invoke(JinDieApiUri.ALLOCATE_SAVE.getApiUri(), jsonObject);
        Integer id = invoke.getId();
        String number = invoke.getNumber();
        shipmentHeader.setUserDef1(id.toString());
        shipmentHeader.setUserDef2(number);
        shipmentHeaderService.updateById(shipmentHeader);
        System.out.println("allocateSave:"+"单号"+code+"成功!");
    }

    //直接调拨单提交
    public void allocateSubmit(String code) throws Exception {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, code));
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("STK_TransferDirect");
        PurchasePushData purchasePushData = new PurchasePushData();
        purchasePush.setData(purchasePushData);
        purchasePush.getData().setIds(shipmentHeader.getUserDef1());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.ALLOCATE_SUBMIT.getApiUri(), jsonObject);
        System.out.println("allocateSubmit:"+"单号"+code+"成功!");
    }

    //直接调拨单审核
    public void allocateAudit(String code) throws Exception {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, code));
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("STK_TransferDirect");
        PurchasePushData purchasePushData = new PurchasePushData();
        purchasePush.setData(purchasePushData);
        purchasePush.getData().setIds(shipmentHeader.getUserDef1());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.ALLOCATE_AUDIT.getApiUri(), jsonObject);
        System.out.println("allocateAudit:"+"单号"+code+"成功!");
    }

    /**
     * 采购退料单操作
     * @throws Exception
     */

    //采购退货单保存
    public void purchase_return_save(String code) throws Exception {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, code));
        List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>().eq(ShipmentDetail::getShipmentCode, code));

        PurchaseReturnSave purchaseReturnSave = newInstancePurchaseReturnSave();

        List<PurchaseReturnSave.DataDTO.ModelDTO.FPURMRBENTRYDTO> fpurmrbentrydtos=new ArrayList<>();

        purchaseReturnSave.setFormid("PUR_MRB");
        purchaseReturnSave.getData().getModel().setFId(shipmentHeader.getUserDef1());

        shipmentDetails.forEach((shipmentDetail)->{
            if(StringUtils.isNotEmpty(shipmentHeader.getUserDef1())&&StringUtils.isNotEmpty(shipmentHeader.getUserDef2())&&StringUtils.isNotEmpty(shipmentDetail.getUserDef1())){
                PurchaseReturnSave.DataDTO.ModelDTO.FPURMRBENTRYDTO fpurmrbentrydto = new PurchaseReturnSave.DataDTO.ModelDTO.FPURMRBENTRYDTO();
                fpurmrbentrydto.setFEntryID(shipmentDetail.getUserDef1());
                fpurmrbentrydto.setFrmrealqty(shipmentDetail.getShipQty());
                fpurmrbentrydtos.add(fpurmrbentrydto);
                purchaseReturnSave.getData().getModel().setFpurmrbentry(fpurmrbentrydtos);
            }
        });
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchaseReturnSave);
        Invoke(JinDieApiUri.PURCHASE_RETURN_SAVE.getApiUri(), jsonObject);
        System.out.println("PURCHASE_RETURN_SAVE:"+"单号"+code+"成功!");
    }

    //采购退货单提交
    public void purchase_return_submit(String code) throws Exception {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, code));
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("PUR_MRB");
        PurchasePushData purchasePushData = new PurchasePushData();
        purchasePush.setData(purchasePushData);
        purchasePush.getData().setIds(shipmentHeader.getUserDef1());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.PURCHASE_RETURN_SUBMIT.getApiUri(), jsonObject);
        System.out.println("PURCHASE_RETURN_SUBMIT:"+"单号"+code+"成功!");
    }

    //采购退货单审核
    public void purchase_return_audit(String code) throws Exception {
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, code));
        PurchasePush purchasePush=new PurchasePush();
        purchasePush.setFormid("PUR_MRB");
        PurchasePushData purchasePushData = new PurchasePushData();
        purchasePush.setData(purchasePushData);
        purchasePush.getData().setIds(shipmentHeader.getUserDef1());
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(purchasePush);
        Invoke(JinDieApiUri.PURCHASE_RETURN_AUDIT.getApiUri(), jsonObject);
        System.out.println("PURCHASE_RETURN_AUDIT:"+"单号"+code+"成功!");
    }

    //仓位值查询:用于直接调拨单
    public String position_select(String warehouseCode) throws Exception {
        PurchaseSelect purchaseSelect=new PurchaseSelect();
        Map map=new HashMap();
        purchaseSelect.setFormId("BD_STOCK");
        purchaseSelect.setFieldKeys("FFlexNumber");
        purchaseSelect.setFilterString("FNumber="+"'"+warehouseCode+"'");
        map.put("data",purchaseSelect);
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(map);
        String s = positionSelectInvoke(JinDieApiUri.POSITION_SELECT.getApiUri(), jsonObject);
        return s;
    }

    //仓位值提交到金蝶  已经提交到测试环境一次了 别再次提交了
    public void position_save() throws Exception {
        LambdaQueryWrapper<Location> lambdaQueryWrapper= Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(Location::getLocationType,"L");
        List<Location> list = locationService.list();
        ArrayList<Position.DataDTO.ModelDTO.FEntityDTO> fEntityDTOS=new ArrayList<>();
        list.forEach(location -> {
            Position.DataDTO.ModelDTO.FEntityDTO fEntityDTO = new Position.DataDTO.ModelDTO.FEntityDTO();
            fEntityDTO.setFFlexValueName(location.getCode());
            fEntityDTO.setFFlexValueNumber(location.getCode());
            fEntityDTOS.add(fEntityDTO);
        });
        Position.DataDTO.ModelDTO modelDTO = new Position.DataDTO.ModelDTO();
        modelDTO.setFid(100001);
        modelDTO.setFEntity(fEntityDTOS);
        Position.DataDTO dataDTO = new Position.DataDTO();
        dataDTO.setIsDeleteEntry("false");
        dataDTO.setModel(modelDTO);
        Position position=new Position();
        position.setData(dataDTO);
        position.setFormid("BD_FLEXVALUES");
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(position);
        Invoke(JinDieApiUri.POISTTION_SAVE.getApiUri(),jsonObject);
    }


    /**
     * 通用参数推送
     * @param uri
     * @param jParas  参数
     * @return  Results.ResultDTO.ResponseStatusDTO.SuccessEntitys
     * @throws Exception
     */
    public  Results.ResultDTO.ResponseStatusDTO.SuccessEntitys Invoke(String uri,JSONObject jParas)
            throws Exception {
        HttpURLConnection connectionInvoke = initUrlConn(uri, jParas);
        BufferedReader reader = new BufferedReader(new InputStreamReader(connectionInvoke.getInputStream()));
        String line;
        String sResult=null;
        while ((line = reader.readLine()) != null) {
            sResult = new String(line.getBytes(), "utf-8");
            System.out.println(sResult);
        }
        Results results = JSONObject.parseObject(sResult, Results.class);
        List<Results.ResultDTO.ResponseStatusDTO.SuccessEntitys> successEntitys = results.getResult().getResponseStatus().getSuccessEntitys();
        List<Results.ResultDTO.ResponseStatusDTO.ErrorsDTO> errors = results.getResult().getResponseStatus().getErrors();
        Results.ResultDTO.ResponseStatusDTO.SuccessEntitys successEntity=null;
        Results.ResultDTO.ResponseStatusDTO.ErrorsDTO errorsDTO=null;
        if(!CollectionUtils.isEmpty(successEntitys)){
            successEntity = successEntitys.get(0);
        }else {
            errorsDTO = errors.get(0);
        }
        reader.close();
        connectionInvoke.disconnect();
        if(StringUtils.isNotNull(successEntity)){
            return successEntity;
        }else {
            throw new ServiceException(errorsDTO.getMessage());
        }

    }

    /**
     * 采购入库单查询参数推送
     * @param uri   JinDieApiUri.PURCHASE_SELECT
     * @param jsonObject   参数
     * @param receiptDetails   入库单明细集合
     * @throws Exception
     */
    public void purchaseSelectInvoke(String uri,JSONObject jsonObject,List<ReceiptDetail> receiptDetails) throws Exception {
        HttpURLConnection connectionInvoke = initUrlConn(uri, jsonObject);
        BufferedReader reader = new BufferedReader(new InputStreamReader(connectionInvoke.getInputStream()));
        String line;
        String sResult=null;
        while ((line = reader.readLine()) != null) {
            sResult = new String(line.getBytes(), "utf-8");
            System.out.println(sResult);
        }
        List<List<Object>> results = JSONObject.parseObject(sResult, ArrayList.class);
        results.forEach((list)->{
            Integer purchaseLineId = (Integer) list.get(0);
            String materialCode = (String) list.get(1);
            receiptDetails.forEach((receiptDetail)->{
                if(receiptDetail.getMaterialCode().trim().equals(materialCode)){
                     receiptDetail.setUserDef1(purchaseLineId.toString());
                     receiptDetailService.updateById(receiptDetail);
                }
            });
        });
        reader.close();
        connectionInvoke.disconnect();
    }

    /**
     * 仓位值集查询参数推送
     * @param uri   JinDieApiUri.POSITION_SELECT
     * @param jsonObject   参数
     * @return   仓位值集字符串
     * @throws Exception
     */
    public String positionSelectInvoke(String uri, JSONObject jsonObject) throws Exception {
        HttpURLConnection connectionInvoke = initUrlConn(uri, jsonObject);
        BufferedReader reader = new BufferedReader(new InputStreamReader(connectionInvoke.getInputStream()));
        String line;
        String sResult=null;
        while ((line = reader.readLine()) != null) {
            sResult = new String(line.getBytes(), "utf-8");
            System.out.println(sResult);
        }
        List<List<Object>> results = JSONObject.parseObject(sResult, ArrayList.class);
        StringBuilder stringBuilder=new StringBuilder();
        results.forEach((list)->{
            stringBuilder.append(list.get(0).toString()+",");
        });
        reader.close();
        connectionInvoke.disconnect();
        return stringBuilder.toString();
    }

    /**
     * 把中文转成Unicode码
     *
     * @param str
     * @return
     */
    public  String chinaToUnicode(String str) {
        String result = "";
        for (int i = 0; i < str.length(); i++) {
            int chr1 = (char) str.charAt(i);
            if (chr1 >= 19968 && chr1 <= 171941) {// 汉字范围 \u4e00-\u9fa5 (中文)
                result += "\\u" + Integer.toHexString(chr1);
            } else {
                result += str.charAt(i);
            }
        }
        return result;
    }

    //初始化采购入库单保存实体
    public  PurchaseBatchSave newInstancePurchaseBatchSave(){
        PurchaseBatchSave purchaseBatchSave=new PurchaseBatchSave();
        PurchaseBatchSave.DataDTO dataDTO = new PurchaseBatchSave.DataDTO();
        PurchaseBatchSave.DataDTO.ModelDTO modelDTO = new PurchaseBatchSave.DataDTO.ModelDTO();
        purchaseBatchSave.setData(dataDTO);
        purchaseBatchSave.getData().setModel(modelDTO);
        return purchaseBatchSave;
    }

    //初始化直接调拨单保存实体
    public  Allocate newInstanceAllocateBatchSave(){
        Allocate allocate=new Allocate();

        Allocate.DataDTO dataDTO = new Allocate.DataDTO();
        Allocate.DataDTO.ModelDTO modelDTO = new Allocate.DataDTO.ModelDTO();
        Allocate.DataDTO.ModelDTO.FAroBaseDTO fAroBaseDTO = new Allocate.DataDTO.ModelDTO.FAroBaseDTO();

        allocate.setData(dataDTO);
        allocate.getData().setModel(modelDTO);
        allocate.getData().getModel().setF_aro_Base(fAroBaseDTO);

        return allocate;
    }

    //初始化直接调拨单内部类(传输model)
    public  void newInstanceAllocateBatchSave2(Allocate.DataDTO.ModelDTO.FBillEntryDTO fBillEntryDTO){
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FMaterialIdDTO fMaterialIdDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FMaterialIdDTO();
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FUnitIDDTO fUnitIDDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FUnitIDDTO();
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FLotDTO fLotDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FLotDTO();
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockIdDTO fSrcStockIdDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockIdDTO();
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO fSrcStockLocIdDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO();
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockIdDTO fDestStockIdDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockIdDTO();
        Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO fDestStockLocIdDTO = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO();

        fBillEntryDTO.setFMaterialId(fMaterialIdDTO);
        fBillEntryDTO.setFUnitID(fUnitIDDTO);
        fBillEntryDTO.setFLot(fLotDTO);
        fBillEntryDTO.setFSrcStockId(fSrcStockIdDTO);
        fBillEntryDTO.setFSrcStockLocId(fSrcStockLocIdDTO);
        fBillEntryDTO.setFDestStockId(fDestStockIdDTO);
        fBillEntryDTO.setFDestStockLocId(fDestStockLocIdDTO);
    }

    //初始化采购退料单保存实体
    public  PurchaseReturnSave newInstancePurchaseReturnSave(){
        PurchaseReturnSave purchaseReturnSave=new PurchaseReturnSave();
        PurchaseReturnSave.DataDTO dataDTO = new PurchaseReturnSave.DataDTO();
        PurchaseReturnSave.DataDTO.ModelDTO modelDTO = new PurchaseReturnSave.DataDTO.ModelDTO();

        purchaseReturnSave.setData(dataDTO);
        purchaseReturnSave.getData().setModel(modelDTO);
        return purchaseReturnSave;
    }

    /**
     * 初始化上游仓位维度值,绑定上游仓位编码
     * @param s  仓位维度值
     * @param fBillEntryDTO  直接调拨单保存实体类—>内部类
     */
    public   void  bindFsrcStockLocIdData(String s,Allocate.DataDTO.ModelDTO.FBillEntryDTO fBillEntryDTO){
         String[] strings = Convert.toStrArray(s);
         for (String string : strings) {
             if(string.trim().equals("FF100001")){
                 Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100001 fsrcstocklocid__ff100001 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100001();
                 fBillEntryDTO.getFSrcStockLocId().setFSRCSTOCKLOCID__FF100001(fsrcstocklocid__ff100001);
                 fBillEntryDTO.getFSrcStockLocId().getFSRCSTOCKLOCID__FF100001().setFNumber("1001");
             }
             if(string.trim().equals("FF100011")){
                 Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100011 fsrcstocklocid__ff100011 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100011();
                 fBillEntryDTO.getFSrcStockLocId().setFSRCSTOCKLOCID__FF100011(fsrcstocklocid__ff100011);
                 fBillEntryDTO.getFSrcStockLocId().getFSRCSTOCKLOCID__FF100011().setFNumber("");
             }
             if(string.trim().equals("FF100015")){
                 Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100015 fsrcstocklocid__ff100015 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100015();
                 fBillEntryDTO.getFSrcStockLocId().setFSRCSTOCKLOCID__FF100015(fsrcstocklocid__ff100015);
                 fBillEntryDTO.getFSrcStockLocId().getFSRCSTOCKLOCID__FF100015().setFNumber("");
             }
             if(string.trim().equals("FF100022")){
                 Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100022 fsrcstocklocid__ff100022 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100022();
                 fBillEntryDTO.getFSrcStockLocId().setFSRCSTOCKLOCID__FF100022(fsrcstocklocid__ff100022);
                 fBillEntryDTO.getFSrcStockLocId().getFSRCSTOCKLOCID__FF100022().setFNumber("");
             }
             if(string.trim().equals("FF100026")){
                 Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100026 fsrcstocklocid__ff100026 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FSrcStockLocIdDTO.FSRCSTOCKLOCID__FF100026();
                 fBillEntryDTO.getFSrcStockLocId().setFSRCSTOCKLOCID__FF100026(fsrcstocklocid__ff100026);
                 fBillEntryDTO.getFSrcStockLocId().getFSRCSTOCKLOCID__FF100026().setFNumber("");
             }
         }
    }

    /**
     * 初始化下游仓位维度值,绑定下游仓位编码
     * @param s  仓位维度值
     * @param fBillEntryDTO  直接调拨单保存实体类—>内部类
     */
    public   void  bindFDestStockLocIdData(String s,Allocate.DataDTO.ModelDTO.FBillEntryDTO fBillEntryDTO){
        String[] strings = Convert.toStrArray(s);
        for (String string : strings) {
            if(string.trim().equals("FF100001")){
                Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100001 fdeststocklocid__ff100001 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100001();
                fBillEntryDTO.getFDestStockLocId().setFDESTSTOCKLOCID__FF100001(fdeststocklocid__ff100001);
                fBillEntryDTO.getFDestStockLocId().getFDESTSTOCKLOCID__FF100001().setFNumber("1001");
            }
            if(string.trim().equals("FF100011")){
                Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100011 fdeststocklocid__ff100011 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100011();
                fBillEntryDTO.getFDestStockLocId().setFDESTSTOCKLOCID__FF100011(fdeststocklocid__ff100011);
                fBillEntryDTO.getFDestStockLocId().getFDESTSTOCKLOCID__FF100011().setFNumber("");
            }
            if(string.trim().equals("FF100015")){
                Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100015 fdeststocklocid__ff100015 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100015();
                fBillEntryDTO.getFDestStockLocId().setFDESTSTOCKLOCID__FF100015(fdeststocklocid__ff100015);
                fBillEntryDTO.getFDestStockLocId().getFDESTSTOCKLOCID__FF100015().setFNumber("");
            }
            if(string.trim().equals("FF100022")){
                Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100022 fdeststocklocid__ff100022 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100022();
                fBillEntryDTO.getFDestStockLocId().setFDESTSTOCKLOCID__FF100022(fdeststocklocid__ff100022);
                fBillEntryDTO.getFDestStockLocId().getFDESTSTOCKLOCID__FF100022().setFNumber("");
            }
            if(string.trim().equals("FF100026")){
                Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100026 fdeststocklocid__ff100026 = new Allocate.DataDTO.ModelDTO.FBillEntryDTO.FDestStockLocIdDTO.FDESTSTOCKLOCID__FF100026();
                fBillEntryDTO.getFDestStockLocId().setFDESTSTOCKLOCID__FF100026(fdeststocklocid__ff100026);
                fBillEntryDTO.getFDestStockLocId().getFDESTSTOCKLOCID__FF100026().setFNumber("");

            }
        }
    }

    //根据仓库编码,找仓位编码
    public  void bingStockLocIdFnumberData(String s,Allocate.DataDTO.ModelDTO.FBillEntryDTO fBillEntryDTO){
        //这里会有获取仓位值的逻辑
        //...
    }


}