알 이 아 픈 코드
package eman.event.productionView;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import eman.bean.monitor.EquipBean;
import eman.bean.monitor.OperationActualHoursBean;
import eman.bean.monitor.ScanHumanInfo;
import eman.bean.productionView.MonitorTimeBean;
import eman.bean.productionView.MouldPartOperationBean;
import eman.bean.productionView.QueryMouldInfo.MouldBean;
import eman.bean.productionView.QueryMouldInfo.MouldPartInfoBean;
import eman.bean.productionView.QueryMouldInfo.QueryMouldStateInfoForm;
import eman.bean.system.Result;
import eman.event.EventHandlerBase;
import eman.sql.productionView.QueryMouldInfoSql;
import eman.sys.SysConfig;
import eman.tool.ChineseSwitcher;
/**
* , , History: 1.0 1.5 2.0 sam 2005-10-4
* 2.0.1 husha 2005-1-7 2.0.1 husha 2006-1-11
* 2.0.3 sam 2006-2-20 yp 3.0.1.23 2006-03-26
* * yaominxi 2006-04-06 bug 3.1.1
* 2006.5.7 fq 06-11-04 cz 2006-12-22 event searchTtype
* yxb 2007-05-18 hmq 3.5 2007.7.3 myh 2007-12-21 EM-8362
*
*/
public class MouldStateDetailQueryEvent extends EventHandlerBase {
private static Logger log4j = Logger.getRootLogger();
/**
* : 1. 1.1. 1.2. 1.3. :
* , 、 : , 、 1.4. :
* : 1.5. 2. ( )
* 2.1 , 、 2.2 ,
* 2.3 ( )
*
* : MouldBean MouldPartInfoBean ( ) MouldPartOperationBean todo joly
* 2.0 050621 : 1. : 2. : 3. :
* 4. : History: yp 3.0.1.23 2006-03-26 cz 2006-12-21
* sam 3.5.1_lbl 2008-03-12 bug
*/
@SuppressWarnings("unchecked")
public void process(ServletContext sc, HttpServletRequest request,
HttpServletResponse response, HashMap bean) {
QueryMouldStateInfoForm form = new QueryMouldStateInfoForm();
try {
/**
* @author husha Get the over or doing flag to sort the table by
* mould layer
*/
String doingflag = (String) request.getParameter("doingflag");
if (doingflag == null) {
doingflag = "false";
} else {
doingflag = "true";
}
String overflag = (String) request.getParameter("overflag");
if (overflag == null) {
overflag = "false";
} else {
overflag = "true";
}
int mouldWorkingState = 0;
if (request.getParameter("mouldWorkingState") != null
&& !(request.getParameter("mouldWorkingState").equals(""))) {
mouldWorkingState = Integer.parseInt(request
.getParameter("mouldWorkingState"));
}
Result result = null;
if (request.getAttribute("result") != null) {
result = (Result) request.getAttribute("result");
} else {
result = new Result();
}
String pattern = "##0.##";
DecimalFormat df = new DecimalFormat(pattern);
String mouldID;
mouldID = request.getParameter("mouldTextID"); // ID
// ,
// String partMonitorID=request.getParameter("partMonitorID");
QueryMouldInfoSql queryMouldInfoSql = new QueryMouldInfoSql();
if (request.getParameter("mouldPartID") != null) {
mouldID = queryMouldInfoSql.queryMouldIDFromPartID(request
.getParameter("mouldPartID").trim(), result);
}
String operationID = "";
if (request.getParameter("operationID") != null) {
operationID = request.getParameter("operationID");
request.setAttribute("operationID", operationID);
}
// , , checkboxSelect ,
String[] checkboxSelect = request.getParameterValues("isHideDone");
//
request.setAttribute("isHideDone", checkboxSelect);
HashMap mouldStateInfo = null;
if (mouldID.equals("all")) {
mouldID = "";
}
long startTime = System.currentTimeMillis();
String percent1 = "0"; //
String percent2 = ""; //
if (request.getParameter("mouldPartID") != null) {
percent1 = "";
} else {
percent1 = request.getParameter("percent1");
}
if (request.getParameter("mouldPartID") != null) {
percent2 = "";
} else {
percent2 = request.getParameter("percent2");
}
if (percent1 == null) {
percent1 = "";
}
if (percent2 == null) {
percent2 = "";
}
//
String actualStartDate; //
String actualStopDate; //
String planStartDate; //
String planStopDate; //
//
String[] checkActualTimeSelect = request
.getParameterValues("actualTimeSelect");
String[] checkPlanTimeboxSelect = request
.getParameterValues("planTimeSelect");
if (checkActualTimeSelect != null) { //
actualStartDate = request.getParameter("begDate");
actualStopDate = request.getParameter("endDate");
request.setAttribute("actualStartDate", actualStartDate);
request.setAttribute("actualStopDate", actualStopDate);
}
if (checkPlanTimeboxSelect != null) { //
planStartDate = request.getParameter("begTime");
planStopDate = request.getParameter("endTime");
request.setAttribute("planStartDate", planStartDate);
request.setAttribute("planStopDate", planStopDate);
}
//
/*
* if((startDate!=null)&&(!startDate.equals(""))&&(stopDate!=null)&&(!stopDate.equals(""))){
* //1. if (checkboxSelect == null) { //
* mouldStateInfo =
* queryMouldInfoSql.queryMouldStateInfo(dateTimeFrom,dateTimeTo,mouldID,
* 0, 0, result); } else { mouldStateInfo =
* queryMouldInfoSql.queryMouldStateInfo(dateTimeFrom,dateTimeTo,mouldID,
* 5, 0, result); } }else
* if((startDate==null)||(startDate.equals(""))||(stopDate==null)||(stopDate.equals(""))){
*/
// 1.
String mouldName = "";
if (request.getParameter("mouldName") != null) {
mouldName = ChineseSwitcher.toShow(
request.getParameter("mouldName")).trim();
}
String queryStartTime = "";
if (request.getParameter("queryStartDate") != null) {
queryStartTime = request.getParameter("queryStartDate");
}
String queryEndTime = "";
if (request.getParameter("queryEndDate") != null) {
queryEndTime = request.getParameter("queryEndDate");
}
String mouldClassID = "";
if (request.getParameter("mouldClassID") != null) {
mouldClassID = request.getParameter("mouldClassID");
}
String searchType = "leadTimeAll";
if (request.getParameter("searchType") != null) {
searchType = request.getParameter("searchType");
}
String mouldInteriorIDName = ChineseSwitcher.toShow(request
.getParameter("mouldInteriorIDName"));
// , form。 , , , fq
// 06-11-04
form.setMouldID(mouldID);
form.setMouldName(mouldName);
form.setPage(0);
form.setMouldWorkingState(mouldWorkingState);
form.setQueryStartTime(queryStartTime);
form.setQueryEndTime(queryEndTime);
form.setMouldClassID(mouldClassID);
form.setMouldInteriorID(mouldInteriorIDName);
form.setSearchType(searchType);
if (checkboxSelect == null) { //
form.setState(0);
} else {
form.setState(5);
}
mouldStateInfo = queryMouldInfoSql.queryMouldStateInfoByForm(form,
result);
System.out.println("database access *"
+ ((double) System.currentTimeMillis() - startTime) / 1000
+ "* ");
long startTime2 = System.currentTimeMillis();
// 2. ( )
// * 2.1 , 、
// * 2.2 ,
// * 2.3 ( )
ArrayList moulds = (ArrayList) mouldStateInfo.get("moulds");
HashMap mouldsMap = (HashMap) mouldStateInfo.get("mouldsMap");
ArrayList parts = (ArrayList) mouldStateInfo.get("parts");
HashMap partsMap = (HashMap) mouldStateInfo.get("partsMap");
ArrayList operations = (ArrayList) mouldStateInfo.get("operations");
HashMap operationsMap = (HashMap) mouldStateInfo
.get("operationsMap");
ArrayList monitors = (ArrayList) mouldStateInfo.get("monitors");
HashMap operators = (HashMap) mouldStateInfo.get("operators");
HashMap resources = (HashMap) mouldStateInfo.get("resources");
HashMap distributeHoursMap = (HashMap) mouldStateInfo
.get("distributeHoursMap");
if(distributeHoursMap == null)
distributeHoursMap = new HashMap();
// xhy 2009-03-13 OperationActualHours
List operationHoursList = (List) mouldStateInfo
.get("operationHoursList");
// * 2.1 , 、
ArrayList opMonitorList = new ArrayList();
for (int i = 0; i < monitors.size(); i++) {
MonitorTimeBean temp1 = (MonitorTimeBean) monitors.get(i);
opMonitorList.add(temp1);
MonitorTimeBean tempNext = null;
if (!(i + 1 == monitors.size())) { // i
tempNext = (MonitorTimeBean) monitors.get(i + 1);
if (tempNext.getOperationID() == temp1.getOperationID()) {
continue; //
}
}
//
long hourTime = 0; //
java.sql.Timestamp start = null;
java.sql.Timestamp stop = null;
String resourceIDs = "";
String resourceNames = "";
String operatorIDs = "";
String operatorNames = "";
ArrayList allActualResource = new ArrayList();
ArrayList allActualOperator = new ArrayList();
HashMap allActualOperatorMap = new HashMap();
int opID = 0;
// //////////////
for (int j = 0; j < opMonitorList.size(); j++) {
MonitorTimeBean monitor = (MonitorTimeBean) opMonitorList
.get(j);
// ,
java.sql.Timestamp timePoint = monitor.getMonitorTime();
MonitorTimeBean monitorNext = null;
long temHour = 0;
if (j == 0) {
start = timePoint;
} else if (j + 1 == opMonitorList.size()) {
stop = timePoint; // last point,but may be a start
// time
}
// 20050802 ,
String operatorIDNum = monitor.getOperatorID();
int operatorIDNumInt = operatorIDNum.length() / 6;
if (j + 1 != opMonitorList.size() && j % 2 == 0) { // if
// now
// is
// start
// ,and
// has
// next
// point
monitorNext = (MonitorTimeBean) opMonitorList
.get(j + 1);
java.sql.Timestamp timePointNext = monitorNext
.getMonitorTime();
temHour = timePointNext.getTime() - timePoint.getTime();
hourTime = hourTime + (temHour * operatorIDNumInt); // hour
// add
}
// ID
opID = monitor.getOperationID();
//
String resourceID = monitor.getResourceID();
if (resourceIDs.indexOf(resourceID) < 0) { //
resourceIDs += resourceID;
allActualResource.add(resourceID);
allActualResource.add(((EquipBean) resources
.get(resourceID)).getEquipName());
if (resourceIDs.length() == resourceID.length()) { // first
resourceNames += ((EquipBean) resources
.get(resourceID)).getEquipName();
} else {
resourceNames += "; "
+ ((EquipBean) resources.get(resourceID))
.getEquipName();
}
}
//
String operatorID = monitor.getOperatorID();
ScanHumanInfo scanHumanInfo = new ScanHumanInfo();
scanHumanInfo.setHumanMonitorID(((ScanHumanInfo) operators.get(operatorID)).getHumanMonitorID());
scanHumanInfo.setHumanName(((ScanHumanInfo) operators.get(operatorID)).getHumanName());
scanHumanInfo.setHumanID(operatorID);
scanHumanInfo.setActualDistributeHour(temHour);
allActualOperatorMap.put(operatorID, scanHumanInfo);
if(operatorNames == null || operatorNames.indexOf(operatorID) ==-1){
allActualOperator.add(scanHumanInfo);
operatorNames += "; " + scanHumanInfo.getHumanName() + "(" + operatorID + ")";
}
}
// operation ...plan and actual Info
MouldPartOperationBean operation = (MouldPartOperationBean) operationsMap
.get(new Integer(opID));
operation.setActuralStartTime(start);
if (operation.getState().equals("over")) {
operation.setActuralFinishTime(stop);
} else if (operation.getState().equals("pause")) {
operation.setLastPauseTime(stop);
}
// husha@060111
else if (operation.getState().equals("working")) {
if (stop != null) {
operation.setLastStartTime(stop);
} else {
operation.setLastStartTime(start);
}
}
operation.setActuralWorkHour(((hourTime / (1000.0f * 3600))));
operation.setActuralResource(resourceNames);
operation.setOperatorName(operatorNames);
operation.setActuralResources(allActualResource);
operation.setOperators(allActualOperator);
StringBuffer actualDistributeHourInfo = new StringBuffer();
StringBuffer hourErrorInfo = new StringBuffer();
StringBuffer planDistributeHourInfo = new StringBuffer();
String hoursInfo = "";
if (operation.getState().equals("over")) {
float totalActualDistributeHour = 0;
float totalPlanDistributeHour = 0;
for (int k = 0; k < allActualOperator.size(); k++) {
ScanHumanInfo scanHumanInfo = (ScanHumanInfo) allActualOperator
.get(k);
float actualDistributeHour = scanHumanInfo
.getActualDistributeHour()
/ (1000.0f * 3600);
float planDistributeHour = 0;
float hourError = 0;
if (allActualOperator.size() == 1) {
actualDistributeHour = operation
.getActuralWorkHour();
planDistributeHour = Float.parseFloat(operation
.getPlanWorkingHour());
} else {
if (k == allActualOperator.size() - 1) {
actualDistributeHour = operation
.getActuralWorkHour()
- totalActualDistributeHour;
planDistributeHour = Float.parseFloat(operation
.getPlanWorkingHour())
- totalPlanDistributeHour;
} else {
String humanOperationID = operation
.getOperationID()
+ scanHumanInfo.getHumanID();
if (distributeHoursMap.get(humanOperationID) != null) {
planDistributeHour = Float
.parseFloat((String) distributeHoursMap
.get(humanOperationID));
} else {
try {
if (operation.getActuralWorkHour() == 0) {
planDistributeHour = 0;
} else {
planDistributeHour = actualDistributeHour
* Float
.parseFloat(operation
.getPlanWorkingHour())
/ operation
.getActuralWorkHour();
}
} catch (Exception e) {
planDistributeHour = 0;
}
}
}
}
actualDistributeHour = ((actualDistributeHour));
planDistributeHour = ((planDistributeHour));
if ((planDistributeHour + actualDistributeHour) == 0) {
hourError = 0;
} else {
hourError = (planDistributeHour - actualDistributeHour)
/ (planDistributeHour + actualDistributeHour);
}
totalActualDistributeHour += actualDistributeHour;
totalPlanDistributeHour += planDistributeHour;
actualDistributeHourInfo.append(
scanHumanInfo.getHumanName()).append(":")
.append(df.format(actualDistributeHour))
.append("");
planDistributeHourInfo.append(
scanHumanInfo.getHumanName()).append(":")
.append(df.format(planDistributeHour)).append(
"");
// hourErrorInfo.append(scanHumanInfo.getHumanName()).
// append(":").append(df.format(hourError)).append("");
// xhy 2009-03-16
float hours = 0;
if (operationHoursList != null) {
for (int j = 0; j < operationHoursList.size(); j++) {
OperationActualHoursBean operationBean = (OperationActualHoursBean) operationHoursList
.get(j);
if (opID == operationBean.getOpID()) {
if (operationBean.getOperatorID().indexOf(
scanHumanInfo.getHumanMonitorID()) != -1) {
ArrayList reList = operation
.getActuralResources();
if (reList != null) {
for (int s = 0; s < reList.size(); s++) {
String reStr = (String) reList
.get(s);
if (operationBean
.getResourceID()
.equals(reStr)) {
float h = operationBean
.getHours();
//
int len = 0;
for (int n = 0; n < operationBean
.getOperatorID()
.length(); n++) {
char c = operationBean
.getOperatorID()
.charAt(n);
if (c == '+') {
len++;
}
}
if (len > 1) {
//
h = operationBean
.getHours()
/ len;
}
hours += h;
break;
}
}
}
}
}
}
}
hoursInfo += scanHumanInfo.getHumanName() + ":"
+ df.format(hours) + "";
// xhy 2009-04-22 : =( - )/( + )
if ((planDistributeHour + hours) == 0
|| ("0".equals(df.format(hours)) && "0"
.equals(df.format(planDistributeHour)))) {
hourError = 0;
} else {
hourError = (planDistributeHour - hours)
/ (planDistributeHour + hours);
}
hourErrorInfo.append(scanHumanInfo.getHumanName())
.append(":").append(df.format(hourError))
.append("");
}
}
operation.setActuralWorkHour(Float.parseFloat(df
.format(operation.getActuralWorkHour())));
operation.setActualDistributeHourInfo(actualDistributeHourInfo
.toString());
operation.setHourErrorInfo(hourErrorInfo.toString());
operation.setPlanDistributeHourInfo(planDistributeHourInfo
.toString());
operation.setHoursInfo(hoursInfo);
opMonitorList.clear();
}
ArrayList undoOperation = new ArrayList();
ArrayList doingOperation = new ArrayList();
ArrayList doneOperation = new ArrayList();
ArrayList pauseOperation = new ArrayList();
java.sql.Timestamp lastFinishTime // for cal lastFinishTime of
// part
= new java.sql.Timestamp(0);
// * 2.2 ,
// * 2.3 ( )
// save ops to their parts---
for (int i = 0; i < operations.size(); i++) {
MouldPartOperationBean operation = (MouldPartOperationBean) operations
.get(i);
MouldPartOperationBean operationNext = null;
if (i + 1 != operations.size()) {
operationNext = (MouldPartOperationBean) operations
.get(i + 1);
}
//
if (operation.getReasonOperationID() != 0) {
if (operationsMap.get(new Integer(operation
.getReasonOperationID())) != null) {
operation
.setReasonOperationName(((MouldPartOperationBean) operationsMap
.get(new Integer(operation
.getReasonOperationID())))
.getOperationName());
}
}
if (operation != null
&& resources != null
&& operation.getPlanResourceID() != null
&& !operation.getPlanResourceID().equals("")
&& (EquipBean) resources.get(operation
.getPlanResourceID()) != null) {
operation.setEquip(((EquipBean) resources.get(operation
.getPlanResourceID())).getEquipName());
} else {
operation.setEquip("");
}
if (operation.getPlanFinishTime() != null
&& operation.getPlanFinishTime().getTime() > lastFinishTime
.getTime()) {
lastFinishTime.setTime(operation.getPlanFinishTime()
.getTime()); // part's last
}
String newPartID = operation.getMouldPartID();
if (operation.getState().equals("waiting")) {
undoOperation.add(operation);
} else if (operation.getState().equals("working")) {
doingOperation.add(operation);
} else if (operation.getState().equals("over")) {
doneOperation.add(operation);
} else if (operation.getState().equals("pause")) {
pauseOperation.add(operation);
}
if (operationNext == null
|| !newPartID.equals(operationNext.getMouldPartID())) { // last
// or
// next
// part
// is
// diff
// part
// save a part ,then next part or out
eman.bean.productionView.QueryMouldInfo.MouldPartInfoBean partTemp = ((eman.bean.productionView.QueryMouldInfo.MouldPartInfoBean) partsMap
.get(newPartID));
partTemp.setUndoOperationList(undoOperation);
partTemp.setDoingOperationList(doingOperation);
partTemp.setDoneOperationList(doneOperation);
partTemp.setPauseOperationList(pauseOperation);
partTemp.setLastPlanFinishTime(new Timestamp(lastFinishTime
.getTime()));
// back to init state
if (operationNext != null) {
lastFinishTime = new java.sql.Timestamp(0);
undoOperation = new ArrayList();
doingOperation = new ArrayList();
doneOperation = new ArrayList();
pauseOperation = new ArrayList();
}
}
}
// myh 2007-12-21
java.sql.Timestamp lastFinishTimeMould = new java.sql.Timestamp(0);
for (int i = 0; i < parts.size(); i++) {
MouldPartInfoBean part = (MouldPartInfoBean) parts.get(i);
if (part.getLastPlanFinishTime() != null
&& part.getLastPlanFinishTime().getTime() > lastFinishTimeMould
.getTime()) {
lastFinishTimeMould.setTime(part.getLastPlanFinishTime()
.getTime());
}
String newMouldID = part.getMouldID();
if (((MouldBean) mouldsMap.get(newMouldID)).getMouldpartList() == null) {
((MouldBean) mouldsMap.get(newMouldID))
.setMouldpartList(new ArrayList());
}
if (lastFinishTimeMould.getTime() != 0) {
((MouldBean) mouldsMap.get(newMouldID))
.setMouldPanFinishTime(new Timestamp(
lastFinishTimeMould.getTime()));
}
((MouldBean) mouldsMap.get(newMouldID)).getMouldpartList().add(
part);
}
String interiorID = ((SysConfig) sc.getAttribute("sysConfig"))
.getInteriorID();
if (interiorID == null || interiorID.equals("")) {
interiorID = " ";
}
String clientID = ((SysConfig) sc.getAttribute("sysConfig"))
.getClientID();
if (clientID == null || clientID.equals("")) {
clientID = " ";
}
request.setAttribute("pageControl", mouldStateInfo
.get("pageControl"));
request.setAttribute("isByOperationOrderID", "false");
request.setAttribute("doingflag", doingflag);
request.setAttribute("overflag", overflag);
request.setAttribute("result", result);
Collections.sort(moulds, new java.util.Comparator() {
public int compare(Object obj1, Object obj2) {
return ((MouldBean) obj1).getMouldInteriorID().compareTo(
((MouldBean) obj2).getMouldInteriorID());
}
});
request.setAttribute("mouldList", moulds);
request.setAttribute("percent1", percent1);
request.setAttribute("percent2", percent2);
request.setAttribute("interiorID", interiorID);
request.setAttribute("clientID", clientID);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
토요일 내 내 이 코드 에서 죽 었 다.이 코드 를 쓴 사람, 나 는 네가 평생 아 내 를 찾 지 못 할 것 이 라 고 저주 한다. 나 는 미 치 겠 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JPA + QueryDSL 계층형 댓글, 대댓글 구현(2)이번엔 전편에 이어서 계층형 댓글, 대댓글을 다시 리팩토링해볼 예정이다. 이전 게시글에서는 계층형 댓글, 대댓글을 구현은 되었지만 N+1 문제가 있었다. 이번에는 그 N+1 문제를 해결해 볼 것이다. 위의 로직은 이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.