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

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.haoban.manage.web.vo.open.OpenQwAlarmLogExcelVO;
import com.gic.haoban.task.manage.api.dto.open.OpenQwAlarmLogDTO;
import com.gic.haoban.task.manage.api.qdto.open.AlarmWordsLogQDTO;
import com.gic.haoban.task.manage.api.service.OpenQwApiService;
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 OpenAlarmWordsLogExcelHandler extends DownloadHandlerAbstract<OpenQwAlarmLogExcelVO> {

    @Autowired
    private OpenQwApiService openQwApiService ;

    @Override
    public List<OpenQwAlarmLogExcelVO> getData(Context context, String json, Integer currentPage) {
        AlarmWordsLogQDTO qdto = JSON.parseObject(json, AlarmWordsLogQDTO.class);
        BasePageInfo pageInfo = new BasePageInfo() ;
        pageInfo.setPageSize(this.getPageSize());
        pageInfo.setPageNum(currentPage);
        ServiceResponse<Page<OpenQwAlarmLogDTO>> page = this.openQwApiService.alarmWordsLogPage(qdto, pageInfo);
        List<OpenQwAlarmLogExcelVO> voList = new ArrayList<>();
        if (null != page && CollectionUtils.isNotEmpty(page.getResult().getResult())) {
            for(OpenQwAlarmLogDTO item : page.getResult().getResult()) {
                OpenQwAlarmLogExcelVO vo = EntityUtil.changeEntityByJSON(OpenQwAlarmLogExcelVO.class,item) ;
                if(item.getChatType()==1) {
                }else {
                }
                voList.add(vo) ;
            }
        }
        return voList;
    }

    @Override
    public List<String> getColumnNames() {
        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", "chatTypeExcel","memberName","memberNick","memberPhone","groupChatName","alarmWords","content","createTimeExcel");
    }

    @Override
    public Integer getPageSize() {
        return 1000 ;
    }
}
