package com.goldenwater.gx.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.goldenwater.gx.domain.GxExchangeUnit;
import com.goldenwater.gx.mapper.GxExchangeUnitMapper;
import com.goldenwater.gx.service.IGxExchangeUnitService;

/**
 * 数据交换单位Service业务层处理
 */
@Service
public class GxExchangeUnitServiceImpl implements IGxExchangeUnitService {
    @Autowired
    private GxExchangeUnitMapper gxExchangeUnitMapper;

    @Override
    public GxExchangeUnit selectGxExchangeUnitById(Long id) {
        return gxExchangeUnitMapper.selectGxExchangeUnitById(id);
    }

    @Override
    public List<GxExchangeUnit> selectGxExchangeUnitList(GxExchangeUnit unit) {
        return gxExchangeUnitMapper.selectGxExchangeUnitList(unit);
    }

    @Override
    public int insertGxExchangeUnit(GxExchangeUnit unit) {
        if (unit.getOrderNum() == null || unit.getOrderNum() == 0) {
            Integer maxOrderNum = gxExchangeUnitMapper.selectMaxOrderNum();
            unit.setOrderNum(maxOrderNum + 1);
        }
        return gxExchangeUnitMapper.insertGxExchangeUnit(unit);
    }

    @Override
    public int updateGxExchangeUnit(GxExchangeUnit unit) {
        return gxExchangeUnitMapper.updateGxExchangeUnit(unit);
    }

    @Override
    public int deleteGxExchangeUnitByIds(Long[] ids) {
        return gxExchangeUnitMapper.deleteGxExchangeUnitByIds(ids);
    }

    @Override
    public int deleteGxExchangeUnitById(Long id) {
        return gxExchangeUnitMapper.deleteGxExchangeUnitById(id);
    }

    @Override
    public Integer selectMaxOrderNum() {
        return gxExchangeUnitMapper.selectMaxOrderNum();
    }
}
