package com.zcloud.basic.info.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.basic.info.domain.gateway.UserQualificationInfoGateway;
import com.zcloud.basic.info.domain.model.UserQualificationInfoE;
import com.zcloud.basic.info.persistence.dataobject.UserQualificationInfoDO;
import com.zcloud.basic.info.persistence.repository.UserQualificationInfoRepository;
import com.zcloud.gbscommon.utils.UuidUtil;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
* web-infrastructure
* @Author SondonYong
* @Date 2025-10-31 09:50:34
*/
@Service
@AllArgsConstructor
public class UserQualificationInfoGatewayImpl implements UserQualificationInfoGateway {
    private final UserQualificationInfoRepository userQualificationInfoRepository;

    @Override
    public Boolean add(UserQualificationInfoE userQualificationInfoE) {
        UserQualificationInfoDO d = new UserQualificationInfoDO();
        BeanUtils.copyProperties(userQualificationInfoE, d);
        if(StringUtils.isEmpty(d.getUserQualificationinfoId())){
            d.setUserQualificationinfoId(UuidUtil.get32UUID());
        }
        // 当前登录账号企业id/租户id
        d.setCorpinfoId(AuthContext.getTenantId());
        userQualificationInfoRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(UserQualificationInfoE userQualificationInfoE) {
        UserQualificationInfoDO d = new UserQualificationInfoDO();
        BeanUtils.copyProperties(userQualificationInfoE, d);
        userQualificationInfoRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedUserQualificationInfoById(Long id) {
        return userQualificationInfoRepository.removeById(id);
    }

    @Override
    public Boolean deletedUserQualificationInfoByIds(Long[] ids) {
        return userQualificationInfoRepository.removeByIds(Arrays.asList(ids));
    }
}

