//交接班记录补算
public void handMakeup()
{
//获取当前时间
Date date = new Date();
List<ChildrenSystem> list = childrenSystemDao.getByName(null);
for(int i=0; i<list.size(); i++)
{
System.out.println(list.get(i).getId()+"----------------");
diGui(list.get(i).getId(), date);
}
}
public void diGui(Long systemId, Date date)
{
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
List<HandRecord> handRecords = getByEndTimeIsNull(systemId);
HandRecord handRecord = handRecords.get(0);
Date wtBegin = handRecord.getWtBegin();
String time = sdf.format(wtBegin);
Long systemId2 = handRecord.getSystemId();
if(systemId2 == 1L)
{
systemId2 = 0L;
}
//通过开始时间去倒班时间表中查询记录
String dutyName = dutyTimeDao.getDutyNameByStartTime(time, systemId2);
DutyTime dutyTime = dutyTimeDao.getDutyTimeByDutyName(dutyName, systemId2);
try {
if(sdf.parse(dutyTime.getStartTime()).getTime() > sdf.parse(dutyTime.getEndTime()).getTime())
{
wtBegin = new Date(wtBegin.getTime() + sdf.parse(dutyTime.getEndTime()).getTime() - sdf.parse(time).getTime()+24*60*60*1000);
}else{
wtBegin = new Date(wtBegin.getTime() + sdf.parse(dutyTime.getEndTime()).getTime() - sdf.parse(time).getTime());
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//若成立,则代表有间隔的交接班记录没有产生,应终结该条记录并产生新的记录
if(wtBegin.getTime() < date.getTime())
{
for(int i=0; i<handRecords.size(); i++)
{
HandRecord handRecord2 = handRecords.get(i);
//现将上一条记录终结
handRecord2.setWtEnd(wtBegin);
save(handRecord2);
//再产生一条新的记录
//首先确定当班班值的名字
String dutyName2 = dutyTimeDao.getDutyNameByStartTime(sdf.format(wtBegin), systemId2);
DutyTable dutyTable = dutyTableDao.getDutyTableByDate(wtBegin, systemId2);
ArrayList<String> list = new ArrayList<String>();
list.add(dutyTable.getDuty1());
list.add(dutyTable.getDuty2());
list.add(dutyTable.getDuty3());
list.add(dutyTable.getDuty4());
list.add(dutyTable.getDuty5());
list.add(dutyTable.getDuty6());
list.add(dutyTable.getDuty7());
list.add(dutyTable.getDuty8());
list.add(dutyTable.getDuty9());
//接班的班次号
int takeTeamId = 0;
for(int j=0; j<list.size();j++)
{
if(list.get(j).equals(dutyName2))
{
takeTeamId = j+1;
break;
}
}
handRecord2.setId(null);
handRecord2.setWtBegin(wtBegin);
handRecord2.setWtEnd(null);
handRecord2.setTeamId(takeTeamId);
save(handRecord2);
}
System.out.println("装备进行递归");
//进行递归
diGui( systemId, date);
}
return;
}