package com.chinaweal.aiccs.aiccs.expelled.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaweal.aiccs.aiccs.expelled.entity.ExpelledEntInfo;
import com.chinaweal.aiccs.aiccs.expelled.mapper.ExpelledEntInfoMapper;
import com.chinaweal.aiccs.aiccs.expelled.service.IExpelledEntInfoService;
import com.chinaweal.aiccs.utils.BeanUtil;
import com.chinaweal.aiccs.utils.DocumentNoGenerator;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @Description: 市场主体拟除名名单企业信息表实现类
 * @Author: TiAmo-cc
 * @Email: 1049976610@qq.com
 * @Date: 2026/1/7 10:35
 */
@Service
public class ExpelledEntInfoServiceImpl extends ServiceImpl<ExpelledEntInfoMapper, ExpelledEntInfo> implements IExpelledEntInfoService {

    @Override
    public void saveExpelledEntInfo(ExpelledEntInfo query) {
        ExpelledEntInfo entInfo = getExpelledEntInfo(query.getBizId(), query.getExpelledId());
        if (entInfo == null) {
            entInfo = new ExpelledEntInfo();
            entInfo.setId(UUID.randomUUID().toString());
            entInfo.setNoticeNo(generateNoticeNo());
            entInfo.setSendStatus("0");
        }
        BeanUtil.copyBean(query, entInfo);
        saveOrUpdate(entInfo);
    }

    @Override
    public ExpelledEntInfo getExpelledEntInfo(String bizId, String expelledId) {
        return getOne(new LambdaQueryWrapper<ExpelledEntInfo>().eq(ExpelledEntInfo::getBizId, bizId).eq(ExpelledEntInfo::getExpelledId, expelledId));
    }

    @Override
    public ExpelledEntInfo getExpelledEntInfo(String noticeNo) {
        return getOne(new LambdaQueryWrapper<ExpelledEntInfo>().eq(ExpelledEntInfo::getNoticeNo, noticeNo));
    }

    @Override
    public String generateNoticeNo() {
        String noticeNo = DocumentNoGenerator.generateNoticeNo();
        ExpelledEntInfo entInfo = getExpelledEntInfo(noticeNo);
        if (entInfo == null) {
            return noticeNo;
        }
        return generateNoticeNo();
    }

    @Override
    public List<ExpelledEntInfo> searchEntInfoByBizId(String bizId) {
        return list(new LambdaQueryWrapper<ExpelledEntInfo>().eq(ExpelledEntInfo::getBizId, bizId));
    }
}
