package com.hys.app.service.erp.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hys.app.controller.erp.use.msg.MsgUtilClient;
import com.hys.app.controller.erp.use.msg.msgTemplate.MailMsgContant;
import com.hys.app.controller.erp.use.msg.msgTemplate.MailMsgDefault;
import com.hys.app.controller.erp.use.msg.msgTemplate.SystemMsgContent;
import com.hys.app.controller.erp.use.msg.msgTemplate.SystemMsgTemplate;
import com.hys.app.converter.erp.CompanyConverter;
import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.exception.ServiceException;
import com.hys.app.framework.util.StringUtil;
import com.hys.app.mapper.erp.CompanyBandMsgMapper;
import com.hys.app.mapper.erp.CompanyErpMapper;
import com.hys.app.mapper.system.AdminUserMapper;
import com.hys.app.model.erp.entity.*;
import com.hys.app.model.system.dos.AdminUser;
import com.hys.app.service.erp.CompanyBandMsgManager;
import com.hys.app.service.erp.CompanyErpManager;
import com.hys.app.service.erp.CompanyPackageManager;
import com.hys.app.util.PinYingUtil;
import com.hys.app.util.ValidateUtil;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 平台管理员业务类
 *
 * @author zh
 * @version v7.0
 * @since v7.0.0
 * 2018-06-20 20:38:26
 */
@Service
@AllArgsConstructor
public class CompanyBandMsgManagerImpl extends ServiceImpl<CompanyBandMsgMapper, CompanyBandMsg> implements CompanyBandMsgManager {

    private RedisTemplate redisTemplate;

    @Override
    public List<CompanyBandMsg> getCompanyBandMsg(Long companyId) {
        List<CompanyBandMsg> msgs = (List<CompanyBandMsg>) redisTemplate.opsForHash().get("companyTemplate", companyId.toString());
        if (CollUtil.isEmpty(msgs)) {
            msgs = list(new LambdaQueryWrapper<CompanyBandMsg>().eq(CompanyBandMsg::getCompanyId, companyId));
        }
        redisTemplate.opsForHash().put("companyTemplate", companyId.toString(), msgs);
        return msgs;
    }

    @Override
    public List<String> getCompanyBandMsgCode(Long companyId) {
        List<CompanyBandMsg> companyBandMsg = getCompanyBandMsg(companyId);
        return companyBandMsg.stream().map(CompanyBandMsg::getTemplateCode).collect(Collectors.toList());
    }
}
