package cn.com.ctop.kuaishou.modules.report.service.impl;

import cn.com.ctop.kuaishou.modules.report.mapper.KsNewGroupReportMapper;
import cn.com.ctop.kuaishou.modules.report.service.IKsNewGroupReportService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 *  Created By JQ.bi on 2020.11.2
 */
@Slf4j
@Service
public class KsNewGroupReportServiceImpl implements IKsNewGroupReportService {

    @Autowired
    private KsNewGroupReportMapper NewGroupReportMapper;

    @Override
    public List<JSONObject> getKsNewGroupGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order) {
        return NewGroupReportMapper.queryKsNewGroupGroupByAccount(accountIds,startDate,endDate,target,order);
    }

    @Override
    public List<JSONObject> getKsNewGroupGroupByStatDate(JSONArray accountIds, String startDate, String endDate) {
        List<JSONObject> resultList= new ArrayList<>();
        try {
            if(DateUtils.isMoreSixMonth(startDate,endDate)){
                resultList = NewGroupReportMapper.queryKsNewGroupGroupByMonth(accountIds,startDate,endDate);
            }
            else {
                resultList = NewGroupReportMapper.queryKsNewGroupGroupByStatDate(accountIds,startDate,endDate);
            }
        } catch (ParseException e) {
            log.error(e.getMessage());
        }
        return resultList;
    }

    @Override
    public JSONObject getSumNewGroupBy(JSONArray accountIds, String startDate, String endDate) {
        return NewGroupReportMapper.querySumNewGroupBy(accountIds,startDate,endDate);
    }

}
