|  |  | 
 |  |  |         for(KingDeeUtilType kingDeeUtilType : KingDeeUtilType.values()) { | 
 |  |  |             InFormIdParam inFormIdParam = new InFormIdParam(); | 
 |  |  |             DocType docType = docTypeService.selectOne(new EntityWrapper<DocType>().eq("doc_name", kingDeeUtilType.desc)); | 
 |  |  |             if (Cools.isEmpty(docType)){ | 
 |  |  |             if (Cools.isEmpty(docType) && !kingDeeUtilType.formId.equals("BD_MATERIAL")){ | 
 |  |  |                 docType = docTypeService.selectOrAdd(kingDeeUtilType.desc, kingDeeUtilType.pakIn.equals(1)); | 
 |  |  |             } | 
 |  |  |             inFormIdParam.setFormId(kingDeeUtilType.formId); | 
 |  |  | 
 |  |  |             jsonObject.put("Limit", inFormIdParam.getLimit()); | 
 |  |  |             jsonObject.put("StartRow", inFormIdParam.getStartRow()); | 
 |  |  |             //物料档案查询 | 
 |  |  |             if(inFormIdParam.getFormId().equals("BD_MATERIAL")){ | 
 |  |  |             if(kingDeeUtilType.formId.equals("BD_MATERIAL")){ | 
 |  |  |                 Tag tag = tagService.selectByName("全部", 1); | 
 |  |  |                 //物料状态 FUseOrgId .FNumber | 
 |  |  |                 FDocumentStatus="C"; | 
 |  |  |                 jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(tag.getUpdateTime())+"' and FDocumentStatus='"+FDocumentStatus+"' and FUseOrgId .FNumber='201'"); | 
 |  |  |                 jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(tag.getUpdateTime())+"' and FDocumentStatus='"+FDocumentStatus+"' and FUseOrgId .FNumber='100'"); | 
 |  |  |                 jsonObject.put("FieldKeys", "FName,FNumber,FCreateDate,FSpecification,FDocumentStatus"); | 
 |  |  |                 // FName : 物料名称 ; | 
 |  |  |                 // FNumber :物料编号; | 
 |  |  | 
 |  |  |                 //获取最新时间 | 
 |  |  |                 //单据状态 | 
 |  |  |                 FDocumentStatus="B"; | 
 |  |  |                 jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(docType.getCreateTime())+"' and FStockId.Fname='立库'"+" and FDocumentStatus='"+FDocumentStatus+"'"); | 
 |  |  |                 jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(docType.getCreateTime())+"'"+" and FStockId.Fname='立库'"+" and FDocumentStatus='"+FDocumentStatus+"'"); | 
 |  |  |                 jsonObject.put("FieldKeys", "FBillNo,FCreateDate,FMaterialId.FNumber,FMaterialId.FName,FMaterialId.FSpecification,"+kingDeeUtilType.anfme+",FDocumentStatus"); | 
 |  |  |                 // FBillNo :单据编号; | 
 |  |  |                 // FCreateDate :单据创建时间; | 
 |  |  | 
 |  |  |                     for (int j = 0; j < data.size(); j++) { | 
 |  |  |                         JSONArray jsonArray = data.getJSONArray(j); | 
 |  |  |                         //对美国时间进行转换 | 
 |  |  |                         Date date = KingDeeUtil.KingDeeDate(jsonArray.get(2).toString()); | 
 |  |  |                         Date jsonDate = KingDeeUtil.KingDeeDate(jsonArray.get(2).toString()); | 
 |  |  |                         //生成商品档案 | 
 |  |  |                         //商品编号 | 
 |  |  |                         Mat mat = matService.selectByMatnr(jsonArray.get(1).toString()); | 
 |  |  | 
 |  |  |                             mat.setMaktx(jsonArray.get(0).toString()); | 
 |  |  |                             mat.setSpecs(jsonArray.get(3).toString());//规格 | 
 |  |  |                             mat.setTagId(tag.getId()); | 
 |  |  |                             mat.setCreateTime(date);//商品创建时间 | 
 |  |  |                             mat.setCreateTime(jsonDate);//商品创建时间 | 
 |  |  |                             mat.setUpdateTime(new Date()); | 
 |  |  |                             mat.setStatus(1); | 
 |  |  |                             //最新抓取商品时间 | 
 |  |  |                             if (!matService.insert(mat)) { | 
 |  |  | //                                throw new CoolException("服务器内部错误,请联系管理员"); | 
 |  |  |                                 callApiLogSaveMat(mat,kingDeeUtilType, "同步新物料出错!!!"+mat, false); | 
 |  |  |                                 log.info("同步新物料出错!!!参数:[{}]、[{}]",mat,jsonArray); | 
 |  |  |                             } else { | 
 |  |  |                                 log.info("同步新物料[商品编号:{}]", mat.getMatnr()); | 
 |  |  |                                 callApiLogSaveMat(mat,kingDeeUtilType, "同步新物料!", true); | 
 |  |  | //                                log.info("同步新物料[商品编号:{}]", mat.getMatnr()); | 
 |  |  |                             } | 
 |  |  |                         }else { | 
 |  |  |                             log.info("同步新物料[商品编号:{}],商品编号重复!!!", mat.getMatnr()); | 
 |  |  |                             if (!jsonDate.equals(tag.getUpdateTime())){ | 
 |  |  |                                 callApiLogSaveMat(mat,kingDeeUtilType, "商品编号重复:"+mat.getMatnr(), false); | 
 |  |  |                                 log.info("同步新物料[商品编号:{}],商品编号重复!!!", mat.getMatnr()); | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                         tag.setUpdateTime(date); | 
 |  |  |                         tag.setUpdateTime(jsonDate); | 
 |  |  |                     } | 
 |  |  |                     tagService.updateById(tag); | 
 |  |  |                 } else { | 
 |  |  |                     for (int j = 0; j < data.size(); j++) { | 
 |  |  |                         JSONArray jsonArray = data.getJSONArray(j); | 
 |  |  |                         //最新抓取时间 | 
 |  |  |                         Date jsonDate = KingDeeUtil.KingDeeDate(jsonArray.get(1).toString()); | 
 |  |  |                         docType.setCreateTime(jsonDate); | 
 |  |  |                         Order order = orderService.selectByNo(jsonArray.get(0).toString()); | 
 |  |  |                         if (Cools.isEmpty(order)) { | 
 |  |  |                             Date now = new Date(); | 
 |  |  | 
 |  |  |                                     null    // 备注 | 
 |  |  |                             ); | 
 |  |  |  | 
 |  |  |                             //最新抓取时间 | 
 |  |  |                             Date jsonDate = KingDeeUtil.KingDeeDate(jsonArray.get(2).toString()); | 
 |  |  |                             docType.setCreateTime(jsonDate); | 
 |  |  |                             docTypeService.updateById(docType); | 
 |  |  |                             if (!orderService.insert(order)) { | 
 |  |  |                                 throw new CoolException("生成单据主档失败,请联系管理员"); | 
 |  |  |                                 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)) { | 
 |  |  |                             throw new CoolException(jsonArray.get(2).toString() + "编号商品检索失败,请先添加商品"); | 
 |  |  |                             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)) { | 
 |  |  | 
 |  |  |                         orderDetl.setUpdateTime(new Date()); | 
 |  |  |                         orderDetl.setStatus(1); | 
 |  |  |                         orderDetl.setQty(0.0D); | 
 |  |  |                         Date date = KingDeeUtil.KingDeeDate(jsonArray.get(1).toString()); | 
 |  |  |                         //最新抓取时间 | 
 |  |  |                         docType.setCreateTime(date); | 
 |  |  |                         if (!orderDetlService.insert(orderDetl)) { | 
 |  |  |                             throw new CoolException("生成单据明细失败,请联系管理员"); | 
 |  |  |                             callApiLogSaveOrder(order,kingDeeUtilType, "生成单据明细失败,请联系管理员!订单号:"+order.getOrderNo(), false); | 
 |  |  | //                            throw new CoolException("生成单据明细失败,请联系管理员"); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     docTypeService.updateById(docType); | 
 |  |  |                 } | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 log.error("fail", e); | 
 |  |  | //            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); | 
 |  |  |                 return FAIL.setMsg(e.getMessage()); | 
 |  |  |             } finally { | 
 |  |  |                 try { | 
 |  |  |                     // 保存接口日志 | 
 |  |  |                     apiLogService.save( | 
 |  |  |                             "轮询数据", | 
 |  |  |                             URL + inaddress, | 
 |  |  |                             null, | 
 |  |  |                             "127.0.0.1", | 
 |  |  |                             add, | 
 |  |  |                             response, | 
 |  |  |                             success | 
 |  |  |                     ); | 
 |  |  |                 } catch (Exception e) { | 
 |  |  |                     log.error("", e); | 
 |  |  |                 } | 
 |  |  | //                try { | 
 |  |  | //                    // 保存接口日志 | 
 |  |  | //                    apiLogService.save( | 
 |  |  | //                            "轮询数据", | 
 |  |  | //                            URL + inaddress, | 
 |  |  | //                            null, | 
 |  |  | //                            "127.0.0.1", | 
 |  |  | //                            add, | 
 |  |  | //                            response, | 
 |  |  | //                            success | 
 |  |  | //                    ); | 
 |  |  | //                } catch (Exception e) { | 
 |  |  | //                    log.error("", e); | 
 |  |  | //                } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return SUCCESS; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void callApiLogSaveMat(Mat mat, KingDeeUtilType kingDeeUtilType, String response, Boolean bool) { | 
 |  |  |         apiLogService.save("获取"+kingDeeUtilType.desc, kingDeeUtilType.formId, "null", URL, | 
 |  |  |                 "物料编号:" + mat.getMatnr() + "、物料名称:" + mat.getName() + "、类型:" + mat.getTagId$() + "、状态:" + mat.getStatus$(), | 
 |  |  |                 response, bool); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void callApiLogSaveOrder(Order order, KingDeeUtilType kingDeeUtilType, String response, Boolean bool) { | 
 |  |  |         apiLogService.save("获取"+kingDeeUtilType.desc, kingDeeUtilType.formId, "null", URL, | 
 |  |  |                 "单据编号:" + order.getId() +  "、状态:" + order.getStatus$(), | 
 |  |  |                 response, bool); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |