package cn.lihu.jh.module.ecg.service.devrent; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; import cn.lihu.jh.module.ecg.controller.admin.devrent.vo.*; import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO; import cn.lihu.jh.framework.common.pojo.PageResult; import cn.lihu.jh.framework.common.pojo.PageParam; import cn.lihu.jh.framework.common.util.object.BeanUtils; import cn.lihu.jh.module.ecg.dal.mysql.devrent.DevRentMapper; import javax.annotation.Resource; import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; /** * 装机拆机 Service 实现类 * * @author 芋道源码 */ @Service @Validated public class DevRentServiceImpl implements DevRentService { @Resource private DevRentMapper devRentMapper; @Override public Integer createDevRent(DevRentSaveReqVO createReqVO) { // 插入 DevRentDO devRent = BeanUtils.toBean(createReqVO, DevRentDO.class); devRentMapper.insert(devRent); // 返回 return devRent.getId(); } @Override public void updateDevRent(DevRentSaveReqVO updateReqVO) { // 校验存在 validateDevRentExists(updateReqVO.getId()); // 更新 DevRentDO updateObj = BeanUtils.toBean(updateReqVO, DevRentDO.class); devRentMapper.updateById(updateObj); } @Override public void deleteDevRent(Integer id) { // 校验存在 validateDevRentExists(id); // 删除 devRentMapper.deleteById(id); } private void validateDevRentExists(Integer id) { if (devRentMapper.selectById(id) == null) { throw exception(DEV_RENT_NOT_EXISTS); } } @Override public DevRentDO getDevRent(Integer id) { return devRentMapper.selectById(id); } @Override public PageResult getDevRentPage(DevRentPageReqVO pageReqVO) { return devRentMapper.selectPage(pageReqVO); } }