package com.wm.affnet.util;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import com.wm.affnet.dao.impl.AffDeptCatMapDao;
import com.wm.affnet.dataobj.AffDeptCatMap;
@SuppressWarnings("unchecked")
public class DeptCatMap {
public static Vector deptNames;
public static HashMap> deptCatMap;
public static HashMap deptNameIdMap;
public static HashMap catNameIdMap;
public static HashMap> deptCatNameMap;
public static Hashtable hashDeptCat;
static {
deptNames = new Vector();
deptCatMap = new HashMap>();
deptNameIdMap = new HashMap();
catNameIdMap = new HashMap();
deptCatNameMap = new HashMap>();
hashDeptCat = new Hashtable();
String deptName = "";
Long deptId = 0L;
try {
AffDeptCatMapDao affDeptCatMapDao = AffDeptCatMapDao.getInstance();
List
list = affDeptCatMapDao.findByStatus(Constants.DEPT_CAT_MAP_STATUS_ACTIVE);
Vector[] deptCats = new Vector[list.size()];
Vector[] deptCatNames = new Vector[list.size()];
int i = 0;
deptCats[0] = new Vector();
deptCatNames[0] = new Vector();
if (list != null && list.size() != 0) {
for (AffDeptCatMap affDeptCatMap : list) {
if (!deptName.equals("")) {
if (!deptName.equals(affDeptCatMap.getDeptName())) {
deptNames.add(deptName);
deptCatMap.put(deptName, deptCats[i]);
deptNameIdMap.put(deptName, deptId);
++i;
deptCats[i] = new Vector();
deptCatNames[i] = new Vector();
}
}
deptName = affDeptCatMap.getDeptName();
deptId = affDeptCatMap.getDeptId();
String catName = affDeptCatMap.getCatName();
Long catId = affDeptCatMap.getCatId();
deptCats[i].add(catId);
deptCatNames[i].add(catName);
catNameIdMap.put(catId, catName);
hashDeptCat.put(String.valueOf(deptId), deptName);
hashDeptCat.put(String.valueOf(catId), catName);
}
deptNames.add(deptName);
deptCatMap.put(deptName, deptCats[i]);
deptNameIdMap.put(deptName, deptId);
deptCatNameMap.put(deptName, deptCatNames[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getScript(HashMap> deptCatMap, String strFormName,
String strDeptName, String strCatName) {
String javaScriptOut = "";
Iterator iterator = deptCatMap.keySet().iterator();
int outerCount = 0;
while (iterator.hasNext()) {
String mapKey = iterator.next();
Vector mapValue = deptCatMap.get(mapKey);
int mapValueSize = mapValue.size();
outerCount++;
if (outerCount == 1) {
javaScriptOut = "if(document." + strFormName + "." + strDeptName + ".value == '"
+ deptNameIdMap.get(mapKey) + "') {\n";
} else {
javaScriptOut = javaScriptOut + "else if(document." + strFormName + "." + strDeptName + ".value == '"
+ deptNameIdMap.get(mapKey) + "') {\n";
}
for (int j = 0; j < mapValueSize; j++) {
javaScriptOut = javaScriptOut + "addOption(document." + strFormName + "." + strCatName + ", \""
+ catNameIdMap.get(mapValue.elementAt(j)) + "\", \"" + mapValue.elementAt(j) + "\");\n";
}
javaScriptOut = javaScriptOut + "}\n";
}
System.out.println(javaScriptOut+"in DeptCatMap");
return javaScriptOut;
}
public static Hashtable getDeptCat() {
return hashDeptCat;
}
}
阅读(326) | 评论(0) | 转发(0) |