IThirdServiceImpl.java 2.4 KB
package com.it.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.it.entity.CommonConstant;
import com.it.entity.ThirdPosition;
import com.it.mapper.ThirdMapper;
import com.it.service.IThirdService;
import com.it.tool.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.Map;

@Service
public class IThirdServiceImpl implements IThirdService {

    @Autowired
    private ThirdMapper thirdMapper;

    private static DecimalFormat df = new DecimalFormat("######0.0000");

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public void savePosition(JSONObject jsonObject) {
        addMsgLog(jsonObject);//添加接收报文日志
        ThirdPosition thirdPosition = new ThirdPosition();
        thirdPosition.setNodeId(jsonObject.getString("NodeId"));
        Map xyMap = jsonObject.getObject("position",Map.class);
        thirdPosition.setPositionx(xyMap.get("x").toString());
        thirdPosition.setPositiony(xyMap.get("y").toString());
        thirdPosition.setSystemId(jsonObject.getString("SystemId"));
        thirdPosition.setType(jsonObject.getString("Type"));
        thirdPosition.setGroup(jsonObject.getString("group"));
        thirdPosition.setGroupNumber(jsonObject.getInteger("groupNumber"));

    }

    /**
     * 收报文日志
     * @param jsonObject
     */
    private void addMsgLog(JSONObject jsonObject) {
        String sql = "INSERT INTO sys_msg_log  ( mag_log )  VALUES  ( '"+jsonObject.toJSONString()+"' )";
        System.out.println("**********"+sql);
        thirdMapper.addMsg(sql);
    }

    public static void main(String[] args) {
        changCoordinate("600.2330322265625","-300.28587341308594");
    }


    private static void changCoordinate(String x1, String y1) {
        double blc = 2.54;//联通比例尺

        double fd_x = blc*(Double.valueOf(x1)-CommonConstant.LT_B1_X)+CommonConstant.LT_B1_X;
        double fd_y = blc*(Double.valueOf(y1)+CommonConstant.LT_B1_Y)-CommonConstant.LT_B1_Y;
        System.out.println("放大后的坐标为:X:"+fd_x+",Y:"+fd_y);

        double a = CommonConstant.MQ_B1_X - CommonConstant.LT_B1_X;//原点偏移x
        double b = CommonConstant.MQ_B1_Y - CommonConstant.LT_B1_Y;//原点偏移y

        double x = Double.valueOf(fd_x) +  a;
        double y = Double.valueOf(fd_y) +  b;
        System.out.println("新坐标为:X:"+x+",Y:"+y);
    }
}