Commit 68811cd2 by wangli

mybatisplus to jpa

1 parent f390e67c
package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dao.OrderEventDao;
import com.dituhui.pea.order.dao.OrderInfoDao;
import com.dituhui.pea.order.dto.OrderChangeListDTO;
import com.dituhui.pea.order.dto.WorkbenchSummaryResp;
import com.dituhui.pea.order.entity.OrderEventEntity;
import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrderInfo;
import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.service.WorkbenchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,8 +17,15 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
......@@ -28,10 +35,10 @@ public class WorkbenchServiceImpl implements WorkbenchService {
private OrderEventDao orderEventDao;
@Autowired
private OrderInfoMPDao orderInfoMPDao;
private OrderInfoDao orderInfoDao;
@Autowired
private OrderInfoDao orderInfoDao;
private EntityManager entityManager;
@Override
public Result<?> getOrderChangeList(OrderChangeListDTO.Request reqDTO) {
......@@ -89,27 +96,95 @@ public class WorkbenchServiceImpl implements WorkbenchService {
}
private List<Map<String, Object>> queryCountByAppointmentMethod(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("appointment_method, appointment_status, COUNT(*) as count")
.lambda()
.eq(OrderInfo::getDt, dt)
.eq(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getAppointmentMethod, OrderInfo::getAppointmentStatus);
return orderInfoMPDao.selectMaps(wrapper);
}
private List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) {
QueryWrapper<OrderInfo> wrapper = new QueryWrapper<>();
wrapper.select("service_status, COUNT(*) as count")
.lambda()
.eq(OrderInfo::getDt, dt)
.eq(levelType.equals("cluster"), OrderInfo::getOrgClusterId, levelValue)
.eq(levelType.equals("branch"), OrderInfo::getOrgBranchId, levelValue)
.eq(levelType.equals("group"), OrderInfo::getOrgGroupId, levelValue)
.groupBy(OrderInfo::getServiceStatus);
return orderInfoMPDao.selectMaps(wrapper);
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);
Root<OrderInfo> root = criteriaQuery.from(OrderInfo.class);
criteriaQuery.multiselect(
root.get("appointmentMethod"),
root.get("appointmentStatus"),
criteriaBuilder.count(root).alias("count")
);
Predicate datePredicate = criteriaBuilder.equal(root.get("dt"), dt);
Predicate levelPredicate = null;
if ("cluster".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgClusterId"), levelValue);
} else if ("branch".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgBranchId"), levelValue);
} else if ("group".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgGroupId"), levelValue);
}
if (levelPredicate != null) {
criteriaQuery.where(datePredicate, levelPredicate);
} else {
criteriaQuery.where(datePredicate);
}
criteriaQuery.groupBy(root.get("appointmentMethod"), root.get("appointmentStatus"));
TypedQuery<Object[]> typedQuery = entityManager.createQuery(criteriaQuery);
List<Object[]> results = typedQuery.getResultList();
List<Map<String, Object>> mappedResults = results.stream()
.map(result -> {
Map<String, Object> map = Map.of(
"appointmentMethod", result[0],
"appointmentStatus", result[1],
"count", result[2]
);
return map;
})
.collect(Collectors.toList());
return mappedResults;
}
public List<Map<String, Object>> queryCountByOrderStatus(String levelType, String levelValue, LocalDate dt) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);
Root<OrderInfo> root = criteriaQuery.from(OrderInfo.class);
criteriaQuery.multiselect(
root.get("serviceStatus"),
criteriaBuilder.count(root).alias("count")
);
Predicate datePredicate = criteriaBuilder.equal(root.get("dt"), dt);
Predicate levelPredicate = null;
if ("cluster".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgClusterId"), levelValue);
} else if ("branch".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgBranchId"), levelValue);
} else if ("group".equals(levelType)) {
levelPredicate = criteriaBuilder.equal(root.get("orgGroupId"), levelValue);
}
if (levelPredicate != null) {
criteriaQuery.where(datePredicate, levelPredicate);
} else {
criteriaQuery.where(datePredicate);
}
criteriaQuery.groupBy(root.get("serviceStatus"));
TypedQuery<Object[]> typedQuery = entityManager.createQuery(criteriaQuery);
List<Object[]> results = typedQuery.getResultList();
List<Map<String, Object>> mappedResults = results.stream()
.map(result -> {
Map<String, Object> map = Map.of(
"serviceStatus", result[0],
"count", result[1]
);
return map;
})
.collect(Collectors.toList());
return mappedResults;
}
private HashMap<String, Long> transAppointmentMethod(List<Map<String, Object>> results) {
......@@ -211,12 +286,10 @@ public class WorkbenchServiceImpl implements WorkbenchService {
return items;
}
private <T> HashMap<String, List<T>> packParams(String key, T ...values) {
private <T> HashMap<String, List<T>> packParams(String key, T... values) {
HashMap<String, List<T>> map = new HashMap<>();
List<T> value = new ArrayList<>();
for(T v: values){
value.add(v);
}
Collections.addAll(value, values);
map.put(key, value);
return map;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!