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

import com.bonus.sgzb.base.domain.MaMachine;
import com.bonus.sgzb.base.api.domain.MaType;
import com.bonus.sgzb.base.mapper.MaMachineMapper;
import com.bonus.sgzb.base.mapper.MaTypeMapper;
import com.bonus.sgzb.base.service.MaMachineService;
import org.springframework.stereotype.Service;

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

@Service
public class MaMachineServiceImpl implements MaMachineService {

    @Resource
    private MaMachineMapper maMachineMapper;

    @Resource
    private MaTypeMapper typeMapper;


    @Override
    public List<MaMachine> getMaMachine(MaMachine maMachine) {
        List<MaMachine> maMachineList = maMachineMapper.getMaMachine(maMachine);
        for (MaMachine machine : maMachineList) {
            // 添加查询物品种类,设备类型,规格型号
            getType(machine);
        }
        return maMachineList;
    }

    /**
     *  添加查询物品种类,设备类型,规格型号
     * @param machine
     * @return
     */
    private void getType(MaMachine machine) {
        long typeId = machine.getTypeId();
        // 规格型号
        MaType maType = typeMapper.selectTypeByTypeId(typeId);
        // 设备类型
        machine.setSpecificationType(maType.getTypeName());
        MaType maType1 = typeMapper.selectTypeByTypeId(maType.getParentId());
        // 物品种类
        machine.setDeviceType(maType1.getTypeName());
        MaType maType2 = typeMapper.selectTypeByTypeId(maType1.getParentId());
        machine.setItemType(maType2.getTypeName());
    }

    @Override
    public int maMachineAdd(MaMachine maMachine) {
        return maMachineMapper.maMachineAdd(maMachine);
    }

    @Override
    public int remove(Long[] maIds) {
        return maMachineMapper.remove(maIds);
    }

    @Override
    public int updateMaMachine(MaMachine maMachine) {
        return maMachineMapper.updateMaMachine(maMachine);
    }

    /**
     * 查询机具设备管理ma_machine
     *
     * @param maId 机具设备管理ma_machine主键
     * @return 机具设备管理ma_machine
     */
    @Override
    public MaMachine selectMaMachineByMaId(Long maId)
    {
        return maMachineMapper.selectMaMachineByMaId(maId);
    }
}
