提交 395e18fc authored 作者: gongwenjie's avatar gongwenjie

考勤

上级 4dfb343a
......@@ -191,129 +191,85 @@ public class ApprovalInformationServiceImpl implements ApprovalInformationServic
/**
* 计算调休时长
*/
private Long computeTime(Date startTime,Date endTime){
private Long computeTime(Date startTime,Date endTime) throws Exception{
Config config = configDao.findAll().get(0);
String workTime = config.getWorkTime();//上班时间
String afterWorkTime = config.getAfterWorkTime();//下班时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
String format = sdf2.format(startTime);
try {
Date parse = sdf2.parse(format);
List<Day> days = dayDao.findAllByStatusAndDateBetween("0", parse, endTime);
long hours = 0;
if(days!=null){
for (Day day : days) {
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd "+workTime);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd " + afterWorkTime);
Calendar calendar = Calendar.getInstance();
Calendar calendar1 = Calendar.getInstance();
String format = sdf.format(startTime);
Date parse = sdf.parse(format);
String format1 = sdf2.format(startTime);
Date parse1 = sdf2.parse(format1);
calendar1.setTime(parse1);
calendar.setTime(parse);//设置上班时间
String format2 = sdf3.format(startTime);
String format3 = sdf3.format(endTime);
long hours = 0;
long hour = 60 * 1000 * 60;
if(startTime.before(calendar.getTime())){
if(format2.equals(format3)){
Date leaveWork = calendar1.getTime();
if(endTime.before(leaveWork)){
long miSecond = endTime.getTime() - calendar.getTime().getTime();
if(miSecond%hour==0){
hours = miSecond / hour;
}else{
hours = miSecond / hour + 1;
}
}else{
hours = 8;
}
}else{
hours = 8;
while (true){
calendar.add(Calendar.DATE,1);
calendar1.add(Calendar.DATE,1);
Date leaveWork = calendar1.getTime();
Date startWorkTime = calendar.getTime();
if(endTime.before(startWorkTime)){
return hours;
}else{
if(endTime.before(leaveWork)){
long miSecond = endTime.getTime() - calendar.getTime().getTime();
if(miSecond%hour==0){
hours = miSecond / hour + hours;
}else{
hours = miSecond / hour + 1 + hours;
}
}else{
hours += 8;
}
}
}
}
}else{
if(format2.equals(format3)){
Date leaveWork = calendar1.getTime();
if(endTime.before(leaveWork)){
long miSecond = endTime.getTime() - startTime.getTime();
if(miSecond%hour==0){
hours = miSecond / hour;
}else{
hours = miSecond / hour + 1;
}
}else{
long miSecond = leaveWork.getTime() - startTime.getTime();
if(miSecond%hour==0){
hours = miSecond / hour;
}else{
hours = miSecond / hour + 1;
}
}
}
} catch (ParseException e) {
e.printStackTrace();
}
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
// Config config = configDao.findAll().get(0);
// SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd "+config.getWorkTime());
// SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd "+config.getAfterWorkTime());
// String format = sdf.format(startTime);
// try {
// Calendar calendar = Calendar.getInstance();
// Date parse1 = sdf2.parse(format);//该天的上班时间
// Date parse2 = sdf3.parse(format);
// Date parse = sdf.parse(format);
// Day day = dayDao.findByDate(parse);
// String status = day.getStatus();
// long hours = 0;
//
// while(true){
// if(parse1.before(startTime)){
// if(endTime.before(parse2)){
// Long time = endTime.getTime() - startTime.getTime();
// long hour = 1000*60*60;
// if(time%hour==0){
// hours = time/hour;
// }else{
// hours = time/hour + 1;
// }
// }else{
//
// }
// }
// }
//
//
//
//
// //判断该天是否是工作日
// if(status.equals("0")) {
// if(parse1.before(startTime)){
// if(endTime.before(parse2)){
// Long time = endTime.getTime() - startTime.getTime();
// long hour = 1000*60*60;
// if(time%hour==0){
// hours = time/hour;
// }else{
// hours = time/hour + 1;
// }
// }else{
// calendar.setTime(parse1);
// calendar.add(Calendar.DATE,1);
// Date time = calendar.getTime();
// Day day1 = dayDao.findByDate(time);
// if(day1.getStatus().equals("0")){
//
// }
// }
// }
// }else{
// calendar.setTime(parse1);
// calendar.add(Calendar.DATE,1);
// Date time = calendar.getTime();
// calendar.setTime(parse2);
// calendar.add(Calendar.DATE,1);
// Date time1 = calendar.getTime();
// Day day1 = dayDao.findByDate(time);
// if(time.before(endTime)){
// if(endTime.before(parse2)){
//
// }
// }
// }
//
//// if(status.equals("0")){//判断该天是否是工作日
//// if(parse1.before(startTime)&&endTime.before(parse2)){
//// if(endTime.before(parse2)){
//// Long time = endTime.getTime() - startTime.getTime();
//// long hour = 1000*60*60;
//// long hours = 0;
//// if(time%hour==0){
//// hours = time/hour;
//// }else{
//// hours = time/hour + 1;
//// }
//// }else{
//// calendar.setTime(parse1);
//// calendar.add(Calendar.DATE,1);//往后一天的上班时间
//// Date time1 = calendar.getTime();
//// if(endTime.before(time1)){
//// Long time = parse2.getTime() - startTime.getTime();
//// long hour = 1000*60*60;
//// long hours = 0;
//// if(time%hour==0){
//// hours = time/hour;
//// }else{
//// hours = time/hour + 1;
//// }
//// }
//// }
////
//// }
//// }
//
//
//
// } catch (ParseException e) {
// e.printStackTrace();
// }
return null;
}
......
......@@ -576,42 +576,43 @@ public class UserServiceImpl implements IUserService {
*/
@Override
public boolean judgeParent(String id, String userId) {
List<UserRole> userRoles1 = userRoleDao.findAllByUserId(userId);
List<UserRole> userRoles2 = userRoleDao.findAllByUserId(id);
List<String> roleIds = new ArrayList<>();
List<String> roleIds2 = new ArrayList<>();
Optional<User> optional = pasUserDao.findById(userId);
boolean flag = false;
if(userRoles2!=null){
userRoles2.forEach(userRole -> roleIds.add(userRole.getRoleId()));
List<Role> roles = roleDao.findAllByIdIn(roleIds);
List<String> departIds = new ArrayList<>();
if(roles!=null){
roles.forEach(role -> {
List<String> authorityIds = new ArrayList<>();
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(role.getId());
if(roleAuthorities!=null){
roleAuthorities.forEach(roleAuthority -> {
authorityIds.add(roleAuthority.getAuthorityId());
});
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
if(authorities!=null){
authorities.forEach(authority -> {
if(authority.getName().equals("修改任务")){
departIds.add(role.getDepartmentId());
}
if(optional.isPresent()){
User user = optional.get();
List<String> departmentIdList = user.getDepartmentIds();
List<UserRole> userRoles2 = userRoleDao.findAllByUserId(id);
List<String> roleIds = new ArrayList<>();
List<String> roleIds2 = new ArrayList<>();
if(userRoles2!=null){
userRoles2.forEach(userRole -> roleIds.add(userRole.getRoleId()));
List<Role> roles = roleDao.findAllByIdIn(roleIds);
List<String> departIds = new ArrayList<>();
if(roles!=null){
roles.forEach(role -> {
List<String> authorityIds = new ArrayList<>();
List<RoleAuthority> roleAuthorities = roleAuthorityDao.findAllByRoleId(role.getId());
if(roleAuthorities!=null){
roleAuthorities.forEach(roleAuthority -> {
authorityIds.add(roleAuthority.getAuthorityId());
});
List<Authority> authorities = authorityDao.findAllByIdIn(authorityIds);
if(authorities!=null){
authorities.forEach(authority -> {
if(authority.getName().equals("修改任务")){
departIds.add(role.getDepartmentId());
}
});
}
}
}
});
}
});
}
if(userRoles1!=null){
userRoles1.forEach(userRole -> roleIds2.add(userRole.getRoleId()));
List<Role> roleList = roleDao.findAllByIdIn(roleIds2);
List<String> departmentIds = new ArrayList<>();//自身或者上级部门
roleList.forEach(role -> {
String departmentId = role.getDepartmentId();
List<String> parentDepartIds = findParentDepartIds(departmentId, new ArrayList<String>());
departmentIdList.forEach(deId -> {
List<String> parentDepartIds = findParentDepartIds(deId, new ArrayList<String>());
if(parentDepartIds!=null){
parentDepartIds.forEach(str->{
if(!departmentIds.contains(str)){
......@@ -626,8 +627,10 @@ public class UserServiceImpl implements IUserService {
flag = true;
}
}
}
}
return flag;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论