package com.pqs9900.serviceImpl.DataInfo;

import com.njcn.pojo.terminal.DeviceUnitPO;
import com.njcn.pojo.terminal.DeviceUnitVO;
import com.pqs9900.mapper.DataInfo.DeviceUnitMapper;
import com.pqs9900.service.DataInfo.DeviceUnitService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * system
 *
 * @author cdf
 * @date 2023/8/17
 */
@Service
public class DeviceUnitServiceImpl implements DeviceUnitService {

    @Resource
    private DeviceUnitMapper deviceUnitMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addUnit(DeviceUnitPO deviceUnitPO) {
        deviceUnitMapper.deleteByPrimaryKey(deviceUnitPO.getDevIndex());
        deviceUnitMapper.insert(deviceUnitPO);
        return true;
    }

    @Override
    public List<DeviceUnitVO> unitTable(Integer devFlag) {
        return deviceUnitMapper.unitTable(devFlag);
    }

    @Override
    public DeviceUnitVO lineUnitDetail(Integer lineId) {
        DeviceUnitVO deviceUnitVO = deviceUnitMapper.lineUnitDetail(lineId);
        if(Objects.isNull(deviceUnitVO)){
            return new DeviceUnitVO();
        }
        return deviceUnitVO;
    }

    @Override
    public DeviceUnitPO devUnitDetail(Integer devId) {
        DeviceUnitPO po = new DeviceUnitPO();
        po.setDevIndex(devId);
        DeviceUnitPO deviceUnitPO = deviceUnitMapper.selectByPrimaryKey(devId);
        if(Objects.isNull(deviceUnitPO)){
            return po;
        }
        return deviceUnitPO;
    }
}
