package com.comtop.dms.outage.scheduled.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.comtop.util.commonservice.QueryCondition;
import com.comtop.util.page.PageConstants;
import com.comtop.util.page.pagination.Pagination;
import com.comtop.util.page.pagination.PaginationAttribute;
import com.comtop.dms.common.action.BaseAction;
import com.comtop.dms.common.util.DmsUtils;
import com.comtop.dms.common.util.TimeUtil;
import com.comtop.dms.outage.common.OutageConfigUtil;
import com.comtop.dms.outage.common.ScheduledOutageConstants;
import com.comtop.dms.outage.scheduled.delegate.ScheduledOutageMan;
import com.comtop.dms.outage.scheduled.model.ScheduledOutageVO;
public class DispatchConfirmingGanttListAction extends BaseAction {
public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {
SAXReader saxReader = new SAXReader();
DocumentFactory df = saxReader.getDocumentFactory();
Document dataDoc=df.createDocument() ;
Element project = dataDoc.addElement("Project");
Element Tasks = project.addElement("Tasks");
project.addElement("Resources");
project.addElement("Assignments");
//查询数据
List list = executeGetList(mapping, actionForm, request, response);
//初始化数据
Tasks.add(this.initData(df,(ScheduledOutageVO)list.get(0)));
//数据转化
Tasks = this.addTaskElement(list, Tasks, df);
request.removeAttribute("dataDoc");
request.setAttribute("dataDoc", dataDoc.asXML());
return mapping.findForward("dispatchConfirming");
}
/**
* 查询数据
* @param mapping
* @param actionForm
* @param request
* @param response
* @return
* @throws Exception
*/
public List executeGetList(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ScheduledOutageForm scheduledOutageForm = (ScheduledOutageForm) actionForm;
// 从session中获取查询条件
List alCondition = new ArrayList();
List alQueryCondition = new ArrayList();
for (int i = 0; i < alCondition.size(); i++) {
alQueryCondition.add((QueryCondition) alCondition.get(i));
}
// 只能查询状态为待执行、执行中、已延期、和已执行的停电计划
alQueryCondition.add(new QueryCondition("AND", "", "state", "<",
ScheduledOutageConstants.SCHEDULED_STATE_OVERED, ""));
alQueryCondition.add(new QueryCondition("AND", "", "state", ">=",
ScheduledOutageConstants.SCHEDULED_STATE_WILLEXECUTE, ""));
// 设置查询工作流审批完成的条件
alQueryCondition.add(new QueryCondition("AND", "", "flowState", "=", ScheduledOutageConstants.STATE_COMPLETE,
""));
ScheduledOutageMan scheduledOutageMan = new ScheduledOutageMan();
//查询类型
String strQueryType = OutageConfigUtil.getQueryType();
int iCount = 0;
Pagination objPGN;
List lstDispatchConfirm;
String strOverhaulContent = scheduledOutageForm.getOverhaulContent().trim();
if ("dis4sz".equals(strQueryType)) {
if("".equals(strOverhaulContent)){
iCount = scheduledOutageMan.queryViewScheduledOutageCount(alQueryCondition);
objPGN = PaginationAttribute.getPaginationByPost(request, iCount, PageConstants.DEFAULT_PAGE_SIZE);
lstDispatchConfirm = scheduledOutageMan.queryViewScheduledOutageList(alQueryCondition, objPGN.getCurPage(),
objPGN.getPageSize());
}else{
iCount = scheduledOutageMan.queryViewScheduledOutageCount(alQueryCondition, strOverhaulContent);
objPGN = PaginationAttribute.getPaginationByPost(request, iCount, PageConstants.DEFAULT_PAGE_SIZE);
lstDispatchConfirm = scheduledOutageMan.queryViewScheduledOutageList(alQueryCondition, strOverhaulContent, objPGN.getCurPage(),
objPGN.getPageSize());
}
} else {
String strDeptCode = this.getCurrUserDept(request).getCode();
if(strDeptCode.length()>=6){
String strBigDeptCode = this.getCurrUserBigDept(request).getCode();
//设置过虑条件只查询当前用户所属部门的停电单
alQueryCondition.add(new QueryCondition("AND", "", "departmentCode", "LIKE", strBigDeptCode, ""));
}else if(strDeptCode.length()>=4 && strDeptCode.length()<6){
//设置过虑条件只查询当前用户所属部门的停电单
alQueryCondition.add(new QueryCondition("AND", "", "departmentCode", "LIKE", strDeptCode, ""));
}
if("".equals(strOverhaulContent)){
iCount = scheduledOutageMan.queryScheduledOutageCount(alQueryCondition);
objPGN = PaginationAttribute.getPaginationByPost(request, iCount, PageConstants.DEFAULT_PAGE_SIZE);
lstDispatchConfirm = scheduledOutageMan.queryScheduledOutageList(alQueryCondition, objPGN.getCurPage(),
objPGN.getPageSize());
}else{
iCount = scheduledOutageMan.queryScheduledOutageCount(alQueryCondition, strOverhaulContent);
objPGN = PaginationAttribute.getPaginationByPost(request, iCount, PageConstants.DEFAULT_PAGE_SIZE);
lstDispatchConfirm = scheduledOutageMan.queryScheduledOutageList(alQueryCondition, strOverhaulContent, objPGN.getCurPage(),
objPGN.getPageSize());
}
}
//查询关联工作票数量
ScheduledOutageVO scheduledOutageVO = null;
for (int i = 0, j = lstDispatchConfirm.size(); i < j; i++) {
scheduledOutageVO = (ScheduledOutageVO)lstDispatchConfirm.get(i);
int iWorkwritNum = scheduledOutageMan.getDisObjectRelationCount(String.valueOf(scheduledOutageVO
.getScheduledId()));
scheduledOutageVO.setWorkwritNum(iWorkwritNum);
}
return lstDispatchConfirm;
}
/**
* 初始化第一条数据
* @param documentFactory
* @param scheduledOutageVO
* @return
*/
public Element initData(DocumentFactory documentFactory, ScheduledOutageVO scheduledOutageVO){
Element Task = documentFactory.createElement("Task");
Element UID = documentFactory.createElement("UID");
Element ID = documentFactory.createElement("ID");
Element OutlineNumber = documentFactory.createElement("OutlineNumber");
Element Start = documentFactory.createElement("Start");
Element Finish = documentFactory.createElement("Finish");
Element Summary = documentFactory.createElement("Summary");
Element PercentComplete = documentFactory.createElement("PercentComplete");
Element applyDepartment = documentFactory.createElement("applyDepartment");
Element Name = documentFactory.createElement("Name");
Element scheduledCode = documentFactory.createElement("scheduledCode");
Element voltageGrade = documentFactory.createElement("voltageGrade");
Element outageRange = documentFactory.createElement("outageRange");
Element turnPowerSupply = documentFactory.createElement("turnPowerSupply");
Element gridType = documentFactory.createElement("gridType");
Element state = documentFactory.createElement("state")
- 1
- 2
- 3
前往页