package com.gic.haoban.manage.web.controller.moment;

import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.api.dto.EnterpriseDTO;
import com.gic.haoban.manage.api.dto.moment.QwMomentPlanDTO;
import com.gic.haoban.manage.api.dto.moment.QwMomentPlanDataDTO;
import com.gic.haoban.manage.api.qdto.moment.PlanDataListQDTO;
import com.gic.haoban.manage.api.qdto.moment.QwMomentPlanQDTO;
import com.gic.haoban.manage.api.service.moment.QwMomentApiService;
import com.gic.haoban.manage.web.vo.moment.MomentDataExcelVO;
import com.gic.haoban.manage.web.vo.moment.MomentPlanExcelVO;
import com.gic.web.common.download.DownloadHandlerAbstract;
import com.gic.web.common.download.context.Context;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

@Service
public class MomentDataExcelHandler extends DownloadHandlerAbstract<MomentDataExcelVO> {

    @Autowired
    private QwMomentApiService qwMomentApiService ;
    @Override
    public List<MomentDataExcelVO> getData(Context context, String json, Integer currentPage) {
        PlanDataListQDTO qdto = JSON.parseObject(json, PlanDataListQDTO.class);
        BasePageInfo pageInfo = new BasePageInfo() ;
        pageInfo.setPageSize(this.getPageSize());
        pageInfo.setPageNum(currentPage);
        ServiceResponse<Page<QwMomentPlanDataDTO>> pageResp = this.qwMomentApiService.dataList(qdto);
        List<MomentDataExcelVO> voList = new ArrayList<>();
        if (null != pageResp && CollectionUtils.isNotEmpty(pageResp.getResult().getResult())) {
            EnterpriseDTO en = this.enterpriseService.getEnterpriseById(qdto.getEnterpriseId()) ;
            for(QwMomentPlanDataDTO item : pageResp.getResult().getResult()) {
                MomentDataExcelVO vo = EntityUtil.changeEntityByJSON(MomentDataExcelVO.class,item) ;
                voList.add(vo) ;
            }
        }
        return voList;
    }

    @Override
    public List<String> getColumnNames() {
        return new ArrayList<>() ;
    }

    @Override
    public List<String> getColumnNames(Context context) {
        String json = context.getDownloadReportDTO().getSearchDataParams();
        PlanDataListQDTO qdto = JSON.parseObject(json, PlanDataListQDTO.class);
        if(qdto.getType()==1) {
            return Arrays.asList("员工姓名",  "导购名称", "导购code","所属门店名称", "门店code","客户姓名","客户手机号","点赞时间");
        }else {
            return Arrays.asList("员工姓名",  "导购名称", "导购code","所属门店名称", "门店code","客户姓名","客户手机号","评论时间");
        }
    }

    @Override
    public LinkedHashMap<String, List<String>> doubleColumnNames() {
        return null;
    }

    @Override
    public List<String> getColumns() {
        return Arrays.asList("staffName",  "clerkName", "clerkCode","storeName", "storeCode","memberName","memberPhone","timeExcel");
    }
}
