`
xxtianxiaxing
  • 浏览: 691021 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

静态页面生成

    博客分类:
  • web
阅读更多
package com.here.web.common.wx;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.here.web.common.TypesTypes;
import com.here.web.model.Harea;
import com.here.web.model.HereCorporation;
import com.here.web.model.HereDeploy;
import com.here.web.model.HereProduct;
import com.here.web.model.HereProductparameter;
import com.here.web.model.HereProductparametercategory;
import com.here.web.model.HereProductselfdefinitionparameter;
import com.here.web.model.HereUser;
import com.here.web.service.register.HareaService;
import com.here.web.service.wwq.HereProductparametercategoryService;

public class BuildHereDeployContent{
	
	//它为当前工程的应用路径
	private String path;
	
	public void buildHtml(HareaService hareaService, 
						  HereDeploy hereDeploy, 
						  String servletContextPath, 
						  HereCorporation hereCorporation){
		try{ 	
			this.path = servletContextPath;
			String filePath = servletContextPath + "app\\deploy\\depshow\\depcontent.htm";
			
			String templateContent = "";
			StringBuffer tempSB = new StringBuffer("");
			FileInputStream fileinputstream = new FileInputStream(filePath);// 
			InputStreamReader   isr   =   new   InputStreamReader(fileinputstream, "utf-8");  
			BufferedReader br = new BufferedReader(isr);
			String line=null;
            line=br.readLine();
            while(line!=null){
            	tempSB.append(line+"\n\r");
                line=br.readLine();
            }
			templateContent = tempSB.toString();
			
//替换与hereCorporation有关系的内容
			if(null != hereCorporation.getMainMarkets()){
				templateContent=templateContent.replaceAll("###hereCorporation.realName###",hereCorporation.getRealName()+ "");
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.realName###","");
			}
			templateContent=templateContent.replaceAll("###hereCorporation.corpName###",hereCorporation.getCorpName() + "");
			
			//经营模式
			TypesTypes tt = new TypesTypes();
			String[] businessTypes = hereCorporation.getBusinessType().split(",");
			StringBuffer sb = new StringBuffer("");
			if(businessTypes.length == 2){
				sb.append(tt.businessTypes(businessTypes[0]) + "  " + tt.businessTypes(businessTypes[1]));
			}else{
				sb.append(tt.businessTypes(businessTypes[0]));
			}
			templateContent=templateContent.replaceAll("###hereCorporation.businessType###",sb.toString());
			
			//主营行业
			String corpClasses = getCorpClasses(hereCorporation);
			templateContent=templateContent.replaceAll("###hereCorporation.corpClasses###",corpClasses);
			
			templateContent=templateContent.replaceAll("###hereCorporation.corpIntro###", hereCorporation.getCorpIntro());
			
			//地址
			if(null != hereCorporation.getCorpAddress()){
				templateContent=templateContent.replaceAll("###hereCorporation.corpAddress###", hereCorporation.getCorpAddress());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.corpAddress###", "");
			}
			
			//性别
			if(null != hereCorporation.getSex()){
				if("1".equals(hereCorporation.getSex())) {
					templateContent=templateContent.replaceAll("###hereCorporation.sex###", "男");
				}else{
					templateContent=templateContent.replaceAll("###hereCorporation.sex###", "女");
				}
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.sex###", "");
			}
			
			//邮政编码
			if(null != hereCorporation.getCorpPostalCode()){
				templateContent=templateContent.replaceAll("###hereCorporation.corpPostalCode###", hereCorporation.getCorpPostalCode());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.corpPostalCode###", "");
			}
			
			//网址
			if(null != hereCorporation.getCorpWebsiteUrl()){
				templateContent=templateContent.replaceAll("###hereCorporation.corpWebsiteUrl###", hereCorporation.getCorpWebsiteUrl());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.corpWebsiteUrl###", "");
			}
			
			//电子邮件
			if(null != hereCorporation.getBusinessEmail()){
				templateContent=templateContent.replaceAll("###hereCorporation.businessEmail###", hereCorporation.getBusinessEmail());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.businessEmail###", "");
			}
			
			//联系人
			if(null != hereCorporation.getRealName()){
				templateContent=templateContent.replaceAll("###hereCorporation.realName###", hereCorporation.getRealName());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.realName###", "");
			}
			
			//移动电话
			if(null != hereCorporation.getMobile()){
				templateContent=templateContent.replaceAll("###hereCorporation.mobile###", hereCorporation.getMobile());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.mobile###", "");
			}
			
			//传真
			if(null != hereCorporation.getFaxNumber()){
				templateContent=templateContent.replaceAll("###hereCorporation.faxNumber###", hereCorporation.getFaxNumber());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.faxNumber###", "");
			}
			
			//电话
			if(null != hereCorporation.getPhoneNumber()){
				templateContent=templateContent.replaceAll("###hereCorporation.phoneNumber###", hereCorporation.getPhoneNumber());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.phoneNumber###", "");
			}
			
			//所在地区
			String country = "";
			String province = "";
			String city = "";
			if(null != hereCorporation.getCountry() && hereCorporation.getCountry() != 0){
				country = hareaService.queryById(hereCorporation.getCountry(), Harea.class).getAreaNameZh();
			}
			if(null != hereCorporation.getProvince() && hereCorporation.getProvince() != 0){
				province = hareaService.queryById(hereCorporation.getProvince(), Harea.class).getAreaNameZh();
			}
			if(null != hereCorporation.getCity() && hereCorporation.getCity() != 0){
				city = hareaService.queryById(hereCorporation.getCity(), Harea.class).getAreaNameZh();
			}
			templateContent=templateContent.replaceAll("###hereCorporation.country###",country);
			templateContent=templateContent.replaceAll("###hereCorporation.province###",province);
			templateContent=templateContent.replaceAll("###hereCorporation.city###",city);
			
			templateContent=templateContent.replaceAll("###hereDeploy.demtCountry###",country);
			templateContent=templateContent.replaceAll("###hereDeploy.demtProvince###",province);
			templateContent=templateContent.replaceAll("###hereDeploy.demtCity###",city);
			
			//公司图片
			if(null != hereCorporation.getCorpLogo()){
				templateContent=templateContent.replaceAll("###hereCorporation.corpLogo###", hereCorporation.getCorpLogo());
			}else{
				templateContent=templateContent.replaceAll("###hereCorporation.corpLogo###", "");
			}
		//展会信息
			//展会分类
			if(null != hereDeploy.getDeployClass()){
				System.out.println("hereDeploy.getDeployClass():"+hereDeploy.getDeployClass());
				templateContent=templateContent.replaceAll("###hereDeploy.deployClass###", TypesTypes.getDeployClass(String.valueOf(hereDeploy.getDeployClass())));
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.deployClass###", "");
			}
			
			//主办单位
			if(null != hereDeploy.getCorpMainTake()){
				templateContent=templateContent.replaceAll("###hereDeploy.corpMainTake###", hereDeploy.getCorpMainTake());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.corpMainTake###", "");
			}
			
			//承办单位
			if(null != hereDeploy.getCorpUnderTake()){
				templateContent=templateContent.replaceAll("###hereDeploy.corpUnderTake###", hereDeploy.getCorpUnderTake());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.corpUnderTake###", "");
			}
			
			//开始日期
			if(null != hereDeploy.getStartDate()){
				templateContent=templateContent.replaceAll("###hereDeploy.startDate###", this.DatetoStr(hereDeploy.getStartDate()));
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.startDate###", "");
			}
			
			//结束日期
			if(null != hereDeploy.getEndDate()){
				templateContent=templateContent.replaceAll("###hereDeploy.endDate###", this.DatetoStr(hereDeploy.getEndDate()));
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.endDate###", "");
			}
			
			//联系人
			if(null != hereDeploy.getLinkMan()){
				templateContent=templateContent.replaceAll("###hereDeploy.linkMan###", hereDeploy.getLinkMan());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.linkMan###", "");
			}
			
			//联系电话
			if(null != hereDeploy.getLinkPhone()){
				templateContent=templateContent.replaceAll("###hereDeploy.linkPhone###", hereDeploy.getLinkPhone());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.linkPhone###", "");
			}
			//举办地点
			if(null != hereDeploy.getDemtAddress()){
				templateContent=templateContent.replaceAll("###hereDeploy.demtAddress###", hereDeploy.getDemtAddress());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.demtAddress###", "");
			}
			
			//原始图片
			if(null != hereDeploy.getDeployPic()){
				templateContent=templateContent.replaceAll("###hereDeploy.deployPic###", hereDeploy.getDeployPic());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.deployPic###", "");
			}
			
			//缩略图
			if(null != hereDeploy.getDeployPicThumb()){
				templateContent=templateContent.replaceAll("###hereDeploy.deployPicThumb###", hereDeploy.getDeployPicThumb());
			}else{
				templateContent=templateContent.replaceAll("###hereDeploy.deployPicThumb###", "");
			}
			

			String filename = hereDeploy.getDeployId()+ ".htm"; 
            String fileAbsoluteName = this.path + "\\app\\deploy\\depshow\\" + filename;// ��ɵ�html�ļ�����·����
			
			FileOutputStream fileoutputstream = new FileOutputStream(fileAbsoluteName);// ��b�ļ������
			byte tag_bytes[] = templateContent.getBytes("utf-8"); 
			fileoutputstream.write(tag_bytes);
			fileoutputstream.close(); 

		}catch(Exception e){
			e.printStackTrace();
		} 
	}
	
	// 主营行业
	private String getCorpClasses(HereCorporation hereCorporation) {
		String bc = hereCorporation.getCorpBigClass();
		String mc = hereCorporation.getCorpMiddleClass();
		String sc = hereCorporation.getCorpSmallClass();
		boolean k = false;
		StringBuffer corpClasses = new StringBuffer("");
		if (null != bc && !"".equals(bc) && !bc.equals("null")) {
			if (true == bc.contains(",")) {
				String[] boc = bc.split(",");
				String[] moc = mc.split(",");
				String[] soc = sc.split(",");
				for (int i = 0; i < boc.length; i++) {
					if (!k) {
						if (!moc[i].equals(" ")) {
							if (!soc[i].equals(" ")) {
								corpClasses.append(boc[i] + " >> " + moc[i]
										+ " >> " + soc[i]);
							} else {
								corpClasses.append(boc[i] + " >> " + moc[i]);
							}
						} else {
							corpClasses.append(boc[i]);
						}
						k = true;
					} else {
						if (!moc[i].equals(" ")) {
							if (!soc[i].equals(" ")) {
								corpClasses.append("," + boc[i] + " >> " + moc[i]
										+ " >> " + soc[i]);
							} else {
								corpClasses
										.append("," + boc[i] + " >> " + moc[i]);
							}
						} else {
							corpClasses.append("," + boc[i]);
						}
					}

				}
			} else {
				if (!"".equals(mc) && null != mc && !"null".equals("mc")) {
					if (!"".equals(sc) && null != sc && !"null".equals(sc)) {
						corpClasses.append(bc + " >> " + mc + " >> " + sc);
					} else {
						corpClasses.append(bc + " >> " + mc);
					}
				} else {
					corpClasses.append(bc);
				}
			}
		}

		return corpClasses.toString().replaceAll(",", "<br>");
	}
	//date到String
	public String DatetoStr(Date time) {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		//date转string
		String timeStr = dateFormat.format(time);
		return timeStr;
	}
}


分享到:
评论

相关推荐

    雨尘SEO静态页面生成系统版本源码3秒钟可生成上千条单页面SEO必备神器.zip

    一款随机静态页面生成系统,一秒钟可生成上千条单页面,批量生成单页用来做SEO是非常不错的源码。 雨尘SEO静态页面生成系统PHP网站源码v1.3最新版本,支持文章采集,功能,多模板选择批量生成单页,本次更新增了百度...

    PHP随机静态页面生成系统源码 雨尘SEO系统v1.3

    一款随机静态页面生成系统,一秒钟可生成上千条单页面,批量生成单页用来做SEO是非常不错的源码。雨尘SEO静态页面生成系统源码v1.3版本,支持文章采集,功能,多模板选择批量生成单页,本次更新增了百度自动推送和...

    web静态网页生成器

    "Web静态网页生成器"是一种工具,主要用于自动化创建和构建静态HTML页面。在互联网发展初期,静态网页是最常见的形式,它们由纯HTML代码组成,不包含任何服务器端脚本,如PHP、Java或ASP等。静态网页加载速度快,对...

    SEO静态页面生成系统.rar

    在这个名为"SEO静态页面生成系统.rar"的压缩包中,我们可以推测包含的是一个用于创建优化搜索引擎排名的静态网页生成工具。 静态页面与动态页面不同,它们不依赖服务器端的脚本执行,而是直接以HTML文件的形式存在...

    html静态页面生成

    1. 创建控制器和视图:在ASP.NET MVC或ASP.NET Core项目中,定义一个控制器,为每个需要生成静态页面的URL创建一个动作。编写相应的视图,定义页面布局和内容。 2. 渲染视图为HTML:在控制器动作中,使用`...

    静态页面生成系统

    在本案例中,"xiaokongzi_51aspx"这个压缩包文件很可能包含了一个基于C#开发的静态页面生成系统的源代码或者部署文件。C#是一种常用的编程语言,尤其在Microsoft .NET框架下,它非常适合构建Web应用程序。使用C#来...

    通用静态页面生成系统

    总的来说,通用静态页面生成系统结合了参数化数据获取、JSP分页技术,旨在提供一个高效、可定制的解决方案,以生成静态网页,提升网站性能。无论是开发还是运维,都能从中获益,实现更优质的网站管理和用户体验。

    php静态 页面生成

    这种方法虽然简单有效,但也有其局限性,例如无法自动更新静态页面,当内容变化时需要手动或通过脚本重新生成。此外,对于大型复杂的网站,可能需要更复杂的缓存策略,如使用缓存服务(如Varnish)或者PHP框架提供的...

    基于JavaScript Vue实现的静态网页生成源码+项目说明.zip

    基于JavaScript Vue实现的静态网页生成源码+项目说明.zip基于JavaScript Vue实现的静态网页生成源码+项目说明.zip基于JavaScript Vue实现的静态网页生成源码+项目说明.zip基于JavaScript Vue实现的静态网页生成源码+...

    PHP网站源码 雨尘SEO静态页面生成系统源码

    一款随机静态页面生成系统,一秒钟可生成上千条单页面,批量生成单页用来做 SEO 是非常不错的源码,程序支持二级目录运行,可自行添加模板请参考后台教程。 1、第一次使用程序前请先手动导入 sql 文件到数据库,并...

    伪静态页面生成技术|静态页面|生成技术

    伪静态页面生成技术是网站优化的重要手段,它结合了动态网页的灵活性和静态网页的优势,有助于提升SEO排名和用户体验。通过URL重写、服务器端转换或前端路由等方式,我们可以轻松实现伪静态效果。在实际应用中,合理...

    通用静态页面生成系统(Engineer) v.1

    《通用静态页面生成系统(Engineer) v.1》是一款高效能、低成本的网页生成工具,旨在优化企业网站性能,减轻服务器压力,从而降低企业运营成本。Engineer系统的核心功能在于将动态内容转换为静态HTML页面,使得用户...

    asp.net 静态页面生成

    2. 交互功能:静态页面失去了动态网页的交互性,如表单提交、登录验证等功能需要额外处理。 3. 版本控制:静态文件的管理需要考虑版本控制,避免旧版页面的误用。 五、源码学习 提供的"生成静态页面源码"可能包含...

    静态页面生成例子 ASP

    这个ASP的静态页面生成例子就是一个很好的学习素材。 ASP(Active Server Pages)是微软推出的一种服务器端脚本环境,它允许开发人员使用VBScript或JScript等脚本语言创建动态网页。在ASP中,通过结合HTML代码和...

    首页静态页面生成工具

    在标签中提到了“静态页面”,静态页面是不通过服务器端脚本(如PHP、ASP.NET等)动态生成的HTML文件,它们的内容在网页被创建时就已经确定,不会根据用户的交互或特定条件变化。这种页面加载速度快,但更新维护相对...

    .net静态页面生成

    .NET框架中的静态页面生成是一种优化网站性能的技术,它允许开发者将动态生成的网页内容转换为静态HTML文件,从而减轻服务器负担,提高用户访问速度。这种技术尤其适用于内容更新不频繁,但访问量较大的网站,例如...

Global site tag (gtag.js) - Google Analytics