package com.ktg.iscs.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.iscs.domain.IsMaterialsPropertyValue;
import com.ktg.iscs.mapper.IsMaterialsPropertyValueMapper;
import com.ktg.iscs.service.IIsMaterialsPropertyValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 物资属性值Service业务层处理
 *
 * @author cgj
 * @date 2025-02-05
 */
@Service
public class IsMaterialsPropertyValueServiceImpl extends ServiceImpl<IsMaterialsPropertyValueMapper, IsMaterialsPropertyValue> implements IIsMaterialsPropertyValueService {

    @Autowired
    private IsMaterialsPropertyValueMapper isMaterialsPropertyValueMapper;

    @Override
    public Page<IsMaterialsPropertyValue> getIsMaterialsPropertyValuePage(Page<IsMaterialsPropertyValue> page, IsMaterialsPropertyValue isMaterialsPropertyValue) {
        Page<IsMaterialsPropertyValue> result = isMaterialsPropertyValueMapper.getIsMaterialsPropertyValuePage(page, isMaterialsPropertyValue);
        return result;
    }

    @Override
    public Boolean insertIsMaterialsPropertyValue(IsMaterialsPropertyValue isMaterialsPropertyValue) {
        List<IsMaterialsPropertyValue> list = list(Wrappers.<IsMaterialsPropertyValue>lambdaQuery()
                .eq(IsMaterialsPropertyValue::getPropertyId, isMaterialsPropertyValue.getPropertyId())
                .eq(IsMaterialsPropertyValue::getValueName, isMaterialsPropertyValue.getValueName()));
        Assert.isTrue(list.isEmpty(), "该名称已被使用!");
        return save(isMaterialsPropertyValue);
    }

    @Override
    public Boolean updateIsMaterialsPropertyValue(IsMaterialsPropertyValue isMaterialsPropertyValue) {
        List<IsMaterialsPropertyValue> list = list(Wrappers.<IsMaterialsPropertyValue>lambdaQuery()
                .eq(IsMaterialsPropertyValue::getPropertyId, isMaterialsPropertyValue.getPropertyId())
                .eq(IsMaterialsPropertyValue::getValueName, isMaterialsPropertyValue.getValueName())
                .ne(IsMaterialsPropertyValue::getRecordId, isMaterialsPropertyValue.getRecordId()));
        Assert.isTrue(list.isEmpty(), "该名称已被使用!");
        return updateById(isMaterialsPropertyValue);
    }


}
