⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 custsortmgr.java

📁 java阿里巴巴代码
💻 JAVA
字号:
package com.saas.biz.sortMgr;

import java.util.*;

import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;
import com.saas.biz.dao.productclassDAO.*;
import java.lang.StringBuilder;

public class custSortMgr{
	/*
	 * 获取企业的分类信息 +1 次重载 @author: 潘晓峰 @Date: 2007-9-2 @FileName: custSortMgr.java
	 * @PackageName: com.saas.biz.sort @Method Name: getSortItems
	 * 
	 * 形 参: parent 父分类 ID 编号,获取顶级分类可以传递 null 零长度字符串或 000000000000000
	 * 
	 * 返回值: 若成功返回子分类信息,子分类信息被装载在 ArrayList 实例中
	 */
	public ArrayList getSortItems() {
		return this.getSortItems("000000000000000");
	}

	public ArrayList getSortItems(String parent) {
		if (parent == null || parent.length() == 0)
			parent = "000000000000000";

		ProductclassExt pe = new ProductclassExt();
		pe.setParam(":VCLASS_TYPE", "0");
		pe.setParam(":VUP_CLASS_ID", parent);

		ArrayList result = pe.selByList("SEL_CHILD_CLASS");

		return result;
	}

	// 刘阳2007.12.26
	public Map getClassByParentId(String parent) {
		Map<String, String> classMap = new LinkedHashMap<String, String>();
		ProductclassExt pe = new ProductclassExt();
		pe.setParam(":VCLASS_TYPE", "3");// 企业分类
		pe.setParam(":VUP_CLASS_ID", parent);
		ArrayList result = pe.selByList("SEL_BY_PARENTID");
		if (result != null && result.size() > 0) {
			for (int i = 0; i < result.size(); i++) {
				HashMap map = (HashMap) result.get(i);
				String keys = map.get("class_id").toString();
				String value = map.get("class_name").toString();
				classMap.put(keys, value);
			}
		}
		return classMap;
	}

	/*
	 * 获取指定企业分类是否有子分类 @author: 潘晓峰 @Date: 2007-9-2 @FileName: custSortMgr.java
	 * @PackageName: com.saas.biz.sort @Method Name: hasSubItems
	 * 
	 * 形 参: parent 父分类 ID 编号,获取顶级分类可以传递 null 零长度字符串或 000000000000000
	 * 
	 * 返回值: 若成功返回子分类信息,子分类信息被装载在 ArrayList 实例中
	 */
	public boolean hasSubItems(String parent) {
		if (parent == null || parent.length() == 0)
			parent = "000000000000000";

		ProductclassExt pe = new ProductclassExt();
		pe.setParam(":VCLASS_TYPE", "0");
		pe.setParam(":VUP_CLASS_ID", parent);

		ArrayList result = pe.selByList("SEL_HASCHILD_CLASS");

		if (result == null || result.get(0) == null || "0".equals(((HashMap) result.get(0)).get("class_total").toString()))
			return false;
		else
			return true;
	}

	/**
	 * 取出分类信息
	 * 
	 * @class_Type
	 * @up_Class_Id
	 * @class_Name
	 */
	public List getClassInfoByLimit(String up_class_id, String class_type, int limit) throws SaasApplicationException {
		List<HashMap> resultList = new ArrayList<HashMap>();
		List list = new ArrayList();
		ProductclassExt prodExt = new ProductclassExt();
		prodExt.setParam(":VUP_CLASS_ID", up_class_id);
		prodExt.setParam(":VCLASS_TYPE", class_type);
		prodExt.setParam(":VNUM", limit);
		list = prodExt.selByList("SEL_BY_UP_TYPE",0,limit);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HashMap obj = (HashMap) list.get(i);
				HashMap<String, String> map = new HashMap<String, String>();
				String id = obj.get("class_id").toString();
				String name = obj.get("class_name").toString();
				map.put("id", id);
				map.put("name", name);
				resultList.add(map);
			}
		}
		return resultList;
	}

	// 取出分类
	public ArrayList getClassInfoByUpType(String up_id, String type) throws SaasApplicationException {
		ArrayList list = new ArrayList();
		ProductclassExt pe = new ProductclassExt();
		pe.setParam(":VCLASS_TYPE", type);
		pe.setParam(":VUP_CLASS_ID", up_id);
		list = pe.selByList("SEL_BY_PARENTID");
		return list;
	}

	/**
	 * @主方法 生成所有分类模板
	 */
    public List getHtmlTemplateInfo(String up_id, String type,String linkUrl)throws SaasApplicationException{
    	List list=new ArrayList();
    	List lists =new ArrayList();
    	list=getClassInfoByUpType(up_id,type);
    	if(list != null && list.size()>0){
    		lists=getHTMLCodeByHead(list,linkUrl,type);
    	}
    	return lists;
    }
	/**
	 * 生成一级、二级分类和三级分类的代码 LinkUrl=/enterprise/e_list.jsp?p_class=
	 * 
	 * @param R_list
	 * @param linkUrl
	 * @return
	 * @throws SaasApplicationException
	 */

	@SuppressWarnings("unchecked")
	public List getHTMLCodeByHead(List R_list, String linkUrl, String type) throws SaasApplicationException {
		List resultList = new ArrayList();
		if (R_list != null && R_list.size() > 0) {
			for (int i = 0; i < R_list.size(); i++) {
				HashMap map = (HashMap) R_list.get(i);
				String id = map.get("class_id").toString();
				String name = map.get("class_name").toString();
				resultList.add(createHtmlTemplate(id, name, linkUrl, type));
			}
		}
		return resultList;
	}

	// 生成分类HTML
	@SuppressWarnings( { "unused", "unchecked" })
	public List createHtmlTemplate(String id, String name, String linkUrl, String type) throws SaasApplicationException {
		String htmlString = "", classOneName = "";
		classOneName = "<a href=" + linkUrl + ">" + name + "</a>";
		List resultList = new ArrayList();
		// 取出二级数据
		ArrayList secendList = getClassInfoByUpType(id, type);
		if (secendList != null && secendList.size() > 0) {
			int counter = secendList.size();// 二级的记录总数
			List list_1 = new ArrayList();
			List list_2 = new ArrayList();
			List list_3 = new ArrayList();
			if (counter % 2 == 0) {
				// 偶数
				list_1.addAll(secendList.subList(0, counter / 2));
				list_2.addAll(secendList.subList(counter / 2, counter));
			}
			else {
				// 奇数
				int subIni = counter / 2;
				list_1.addAll(secendList.subList(0, subIni));
				list_2.addAll(secendList.subList(subIni, counter - 1));
				list_3.addAll(secendList.subList(counter - 1, counter));
			}
			// 开始生成二级和三级HTML
			htmlString = cteateHtmlClassInfo(list_1, linkUrl, type);
			htmlString = htmlString + cteateHtmlClassInfo(list_2, linkUrl, type);
			htmlString = htmlString + cteateHtmlClassInfo(list_3, linkUrl, type);
		}
		resultList.add(classOneName);
		resultList.add(htmlString);
		return resultList;
	}

	// 生成二级和三级HTML分类信息(二级list)
	public String cteateHtmlClassInfo(List list, String linkUrl, String type) throws SaasApplicationException {
		String Html = "", main_Html = "", temp_Html = "", three_Html = "";
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HashMap map = (HashMap) list.get(i);
				String id = map.get("class_id").toString();
				String name = map.get("class_name").toString();
				if (i > 0 && i % 3 == 0) {
					main_Html = main_Html + temp_Html + three_Html;
					temp_Html = "";
					three_Html = "";
				}
				temp_Html = temp_Html + "<a href=" + linkUrl + id + "><strong>" + name + "</strong></a>";
				three_Html = three_Html + createThreeClassInfo(id, linkUrl, type);
			}
		}
		return Html;
	}

	// 生成三级分类信息
	public String createThreeClassInfo(String id, String linkUrl, String type) throws SaasApplicationException {
		String Html = "";
		ArrayList threeList = getClassInfoByUpType(id, type);
		if (threeList != null && threeList.size() > 0) {
			for (int i = 0; i < threeList.size() && i < 10; i++) {
				HashMap map = (HashMap) threeList.get(i);
				String idx = map.get("class_id").toString();
				String name = map.get("class_name").toString();
				Html = Html + "<a href=" + linkUrl + idx + ">" + name + "</a>&nbsp;|&nbsp;";
			}
		}
		return Html;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -