package com.iotechn.unimall.admin.api.dashboard;

import com.iotechn.unimall.core.exception.ServiceException;
import com.iotechn.unimall.data.domain.AdminDO;
import com.iotechn.unimall.data.dto.DashboardIntegralDTO;
import com.iotechn.unimall.data.mapper.*;
import com.iotechn.unimall.data.model.KVModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by rize on 2019/7/15.
 */
@Service
public class DashboardServiceImpl implements DashboardService {

    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Object integral(Long adminId,Long companyId) throws ServiceException {
        DashboardIntegralDTO dto = new DashboardIntegralDTO();
        AdminDO adminDO = adminMapper.selectById(adminId);
        dto.setCompanyId(adminDO.getCompanyId());
        Integer days = 7;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        String startDay = sdf.format(new Date(System.currentTimeMillis() - 1000l * 60 * 60 * 24 * days));
        SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
        List<Object[]> orderCount = new LinkedList<>();
        Object[] orderCountNameArray = new Object[days];
        Object[] orderCountValueArray = new Object[days];
        orderCount.add(orderCountNameArray);
        orderCount.add(orderCountValueArray);
        dto.setDaysOrder(orderCount);
        List<Object[]> orderSum = new LinkedList<>();
        Object[] orderSumNameArray = new Object[days];
        Object[] orderSumValueArray = new Object[days];
        orderSum.add(orderSumNameArray);
        orderSum.add(orderSumValueArray);
        dto.setDaysSum(orderSum);

        return dto;
    }
    @Override
    public String getAdminId(Long adminId) throws ServiceException {
        return adminId+"";
    }
}
