|
@@ -0,0 +1,214 @@
|
|
|
+package com.ydd.module.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ydd.common.core.domain.entity.SysUser;
|
|
|
+import com.ydd.common.core.page.PageResult;
|
|
|
+import com.ydd.common.enums.UserTypeEnums;
|
|
|
+import com.ydd.common.utils.StringUtils;
|
|
|
+import com.ydd.module.domain.*;
|
|
|
+import com.ydd.module.dto.BillOrderDto;
|
|
|
+import com.ydd.module.dto.SystemOrderDto;
|
|
|
+import com.ydd.module.enums.DeliveryStatusEnum;
|
|
|
+import com.ydd.module.mapper.ProfitsBillOrderMapper;
|
|
|
+import com.ydd.module.service.*;
|
|
|
+import com.ydd.third.common.utils.DateUtils;
|
|
|
+import org.apache.commons.compress.utils.Lists;
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Demo class
|
|
|
+ *
|
|
|
+ * @author 14027
|
|
|
+ * @date 2022/4/25 10:20
|
|
|
+ */
|
|
|
+@Service("profitsBillOrderServiceImpl")
|
|
|
+public class ProfitsBillOrderServiceImpl extends ServiceImpl<ProfitsBillOrderMapper, ProfitsBillOrder> implements IProfitsBillOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IWaimaiOrderService iWaimaiOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDspWaimaiService iDspWaimaiService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IShopService iShopService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IMerchantService iMerchantService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAgentService iAgentService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void billOrderStatistics() {
|
|
|
+ // 查询所有外卖平台
|
|
|
+ List<DspWaimai> dspWaimaiList = iDspWaimaiService.selectWaimaiList();
|
|
|
+
|
|
|
+// for (int i = 225; i >= 1; i--) {
|
|
|
+ String date = DateFormatUtils.format(DateUtils.addDateDays(new Date(), -1), "yyyy-MM-dd");
|
|
|
+ String startDate = date.concat(" 00:00:00");
|
|
|
+ String endDate = date.concat(" 23:59:59");
|
|
|
+ Long year = Integer.valueOf(date.split("-")[0]).longValue();
|
|
|
+ Long month = Integer.valueOf(date.split("-")[1]).longValue();
|
|
|
+ Long day = Integer.valueOf(date.split("-")[2]).longValue();
|
|
|
+
|
|
|
+ // 查询当天同步外卖订单的所有门店
|
|
|
+ List<BillOrderDto> shopIdList = baseMapper.selectListByShopId(null, startDate, endDate);
|
|
|
+ Map<Long, List<BillOrderDto>> map = shopIdList.stream().collect(Collectors.groupingBy(BillOrderDto::getShopId));
|
|
|
+ Set<Long> shopIds = map.keySet();
|
|
|
+
|
|
|
+ for (Long shopId : shopIds) {
|
|
|
+ ProfitsBillOrder profitsBillOrder = new ProfitsBillOrder();
|
|
|
+ profitsBillOrder.setShopId(shopId);
|
|
|
+
|
|
|
+ // 获取商家id
|
|
|
+ Shop shop = iShopService.getById(shopId);
|
|
|
+ profitsBillOrder.setMerchantId(shop.getMerchantId());
|
|
|
+ //获取服务商id
|
|
|
+ if (shop.getMerchantId() != null) {
|
|
|
+ Merchant merchant = iMerchantService.getById(shop.getMerchantId());
|
|
|
+ profitsBillOrder.setAgentId(merchant.getAgentId());
|
|
|
+ }
|
|
|
+
|
|
|
+ profitsBillOrder.setYear(year);
|
|
|
+ profitsBillOrder.setMonth(month);
|
|
|
+ profitsBillOrder.setDay(day);
|
|
|
+
|
|
|
+ // 根据门店查询相关订单信息
|
|
|
+ List<BillOrderDto> billOrderDtoList = baseMapper.selectListByShopId(shopId, startDate, endDate);
|
|
|
+ // 根据门店查询发单订单信息
|
|
|
+ List<BillOrderDto> billOrderDtos = baseMapper.selectBillOrderByShopId(shopId, startDate, endDate);
|
|
|
+ for (DspWaimai waimai : dspWaimaiList) {
|
|
|
+ Integer orderType = waimai.getType();
|
|
|
+
|
|
|
+ // 门店外卖平台list
|
|
|
+ List<BillOrderDto> waimaiBillList = billOrderDtoList.stream().filter(bill -> bill.getOrderType().equals(orderType)).collect(Collectors.toList());
|
|
|
+ // 门店外卖平台发单list
|
|
|
+ List<BillOrderDto> waimaiBills= billOrderDtos.stream().filter(bill -> bill.getOrderType().equals(orderType)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isNotEmpty(waimaiBillList)) {
|
|
|
+ profitsBillOrder.setOrderType(orderType);
|
|
|
+
|
|
|
+ // 门店订单同步数量
|
|
|
+ Long orderSyncNum = (long) waimaiBillList.size();
|
|
|
+ profitsBillOrder.setOrderSyncNum(orderSyncNum);
|
|
|
+
|
|
|
+ // 发单量
|
|
|
+// Long orderBillNum = waimaiBillList.stream().filter(bill -> bill.getDeliveryStatus() > DeliveryStatusEnum.ORDERS_TO_BE_BILLED.getStatus()
|
|
|
+// || DeliveryStatusEnum.CANCEL.getStatus().equals(bill.getDeliveryStatus())).count();
|
|
|
+ Long orderBillNum = (long) waimaiBills.size();
|
|
|
+ profitsBillOrder.setOrderBillNum(orderBillNum);
|
|
|
+
|
|
|
+ // 完成量
|
|
|
+ Long orderCompleteNum = waimaiBillList.stream().filter(bill -> DeliveryStatusEnum.FINISH.getStatus().equals(bill.getDeliveryStatus())).count();
|
|
|
+ profitsBillOrder.setOrderCompleteNum(orderCompleteNum);
|
|
|
+
|
|
|
+ Date date1 = DateUtils.addDateDays(new Date(), -0);
|
|
|
+ profitsBillOrder.setCreateTime(date1);
|
|
|
+
|
|
|
+ baseMapper.insert(profitsBillOrder);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult selectOrderBillStatistics(Page page, SystemOrderDto orderDto) {
|
|
|
+ boolean flag = handleListSearchCondition(orderDto, new SysUser());
|
|
|
+ if (!flag) {
|
|
|
+ page.setRecords(Lists.newArrayList());
|
|
|
+ return new PageResult(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ orderDto.setCreateStartTime(handlDate(orderDto.getCreateStartTime()));
|
|
|
+ orderDto.setCreateEndTime(handlDate(orderDto.getCreateEndTime()));
|
|
|
+
|
|
|
+ // 查询所有外卖数据
|
|
|
+ List<BillOrderDto> list = baseMapper.selectBillOrderPage(page, orderDto);
|
|
|
+ for (BillOrderDto dto : list) {
|
|
|
+ // 门店名称
|
|
|
+ Shop shop = iShopService.getById(dto.getShopId());
|
|
|
+ if (Objects.nonNull(shop)) {
|
|
|
+ dto.setShopName(shop.getName());
|
|
|
+ // 商家名称
|
|
|
+ Merchant merchant = iMerchantService.getById(shop.getMerchantId());
|
|
|
+ if (Objects.nonNull(merchant)) {
|
|
|
+ dto.setMerchantName(merchant.getMerchantName());
|
|
|
+ dto.setMerchantMobile(merchant.getMobile());
|
|
|
+ // 代理商名称
|
|
|
+ Agent agent = iAgentService.getById(merchant.getAgentId());
|
|
|
+ if (Objects.nonNull(agent)) {
|
|
|
+ dto.setAgentName(agent.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dto.setOrderBillRate(dto.getOrderBillRate().setScale(2, BigDecimal.ROUND_FLOOR));
|
|
|
+ dto.setOrderCompleteRate(dto.getOrderCompleteRate().setScale(2, BigDecimal.ROUND_FLOOR));
|
|
|
+ }
|
|
|
+
|
|
|
+ page.setRecords(list);
|
|
|
+ return new PageResult(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String handlDate(String time) {
|
|
|
+ if (StringUtils.isNotBlank(time)) {
|
|
|
+ Date s = DateUtils.stringToDate(time, "yyyy-MM-dd HH:mm:ss");
|
|
|
+ String t = DateUtils.format(DateUtils.addDateDays(s, 1), "yyyy-MM-dd HH:mm:ss");
|
|
|
+ return t;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean handleListSearchCondition(SystemOrderDto order, SysUser user) {
|
|
|
+ boolean result = true;
|
|
|
+ if (StringUtils.isNotBlank(order.getMerchantName())) {
|
|
|
+ List<Long> merchantIds = iMerchantService.selectIdByName(order.getMerchantName());
|
|
|
+ if (CollectionUtils.isEmpty(merchantIds)) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ order.setMerchantIds(merchantIds);
|
|
|
+ }
|
|
|
+ if(UserTypeEnums.AGENT.getCode().equals(user.getType()) && user.getAgentId() != null) {
|
|
|
+ List<Long> agentIds = iAgentService.listAgent(user.getAgentId());
|
|
|
+ if (CollectionUtils.isEmpty(agentIds)) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ order.setAgentIds(agentIds);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(user.getAgentIds())) {
|
|
|
+ if (CollectionUtils.isEmpty(order.getAgentIds())) {
|
|
|
+ order.setAgentIds(user.getAgentIds());
|
|
|
+ } else {
|
|
|
+ order.getAgentIds().retainAll(user.getAgentIds());
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(order.getAgentIds())) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 新增订单门店查询按钮
|
|
|
+ if (StringUtils.isNotEmpty(order.getShopName())) {
|
|
|
+ List<Shop> shopList = iShopService.list(new QueryWrapper<Shop>().eq("deleted", 0)
|
|
|
+ .eq("status", 1).like("name", order.getShopName()));
|
|
|
+ List<Long> shopIds = shopList.stream().map(Shop::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(shopIds)) {
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ order.setShopIds(shopIds);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|