| | |
| | | import com.core.common.Cools; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.erp.kingdee.entity.param.InFormIdParam; |
| | | import com.zy.erp.kingdee.enums.KingDeeUtilType; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.erp.kingdee.utils.KingDeeUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Transactional |
| | | public synchronized ReturnT<String> start() { |
| | | SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | //登录金蝶 |
| | | ReturnT<String> start = loginAuthenticationHandler.start(); |
| | | for(KingDeeUtilType kingDeeUtilType : KingDeeUtilType.values()) { |
| | | 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) && !kingDeeUtilType.formId.equals("BD_MATERIAL")){ |
| | | if (Cools.isEmpty(docType) && !kingDeeUtilType.formId.equals("BD_MATERIAL")) { |
| | | docType = docTypeService.selectOrAdd(kingDeeUtilType.desc, kingDeeUtilType.pakIn.equals(1)); |
| | | } |
| | | inFormIdParam.setFormId(kingDeeUtilType.formId); |
| | | inFormIdParam.setLimit(100); |
| | | inFormIdParam.setStartRow("0"); |
| | | String FDocumentStatus=null; |
| | | String FDocumentStatus = null; |
| | | |
| | | //条件和需要获得的结果拼接 |
| | | JSONObject jsonObject = new JSONObject(); |
| | |
| | | jsonObject.put("Limit", inFormIdParam.getLimit()); |
| | | jsonObject.put("StartRow", inFormIdParam.getStartRow()); |
| | | //物料档案查询 |
| | | if(kingDeeUtilType.formId.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='100'"); |
| | | FDocumentStatus = "C"; |
| | | 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 :物料编号; |
| | | // FCreateDate :物料创建时间; |
| | | // FSpecification :物料规格; |
| | | // FDocumentStatus :物料状态 |
| | | }else{ |
| | | } else { |
| | | //获取最新时间 |
| | | //单据状态 |
| | | FDocumentStatus="B"; |
| | | 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"); |
| | | FDocumentStatus = "B"; |
| | | 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 :单据创建时间; |
| | | // FMaterialId.FNumber : 物料编码; |
| | |
| | | .build() |
| | | .doPost(); |
| | | JSONArray data = JSON.parseArray(response); |
| | | if(data.size()<=0) continue; |
| | | if (data.getJSONArray(0).get(0).toString().length()>=20) continue; |
| | | if (data.size() <= 0) continue; |
| | | if (data.getJSONArray(0).get(0).toString().length() >= 20) continue; |
| | | if (kingDeeUtilType.formId.equals("BD_MATERIAL")) {//物料档案 |
| | | Tag tag = tagService.selectByName("全部", 1); |
| | | for (int j = 0; j < data.size(); j++) { |
| | |
| | | //最新抓取商品时间 |
| | | if (!matService.insert(mat)) { |
| | | // throw new CoolException("服务器内部错误,请联系管理员"); |
| | | callApiLogSaveMat(mat,kingDeeUtilType, "同步新物料出错!!!"+mat, false); |
| | | log.info("同步新物料出错!!!参数:[{}]、[{}]",mat,jsonArray); |
| | | callApiLogSaveMat(mat, kingDeeUtilType, "同步新物料出错!!!" + mat, false); |
| | | log.info("同步新物料出错!!!参数:[{}]、[{}]", mat, jsonArray); |
| | | } else { |
| | | callApiLogSaveMat(mat,kingDeeUtilType, "同步新物料!", true); |
| | | callApiLogSaveMat(mat, kingDeeUtilType, "同步新物料!", true); |
| | | // log.info("同步新物料[商品编号:{}]", mat.getMatnr()); |
| | | } |
| | | }else { |
| | | if (!jsonDate.equals(tag.getUpdateTime())){ |
| | | callApiLogSaveMat(mat,kingDeeUtilType, "商品编号重复:"+mat.getMatnr(), false); |
| | | } else { |
| | | if (!jsonDate.equals(tag.getUpdateTime())) { |
| | | callApiLogSaveMat(mat, kingDeeUtilType, "商品编号重复:" + mat.getMatnr(), false); |
| | | log.info("同步新物料[商品编号:{}],商品编号重复!!!", mat.getMatnr()); |
| | | } |
| | | } |
| | |
| | | ); |
| | | |
| | | if (!orderService.insert(order)) { |
| | | if (!jsonDate.equals(docType.getCreateTime())){ |
| | | callApiLogSaveOrder(order,kingDeeUtilType, "生成单据主档失败,请联系管理员"+order, false); |
| | | 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); |
| | | if (!jsonDate.equals(docType.getCreateTime())) { |
| | | callApiLogSaveOrder(order, kingDeeUtilType, "编号商品检索失败,请先添加商品" + jsonArray.get(2).toString(), false); |
| | | } |
| | | continue; |
| | | } |
| | |
| | | orderDetl.setStatus(1); |
| | | orderDetl.setQty(0.0D); |
| | | if (!orderDetlService.insert(orderDetl)) { |
| | | callApiLogSaveOrder(order,kingDeeUtilType, "生成单据明细失败,请联系管理员!订单号:"+order.getOrderNo(), false); |
| | | callApiLogSaveOrder(order, kingDeeUtilType, "生成单据明细失败,请联系管理员!订单号:" + order.getOrderNo(), false); |
| | | // throw new CoolException("生成单据明细失败,请联系管理员"); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | public void callApiLogSaveMat(Mat mat, KingDeeUtilType kingDeeUtilType, String response, Boolean bool) { |
| | | apiLogService.save("获取"+kingDeeUtilType.desc, kingDeeUtilType.formId, "null", URL, |
| | | 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$(), |
| | | apiLogService.save("获取" + kingDeeUtilType.desc, kingDeeUtilType.formId, "null", URL, |
| | | "单据编号:" + order.getId() + "、状态:" + order.getStatus$(), |
| | | response, bool); |
| | | } |
| | | |