|  |  | 
 |  |  | package cn.lihu.jh.module.ecg.service.devmanage; | 
 |  |  |  | 
 |  |  | import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceStatisticDO; | 
 |  |  | import cn.lihu.jh.module.infra.api.config.ConfigApi; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.validation.annotation.Validated; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | 
 |  |  | import javax.annotation.Resource; | 
 |  |  |  | 
 |  |  | import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; | 
 |  |  | import static cn.lihu.jh.module.ecg.Constants.DEV_CODE_CHOICE; | 
 |  |  | import static cn.lihu.jh.module.ecg.Constants.ECG_SCREEN_PANE_PASSED_KEY; | 
 |  |  | import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  | 
 |  |  | @Service | 
 |  |  | @Validated | 
 |  |  | public class DeviceServiceImpl implements DeviceService { | 
 |  |  |     @Resource | 
 |  |  |     private ConfigApi configApi; | 
 |  |  |  | 
 |  |  |     @Resource | 
 |  |  |     private DeviceMapper deviceMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer createDevice(DeviceSaveReqVO createReqVO) { | 
 |  |  |         // 读取 设备编号选择 系统配置 | 
 |  |  |         Integer devCodeChoice = Integer.valueOf(configApi.getConfigValueByKey(DEV_CODE_CHOICE)); | 
 |  |  |         if (0 == devCodeChoice) | 
 |  |  |             createReqVO.setDevId( createReqVO.getDevCodeIntrinsic() ); | 
 |  |  |         else if (1 == devCodeChoice) | 
 |  |  |             createReqVO.setDevId( createReqVO.getDevCodeHosp() ); | 
 |  |  |         else if (2 == devCodeChoice) | 
 |  |  |             createReqVO.setDevId( createReqVO.getDevCodeDept() ); | 
 |  |  |         else | 
 |  |  |             createReqVO.setDevId( createReqVO.getDevCodeDept() ); | 
 |  |  |  | 
 |  |  |         // 插入 | 
 |  |  |         DeviceDO device = BeanUtils.toBean(createReqVO, DeviceDO.class); | 
 |  |  |         deviceMapper.insert(device); | 
 |  |  | 
 |  |  |     public void updateDevice(DeviceSaveReqVO updateReqVO) { | 
 |  |  |         // 校验存在 | 
 |  |  |         validateDeviceExists(updateReqVO.getId()); | 
 |  |  |  | 
 |  |  |         // 读取 设备编号选择 系统配置 | 
 |  |  |         Integer devCodeChoice = Integer.valueOf(configApi.getConfigValueByKey(DEV_CODE_CHOICE)); | 
 |  |  |         if (0 == devCodeChoice) | 
 |  |  |             updateReqVO.setDevId( updateReqVO.getDevCodeIntrinsic() ); | 
 |  |  |         else if (1 == devCodeChoice) | 
 |  |  |             updateReqVO.setDevId( updateReqVO.getDevCodeHosp() ); | 
 |  |  |         else if (2 == devCodeChoice) | 
 |  |  |             updateReqVO.setDevId( updateReqVO.getDevCodeDept() ); | 
 |  |  |         else | 
 |  |  |             updateReqVO.setDevId( updateReqVO.getDevCodeDept() ); | 
 |  |  |  | 
 |  |  |         // 更新 | 
 |  |  |         DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class); | 
 |  |  |         deviceMapper.updateById(updateObj); | 
 |  |  | 
 |  |  |         validateDeviceExists(updateReqVO.getId()); | 
 |  |  |         // 更新 | 
 |  |  |         DeviceDO updateObj = BeanUtils.toBean(updateReqVO, DeviceDO.class); | 
 |  |  |         return deviceMapper.updateDevState(updateObj.getDevId(), updateObj.getState(), updateObj.getStateDate()); | 
 |  |  |         return deviceMapper.updateDevState(updateObj.getDevId(), updateObj.getState(), updateObj.getStateDate(), updateObj.getComment()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override |