java-Calendar使用

2022/3/21 12:57:54

本文主要是介绍java-Calendar使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

    /**
     * 累计使用 上月使用  本月使用 上周使用 本周使用 本月剩余
     * @param schoolId
     * @param currPage
     * @param pageSize
     * @return
     */
    @Override
    public PageBean<KwDevicePhoneSim> listSim(Integer schoolId, Integer currPage, Integer pageSize) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.set(Calendar.DAY_OF_WEEK, 2);
        String fromDateWeek = simpleDateFormat.format(calendar.getTime());
        calendar.add(Calendar.WEEK_OF_YEAR,-1);
        String fromDateLastWeek = simpleDateFormat.format(calendar.getTime());

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setFirstDayOfWeek(Calendar.MONDAY);
        calendar2.set(Calendar.DAY_OF_WEEK, 1);
        String toDateWeek = simpleDateFormat.format(calendar2.getTime());
        calendar.add(Calendar.WEEK_OF_YEAR,-1);
        String toDateLastWeek = simpleDateFormat.format(calendar2.getTime());

        Calendar calendar3 = Calendar.getInstance();
        calendar3.setTime(new Date());
        calendar3.set(Calendar.DAY_OF_MONTH, 0);
        String toDateLastMoth = simpleDateFormat.format(calendar3.getTime());

        Calendar calendar4 = Calendar.getInstance();
        calendar4.setTime(new Date());
        calendar4.set(Calendar.DAY_OF_MONTH, 1);
        calendar4.add(Calendar.MONTH,-1);
        String fromDateLastMonth = simpleDateFormat.format(calendar4.getTime());

        //这个月的第一天
        Calendar calendar5 = Calendar.getInstance();
        calendar5.setTime(new Date());
        calendar5.set(Calendar.DAY_OF_MONTH, 1);
        String fromDateMonth = simpleDateFormat.format(calendar5.getTime());

        String toDateMonth = simpleDateFormat.format(new Date());

        PageHelper.startPage(currPage, pageSize);
        List<KwDevicePhoneSim> phoneSimList = baseMapper.selectList(new QueryWrapper<KwDevicePhoneSim>().eq("school_id", schoolId));
        PageBean<KwDevicePhoneSim> pageBean = new PageBean<>(phoneSimList);
        List<KwDevicePhoneSim> list = pageBean.getList();
        for (KwDevicePhoneSim sim : list) {
            int allDur = getCallDuration(sim.getSimNumber(), null, null, false);//所有时间
            int weekDur = getCallDuration(sim.getSimNumber(), fromDateWeek, toDateWeek, true);//当前星期
            int lastWeekDur = getCallDuration(sim.getSimNumber(), fromDateLastWeek, toDateLastWeek, false);//上星期
            int monthDur = getCallDuration(sim.getSimNumber(), fromDateMonth, toDateMonth, true);//当前月
            int lastMonthDur = getCallDuration(sim.getSimNumber(), fromDateLastMonth, toDateLastMoth, false);//上个月
            sim.setAllDur(allDur).setWeekDur(weekDur).setLastWeekDur(lastWeekDur).setMonthDur(monthDur).setLastMonthDur(lastMonthDur);
            sim.setRemaim(sim.getPackages()*60 - monthDur);
           List<KwAttendanceDevice> device = deviceMapper.selectList(new QueryWrapper<KwAttendanceDevice>().eq("sim_id", sim.getId()).eq("school_id", schoolId));
            if (device.size()>0){
                sim.setDeviceNo(device.get(0).getDeviceNo());
                sim.setLocation(device.get(0).getLocation());
            }
        }
        return pageBean;
    }



这篇关于java-Calendar使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程