自动化立体仓库 - WMS系统
野心家
9 天以前 fe230e1fa505f5e5734de7b15b8225d6ec49659e
src/main/java/com/zy/asrs/controller/MatController.java
@@ -19,7 +19,6 @@
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.TagService;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.task.kingdee.handler.LoginAuthenticationHandler;
import com.zy.asrs.utils.MatExcelListener;
import com.zy.common.CodeRes;
import com.zy.common.config.AdminInterceptor;
@@ -69,8 +68,6 @@
    private LocDetlService locDetlService;
    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;
    @Autowired
    private LoginAuthenticationHandler loginAuthenticationHandler;
    @RequestMapping(value = "/mat/auto/matnr/auth")
    public R autoMatnr() {
@@ -159,154 +156,6 @@
        mat.setStatus(1);
        if (!matService.insert(mat)) {
            throw new CoolException("添加失败,请联系管理员");
        }
        return R.ok();
    }
    @RequestMapping(value = "/mat/KingDeeadd/auth")
    @ManagerAuth
    public R KingDeeadd() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //登录金蝶
        ReturnT<String> start = loginAuthenticationHandler.start();
        InFormIdParam inFormIdParam = new InFormIdParam();
        inFormIdParam.setFormId("BD_MATERIAL");
        inFormIdParam.setLimit(10000000);
        inFormIdParam.setStartRow("0");
        String FDocumentStatus = "C";
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();
        // 获取前一个月的同一天
        LocalDate previousMonthDate = currentDate.minusMonths(1);
        // 格式化日期为 "yyyyMMdd" 格式
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate2 = previousMonthDate.format(formatter1);
        //条件和需要获得的结果拼接
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("FormId", inFormIdParam.getFormId());
        jsonObject.put("Limit", inFormIdParam.getLimit());
        jsonObject.put("StartRow", inFormIdParam.getStartRow());
        jsonObject.put("FilterString", "FCreateDate>'" + formattedDate2 + "' and FDocumentStatus='" + FDocumentStatus + "' and FUseOrgId .FNumber='201'");
        jsonObject.put("FieldKeys", "FName,FNumber,FCreateDate,FSpecification,FDocumentStatus,FTuhao");
        // FName : 物料名称 ;
        // FNumber :物料编号;
        // FCreateDate :物料创建时间;
        // FSpecification :物料规格;
        // FDocumentStatus :物料状态
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("data", jsonObject);
        String add = jsonObject1.toJSONString();
        //上报
        String response = "";
        boolean success = false;
        try {
            //获取Cookie值
            HashMap<String, Object> headers = new HashMap<>();
            headers.put("Cookie", start.getContent());
            response = new HttpHandler.Builder()
                    .setHeaders(headers)
                    .setUri(URL)
                    .setPath(inaddress)
                    .setJson(add)
                    .build()
                    .doPost();
            JSONArray data = JSON.parseArray(response);
            int i = 0;
            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.setModel(jsonArray.get(5).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());
                                }
                            }
                        }
                    }
                }
            }
//            if (data.getJSONArray(0).get(0).toString().length() < 20) {
//                success = true;
//                JSONArray jsonArray = data.getJSONArray(0);
//                //生成商品档案
//                //商品编号
//                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 {
//                throw new CoolException("没有找到指定物料档案,请联系管理员");
//            }
        } catch (Exception e) {
            log.error("fail", e);
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "轮询数据",
                        URL + inaddress,
                        null,
                        "127.0.0.1",
                        add,
                        response,
                        success
                );
            } catch (Exception e) {
                log.error("", e);
            }
        }
        return R.ok();
    }