package com.nms.server.thread.mission;

import java.util.List;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;

import com.nms.server.bean.MissionResult;
import com.nms.server.bean.MissionStateTable;
import com.nms.server.bean.Task6;
import com.nms.server.util.ExceptionPrintUtils;
import com.nms.server.util.socket.SSLSocketCallable;
import com.socket.utils.FileComment;

public class NMSClientTask6Cover extends SSLSocketCallable{
	private final Logger logger = Logger.getLogger(NMSClientTask6Cover.class);
	private Task6 task6 ;
	private MissionStateTable mission;
	private MissionResult result;
	private String ip;
	private List<FileComment> fileCommentsList;
	public NMSClientTask6Cover(String ip,int port,MissionStateTable mission,Task6 object, MissionResult result,List<FileComment> fileCommentsList)  throws Exception{
		super(ip,port);
		this.ip = ip;
		this.task6 = object;
		this.mission = mission;
		this.result = result;
		this.fileCommentsList = fileCommentsList;
	}

	@Override
	protected String toDo() throws Exception {
		Thread.currentThread().setName("Task 6 id:> "+mission.getMissionId()+" IP:> "+this.socket.getRemoteSocketAddress());
		try {
			//-- 补全任务信息
			task6.setTaskId(mission.getMissionId());
			task6.setTaskType(mission.getMissionType());
			task6.setState(result.getResult());

			JSONObject object = new JSONObject();
			object.put("typeInfo", mission.getMissionType());
			object.put("taskInfo", task6);
			logger.debug("JSONObject "+object.toString());
			this.sendMessage("char:task");
			this.receiveMessage();
			this.sendMessage(object.toString());
			String string =  this.receiveMessage();
			logger.debug("升级部署之文件推送结果 "+string);
			this.sendMessage(SUCCESS);
			return string;
		} catch (Exception e) {
			logger.error(ExceptionPrintUtils.printExceptionStack(e));
			return null;
		}
	}
}
