| package com.xzx.gc.user.controller;  | 
|   | 
| import cn.hutool.core.collection.CollUtil;  | 
| import cn.hutool.core.convert.Convert;  | 
| import cn.hutool.core.date.DateTime;  | 
| import cn.hutool.core.date.DateUtil;  | 
| import com.xzx.gc.common.Result;  | 
| import com.xzx.gc.common.constant.CommonEnum;  | 
| import com.xzx.gc.common.constant.Constants;  | 
| import com.xzx.gc.common.constant.OrderEnum;  | 
| import com.xzx.gc.common.request.BaseController;  | 
| import com.xzx.gc.common.utils.BusinessUtil;  | 
| import com.xzx.gc.common.utils.DateUtils;  | 
| import com.xzx.gc.entity.OrderInfo;  | 
| import com.xzx.gc.entity.OtherUserInfo;  | 
| import com.xzx.gc.model.order.OrderReportDetailDto;  | 
| import com.xzx.gc.model.order.OrderReportDetailParamDto;  | 
| import com.xzx.gc.model.order.OrderReportDto;  | 
| import com.xzx.gc.user.mapper.AccountMapper;  | 
| import com.xzx.gc.user.mapper.OrderMapper;  | 
| import com.xzx.gc.user.mapper.PayRequestMapper;  | 
| import com.xzx.gc.user.service.*;  | 
| import io.swagger.annotations.Api;  | 
| import io.swagger.annotations.ApiOperation;  | 
| import lombok.extern.slf4j.Slf4j;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.validation.annotation.Validated;  | 
| import org.springframework.web.bind.annotation.PostMapping;  | 
| import org.springframework.web.bind.annotation.RequestBody;  | 
| import org.springframework.web.bind.annotation.RequestMapping;  | 
| import org.springframework.web.bind.annotation.RestController;  | 
|   | 
| import javax.servlet.http.HttpServletRequest;  | 
| import java.util.ArrayList;  | 
| import java.util.List;  | 
| import java.util.stream.Collectors;  | 
|   | 
| /**  | 
|  * @author :zz  | 
|  */  | 
| @RestController  | 
| @RequestMapping("/orderReport")  | 
| @Api(tags = {"合伙人报表管理"})  | 
| @Validated  | 
| @Slf4j  | 
| public class OrderReportController extends BaseController {  | 
|   | 
|     @Autowired  | 
|     private OrderMapper orderMapper;  | 
|   | 
|     @Autowired  | 
|     private PayRequestMapper payRequestMapper;  | 
|   | 
|   | 
|     @Autowired  | 
|     private OrderReportService orderReportService;  | 
|   | 
|     @Autowired  | 
|     private AccountMapper accountMapper;  | 
|   | 
|     @Autowired  | 
|     private OtherUserService otherUserService;  | 
|   | 
|     @Autowired  | 
|     private BusinessUtil businessUtil;  | 
|   | 
|   | 
|     @PostMapping("")  | 
|     @ApiOperation(value = "查询报表数据")  | 
|     public Result<OrderReportDto> find(HttpServletRequest request) {  | 
|         String userId = getUserId(request);  | 
|         OtherUserInfo byId = otherUserService.findById(userId);  | 
|         String partnerId = byId.getPartnerId();  | 
|         OrderReportDto orderReportDto = orderReportService.findByPartneId(partnerId);  | 
|         if(Constants.DEFAULT_PARTNER_ID.equals(partnerId)){  | 
|             orderReportDto.setIsPlat(true);  | 
|         }  | 
|         return Result.success(orderReportDto);  | 
|     }  | 
|   | 
|   | 
|     @PostMapping("/detail")  | 
|     @ApiOperation(value = "查询报表明细")  | 
|     public Result<List<OrderReportDetailDto>> detail(@Validated @RequestBody OrderReportDetailParamDto orderReportDetailParamDto, HttpServletRequest request) {  | 
|         Integer type = orderReportDetailParamDto.getType();  | 
|         String areaId = orderReportDetailParamDto.getAreaId();  | 
|         int level = orderReportDetailParamDto.getLevel();  | 
|         List<OrderReportDetailDto> list=null;  | 
|         List<OrderReportDetailDto> listToday=null;  | 
|         List<OrderReportDetailDto> listYesterday=null;  | 
|         //当前时间  | 
|         DateTime nowData = DateUtil.parse(DateUtil.now(), DateUtils.DATE_FORMAT_YMD);  | 
|   | 
|         if(businessUtil.getVersion(request.getHeader("version")).compareTo(Convert.toDouble(CommonEnum.版本号1点6.getValue()))>=0){  | 
|             String userId = getUserId(request);  | 
|             OtherUserInfo byId = otherUserService.findById(userId);  | 
|             String partnerId = byId.getPartnerId();  | 
|             List<OrderInfo> orderInfos = orderMapper.findDetailByPartned(partnerId);  | 
|   | 
|             if (OrderEnum.今日回收金额.getValue().equals(type.toString())) {  | 
|                 List<OrderInfo> todayOrderList = orderReportService.getCompleteOrderListByTime(orderInfos,0);  | 
|                 list = orderReportService.getDetail(todayOrderList,1);  | 
|             } else if (OrderEnum.回收总金额.getValue().equals(type.toString())) {  | 
|                 //筛选订单已完成的列表  | 
|                 List<OrderInfo> collect =orderReportService.getCompleteOrderListByTime(orderInfos,orderReportDetailParamDto.getTimeType());  | 
|                 List<OrderInfo> TodayOrder = new ArrayList<>();  | 
|                 List<OrderInfo> YesterdayOrder = new ArrayList<>();  | 
|                 //订单已完成的列表  | 
|                 for (OrderInfo orderInfo : collect) {  | 
|                     String completeTime = orderInfo.getCompleteTime();  | 
|                     DateTime parse = DateUtil.parse(completeTime, DateUtils.DATE_FORMAT_YMD);  | 
|   | 
|                     //今日回收金额  | 
|                     if (DateUtil.isSameDay(parse, nowData)) {  | 
|                         TodayOrder.add(orderInfo);  | 
|                     }  | 
|                     //昨天回收金额  | 
|                     long l = DateUtil.betweenDay(parse, nowData, true);  | 
|                     if (l == 1) {  | 
|                         YesterdayOrder.add(orderInfo);  | 
|                     }  | 
|                 }  | 
|                 list = orderReportService.getDetail(collect,1);  | 
|   | 
|               /*  //获取日均金额  | 
|                 if (CollUtil.isNotEmpty(list)) {  | 
|                     for (OrderReportDetailDto orderReportDetailDto : list) {  | 
|                         String areaId1 = orderReportDetailDto.getAreaId();  | 
|                         int level1 = orderReportDetailDto.getLevel();  | 
|                         List<OrderInfo> collect1 = orderReportService.findByAreaAndLevel(collect, areaId1, level1);  | 
|                         if (CollUtil.isNotEmpty(collect1)) {  | 
|                             String moneyAvg = orderReportService.getMoneyAvg(collect1, nowData);  | 
|                             orderReportDetailDto.setMoneyAvg(moneyAvg);  | 
|                         }  | 
|                     }  | 
|                 }  | 
|                 //今日的明细  | 
|                 listToday = orderReportService.getDetail(TodayOrder);  | 
|                 //昨天的明细  | 
|                 listYesterday = orderReportService.getDetail(YesterdayOrder);  | 
|                 //设置环比  | 
|                 orderReportService.setRatio(list, listToday, listYesterday, 1);*/  | 
|             } else if (OrderEnum.今日下单用户量.getValue().equals(type.toString())) {  | 
|                 List<OrderInfo> todayOrderList = orderReportService.getOrderUserListByTime(orderInfos,0);  | 
|                 list = orderReportService.getDetail(todayOrderList,2);  | 
|             } else if (OrderEnum.下单总用户量.getValue().equals(type.toString())) {  | 
|                 List<OrderInfo> collect = orderReportService.getOrderUserListByTime(orderInfos,orderReportDetailParamDto.getTimeType());  | 
|                 List<OrderInfo> TodayOrder = new ArrayList<>();  | 
|                 List<OrderInfo> YesterdayOrder = new ArrayList<>();  | 
|                 for (OrderInfo orderInfo : collect) {  | 
|                     String createTime = orderInfo.getCreateTime();  | 
|                     DateTime parse3 = DateUtil.parse(createTime, DateUtils.DATE_FORMAT_YMD);  | 
|   | 
|                     //当天下单用户量  | 
|                     if (DateUtil.isSameDay(parse3, nowData)) {  | 
|                         TodayOrder.add(orderInfo);  | 
|                     }  | 
|   | 
|                     //昨天下单用户量  | 
|                     long l = DateUtil.betweenDay(parse3, nowData, true);  | 
|                     if (l == 1) {  | 
|                         YesterdayOrder.add(orderInfo);  | 
|                     }  | 
|                 }  | 
|                 list = orderReportService.getDetail(collect,2);  | 
|   | 
|                 //获取日均下单  | 
| //                if (CollUtil.isNotEmpty(list)) {  | 
| //                    for (OrderReportDetailDto orderReportDetailDto : list) {  | 
| //                        String areaId1 = orderReportDetailDto.getAreaId();  | 
| //                        int level1 = orderReportDetailDto.getLevel();  | 
| //                        List<OrderInfo> collect1 = orderReportService.findByAreaAndLevel(collect, areaId1, level1);  | 
| //                        if (CollUtil.isNotEmpty(collect1)) {  | 
| //                            int numAvg = orderReportService.getNumAvg(collect1, nowData);  | 
| //                            orderReportDetailDto.setNumAvg(numAvg);  | 
| //                        }  | 
| //                    }  | 
| //                }  | 
|   | 
| //                //今日的明细  | 
| //                listToday = orderReportService.getDetail(TodayOrder);  | 
| //                //昨天的明细  | 
| //                listYesterday = orderReportService.getDetail(YesterdayOrder);  | 
| //                //设置环比  | 
| //                orderReportService.setRatio(list, listToday, listYesterday, 2);  | 
|             } else if (OrderEnum.未提现总金额.getValue().equals(type.toString())) {  | 
|                 //未提现 查询所有账户  | 
|                 List<OrderInfo> notWithdraw = orderReportService.findNotWithdraw(partnerId);  | 
|                 list = orderReportService.getDetail(notWithdraw,1);  | 
|             }  | 
|   | 
|   | 
|         }else {  | 
|   | 
|             //所有订单  | 
|             List<OrderInfo> orderInfos = orderMapper.findDetail();  | 
|             if (OrderEnum.今日回收金额.getValue().equals(type.toString())) {  | 
|                 List<OrderInfo> todayOrderList = orderReportService.getTodayCompleteOrderList(orderInfos);  | 
|                 list = orderReportService.getDetail(todayOrderList, level, areaId);  | 
|             } else if (OrderEnum.回收总金额.getValue().equals(type.toString())) {  | 
|                 //筛选订单已完成的列表  | 
|                 List<OrderInfo> collect = orderInfos.stream().filter(x -> x.getOrderStatus().equals(OrderEnum.完成.getValue()) || x.getOrderStatus().equals(OrderEnum.入库中.getValue()) || x.getOrderStatus().equals(OrderEnum.待入库.getValue())).collect(Collectors.toList());  | 
|                 List<OrderInfo> TodayOrder = new ArrayList<>();  | 
|                 List<OrderInfo> YesterdayOrder = new ArrayList<>();  | 
|                 //订单已完成的列表  | 
|                 for (OrderInfo orderInfo : collect) {  | 
|                     String completeTime = orderInfo.getCompleteTime();  | 
|                     DateTime parse = DateUtil.parse(completeTime, DateUtils.DATE_FORMAT_YMD);  | 
|   | 
|                     //今日回收金额  | 
|                     if (DateUtil.isSameDay(parse, nowData)) {  | 
|                         TodayOrder.add(orderInfo);  | 
|                     }  | 
|                     //昨天回收金额  | 
|                     long l = DateUtil.betweenDay(parse, nowData, true);  | 
|                     if (l == 1) {  | 
|                         YesterdayOrder.add(orderInfo);  | 
|                     }  | 
|                 }  | 
|                 list = orderReportService.getDetail(collect, level, areaId);  | 
|   | 
|                 //获取日均金额  | 
|                 if (CollUtil.isNotEmpty(list)) {  | 
|                     for (OrderReportDetailDto orderReportDetailDto : list) {  | 
|                         String areaId1 = orderReportDetailDto.getAreaId();  | 
|                         int level1 = orderReportDetailDto.getLevel();  | 
|                         List<OrderInfo> collect1 = orderReportService.findByAreaAndLevel(collect, areaId1, level1);  | 
|                         if (CollUtil.isNotEmpty(collect1)) {  | 
|                             String moneyAvg = orderReportService.getMoneyAvg(collect1, nowData);  | 
|                             orderReportDetailDto.setMoneyAvg(moneyAvg);  | 
|                         }  | 
|                     }  | 
|                 }  | 
|                 //今日的明细  | 
|                 listToday = orderReportService.getDetail(TodayOrder, level, areaId);  | 
|                 //昨天的明细  | 
|                 listYesterday = orderReportService.getDetail(YesterdayOrder, level, areaId);  | 
|                 //设置环比  | 
|                 orderReportService.setRatio(list, listToday, listYesterday, 1);  | 
|             } else if (OrderEnum.今日下单用户量.getValue().equals(type.toString())) {  | 
|                 List<OrderInfo> todayOrderList = orderReportService.getTodayOrderUserList(orderInfos);  | 
|                 list = orderReportService.getDetail(todayOrderList, level, areaId);  | 
|             } else if (OrderEnum.下单总用户量.getValue().equals(type.toString())) {  | 
|                 List<OrderInfo> collect = orderReportService.removeRepeatUser(orderInfos);  | 
|                 List<OrderInfo> TodayOrder = new ArrayList<>();  | 
|                 List<OrderInfo> YesterdayOrder = new ArrayList<>();  | 
|                 for (OrderInfo orderInfo : collect) {  | 
|                     String createTime = orderInfo.getCreateTime();  | 
|                     DateTime parse3 = DateUtil.parse(createTime, DateUtils.DATE_FORMAT_YMD);  | 
|   | 
|                     //当天下单用户量  | 
|                     if (DateUtil.isSameDay(parse3, nowData)) {  | 
|                         TodayOrder.add(orderInfo);  | 
|                     }  | 
|   | 
|                     //昨天下单用户量  | 
|                     long l = DateUtil.betweenDay(parse3, nowData, true);  | 
|                     if (l == 1) {  | 
|                         YesterdayOrder.add(orderInfo);  | 
|                     }  | 
|                 }  | 
|                 list = orderReportService.getDetail(collect, level, areaId);  | 
|   | 
|                 //获取日均下单  | 
|                 if (CollUtil.isNotEmpty(list)) {  | 
|                     for (OrderReportDetailDto orderReportDetailDto : list) {  | 
|                         String areaId1 = orderReportDetailDto.getAreaId();  | 
|                         int level1 = orderReportDetailDto.getLevel();  | 
|                         List<OrderInfo> collect1 = orderReportService.findByAreaAndLevel(collect, areaId1, level1);  | 
|                         if (CollUtil.isNotEmpty(collect1)) {  | 
|                             int numAvg = orderReportService.getNumAvg(collect1, nowData);  | 
|                             orderReportDetailDto.setNumAvg(numAvg);  | 
|                         }  | 
|                     }  | 
|                 }  | 
|   | 
|                 //今日的明细  | 
|                 listToday = orderReportService.getDetail(TodayOrder, level, areaId);  | 
|                 //昨天的明细  | 
|                 listYesterday = orderReportService.getDetail(YesterdayOrder, level, areaId);  | 
|                 //设置环比  | 
|                 orderReportService.setRatio(list, listToday, listYesterday, 2);  | 
|             } else if (OrderEnum.未提现总金额.getValue().equals(type.toString())) {  | 
|                 //未提现 查询所有账户  | 
|                 List<OrderInfo> accountInfos = accountMapper.findArea();  | 
|                 list = orderReportService.getDetail(accountInfos, level, areaId);  | 
|             } else if (OrderEnum.已提现总金额.getValue().equals(type.toString())) {  | 
|                 //已提现金额 查询交易记录表  | 
|                 List<OrderInfo> accountInfos = payRequestMapper.findArea();  | 
|                 list = orderReportService.getDetail(accountInfos, level, areaId);  | 
|             }  | 
|         }  | 
|         return Result.success(list);  | 
|     }  | 
|   | 
|   | 
| }  |