package org.jeecg.modules.adweb.site.service;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.adweb.site.entity.AdwebSite;
import org.jeecg.modules.adweb.site.mapper.AdwebSiteMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 站点管理服务类
 */
@Service
public class SiteManageService {
    
    protected Logger logger = LoggerFactory.getLogger(SiteManageService.class);
    @Resource
    private AdwebSiteMapper adwebSiteMapper;


    public String getSiteCode(String siteCode) {
        if (StringUtils.isEmpty(siteCode)) {
            siteCode = RandomUtil.randomStringUpper(6);

            LambdaQueryWrapper<AdwebSite> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(AdwebSite::getCode, siteCode);
            List<AdwebSite> list = adwebSiteMapper.selectList(queryWrapper);
            if (!list.isEmpty()) {
                siteCode = getSiteCode(null);
            }
        }
        return siteCode;
    }
}
