Browse Source

修改启用/禁用状态接口

tags/V1.3.3^2
suqin 11 months ago
parent
commit
9452d11bf2
4 changed files with 83 additions and 0 deletions
  1. +12
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/IotEquipmentController.java
  2. +8
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/iotequipment/IotEquipmentService.java
  3. +12
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/iotequipment/IotEquipmentServiceImpl.java
  4. +51
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/iotequipment/edit/EditIotEquipmentService.java

+ 12
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/IotEquipmentController.java View File

@@ -73,4 +73,16 @@ public class IotEquipmentController {
public JsonResult deletedById(@PathVariable("id") String id) {
return iotEquipmentService.deletedById(id);
}


/**
* 启用禁用算法
*/
@PutMapping("/enable/{id}/{status}")
public JsonResult isEnabled(@PathVariable("id") String id,@PathVariable("status") Integer status ) {
return iotEquipmentService.isEnabled(id,status);
}



}

+ 8
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/iotequipment/IotEquipmentService.java View File

@@ -44,4 +44,12 @@ public interface IotEquipmentService {
*/
JsonResult deletedById(String id);


/**
* 启用、禁用
* @param id
* @param status
* @return
*/
JsonResult isEnabled(String id, int status);
}

+ 12
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/iotequipment/IotEquipmentServiceImpl.java View File

@@ -85,4 +85,16 @@ public class IotEquipmentServiceImpl implements IotEquipmentService {
public JsonResult deletedById(String id) {
return deleteEditIotEquipmentByIdService.deletedById(id);
}

/**
* 启用、禁用
* @param id
* @param status
* @return
*/
@Override
public JsonResult isEnabled(String id, int status) {
return editIotEquipmentService.isEnabled(id,status);
}

}

+ 51
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/iotequipment/edit/EditIotEquipmentService.java View File

@@ -97,4 +97,55 @@ public class EditIotEquipmentService {
return JsonResult.success();
}

/**
* 启用、禁用
* @param id
* @param status
* @return
*/
public JsonResult isEnabled(String id, int status) {
JsonResult result = this.check1(id, status);

if (0 != result.getCode()) {
log.info("物联设备状态:校验失败:{}", result.getMsg());
return result;
}

IotEquipment equipment = new IotEquipment();
equipment.setId(id);
equipment.setStatus(status);
int rowId = iotEquipmentMapper.updateById(equipment);
if (rowId <= 0) {
log.info("启用,禁用算法:失败:{}", result.getMsg());
return JsonResult.error("启用,禁用算法:失败");
}
return JsonResult.success();
}

/**
* 检查启用/禁用参数
* @param id
* @param status
* @return
*/
private JsonResult check1(String id,int status) {
if (StringUtils.isEmpty(id)) {
throw new ServiceException("设备Id码为空");
}
if(String.valueOf(status).equals("")){
throw new ServiceException("设备状态为空");
}

if(1 != status && 0 != status){
throw new ServiceException("无法修改状态,状态只有启用或者禁用两种!");
}

IotEquipment iotEquipment = iotEquipmentMapper.selectOne(new LambdaQueryWrapper<IotEquipment>()
.eq(IotEquipment::getId, id)
.eq(IotEquipment::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isEmpty(iotEquipment)) {
throw new ServiceException("该设备不存在");
}
return JsonResult.success(iotEquipment);
}
}

Loading…
Cancel
Save