package com.szpg.plc;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.szpg.db.dao.PgDeviceDao;
import com.szpg.db.dao.PgHjsbblDao;
import com.szpg.db.dao.impl.PgDeviceDaoImpl;
import com.szpg.db.dao.impl.PgHjsbblDaoImpl;
import com.szpg.db.data.PgDevice;
import com.szpg.util.HttpRequest;

public class SendBaseServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4332152300810738268L;

	@Override
	public void init() throws ServletException {
		// 1根据ACU获取其所有的资产设备Device
		PgDeviceDao deviceDao = new PgDeviceDaoImpl();
		PgHjsbblDao blDao = new PgHjsbblDaoImpl();
		List<PgDevice> deviceList = deviceDao.findDeviceByAcu("YXL.ACU001");
		
		System.out.println("开始推送资产数据" + deviceList.size());
		
		int count = 0;
		
		// 2遍历ACU列表，获取其IP地址与端口号
		for (PgDevice device : deviceList) {
			// 发送 POST 请求
			// 推送资产表
			StringBuilder sb = new StringBuilder();
			sb.append("tableName=ZZB");
			sb.append("&Ent.ZCBH=").append(device.getAssetcode());
			sb.append("&Ent.ZCTM=");
			sb.append("&Ent.ZCMC=").append(device.getAssetname());
			sb.append("&Ent.SBLX=").append(device.getDevtype());
			sb.append("&Ent.SYSM=");
			sb.append("&Ent.AZSJ=");
			sb.append("&Ent.SFBF=0");
			
			String sr = HttpRequest.sendPostByHttp("http://10.10.2.19:9056/GLTHXC/api/Common/AddData", sb.toString());
			System.out.println(sr + " ====> " + count++);
		}
		
		System.out.println("推送资产数据结束" + count);
	}
}
