package com.lightinit.hsdataplatform.impl.admin;

import com.lightinit.hsdataplatform.mapper.OrderMapper;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.YearMonthDayModel;
import com.lightinit.hsdataplatform.service.admin.IOrderTradeService;
import com.lightinit.hsdataplatform.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class OrderTradeServiceImpl implements IOrderTradeService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public ResultState queryList(String year, String month, String day) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        ResultState resultState = new ResultState();
        HashMap<String, Object> map = new HashMap<>();
        List<String> names = new ArrayList<>();
        List<Long> counts = new ArrayList<>();
        List<YearMonthDayModel> list =  orderMapper.queryCountList(year,month,day);
        for(YearMonthDayModel monthDayModel : list) {
            if((year!=null && year !="") && (month ==null || month=="" )) {
                names.add(monthDayModel.getMonth()+"月");
                counts.add(monthDayModel.getCount());
            } else if((year!=null && year !="") && (month !=null && month!="")) {
                names.add(monthDayModel.getDay()+"日");
                counts.add(monthDayModel.getCount());
            }else {
                if(null==monthDayModel.getYear()) {
                    names.add("未知"+"年");
                }else {
                    names.add(monthDayModel.getYear()+"年");
                }

                counts.add(monthDayModel.getCount());
            }

        }
        map.put("names",names);
        map.put("counts",counts);
        resultState.setData(map);
        return resultState;
    }
}
