Java tutorial
package cn.com.gps169.server.handler.impl; import java.util.Calendar; import java.util.Date; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import cn.com.gps169.common.model.GpsInfo; import cn.com.gps169.common.tool.DateUtil; import cn.com.gps169.db.model.Terminal; import cn.com.gps169.db.model.TerminalVehicle; import cn.com.gps169.db.model.Vehicle; import cn.com.gps169.server.handler.GpsHandler; import cn.com.gps169.server.handler.IJt808Handler; import cn.com.gps169.server.handler.RunningStatusHandler; import cn.com.gps169.server.protocol.Jt808Message; import cn.com.gps169.server.protocol.impl.JT0200; import cn.com.gps169.server.tool.JT808Constants; /** * ??? * @author tianfei * */ @Component("jt0200Handler") public class JT0200Handler extends IJt808Handler { private transient Logger Logger = LoggerFactory.getLogger(JT0200Handler.class); @Autowired private GpsHandler gpsHandler; @Autowired private RunningStatusHandler runningStatusHandler; @Override public void handle(Jt808Message msg) { JT0200 body = (JT0200) msg.getBody(); GpsInfo gi = new GpsInfo(); Date dt = DateUtil.stringToDatetime(body.getTime()); if (dt == null) { Logger.error(String.format( "sim?:%s,?%s,??:%s", gi.getSimNo(), msg.getSimNo(), body.getTime())); return; } Calendar c = Calendar.getInstance(); c.setTime(dt); // ???,? if (c.get(Calendar.YEAR) != Calendar.getInstance().get(Calendar.YEAR)) { Logger.info(String.format("??:??:%s,?", DateUtil.TIMEFORMATER1().format(dt))); return; } if (body.getLatitude() <= 0 || body.getLongitude() <= 0) { Logger.info(String.format("?,?? :??:%s", DateUtil.TIMEFORMATER1().format(dt))); return; } Terminal tmnl = terminalCacheManager.getTerminalBySimNo(msg.getSimNo()); TerminalVehicle tv = tmnlVehicleCacheManager.findCurBindRelationsByTerminalId(tmnl.getTerminalId()); Vehicle vehicle = null; if (tv != null) { vehicle = vehicleCacheManager.findVehicleById(tv.getVehicleId()); if (vehicle != null) { //? gi.setVid(vehicle.getVehicleId()); if (body.getSpeed() > 1) { dataAcquireCacheManager.setRunningStatus(vehicle.getVehicleId(), JT808Constants.VEHICLE_RUNNING_STATUS_RUNNING); gi.setRunStatus(JT808Constants.VEHICLE_RUNNING_STATUS_RUNNING); } else { dataAcquireCacheManager.setRunningStatus(vehicle.getVehicleId(), JT808Constants.VEHICLE_RUNNING_STATUS_STOP); gi.setRunStatus(JT808Constants.VEHICLE_RUNNING_STATUS_STOP); } } else { Logger.error("? ?"); return; } } else { Logger.error("SIM:" + msg.getSimNo()); return; } //GPS? gi.setTid(tmnl.getTerminalId()); gi.setSendTime(dt); gi.setPlateNo(vehicle.getLicensePlate()); gi.setSimNo(msg.getSimNo()); gi.setLatitude(0.000001 * body.getLatitude()); gi.setLongitude(0.000001 * body.getLongitude()); gi.setSpeed(0.1 * body.getSpeed()); gi.setDirection(body.getDirection()); gi.setStatus(body.getStatus()); gi.setAlarmStatus(body.getAlarm()); gi.setMileage(0.1 * body.getMileage()); gi.setFuel(0.1 * body.getFuel()); gi.setRecordSpeed(0.1 * body.getRecorderSpeed()); gi.setAltitude(body.getAltitude()); gi.setStatus(body.getStatus()); //??? gpsHandler.addGps(gi); //??? runningStatusHandler.processData(gi); //TODO:? } }