package com.bonus.sgzb.machine.service.impl;

import com.bonus.sgzb.common.core.constant.UserConstants;
import com.bonus.sgzb.common.core.utils.StringUtils;
import com.bonus.sgzb.machine.damain.MaPartType;
import com.bonus.sgzb.machine.damain.MaType;
import com.bonus.sgzb.machine.mapper.MaPartTypeMapper;
import com.bonus.sgzb.machine.service.IPartTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 配件类型管理ma_part_type(MaPartType)表服务实现类
 *
 * @author makejava
 * @since 2023-11-27 16:44:20
 */
@Service("maPartTypeService")
public class MaPartTypeServiceImpl implements IPartTypeService {

    @Autowired
    private MaPartTypeMapper maPartTypeMapper;
    /**
     * 校验配件名称唯一性
     * @param maPartType
     * @return
     */
    @Override
    public boolean checkPaNameUnique(MaPartType maPartType) {
        Long paId = StringUtils.isNull(maPartType.getPaId()) ? -1L : maPartType.getPaId();
        MaPartType info = maPartTypeMapper.checkPartNameUnique(maPartType.getPaId());
        if (StringUtils.isNotNull(info) && info.getPaId().longValue() != paId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 新增配件管理
     * @param maPartType
     * @return
     */
    @Override
    public int insertMaPart(MaPartType maPartType) {

        return maPartTypeMapper.insertMaPartType(maPartType);
    }

    /**
     * 查询配件类型列表
     * @param maPartType
     * @return
     */
    @Override
    public List<MaPartType> selectMaPartList(MaPartType maPartType) {
        return maPartTypeMapper.selectMaPartType(maPartType);
    }

    /**
     * 导出配件管理类型
     * @param maPartType
     * @return
     */
    @Override
    public List<MaPartType> selectMyPartTypeList(MaPartType maPartType) {
        return maPartTypeMapper.selectMaPartType(maPartType);
    }

    /**
     * 查询是否含有子集
     * @param paId
     * @return
     */
    @Override
    public boolean hasChildBypaId(Long paId) {
        int result = maPartTypeMapper.hasChildByPaId(paId);
        return result > 0;
    }

    /**
     * 删除配件类型
     * @param paId
     * @return
     */
    @Override
    public int deletePaById(Long paId) {
        return maPartTypeMapper.deletePaById(paId);
    }
}

