编程语言
首页 > 编程语言> > java-Calendar使用

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,format,simpleDateFormat,使用,new,Calendar,calendar,sim
来源: https://www.cnblogs.com/kltsee/p/16034049.html