Newer
Older
pgdsc / src / com / szpg / plc / PGDSCServlet.java
ty-pc\admin on 22 May 2019 7 KB 20190522 环境监测功能梳理
package com.szpg.plc;

import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

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

import com.szpg.db.dao.PgAcuDao;
import com.szpg.db.dao.impl.PgAcuDaoImpl;
import com.szpg.db.data.PgAcu;
import com.szpg.plc.server.ACUClient;
import com.szpg.plc.server.ACUClientUtil;
import com.szpg.task.ACUSocketCheckTask;
import com.szpg.task.ReadAssetInSpectionTask;
import com.szpg.task.ReadCH4ValueTask;
import com.szpg.task.ReadCOValueTask;
import com.szpg.task.ReadDSStatusTask;
import com.szpg.task.ReadHSStatusTask;
import com.szpg.task.ReadHSValueTask;
import com.szpg.task.ReadMaintanceTask;
import com.szpg.task.ReadO2ValueTask;
import com.szpg.task.ReadWSValueTask;
import com.szpg.task.ReadYWStatusTask;
import com.szpg.task.SetCH4ThresholdTask;
import com.szpg.task.SetCOThresholdTask;
import com.szpg.task.SetHSThresholdTask;
import com.szpg.task.SetO2ThresholdTask;
import com.szpg.task.SetWSThresholdTask;
import com.szpg.util.Configure;

public class PGDSCServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4422075957571639803L;
	
	@Override
	public void init() throws ServletException {
		// 1获取数据库中所有ACU
		PgAcuDao acuDao = new PgAcuDaoImpl();
		List<PgAcu> acuList = acuDao.findAllACU();
		
		// 2遍历ACU列表,获取其IP地址与端口号
		for (PgAcu acu : acuList) {
			ACUClient client = new ACUClient(acu.getAcu_host(), Integer.parseInt(acu.getAcu_port()));
			
			client.setAcucode(acu.getAcu_code());
			client.setNet(acu.getAcu_net());
			client.setNode(acu.getAcu_node());
			client.setUnit(acu.getAcu_unit());
			
			// 3将ACU的信息加入到map中
			ACUClientUtil.getInstance().addClient(client);
			
			// 4新建线程启动client
			new ScheduledThreadPoolExecutor(1).scheduleAtFixedRate(new ACUSocketCheckTask(client), 0, 30, TimeUnit.SECONDS);
		}
		
		// 3启动查询温湿度的定时任务
		sendQueryWSValueCommand();
		sendSetWSThresholdCommand();
		
		// 4启动查询甲烷的定时任务
		sendQueryCH4ValueCommand();
		sendSetCH4ThresholdCommand();
		
		// 5启动查询一氧化碳的定时任务
		sendQueryCOValueCommand();
		sendSetCOThresholdCommand();
		
		// 6氧气
		sendQueryO2ValueCommand();
		sendSetO2ThresholdCommand();
		
		// 7硫化氢
		sendQueryHSValueCommand();
		sendSetHSThresholdCommand();
		
		// 8对射报警
//		sendDSStatusCommand();
		
		// 9液位报警
//		sendYWStatusCommand();

		//10巡检数据同步
		synchAssetInSpection();

		//运维数据同步
		synchMaintanceRecord();
	}
	
	/**
	 * 发送查询温湿度监测值命令
	 * 
	 * @param client
	 */
	private void sendQueryWSValueCommand() {
		int interval = Integer.parseInt(Configure.getProperty("sys", "READ_WS_VALUE_INTERVAL", "60"));
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadWSValueTask(), 20, interval * 60, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询氧气监测值命令
	 * 
	 * @param client
	 */
	private void sendQueryO2ValueCommand() {
		int interval = Integer.parseInt(Configure.getProperty("sys", "READ_O2_VALUE_INTERVAL", "60"));
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadO2ValueTask(), 40, interval * 60, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询硫化氢监测值命令
	 * 
	 * @param client
	 */
	private void sendQueryHSValueCommand() {
		int interval = Integer.parseInt(Configure.getProperty("sys", "READ_HS_VALUE_INTERVAL", "60"));
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadHSValueTask(), 50, interval * 60, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询甲烷监测值命令
	 * 
	 * @param client
	 */
	private void sendQueryCH4ValueCommand() {
		int interval = Integer.parseInt(Configure.getProperty("sys", "READ_CH4_VALUE_INTERVAL", "60"));
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadCH4ValueTask(), 10, interval * 60, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询一氧化碳监测值命令
	 * 
	 * @param client
	 */
	private void sendQueryCOValueCommand() {
		int interval = Integer.parseInt(Configure.getProperty("sys", "READ_CO_VALUE_INTERVAL", "60"));
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadCOValueTask(), 30, interval * 60, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询温湿度报警状态命令
	 * @param client
	 */
	private void sendSetWSThresholdCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new SetWSThresholdTask(), 25, 1440, TimeUnit.MINUTES); // 每日重置所有设备的温湿度阈值
	}
	
	/**
	 * 发送查询甲烷报警状态命令
	 * @param client
	 */
	private void sendSetCH4ThresholdCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new SetCH4ThresholdTask(), 15, 1440, TimeUnit.MINUTES); // 每日重置所有设备的甲烷浓度阈值
	}
	
	/**
	 * 发送查询一氧化碳报警状态命令
	 * @param client
	 */
	private void sendSetCOThresholdCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new SetCOThresholdTask(), 35, 1440, TimeUnit.MINUTES); // 每日重置所有设备的一氧化碳浓度阈值
	}
	
	/**
	 * 发送查询一氧化碳报警状态命令
	 * @param client
	 */
	private void sendSetO2ThresholdCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new SetO2ThresholdTask(), 45, 1440, TimeUnit.MINUTES); // 每日重置所有设备的氧气浓度阈值
	}
	
	/**
	 * 发送查询硫化氢报警状态命令
	 * @param client
	 */
	private void sendSetHSThresholdCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new SetHSThresholdTask(), 55, 1440, TimeUnit.MINUTES); // 每日重置所有设备的硫化氢浓度阈值
	}
	
	/**
	 * 发送查询对射报警状态命令
	 * @param client
	 */
	private void sendDSStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadDSStatusTask(), 60, 600, TimeUnit.SECONDS);
	}
	
	/**
	 * 发送查询爆管液位报警状态命令
	 * @param client
	 */
	private void sendYWStatusCommand() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadYWStatusTask(), 70, 600, TimeUnit.SECONDS);
	}

	/**
	 * 调用巡检接口同步数据
	 * @param
	 */
	private void synchAssetInSpection() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadAssetInSpectionTask(), 60, 600, TimeUnit.SECONDS);
	}

	/**
	 * 调用维护接口同步数据
	 * @param
	 */
	private void synchMaintanceRecord() {
		ScheduledExecutorService sche = new ScheduledThreadPoolExecutor(1);
		sche.scheduleWithFixedDelay(new ReadMaintanceTask(), 60, 600, TimeUnit.SECONDS);
	}

}