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.QwMomentPlanAttendDTO;
import com.gic.haoban.manage.api.dto.moment.QwMomentPlanDTO;
import com.gic.haoban.manage.api.qdto.moment.PlanClerkListQDTO;
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.MomentClerkExcelVO;
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 MomentClerkExcelHandler extends DownloadHandlerAbstract<MomentClerkExcelVO> {

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

    @Override
    public List<String> getColumnNames() {
        return Arrays.asList();
    }

    @Override
    public List<String> getColumnNames(Context context) {
        String json = context.getDownloadReportDTO().getSearchDataParams();
        PlanClerkListQDTO qdto = JSON.parseObject(json, PlanClerkListQDTO.class);
        if(qdto.getStatusFlag()==1) {
            return Arrays.asList("员工姓名", "员工id" ,  "导购名称", "导购code","所属门店名称", "门店code","完成情况","发布时间","点赞数","评论数");
        }else {
            return Arrays.asList("员工姓名", "员工id" ,  "导购名称", "导购code","所属门店名称", "门店code","下发失败原因");
        }
    }

    @Override
    public List<String> getColumns(Context context) {
        String json = context.getDownloadReportDTO().getSearchDataParams();
        PlanClerkListQDTO qdto = JSON.parseObject(json, PlanClerkListQDTO.class);
        if(qdto.getStatusFlag()==1) {
            return Arrays.asList("staffName", "staffId", "clerkName", "clerkCode","storeName", "storeCode","taskStatusExcel","sendTimeExcel","likeCount","commentCount");
        }else {
            return Arrays.asList("staffName", "staffId", "clerkName", "clerkCode","storeName", "storeCode","reason");
        }
    }

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

    @Override
    public List<String> getColumns() {
        return Arrays.asList();
    }
}
