package com.ruoyi.project.common.service.impl;

import com.google.common.collect.Lists;
import com.ruoyi.common.importExcel.excel.helper.BasicTableInfoHelper;
import com.ruoyi.common.importExcel.excel.tempInfo.AccountInfoHelper;
import com.ruoyi.common.importExcel.utils.ExcelUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.common.domain.Message;
import com.ruoyi.project.common.mapper.CommonMapper;
import com.ruoyi.project.common.service.ICommonService;
import com.ruoyi.project.common.service.ISseEmitterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xiewd
 */
@Service
public class CommonServiceImpl implements ICommonService {

    @Resource
    private CommonMapper commonMapper;
    @Resource
    private ISseEmitterService sseEmitterService;
    @Resource
    private RedisCache redisCache;

    /**
     *
     * @param type 取区域和代理商id ： seq_area_agent
     * @return
     */
    @Override
    public Long getCommonID(String type) {
        Long id = commonMapper.getCommonId(type);
        return id;
    }

    /**
     * 测试导入验证
     * @param tableInfo
     * @param customerInfoHelpers
     * @return
     */
    @Override
    public ExcelUtils.UploadResult<AccountInfoHelper> checkTransportBillInfo(BasicTableInfoHelper tableInfo, List<AccountInfoHelper> customerInfoHelpers) {
        return ExcelUtils.checkData(customerInfoHelpers, it -> {
            List<String> businessErrors = Lists.newArrayList();
//            if(StringUtils.isEmpty(it.getCustomerName())){
//                businessErrors.add("客户名称不为空");
//            }
            return businessErrors;
        });
    }

    /**
     * 测试导入验证后新增
     * @param basicTableInfoHelper
     * @param dataList
     * @return
     */
    @Override
    public  List<String> testSave(BasicTableInfoHelper basicTableInfoHelper, @NotEmpty List<AccountInfoHelper> dataList) {
        //导入成功
        return new ArrayList<>();
    }

    @Override
    public void test() {
//        String res = redisCache.generateSerialNumber("TXR");
//        sseEmitterService.sendMessageToUserId(SecurityUtils.getUserId(), true);
        List<Long> ids = new ArrayList<>();
        ids.add(1L);
        Message message = new Message();
        message.setMessageContent("测试推送消息");
        message.setMessageType("11");
        message.setCreateBy("1");
        sseEmitterService.sendSaveMessage(ids,message);
    }
}
