|
@@ -0,0 +1,92 @@
|
|
|
+package com.sky.ioc.service.device.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.sky.ioc.entity.domain.device.DeviceType;
|
|
|
+import com.sky.ioc.entity.domain.device.SecurityDevice;
|
|
|
+import com.sky.ioc.mapper.device.DeviceTypeMapper;
|
|
|
+import com.sky.ioc.mapper.device.SecurityDeviceMapper;
|
|
|
+import com.sky.ioc.service.device.SecurityDeviceService;
|
|
|
+import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.object.UpdatableSqlQuery;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class SecurityDeviceServiceImpl implements SecurityDeviceService {
|
|
|
+ @Autowired
|
|
|
+ SecurityDeviceMapper securityDeviceMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DeviceTypeMapper deviceTypeMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg editDevice(Integer id,String name,String device_location) {
|
|
|
+ if(StringUtils.isNotBlank(name)){
|
|
|
+ UpdateWrapper updateWrapper = new UpdateWrapper();
|
|
|
+ updateWrapper.eq("id",id);
|
|
|
+ updateWrapper.set("device_name",name);
|
|
|
+ updateWrapper.set("device_location",device_location);
|
|
|
+ securityDeviceMapper.update(null,updateWrapper);
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }else{
|
|
|
+ return ReturnMsg.fail("设备名称不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg addDevice(String device_ids,String device_type_id) {
|
|
|
+ if(StringUtils.isNotBlank(device_ids)){
|
|
|
+ DeviceType deviceType = deviceTypeMapper.selectById(device_type_id);
|
|
|
+ if(deviceType==null){
|
|
|
+ deviceType = new DeviceType();
|
|
|
+ deviceType.setId(Integer.valueOf(device_type_id));
|
|
|
+ deviceType.setDevice_ids(device_ids);
|
|
|
+ deviceTypeMapper.updateById(deviceType);
|
|
|
+ }else{
|
|
|
+
|
|
|
+ String ids = deviceType.getDevice_ids();
|
|
|
+ JSONArray json = JSON.parseArray(ids);
|
|
|
+ JSONArray jsonnew =JSONObject.parseArray(device_ids);
|
|
|
+ jsonnew.addAll(json);
|
|
|
+ deviceType.setDevice_ids(jsonnew.toJSONString());
|
|
|
+ deviceTypeMapper.updateById(deviceType);
|
|
|
+
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok();
|
|
|
+ }else{
|
|
|
+ return ReturnMsg.fail("设备id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg delDevice(String device_ids,String device_type_id) {
|
|
|
+ if (StringUtils.isNotBlank(device_ids)&&StringUtils.isNotBlank(device_type_id)){
|
|
|
+ DeviceType deviceType = deviceTypeMapper.selectById(device_type_id);
|
|
|
+ if(deviceType!=null){
|
|
|
+ String res = deviceType.getDevice_ids();
|
|
|
+ JSONArray ids = JSON.parseArray(device_ids);
|
|
|
+ JSONArray array = JSON.parseArray(res);
|
|
|
+ array.removeAll(ids);
|
|
|
+ deviceTypeMapper.updateById(deviceType);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return ReturnMsg.fail("设备id和设备类别不能为空");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getDevice(Integer id) {
|
|
|
+ if(id!=null){
|
|
|
+ SecurityDevice securityDevice = securityDeviceMapper.selectById(id);
|
|
|
+ return ReturnMsg.ok(securityDevice);
|
|
|
+ }else{
|
|
|
+ return ReturnMsg.fail("设备id不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|