package com.zcloud.primeport.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zcloud.primeport.domain.gateway.MkmjApprovalUserGateway;
import com.zcloud.primeport.domain.model.MkmjApprovalUserE;
import com.zcloud.primeport.persistence.dataobject.MkmjApprovalUserDO;
import com.zcloud.primeport.persistence.repository.MkmjApprovalUserRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * web-infrastructure
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:17
 */
@Service
@AllArgsConstructor
public class MkmjApprovalUserGatewayImpl implements MkmjApprovalUserGateway {
    private final MkmjApprovalUserRepository mkmjApprovalUserRepository;

    @Override
    public Boolean add(MkmjApprovalUserE mkmjApprovalUserE) {
        MkmjApprovalUserDO d = new MkmjApprovalUserDO();
        BeanUtils.copyProperties(mkmjApprovalUserE, d);
        mkmjApprovalUserRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(MkmjApprovalUserE mkmjApprovalUserE) {
        MkmjApprovalUserDO d = new MkmjApprovalUserDO();
        BeanUtils.copyProperties(mkmjApprovalUserE, d);
        mkmjApprovalUserRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedMkmjApprovalUserById(Long id) {
        return mkmjApprovalUserRepository.removeById(id);
    }

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

    @Override
    public MkmjApprovalUserE getByUserId(Long userId) {
        LambdaQueryWrapper<MkmjApprovalUserDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MkmjApprovalUserDO::getUserId, userId);
        wrapper.eq(MkmjApprovalUserDO::getDeleteEnum, "FALSE");
        MkmjApprovalUserDO d = mkmjApprovalUserRepository.getOne(wrapper);
        if (d == null) {
            return null;
        }
        MkmjApprovalUserE e = new MkmjApprovalUserE();
        BeanUtils.copyProperties(d, e);
        return e;
    }
}
