package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireCheckStandardGateway;
import com.zcloud.fire.check.domain.model.FireCheckStandardE;
import com.zcloud.fire.check.persistence.dataobject.FireCheckStandardDO;
import com.zcloud.fire.check.persistence.repository.FireCheckStandardRepository;
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.Arrays;
import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-11-26 10:12:15
 */
@Service
@AllArgsConstructor
public class FireCheckStandardGatewayImpl implements FireCheckStandardGateway {
    private final FireCheckStandardRepository fireCheckStandardRepository;

    @Override
    public Boolean add(FireCheckStandardE fireCheckStandardE) {
        if(StringUtils.isEmpty(fireCheckStandardE.getFireCheckStandardId())){
            fireCheckStandardE.setFireCheckStandardId(Tools.get32UUID());
        }
        if(fireCheckStandardE.getCorpinfoId() == null){
            fireCheckStandardE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireCheckStandardDO d = new FireCheckStandardDO();
        BeanUtils.copyProperties(fireCheckStandardE, d);
        fireCheckStandardRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(FireCheckStandardE fireCheckStandardE) {
        FireCheckStandardDO d = new FireCheckStandardDO();
        BeanUtils.copyProperties(fireCheckStandardE, d);
        fireCheckStandardRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireCheckStandardById(Long id) {
        return fireCheckStandardRepository.removeById(id);
    }

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

