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

import cn.com.ctop.kuaishou.modules.report.mapper.KsNewPlanReportMapper;
import cn.com.ctop.kuaishou.modules.report.service.IKsNewPlanReportService;
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 KsNewPlanReportServiceImpl  implements IKsNewPlanReportService {

    @Autowired
    private KsNewPlanReportMapper newPlanReportMapper;

    @Override
    public List<JSONObject> getKsNewPlanGroupByAccount(JSONArray accountIds, String startDate, String endDate, String target, String order) {
        return newPlanReportMapper.queryKsNewPlanGroupByAccount(accountIds,startDate,endDate,target,order);
    }

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

    @Override
    public JSONObject getSumNewPlanBy(JSONArray accountIds, String startDate, String endDate) {
        return newPlanReportMapper.querySumNewPlanBy(accountIds,startDate,endDate);
    }

    @Override
    public List<JSONObject> getAllOperator() {
        return newPlanReportMapper.queryAllOperator();
    }

    @Override
    public JSONArray getAccountIdsByUserId(String userId) {
        return newPlanReportMapper.queryAccountIdsByUserId(userId);
    }

    @Override
    public JSONArray getAccountIdsByMedia() {
        return newPlanReportMapper.queryAccountIdsByMedia();
    }

}
