PointUtil.java 2.6 KB
package com.myproject.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.query.Criteria;

import java.util.concurrent.ExecutionException;


public class PointUtil {

    protected static final transient Logger log = LogManager.getLogger(PointUtil.class);
    public static Point getPosPoint(String posId ) {
        return getPosPoint(posId,true   );
    }

    /**
     * 获取坐标
     * @param posId 库位号
     * @param isUpdatePos true=更新库位坐标。false=查询使用
     * @return
     */
    public static Point getPosPoint(String posId, boolean isUpdatePos) {
//        库位号格式:
//        例:05AA03040102
//        05:表示料仓编号,01-08
//        AA:存储机构A面或B面,AA或者BB
//        03:表示抽屉在第几行
//        04:表示抽屉在第几列
//        01:表示在抽屉中的第几行
//        02:表示在抽屉中的第几列
        Point p = new Point(0, 0);
        try {
            if (posId.length() == 12) {
                double storageNum = 0;
                int storage = Integer.parseInt(posId.substring(0, 2));

                String typeStr = posId.substring(2, 4);
                if (typeStr.equals("AA")) {
                    if(isUpdatePos){
                        storageNum = storage * 10 + 1;
                    }else{

                        storageNum = storage * 10 + 2;
                    }
                } else {
                    if(isUpdatePos){
                        storageNum = storage * 10 + 2;
                    }else{
                        storageNum = storage * 10 + 1;
                    }
                }
                double row = Integer.parseInt(posId.substring(4, 6));
                double column = Integer.parseInt(posId.substring(6, 8));

                double x = storageNum + column / 100;
                double y = storageNum + row / 1000;

                double drawerRow=1;
                double drawerColumn=1;
                if (isUpdatePos) {
                     drawerRow = Integer.parseInt(posId.substring(8, 10));
                     drawerColumn = Integer.parseInt(posId.substring(10, 12));
                }
                x += drawerColumn / 100 / 1000;
                y += +drawerRow / 1000 / 100;

                p = new Point(x, y);
            }
        } catch (Exception ex) {
            log.error("解析库位[" + posId + "]的坐标出错:" + ex);
        }

//        log.info("解析库位[" + posId + "]的坐标结果:" + p.toString());

        return p;
    }

}