package com.goafanti.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.goafanti.common.dao.TOrderNewMapper;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.order.bo.*;
import com.goafanti.order.bo.outStatistics.OutOrderSalesSourceAmount;
import com.goafanti.order.service.OrderStatisticsService;
import groovy.util.logging.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

@Service
@Log4j
public class OrderStatisticsServiceImpl extends BaseMybatisDao<TOrderNewMapper> implements OrderStatisticsService {
	@Autowired
	private TOrderNewMapper tOrderNewMapper;

	@Override
	public Object orderSalesSource(InputOrderSalesSource in) {
		if (in.getSort()==null)in.setSort(1);
		if(in.getEndDate()!=null)in.setEndDate(in.getEndDate()+" 23:59:59");
		if (in.getDeps()!=null){
			List<String> ls= JSON.parseArray(in.getDeps(),String.class);
			in.setListDep(ls);
		}
		if (in.getSort()==1){
			List<OutOrderSalesSource> outOrderSalesSources = tOrderNewMapper.orderSalesSource(in);
			return outOrderSalesSources;
		}else if (in.getSort()==0){
			List<OutOrderSalesSourceAmount> outOrderSalesSources = tOrderNewMapper.orderSalesSourceAmount(in);
			return outOrderSalesSources;
		}
		return null;
	}

}
