自动化立体仓库 - WMS系统
#
野心家
2023-08-15 70b53436d2329221c10d44a98bef35714faa4968
src/main/java/com/zy/asrs/task/kingdee/handler/InboundOrderHandler.java
@@ -71,7 +71,7 @@
    @Transactional
    public synchronized ReturnT<String> start() {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //登录金蝶r
        //登录金蝶
        ReturnT<String> start = loginAuthenticationHandler.start();
        for(int i=0;i<14;i++) {
            InFormIdParam inFormIdParam = new InFormIdParam();
@@ -89,7 +89,7 @@
                //生产领料
                case 3 : inFormIdParam.setFormId("PRD_PickMtrl");docName=22;anfme ="FActualQty"; break;
                //生产退料
                case 4 : inFormIdParam.setFormId("BD_MATERIAL");docName=24;anfme ="FQty"; break;
                case 4 : inFormIdParam.setFormId("PRD_ReturnMtrl");docName=24;anfme ="FQty"; break;
                //生产补料
                case 5 : inFormIdParam.setFormId("PRD_FeedMtrl");docName=25;anfme ="FActualQty"; break;
                //直接调拨单
@@ -109,7 +109,7 @@
                //销售退货
                case 13 : inFormIdParam.setFormId("SAL_RETURNSTOCK");docName=33;anfme ="FRealQty"; break;
            }
            inFormIdParam.setLimit(10);
            inFormIdParam.setLimit(100);
            inFormIdParam.setStartRow("0");
            Date time=new Date();
            String FDocumentStatus=null;
@@ -124,9 +124,9 @@
                Tag tag = tagService.selectById(20);
                //最新时间
                time=tag.getCreateTime();
                //物料状态
                //物料状态 FUseOrgId .FNumber
                FDocumentStatus="C";
                jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(time)+"' and FDocumentStatus='"+FDocumentStatus+"'");
                jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(time)+"' and FDocumentStatus='"+FDocumentStatus+"' and FUseOrgId .FNumber='201'");
                jsonObject.put("FieldKeys", "FName,FNumber,FCreateDate,FSpecification,FDocumentStatus");
                // FName : 物料名称 ;
                // FNumber :物料编号;
@@ -137,8 +137,8 @@
                //获取最新时间
                DocType docType= docTypeService.selectById(docName);
                //单据状态
                FDocumentStatus="C";
                jsonObject.put("FilterString", "FCreateDate>'"+sdf.format(docType.getCreateTime())+"' and FDocumentStatus='"+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,"+anfme+",FDocumentStatus");
                // FBillNo :单据编号;
                // FCreateDate :单据创建时间;
@@ -152,8 +152,6 @@
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("data", jsonObject);
            String add = jsonObject1.toJSONString();
            System.out.println(add);
            //上报
            String response = "";
            boolean success = false;
@@ -169,115 +167,134 @@
                        .build()
                        .doPost();
                JSONArray data = JSON.parseArray(response);
                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());//规格
                            //对美国时间进行转换
                            DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                            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());
//                        }
                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 {
                            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");
                        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 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)) {
//                            throw new CoolException("生成单据明细失败,请联系管理员");
//                        }
                    }
                }
            } catch (Exception e) {
                log.error("fail", e);
@@ -287,8 +304,8 @@
                try {
                    // 保存接口日志
                    apiLogService.save(
                            "登录金蝶",
                            MesConstant.URL + MesConstant.PAKIN_URL,
                            "轮询数据",
                            URL + inaddress,
                            null,
                            "127.0.0.1",
                            add,