|
|
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.poteviohealth.cgp.common.filter.TokenContext;
|
|
|
@@ -21,10 +20,13 @@ import com.poteviohealth.cgp.common.integrated.order.model.OrderStatisticsData;
|
|
|
import com.poteviohealth.cgp.common.integrated.partner.model.AreaDTO;
|
|
|
import com.poteviohealth.cgp.common.integrated.partner.model.EmployeeStationFace;
|
|
|
import com.poteviohealth.cgp.common.integrated.partner.model.EmployeeStationJsonFace;
|
|
|
+import com.poteviohealth.cgp.common.service.impl.BaseServiceImpl;
|
|
|
import com.poteviohealth.cgp.statistics.mapper.OrderMapper;
|
|
|
import com.poteviohealth.cgp.statistics.model.Order;
|
|
|
+import com.poteviohealth.cgp.statistics.model.indto.OrderServiceWebInDTO;
|
|
|
import com.poteviohealth.cgp.statistics.model.outdto.*;
|
|
|
import com.poteviohealth.cgp.statistics.service.IOrderService;
|
|
|
+import com.poteviohealth.cgp.statistics.utils.OrderExcelTask;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -37,6 +39,10 @@ import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ForkJoinPool;
|
|
|
+import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -45,7 +51,7 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
@Log4j2
|
|
|
-public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
|
|
|
+public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implements IOrderService {
|
|
|
|
|
|
@Value("${sync.dbName}")
|
|
|
private String dbName;
|
|
|
@@ -169,6 +175,198 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<OrderExcelDTO> orderExcel(OrderServiceWebInDTO dto) {
|
|
|
+ Integer operatorId = TokenContext.cureOperatorId();
|
|
|
+ QueryWrapper queryWrapper = orderServiceQuery(dto, "o.");
|
|
|
+ queryWrapper.eq("od.operator_id",operatorId);
|
|
|
+ int count;
|
|
|
+ if (null != dto.getProductIds()) {
|
|
|
+ queryWrapper.eq("od.product_id", dto.getProductIds());
|
|
|
+ count = baseMapper.orderPageListAllSize(queryWrapper,dbName,operatorId);
|
|
|
+ }else{
|
|
|
+ QueryWrapper<Order> queryWrapper2 = orderServiceQuery(dto, "o.");
|
|
|
+ count = baseMapper.orderPageListSize(queryWrapper2,dbName,operatorId);
|
|
|
+ }
|
|
|
+ List<OrderExcelDTO> list = Lists.newArrayList();
|
|
|
+ ForkJoinPool pool = new ForkJoinPool();
|
|
|
+ OrderExcelTask task = new OrderExcelTask(0,count, queryWrapper, operatorId, dbName,baseMapper);
|
|
|
+ Future<List<OrderExcelDTO>> future = pool.submit(task);
|
|
|
+ try {
|
|
|
+ do {
|
|
|
+ try {
|
|
|
+ pool.awaitTermination(1, TimeUnit.SECONDS);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } while (!future.isDone());
|
|
|
+ pool.shutdown();
|
|
|
+ list = future.get();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private QueryWrapper orderServiceQuery(OrderServiceWebInDTO orderServiceWebInDTO, String prefix) {
|
|
|
+ QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
|
|
|
+ orderQueryWrapper.eq(prefix+"operator_id",TokenContext.cureOperatorId());
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueCustomerName())) {
|
|
|
+ orderQueryWrapper.eq(prefix + "customer_name", orderServiceWebInDTO.getSearchValueCustomerName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValuePhone())) {
|
|
|
+ orderQueryWrapper.eq(prefix + "phone", orderServiceWebInDTO.getSearchValuePhone());
|
|
|
+ }else if (StringUtils.isNotBlank(orderServiceWebInDTO.getPhone())) {
|
|
|
+ orderQueryWrapper.eq(prefix + "phone", orderServiceWebInDTO.getPhone());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueName())) {
|
|
|
+ orderQueryWrapper.eq(prefix + "name", orderServiceWebInDTO.getSearchValueName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueIdNumber())) {
|
|
|
+ orderQueryWrapper.eq(prefix + "id_number", orderServiceWebInDTO.getSearchValueIdNumber());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueEmployeeName())) {
|
|
|
+ orderQueryWrapper.like(prefix + "employee_name", orderServiceWebInDTO.getSearchValueEmployeeName());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getSearchValueOrderCode())) {
|
|
|
+ orderQueryWrapper.eq(prefix + "sn", orderServiceWebInDTO.getSearchValueOrderCode());
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getOrderStatus()) {
|
|
|
+ if(orderServiceWebInDTO.getOrderStatus().equals(17)){
|
|
|
+ //已回访
|
|
|
+ orderQueryWrapper.eq(prefix + "visit_status",1);
|
|
|
+ }else{
|
|
|
+ orderQueryWrapper.eq(prefix + "order_status", orderServiceWebInDTO.getOrderStatus());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getIsReturn()) {
|
|
|
+ if(orderServiceWebInDTO.getIsReturn().equals(1)){
|
|
|
+ orderQueryWrapper.ne(prefix + "return_num", 0);
|
|
|
+ }else{
|
|
|
+ orderQueryWrapper.eq(prefix + "return_num", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getPayStatus()) {
|
|
|
+ orderQueryWrapper.eq(prefix + "pay_status", orderServiceWebInDTO.getPayStatus());
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getPayStyle()) {
|
|
|
+ orderQueryWrapper.eq(prefix + "pay_style", orderServiceWebInDTO.getPayStyle());
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getEmployeeId()) {
|
|
|
+ orderQueryWrapper.eq(prefix + "employee_id",orderServiceWebInDTO.getEmployeeId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(orderServiceWebInDTO.getReviewReason())) {
|
|
|
+ orderQueryWrapper.likeRight(prefix + "review_reason",orderServiceWebInDTO.getReviewReason());
|
|
|
+ }
|
|
|
+ if(orderServiceWebInDTO.getStationId() != null && orderServiceWebInDTO.getSource() != null){
|
|
|
+ switch (orderServiceWebInDTO.getSource()){
|
|
|
+ case 0:
|
|
|
+ case 2:
|
|
|
+ orderQueryWrapper.eq(prefix + "service_station_id",orderServiceWebInDTO.getStationId());
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ orderQueryWrapper.eq(prefix + "supplier_one_id",orderServiceWebInDTO.getStationId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(orderServiceWebInDTO.getServiceStationIds() != null && !orderServiceWebInDTO.getServiceStationIds().isEmpty()){
|
|
|
+ List<Integer> oneList = orderServiceWebInDTO.getServiceStationIds().stream().filter(s->s<0).collect(Collectors.toList());
|
|
|
+ List<Integer> supplierList = Lists.newArrayList();
|
|
|
+ for (Integer integer : oneList) {
|
|
|
+ supplierList.add(integer*-1);
|
|
|
+ }
|
|
|
+ List<Integer> twoList = orderServiceWebInDTO.getServiceStationIds().stream().filter(s->s>0).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(!supplierList.isEmpty() && !twoList.isEmpty()){
|
|
|
+ orderQueryWrapper.and(wr->wr.in(prefix + "supplier_one_id",supplierList).or().in(prefix + "service_station_id",twoList));
|
|
|
+ }else if(!supplierList.isEmpty()){
|
|
|
+ orderQueryWrapper.in(prefix + "supplier_one_id",supplierList);
|
|
|
+ }else if(!twoList.isEmpty()){
|
|
|
+ orderQueryWrapper.in(prefix + "service_station_id",twoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getPayWay() != null) {
|
|
|
+ orderQueryWrapper.eq(prefix + "pay_way", orderServiceWebInDTO.getPayWay());
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getInvalidTime()) {
|
|
|
+ orderQueryWrapper.eq(prefix + "invalid_time", orderServiceWebInDTO.getInvalidTime());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getStartDate() != null) {
|
|
|
+ orderQueryWrapper.ge(prefix + "order_time", orderServiceWebInDTO.getStartDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getEndDate() != null) {
|
|
|
+ orderQueryWrapper.le(prefix + "order_time", orderServiceWebInDTO.getEndDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getHomeStartDate() != null) {
|
|
|
+ orderQueryWrapper.ge(prefix + "home_time", orderServiceWebInDTO.getHomeStartDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getHomeEndDate() != null) {
|
|
|
+ orderQueryWrapper.le(prefix + "home_time", orderServiceWebInDTO.getHomeEndDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getFinishStartDate() != null) {
|
|
|
+ orderQueryWrapper.ge(prefix + "finish_time", orderServiceWebInDTO.getFinishStartDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getFinishEndDate() != null) {
|
|
|
+ orderQueryWrapper.le(prefix + "finish_time", orderServiceWebInDTO.getFinishEndDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getSearchStartDate() != null && StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchDateStr())) {
|
|
|
+ orderQueryWrapper.ge(prefix + orderServiceWebInDTO.getSearchDateStr(), orderServiceWebInDTO.getSearchStartDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getSearchEndDate() != null && StringUtils.isNotEmpty(orderServiceWebInDTO.getSearchDateStr())) {
|
|
|
+ orderQueryWrapper.le(prefix + orderServiceWebInDTO.getSearchDateStr(), orderServiceWebInDTO.getSearchEndDate());
|
|
|
+ }
|
|
|
+ if (orderServiceWebInDTO.getVisitReserve() != null) {
|
|
|
+ switch (orderServiceWebInDTO.getVisitReserve()){
|
|
|
+ case 0:
|
|
|
+ orderQueryWrapper.isNotNull(prefix + "visit_reserve_date");
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ orderQueryWrapper.isNull(prefix + "visit_reserve_date");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != orderServiceWebInDTO.getPageType()) {
|
|
|
+ if(orderServiceWebInDTO.getPageType().equals(15)){
|
|
|
+ orderQueryWrapper.eq(prefix + "order_status", 15);
|
|
|
+ }else if(orderServiceWebInDTO.getPageType().equals(16)){
|
|
|
+ orderQueryWrapper.gt(prefix + "return_num", 0);
|
|
|
+ }else if(orderServiceWebInDTO.getPageType().equals(17)){
|
|
|
+ orderQueryWrapper.eq(prefix + "order_status",16);
|
|
|
+ }else if(orderServiceWebInDTO.getPageType().equals(19)){
|
|
|
+ orderQueryWrapper.eq(prefix + "visit_status", 1);
|
|
|
+ }else if (orderServiceWebInDTO.getPageType().equals(11)) {
|
|
|
+ orderQueryWrapper.in(prefix + "order_status", Lists.newArrayList(11,12));
|
|
|
+ } else {
|
|
|
+ orderQueryWrapper.eq(prefix + "order_status", orderServiceWebInDTO.getPageType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ orderQueryWrapper.eq(orderServiceWebInDTO.getPlanId() != null,prefix + "plan_id", orderServiceWebInDTO.getPlanId());
|
|
|
+
|
|
|
+ String station = prefix+"station_id";
|
|
|
+ if(TokenContext.cureWebUser().getType()!= null &&
|
|
|
+ (TokenContext.cureWebUser().getType().equals(2)||TokenContext.cureWebUser().getType().equals(12))){
|
|
|
+ station = prefix+"service_station_id";
|
|
|
+ }
|
|
|
+ orderQueryWrapper.in(!orderServiceWebInDTO.getStationIds().isEmpty(),station,orderServiceWebInDTO.getStationIds());
|
|
|
+
|
|
|
+ Integer supplierId = TokenContext.curSupplierId();
|
|
|
+ Integer belong = TokenContext.wbBelong();
|
|
|
+ if(belong.equals(1)){
|
|
|
+ //一级供应商
|
|
|
+ if (supplierId != null && !supplierId.equals(-1)) {
|
|
|
+ orderQueryWrapper.eq(prefix + "supplier_one_id", supplierId);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ orderQueryWrapper.in(!orderServiceWebInDTO.getSupplierIds().isEmpty(),prefix + "supplier_id",orderServiceWebInDTO.getSupplierIds());
|
|
|
+ }
|
|
|
+
|
|
|
+ orderQueryWrapper.eq(prefix + "order_type", 2);
|
|
|
+ return orderQueryWrapper;
|
|
|
+ }
|
|
|
+
|
|
|
private List<ListParams> getSubsidyCustomerMealList(DateParams dateParams,List<Integer> operatorIds){
|
|
|
List<ListParams> returnList = Lists.newArrayList();
|
|
|
QueryWrapper queryWrapper = new QueryWrapper<>();
|