package com.zcloud.basic.info.gatewayimpl;

import com.zcloud.basic.info.domain.gateway.CorpQualificationInfoGateway;
import com.zcloud.basic.info.domain.model.CorpQualificationInfoE;
import com.zcloud.basic.info.persistence.dataobject.CorpQualificationInfoDO;
import com.zcloud.basic.info.persistence.repository.CorpQualificationInfoRepository;
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-29 16:02:46
 */
@Service
@AllArgsConstructor
public class CorpQualificationInfoGatewayImpl implements CorpQualificationInfoGateway {
    private final CorpQualificationInfoRepository corpQualificationInfoRepository;

    @Override
    public Boolean add(CorpQualificationInfoE corpQualificationInfoE) {
        CorpQualificationInfoDO d = new CorpQualificationInfoDO();
        BeanUtils.copyProperties(corpQualificationInfoE, d);
        if(StringUtils.isEmpty(d.getCorpQualificationinfoId())){
            d.setCorpQualificationinfoId(Tools.get32UUID());
        }
        corpQualificationInfoRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(CorpQualificationInfoE corpQualificationInfoE) {
        CorpQualificationInfoDO d = new CorpQualificationInfoDO();
        BeanUtils.copyProperties(corpQualificationInfoE, d);
        corpQualificationInfoRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedCorpQualificationInfoById(Long id) {
        return corpQualificationInfoRepository.removeById(id);
    }

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

