package com.zcloud.basic.info.gatewayimpl;

import com.zcloud.basic.info.domain.gateway.CorpInfoXgfGateway;
import com.zcloud.basic.info.domain.model.CorpInfoXgfE;
import com.zcloud.basic.info.persistence.dataobject.CorpInfoDO;
import com.zcloud.basic.info.persistence.repository.CorpInfoRepository;
import com.zcloud.gbscommon.utils.Tools;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-10-31 10:52:09
 */
@Service
@AllArgsConstructor
public class CorpInfoXgfGatewayImpl implements CorpInfoXgfGateway {
    private final CorpInfoRepository corpInfoRepository;

    @Override
    public Boolean add(CorpInfoXgfE corpInfoXgfE) {
        CorpInfoDO d = new CorpInfoDO();
        BeanUtils.copyProperties(corpInfoXgfE, d);
        if(StringUtils.isEmpty(d.getCorpinfoId())){
            d.setCorpinfoId(Tools.get32UUID());
        }
        corpInfoRepository.save(d);
        return true;
    }

    @Override
    public Long addInfo(CorpInfoXgfE corpInfoXgfE) {
        CorpInfoDO d = new CorpInfoDO();
        BeanUtils.copyProperties(corpInfoXgfE, d);
        if(StringUtils.isEmpty(d.getCorpinfoId())){
            d.setCorpinfoId(Tools.get32UUID());
        }
        corpInfoRepository.save(d);
        return d.getId();
    }

    @Override
    public Boolean update(CorpInfoXgfE corpInfoXgfE) {
        CorpInfoDO d = new CorpInfoDO();
        BeanUtils.copyProperties(corpInfoXgfE, d);
        corpInfoRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedCorpInfoXgfById(Long id) {
        return corpInfoRepository.removeById(id);
    }

    @Override
    public Boolean deletedCorpInfoXgfByIds(Long[] ids) {
        return corpInfoRepository.removeByIds(Collections.singletonList(ids));
    }
}

