静态页面生成

xiaoxiao2024-04-19  15

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; }}
转载请注明原文地址: https://www.6miu.com/read-5015099.html

最新回复(0)