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

📄 createenterprisehtml.java

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

import tools.util.FileIO;
import tools.util.StrReplace;
import com.saas.sys.log.Logger;
import java.util.Iterator;
import com.base.config.ProjectConfig;
import com.saas.sys.exp.SaasApplicationException;
import tools.util.StringUtil;

import com.saas.biz.AreaInfoMgr.AreaInfo;
import com.saas.biz.attachMgr.Attachinfo;
import com.saas.biz.custMgr.Custinfo;
import com.saas.biz.dao.productclassDAO.*;
import com.saas.biz.newsMgr.NewsInfo;
import com.saas.biz.productclassMgr.Productclass;
import java.util.*;

/**
 * Created by caiwch Date: 2008-7-8 Time: 22:55:03
 */
public class CreateEnterpriseHtml {
	
	
	FileAndString FileString = new FileAndString();
	
	
	Logger log = new Logger(this);
	
	
	
	public void createEnterpriseIndex(String rootpath) throws SaasApplicationException {

		String str = "";
		String strTemp = "";
		String filepath = rootpath + "/" + "enterprise/index.html";
		String templatePath = rootpath + "/" + "templates/enterprise.html";
		String templateStr = FileIO.LoadFile(templatePath);
		String[] tab = { "{#include:top#}", "{#include:bottom#}" };
		log.LOG_INFO(filepath);
		log.LOG_INFO(templatePath);
		
		str = StrReplace.replace(templateStr, tab[0], FileString.f2s(rootpath + "/top.html"));
		str = StrReplace.replace(str, tab[1], FileString.f2s(rootpath + "/footer.html"));
		
		
		// 企业频道 {#EnterpriseChannel:1#}{#EnterpriseChannel:5#}
		log.LOG_INFO("企业频道");
		String initStr = "<tr><td width=\"100\"><img src=\"{#src#}\" width=\"100\" height=\"100\" alt=\"\" /></td>" + "<td><a href=\"{#href#}\"><strong>{#title#}</strong></a><br>{#content#}</td></tr>";
		String initStr1 = "<li>·<a href=\"{#href#}\">{#title#}</a></li>";
		
		strTemp = "";
		String strTemp1 = "";
		ArrayList SuccessList = new Productclass().genClassNameByRsrv_str1("1", "成功故事");
		log.LOG_INFO("SuccessList =  " + SuccessList);
		if (SuccessList != null & SuccessList.size() > 0) {
			HashMap sucmap = (HashMap) SuccessList.get(0);
			String class_id = sucmap.get("class_id").toString();
			ArrayList sucList = new NewsInfo().genNewsByNewsType(class_id, 6);
			if (sucList != null && sucList.size() > 0) {
				for (int j = 0; j < sucList.size(); j++) {
					HashMap sumap = (HashMap) sucList.get(j);
					String news_id = "";
					String cust_id = "";
					String title = "", sub_title = "";
					String content = "";
					if (sumap.get("news_id") != null) {
						news_id = sumap.get("news_id").toString();
					}
					if (sumap.get("cust_id") != null) {
						cust_id = sumap.get("cust_id").toString();
					}
					if (sumap.get("title") != null) {
						title = sumap.get("title").toString();
					}
					else {
						title = "";
					}
					if (sumap.get("content") != null) {
						content = sumap.get("content").toString();
						if (content.length() > 15) {
							content = StringUtil.getLimitLengthString(content, "", 60) + "..";
						}
					}
					if (j == 0) {
						String filePath = new NewsInfo().getCustAttachPath(news_id, "0");
						if (filePath == "" || filePath.equals("")) {
							filePath = "/upload/default.gif";
						}
						strTemp = strTemp + initStr;
						strTemp = StrReplace.replace(strTemp, "{#src#}", filePath);
						strTemp = StrReplace.replace(strTemp, "{#href#}", "/zone_b2b/news/zixun_list_content.jsp?news_id=" + news_id);// /////////////////////////////////////
						strTemp = StrReplace.replace(strTemp, "{#title#}", title);
						strTemp = StrReplace.replace(strTemp, "{#content#}", content);
					}
					else if (j >= 1 && j < sucList.size()) {
						if (title.length() > 15) {
							title = StringUtil.getLimitLengthString(title, "", 30) + "..";
						}
						strTemp1 = strTemp1 + initStr1;
						strTemp1 = StrReplace.replace(strTemp1, "{#href#}", "/zone_b2b/news/zixun_list_content.jsp?news_id=" + news_id);// /////////////////////////////////////
						strTemp1 = StrReplace.replace(strTemp1, "{#title#}", title);
					}
				}
			}
		}
		str = StrReplace.replace(str, "{#EnterpriseChannel:1#}", strTemp);
		str = StrReplace.replace(str, "{#EnterpriseChannel:5#}", strTemp1);
		
		log.LOG_INFO("最新企业");
		// 最新企业 {#LatestEnterprise:picture:name:1#} {#LatestEnterprise:6#} {#LatestEnterprise:12#}
		initStr1 = "<li>·<a href=\"{#href#}\" title=\"{#detail:title_long#}\">{#cust_name#}</a><span class=\"zi\">[{#type#}]</span></li>";
		strTemp = "";
		ArrayList enterprise = new Custinfo().getCustomerList(12);
		
		if (enterprise != null && enterprise.size() > 0) {
			for (int i = 0; i < enterprise.size(); i++) {
				HashMap map = (HashMap) enterprise.get(i);
				String cust_id = "";
				String cust_name = "";
				String sub_custName = "";
				String cust_type = "";
				if (map.get("cust_id") != null) {
					cust_id = map.get("cust_id").toString();
				}
				if (map.get("cust_name") != null) {
					cust_name = map.get("cust_name").toString();
					if (cust_name.length() > 8) {
						sub_custName = StringUtil.getLimitLengthString(cust_name, "", 24);
					}
					else {
						sub_custName = cust_name;
					}
				}
				if (map.get("cust_type") != null) {
					cust_type = map.get("cust_type").toString();
				}
				
				strTemp = strTemp + initStr1;
				strTemp = StrReplace.replace(strTemp, "{#href#}", "/zone_b2b/enterprise/customer/" + cust_id); // /////////////////////////////////////////////////////////////////////////////////
				strTemp = StrReplace.replace(strTemp, "{#detail:title_long#}", cust_name);
				strTemp = StrReplace.replace(strTemp, "{#cust_name#}", sub_custName);
				strTemp = StrReplace.replace(strTemp, "{#type#}", cust_type);
				
			}
		}
		str = StrReplace.replace(str, "{#LatestEnterprise:12#}", strTemp);
		
		log.LOG_INFO("企业动态");
		initStr = "<tr><td><strong><a href=\"{#href1#}\">{#title1#}</a></strong><br>{#content1#}</td></tr><tr><td height=\"1\" class=\"xian\"></td></tr>";
		initStr1 = "<li><a href=\"{#href#}\">{#title#}</a><span class=\"zi\">({#date#})</span></li>";
		
		strTemp = "";
		strTemp1 = "";
		ArrayList dynamicList = new Productclass().genClassNameByRsrv_str1("1", "企业动态");
		if (dynamicList != null & dynamicList.size() > 0) {
			HashMap dymap = (HashMap) dynamicList.get(0);
			String class_id = dymap.get("class_id").toString();
			ArrayList dyList = new NewsInfo().genNewsByNewsType(class_id, 10);
			if (dyList != null && dyList.size() > 0) {
				for (int j = 0; j < dyList.size(); j++) {
					HashMap dmap = (HashMap) dyList.get(j);
					String news_id = "";
					String cust_id = "";
					String title = "", sub_title = "";
					String content = "";
					String publish_date = "";
					if (dmap.get("news_id") != null) {
						news_id = dmap.get("news_id").toString();
					}
					if (dmap.get("cust_id") != null) {
						cust_id = dmap.get("cust_id").toString();
					}
					if (dmap.get("title") != null) {
						title = dmap.get("title").toString();
					}
					else {
						title = "";
					}
					if (dmap.get("content") != null) {
						content = dmap.get("content").toString();
						content = StringUtil.getLimitLengthString(content, "", 14);
					}
					if (dmap.get("publish_date") != null) {
						publish_date = dmap.get("publish_date").toString();
						if (publish_date.length() > 10)
							publish_date = publish_date.substring(3, 10);
					}
					if (j == 0) {
						strTemp = strTemp + initStr;
						strTemp = StrReplace.replace(strTemp, "{#href1#}", "/zone_b2b/news/zixun_list_content.jsp?news_id=" + news_id);// /////////////////////////////////////
						strTemp = StrReplace.replace(strTemp, "{#title1#}", title);
						strTemp = StrReplace.replace(strTemp, "{#content1#}", content);
					}
					else if (j >= 1 && j < dyList.size()) {
						if (title.length() > 10) {
							title = StringUtil.getLimitLengthString(title, "", 14);
						}
						strTemp1 = strTemp1 + initStr1;
						strTemp1 = StrReplace.replace(strTemp1, "{#href#}", "/zone_b2b/news/zixun_list_content.jsp?news_id=" + news_id);// /////////////////////////////////////
						strTemp1 = StrReplace.replace(strTemp1, "{#title#}", title);
						strTemp1 = StrReplace.replace(strTemp1, "{#date#}", publish_date);
					}
				}
			}
		}
		str = StrReplace.replace(str, "{#Dynamic:up#}", strTemp);
		str = StrReplace.replace(str, "{#Dynamic:down#}", strTemp1);
		
		
		// 行业市场 {#IndustryMarket#}
		log.LOG_INFO("行业市场");
		try {
			str = StrReplace.replace(str, "{#IndustryMarket#}", getHtmlTemplateStr("000000000000000", "3", "/zone_b2b/calalogList.jsp?&enterprise=1&type="));
		}
		catch (SaasApplicationException e) {
			e.printStackTrace();
		}
		// 省份信息
		String province = getProvinceInfo();
		str = StrReplace.replace(str, "{#provice-1#}", province);
		// 所属专区
		String select = getClassInfoByType();
		str = StrReplace.replace(str, "{#calalog-sale#}", select);
		FileIO.SaveToFile(str, filepath);
		
	}
	
	
	
	// 专区信息
	public String getClassInfoByType() throws SaasApplicationException {

		Productclass product = new Productclass();
		String select = product.getSelectedByComm("3", "1");
		return select;
	}
	
	
	
	// 省份信息
	public String getProvinceInfo() throws SaasApplicationException {

		String province = "";
		AreaInfo area = new AreaInfo();
		province = area.getCountrySelect("5J2mc0X0G85BH");
		return province;
	}
	
	
	public String getHtmlTemplateStr(String up_id, String type, String linkUrl) throws SaasApplicationException {

		String html = "";
		ArrayList sourceList = getClassInfoByUpType(up_id, type);
		log.LOG_INFO("sourceList=" + sourceList);
		if (sourceList != null && sourceList.size() > 0) {
			for (int i = 0, j = 0; i < 11 && j < 7; i = i + 2, j++) {
				String temp = "", tt = "";
				// log.LOG_INFO("开始获取一级分类.."+up_id+"|"+type+"| loop====" );
				if (sourceList.size() > i) {
					HashMap map1 = (HashMap) sourceList.get(i);
					String idx1 = map1.get("class_id").toString();
					String name1 = map1.get("class_name").toString();
					
					HashMap map2 = (HashMap) sourceList.get(i + 1);
					String idx2 = map2.get("class_id").toString();
					String name2 = map2.get("class_name").toString();
					if (j % 2 == 0) {
						tt = replaceTop1(idx1, name1, idx2, name2, linkUrl, type);
					}
					else {
						tt = replaceTop2(idx1, name1, idx2, name2, linkUrl, type);
					}
					html = html + tt;
				}
			}
		}
		
		return html;
	}
	
	
	public String replaceTop1(String idx1, String name1, String idx2, String name2, String linkUrl, String type) throws SaasApplicationException {

		String title = "<tr>                                                   " + "<td width=\"50%\" valign=\"top\" bgcolor=\"EDF2F8\">             " + "   <a href=\"" + linkUrl + type + "&class_id=" + idx1 + "\" class=\"cpbt\">" + name1 + "</a><br>                " + createHtmlTemplate(idx1, name1, linkUrl, type) + "</td>                                                            " + "<td width=\"50%\" valign=\"top\">                                " + "   <a href=\"" + linkUrl + type + "&class_id=" + idx2 + "\" class=\"cpbt\">" + name2 + "</a><br>                " + createHtmlTemplate(idx2, name2, linkUrl, type) + "</td>																													  " + "</tr>																													  ";
		
		return title;
	}
	
	
	public String replaceTop2(String idx3, String name3, String idx4, String name4, String linkUrl, String type) throws SaasApplicationException {

		String resource1 = createHtmlTemplate(idx3, name3, linkUrl, type);
		String resource2 = createHtmlTemplate(idx4, name4, linkUrl, type);
		log.LOG_INFO("resource2.........");
		String title = "<tr>																										" + "<td valign=\"top\">                                              " + "   <a href=\"" + linkUrl + type + "&class_id=" + idx3 + "\" class=\"cpbt\">" + name3 + "</a><br>  					    " + resource1 + "</td>                                                            " + "<td valign=\"top\" bgcolor=\"EDF2F8\">                           " + "   <a href=\"" + linkUrl + type + "&class_id=" + idx4 + "\" class=\"cpbt\">" + name4 + "</a><br>					      " + resource2 + "</td>                                                            " + "</tr>                                                            ";
		
		return title;
	}
	
	
	
	// 生成分类HTML
	@SuppressWarnings("unused")
	public String createHtmlTemplate(String id, String name, String linkUrl, String type) throws SaasApplicationException {

		String classHtml = ""; // [4]= new String[]{};
		ArrayList secondList = getClassInfoByUpType(id, type);
		log.LOG_INFO("secondList.........");
		classHtml = classHtml + replaceTwo(secondList, linkUrl, type);
		log.LOG_INFO("classHtml.........");
		return classHtml;
	}
	
	
	public String replaceTwo(ArrayList secondList, String linkUrl, String type) throws SaasApplicationException {

		String title = "";
		if (secondList != null && secondList.size() > 0) {
			for (int i = 0; i < 12; i++) {
				if (secondList.size() > i) {
					HashMap map = (HashMap) secondList.get(i);
					String id = map.get("class_id").toString();
					String name = "", allName = "";
					if (map.get("class_name") != null) {
						allName = map.get("class_name").toString();
						if (allName.length() > 4) {
							name = StringUtil.getLimitLengthString(allName, "", 9);
						}
						else {
							name = allName;
							for (int j = 0; j < 6 - name.length(); j++) {
								name = name + "&nbsp";
							}
						}
					}
					title = title + "<a href=\"" + linkUrl + type + "&class_id=" + id + "\" title=\"" + allName + "\"class=\"news\">" + name + " |</a> ";
				}
			}
		}
		return title;
	}
	
	
	
	// 取出分类
	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;
		
	}
	
}

⌨️ 快捷键说明

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