|  |  |  | 
|---|
|  |  |  | package com.ruoyi.order.service.impl; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.R; | 
|---|
|  |  |  | import com.ruoyi.common.core.utils.GaoDeMapUtil; | 
|---|
|  |  |  | import com.ruoyi.common.core.vo.AddressDto; | 
|---|
|  |  |  | import com.ruoyi.common.core.vo.PaperInVo; | 
|---|
|  |  |  | import com.ruoyi.common.core.vo.Path; | 
|---|
|  |  |  | import com.ruoyi.order.entity.ChangeDispatch; | 
|---|
|  |  |  | import com.ruoyi.order.entity.Order; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.ruoyi.order.request.UserOrderRequest; | 
|---|
|  |  |  | import com.ruoyi.order.service.ChangeDispatchService; | 
|---|
|  |  |  | import com.ruoyi.order.service.OrderService; | 
|---|
|  |  |  | import com.ruoyi.order.vo.*; | 
|---|
|  |  |  | import com.ruoyi.order.vo.MoneyQueryRequest; | 
|---|
|  |  |  | import com.ruoyi.order.vo.OrderCountRequest; | 
|---|
|  |  |  | import com.ruoyi.order.vo.OrderCountVO; | 
|---|
|  |  |  | import com.ruoyi.order.vo.OrderPageCountVO; | 
|---|
|  |  |  | import com.ruoyi.order.vo.OrderQueryRequest; | 
|---|
|  |  |  | import com.ruoyi.order.vo.OrderQueryVO; | 
|---|
|  |  |  | import com.ruoyi.order.vo.OrderResultVO; | 
|---|
|  |  |  | import com.ruoyi.order.vo.WorkerOrderCountVO; | 
|---|
|  |  |  | import com.ruoyi.order.vo.WorkerOrderRankVO; | 
|---|
|  |  |  | import com.ruoyi.user.api.feignClient.UserClient; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | 
|---|
|  |  |  | import java.time.Month; | 
|---|
|  |  |  | import java.time.Year; | 
|---|
|  |  |  | import java.time.temporal.TemporalAdjusters; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | String countType = orderCount.getCountType(); | 
|---|
|  |  |  | String startTime = orderCount.getStartTime(); | 
|---|
|  |  |  | String endTime = orderCount.getEndTime(); | 
|---|
|  |  |  | //        String [] siteIds = orderCount.getSiteIds(); | 
|---|
|  |  |  | List<OrderQueryVO> list; | 
|---|
|  |  |  | // 根据查询类型查询订单信息 | 
|---|
|  |  |  | if (OrderConstants.YEAR.equals(countType)) { | 
|---|
|  |  |  | list = baseMapper.orderCountByYear(cityList, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByYear(cityList, orderState,orderCount.getSiteIds()); | 
|---|
|  |  |  | } else if (OrderConstants.MONTH.equals(countType)) { | 
|---|
|  |  |  | list = baseMapper.orderCountByMonth(cityList, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByMonth(cityList, orderState, orderCount.getSiteIds()); | 
|---|
|  |  |  | } else if (OrderConstants.WEEK.equals(countType)) { | 
|---|
|  |  |  | list = baseMapper.orderCountByWeek(cityList, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByWeek(cityList, orderState, orderCount.getSiteIds()); | 
|---|
|  |  |  | } else if (OrderConstants.TODAY.equals(countType)) { | 
|---|
|  |  |  | list = baseMapper.orderCountByToday(cityList, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByToday(cityList, orderState, orderCount.getSiteIds()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | startTime = startTime + " 00:00:00"; | 
|---|
|  |  |  | 
|---|
|  |  |  | long diffInMillis = date2.getTime() - date1.getTime(); | 
|---|
|  |  |  | long diffInDays = diffInMillis / (24 * 60 * 60 * 1000); | 
|---|
|  |  |  | if (diffInDays > Constants.YEAR_DAY) { | 
|---|
|  |  |  | list = baseMapper.orderCountByTimeRangeYear(cityList, startTime, endTime, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByTimeRangeYear(cityList, startTime, endTime, orderState, orderCount.getSiteIds()); | 
|---|
|  |  |  | } else if (diffInDays > Constants.THIRTY) { | 
|---|
|  |  |  | list = baseMapper.orderCountByTimeRangeMonth(cityList, startTime, endTime, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByTimeRangeMonth(cityList, startTime, endTime, orderState, orderCount.getSiteIds()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | list = baseMapper.orderCountByTimeRange(cityList, startTime, endTime, orderState); | 
|---|
|  |  |  | list = baseMapper.orderCountByTimeRange(cityList, startTime, endTime, orderState, orderCount.getSiteIds()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (ParseException e) { | 
|---|
|  |  |  | list = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | orderNumber = list.stream().filter(order -> order.getNumber() != null) | 
|---|
|  |  |  | .mapToInt(OrderQueryVO::getNumber).sum(); | 
|---|
|  |  |  | fakeNumber = list.stream().filter(order -> order.getFakeCount() != null) | 
|---|
|  |  |  | .mapToInt(OrderQueryVO::getNumber).sum(); | 
|---|
|  |  |  | .mapToInt(OrderQueryVO::getFakeCount).sum(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OrderResultVO(totalMoney, orderNumber, list,fakeNumber); | 
|---|
|  |  |  | return new OrderResultVO(totalMoney, orderNumber, list,fakeNumber); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | Page<Order> page = Page.of(orderQueryRequest.getPageNum(), orderQueryRequest.getPageSize()); | 
|---|
|  |  |  | // 基础查询 | 
|---|
|  |  |  | Page<Order> pageList = baseMapper.queryPage(orderQueryRequest, page); | 
|---|
|  |  |  | List<ChangeDispatch> list = changeDispatchService.lambdaQuery() | 
|---|
|  |  |  | .eq(ChangeDispatch::getIsDelete, 0) | 
|---|
|  |  |  | .orderByDesc(ChangeDispatch::getCreateTime).list(); | 
|---|
|  |  |  | for (Order order : pageList.getRecords()) { | 
|---|
|  |  |  | ChangeDispatch changeDispatch = changeDispatchService.lambdaQuery() | 
|---|
|  |  |  | .eq(ChangeDispatch::getOrderId, order.getId()) | 
|---|
|  |  |  | .eq(ChangeDispatch::getIsDelete, 0) | 
|---|
|  |  |  | .orderByDesc(ChangeDispatch::getCreateTime) | 
|---|
|  |  |  | .last("limit 1").one(); | 
|---|
|  |  |  | ChangeDispatch changeDispatch = list.stream().filter(e -> e.getOrderId().equals(order.getId())) | 
|---|
|  |  |  | .findFirst().orElse(null); | 
|---|
|  |  |  | if (null != changeDispatch) { | 
|---|
|  |  |  | order.setApplyReason(changeDispatch.getApplyReason()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return pageList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<String> queryPage1(OrderQueryRequest orderQueryRequest) { | 
|---|
|  |  |  | Page<Order> page = Page.of(orderQueryRequest.getPageNum(), orderQueryRequest.getPageSize()); | 
|---|
|  |  |  | // 基础查询 | 
|---|
|  |  |  | Page<Order> pageList = baseMapper.queryPage1(orderQueryRequest, page); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return  pageList.getRecords().stream().map(Order::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Page<OrderCountVO> orderCount(String name, String phone, List<String> cityList, Page<OrderCountVO> page) { | 
|---|
|  |  |  | return baseMapper.orderCount(name, phone, cityList, page); | 
|---|
|  |  |  | public Page<OrderCountVO> orderCount(String name, String phone, List<String> cityList, Page<OrderCountVO> page,List<String>siteIds) { | 
|---|
|  |  |  | return baseMapper.orderCount(name, phone, cityList, page, siteIds); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public OrderPageCountVO orderPageCount(OrderQueryRequest orderQueryRequest) { | 
|---|
|  |  |  | List<Order> orderList = baseMapper.orderPageCount(orderQueryRequest); | 
|---|
|  |  |  | int total = 0; | 
|---|
|  |  |  | int toBeDispatched = 0; | 
|---|
|  |  |  | int stayDoorstep = 0; | 
|---|
|  |  |  | int toBeCompleted = 0; | 
|---|
|  |  |  | int completed = 0; | 
|---|
|  |  |  | int canceled = 0; | 
|---|
|  |  |  | int reInvestment = 0; | 
|---|
|  |  |  | for (Order order : orderList) { | 
|---|
|  |  |  | total++; | 
|---|
|  |  |  | Integer state = order.getState(); | 
|---|
|  |  |  | if (Constants.ZERO.equals(state)) { | 
|---|
|  |  |  | toBeDispatched++; | 
|---|
|  |  |  | } else if (Constants.ONE.equals(state)) { | 
|---|
|  |  |  | stayDoorstep++; | 
|---|
|  |  |  | } else if (Constants.TWO.equals(state)) { | 
|---|
|  |  |  | toBeCompleted++; | 
|---|
|  |  |  | } else if (Constants.THREE.equals(state)) { | 
|---|
|  |  |  | completed++; | 
|---|
|  |  |  | } else if (Constants.FOUR.equals(state)) { | 
|---|
|  |  |  | canceled++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (order.getState().equals(Constants.SIX)) { | 
|---|
|  |  |  | reInvestment++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return new OrderPageCountVO(total, toBeDispatched, stayDoorstep, | 
|---|
|  |  |  | toBeCompleted, completed, canceled, reInvestment); | 
|---|
|  |  |  | Order order = baseMapper.orderPageCount(orderQueryRequest); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer toBeDispatched = order.getToBeDispatched(); | 
|---|
|  |  |  | Integer stayDoorstep = order.getStayDoorstep(); | 
|---|
|  |  |  | Integer toBeCompleted = order.getToBeCompleted(); | 
|---|
|  |  |  | Integer completed = order.getCompleted(); | 
|---|
|  |  |  | Integer canceled = order.getCanceled(); | 
|---|
|  |  |  | Integer reInvestment = order.getReInvestment(); | 
|---|
|  |  |  | int total = toBeDispatched + stayDoorstep + toBeCompleted + completed + canceled + reInvestment; | 
|---|
|  |  |  | return new OrderPageCountVO(total, toBeDispatched, stayDoorstep, | 
|---|
|  |  |  | toBeCompleted, completed, canceled, reInvestment); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public BigDecimal tradeMoney(MoneyQueryRequest moneyQueryRequest) { | 
|---|
|  |  |  | if(moneyQueryRequest.getSiteIds()==null){ | 
|---|
|  |  |  | moneyQueryRequest.setSiteIds(new ArrayList<>()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<String> cityList = moneyQueryRequest.getCityList(); | 
|---|
|  |  |  | String type = moneyQueryRequest.getType(); | 
|---|
|  |  |  | // 计算当前季度时间所包含时间 | 
|---|
|  |  |  | 
|---|
|  |  |  | return String.valueOf(order.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<PaperInVo> papercout(String workId,String date) { | 
|---|
|  |  |  | return this.baseMapper.papercout(workId,date); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据当前月份获取当前季度的开始月份 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | return Month.OCTOBER; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 增加发送短信次数 | 
|---|
|  |  |  | * @param orderId 订单id | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void messageCount(String orderId) { | 
|---|
|  |  |  | Order byId = this.getById(orderId); | 
|---|
|  |  |  | byId.setMsgCount(byId.getMsgCount()==null?1:byId.getMsgCount()+1); | 
|---|
|  |  |  | this.updateById(byId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|