作者存档
2015一月28

Nutz:通过Java代码生成表格图片

效果图:

i

源码不解释:

 private void ResultToJpg(List<Map> list, String title, HttpServletResponse response) {
        BufferedImage image;
        int totalrow = list.size();
        int totalcol = 7;
        int imageWidth = 640;
        int rowheight = 40;
        int imageHeight = totalrow * rowheight + 105;
        int startHeight = 20;
        int startWidth = 10;
        int colwidth = (int) ((imageWidth - 20) / totalcol);
        int colwidth2 = (int) ((imageWidth - 20) / (totalcol + 1));
        image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
        Graphics2D graphics = (Graphics2D) image.getGraphics();
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, imageWidth, imageHeight);
        Font font = new Font("微软雅黑", Font.BOLD, 20);
        graphics.setFont(font);
        graphics.setColor(new Color(112, 48, 158));
        graphics.drawString(Strings.sNull(title), startWidth, startHeight + 10);
        font = new Font("微软雅黑", Font.PLAIN, 13);
        graphics.setColor(new Color(99, 99, 99));
        graphics.setFont(font);
        String subtitle1 = "欢迎访问";
        graphics.drawString(subtitle1, startWidth, startHeight + 30);
        font = new Font("Arial, Helvetica, sans-serif", Font.BOLD, 13);
        graphics.setColor(new Color(112, 48, 158));
        graphics.setFont(font);
        String subtitle2 = "inm.xuetang.cn";
        graphics.drawString(subtitle2, startWidth + 60, startHeight + 30);
        font = new Font("微软雅黑", Font.PLAIN, 13);
        graphics.setColor(new Color(99, 99, 99));
        graphics.setFont(font);
        String subtitle3 = "冲榜、制榜!";
        graphics.drawString(subtitle3, startWidth + 165, startHeight + 30);
        //画首行
        graphics.setColor(new Color(112, 48, 158));
        graphics.fillRect(startWidth, startHeight + rowheight, imageWidth - 20, rowheight);
        font = new Font("微软雅黑", Font.PLAIN, 12);
        graphics.setColor(Color.WHITE);
        graphics.setFont(font);
        graphics.drawString("#", startWidth + 10, startHeight + rowheight * 2 - 15);
        graphics.drawString("公众号", startWidth + colwidth - 10, startHeight + rowheight * 2 - 15);
        //画表头
        String[] headCells = {"发布", "总阅读数", "  头条", " 平均 ", "总点赞数", " WCI"};
        for (int m = 0; m < headCells.length; m++) {
            graphics.drawString(headCells[m].toString(), startWidth + colwidth2 * m + colwidth * 2, startHeight + rowheight * 2 - 15);
        }
        //画行
        for (int j = 0; j < totalrow; j++) {
            if (j % 2 == 0) {
                graphics.setColor(new Color(255, 255, 255));
            } else {
                graphics.setColor(new Color(238, 238, 238));
            }
            graphics.fillRect(startWidth, startHeight + (j + 1) * rowheight + 40, imageWidth - 20, startHeight + (j + 1) * rowheight);
            font = new Font("微软雅黑", Font.BOLD, 12);
            graphics.setColor(new Color(112, 48, 158));
            graphics.setFont(font);
            graphics.drawString(String.valueOf(j + 1), startWidth + 10, startHeight + (j + 3) * rowheight - 15);
            Map map = list.get(j);
            font = new Font("微软雅黑", Font.PLAIN, 12);
            graphics.setColor(new Color(0, 0, 0));
            graphics.setFont(font);
            graphics.drawString(Strings.sNull(map.get("wx_nickname")), startWidth + (colwidth / 2) - 10, startHeight + (j + 3) * rowheight - 25);
            graphics.drawString(Strings.sNull(map.get("wx_name")), startWidth + (colwidth / 2) - 10, startHeight + (j + 3) * rowheight - 10);
            graphics.drawString(Strings.sNull(map.get("url_times")) + "/" + Strings.sNull(map.get("url_num")), startWidth + colwidth2 + colwidth + 10, startHeight + (j + 3) * rowheight - 15);
            if (NumberUtils.toInt(Strings.sNull(map.get("url_num_10w"))) > 0) {
                String readnum_all = Strings.sNull(map.get("readnum_all"));
                int t = NumberUtils.toInt(readnum_all.substring(readnum_all.length() - 4, readnum_all.length() - 3));
                if (t > 0) {
                    readnum_all = readnum_all.substring(0, readnum_all.length() - 4) + "." + String.valueOf(t);
                } else {
                    readnum_all = readnum_all.substring(0, readnum_all.length() - 4);
                }
                graphics.drawString(readnum_all + "万+", startWidth + colwidth2 + colwidth * 2 + 5, startHeight + (j + 3) * rowheight - 15);
            } else {
                graphics.drawString(Strings.sNull(map.get("readnum_all")), startWidth + colwidth2 + colwidth * 2 + 5, startHeight + (j + 3) * rowheight - 15);
            }
            if (NumberUtils.toInt(Strings.sNull(map.get("url_times_readnum"))) > 100000) {
                String url_times_readnum = Strings.sNull(map.get("url_times_readnum"));
                int t = NumberUtils.toInt(url_times_readnum.substring(url_times_readnum.length() - 4, url_times_readnum.length() - 3));
                if (t > 0) {
                    url_times_readnum = url_times_readnum.substring(0, url_times_readnum.length() - 4) + "." + String.valueOf(t);
                } else {
                    url_times_readnum = url_times_readnum.substring(0, url_times_readnum.length() - 4);
                }
                graphics.drawString(url_times_readnum+"万+", startWidth + colwidth2 + colwidth * 3 - 5, startHeight + (j + 3) * rowheight - 15);
            } else {
                graphics.drawString(Strings.sNull(map.get("url_times_readnum")), startWidth + colwidth2 + colwidth * 3 - 5, startHeight + (j + 3) * rowheight - 15);
            }
            if (NumberUtils.toInt(Strings.sNull(map.get("readnum_av"))) > 100000) {
                String readnum_av = Strings.sNull(map.get("readnum_av"));
                int t = NumberUtils.toInt(readnum_av.substring(readnum_av.length() - 4, readnum_av.length() - 3));
                if (t > 0) {
                    readnum_av = readnum_av.substring(0, readnum_av.length() - 4) + "." + String.valueOf(t);
                } else {
                    readnum_av = readnum_av.substring(0, readnum_av.length() - 4);
                }
                graphics.drawString(readnum_av+"万+", startWidth + colwidth2 + colwidth * 4 - 15, startHeight + (j + 3) * rowheight - 15);
            } else {
                graphics.drawString(Strings.sNull(map.get("readnum_av")), startWidth + colwidth2 + colwidth * 4 - 15, startHeight + (j + 3) * rowheight - 15);

            }
            graphics.drawString(Strings.sNull(map.get("likenum_all")), startWidth + colwidth2 + colwidth * 5 - 20, startHeight + (j + 3) * rowheight - 15);
            graphics.drawString(Strings.sNull(map.get("wci")), startWidth + colwidth2 + colwidth * 6 - 40, startHeight + (j + 3) * rowheight - 15);
        }
        //末行
        graphics.setColor(Color.WHITE);
        graphics.fillRect(startWidth, startHeight + (totalrow + 1) * rowheight + 40, imageWidth - 20, startHeight + (totalrow + 1) * rowheight);
        try {
            response.setContentType("image/png");
            OutputStream out = response.getOutputStream();
            ImageIO.write(image, "png", out);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

 

2015一月17

微信公众号历史文章回溯:人民日报(2012-12-28至2015-01-15)

人民日报(2012-12-28至2015-01-15).xlsx

链接: http://pan.baidu.com/s/1jG67rXs
密码: flo0

2015一月3

微信:最近开发了个微信弹幕软件

关注微信,发送弹幕到电影院大屏幕,后台有审核和黑名单功能。

弹幕字体随机、颜色随机、大小随机、位置随机,都可以设置。

测试效果和当天影院现场图片:

1 2 3

2014十一月14

Java:数字补零

String str = String.format(“%010d”, 1212);

2014十一月10

Temp

ComboIocLoader loader = new ComboIocLoader(
new String[]{
“*org.nutz.ioc.loader.json.JsonLoader”, “ioc/”,
“*org.nutz.ioc.loader.annotation.AnnotationIocLoader”, “cn.xuetang”}
);
ioc = new NutIoc(loader);
dao = ioc.get(Dao.class);

 

2014十一月10

Mysql:截取字符串

SELECT SUBSTRING_INDEX(SUBSTRING(url,LOCATE(“sn=”,url)+3),’&’,1),url FROM wx_kw_url_1111

2014十月24

Android:tcpdump抓包命令

adb shell

su

chmod 777 /data/local/tcpdump

/data/local/tcpdump -p -vv -s 0 -w /sdcard/capture.pcap

2014九月29

MySQL:not in 语句优化

select a.*
from wx_nickname a
left join (select distinct nickname_id from wx_group_nickname )b on
a.id = b.nickname_id
where b.nickname_id is null

2014九月23

NutzWk 企业级WEB后台开发框架开源了

NutzWk

https://github.com/Wizzercn/NutzWk

基于Nutz的开源企业级开发框架。

文件编码全部为UTF-8,可以导入Eclispe、IDEA中,jdk7,tomcat 6/7.
创建空的数据库,首次启动项目会自动初始化数据.

 

本框架已成功应用于XX省交通厅网络问政平台、XX省交通厅CMS内容管理系统、XX公司舆情监测管理中心等项目。

使用条款:
1、个人开源,可以任意修改使用;
2、商业使用,必须更改后台菜单布局、CSS样式、界面颜色等元素(既:不可使用原始界面用于商业项目)。

2014九月15

Cron:表达式在线验证工具

/cron/

 

QQ截图20140915153751

 

Java 解析Cron表达式,计算执行时间源码:

    @At
    @Ok("raw")
    public String getCron(@Param("exp") String exp,HttpServletResponse response) {
        response.setHeader("Content-Type", "text/javascript");//设置跨越访问 $.getScript()
        List<String> list = new ArrayList<String>();
        try {
            exp= URLDecoder.decode(Strings.sNull(exp),"utf-8");
            log.info(exp);
            CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
            cronTriggerImpl.setCronExpression(exp);
            Calendar calendar = Calendar.getInstance();
            Date now = calendar.getTime();
            calendar.add(Calendar.MONTH, 1);//把统计的区间段
            List<Date> dates = TriggerUtils.computeFireTimesBetween(cronTriggerImpl, null, now, calendar.getTime());//这个是重点
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (int i = 0; i < dates.size(); i++) {
                if (i > 9) {//这个是提示的日期个数
                    break;
                }
                list.add(dateFormat.format(dates.get(i)));
            }
        } catch (Exception e) {
        }
        return "var data="+ Json.toJson(list);
    }