package com.xxfc.platform.order.biz;

import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.admin.feign.rest.UserRestInterface;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.mapper.BaseOrderMapper;
import com.xxfc.platform.order.rest.BaseOrderController;
import com.xxfc.platform.tour.feign.TourFeign;
import com.xxfc.platform.vehicle.entity.BranchCompany;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class BackgroundBaseOrderBiz extends BaseBiz<BaseOrderMapper, BaseOrder> implements UserRestInterface {
	@Autowired
	UserFeign userFeign;
	@Autowired
	VehicleFeign vehicleFeign;
	@Autowired
	TourFeign tourFeign;
	@Override
	public UserFeign getUserFeign() {
		return userFeign;
	}

	public ObjectRestResponse getAllOrderList(BaseOrderController.QueryOrderList dto) {
		if (dto.getStartTime() != null) {
			if (dto.getEndTime() == null) {
				dto.setEndTime(new Date().getTime());
			}
		}
		if (dto.getStatus()!=null  ) {
			if (dto.getStatus() == 7) {
				dto.setRefundStatus(2);
				dto.setStatus(null);
			}else if (dto.getStatus() == 8) {
				dto.setRefundStatus(3);
				dto.setStatus(null);
			}
		}
		Query query = new Query(dto);
		PageDataVO pageDataVO = PageDataVO.pageInfo(query, () -> mapper.getAllOrderList(query.getSuper()));
		return ObjectRestResponse.succ(pageDataVO);
	}
}
