package com.jsowell.pile.service.impl;

import com.alibaba.fastjson2.JSON;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.jsowell.adapay.service.AdapayService;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.DelFlagEnum;
import com.jsowell.common.enums.MemberWalletEnum;
import com.jsowell.common.enums.uniapp.OccupyOrderPayStatusEnum;
import com.jsowell.common.enums.uniapp.OccupyOrderStatusEnum;
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.enums.ykc.ScenarioEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.PageUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.OrderPileOccupy;
import com.jsowell.pile.domain.ykcCommond.RemoteControlGroundLockCommand;
import com.jsowell.pile.dto.*;
import com.jsowell.pile.mapper.OrderPileOccupyMapper;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.base.PileInfoVO;
import com.jsowell.pile.vo.uniapp.MemberVO;
import com.jsowell.pile.vo.uniapp.OccupyOrderDetailVO;
import com.jsowell.pile.vo.uniapp.OrderPileOccupyVO;
import com.jsowell.pile.vo.web.BillingTemplateVO;
import com.jsowell.pile.vo.web.OccupyOrderVO;
import com.jsowell.pile.vo.web.OrderListVO;
import com.jsowell.pile.vo.web.UpdateMemberBalanceDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Slf4j
@Service
public class OrderPileOccupyServiceImpl implements OrderPileOccupyService {

    @Resource
    private OrderPileOccupyMapper orderPileOccupyMapper;

    @Resource
    private IPileBasicInfoService pileBasicInfoService;

    @Resource
    private IOrderBasicInfoService orderBasicInfoService;

    @Resource
    private IPileBillingTemplateService pileBillingTemplateService;

    @Resource
    private AdapayService adapayService;

    @Resource
    private IMemberBasicInfoService memberBasicInfoService;

    @Autowired
    private YKCPushCommandService ykcPushCommandService;

    @Autowired
    private OrderPileOccupyService orderPileOccupyService;

    @Autowired
    private RedisCache redisCache;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return orderPileOccupyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(OrderPileOccupy record) {
        return orderPileOccupyMapper.insert(record);
    }

    @Override
    public int insertOrUpdate(OrderPileOccupy record) {
        return orderPileOccupyMapper.insertOrUpdate(record);
    }

    @Override
    public int insertOrUpdateSelective(OrderPileOccupy record) {
        return orderPileOccupyMapper.insertOrUpdateSelective(record);
    }

    @Override
    public int insertSelective(OrderPileOccupy record) {
        return orderPileOccupyMapper.insertSelective(record);
    }

    @Override
    public OrderPileOccupy selectByPrimaryKey(Integer id) {
        return orderPileOccupyMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(OrderPileOccupy record) {
        return orderPileOccupyMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(OrderPileOccupy record) {
        return orderPileOccupyMapper.updateByPrimaryKey(record);
    }

    @Override
    public int updateBatch(List<OrderPileOccupy> list) {
        return orderPileOccupyMapper.updateBatch(list);
    }

    @Override
    public int updateBatchSelective(List<OrderPileOccupy> list) {
        return orderPileOccupyMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert(List<OrderPileOccupy> list) {
        return orderPileOccupyMapper.batchInsert(list);
    }

    /**
     * 根据占桩订单编号查询占桩订单
     *
     * @param occupyCode 占桩订单编号
     * @return
     */
    @Override
    public OrderPileOccupy queryByOccupyCode(String occupyCode) {
        if (StringUtils.isBlank(occupyCode)) {
            return null;
        }
        return orderPileOccupyMapper.queryByOccupyCode(occupyCode);
    }

    @Override
    public List<OrderPileOccupy> selectOrderPileOccupyList(OrderPileOccupy orderPileOccupy) {
        return orderPileOccupyMapper.selectOrderPileOccupyList(orderPileOccupy);
    }

    @Override
    public List<OccupyOrderVO> getOrderPileOccupyList(OrderPileOccupy orderPileOccupy) {
        return orderPileOccupyMapper.getOrderPileOccupyList(orderPileOccupy);
    }

    /**
     * 查询占桩订单列表
     *
     * @param dto
     * @return
     */
    @Override
    public List<OrderPileOccupy> queryOccupyOrderList(QueryOccupyOrderDTO dto) {
        return orderPileOccupyMapper.queryOccupyOrderList(dto);
    }

    /**
     * 生成占桩订单
     * 在会员操作降地锁后，就生成占桩订单
     *
     * @param dto 会员id  充电桩编号  充电桩枪口号
     */
    @Override
    public String generateOccupyPileOrder(GenerateOccupyOrderDTO dto) {
        String memberId = dto.getMemberId();
        String pileSn = dto.getPileSn();
        String connectorCode = dto.getConnectorCode();

        String redisKey = CacheConstants.GROUND_LOCK_OCCUPY_ORDER + pileSn + connectorCode;
        String cacheObject = redisCache.getCacheObject(redisKey);
        if (StringUtils.isNotBlank(cacheObject)) {
            throw new BusinessException(ReturnCodeEnum.CODE_HAS_OCCUPY_PILE_ORDER_ERROR);
        }

        // 创建占桩订单
        OrderPileOccupy orderPileOccupy = new OrderPileOccupy();
        String occupyCode = "OP" + IdUtils.getOrderCode();
        orderPileOccupy.setOccupyCode(occupyCode);
        orderPileOccupy.setMemberId(memberId);
        orderPileOccupy.setStatus(OccupyOrderStatusEnum.DRAFT_ORDER.getCode()); // 草稿单
        orderPileOccupy.setPayStatus(Constants.TWO); // 无需支付
        orderPileOccupy.setPileSn(pileSn);
        PileInfoVO pileInfoVO = pileBasicInfoService.selectPileInfoBySn(pileSn);
        if (pileInfoVO != null) {
            orderPileOccupy.setStationId(pileInfoVO.getStationId());
        }
        orderPileOccupy.setConnectorCode(connectorCode);
        orderPileOccupy.setPileConnectorCode(pileSn + connectorCode);
        // orderPileOccupy.setStartTime(DateUtils.getNowDate());
        orderPileOccupy.setDelFlag(DelFlagEnum.NORMAL.getValue());
        orderPileOccupyMapper.insertSelective(orderPileOccupy);

        // 放缓存
        redisCache.setCacheObject(redisKey, occupyCode, CacheConstants.cache_expire_time_10d);

        return orderPileOccupy.getOccupyCode();
    }

    /**
     * 占桩订单停止计费/停止占桩订单计费
     * 收到地锁升起指令，调用这个方法，停止计时
     *
     * @param pileSn        充电站编号
     * @param connectorCode 枪口号
     */
    @Override
    public void stopOccupyPileOrder(String pileSn, String connectorCode) {
        log.info("桩号：{}， 枪口：{}， 停止占桩订单计费", pileSn, connectorCode);
        // 根据充电站sn和枪口号，查询占桩中的占桩订单
        OrderPileOccupy orderPileOccupy = getOccupiedOrder(pileSn, connectorCode);
        if (orderPileOccupy == null) {
            return;
        }
        // 设置结束时间
        orderPileOccupy.setEndTime(DateUtils.getNowDate());

        // 计算金额
        BigDecimal orderAmount = calculateOccupyPileOrderAmount(orderPileOccupy);

        if (orderAmount.compareTo(BigDecimal.ZERO) > 0) {
            // 需要支付金额，订单挂起
            orderPileOccupy.setStatus(Constants.TWO); // 2-订单挂起
        } else {
            // 订单金额为0
            orderPileOccupy.setPayStatus(Constants.TWO); // 2-无需支付
            orderPileOccupy.setStatus(Constants.ONE); // 1-订单完成
        }
        orderPileOccupy.setOrderAmount(orderAmount);
        // 更新数据库
        orderPileOccupyMapper.updateByPrimaryKeySelective(orderPileOccupy);
    }

    /**
     * 计算占桩订单金额
     * calculateTheAmountOfTheOccupancyOrder
     */
    private BigDecimal calculateOccupyPileOrderAmount(OrderPileOccupy orderPileOccupy) {
        log.info("计算占桩订单金额 start:{}", JSON.toJSONString(orderPileOccupy));
        BigDecimal resultAmount = BigDecimal.ZERO;
        String occupyCode = orderPileOccupy.getOccupyCode();
        Date startTime = orderPileOccupy.getStartTime(); // 占桩开始时间
        Date endTime = orderPileOccupy.getEndTime(); // 占桩结束时间

        /*
         查新站点计费模板
         */
        BillingTemplateVO billingTemplate = pileBillingTemplateService.queryUsedBillingTemplate(orderPileOccupy.getStationId());
        if (billingTemplate == null) {
            log.info("计算占桩订单金额-查询站点:{}计费模板为空, 不收取占桩费用", orderPileOccupy.getStationId());
            return resultAmount;
        }
        Integer freeTime = billingTemplate.getFreeTime(); // 免费时长
        BigDecimal occupyFee = billingTemplate.getOccupyFee(); // 占桩费率
        if (freeTime == null || occupyFee == null) {
            log.info("计算占桩订单金额-站点:{}计费模板未设置免费时长和占桩费率, 不收取占桩费用", orderPileOccupy.getStationId());
            return resultAmount;
        }

        // 占桩时长
        long occupyTime = DateUtils.intervalTime(startTime, endTime); // 22
        if (freeTime > occupyTime) {
            log.info("计算占桩订单金额-站点:{}的占桩订单:{}, 免费时长:{}大于占桩时长:{}, 不收取占桩费用", orderPileOccupy.getStationId(), occupyCode, freeTime, occupyTime);
            return resultAmount;
        }

        /*
        查询会员在占用时段内有没有充电订单
         */
        QueryOrderDTO dto = new QueryOrderDTO();
        dto.setMemberId(orderPileOccupy.getMemberId());
        dto.setStationId(orderPileOccupy.getStationId());
        // 查询在占桩期间创建的订单
        dto.setStartTime(DateUtils.formatDateTime(startTime));
        dto.setEndTime(DateUtils.formatDateTime(endTime));
        List<OrderListVO> orderListVOS = orderBasicInfoService.selectOrderBasicInfoList(dto);

        /*
        计算充电时长
         */
        long sumChargingTime = 0;
        for (OrderListVO orderListVO : orderListVOS) {
            String chargeStartTime = orderListVO.getChargeStartTime();
            String chargeEndTime = orderListVO.getChargeEndTime();
            // 如果没有开始时间或者结束时间，就不计入充电时长
            if (StringUtils.isBlank(chargeStartTime) || StringUtils.isBlank(chargeEndTime)) {
                continue;
            }
            long l = DateUtils.intervalTime(chargeStartTime, chargeEndTime);
            sumChargingTime = sumChargingTime + l; // 17
        }

        /*
         计算应收金额
         应收金额 = （总占用时长 - （免费时长 + 充电时长）） * 占桩费率
         */
        BigDecimal totalOccupyTime = new BigDecimal(occupyTime + ""); // 22
        BigDecimal totalFreeTime = new BigDecimal(freeTime).add(new BigDecimal(sumChargingTime)); // 27
        log.info("totalOccupyTime:{}, totalFreeTime:{}", totalOccupyTime, totalFreeTime);
        if (totalFreeTime.compareTo(totalOccupyTime) >= 0) {
            log.info("计算占桩订单金额-站点:{}的占桩订单:{}, 总免费时长:{}大于占桩时长:{}, 不收取占桩费用", orderPileOccupy.getStationId(), occupyCode, totalFreeTime, totalOccupyTime);
            return resultAmount;
        }
        // 需要计费的时间
        BigDecimal time = totalOccupyTime.subtract(totalFreeTime);
        resultAmount = time.multiply(occupyFee);
        BigDecimal maxOccupyFee = billingTemplate.getMaxOccupyFee();
        if (Objects.isNull(maxOccupyFee)) {
            maxOccupyFee = new BigDecimal("100");
        }
        if (resultAmount.compareTo(maxOccupyFee) > 0) {
            // 计算出来的费用高于计费模板中设置的最高占桩费用，设置占桩费为计费模板中的费用
            resultAmount = maxOccupyFee;
        }
        log.info("计算占桩订单金额 end:{}", JSON.toJSONString(orderPileOccupy));
        return resultAmount;
    }

    public static void main(String[] args) {
        long l = DateUtils.intervalTime("2023-08-21 17:19:06", "2023-08-21 17:36:56");
        long l2 = DateUtils.intervalTime("2023-08-21 17:16:56", "2023-08-21 17:38:18");
        System.out.println(l2);
    }

    /**
     * 根据会员id查询挂起状态占桩订单
     */
    @Override
    public List<OrderPileOccupy> queryHangUpOrderByMemberId(String memberId) {
        return orderPileOccupyMapper.queryHangUpOrderByMemberId(memberId);
    }

    /**
     * 通过memberId查询未支付状态订单
     *
     * @param memberId
     * @return
     */
    @Override
    public OrderPileOccupy queryUnPayOrderByMemberId(String memberId) {
        return orderPileOccupyMapper.queryUnPayOrderByMemberId(memberId);
    }

    /**
     * 查询占桩订单列表
     *
     * @param dto
     * @return
     */
    @Override
    public PageResponse getOccupyOrderInfo(QueryOccupyOrderDTO dto) {
        int pageNum = dto.getPageNum() == 0 ? 1 : dto.getPageNum();
        int pageSize = dto.getPageSize() == 0 ? 10 : dto.getPageSize();
        // 分页
        PageUtils.startPage(pageNum, pageSize);
        List<OrderPileOccupyVO> list = orderPileOccupyMapper.getOccupyOrderInfo(dto);
        PageInfo<OrderPileOccupyVO> pageInfo = new PageInfo<>(list);

        for (OrderPileOccupyVO orderPileOccupyVO : pageInfo.getList()) {
            // 订单状态
            orderPileOccupyVO.setStatus(OccupyOrderStatusEnum.getValueByCode(orderPileOccupyVO.getStatus()));
            // 支付状态
            orderPileOccupyVO.setPayStatus(OccupyOrderPayStatusEnum.getValueByCode(orderPileOccupyVO.getPayStatus()));
        }

        PageResponse pageResponse = PageResponse.builder()
                .pageSize(pageSize)
                .pageNum(pageNum)
                .list(pageInfo.getList())
                .pages(pageInfo.getPages())
                .total(pageInfo.getTotal())
                .build();
        return pageResponse;
    }

    /**
     * 根据桩编号、枪口号查询最近一条占桩订单
     * draft
     *
     * @param pileSn
     * @param connectorCode
     * @return
     */
    @Override
    public OrderPileOccupy getDraftOccupyOrder(String pileSn, String connectorCode) {
        List<OrderPileOccupy> list = orderPileOccupyMapper.queryDraftOccupyOrder(pileSn, connectorCode);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        if (list.size() > 1) {
            List<Integer> collect = list.stream().map(OrderPileOccupy::getId).collect(Collectors.toList());
            log.info("根据pileSn:{}, connectorCode:{}, 查询出多条草稿状态的占桩订单, ids:{}", pileSn, connectorCode, collect);
        }
        return list.get(0);
    }

    /**
     * 查询占桩中的订单
     *
     * @param pileSn
     * @param connectorCode
     * @return
     */
    public OrderPileOccupy getOccupiedOrder(String pileSn, String connectorCode) {
        OrderPileOccupy result = null;

        // 查缓存中的占桩订单编号
        String redisKey = CacheConstants.GROUND_LOCK_OCCUPY_ORDER + pileSn + connectorCode;
        String orderCode = redisCache.getCacheObject(redisKey);
        if (StringUtils.isNotBlank(orderCode)) {
            result = queryByOccupyCode(orderCode);
        } else {
            List<OrderPileOccupy> list = orderPileOccupyMapper.queryOccupiedOrder(pileSn, connectorCode);
            if (CollectionUtils.isNotEmpty(list)) {
                if (list.size() > 1) {
                    List<Integer> collect = list.stream().map(OrderPileOccupy::getId).collect(Collectors.toList());
                    log.info("根据pileSn:{}, connectorCode:{}, 查询出多条占桩中的占桩订单, ids:{}", pileSn, connectorCode, collect);
                }
                result = list.get(0);
            }
        }
        return result;
    }

    @Override
    public void remoteGroundLock(RemoteGroundLockDTO dto) {
        log.info("控制地锁升降并生成占桩订单 params:{}", JSON.toJSONString(dto));
        // 如果是降锁生成占桩订单
        if (StringUtils.equals(dto.getOperate(), Constants.ZERO)) {
            // 生成占桩订单
            GenerateOccupyOrderDTO generateOccupyOrderDTO = new GenerateOccupyOrderDTO();
            generateOccupyOrderDTO.setMemberId(dto.getMemberId());
            generateOccupyOrderDTO.setPileSn(dto.getPileSn());
            generateOccupyOrderDTO.setConnectorCode(dto.getConnectorCode());
            // 生成占桩订单(草稿单)
            orderPileOccupyService.generateOccupyPileOrder(generateOccupyOrderDTO);
        }

        // 控制地锁升降
        RemoteControlGroundLockCommand command = new RemoteControlGroundLockCommand();
        command.setPileSn(dto.getPileSn());
        command.setConnectorCode(dto.getConnectorCode());
        command.setOperate(dto.getOperate());
        ykcPushCommandService.pushRemoteControlGroundLock(command);
    }

    /**
     * 获取占桩订单详情
     *
     * @param occupyCode
     */
    @Override
    public OccupyOrderDetailVO getOccupyOrderDetail(String occupyCode) {
        OccupyOrderDetailVO vo = orderPileOccupyMapper.getOccupyOrderDetail(occupyCode);
        // 订单状态
        vo.setOrderStatus(OccupyOrderStatusEnum.getValueByCode(vo.getOrderStatus()));
        // 支付状态
        vo.setPayStatus(OccupyOrderPayStatusEnum.getValueByCode(vo.getPayStatus()));
        if (vo.getEndTime() != null && vo.getStartTime() != null) {
            // 计算占桩时长
            vo.setOccupyTime(DateUtils.getDatePoor(DateUtils.parseDate(vo.getEndTime()), DateUtils.parseDate(vo.getStartTime())));
        }
        return vo;
    }

    /**
     * 使该笔订单免费/修改订单金额（后管用）
     *
     * @param dto
     * @return
     */
    @Override
    public int updateOrderInfoForWeb(MakeOrderFreeDTO dto) {
        // 先取type
        String type = dto.getType();
        if (StringUtils.equals("1", type)) {
            // 直接免费
            return orderPileOccupyMapper.makeOrderFree(dto.getOccupyCode());
        } else {
            // 修改订单金额
            OrderPileOccupy occupy = selectByPrimaryKey(dto.getId().intValue());
            BigDecimal orderAmount = occupy.getOrderAmount();
            if (orderAmount.subtract(dto.getOrderAmount()).compareTo(BigDecimal.ZERO) < 0 ) {
                // 说明改的金额要比实际订单金额大，不予修改
                return 0;
            }
            occupy.setOrderAmount(dto.getOrderAmount());

            return orderPileOccupyMapper.updateByPrimaryKeySelective(occupy);
        }
    }

    @Override
    public void closeOccupyPileOrder(String pileSn, String connectorCode) {
        log.info("关闭占桩订单 pileSn:{}, connectorCode:{}", pileSn, connectorCode);
        // 查询草稿状态的占桩订单
        OrderPileOccupy draftOccupyOrder = getDraftOccupyOrder(pileSn, connectorCode);
        // 关闭草稿订单
        if (draftOccupyOrder != null) {
            draftOccupyOrder.setStatus(Constants.ONE);
            draftOccupyOrder.setPayStatus(Constants.TWO);
            updateByPrimaryKey(draftOccupyOrder);
        }
    }

    /*
     * 支付占桩订单
     *
     * @param dto
     * @return
     */
    @Override
    public Map<String, Object> payOccupyPileOrder(PayOrderDTO dto) {
        // 查询占桩订单详情
        OrderPileOccupy orderPileOccupy = queryByOccupyCode(dto.getOrderCode());
        if (orderPileOccupy == null) {
            throw new BusinessException(ReturnCodeEnum.CODE_QUERY_ORDER_INFO_IS_NULL);
        }
        // 支付方式
        Map<String, Object> resultMap = Maps.newHashMap();
        if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_BALANCE.getValue())) {
            // 余额支付占桩订单
            balancePayOccupyPileOrder(dto);
        } else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WECHATPAY.getValue())) {
            // 返回支付参数
            dto.setGoodsTitle("占桩费用");
            dto.setGoodsDesc("占桩订单金额");
            dto.setType(ScenarioEnum.OCCUPY.getValue());
            Map<String, Object> weixinMap = adapayService.createPayment(dto);
            resultMap.put("weixinMap", weixinMap);
        } else if (StringUtils.equals(dto.getPayMode(), OrderPayModeEnum.PAYMENT_OF_WHITELIST.getValue())) { // 白名单支付
            whiteListPayOccupyPileOrder(dto);
        }
        return resultMap;
    }

    private void balancePayOccupyPileOrder(PayOrderDTO dto) {
        // 查会员余额
        MemberVO memberVO = memberBasicInfoService.queryMemberInfoByMemberId(dto.getMemberId());
        if (memberVO == null) {
            throw new BusinessException(ReturnCodeEnum.CODE_MEMBER_NOT_FOUND_ERROR);
        }

        // 校验金额
        BigDecimal principalBalance = memberVO.getPrincipalBalance();
        if (dto.getPayAmount().compareTo(principalBalance) > 0) {
            throw new BusinessException(ReturnCodeEnum.CODE_BALANCE_IS_INSUFFICIENT);
        }
        // 扣除会员余额
        UpdateMemberBalanceDTO updateMemberBalanceDTO = new UpdateMemberBalanceDTO();
        updateMemberBalanceDTO.setMemberId(dto.getMemberId());
        updateMemberBalanceDTO.setUpdatePrincipalBalance(dto.getPayAmount()); // 更新会员本金金额，单位元
        updateMemberBalanceDTO.setType(MemberWalletEnum.TYPE_OUT.getValue());
        updateMemberBalanceDTO.setSubType(MemberWalletEnum.SUBTYPE_PAYMENT_FOR_ORDER.getValue());
        memberBasicInfoService.updateMemberBalance(updateMemberBalanceDTO);

        // 更新占桩订单状态
        OrderPileOccupy orderPileOccupy = queryByOccupyCode(dto.getOrderCode());
        orderPileOccupy.setStatus(OccupyOrderStatusEnum.ORDER_COMPLETE.getValue());
        orderPileOccupy.setPayStatus(OccupyOrderPayStatusEnum.PAYMENT_COMPLETION.getValue());
        updateByPrimaryKeySelective(orderPileOccupy);
    }

    private void whiteListPayOccupyPileOrder(PayOrderDTO dto) {
        // 更新占桩订单状态
        OrderPileOccupy orderPileOccupy = queryByOccupyCode(dto.getOrderCode());
        orderPileOccupy.setStatus(OccupyOrderStatusEnum.ORDER_COMPLETE.getValue());
        orderPileOccupy.setPayStatus(OccupyOrderPayStatusEnum.NO_PAYMENT_REQUIRED.getValue());
        updateByPrimaryKeySelective(orderPileOccupy);
    }
}
