package com.zcloud.basic.info.gatewayimpl;

import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.gateway.UserCorpGateway;
import com.zcloud.basic.info.domain.model.UserCorpE;
import com.zcloud.basic.info.persistence.dataobject.UserCorpDO;
import com.zcloud.basic.info.persistence.repository.UserCorpRepository;
import com.zcloud.gbscommon.utils.Tools;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-12-02 11:13:33
 */
@Service
@AllArgsConstructor
public class UserCorpGatewayImpl implements UserCorpGateway {
    private final UserCorpRepository userCorpRepository;

    @Override
    public Boolean add(UserCorpE userCorpE) {
        if(StringUtils.isEmpty(userCorpE.getUserCorpId())){
            userCorpE.setUserCorpId(Tools.get32UUID());
        }
        UserCorpDO d = new UserCorpDO();
        BeanUtils.copyProperties(userCorpE, d);
        userCorpRepository.save(d);
        userCorpE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(UserCorpE userCorpE) {
        UserCorpDO d = new UserCorpDO();
        BeanUtils.copyProperties(userCorpE, d);
        userCorpRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedUserCorpById(Long id) {
        return userCorpRepository.removeById(id);
    }

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

