| | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | String path = null; |
| | | Date now = new Date(); |
| | | //物料档案查询 |
| | | if(kingDeeUtilType.formId.equals("BD_MATERIAL")){ |
| | | // Mat latestMat = matService.selectLatest(); |
| | | String latestUpdateTime = sdf1.format(docType.getUpdateTime()); |
| | | // Tag tag = tagService.selectByName("全部", 1); |
| | | switch (kingDeeUtilType.formId) { |
| | | case "BD_MATERIAL": //物料同步 |
| | | jsonObject.put("id", null);//id |
| | | jsonObject.put("number", null);//编码 |
| | | jsonObject.put("createorg_number", null);//创建组织 |
| | |
| | | jsonObject.put("end_approvedate", sdf2.format(now));//审核截止 |
| | | jsonObject.put("status", Arrays.asList("B", "C"));//数据状态 [A:暂存, B:已提交, C:已审核] |
| | | path = matAddress; |
| | | } |
| | | else if(kingDeeUtilType.formId.equals("BD_RRGANIZATION")){ |
| | | break; |
| | | case "BD_RRGANIZATION": //货主同步 |
| | | jsonObject.put("start_createtime", "2025-01-01 00:00:00");//id |
| | | jsonObject.put("end_createtime", sdf1.format(now)); |
| | | jsonObject.put("id", null); |
| | |
| | | jsonObject.put("createorg_number", null); |
| | | jsonObject.put("status", Arrays.asList("B", "C"));//数据状态 [A:暂存, B:已提交, C:已审核] |
| | | path = orgAddress; |
| | | } |
| | | else if(kingDeeUtilType.formId.equals("PUR_RECEIVEBIll")){ |
| | | jsonObject.put("start_biztime", "2025-01-01 00:00:00");//业务起始日期 |
| | | break; |
| | | case "PUR_RECEIVEBIll": //已审核收料单查询 |
| | | jsonObject.put("start_biztime", latestUpdateTime);//业务起始日期 |
| | | jsonObject.put("end_biztime", sdf1.format(now));//业务结束日期 |
| | | jsonObject.put("billno", null); |
| | | jsonObject.put("billstatus", Arrays.asList("C"));//数据状态 [A:暂存, B:已提交, C:已审核] |
| | |
| | | jsonObject.put("org_number", null); |
| | | jsonObject.put("supplier_number", null); |
| | | path = imPurreceiveBillAddress; |
| | | break; |
| | | } |
| | | JSONObject jsonObject1 = new JSONObject(); |
| | | jsonObject1.put("data", jsonObject); |
| | |
| | | } |
| | | } |
| | | } |
| | | // else { |
| | | // int pageSize = jsonResponse.getJSONObject("data").getIntValue("pageSize"); |
| | | // int totalCount = jsonResponse.getJSONObject("data").getIntValue("totalCount"); |
| | | // int totalPages = (int) Math.ceil((double) totalCount / pageSize); |
| | | // for (int page = 1; page <= totalPages; page++) { |
| | | // jsonObject1.put("pageNo", page); |
| | | // add = jsonObject1.toJSONString(); |
| | | // // 重新发起请求以获取该页的数据 |
| | | // response = new HttpHandler.Builder() |
| | | // .setHeaders(headers) |
| | | // .setUri(URL) |
| | | // .setPath(path) |
| | | // .setJson(add) |
| | | // .build() |
| | | // .doPost(); |
| | | // |
| | | // jsonResponse = JSON.parseObject(response); |
| | | // data = jsonResponse.getJSONObject("data").getJSONArray("rows"); |
| | | // for (int j = 0; j < data.size(); j++) { |
| | | // JSONObject jsonObjectNew = data.getJSONObject(j); |
| | | // Date updateTime = sdf1.parse(jsonObjectNew.get("modifytime").toString()); |
| | | // String ownerUuid = jsonObjectNew.get("number").toString(); |
| | | // String owner = jsonObjectNew.get("name").toString(); |
| | | // Date createTime = sdf1.parse(jsonObjectNew.get("createtime").toString()); |
| | | // String billNo = jsonObjectNew.get("billno").toString(); |
| | | // |
| | | // Order order = OrderInAndOutUtil.selectByNo(kingDeeUtilType.pakIn == 1, billNo); |
| | | //// Order order = orderService.selectByNo(jsonArray.get(0).toString()); |
| | | //// LocOwner locOwner = null; |
| | | //// if (!Cools.isEmpty(1)) { |
| | | //// locOwner = locOwnerService.selectById(1); |
| | | //// } else { |
| | | //// locOwner = locOwnerService.selectById(1); |
| | | //// } |
| | | // if (Cools.isEmpty(order)) { |
| | | // // 单据主档 |
| | | // order = new Order( |
| | | // String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | // billNo, // 订单编号 |
| | | // createTime, // 单据日期 |
| | | // docType.getDocId(), // 单据类型 |
| | | // null, // 项目编号 |
| | | // "1", //项目名称 客户PO号 |
| | | // null, // 调拨项目编号 |
| | | // null, // 初始票据号 |
| | | // null, // 票据号 |
| | | // null, // 客户编号 |
| | | // locOwner.getOwner(), // 客户 |
| | | // null, // 联系方式 |
| | | // null, // 操作人员 |
| | | // null, // 合计金额 |
| | | // null, // 优惠率 |
| | | // null, // 优惠金额 |
| | | // null, // 销售或采购费用合计 |
| | | // null, // 实付金额 |
| | | // null, // 付款类型 |
| | | // null, // 业务员 |
| | | // null, // 结算天数 |
| | | // null, // 邮费支付类型 |
| | | // null, // 邮费 |
| | | // null, // 付款时间 |
| | | // null, // 发货时间 |
| | | // null, // 物流名称 |
| | | // null, // 物流单号 |
| | | // 1L, // 订单状态 |
| | | // 1, // 状态 |
| | | // 9527L, // 添加人员 |
| | | // now, // 添加时间 |
| | | // 9527L, // 修改人员 |
| | | // now, // 修改时间 |
| | | // null // 备注 |
| | | // ); |
| | | // OrderInAndOutUtil.insertOrder(kingDeeUtilType.pakIn == 1, order); |
| | | // |
| | | //// if (!orderService.insert(order)) { |
| | | //// if (!jsonDate.equals(docType.getCreateTime())){ |
| | | //// callApiLogSaveOrder(order,kingDeeUtilType, "生成单据主档失败,请联系管理员"+order, false); |
| | | //// } |
| | | //// continue; |
| | | ////// throw new CoolException("生成单据主档失败,请联系管理员"); |
| | | //// } |
| | | // } |
| | | // //物料编码 |
| | | // Mat mat = matService.selectByMatnr(jsonArray.get(2).toString()); |
| | | // if (Cools.isEmpty(mat)) { |
| | | // if (!jsonDate.equals(docType.getCreateTime())){ |
| | | // callApiLogSaveOrder(order,kingDeeUtilType, "编号商品检索失败,请先添加商品"+jsonArray.get(2).toString(), false); |
| | | // } |
| | | // continue; |
| | | // } |
| | | //// OrderDetl orderDetl1 = orderDetlService.selectOne(new EntityWrapper<OrderDetl>().eq("order_no", jsonArray.get(0).toString()).eq("matnr", jsonArray.get(2).toString())); |
| | | //// if (!Cools.isEmpty(orderDetl1)) { |
| | | //// continue; |
| | | //// } |
| | | // Order order1 = OrderInAndOutUtil.selectByNo(kingDeeUtilType.pakIn == 1, jsonArray.get(0).toString()); |
| | | // List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(kingDeeUtilType.pakIn == 1, order1.getId()); |
| | | // boolean sign = false; |
| | | // for (OrderDetl orderDetl : orderDetls){ |
| | | // if (orderDetl.getMatnr().equals( jsonArray.get(2).toString())){ |
| | | // sign = true; |
| | | // break; |
| | | // } |
| | | // } |
| | | // if (sign){ |
| | | // continue; |
| | | // } |
| | | // OrderDetl orderDetl = new OrderDetl(); |
| | | // orderDetl.sync(mat); |
| | | // orderDetl.setBatch(null); |
| | | // orderDetl.setAnfme(Double.parseDouble(jsonArray.get(5).toString())); |
| | | // orderDetl.setOrderId(order.getId()); |
| | | // orderDetl.setOrderNo(order.getOrderNo()); |
| | | // orderDetl.setCreateBy(9527L); |
| | | // orderDetl.setCreateTime(new Date()); |
| | | // orderDetl.setUpdateBy(9527L); |
| | | // orderDetl.setUpdateTime(new Date()); |
| | | // orderDetl.setStatus(1); |
| | | // orderDetl.setQty(0.0D); |
| | | //// if (!orderDetlService.insert(orderDetl)) { |
| | | //// callApiLogSaveOrder(order,kingDeeUtilType, "生成单据明细失败,请联系管理员!订单号:"+order.getOrderNo(), false); |
| | | ////// throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | //// } |
| | | // OrderInAndOutUtil.insertOrderDetl(kingDeeUtilType.pakIn == 1,order,orderDetl); |
| | | // } |
| | | // docTypeService.updateById(docType); |
| | | // } |
| | | // } |
| | | else { |
| | | int pageSize = jsonResponse.getJSONObject("data").getIntValue("pageSize"); |
| | | int totalCount = jsonResponse.getJSONObject("data").getIntValue("totalCount"); |
| | | int totalPages = (int) Math.ceil((double) totalCount / pageSize); |
| | | for (int page = 1; page <= totalPages; page++) { |
| | | jsonObject1.put("pageNo", page); |
| | | add = jsonObject1.toJSONString(); |
| | | // 重新发起请求以获取该页的数据 |
| | | response = new HttpHandler.Builder() |
| | | .setHeaders(headers) |
| | | .setUri(URL) |
| | | .setPath(path) |
| | | .setJson(add) |
| | | .build() |
| | | .doPost(); |
| | | |
| | | jsonResponse = JSON.parseObject(response); |
| | | data = jsonResponse.getJSONObject("data").getJSONArray("rows"); |
| | | for (int j = 0; j < data.size(); j++) { |
| | | JSONObject jsonObjectNew = data.getJSONObject(j); |
| | | Date updateTime = sdf1.parse(jsonObjectNew.get("modifytime").toString()); |
| | | String ownerUuid = jsonObjectNew.get("supplier_number").toString();//货主编码 |
| | | String owner = jsonObjectNew.get("supplier_name").toString();//货主名称 |
| | | Date createTime = sdf1.parse(jsonObjectNew.get("createtime").toString()); |
| | | String billNo = jsonObjectNew.get("billno").toString(); |
| | | |
| | | Order order = OrderInAndOutUtil.selectByNo(kingDeeUtilType.pakIn == 1, billNo);//检索单据 |
| | | LocOwner locOwner = null; |
| | | if (ownerUuid != null) { |
| | | locOwner = locOwnerService.selectByUuid(ownerUuid); |
| | | if (locOwner == null) { |
| | | callApiLogSaveOrder(order,kingDeeUtilType, "货主检索失败,请先添加对应货主编号:"+ownerUuid, false);continue; |
| | | } |
| | | } else{ |
| | | callApiLogSaveOrder(order,kingDeeUtilType, "货主检索失败,未查询到货主编号!", false);continue; |
| | | } |
| | | if (Cools.isEmpty(order)) { |
| | | // 单据主档 |
| | | order = new Order( |
| | | String.valueOf(snowflakeIdWorker.nextId()), // 编号[非空] |
| | | billNo, // 订单编号 |
| | | createTime.toString(), // 单据日期 |
| | | docType.getDocId(), // 单据类型 |
| | | null, // 项目编号 |
| | | "1", //项目名称 客户PO号 暂时不知道字段是哪个 |
| | | null, // 调拨项目编号 |
| | | null, // 初始票据号 |
| | | null, // 票据号 |
| | | null, // 项目id |
| | | locOwner.getOwner(), // 客户 |
| | | null, // 联系方式 |
| | | null, // 操作人员 |
| | | null, // 合计金额 |
| | | null, // 优惠率 |
| | | null, // 优惠金额 |
| | | null, // 销售或采购费用合计 |
| | | null, // 实付金额 |
| | | null, // 付款类型 |
| | | null, // 业务员 |
| | | null, // 结算天数 |
| | | null, // 邮费支付类型 |
| | | null, // 邮费 |
| | | null, // 付款时间 |
| | | null, // 发货时间 |
| | | null, // 物流名称 |
| | | null, // 物流单号 |
| | | 1L, // 订单状态 |
| | | 1, // 状态 |
| | | 9527L, // 添加人员 |
| | | now, // 添加时间 |
| | | 9527L, // 修改人员 |
| | | now, // 修改时间 |
| | | null // 备注 |
| | | ); |
| | | OrderInAndOutUtil.insertOrder(kingDeeUtilType.pakIn == 1, order); |
| | | } |
| | | JSONArray billEntryArray = jsonObjectNew.getJSONArray("billentry"); |
| | | for (int k = 0; k < billEntryArray.size(); k++) { |
| | | JSONObject entry = billEntryArray.getJSONObject(k); |
| | | String matnr = entry.getString("material_number"); |
| | | Double qty = entry.getDouble("qty"); |
| | | //物料编码 |
| | | Mat mat = matService.selectByMatnr(matnr); |
| | | if (Cools.isEmpty(mat)) { |
| | | callApiLogSaveOrder(order,kingDeeUtilType, "编号商品检索失败,请先添加商品"+matnr, false); |
| | | continue; |
| | | } |
| | | Order order1 = OrderInAndOutUtil.selectByNo(kingDeeUtilType.pakIn == 1, billNo); |
| | | List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(kingDeeUtilType.pakIn == 1, order1.getId()); |
| | | boolean sign = false; |
| | | for (OrderDetl orderDetl : orderDetls){ |
| | | if (orderDetl.getMatnr().equals(matnr)){ |
| | | sign = true; |
| | | break; |
| | | } |
| | | } |
| | | if (sign){ |
| | | continue; |
| | | } |
| | | OrderDetl orderDetl = new OrderDetl(); |
| | | orderDetl.sync(mat); |
| | | orderDetl.setBatch(null); |
| | | orderDetl.setAnfme(qty); |
| | | orderDetl.setOrderId(order.getId()); |
| | | orderDetl.setOrderNo(order.getOrderNo()); |
| | | orderDetl.setCreateBy(9527L); |
| | | orderDetl.setCreateTime(new Date()); |
| | | orderDetl.setUpdateBy(9527L); |
| | | orderDetl.setUpdateTime(new Date()); |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | OrderInAndOutUtil.insertOrderDetl(kingDeeUtilType.pakIn == 1,order,orderDetl); |
| | | } |
| | | } |
| | | docTypeService.updateById(docType); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("fail", e); |
| | | // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |