/** 输出Sitemap */ @At @Ok("raw:xml") public File sitemap() throws MalformedURLException, ParseException { String tmpdir = conf.get("website.tmp_dir", "/tmp"); Files.createDirIfNoExists(tmpdir); final WebSitemapGenerator gen = new WebSitemapGenerator(urlbase, new File(tmpdir)); gen.addUrl(urlbase + "/yvr/list"); dao.each( Topic.class, Cnd.orderBy().desc("createTime"), dao.createPager(1, 1000), new Each<Topic>() { public void invoke(int index, Topic topic, int length) { try { Options options = new Options(urlbase + "/yvr/t/" + topic.getId()); // TODO 从redis读取最后更新时间 // options.lastMod(topic.getCreateAt()); WebSitemapUrl url = new WebSitemapUrl(options); gen.addUrl(url); } catch (Exception e) { e.printStackTrace(); } } }); List<File> list = gen.write(); if (list.size() > 0) return list.get(0); return null; }
public void updateTacTerminal() { /** * List<String[]> list = CvsFileParser.getCSV("厂商数据_01.csv"); for(String[] ss:list){ * if(ss.length < 3){ System.out.println(" >> "+ss[0]+"|"+ss[1]); } } */ Cnd condition = Cnd.where("d_status", "=", "1"); List<Tac> tlist = dao.search(Tac.class, condition.orderBy().asc("d_hsman_name")); for (Tac t : tlist) { List<String[]> list = CvsFileParser.getCSV("厂商数据_01.csv"); for (String[] str : list) { if (t.getHsmanName().toLowerCase().equals(str[0].toLowerCase())) { if (!"0".equals(str[1])) { t.setHsmanNameEn(str[1].toLowerCase()); } if (!"0".equals(str[2])) { t.setHsmanName(str[2].toLowerCase()); } if (dao.update(t)) { System.out.println( " >> 更新成功[" + t.getId() + "|" + t.getTac() + "|" + t.getHsmanName() + "|" + t.getHsmanNameEn() + "]"); break; } } } } }
@At("/f/list") @Ok("ftl:forum/list") public Object list(String page, String pageSize) { OrderBy cnd = Cnd.orderBy().desc("createTime"); List<ForumTip> list = dao.query(ForumTip.class, cnd, null); for (ForumTip forumTip : list) { dao.fetchLinks(forumTip, null); } System.out.println(list.size()); return list; }
public void test6() { Cnd condition = Cnd.where("d_status", "=", "1"); List<Tac> tlist = dao.search(Tac.class, condition.orderBy().asc("d_hsman_name")); for (Tac t : tlist) { // System.out.print(" > // "+t.getHsmanName()+"|"+t.getHsmanNameEn()+"|"+t.getHstypeName()+"|"+t.getHstypeNameEn()); // 如果是英文,则将中文名称制空,然后修改英文 /** * if(t.getHsmanName().matches("^[a-zA-Z]*")){ t.setHsmanName("暂无"); t.setCreatetime(new * Date()); } */ if (null != t.getHsmanNameEn() && !"".equals(t.getHsmanNameEn()) && t.getHstypeName().toLowerCase().startsWith(t.getHsmanNameEn().toLowerCase())) { String hstypename = t.getHstypeName().toLowerCase().replace(t.getHsmanNameEn().toLowerCase(), ""); if (null != hstypename) { t.setHstypeName(hstypename.trim()); System.out.println(" -> 1:" + hstypename.trim()); } } if (null != t.getHsmanName() && !"".equals(t.getHsmanName()) && t.getHstypeName().toLowerCase().startsWith(t.getHsmanName().toLowerCase())) { String hstypename = t.getHstypeName().toLowerCase().replace(t.getHsmanName().toLowerCase(), ""); if (null != hstypename) { t.setHstypeName(hstypename.trim()); System.out.println(" -> 2:" + hstypename.trim()); } } if (t.getHstypeName().startsWith("one touch ")) { String hstypename = t.getHstypeName().toLowerCase().replace("one touch ", ""); t.setHstypeName(hstypename); } String[] strs = t.getHstypeName().toLowerCase().split(" "); if (strs.length > 2) { String hsman = strs[0]; String hstype = strs[1]; System.out.println( " > [" + t.getHsmanName() + "|" + t.getHstypeName() + "] " + hsman + "|" + hstype); } /** */ // if(dao.update(t)){ // System.out.println(" >> 更新厂商名称为英文的厂商名称成功!"); // } } }
/** * 分页查找 resource * * @param categoryId 分类id好好 * @param order * @param pager * @return */ public List<Resource> search(Integer categoryId, Integer tagId, String order, Pager pager) { List<Resource> query = null; if (categoryId != null) { query = dao.query(Resource.class, Cnd.where("categoryId", "=", categoryId).desc("id"), pager); if (pager != null) { pager.setRecordCount(dao.count(Resource.class, Cnd.where("categoryId", "=", categoryId))); } } else { query = dao.query(Resource.class, Cnd.orderBy().desc("id"), pager); if (pager != null) { pager.setRecordCount(dao.count(Resource.class)); } } for (Resource resource : query) { resourceRelationFull(resource); } return query; }
/** 全文输出 */ @At @Ok("raw:xml") public String rss() throws IOException, FeedException { SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("rss_2.0"); String urlbase = conf.get("website.urlbase", "https://nutz.cn"); feed.setLink(urlbase); feed.setTitle(conf.get("website.title", "Nutz社区")); feed.setDescription(conf.get("website.description", "一个有爱的社区")); feed.setAuthor(conf.get("website.author", "wendal")); feed.setEncoding("UTF-8"); feed.setLanguage("zh-cn"); List<SyndEntry> entries = new ArrayList<SyndEntry>(); SyndEntry entry; SyndContent description; List<Topic> list = dao.query(Topic.class, Cnd.orderBy().desc("createTime"), dao.createPager(1, 10)); for (Topic topic : list) { dao.fetchLinks(topic, "author"); entry = new SyndEntryImpl(); entry.setTitle(topic.getTitle()); entry.setLink(urlbase + "/yvr/t/" + topic.getId()); entry.setPublishedDate(topic.getCreateTime()); description = new SyndContentImpl(); description.setType("text/html"); description.setValue(Markdowns.toHtml(topic.getContent(), urlbase)); entry.setDescription(description); entry.setAuthor(topic.getAuthor().getLoginname()); entries.add(entry); } feed.setEntries(entries); if (list.size() > 0) { feed.setPublishedDate(list.get(0).getCreateTime()); } SyndFeedOutput output = new SyndFeedOutput(); return output.outputString(feed, true); }
public void waplog() throws ClassNotFoundException { if (null != dao) { System.out.println(" >> dao is not null"); List<String[]> list = IMEIParser.getCSV("wap19.csv"); List<Tac> tlist = dao.search(Tac.class, Cnd.orderBy().asc("d_id")); Tac tac = null; int fo = 0; int offset = 0; for (String[] s : list) { tac = new Tac(); try { if (null == s[2] || "".equals(s[2])) { continue; } } catch (Exception e) { continue; } tac.setTac(s[2]); String info = s[3].split("/")[0]; info = info.replace("\"", "").replace("_CMCC", "").trim(); if (info.startsWith("Nokia")) { int start = info.lastIndexOf("a"); if (start > 0) { tac.setHsmanName("Nokia"); tac.setHstypeName(info.substring(start + 1, info.length())); } } else if (info.startsWith("SonyEricsson")) { int start = info.lastIndexOf("n"); if (start > 0) { tac.setHsmanName("SonyEricsson"); tac.setHstypeName(info.substring(start + 1, info.length())); } } else if (info.startsWith("OPPO")) { } else { String[] hs = info.split("-"); int length = hs.length; if (length < 2) { System.out.println(" >> info:" + info); } else { if (length == 2) { tac.setHsmanName(hs[0]); tac.setHstypeName(hs[1]); } else if (length == 3) { tac.setHsmanName(hs[0] + "-" + hs[1]); tac.setHstypeName(hs[2]); } else { fo++; } } } if (null == tac.getHsmanName() || "".equals(tac.getHsmanName())) { continue; } if (null == tac.getHstypeName() || "".equals(tac.getHstypeName())) { continue; } Tac tmp = dao.findByCondition(Tac.class, Cnd.where("d_tac", "=", tac.getTac())); if (null == tmp) { tac = dao.save(tac); // System.out.println(" >> "+tac.getId()); offset++; } else { // System.out.println(" >> 已存在tac["+tmp.getTac()+"]"); } } System.out.println(" >> fo:" + fo); System.out.println(" >> offset:" + offset); } else { System.out.println(" >> dao is null"); } }
public void waplogPatch() throws ClassNotFoundException { if (null != dao) { System.out.println(" >> dao is not null"); List<Tac> tlist = dao.search(Tac.class, Cnd.orderBy().asc("d_id")); int fo = 0; int offset = 0; for (Tac s : tlist) { if (!s.getHsmanName().equals("参照机型名称(英文)")) { continue; } if (null == s.getHstypeName() || s.getHstypeName().equals("")) { continue; } String info = s.getHstypeName().split("/")[0]; info = info.replace("\"", "").replace("_CMCC", "").trim(); if (info.startsWith("Nokia")) { int start = info.lastIndexOf("a"); if (start > 0) { s.setHsmanName("Nokia"); s.setHsmanNameEn("Nokia"); s.setHstypeName(info.substring(start + 1, info.length())); s.setHstypeNameEn(info.substring(start + 1, info.length())); } } else if (info.startsWith("SonyEricsson")) { int start = info.lastIndexOf("n"); if (start > 0) { s.setHsmanName("SonyEricsson"); s.setHsmanNameEn("SonyEricsson"); s.setHstypeName(info.substring(start + 1, info.length())); s.setHstypeNameEn(info.substring(start + 1, info.length())); } } else { String[] hs = info.split("-"); int length = hs.length; if (length < 2) { System.out.println(" >> info:" + info); } else { if (length == 2) { s.setHsmanName(hs[0]); s.setHsmanNameEn(hs[0]); s.setHstypeName(hs[1]); s.setHstypeNameEn(hs[1]); } else if (length == 3) { s.setHsmanName(hs[0] + "-" + hs[1]); s.setHsmanNameEn(hs[0] + "-" + hs[1]); s.setHstypeName(hs[2]); s.setHstypeNameEn(hs[2]); } else { fo++; } } } if (null == s.getHsmanName() || "".equals(s.getHsmanName())) { continue; } if (null == s.getHstypeName() || "".equals(s.getHstypeName())) { continue; } if (dao.update(s)) { offset++; } // Tac tmp = dao.findByCondition(Tac.class, Cnd.where("d_tac", "=", tac.getTac())); // if(null == tmp){ // tac = dao.save(tac); // offset++; // } } System.out.println(" >> fo:" + fo); System.out.println(" >> offset:" + offset); } else { System.out.println(" >> dao is null"); } }
/** * 查询数据库中的全部数据 * * @param <T> * @param c 查询的表 * @param orderby desc 排序的条件 * @return List */ public <T> List<T> search(Class<T> c, String orderby) { return dao.query(c, Cnd.orderBy().desc(orderby), null); }
/** * 分页查询表中所有数据 * * @param <T> * @param c 查询的表 * @param currentPage 当前页数 * @param pageSize 每页显示数量 * @param orderby desc排序的条件 * @return List */ public <T> List<T> searchByPage(Class<T> c, int currentPage, int pageSize, String orderby) { Pager pager = dao.createPager(currentPage, pageSize); return dao.query(c, Cnd.orderBy().desc(orderby), pager); }