AirPortCar.java 4.0 KB
package com.air.model;

import com.air.model.base.BaseAirPortCar;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;

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

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

	/**
	 * 查询
	 * 
	 * @param page
	 *            页码
	 * @param pageNum
	 *            每页数量
	 * @param key
	 *            关键字
	 * @param isApi
	 *            是否用于api
	 */
	public Page<AirPortCar> searchPre(int page, int pageNum, String key, int sysUserId) {
		String orderBy = " order by updateTime desc";
		StringBuilder sb = new StringBuilder();
		String table = table();
		sb.append(" from " + table);
		sb.append(" where id>0");
		if (!StrKit.isBlank(key)) {
			// 搜索
			sb.append(" and (agentName like '%" + key + "%'");
			sb.append(" or driverName like '%" + key + "%'");
			sb.append(" or phone like '%" + key + "%'");
			sb.append(" or carNo like '%" + key + "%')");
		}

		sb.append(" and sysUserId=" + sysUserId);

		String listSql = sb.toString();
		Page<AirPortCar> dataList = AirPortCar.dao.paginate(page, pageNum, "select *", listSql + orderBy);
		return dataList;
	}

	/**
	 * 查询
	 * 
	 * @param page
	 *            页码
	 * @param pageNum
	 *            每页数量
	 * @param key
	 *            关键字
	 * @param status
	 *            车辆进出场状态
	 * @param stationArea
	 *            货站区域标识
	 */
	public Page<AirPortCar> search(int page, int pageNum, String key, AirPortCarStatus status, String stationArea) {
		String orderBy = " order by updateTime desc";
		if (status != null) {
			switch (status) {
			case APPLY:
				orderBy = " order by applyTime desc";
				break;
			case ENTER:
				orderBy = " order by enterTime desc";
				break;
			case LEFT:
				orderBy = " order by leaveTime desc";
				break;
			default:
				break;
			}
		}

		String listSql = buildListSql(key, status, stationArea);
		Page<AirPortCar> dataList = AirPortCar.dao.paginate(page, pageNum, "select *", listSql + orderBy);
		return dataList;
	}

	private String buildListSql(String key, AirPortCarStatus status, String stationArea) {
		StringBuilder sb = new StringBuilder();
		String table = table();
		sb.append(" from " + table);
		sb.append(" where id>0");
		if (!StrKit.isBlank(key)) {
			// 搜索
			sb.append(" and (agentName like '%" + key + "%'");
			sb.append(" or driverName like '%" + key + "%'");
			sb.append(" or phone like '%" + key + "%'");
			sb.append(" or carNo like '%" + key + "%')");
		}

		if (status != null) {
			sb.append(" and status=" + status.ordinal());
		}

		if (stationArea != null) {
			sb.append(" and stationArea='" + stationArea + "'");
		}

		return sb.toString();
	}

	/**
	 * 
	 * @param page
	 *            页码
	 * @param pageNum
	 *            每页请求数量
	 * @param key
	 *            搜索关键字
	 * @param portNo
	 *            码头编号
	 * @param stationArea
	 *            货站区域标识
	 * @param isPickup
	 *            是否为提货(是否为进港码头)
	 * @return
	 */
	public Page<AirPortCar> search(int page, int pageNum, String key, int portNo, String stationArea,
			boolean isPickup) {
		String orderBy = " order by isStick desc";
		StringBuilder sb = new StringBuilder();
		String table = table();
		sb.append(" from " + table);
		sb.append(" where id>0");
		if (!StrKit.isBlank(key)) {
			// 搜索
			sb.append(" and (agentName like '%" + key + "%'");
			sb.append(" or driverName like '%" + key + "%'");
			sb.append(" or phone like '%" + key + "%'");
			sb.append(" or carNo like '%" + key + "%')");
		}
		
		sb.append(" and status=" + AirPortCarStatus.ENTER.ordinal());

		if (stationArea != null) {
			sb.append(" and stationArea='" + stationArea + "'");
		}

		if (portNo > 0) {
			sb.append(" and portNo=" + portNo);
		}

		sb.append(" and isPickup=" + isPickup);

		String listSql = sb.toString();
		Page<AirPortCar> dataList = AirPortCar.dao.paginate(page, pageNum, "select *", listSql + orderBy);
		return dataList;
	}

}