| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.Map.Entry; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> queryProjectCost(ProjectQueryCriteria criteria) throws ParseException { |
| | | // 判断入参完整性 |
| | | if (criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) { |
| | | return null; |
| | | } |
| | | |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | |
| | | Sort sort = Sort.by(Sort.Order.desc("createTime")); |
| | | ProjectQueryCriteria criteria1 = new ProjectQueryCriteria(); |
| | | // criteria1.setProjectDistinguish("project_distinguish_product"); // TODO |
| | | criteria1.setProjectStatusNotEqual(Constant.PROJECT_STATUS_COMPLETED); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | List<Project> projectList = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria1, criteriaBuilder), sort); |
| | | |
| | | for (Project project : projectList) { |
| | | Query query = new Query( |
| | | Criteria.where("projectId").is(project.getId()) |
| | | .and("planStartTime").gte(sdf.parse(criteria.getTargetYear() + "-01-01")) |
| | | ); |
| | | List<TaskMongo> taskMongoList = mongoTemplate.find(query, TaskMongo.class); |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("projectName", project.getName()); |
| | | |
| | | List<TaskUserMongo> taskUserMongoList = mongoTemplate.find(new Query(Criteria.where("task").in(taskMongoList)), TaskUserMongo.class); |
| | | result.put("taskHours", taskUserMongoList.stream().mapToDouble(TaskUserMongo::getTaskHours).sum()); |
| | | result.put("consumedHours", taskUserMongoList.stream().mapToDouble(TaskUserMongo::getCostHours).sum()); |
| | | |
| | | if (!result.get("consumedHours").equals(0.0D)) { |
| | | resultList.add(result); |
| | | } |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> querySubgroupTurnover(ProjectQueryCriteria criteria) { |
| | | // 判断入参完整性 |
| | | if (criteria.getTargetYear() == null || "".equals(criteria.getTargetYear())) { |