| | |
| | | */ |
| | | package me.zhengjie.modules.task.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import me.zhengjie.modules.project.domain.Project; |
| | | import me.zhengjie.modules.system.domain.DictDetail; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.task.domain.*; |
| | | import me.zhengjie.modules.task.repository.TaskRepository; |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyMongoDto; |
| | | import me.zhengjie.utils.*; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyDto; |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria; |
| | | import me.zhengjie.modules.task.service.mapstruct.TaskDaliyMapper; |
| | | import me.zhengjie.utils.DateUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import org.springframework.data.domain.Sort; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * @author 赵士淞 |
| | |
| | | private final ProjectRepository projectRepository; |
| | | private final UserRepository userRepository; |
| | | private final TaskUserRepository taskUserRepository; |
| | | private final TaskRepository taskRepository; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final RoleService roleService; |
| | | private final MongoTemplate mongoTemplate; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<TaskDaliyDto> queryAll(TaskDaliyQueryCriteria criteria) { |
| | | return taskDaliyMapper.toDto(taskDaliyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); |
| | | public List<TaskDaliyMongoDto> queryAll(TaskDaliyQueryCriteria criteria) { |
| | | Criteria criteriaMongo = new Criteria(); |
| | | criteriaMongo.and("userId").is(SecurityUtils.getCurrentUserId()); |
| | | |
| | | if (criteria.getTaskId() != null || criteria.getProjectId() != null || criteria.getName() != null) { |
| | | Criteria criteriaTaskUserMongo = new Criteria(); |
| | | if (criteria.getTaskMongoId() != null) { |
| | | criteriaTaskUserMongo.and("task").is(criteria.getTaskMongoId()); |
| | | } else if (criteria.getProjectId() != null) { |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(Query.query(Criteria.where("projectId").is(criteria.getProjectId())), TaskMongo.class); |
| | | criteriaTaskUserMongo.and("task").in(taskMongoList); |
| | | } |
| | | if (criteria.getName() != null) { |
| | | Pattern pattern = Pattern.compile("^.*" + criteria.getName() + ".*$", Pattern.CASE_INSENSITIVE); |
| | | criteriaTaskUserMongo.and("name").is(pattern); |
| | | } |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(Query.query(criteriaTaskUserMongo), TaskUserMongo.class); |
| | | criteriaMongo.and("taskUserMongo").in(taskUserMongoList); |
| | | } |
| | | if (criteria.getFillDates() != null) { |
| | | DateTime startTime = new DateTime(criteria.getFillDates().get(0)); |
| | | DateTime endTime = new DateTime(criteria.getFillDates().get(1)); |
| | | criteriaMongo.andOperator(Criteria.where("fillDate").gte(startTime), Criteria.where("fillDate").lte(endTime)); |
| | | } |
| | | |
| | | Query query = Query.query(criteriaMongo); |
| | | long count = mongoTemplate.count(query, TaskDaliyMongo.class); |
| | | // 如果用户的日报为空 |
| | | if (count == 0) { |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | //如果这个用户的日报不为空 |
| | | List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(query, TaskDaliyMongo.class); |
| | | List<TaskDaliyMongoDto> resultList = new ArrayList<>(); |
| | | daliyMongoList.sort((o1, o2) -> o2.getFillDate().compareTo(o1.getFillDate())); |
| | | for (TaskDaliyMongo taskDaliyMongo : daliyMongoList) { |
| | | TaskDaliyMongoDto dto = new TaskDaliyMongoDto(); |
| | | dto.setId(taskDaliyMongo.getId()); |
| | | dto.setFillDate(taskDaliyMongo.getFillDate()); |
| | | dto.setUserId(taskDaliyMongo.getUserId()); |
| | | dto.setProjectId(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId()); |
| | | dto.setTaskName(taskDaliyMongo.getTaskUserMongo().getTask().getName()); |
| | | dto.setTaskId(taskDaliyMongo.getTaskUserMongo().getTask().getId()); |
| | | dto.setConsumedHours(taskDaliyMongo.getConsumedHours()); |
| | | dto.setTaskProgress(taskDaliyMongo.getTaskProgress()); |
| | | dto.setSettlementStatus(taskDaliyMongo.getSettlementStatus()); |
| | | dto.setRemarks(taskDaliyMongo.getRemarks()); |
| | | dto.setTaskUserMongo(taskDaliyMongo.getTaskUserMongo()); |
| | | resultList.add(dto); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | |
| | | // @Override |
| | | // public void download(List<TaskDaliyDto> all, HttpServletResponse response) throws IOException { |
| | | // List<Map<String, Object>> list = new ArrayList<>(); |
| | | // for (TaskDaliyDto taskDaliy : all) { |
| | | // String projectName = taskDaliy.getProjectId() != null ? projectRepository.findById(taskDaliy.getProjectId()).orElseGet(Project::new).getName() : ""; |
| | | // String taskName = taskDaliy.getTaskId() != null ? taskRepository.findById(taskDaliy.getTaskId()).orElseGet(Task::new).getName() : ""; |
| | | // String userNickName = taskDaliy.getUserId() != null ? userRepository.findById(taskDaliy.getUserId()).orElseGet(User::new).getNickName() : ""; |
| | | // String settlementStatus = taskDaliy.getSettlementStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.SETTLEMENT_STATUS, taskDaliy.getSettlementStatus()).getLabel() : ""; |
| | | // Map<String, Object> map = new LinkedHashMap<>(); |
| | | // map.put("填写日期", taskDaliy.getFillDate()); |
| | | // map.put("项目名称", projectName); |
| | | // map.put("任务名称", taskName); |
| | | // map.put("员工姓名", userNickName); |
| | | // map.put("消耗工时", taskDaliy.getConsumedHours()); |
| | | // map.put("消耗工作量", taskDaliy.getConsumedWorkload()); |
| | | // map.put("任务进度", taskDaliy.getTaskProgress()); |
| | | // map.put("结算状态", settlementStatus); |
| | | // map.put("备注", taskDaliy.getRemarks()); |
| | | // map.put("创建者", taskDaliy.getCreateBy()); |
| | | // map.put("创建时间", taskDaliy.getCreateTime()); |
| | | // map.put("更新者", taskDaliy.getUpdateBy()); |
| | | // map.put("更新时间", taskDaliy.getUpdateTime()); |
| | | // list.add(map); |
| | | // } |
| | | // FileUtil.downloadExcel(list, response); |
| | | // } |
| | | @Override |
| | | public void download(List<TaskDaliyMongoDto> all, HttpServletResponse response) throws IOException { |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | Map<Long, String> projectNameMap = new HashMap<>(); |
| | | Map<Long, String> userNickNameMap = new HashMap<>(); |
| | | Map<String, String> settlementStatusMap = dictDetailRepository.findByDictName(Constant.SETTLEMENT_STATUS).stream().collect(Collectors.toMap(DictDetail::getValue, DictDetail::getLabel)); |
| | | |
| | | for (TaskDaliyMongoDto taskDaliy : all) { |
| | | if (ObjectUtils.isNotEmpty(taskDaliy.getProjectId()) && !projectNameMap.containsKey(taskDaliy.getProjectId())) { |
| | | Project project = projectRepository.findById(taskDaliy.getProjectId()).orElseGet(Project::new); |
| | | if (project.getId() != null) { |
| | | projectNameMap.put(project.getId(), project.getName()); |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(taskDaliy.getUserId()) && !userNickNameMap.containsKey(taskDaliy.getUserId())) { |
| | | User user = userRepository.findById(taskDaliy.getUserId()).orElseGet(User::new); |
| | | if (user.getId() != null) { |
| | | userNickNameMap.put(user.getId(), user.getNickName()); |
| | | } |
| | | } |
| | | |
| | | // 录入数据 |
| | | Map<String, Object> map = new LinkedHashMap<>(); |
| | | map.put("填写日期", taskDaliy.getFillDate()); |
| | | map.put("所属员工", Optional.ofNullable(userNickNameMap.get(taskDaliy.getUserId())).orElse(null)); |
| | | map.put("所属项目", Optional.ofNullable(projectNameMap.get(taskDaliy.getProjectId())).orElse(null)); |
| | | map.put("所属任务", taskDaliy.getTaskName()); |
| | | map.put("分配任务", taskDaliy.getTaskUserMongo().getName()); |
| | | map.put("消耗工时", taskDaliy.getConsumedHours()); |
| | | map.put("任务进度", taskDaliy.getTaskProgress()); |
| | | map.put("绩效类型", taskDaliy.getTaskUserMongo().getPerformanceType().equals("1") ? "绩效" : "非绩效"); |
| | | map.put("结算状态", Optional.ofNullable(settlementStatusMap.get(taskDaliy.getSettlementStatus())).orElse(taskDaliy.getSettlementStatus())); |
| | | map.put("备注", taskDaliy.getRemarks()); |
| | | list.add(map); |
| | | } |
| | | FileUtil.downloadExcel(list, response); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryOtherWage(TaskDaliyQueryCriteria criteria) { |