⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderentity.java

📁 短信开发用于文件交换处理转发的类模块
💻 JAVA
字号:
package com.pub.backserver.order;

import org.apache.log4j.Logger;
import org.apache.mina.common.ByteBuffer;

import com.pub.backserver.EntityHead;

/**
 * @author cnyqaio@hotmail.com
 * @create 2007-7-16
 */

public class OrderEntity extends EntityHead {

	private static Logger log = Logger.getLogger(OrderEntity.class);

	public static final int PackageLength = 49;

	public static final int orderLength = 41;

	/** 定长21个字节 手机号 */
	private String mobile;
	/** 定长 2个字节 运营商提供的消息编号 */
	private short operationId;
	/** 定长 2个字节 省编号 */
	private short provinceId;
	/** 定长 4个字节 产品编号 */
	private int prodId;
	/** 定长 4个字节 网关编号 */
	private int gwId;
	/** 定长 4个字节 渠道ID */
	private int channelId;

	/** 定长4个字节 为合作方分配的服务代码ID */
	private int serviceCodeId;

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("mobile=").append(getMobile()).append(";");
		sb.append("operationId=").append(getOperationId()).append(";");
		sb.append("provinceId=").append(getProvinceId()).append(";");
		sb.append("prodId=").append(getProdId()).append(";");
		sb.append("gwId=").append(getGwId()).append(";");
		sb.append("channelId=").append(getChannelId()).append(";");
		sb.append("serviceCode=").append(getServiceCodeId());
		return sb.toString();
	}

	public void reset() {
		operationId = provinceId = (short) (prodId = 0);
		channelId = 1;
	}
	public int getChannelId() {
		return channelId;
	}

	public void setChannelId(int channelId) {
		this.channelId = channelId;
	}

	public int getGwId() {
		return gwId;
	}

	public void setGwId(int gwId) {
		this.gwId = gwId;
	}

	public int getProdId() {
		return prodId;
	}

	public void setProdId(int prodId) {
		this.prodId = prodId;
	}

	public void setOperationId(short operationId) {
		this.operationId = operationId;
	}

	public void setProvinceId(short provinceId) {
		this.provinceId = provinceId;
	}

	public OrderEntity() {
		super(PackageLength);
	}


	public short getOperationId() {
		return operationId;
	}

	public void setOperation(short operationId) {
		this.operationId = operationId;
	}

	public short getProvinceId() {
		return provinceId;
	}

	public void setProvince(short proviceId) {
		this.provinceId = proviceId;
	}

	public int getServiceCodeId() {
		return serviceCodeId;
	}

	public void setServiceCodeId(int serviceCodeId) {
		this.serviceCodeId = serviceCodeId;
	}

	public int writePackage(ByteBuffer out) throws Exception {
//		super.setTotalLength(PackageLength);
		super.writePackage(out);
//		out.putString(this.getMobile(), 21, Message.charset.newEncoder());
		str2bytebuffer(out, this.getMobile(), 21);
		out.putShort(this.getOperationId());
		out.putShort(this.getProvinceId());
		out.putInt(this.getProdId());
		out.putInt(this.getGwId());
		out.putInt(this.getChannelId());
		out.putInt(this.getServiceCodeId());
		return 0;
	}

	public int readPackage(ByteBuffer in) throws Exception {
		super.readPackage(in);
//		this.setMobile(in.getString(21, Message.charset.newDecoder()));
		this.setMobile(bytebuffer2str(in, 21));
		this.setOperation(in.getShort());
		this.setProvince(in.getShort());
		this.setProdId(in.getInt());
		this.setGwId(in.getInt());
		this.setChannelId(in.getInt());
		this.setServiceCodeId(in.getInt());

		return 0;
	}

	
	public int writePackage(java.nio.ByteBuffer out) throws Exception {
//		super.setTotalLength(PackageLength);
		super.writePackage(out);
		str2bytebuffer(out,this.getMobile(),21);
		out.putShort(this.getOperationId());
		out.putShort(this.getProvinceId());
		out.putInt(this.getProdId());
		out.putInt(this.getGwId());
		out.putInt(this.getChannelId());
		out.putInt(this.getServiceCodeId());
		return 0;
	}
	
	  protected void str2bytebuffer(java.nio.ByteBuffer buf, String s,int len) {
		    if (buf.remaining() <= len - 1) return;
		    if(s == null){
		      s = "";
		    }
		    if (s.length() < len) {
		      for(int i = 0; i < s.length(); i++) {
		        buf.put((byte)s.charAt(i));
		      }
		      for(int i = s.length(); i < len; i++) {
		        buf.put((byte)0);
		      }
		    } else {
		      for(int i = 0; i < len; i++) {
		        buf.put((byte)s.charAt(i));
		      }
		    }
		  }
	  protected String bytebuffer2str(java.nio.ByteBuffer buf, int len) {
		    if (buf.remaining() <= len - 1) return null;
		    String r = new String();
		    boolean flag = true;
		    for (int i = 0; i < len; i++) {
		      byte temp;
		      if ((temp = buf.get()) != '\0' && flag){
		        r += (char) temp;
		      }
		      else{
		        flag = false;
		      }
		    }
		    return r;
		  }
	public int readPackage(java.nio.ByteBuffer in) throws Exception {
		super.readPackage(in);
		this.setMobile(bytebuffer2str(in,21));
		this.setOperation(in.getShort());
		this.setProvince(in.getShort());
		this.setProdId(in.getInt());
		this.setGwId(in.getInt());
		this.setChannelId(in.getInt());
		this.setServiceCodeId(in.getInt());

		return 0;
	}

	public int getHeaderLength() {
		return HeaderLength;
	}

	public int getPackageLength() {
		return PackageLength;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -