AirPort.java 2.6 KB
package com.air.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.air.model.base.BaseAirPort;
import com.jfinal.log.Log;

@SuppressWarnings("serial")
public class AirPort extends BaseAirPort<AirPort> {
	public static final AirPort dao = new AirPort();

	public String table() {
		return "WDS_"+getClass().getSimpleName();
	}

	/**
	 * 
	 * @param stationArea
	 *            货站区域标识
	 * @param isArrival
	 *            是否为进港(提货)业务
	 * @return
	 */
	public List<AirPort> getAirPortList(String stationArea, boolean isArrival) {
		Map<String, Object> maps = new HashMap<String, Object>();
		maps.put("stationArea", stationArea);
		maps.put("isArrival", isArrival);
		return AirPort.dao.search(maps);
	}

	/**
	 * 查询某个货站最空闲的码头
	 * 
	 * @param stationArea
	 *            货站的区域代码
	 * 
	 * @param isArrival
	 *            是否为进港业务(即提货)
	 * @return
	 */
	public AirPort free(String stationArea, boolean isArrival) {
		String sql = "select * from " + table();
		sql += " where stationArea='" + stationArea + "'";
		sql += " and isArrival=" + isArrival + "";
		String orderBy = " order by waitCount asc";
		sql += orderBy;

		Log.getLog(getClass()).error("sql-->" + sql);

		return AirPort.dao.findFirst(sql);
	}
	/**
	 * 查询某个货站最空闲的码头(没有进港业务(即提货)
	 * 
	 * @param stationArea
	 *        货站的区域代码
	 * @return
	 */
	public AirPort freetwo(String stationArea) {
		String sql = "select * from " + table();
		sql += " where stationArea='" + stationArea + "'";
		String orderBy = " order by waitCount asc";
		sql += orderBy;
		Log.getLog(getClass()).error("sql-->" + sql);
		return AirPort.dao.findFirst(sql);
	}
	public boolean enter(String stationArea, boolean isArrival, int portNo) {
		Map<String, Object> maps = new HashMap<String, Object>();
		maps.put("stationArea", stationArea);
		maps.put("isArrival", isArrival);
		maps.put("portNo", portNo);
		AirPort model = AirPort.dao.searchFirst(maps);
		if (model != null) {
			model.setWaitCount(model.getWaitCount() + 1);
			return model.update();
		}

		return false;
	}

	public boolean left(String stationArea, boolean isArrival, int portNo) {
		Map<String, Object> maps = new HashMap<String, Object>();
		maps.put("stationArea", stationArea);
		maps.put("isArrival", isArrival);
		maps.put("portNo", portNo);
		AirPort model = AirPort.dao.searchFirst1(maps);
		if (model != null) {
			int count = model.getWaitCount() - 1;
			if (count < 0) {
				count = 0;
			}
			model.setWaitCount(count);
			return model.update();
		}

		return false;
	}
}