激光推送样例

激光推送

public class JpushClientUtil {
    private static final Logger log = LoggerFactory.getLogger(JpushClientUtil.class);
    private final static String appKey = "42915a1c8f8cfe1f06f1e439";
    private final static String masterSecret = "d31f9ca1b426f976ceba6f6f";
    private static JPushClient jPushClient = new JPushClient(masterSecret, appKey);


    /**
     * 发送给所有安卓用户
     *
     * @param notification_title 通知内容标题
     * @param msg_title          消息内容标题
     * @param msg_content        消息内容
     * @param extrasparam        扩展字段
     * @return 0推送失败,1推送成功
     */
    public static int sendToAllAndroid(String notification_title, String msg_title, String msg_content, String extrasparam, String cid) {
        int result = 0;
        try {
            PushPayload pushPayload = JpushClientUtil.buildPushObject_android_all_alertWithTitle(notification_title, msg_title, msg_content, extrasparam, cid);
            System.out.println("推送参数:" + pushPayload);
            PushResult pushResult = jPushClient.sendPush(pushPayload);
            System.out.println("推送结果:" + pushResult);
            if (pushResult.getResponseCode() == 200) {
                result = 1;
            }
        } catch (Exception e) {

            e.printStackTrace();
        }

        return result;
    }

    /**
     * 生产发送条件
     *
     * @param notification_title
     * @param msg_title
     * @param msg_content
     * @param extrasparam
     * @param cid
     * @return
     */
    private static PushPayload buildPushObject_android_all_alertWithTitle(String notification_title, String msg_title, String msg_content, String extrasparam, String cid) {
        log.info("构建推送参数,如推荐平台,接收对象");
        //具体参看接口文档
        //https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/
        List list = new ArrayList();
         Audience.tag(list);
//          Audience audience = Audience.alias("112201","112202");//别名推送
//         Audience audience = Audience.tag("tag1");
//        Audience audience = Audience.all();
         Audience audience = Audience.registrationId("140fe1da9e369dfdd2a", "140fe1da9e369dfdd2a");
//        Audience audience = Audience.segment("c8f2fff736");
        return PushPayload.newBuilder()
                //指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台
                .setPlatform(Platform.android())
                //设置发送消息id
                //  .setCid(cid)
                //指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration id
                .setAudience(audience)
                // .setAudience(Audience.tag(list))
                //jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
                .setNotification(Notification.newBuilder()
                        //指定当前推送的android通知
                        .addPlatformNotification(AndroidNotification.newBuilder()
                                .setAlert(notification_title)
//                                .setTitle(notification_title)
//                                .setTitle(msg_content)
                                .setInbox(msg_content)
                                //此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
                                .addExtra("androidNotification extras key", extrasparam)
                                .build())
                        .build()
                )
                //Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
                // sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
                // [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg_content)
                        .setTitle(msg_title)
                        .addExtra("message extras key", extrasparam)
                        .build())

                .setOptions(Options.newBuilder()
                        //此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
                        .setApnsProduction(false)
                        //此字段是给开发者自己给推送编号,方便推送者分辨推送记录
                        .setSendno(1)
                        //此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒
                        .setTimeToLive(86400)
                        .build())
                .build();
    }

    /**
     * 发送测试
     *
     * @param args
     */
//    public static void main(String[] args) {
        String num = "-0405-别名";
        String notification_title = "推送测试-通知标题" + num;
        String msg_title = "我是王召" + num;
        String msg_content = "我是内容" + num;
        String extrasparam = "我是扩展的json" + num;
//        String notification_title = "永红煤矿"+",21避难所qwewqeqw"+",模拟量"+",32%"+",韦尔奇二群二群无 任务全二二请问请问";
//        String msg_title = "瓦斯报警";
//        String msg_content = "瓦斯报警";
//        String extrasparam = "11111";
//        String cid = String.valueOf(System.currentTimeMillis());
//        int i = JpushClientUtil.sendToAllAndroid(notification_title, msg_title, msg_content, extrasparam, cid);
//        System.out.println("i=" + i);
//    }

poi导出

 //下井人员月报表导出
    @RequestMapping("/DownPersonnelMouth/export")
    public void exportdaily(CspLocmonthdata cspLocmonthdata, HttpServletResponse response){
        if ("请选择煤矿".equals(cspLocmonthdata.getCsMineShortname())){
            cspLocmonthdata.setCsMineShortname("");
        }else {
            cspLocmonthdata.setName(cspLocmonthdata.getCsMineShortname());
        }
        List<CspLocmonthdata> list = cspLocmonthdataService.findList(cspLocmonthdata);
        String fileName="下井人员月报表";
        InputStream in=null;
        XSSFWorkbook xss1=null;
        try {
            in = new FileInputStream(sunnyitProperties.getFileUploadPath()+fileName+".xlsx");
            xss1= new XSSFWorkbook(in);
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(in!=null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        XSSFSheet sheet = xss1.getSheetAt(0);
        //对前端状况不做判断
        //设置第一行
        handlerTitle1(cspLocmonthdata.getUpdatetime(),
                StringUtils.isNotEmpty(cspLocmonthdata.getName())?cspLocmonthdata.getName():""
                ,sheet);
        //设置第二行
//        handlerNeck1(handlerDate1("0",dbfnAqbjtodayrep.getCsDataTime()),
//                handlerDate1("1",dbfnAqbjtodayrep.getCsDataTime()),sheet);
        //设置第三行
//        handlerThird1(dbfnAqbjtodayrep.getCsDataTime(),sheet);
        XSSFCellStyle cellStyle1 = xss1.createCellStyle();
        setStyle1(cellStyle1);
        //数据处理
        handlerData1(list,sheet,cspLocmonthdata.getUpdatetime(),cellStyle1,xss1);
        //文件名称
        String xlsxName=fileName+ DateUtils.getDate("yyyyMMddHHmmss");
        //返回给浏览器下载
        ServletOutputStream sout=null;
        BufferedOutputStream buffOut=null;
        try {
            sout = responseConfigure1(response, xlsxName);
            buffOut = new BufferedOutputStream(sout);
            xss1.write(buffOut);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(buffOut!=null){
                try {
                    buffOut.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(xss1!=null){
                try {
                    xss1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 设置样式
     * @param cellStyle1
     */
    public void setStyle1(XSSFCellStyle cellStyle1){
        //边框样式
        cellStyle1.setBorderBottom(BorderStyle.THIN);
        cellStyle1.setBorderTop(BorderStyle.THIN);
        cellStyle1.setBorderLeft(BorderStyle.THIN);
        cellStyle1.setBorderRight(BorderStyle.THIN);
        //垂直居中对其
        cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
        cellStyle1.setAlignment(HorizontalAlignment.CENTER);
        //指定单元格自动换行
        //cellStyle.setWrapText(true);
    }
    /**
     *  设置第一行
     * @param date 日期
     * @param name 煤矿名称
     * @param sheet
     */
    public void handlerTitle1(String date, String name, Sheet sheet){
        Row headRow = sheet.getRow(0);
        Cell headCell = headRow.getCell(0);
        String headValue = headCell.getStringCellValue();
        String headFormat = String.format(headValue, date, name);
        headCell.setCellValue(headFormat);
    }

    /**
     *  设置第二行
     * @param date1 查询时间
     * @param date2 时间段
     * @param sheet
     */
    public void handlerNeck1(String date1,String date2,Sheet sheet){
        Row neckRow = sheet.getRow(1);
        //获取第一个
        String neckValue1 = neckRow.getCell(0).getStringCellValue();
        String neckFormat1 = String.format(neckValue1, date1);
        neckRow.getCell(0).setCellValue(neckFormat1);
        //获取第二个
        String neckValue2 = neckRow.getCell(13).getStringCellValue();
        String neckFormat2 = String.format(neckValue2, date2);
        neckRow.getCell(13).setCellValue(neckFormat2);
    }

    /**
     * 设置第三行
     * @param date
     * @param sheet
     * @return
     **/
    public void handlerThird1(String date,Sheet sheet){
        Row row = sheet.getRow(2);
        int days = Integer.parseInt(handlerDate1("2", date))+4;
        for (int i =32; i <days; i++) {
            Cell cell = row.getCell(i);
            String format = String.format(cell.getStringCellValue(),String.valueOf(i-3));
            cell.setCellValue(format);
        }
        for (int i = days; i <35; i++) {
            Cell cell = row.getCell(i);
            String format = String.format(cell.getStringCellValue(),"");
            cell.setCellValue(format);
        }
    }

    /**
     *
     * @param type 模式 0当前时间 1 时间段处理
     * @param csDataTime 查询时间 yyyy-MM  不做二次校验
     */
    public String handlerDate1(String type,String csDataTime){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime now = LocalDateTime.now();
        if("0".equals(type)){
            return now.format(formatter);
        }
        if("1".equals(type)){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Calendar todayStart = Calendar.getInstance();
            todayStart.set(Calendar.HOUR_OF_DAY, 0);
            todayStart.set(Calendar.MINUTE, 0);
            todayStart.set(Calendar.SECOND, 0);
            todayStart.set(Calendar.MILLISECOND, 0);
            String startTime = sdf.format(todayStart.getTime());
            Calendar todayEnd = Calendar.getInstance();
            todayEnd.set(Calendar.HOUR_OF_DAY, 23);
            todayEnd.set(Calendar.MINUTE, 59);
            todayEnd.set(Calendar.SECOND, 59);
            todayEnd.set(Calendar.MILLISECOND, 999);
            String endTime = sdf.format(todayEnd.getTime());
            return startTime+"-"+endTime;
        }
        if("2".equals(type)){
//            LocalDate monthDate = LocalDate.parse(csDataTime+"-01", monthFormatter);
            return "24";
        }
        return null;
    }

    /**
     *
     * @param response 响应体
     * @param wjName 文件名
     * @return
     * @throws IOException
     */
    public static ServletOutputStream responseConfigure1(HttpServletResponse response, String wjName) throws IOException {
        //设置response参数,可以打开下载页面
        response.reset();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + new String((wjName + ".xlsx").getBytes(), "iso-8859-1"));
        return response.getOutputStream();
    }

    /**
     *
     * @param list 数据集
     * @param csDataTime 查询时间
     * @param cellStyle 样式
     */
    public void handlerData1(List<CspLocmonthdata> list,Sheet sheet,String csDataTime,XSSFCellStyle cellStyle,XSSFWorkbook xss){
        List<String> arrayList = new ArrayList<>();
        int num=4;
        int days = 6;
        int index=2;
        for (int i = 0; i < list.size(); i++) {
            arrayList.clear();
            arrayList.add(list.get(i).getName());
            arrayList.add(list.get(i).getMinerintimes());
            arrayList.add(list.get(i).getLeaderintimes());
            arrayList.add(list.get(i).getMinerintotaltime());
            arrayList.add(list.get(i).getLeaderintotaltime());
            arrayList.add(list.get(i).getMonthovertime());
            arrayList.add(list.get(i).getUpdatetime());
            for (int j = 0; j <days+1; j++) {
                Row row = sheet.getRow(index);
                if (row==null){
                    row=sheet.createRow(index);
                }
                Cell cell = row.createCell(j);
                cell.setCellValue(arrayList.get(j));
                cell.setCellStyle(cellStyle);
            }
            index++;
        }

        String str="总工:                 " + "科长:                 值班人员:             " + "日期:               ";
        //合并单元格
        sheet.addMergedRegion(new CellRangeAddress(index,index,0,3+num-1));
        Row row = sheet.createRow(index);
        Cell first = row.createCell(0);
        //底部字体样式
        XSSFCellStyle style = xss.createCellStyle();
        bottomStyle1(xss,style);

        first.setCellValue(str);
        first.setCellStyle(style);


    }
    public void bottomStyle1(XSSFWorkbook xss,XSSFCellStyle style){
        XSSFFont font = xss.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short)18);
        font.getCTFont().addNewB();
        style.setFont(font);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setAlignment(HorizontalAlignment.CENTER);
    }

激光推送样例

上一篇:nginx面试题腾讯,day13


下一篇:day13 – 钩子和服务