package cn.axzo.workflow.core.service.impl;

import cn.axzo.workflow.core.repository.entity.ExtAxProperty;
import cn.axzo.workflow.core.repository.mapper.ExtAxPropertyMapper;
import cn.axzo.workflow.core.service.ExtAxPropertyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * 引擎服务持久配置信息表操作 Service 实现
 *
 * @author wangli
 * @since 2024/2/6 16:20
 */
@Service
@Slf4j
public class ExtAxPropertyServiceImpl implements ExtAxPropertyService {
    @Resource
    private ExtAxPropertyMapper mapper;

    @Override
    public ExtAxProperty add(ExtAxProperty property) {
        mapper.insert(property);
        return property;
    }

    @Override
    public ExtAxProperty update(ExtAxProperty property) {
        mapper.updateById(property);
        return property;
    }

    @Override
    public Optional<ExtAxProperty> getByName(String name) {
        if (!StringUtils.hasText(name)) {
            return Optional.empty();
        }
        QueryWrapper<ExtAxProperty> queryWrapper = new QueryWrapper<ExtAxProperty>()
                .eq("name", name);
        return Optional.ofNullable(mapper.selectOne(queryWrapper));
    }
}
