package com.kiisoo.ic.job.detail;

import com.kiisoo.ic.customer.CustomerService;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
import com.kiisoo.ic.synchronous.entity.TurnBackDTO;
import com.kiisoo.ic.synchronous.entity.WxDataDTO;
import com.kiisoo.ic.wx.service.QWMailListManageService;
import com.lmax.disruptor.WorkHandler;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
public class DetailDTOMessageGroupConsumer implements WorkHandler<DetailDTOMessage> {

    int i = 0;
    /**
     * 处理事件， 如入库操作
     *
     * @param detailDtoMessage
     * @throws Exception
     */
    @Override
    public void onEvent(DetailDTOMessage detailDtoMessage) throws Exception {
        detailDtoMessage.setId(UUID.randomUUID().toString());
        String cpUserId = detailDtoMessage.getCpUserId();
        CustomerService customerService = detailDtoMessage.getCustomerService();
        PoiStoreStaffDOMapper poiStoreStaffDOMapper = detailDtoMessage.getPoiStoreStaffDOMapper();
        QWMailListManageService qwMailListManageService = detailDtoMessage.getQwMailListManageService();
        Long storeId = detailDtoMessage.getStoreId();
        List<Map<String,Object>> tagList = poiStoreStaffDOMapper.selectStaffTagByStoreId(storeId);

        try {
            qwMailListManageService.getCustomerNew(cpUserId, detailDtoMessage.getSumCustomer(), customerService, tagList);
        } catch (Exception e) {
            log.error("查询联系人失败：" + cpUserId, e);
        }
    }
}
