- public void consultaionToHtml(String cid) {
- try {
- this.publicOpenId= PropertiesUtils.getPropertiesValue("aloan.openid");
- String cityHtml="";
- GDSMConsultaion vo = gdsmconsultaionService.getObjectById(GDSMConsultaion.class, cid);
- String remarks="";
- if(null!=vo&&null!=vo.getRemarks()){
- if(vo.getRemarks().equals("0")){
- remarks="以上文章内容来源于网络,不代表本公司立场和观点,如有侵权请与我们联系。";
- }else if(vo.getRemarks().equals("1")){
- remarks="以上文章内容来源于宜信月刊(微信ID:yixinyuekan)。";
- }else if(vo.getRemarks().equals("2")){
- remarks="以上内容为原创内容,转发请注明来自宜信普惠金融家。";
- }
- }
- if(null!=vo&&vo.getConsultaionType().equals("cheats")&&vo.getContentLink()==null){
- Map map = new HashMap();
- map.put("consultaionId",vo.getId());
- map.put("title",vo.getTitle());
- map.put("time",StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM-dd"));
- map.put("content",vo.getContent().replaceAll(ResourceLocator.GEDAI_CONSULTAION_PIC_PATH,getSiteUrl()+"/"+ResourceLocator.GEDAI_CONSULTAION_PIC_PATH));
- map.put("path",getSiteUrl());
- map.put("remarks",remarks);
- String path = ResourceLocator.getResourceAbsoluteLocationPath(ResourceLocator.GEDAI_CONSULTAION_HTML_PATH);
- this.ouputFile("comCheats.ftl", vo.getId()+".html", map,path+"/cheats/"+StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM"));
- }else if(null!=vo&&!vo.getConsultaionType().equals("cheats")){
- String functiontype="";
- if(vo.getConsultaionType().equals("essay")){
- functiontype="ESSAY";
- }else if(vo.getConsultaionType().equals("info")){
- functiontype="CONSULTAION";
- }
- List<GDSMCity> cityList=gdManagerService.getGDCityLevel1();
- for(GDSMCity city : cityList){
- cityHtml=cityHtml+"<option value='"+city.getCityCode()+"'>"+city.getCityName()+"</option>";
- }
- String imgurl="";
- if(vo!=null&&vo.getLogoUrl()!=null){
- imgurl=getSiteUrl() +"/"+ ResourceLocator.GEDAI_CONSULTAION_PIC_PATH +"/"+vo.getLogoUrl();
- }else{
- imgurl=getSiteUrl() + "/img/weixin/gdSelfMarketing/logo1.png";
- }
- Map map = new HashMap();
- map.put("publicOpenId",publicOpenId);
- map.put("consultaionId",vo.getId());
- map.put("title",vo.getTitle());
- map.put("time",StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM-dd"));
- map.put("content",vo.getContent().replaceAll(ResourceLocator.GEDAI_CONSULTAION_PIC_PATH,getSiteUrl()+"/"+ResourceLocator.GEDAI_CONSULTAION_PIC_PATH));
- map.put("cityHtml",cityHtml);
- map.put("path",getSiteUrl());
- map.put("shareImageUrl",imgurl);
- map.put("shareDesc","宜信为没有受到传统金融体系重视的高成长性人群提供普惠金融服务宜信普惠。");
- map.put("remarks",remarks);
- map.put("functiontype",functiontype);
- String path = ResourceLocator.getResourceAbsoluteLocationPath(ResourceLocator.GEDAI_CONSULTAION_HTML_PATH);
- for(GDSMCity city : cityList){
- this.ouputFile("comProduct.ftl", vo.getId()+".html", map,path+"/"+city.getCityCode()+"/"+StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM"));
- }
- logger.info("资讯【ID={}】静态化生成成功。", cid);
- }
- } catch (Exception e) {
- logger.info("资讯【ID={}】静态化生成失败。",cid);
- logger.error(e.getMessage(), e);
- }
- }
- public void ouputFile(String ftlName, String fileName, Map<String, Object> map,String path) throws Exception{
- //创建fm的配置
- Configuration config = new Configuration();
- //指定默认编码格式
- config.setDefaultEncoding("UTF-8");
- //设置模板的包路径
- config.setClassForTemplateLoading(this.getClass(), "/com/yixin/gdSelfMarketing/ftl");
- //获得包的模板
- Template template = config.getTemplate(ftlName);
- //指定文件输出的路径
- File file=new File(path+"/"+fileName);
- File parent = file.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- //定义输出流,注意的必须指定编码
- Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path+"/"+fileName)),"UTF-8"));
- //生成模板
- template.process(map, writer);
- writer.close();
- }
public void consultaionToHtml(String cid) { try { this.publicOpenId= PropertiesUtils.getPropertiesValue("aloan.openid"); String cityHtml=""; GDSMConsultaion vo = gdsmconsultaionService.getObjectById(GDSMConsultaion.class, cid); String remarks=""; if(null!=vo&&null!=vo.getRemarks()){ if(vo.getRemarks().equals("0")){ remarks="以上文章内容来源于网络,不代表本公司立场和观点,如有侵权请与我们联系。"; }else if(vo.getRemarks().equals("1")){ remarks="以上文章内容来源于宜信月刊(微信ID:yixinyuekan)。"; }else if(vo.getRemarks().equals("2")){ remarks="以上内容为原创内容,转发请注明来自宜信普惠金融家。"; } } if(null!=vo&&vo.getConsultaionType().equals("cheats")&&vo.getContentLink()==null){ Map map = new HashMap(); map.put("consultaionId",vo.getId()); map.put("title",vo.getTitle()); map.put("time",StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM-dd")); map.put("content",vo.getContent().replaceAll(ResourceLocator.GEDAI_CONSULTAION_PIC_PATH,getSiteUrl()+"/"+ResourceLocator.GEDAI_CONSULTAION_PIC_PATH)); map.put("path",getSiteUrl()); map.put("remarks",remarks); String path = ResourceLocator.getResourceAbsoluteLocationPath(ResourceLocator.GEDAI_CONSULTAION_HTML_PATH); this.ouputFile("comCheats.ftl", vo.getId()+".html", map,path+"/cheats/"+StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM")); }else if(null!=vo&&!vo.getConsultaionType().equals("cheats")){ String functiontype=""; if(vo.getConsultaionType().equals("essay")){ functiontype="ESSAY"; }else if(vo.getConsultaionType().equals("info")){ functiontype="CONSULTAION"; } List<GDSMCity> cityList=gdManagerService.getGDCityLevel1(); for(GDSMCity city : cityList){ cityHtml=cityHtml+"<option value='"+city.getCityCode()+"'>"+city.getCityName()+"</option>"; } String imgurl=""; if(vo!=null&&vo.getLogoUrl()!=null){ imgurl=getSiteUrl() +"/"+ ResourceLocator.GEDAI_CONSULTAION_PIC_PATH +"/"+vo.getLogoUrl(); }else{ imgurl=getSiteUrl() + "/img/weixin/gdSelfMarketing/logo1.png"; } Map map = new HashMap(); map.put("publicOpenId",publicOpenId); map.put("consultaionId",vo.getId()); map.put("title",vo.getTitle()); map.put("time",StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM-dd")); map.put("content",vo.getContent().replaceAll(ResourceLocator.GEDAI_CONSULTAION_PIC_PATH,getSiteUrl()+"/"+ResourceLocator.GEDAI_CONSULTAION_PIC_PATH)); map.put("cityHtml",cityHtml); map.put("path",getSiteUrl()); map.put("shareImageUrl",imgurl); map.put("shareDesc","宜信为没有受到传统金融体系重视的高成长性人群提供普惠金融服务宜信普惠。"); map.put("remarks",remarks); map.put("functiontype",functiontype); String path = ResourceLocator.getResourceAbsoluteLocationPath(ResourceLocator.GEDAI_CONSULTAION_HTML_PATH); for(GDSMCity city : cityList){ this.ouputFile("comProduct.ftl", vo.getId()+".html", map,path+"/"+city.getCityCode()+"/"+StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM")); } logger.info("资讯【ID={}】静态化生成成功。", cid); } } catch (Exception e) { logger.info("资讯【ID={}】静态化生成失败。",cid); logger.error(e.getMessage(), e); } } public void ouputFile(String ftlName, String fileName, Map<String, Object> map,String path) throws Exception{ //创建fm的配置 Configuration config = new Configuration(); //指定默认编码格式 config.setDefaultEncoding("UTF-8"); //设置模板的包路径 config.setClassForTemplateLoading(this.getClass(), "/com/yixin/gdSelfMarketing/ftl"); //获得包的模板 Template template = config.getTemplate(ftlName); //指定文件输出的路径 File file=new File(path+"/"+fileName); File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } //定义输出流,注意的必须指定编码 Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path+"/"+fileName)),"UTF-8")); //生成模板 template.process(map, writer); writer.close(); }
3.访问生成的html文件