自动化立体仓库 - WMS系统
#
野心家
2023-08-10 f9a1f1b0a23bb8bc33a4a649f61f9efcce349279
src/main/java/com/zy/asrs/task/kingdee/handler/InboundOrderHandler.java
@@ -138,7 +138,7 @@
                DocType docType= docTypeService.selectById(docName);
                //单据状态
                FDocumentStatus="B";
                jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(docType.getCreateTime())+"' 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,"+anfme+",FDocumentStatus");
                // FBillNo :单据编号;
                // FCreateDate :单据创建时间;
@@ -167,131 +167,134 @@
                        .build()
                        .doPost();
                JSONArray data = JSON.parseArray(response);
                if(data.size()>0){
                    success = true;
                }
                if(i==0){
                    for (int j = 0; j < data.size(); j++) {
                        JSONArray jsonArray = data.getJSONArray(j);
                        //生成商品档案
                        //商品编号
                        Mat mat = matService.selectByMatnr(jsonArray.get(1).toString());
                        if (mat == null) {
                            mat = new Mat();
                            Tag tag=new Tag();
                            mat.setMatnr(jsonArray.get(1).toString());
                            mat.setMaktx(jsonArray.get(0).toString());
                            mat.setSpecs(jsonArray.get(3).toString());//规格
                            mat.setTagId(20L);
                            //对美国时间进行转换
                            DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                            DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
                            LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(2).toString(), formatter);
                            String format = dateFormat.format(dateTime);
                            Date date = sdf.parse(format);
                            mat.setCreateTime(date);//商品创建时间
                            mat.setUpdateTime(new Date());
                            mat.setStatus(1);
                            //最新抓取商品时间
                            tag.setCreateTime(date);
                        tagService.update(tag,new EntityWrapper<Tag>().eq("id",20));
                        if (!matService.insert(mat)) {
                            throw new CoolException("服务器内部错误,请联系管理员");
                if(data.size()>0) {
                if (data.getJSONArray(0).get(0).toString().length()<20) {
                        if (i == 0) {
                            for (int j = 0; j < data.size(); j++) {
                                JSONArray jsonArray = data.getJSONArray(j);
                                //生成商品档案
                                //商品编号
                                Mat mat = matService.selectByMatnr(jsonArray.get(1).toString());
                                if (mat == null) {
                                    mat = new Mat();
                                    Tag tag = new Tag();
                                    mat.setMatnr(jsonArray.get(1).toString());
                                    mat.setMaktx(jsonArray.get(0).toString());
                                    mat.setSpecs(jsonArray.get(3).toString());//规格
                                    mat.setTagId(20L);
                                    //对美国时间进行转换
                                    DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                                    DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
                                    LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(2).toString(), formatter);
                                    String format = dateFormat.format(dateTime);
                                    Date date = sdf.parse(format);
                                    mat.setCreateTime(date);//商品创建时间
                                    mat.setUpdateTime(new Date());
                                    mat.setStatus(1);
                                    //最新抓取商品时间
                                    tag.setCreateTime(date);
                                    tagService.update(tag, new EntityWrapper<Tag>().eq("id", 20));
                                    if (!matService.insert(mat)) {
                                        throw new CoolException("服务器内部错误,请联系管理员");
                                    } else {
                                        log.info("同步新物料[商品编号:{}]", mat.getMatnr());
                                    }
                                }
                            }
                        } else {
                            log.info("同步新物料[商品编号:{}]", mat.getMatnr());
                            for (int j = 0; j < data.size(); j++) {
                                JSONArray jsonArray = data.getJSONArray(j);
                                Order order = orderService.selectByNo(jsonArray.get(0).toString());
                                if (Cools.isEmpty(order)) {
                                    DocType docType = docTypeService.selectById(docName);
                                    Date now = new Date();
                                    // 单据主档
                                    order = new Order(
                                            String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                                            jsonArray.get(0).toString(),    // 订单编号
                                            DateUtils.convert(now),    // 单据日期
                                            docType.getDocId(),    // 单据类型
                                            null,    // 项目编号
                                            null,    //
                                            null,    // 调拨项目编号
                                            null,    // 初始票据号
                                            null,    // 票据号
                                            null,    // 客户编号
                                            null,    // 客户
                                            null,    // 联系方式
                                            null,    // 操作人员
                                            null,    // 合计金额
                                            null,    // 优惠率
                                            null,    // 优惠金额
                                            null,    // 销售或采购费用合计
                                            null,    // 实付金额
                                            null,    // 付款类型
                                            null,    // 业务员
                                            null,    // 结算天数
                                            null,    // 邮费支付类型
                                            null,    // 邮费
                                            null,    // 付款时间
                                            null,    // 发货时间
                                            null,    // 物流名称
                                            null,    // 物流单号
                                            1L,    // 订单状态
                                            1,    // 状态
                                            9527L,    // 添加人员
                                            now,    // 添加时间
                                            9527L,    // 修改人员
                                            now,    // 修改时间
                                            null    // 备注
                                    );
                                    //对美国时间进行转换
                                    DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                                    DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
                                    LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(1).toString(), formatter);
                                    String format = dateFormat.format(dateTime);
                                    Date date = sdf.parse(format);
                                    //最新抓取时间
                                    docType.setCreateTime(date);
                                    docTypeService.update(docType, new EntityWrapper<DocType>().eq("doc_id", docName));
                                    if (!orderService.insert(order)) {
                                        throw new CoolException("生成单据主档失败,请联系管理员");
                                    }
                                }
                                //物料编码
                                Mat mat = matService.selectByMatnr(jsonArray.get(2).toString());
                                if (Cools.isEmpty(mat)) {
                                    throw new CoolException(jsonArray.get(2).toString() + "编号商品检索失败,请先添加商品");
                                }
                                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;
                                }
                                DocType docType = docTypeService.selectById(docName);
                                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);
                                DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                                DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
                                LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(1).toString(), formatter);
                                String format = dateFormat.format(dateTime);
                                Date date = sdf.parse(format);
                                //最新抓取时间
                                docType.setCreateTime(date);
                                if (!orderDetlService.insert(orderDetl)) {
                                    throw new CoolException("生成单据明细失败,请联系管理员");
                                }
                            }
                        }
                        }
                    }else {
                    }
                }else {
                    for(int j=0;j<data.size();j++){
                        JSONArray jsonArray = data.getJSONArray(j);
                         Order order = orderService.selectByNo(jsonArray.get(0).toString());
                        if (Cools.isEmpty(order)) {
                        DocType docType = docTypeService.selectById(docName);
                        Date now = new Date();
                        // 单据主档
                        order = new Order(
                                String.valueOf(snowflakeIdWorker.nextId()),    // 编号[非空]
                                jsonArray.get(0).toString(),    // 订单编号
                                DateUtils.convert(now),    // 单据日期
                                docType.getDocId(),    // 单据类型
                                null,    // 项目编号
                                null,    //
                                null,    // 调拨项目编号
                                null,    // 初始票据号
                                null,    // 票据号
                                null,    // 客户编号
                                null,    // 客户
                                null,    // 联系方式
                                null,    // 操作人员
                                null,    // 合计金额
                                null,    // 优惠率
                                null,    // 优惠金额
                                null,    // 销售或采购费用合计
                                null,    // 实付金额
                                null,    // 付款类型
                                null,    // 业务员
                                null,    // 结算天数
                                null,    // 邮费支付类型
                                null,    // 邮费
                                null,    // 付款时间
                                null,    // 发货时间
                                null,    // 物流名称
                                null,    // 物流单号
                                1L,    // 订单状态
                                1,    // 状态
                                9527L,    // 添加人员
                                now,    // 添加时间
                                9527L,    // 修改人员
                                now,    // 修改时间
                                null    // 备注
                        );
                        //对美国时间进行转换
                        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
                        LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(1).toString(), formatter);
                        String format = dateFormat.format(dateTime);
                        Date date = sdf.parse(format);
                        //最新抓取时间
                        docType.setCreateTime(date);
                        docTypeService.update(docType,new EntityWrapper<DocType>().eq("doc_id",docName));
                        if (!orderService.insert(order)) {
                            throw new CoolException("生成单据主档失败,请联系管理员");
                        }
                        }
                        //物料编码
                        Mat mat = matService.selectByMatnr(jsonArray.get(2).toString());
                        if (Cools.isEmpty(mat)) {
                            throw new CoolException(jsonArray.get(2).toString() + "编号商品检索失败,请先添加商品");
                        }
                        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;
                        }
                        DocType docType = docTypeService.selectById(docName);
                        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);
                        DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
                        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
                        LocalDateTime dateTime = LocalDateTime.parse(jsonArray.get(1).toString(), formatter);
                        String format = dateFormat.format(dateTime);
                        Date date = sdf.parse(format);
                        //最新抓取时间
                        docType.setCreateTime(date);
                        if (!orderDetlService.insert(orderDetl)) {
                            throw new CoolException("生成单据明细失败,请联系管理员");
                        }
                    }
                }
            } catch (Exception e) {
                log.error("fail", e);