| | |
| | | |
| | | import java.io.IOException; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Map.Entry; |
| | | import java.util.function.Function; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceBusinessTravel; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceBusinessTravelDto; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.project.repository.ProjectRepository; |
| | | import me.zhengjie.modules.system.domain.SysConfigProportion; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final TaskDaliyRepository taskDaliyRepository; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final ProjectPerformanceDetailRepository projectPerformanceDetailRepository; |
| | | private final ProjectRepository projectRepository; |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(ProjectPerformanceQueryCriteria criteria, Pageable pageable){ |
| | | Page<ProjectPerformance> page = projectPerformanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | return PageUtil.toPage(page.map(projectPerformanceMapper::toDto)); |
| | | //将实体转换为Dto(重写) |
| | | Function<ProjectPerformance, ProjectPerformanceDto> func = new Function<ProjectPerformance, ProjectPerformanceDto>(){ |
| | | |
| | | @Override |
| | | public ProjectPerformanceDto apply(ProjectPerformance projectPerformance) { |
| | | // 将实体类转换成DTO |
| | | ProjectPerformanceDto projectPerformanceDto = projectPerformanceMapper.toDto(projectPerformance); |
| | | //查询项目名称 |
| | | Project project = projectRepository.findById(projectPerformanceDto.getProjectId()).orElseGet(Project::new); |
| | | projectPerformanceDto.setProjectName(project.getName()); |
| | | return projectPerformanceDto; |
| | | } |
| | | }; |
| | | return PageUtil.toPage(page.map(func)); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ProjectPerformanceDto create(ProjectPerformance resources) { |
| | | |
| | | List<TaskDailyInterface> taskDailyInterfaceList = taskDaliyRepository.collectCostByProjectIdAndFillDateLessThanGroupUserAndTaskId(resources.getProjectId(), resources.getEndDate()); |
| | | Map<Long, Double> userPerformanceMap = new HashMap<Long, Double>(); |
| | | for (TaskDailyInterface taskDailyInterface : taskDailyInterfaceList) { |
| | | TaskUser taskUser = taskUserRepository.findByTaskIdAndTaskInnerIdAndUserId(taskDailyInterface.getTaskId(), taskDailyInterface.getTaskInnerId(), taskDailyInterface.getUserId()); |
| | | userPerformanceMap.put(taskDailyInterface.getUserId(), userPerformanceMap.getOrDefault(taskDailyInterface.getUserId(), 0.0) + (taskUser.getTaskHours() * taskDailyInterface.getTaskProgress() / 100)); |
| | | } |
| | | |
| | | // 绩效登录 |
| | | projectPerformanceRepository.save(resources); |
| | | |
| | | for (Entry<Long, Double> entry : userPerformanceMap.entrySet()) { |
| | | |
| | | ProjectPerformanceDetail projectPerformanceDetailLast = |
| | | projectPerformanceDetailRepository.findByProjectIdAndUserIdAndYearMonthLessThan(resources.getProjectId(), entry.getKey(), resources.getYearMonth()).orElseGet(ProjectPerformanceDetail::new); |
| | | |
| | | ProjectPerformanceDetail projectPerformanceDetail = new ProjectPerformanceDetail(); |
| | | |
| | | projectPerformanceDetail.setProjectId(resources.getProjectId()); |
| | | projectPerformanceDetail.setYearMonth(resources.getYearMonth()); |
| | | projectPerformanceDetail.setUserId(entry.getKey()); |
| | | |
| | | if (projectPerformanceDetailLast.getPerformanceHours() == null) { |
| | | projectPerformanceDetail.setPerformanceHours(entry.getValue()); |
| | | } else { |
| | | projectPerformanceDetail.setPerformanceHours(entry.getValue() - projectPerformanceDetailLast.getPerformanceHours()); |
| | | } |
| | | |
| | | projectPerformanceDetailRepository.save(projectPerformanceDetail); |
| | | } |
| | | |
| | | return projectPerformanceMapper.toDto(projectPerformanceRepository.save(resources)); |
| | | } |
| | | |
| | | // @Override |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | // public ProjectPerformanceDto create(ProjectPerformance resources) { |
| | | // |
| | | // List<TaskDailyInterface> taskDailyInterfaceList = taskDaliyRepository.collectCostByProjectIdAndFillDateBetweenGroupUserAndTaskId(resources.getProjectId(), resources.getStartDate(), resources.getEndDate()); |
| | | // Map<Long, Double> userPerformanceMap = new HashMap<Long, Double>(); |
| | | // for (TaskDailyInterface taskDailyInterface : taskDailyInterfaceList) { |
| | | // TaskUser taskUser = taskUserRepository.findByTaskIdAndUserId(taskDailyInterface.getTaskId(), taskDailyInterface.getUserId()); |
| | | // userPerformanceMap.put(taskDailyInterface.getUserId(), userPerformanceMap.getOrDefault(taskDailyInterface.getUserId(), 0.0) + (taskUser.getTaskHours() * taskDailyInterface.getTaskProgress() / 100)); |
| | | // } |
| | | // |
| | | // DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | // |
| | | // ProjectPerformance projectPerformance = new ProjectPerformance(); |
| | | // projectPerformance.setProjectId(resources.getProjectId()); |
| | | // |
| | | // projectPerformance.setStartDate(resources.getStartDate()); |
| | | // projectPerformance.setEndDate(resources.getEndDate()); |
| | | // |
| | | // projectPerformance.setYearMonth(resources.getYearMonth()); |
| | | // projectPerformanceRepository.save(projectPerformance); |
| | | // |
| | | // for (Entry<Long, Double> entry : userPerformanceMap.entrySet()) { |
| | | // |
| | | // ProjectPerformanceDetail projectPerformanceDetailLast = |
| | | // projectPerformanceDetailRepository.findByProjectIdAndUserIdAndYearMonth(resources.getProjectId(), entry.getKey(), resources.getYearMonth()).orElse(ProjectPerformanceDetail::new); |
| | | // |
| | | // ProjectPerformanceDetail projectPerformanceDetail = new ProjectPerformanceDetail(); |
| | | // |
| | | // projectPerformanceDetail.setProjectId(resources.getProjectId()); |
| | | // projectPerformanceDetail.setYearMonth(projectPerformance.getYearMonth()); |
| | | // projectPerformanceDetail.setUserId(entry.getKey()); |
| | | // |
| | | // if (projectPerformanceDetailLast.getPerformanceHours() == null) { |
| | | // projectPerformanceDetail.setPerformanceHours(entry.getValue()); |
| | | // } else { |
| | | // projectPerformanceDetail.setPerformanceHours(entry.getValue() - projectPerformanceDetailLast.getPerformanceHours()); |
| | | // } |
| | | // |
| | | // projectPerformanceDetailRepository.save(projectPerformanceDetail); |
| | | // } |
| | | // |
| | | // return projectPerformanceMapper.toDto(projectPerformanceRepository.save(resources)); |
| | | // } |
| | | |
| | | // public Double queryComplianceWork(Long userId, String yearMonth) { |
| | | // // 已达标工时 |
| | | // Double complianceWork = 0D; |
| | | // |
| | | // List<ProjectPerformanceDetail> projectPerformanceDetailList = projectPerformanceDetailRepository.findByUserIdAndYearMonth(userId, yearMonth); |
| | | // for (ProjectPerformanceDetail projectPerformanceDetail : projectPerformanceDetailList) { |
| | | // complianceWork += projectPerformanceDetail.getPerformanceHours(); |
| | | // } |
| | | // return complianceWork; |
| | | // } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | @Override |
| | | public void download(List<ProjectPerformanceDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm"); |
| | | for (ProjectPerformanceDto projectPerformance : all) { |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("项目ID", projectPerformance.getProjectId()); |
| | | map.put("结算开始日", projectPerformance.getStartDate()); |
| | | map.put("结算终了日", projectPerformance.getEndDate()); |
| | | map.put("绩效年月", projectPerformance.getYearMonth()); |
| | | Project project = projectRepository.findById(projectPerformance.getProjectId()).orElseGet(Project::new); |
| | | map.put("项目", project.getName()); |
| | | map.put("结算开始日", (df.format(projectPerformance.getStartDate())).substring(0,10)); |
| | | map.put("结算终了日", (df.format(projectPerformance.getEndDate())).substring(0,10)); |
| | | map.put("绩效年月", (df.format(projectPerformance.getYearMonth())).substring(0,7)); |
| | | map.put("创建者", projectPerformance.getCreateBy()); |
| | | map.put("创建时间", projectPerformance.getCreateTime()); |
| | | map.put("更新者", projectPerformance.getUpdateBy()); |