| | |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | |
| | | import java.util.Map.Entry; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | |
| | | import me.zhengjie.modules.system.repository.SysUserLevelInsuranceRepository; |
| | | import me.zhengjie.modules.system.repository.SysUserLevelWageRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.RoleService; |
| | | import me.zhengjie.modules.system.service.UserService; |
| | | import me.zhengjie.modules.system.service.dto.RoleSmallDto; |
| | | import me.zhengjie.modules.system.service.dto.SysRosteringDto; |
| | | import me.zhengjie.modules.system.service.dto.UserDto; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.enums.DataScopeEnum; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | private final SysUserLevelInsuranceRepository sysUserLevelInsuranceRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final UserService userService; |
| | | private final RoleService roleService; |
| | | |
| | | private final SysLevelRepository sysLevelRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(ProjectCostQueryCriteria criteria, Pageable pageable){ |
| | | public Map<String,Object> queryAll(ProjectCostQueryCriteria criteria, Pageable pageable) { |
| | | // 获取当前用户ID |
| | | Long userId = SecurityUtils.getCurrentUserId(); |
| | | // 查询用户角色 |
| | | List<RoleSmallDto> roleSet = roleService.findByUsersId(userId); |
| | | if (roleSet.stream().anyMatch(role -> DataScopeEnum.find(role.getDataScope()) == DataScopeEnum.THIS_LEVEL)) { |
| | | // 根据用户ID查询负责的项目ID |
| | | List<Long> projectIdList = projectRepository.findIdByLiableUserId(userId); |
| | | // 根据用户ID查询参与的项目ID |
| | | List<Long> taskUserProjectIdList = projectCostRepository.findProjectIdByUserId(userId); |
| | | // 检索条件 |
| | | List<Long> totalProjectIdList = Stream.of(taskUserProjectIdList, projectIdList).flatMap(Collection::stream).distinct().collect(Collectors.toList()); |
| | | if (totalProjectIdList.size() == 0) { |
| | | return PageUtil.toPage(Collections.emptyList(), 0); |
| | | } |
| | | criteria.setProjectIdList(totalProjectIdList); |
| | | } |
| | | |
| | | Page<ProjectCost> page = projectCostRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<ProjectCost, ProjectCostDto> func = new Function<ProjectCost, ProjectCostDto>() { |
| | |
| | | // 工资 |
| | | BigDecimal wageCost = BigDecimal.valueOf(0); |
| | | // 工作天数 |
| | | LocalDateTime enterProject = LocalDateTime.parse(criteria.getEnterProjectTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | LocalDateTime exitProject = LocalDateTime.parse(criteria.getExitProjectTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | LocalDateTime enterProject = criteria.getEnterProjectTime().toLocalDateTime(); |
| | | LocalDateTime exitProject = criteria.getExitProjectTime().toLocalDateTime(); |
| | | |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | Date startDate = simpleDateFormat.parse(criteria.getEnterProjectTime()); |
| | | Date endDate = simpleDateFormat.parse(criteria.getExitProjectTime()); |
| | | Date startDate = criteria.getEnterProjectTime(); |
| | | Date endDate = criteria.getExitProjectTime(); |
| | | |
| | | |
| | | // 通过id获取用户信息 |
| | |
| | | throw new BadRequestException("此用户暂无级别保险"); |
| | | } |
| | | |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(simpleDateFormat.parse(criteria.getEnterProjectTime()), simpleDateFormat.parse(criteria.getExitProjectTime())); |
| | | List<SysConfigHoliday> sysConfigHolidayList = sysConfigHolidayRepository.findByHolidayDateBetween(criteria.getEnterProjectTime(), criteria.getExitProjectTime()); |
| | | |
| | | Map<Long, Double> sysUserLevelWageHoursMap = new HashMap<Long, Double>(); |
| | | for (SysUserLevelWage sysUserLevelWage : sysUserLevelWages) { |
| | |
| | | Double costHours = 0.0; |
| | | SysRosteringDto sysRostering = user.getSysRostering(); |
| | | |
| | | if (currentLocalDate.isEqual(enterProject.toLocalDate())) { |
| | | if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) <= 0) { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } else if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) <= 0) { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } else if (enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) { |
| | | if (enterProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) < 0) { |
| | | enterProject = enterProject.with(sysRostering.getLunchEndTime()); |
| | | } |
| | | costHours = costHours + enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS); |
| | | } |
| | | } else if (currentLocalDate.isEqual(exitProject.toLocalDate())) { |
| | | if (currentLocalDate.isEqual(exitProject.toLocalDate())) { |
| | | if (exitProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && exitProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) <= 0) { |
| | | if (exitProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0) { |
| | | exitProject = exitProject.with(sysRostering.getLunchStartTime()); |
| | |
| | | } else if (exitProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) >= 0) { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |
| | | } else if (currentLocalDate.isEqual(enterProject.toLocalDate())) { |
| | | if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) <= 0) { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } else if (enterProject.toLocalTime().compareTo(sysRostering.getWorkStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) <= 0) { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + enterProject.toLocalTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } else if (enterProject.toLocalTime().compareTo(sysRostering.getLunchStartTime()) > 0 && enterProject.toLocalTime().compareTo(sysRostering.getWorkEndTime()) < 0) { |
| | | if (enterProject.toLocalTime().compareTo(sysRostering.getLunchEndTime()) < 0) { |
| | | enterProject = enterProject.with(sysRostering.getLunchEndTime()); |
| | | } |
| | | costHours = costHours + enterProject.toLocalTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS); |
| | | } |
| | | } else { |
| | | costHours = costHours + sysRostering.getLunchEndTime().until(sysRostering.getWorkEndTime(), ChronoUnit.HOURS) + sysRostering.getWorkStartTime().until(sysRostering.getLunchStartTime(), ChronoUnit.HOURS); |
| | | } |