天翎MyApps技术社区 - 低代码平台 | 流程管理系统 | BPM软件

 找回密码
 注册成为天翎用户
查看: 2079|回复: 0

[源码] 获取相隔工作的分钟数【函数—取具体工作分钟】

[复制链接]
echochen 发表于 2013-12-4 18:07:18 | 显示全部楼层 |阅读模式
本帖最后由 echochen 于 2013-12-4 18:08 编辑

Q:平台有没有封装好的函数去获取工作分钟数????
A:类似具体做法您可以在CalendarProcessBean类下添加一个方法,类似如下图所示:
111.jpg
该方式具体的代码如下:

  1. public double countTimesOfWorkingDayskimi(Date startDate, Date endDate, String calendar) throws Exception {
  2.                 double count = 0;
  3.                 CalendarVO vo = (CalendarVO) doView(calendar);
  4.                 boolean isNegative = false;

  5.                 if (endDate != null && startDate != null) {
  6.                        
  7.                         //***************限制计算时间的年份为当前年份的前后10年start*******************
  8.                         Calendar start = Calendar.getInstance();
  9.                         start.setTime(new Date());
  10.                         start.add(Calendar.YEAR, -10);
  11.                         Date pre = start.getTime();
  12.                         start.add(Calendar.YEAR, 20);
  13.                         Date after = start.getTime();
  14.                         if(startDate.before(pre) || startDate.after(after) ||
  15.                                         endDate.before(pre) || endDate.after(after)){
  16.                                 //startDate或endDate任意一个小于当前年份的前10年  或者 大于当前年份的后10年
  17.                                 return 0.00;
  18.                         }
  19.                         //****************限制计算时间的年份为当前年份的前后10年end******************
  20.                        
  21.                         if (startDate.compareTo(endDate) == 1) {
  22.                                 isNegative = true;
  23.                                 Date temp = startDate;
  24.                                 startDate = endDate;
  25.                                 endDate = temp;
  26.                         }

  27.                         Date currDate = startDate;                               
  28.                        
  29.                         // 处理开始日期剩余时间
  30.                         boolean isStart = true;
  31.                         while (currDate.compareTo(endDate) <= 0) {
  32.                                
  33.                                 DayPart dayPart = vo.findDayPart(currDate);
  34.                                
  35.                                 if (dayPart != null) {
  36.                                         Calendar cald = Calendar.getInstance();
  37.                                         cald.setTime(currDate);
  38.                                         cald.set(Calendar.HOUR_OF_DAY, dayPart.getToHour());
  39.                                         cald.set(Calendar.MINUTE, dayPart.getToMinute());
  40.                                         boolean flag = cald.getTime().compareTo(endDate) <= 0;
  41.                                        
  42.                                         if (flag) {
  43.                                                 count += dayPart.getRemainingMinutes(currDate);
  44.                                         } else if (dayPart.includes(currDate)) {
  45.                                                 // 处理结束日期剩余时间
  46.                                                 Calendar cald2 = Calendar.getInstance();
  47.                                                 cald2.setTime(endDate);
  48.                                                 int fromHour = cald2.get(Calendar.HOUR_OF_DAY);
  49.                                                 int fromMinute = cald2.get(Calendar.MINUTE);
  50.                                                 int toHour = dayPart.getFromHour();
  51.                                                 int toMinute = dayPart.getFromMinute();
  52.                                                 if (isStart) {
  53.                                                         cald2 = Calendar.getInstance();
  54.                                                         cald2.setTime(startDate);
  55.                                                         toHour = cald2.get(Calendar.HOUR_OF_DAY);
  56.                                                         toMinute = cald2.get(Calendar.MINUTE);
  57.                                                         isStart = false;
  58.                                                 }
  59.                                                 count += (fromHour - toHour) * 60 + (fromMinute - toMinute);
  60.                                         }
  61.                                 }
  62.                                 isStart = false;       
  63.                                 currDate = vo.findNextStartDate(currDate);
  64.                         }
  65.                 }

  66.                 count = Math.round(count * 100.0) / 100.0 ;

  67.                 if (isNegative)
  68.                         return -count;

  69.                 return count;
  70.         }
复制代码
添加完成后再平台调用代码如下:
  1. var starttime =getItemValueAsDate("开始日期");
  2. var endtime =getItemValueAsDate("结束日期");
  3. var calendarid ="11e3-251f-5b633995-a1e5-f3a8d2f87a7b";
  4. var cprocess=new Packages.cn.myapps.core.workcalendar.calendar.ejb.CalendarProcessBean();
  5. var rtn=0;
  6. println(starttime+"  =====starttime=="+endtime+"    =====endtime=");
  7. if(starttime!=null && endtime!=null){      
  8.       rtn=cprocess.countTimesOfWorkingDayskimi(starttime,endtime,calendarid);
  9. }
  10. rtn;
复制代码
效果图请查看图:
1.jpg


对应帖子链接:http://www.teemlink.com/bbs/view ... %26amp%3Btypeid%3D2

本版积分规则

QQ|手机版|天翎MyApps技术社区 ( 粤ICP备11093750号 )

GMT+8, 2026-8-12 15:47

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表