Browse Source

优化新增设备功能(重复添加)

Simon 1 year ago
parent
commit
483f49ed3b

+ 21 - 18
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDataDisplayController.java

@@ -154,24 +154,27 @@ public class TDataDisplayController extends BaseController {
     @GetMapping("/mapGpsViewV2")
     public AjaxResult mapGpsViewV2() {   //TODO 暂时写在Controller中
         List<MapGpsDto> dtoList = itShouhuanInfoService.selectMapGpsView();
-        List<AjaxResult> collect = dtoList.stream()
-                .map(mapGpsDto -> {
-                    AjaxResult ajax = new AjaxResult();
-                    List<Float> list = new ArrayList<>();
-                    list.add(mapGpsDto.getGps_long());
-                    list.add(mapGpsDto.getGps_lat());
-                    ajax.put("lnglat", list);
-                    return ajax;
-                }).filter(
-                        person -> {
-                            List<Float> lngList = (List<Float>) person.get("lnglat");
-                            if (lngList != null && !lngList.isEmpty() && lngList.size() >= 2) {
-                                Float lng = lngList.get(0);
-                                Float lat = lngList.get(1);
-                                return lng > 0 && lat > 0;
-                            }
-                            return false;
-                        }).collect(Collectors.toList());
+        List<AjaxResult> collect = new ArrayList<>();
+        if (dtoList != null && !dtoList.isEmpty()) {
+            collect = dtoList.stream()
+                    .map(mapGpsDto -> {
+                        AjaxResult ajax = new AjaxResult();
+                        List<Float> list = new ArrayList<>();
+                        list.add(mapGpsDto.getGps_long());
+                        list.add(mapGpsDto.getGps_lat());
+                        ajax.put("lnglat", list);
+                        return ajax;
+                    }).filter(
+                            person -> {
+                                List<Float> lngList = (List<Float>) person.get("lnglat");
+                                if (lngList != null && !lngList.isEmpty() && lngList.size() >= 2) {
+                                    Float lng = lngList.get(0);
+                                    Float lat = lngList.get(1);
+                                    return lng > 0 && lat > 0;
+                                }
+                                return false;
+                            }).collect(Collectors.toList());
+        }
         return AjaxResult.success("操作成功", collect);
     }
 

+ 28 - 43
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDeviceListController.java

@@ -23,14 +23,13 @@ import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 设备列Controller
- * 
+ *
  * @author zhengjie
  * @date 2023-08-30
  */
 @RestController
 @RequestMapping("/system/device")
-public class TDeviceListController extends BaseController
-{
+public class TDeviceListController extends BaseController {
     @Autowired
     private ITDeviceListService tDeviceListService;
 
@@ -39,8 +38,7 @@ public class TDeviceListController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:device:list')")
     @GetMapping("/list")
-    public TableDataInfo list(TDeviceList tDeviceList)
-    {
+    public TableDataInfo list(TDeviceList tDeviceList) {
         startPage();
         List<TDeviceList> list = tDeviceListService.selectTDeviceListList(tDeviceList);
         return getDataTable(list);
@@ -52,8 +50,7 @@ public class TDeviceListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:device:export')")
     @Log(title = "设备列", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, TDeviceList tDeviceList)
-    {
+    public void export(HttpServletResponse response, TDeviceList tDeviceList) {
         List<TDeviceList> list = tDeviceListService.selectTDeviceListList(tDeviceList);
         ExcelUtil<TDeviceList> util = new ExcelUtil<TDeviceList>(TDeviceList.class);
         util.exportExcel(response, list, "设备列数据");
@@ -64,8 +61,7 @@ public class TDeviceListController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:device:query')")
     @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Integer id)
-    {
+    public AjaxResult getInfo(@PathVariable("id") Integer id) {
         return success(tDeviceListService.selectTDeviceListById(id));
     }
 
@@ -75,8 +71,7 @@ public class TDeviceListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:device:add')")
     @Log(title = "设备列", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody TDeviceList tDeviceList)
-    {
+    public AjaxResult add(@RequestBody TDeviceList tDeviceList) {
         return toAjax(tDeviceListService.insertTDeviceList(tDeviceList));
     }
 
@@ -86,8 +81,7 @@ public class TDeviceListController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:device:edit')")
     @Log(title = "设备列", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody TDeviceList tDeviceList)
-    {
+    public AjaxResult edit(@RequestBody TDeviceList tDeviceList) {
         return toAjax(tDeviceListService.updateTDeviceList(tDeviceList));
     }
 
@@ -96,9 +90,8 @@ public class TDeviceListController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:device:remove')")
     @Log(title = "设备列", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable Integer[] ids)
-    {
+    @DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Integer[] ids) {
         return toAjax(tDeviceListService.deleteTDeviceListByIds(ids));
     }
 
@@ -106,8 +99,7 @@ public class TDeviceListController extends BaseController
      * 下载模板
      */
     @PostMapping("/importTemplate")
-    public void importTemplate(HttpServletResponse response)
-    {
+    public void importTemplate(HttpServletResponse response) {
         ExcelUtil<TDeviceList> util = new ExcelUtil<TDeviceList>(TDeviceList.class);
         util.importTemplateExcel(response, "设备列表模板");
     }
@@ -125,6 +117,7 @@ public class TDeviceListController extends BaseController
 //        String message = tDeviceListService.importTDeviceList(tDeviceLists);
 //        return AjaxResult.success(message);
 //    }
+
     /**
      * 导入
      */
@@ -137,15 +130,15 @@ public class TDeviceListController extends BaseController
         String message = tDeviceListService.importTDeviceListV2(tDeviceLists);
         return AjaxResult.success(message);
     }
+
     /**
      * 查询心率列表
      */
     @GetMapping("/heartRate")
-    public TableDataInfo heartRate(String device_id_code)
-    {
+    public TableDataInfo heartRate(String device_id_code) {
         startPage();
         List<RateDto> list = tDeviceListService.selectTDeviceByDeviceId(device_id_code);
-        for(RateDto dto : list){
+        for (RateDto dto : list) {
             HeartRateDto heartRateDto = JSONObject.parseObject(dto.getContent(), HeartRateDto.class);
             dto.setContent(heartRateDto.getHeart_rate());
         }
@@ -156,11 +149,10 @@ public class TDeviceListController extends BaseController
      * 查询血氧列表
      */
     @GetMapping("/oxygenRate")
-    public TableDataInfo oxygenRate(String device_id_code)
-    {
+    public TableDataInfo oxygenRate(String device_id_code) {
         startPage();
         List<RateDto> list = tDeviceListService.selectTDeviceByOxygen(device_id_code);
-        for(RateDto dto : list){
+        for (RateDto dto : list) {
             OxygenRateDto oxygenRateDto = JSONObject.parseObject(dto.getContent(), OxygenRateDto.class);
             dto.setContent(oxygenRateDto.getOxygen());
         }
@@ -171,11 +163,10 @@ public class TDeviceListController extends BaseController
      * 查询体温列表
      */
     @GetMapping("/tempRate")
-    public TableDataInfo tempRate(String device_id_code)
-    {
+    public TableDataInfo tempRate(String device_id_code) {
         startPage();
         List<RateDto> list = tDeviceListService.selectTDeviceByTemp(device_id_code);
-        for(RateDto dto : list){
+        for (RateDto dto : list) {
             TempRateDto tempRateDto = JSONObject.parseObject(dto.getContent(), TempRateDto.class);
             dto.setContent(tempRateDto.getTemp());
         }
@@ -186,12 +177,11 @@ public class TDeviceListController extends BaseController
      * 查询血压列表
      */
     @GetMapping("/bloodRate")
-    public TableDataInfo bloodRate(String device_id_code)
-    {
+    public TableDataInfo bloodRate(String device_id_code) {
         startPage();
         List<RateDto> list = tDeviceListService.selectTDeviceByBlood(device_id_code);
         List<BloodRateDto> list1 = new ArrayList<>();
-        for(RateDto dto : list){
+        for (RateDto dto : list) {
             BloodRateDto bloodRateDto = JSONObject.parseObject(dto.getContent(), BloodRateDto.class);
             bloodRateDto.setCreatetime(dto.getCreatetime());
             list1.add(bloodRateDto);
@@ -203,12 +193,11 @@ public class TDeviceListController extends BaseController
      * 查询步数列表
      */
     @GetMapping("/stepRate")
-    public TableDataInfo stepRate(String device_id_code)
-    {
+    public TableDataInfo stepRate(String device_id_code) {
         startPage();
         List<RateDto> list = tDeviceListService.selectTDeviceByStep(device_id_code);
         List<StepRateDto> list1 = new ArrayList<>();
-        for(RateDto dto : list){
+        for (RateDto dto : list) {
             StepRateDto stepRateDto = JSONObject.parseObject(dto.getContent(), StepRateDto.class);
             stepRateDto.setCreatetime(dto.getCreatetime());
             list1.add(stepRateDto);
@@ -220,12 +209,11 @@ public class TDeviceListController extends BaseController
      * 查询翻滚列表
      */
     @GetMapping("/rollRate")
-    public TableDataInfo rollRate(String device_id_code)
-    {
+    public TableDataInfo rollRate(String device_id_code) {
         startPage();
         List<RateDto> list = tDeviceListService.selectTDeviceByStep(device_id_code);
         List<RollRateDto> list1 = new ArrayList<>();
-        for(RateDto dto : list){
+        for (RateDto dto : list) {
             RollRateDto rollRateDto = JSONObject.parseObject(dto.getContent(), RollRateDto.class);
             rollRateDto.setCreatetime(dto.getCreatetime());
             list1.add(rollRateDto);
@@ -237,12 +225,11 @@ public class TDeviceListController extends BaseController
      * 查询步数列表
      */
     @GetMapping("/messageRate")
-    public TableDataInfo messageRate(String device_id_code)
-    {
+    public TableDataInfo messageRate(String device_id_code) {
         startPage();
         List<MessageDto> list = tDeviceListService.selectTDeviceByMessage(device_id_code);
         List<RateDto> list1 = new ArrayList<>();
-        for(MessageDto dto : list){
+        for (MessageDto dto : list) {
             RateDto rateDto = new RateDto();
             rateDto.setContent(tDeviceListService.checkMessage(dto.getAlarm_type()));
             rateDto.setCreatetime(dto.getCreatetime());
@@ -255,8 +242,7 @@ public class TDeviceListController extends BaseController
      * 查询设备消息日志
      */
     @GetMapping("/messageLogRate")
-    public TableDataInfo messageLogRate(MessageLogDto messageLogDto)
-    {
+    public TableDataInfo messageLogRate(MessageLogDto messageLogDto) {
         startPage();
         List<MessageLogDto> list = tDeviceListService.selectTDeviceByMessageLog(messageLogDto);
         return getDataTable(list);
@@ -267,8 +253,7 @@ public class TDeviceListController extends BaseController
      */
     @Log(title = "设备阈值", businessType = BusinessType.UPDATE)
     @PostMapping("/deviceValue")
-    public AjaxResult deviceValue(@RequestBody CallPoliceDto callPoliceDto)
-    {
+    public AjaxResult deviceValue(@RequestBody CallPoliceDto callPoliceDto) {
         return toAjax(tDeviceListService.deviceValue(callPoliceDto));
     }
 }

+ 67 - 6
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDeviceListServiceImpl.java

@@ -100,18 +100,79 @@ public class TDeviceListServiceImpl implements ITDeviceListService {
     @Transactional
     @Override
     public int insertTDeviceList(TDeviceList tDeviceList) {
+        /**
+         * TODO 后期在bean中校验字段是否为空
+         */
+        //新增设备
+        if (tDeviceList == null) {
+            throw new ServiceException("新增设备数据不能为空!");
+        }
+        //设备是否绑定用户
+        if (tDeviceList.getUserid() == null) {
+            throw new ServiceException("新增设备未绑定用户!");
+        }
+        //工厂
+        if (tDeviceList.getFactory() == null) {
+            throw new ServiceException("新增设备未选择工厂!");
+        }
+        //设备型号
+        if (tDeviceList.getDeviceModel() == null) {
+            throw new ServiceException("新增设备未选择设备型号!");
+        }
+        //设备标识ID
+        if (tDeviceList.getDeviceId() == null || StringUtils.isEmpty(tDeviceList.getDeviceId())) {
+            throw new ServiceException("新增设备未填写设备标识ID!");
+        }
+        //发放方式
+        if (tDeviceList.getGrantType() == null) {
+            throw new ServiceException("新增设备未选择发放方式!");
+        }
+        //如果是购买方式
+        if (tDeviceList.getGrantType() == 1) {
+            //设备标识ID
+            if (tDeviceList.getPrice() == null || StringUtils.isEmpty(tDeviceList.getPrice())) {
+                throw new ServiceException("新增设备未填写销售价格!");
+            }
+//            //服务费用
+//            if (tDeviceList.getCost() == null || StringUtils.isEmpty(tDeviceList.getCost())) {
+//                throw new ServiceException("新增设备未填写服务费用!");
+//            }
+            //支付方式
+            if (tDeviceList.getPayment() == null) {
+                throw new ServiceException("新增设备未选择支付方式!");
+            }
+        }
+        //根据设备表示ID查询数据库中的设备信息
+        List<RateDto> rateDtoList = tDeviceListMapper.selectTDeviceByDeviceId(tDeviceList.getDeviceId());
+        if (rateDtoList != null && !rateDtoList.isEmpty()) {
+            //如果表中有该设备则提示
+            StringBuilder stringBuilder = new StringBuilder();
+            stringBuilder.append("新增设备信息已存在");
+            //如果有设备标识ID,则提示
+            if (!StringUtils.isEmpty(tDeviceList.getDeviceId())) {
+                stringBuilder.append(", 设备标识ID:" + tDeviceList.getDeviceId());
+            }
+            stringBuilder.append("!");
+            throw new ServiceException(stringBuilder.toString());
+        }
+        //新增时间
+        tDeviceList.setCreateTime(DateUtils.getNowDate());
+        int rows = tDeviceListMapper.insertTDeviceList(tDeviceList);
         TFacility tFacility = new TFacility();
-        if (StringUtils.isNotNull(tDeviceList.getDeviceId())) {
+        //设备编号
+        if (tDeviceList.getDeviceId() != null && !StringUtils.isEmpty(tDeviceList.getDeviceId())) {
             tFacility.setCode(tDeviceList.getDeviceId());
-        } else if (StringUtils.isNotNull(tDeviceList.getSimCode())) {
+        }
+        //设备SIM卡号
+        if (tDeviceList.getSimCode() != null && !StringUtils.isEmpty(tDeviceList.getSimCode())) {
             tFacility.setTelno(tDeviceList.getSimCode());
-        } else if (StringUtils.isNotNull(tDeviceList.getSerialNumber())) {
+        }
+        //设备序列号
+        if (tDeviceList.getSerialNumber() != null && !StringUtils.isEmpty(tDeviceList.getSerialNumber())) {
             tFacility.setIccid(tDeviceList.getSerialNumber());
         }
-        tFacility.setCreateTime(DateUtils.getNowDate());
         tFacilityMapper.insertTFacility(tFacility);
-        tDeviceList.setCreateTime(DateUtils.getNowDate());
-        return tDeviceListMapper.insertTDeviceList(tDeviceList);
+        return rows;
     }
 
     /**