From 095e73d015f05395779673f1fe1db4cab1ac6241 Mon Sep 17 00:00:00 2001 From: 15856 <15856818120@163.com> Date: Thu, 8 Aug 2024 16:16:40 +0800 Subject: [PATCH] =?UTF-8?q?sonaer=E5=BC=82=E5=91=B3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/IotMachineServiceImpl.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java index 563bab1..76378df 100644 --- a/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java +++ b/sgzb-modules/sgzb-material/src/main/java/com/bonus/sgzb/material/service/impl/IotMachineServiceImpl.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.bonus.sgzb.common.core.constant.HttpStatus; import com.bonus.sgzb.common.core.constant.TokenConstants; +import com.bonus.sgzb.common.core.exception.ServiceException; import com.bonus.sgzb.common.core.utils.HttpHelper; import com.bonus.sgzb.common.core.utils.StringHelper; import com.bonus.sgzb.common.core.web.domain.AjaxResult; @@ -77,7 +78,7 @@ public class IotMachineServiceImpl implements IotMachineService { int res = iotMachineMapper.add(iotDto); if (res == 0) { // 如果添加失败,返回保存到数据库异常的错误信息 - throw new RuntimeException(ExceptionEnum.SAVE_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.SAVE_TO_DATABASE.getMsg()); } else { // 添加成功,返回成功的消息和新增的记录数 return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); @@ -110,7 +111,7 @@ public class IotMachineServiceImpl implements IotMachineService { int res = iotMachineMapper.update(iotDto); if (res == 0) { // 如果修改失败,返回修改到数据库异常的错误信息 - throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); } else { // 修改成功,返回成功的消息和修改的记录数 return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res); @@ -181,12 +182,12 @@ public class IotMachineServiceImpl implements IotMachineService { //绑定设备 res = iotMachineMapper.bind(iotDto); if (res == 0) { - throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.BIND_TO_DATABASE.getMsg()); } //更新绑定状态 res = iotMachineMapper.updateBindStatus(iotDto); if (res == 0) { - throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); } } catch (Exception e) { log.error("设备绑定异常:{}", e.getMessage()); @@ -215,12 +216,12 @@ public class IotMachineServiceImpl implements IotMachineService { //解绑设备 res = iotMachineMapper.unbind(iotDto); if (res == 0) { - throw new RuntimeException(ExceptionEnum.UN_BIND_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.UN_BIND_TO_DATABASE.getMsg()); } //更新绑定状态 res = iotMachineMapper.updateUnBindStatus(iotDto); if (res == 0) { - throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); } } catch (Exception e) { log.error("设备解绑异常:{}", e.getMessage()); @@ -240,7 +241,7 @@ public class IotMachineServiceImpl implements IotMachineService { @Override public List getTypeList(IotDto iotDto) { if (iotDto == null || iotDto.getMaCode() == null) { - throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + throw new ServiceException(ExceptionEnum.PARAM_NULL.getMsg()); } return iotMachineMapper.getTypeList(iotDto); } @@ -273,7 +274,7 @@ public class IotMachineServiceImpl implements IotMachineService { @Override public List getRecordList(IotDto iotDto) { if (iotDto == null || iotDto.getIotId() == null) { - throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + throw new ServiceException(ExceptionEnum.PARAM_NULL.getMsg()); } return iotMachineMapper.getRecordList(iotDto); } @@ -287,7 +288,7 @@ public class IotMachineServiceImpl implements IotMachineService { public AjaxResult getLocation(IotDto iotDto) { log.info("getLocation:{}", iotDto); if (iotDto == null || iotDto.getIotId() == null) { - throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + throw new ServiceException(ExceptionEnum.PARAM_NULL.getMsg()); } List list=new ArrayList<>(); Map map=new HashMap<>(); @@ -305,7 +306,7 @@ public class IotMachineServiceImpl implements IotMachineService { String res = HttpHelper.doPost(HttpStatus.LAST_POSITION_URL+redisCode,param); //对返回的结果进行解析 IotLocationVo iotLocationVo = resultDataHandler(res); - log.info("resultDataHandler:{}", iotLocationVo); + log.info("返回结果resultDataHandler:{}", iotLocationVo); return AjaxResult.success(iotLocationVo); } @@ -318,7 +319,7 @@ public class IotMachineServiceImpl implements IotMachineService { public AjaxResult searchItinerary(IotLocationVo iotLocationVo) { log.info("searchItinerary:{}", iotLocationVo); if (iotLocationVo == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) { - throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + throw new ServiceException(ExceptionEnum.PARAM_NULL.getMsg()); } Map map=new HashMap<>(); //从redis中获取token @@ -347,7 +348,7 @@ public class IotMachineServiceImpl implements IotMachineService { log.info("reportParkDetailByTime:{}", iotLocationVo); if (iotLocationVo == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) { - throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + throw new ServiceException(ExceptionEnum.PARAM_NULL.getMsg()); } Map map=new HashMap<>(); //从redis中获取token @@ -376,7 +377,7 @@ public class IotMachineServiceImpl implements IotMachineService { */ private List resultReportParkDetailByTime(String res) { if (res == null) { - throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); + throw new ServiceException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); } List iotLocationVoList = new ArrayList<>(); JSONObject object = JSONObject.parseObject(res); @@ -424,12 +425,12 @@ public class IotMachineServiceImpl implements IotMachineService { //绑定设备 res = iotMachineMapper.bind(iotDto); if (res == 0) { - throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.BIND_TO_DATABASE.getMsg()); } //更新绑定状态 res = iotMachineMapper.updateBindStatus(iotDto); if (res == 0) { - throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); + throw new ServiceException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg()); } } catch (Exception e) { log.error("设备绑定异常:{}", e.getMessage()); @@ -449,7 +450,7 @@ public class IotMachineServiceImpl implements IotMachineService { public AjaxResult reportAlarm(IotLocationVo iotLocationVo) { log.info("reportAlarm:{}", iotLocationVo); if (iotLocationVo == null || iotLocationVo.getIotId() == null || iotLocationVo.getBeginTime() == null || iotLocationVo.getEndTime() == null) { - throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg()); + throw new ServiceException(ExceptionEnum.PARAM_NULL.getMsg()); } Map map=new HashMap<>(); @@ -483,7 +484,7 @@ public class IotMachineServiceImpl implements IotMachineService { */ private List resultReportAlarm(String res) { if (res == null) { - throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); + throw new ServiceException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); } List iotLocationVoList = new ArrayList<>(); JSONObject object = JSONObject.parseObject(res); @@ -514,7 +515,7 @@ public class IotMachineServiceImpl implements IotMachineService { */ private IotLocationVo resultDataHandler(String res) { if (res == null) { - throw new RuntimeException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); + throw new ServiceException(ExceptionEnum.RETURN_DATA_IS_EMPTY.getMsg()); } IotLocationVo iotLocationVo = new IotLocationVo(); JSONObject object = JSONObject.parseObject(res); @@ -535,9 +536,4 @@ public class IotMachineServiceImpl implements IotMachineService { } return iotLocationVo; } - - - - - }