iot设备绑定
This commit is contained in:
parent
7c42f093d4
commit
d0aec00ce0
|
|
@ -12,8 +12,14 @@ import lombok.Getter;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum ExceptionEnum {
|
public enum ExceptionEnum {
|
||||||
|
|
||||||
|
PARAM_NULL(1001, "参数为空"),
|
||||||
|
IOT_CODE_DUPLICATE(1002, "设备编号重复"),
|
||||||
|
IOT_TO_DELETE(1003, "该iot设备绑定相关类型设备,无法删除"),
|
||||||
|
SUCCESS(200, "操作成功"),
|
||||||
SAVE_TO_DATABASE(500, "新增保存失败,请联系管理员!!!"),
|
SAVE_TO_DATABASE(500, "新增保存失败,请联系管理员!!!"),
|
||||||
DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"),
|
DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"),
|
||||||
|
BIND_TO_DATABASE(500, "绑定失败,请联系管理员!!!"),
|
||||||
|
UN_BIND_TO_DATABASE(500, "解绑失败,请联系管理员!!!"),
|
||||||
UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!");
|
UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!");
|
||||||
|
|
||||||
private Integer code;
|
private Integer code;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后端生产随机编码通用方法(格式:今日年月日日期-随机4位编码 20240328-0001)
|
* 后端生产随机编码通用方法(格式:今日年月日日期-随机7位编码 20240328-0000001)
|
||||||
* @Author ma_sh
|
* @Author ma_sh
|
||||||
* @create 2024/3/28 17:42
|
* @create 2024/3/28 17:42
|
||||||
*/
|
*/
|
||||||
|
|
@ -15,7 +15,7 @@ public class FieldGenerator {
|
||||||
public static String generateField() {
|
public static String generateField() {
|
||||||
LocalDate today = LocalDate.now();
|
LocalDate today = LocalDate.now();
|
||||||
String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||||
// 生成UUID并取后4位,转换为纯数字类型
|
// 生成UUID并取后7位,转换为纯数字类型
|
||||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
String uuidLast4Digits = uuid.substring(uuid.length() - 7);
|
String uuidLast4Digits = uuid.substring(uuid.length() - 7);
|
||||||
int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16);
|
int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,149 @@
|
||||||
|
package com.bonus.sgzb.material.controller;
|
||||||
|
|
||||||
|
import com.bonus.sgzb.common.core.web.controller.BaseController;
|
||||||
|
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
|
||||||
|
import com.bonus.sgzb.material.domain.IotDto;
|
||||||
|
import com.bonus.sgzb.material.domain.IotRecordVo;
|
||||||
|
import com.bonus.sgzb.material.domain.IotVo;
|
||||||
|
import com.bonus.sgzb.material.service.IotMachineService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/4 16:23
|
||||||
|
* iot设备管理控制层
|
||||||
|
*/
|
||||||
|
@Api(tags = " iot设备管理控制层")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iotMachine")
|
||||||
|
@Slf4j
|
||||||
|
public class IotMachineController extends BaseController {
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IotMachineService iotMachineService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备管理列表
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "获取设备管理列表")
|
||||||
|
@GetMapping("/getIotList")
|
||||||
|
public TableDataInfo getIotList(IotDto iotDto) {
|
||||||
|
log.info("获取设备管理列表传参:{}", iotDto);
|
||||||
|
startPage();
|
||||||
|
List<IotVo> list = iotMachineService.getIotList(iotDto);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加或者修改设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("添加或者修改设备")
|
||||||
|
@PostMapping("/addOrUpdate")
|
||||||
|
public AjaxResult addOrUpdate(@Validated @RequestBody IotDto iotDto) {
|
||||||
|
log.info("添加或者修改设备传参:{}", iotDto);
|
||||||
|
if (iotDto.getIotId() != null) {
|
||||||
|
return iotMachineService.update(iotDto);
|
||||||
|
}
|
||||||
|
return iotMachineService.add(iotDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备
|
||||||
|
* @param iotId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "删除设备")
|
||||||
|
@DeleteMapping("/deleteById/{iotId}")
|
||||||
|
public AjaxResult deleteByIds(@PathVariable("iotId") Long iotId) {
|
||||||
|
log.info("删除设备传参:{}", iotId);
|
||||||
|
return iotMachineService.deleteById(iotId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("绑定设备")
|
||||||
|
@PostMapping("/bind")
|
||||||
|
public AjaxResult bind(@Validated @RequestBody IotDto iotDto) {
|
||||||
|
log.info("绑定设备传参:{}", iotDto);
|
||||||
|
return iotMachineService.bind(iotDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解绑设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("解绑设备")
|
||||||
|
@PostMapping("/unbind")
|
||||||
|
public AjaxResult unbind(@Validated @RequestBody IotDto iotDto) {
|
||||||
|
log.info("解绑设备传参:{}", iotDto);
|
||||||
|
return iotMachineService.unbind(iotDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型id查询设备绑定列表
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据类型id查询设备绑定列表")
|
||||||
|
@GetMapping("/getTypeList")
|
||||||
|
public TableDataInfo getTypeList(IotDto iotDto) {
|
||||||
|
startPage();
|
||||||
|
log.info("根据类型id查询设备绑定列表传参:{}", iotDto);
|
||||||
|
List<IotVo> typeList = iotMachineService.getTypeList(iotDto);
|
||||||
|
return getDataTable(typeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iot设备类型查询设备编码
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据iot设备类型查询设备编码")
|
||||||
|
@GetMapping("/selectList")
|
||||||
|
public AjaxResult selectList(IotDto iotDto) {
|
||||||
|
log.info("根据iot设备类型查询设备编码:{}", iotDto);
|
||||||
|
return iotMachineService.selectList(iotDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iot设备获取绑定记录(分页)
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据iot设备获取绑定记录(分页)")
|
||||||
|
@GetMapping("/getRecordList")
|
||||||
|
public TableDataInfo getRecordList(IotDto iotDto) {
|
||||||
|
startPage();
|
||||||
|
log.info("根据iot设备获取绑定记录(分页):{}", iotDto);
|
||||||
|
List<IotRecordVo> list = iotMachineService.getRecordList(iotDto);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iot设备获取绑定记录(全量不分页,供前端数据使用)
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据iot设备获取绑定记录(全量不分页,供前端数据使用)")
|
||||||
|
@GetMapping("/getRecordListAll")
|
||||||
|
public AjaxResult getRecordListAll(IotDto iotDto) {
|
||||||
|
List<IotRecordVo> list = iotMachineService.getRecordList(iotDto);
|
||||||
|
return AjaxResult.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.bonus.sgzb.material.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/11 15:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IotCodeVo {
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long iotId;
|
||||||
|
|
||||||
|
/** iot设备编码 */
|
||||||
|
@ApiModelProperty(value = "iot设备编码")
|
||||||
|
private String iotCode;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.bonus.sgzb.material.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/4 17:10
|
||||||
|
* iot设备管理传参dto
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IotDto {
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long iotId;
|
||||||
|
|
||||||
|
/** 类型id */
|
||||||
|
@ApiModelProperty(value = "类型id")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
/** 被绑定机具编号 */
|
||||||
|
@ApiModelProperty(value = "被绑定机具编号")
|
||||||
|
private String maCode;
|
||||||
|
|
||||||
|
/** iot设备类型 */
|
||||||
|
@ApiModelProperty(value = "iot设备类型")
|
||||||
|
private String iotType;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "iot设备类型id")
|
||||||
|
private String iotTypeId;
|
||||||
|
|
||||||
|
/** iot设备编码 */
|
||||||
|
@ApiModelProperty(value = "iot设备编码")
|
||||||
|
private String iotCode;
|
||||||
|
|
||||||
|
/** iot设备状态 (0 在线, 1 下线)*/
|
||||||
|
@ApiModelProperty(value = "iot设备状态 (0 在线, 1 下线)")
|
||||||
|
private int iotStatus;
|
||||||
|
|
||||||
|
/** iot设备二维码 */
|
||||||
|
@ApiModelProperty(value = "iot设备二维码")
|
||||||
|
private String qrCode;
|
||||||
|
|
||||||
|
/** 创建人 */
|
||||||
|
@ApiModelProperty(value = "创建人")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/** 更新人 */
|
||||||
|
@ApiModelProperty(value = "更新人")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/** 更新时间 */
|
||||||
|
@ApiModelProperty(value = "更新时间")
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
/** 绑定人 */
|
||||||
|
@ApiModelProperty(value = "绑定人")
|
||||||
|
private String binder;
|
||||||
|
|
||||||
|
/** 解绑人 */
|
||||||
|
@ApiModelProperty(value = "解绑人")
|
||||||
|
private String unBinder;
|
||||||
|
|
||||||
|
/** 关键字 */
|
||||||
|
@ApiModelProperty(value = "关键字")
|
||||||
|
private String keyWord;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.bonus.sgzb.material.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/11 15:55
|
||||||
|
* @Description iot绑定记录返回vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IotRecordVo {
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "iot设备id")
|
||||||
|
private Long iotId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "绑定类型id")
|
||||||
|
private Long typeId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "绑定类型名称")
|
||||||
|
private String typeName;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "设备编码")
|
||||||
|
private String maCode;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "绑定时间")
|
||||||
|
private String bindTime;
|
||||||
|
|
||||||
|
/** 解绑时间 */
|
||||||
|
@ApiModelProperty(value = "解绑时间")
|
||||||
|
private String unBindTime;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.bonus.sgzb.material.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/11 14:57
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IotTypeVo {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "iot设备类型id")
|
||||||
|
private String iotTypeId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "父级id")
|
||||||
|
private String pId;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "iot设备类型名称")
|
||||||
|
private String iotTypeName;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.bonus.sgzb.material.domain;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/4 17:00
|
||||||
|
* iot设备管理返回vo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class IotVo {
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** iot设备ID */
|
||||||
|
@ApiModelProperty(value = "iot设备ID")
|
||||||
|
private Long iotId;
|
||||||
|
|
||||||
|
/** iot设备类型 */
|
||||||
|
@ApiModelProperty(value = "iot设备类型")
|
||||||
|
private String iotType;
|
||||||
|
|
||||||
|
/** iot设备类型名称 */
|
||||||
|
@ApiModelProperty(value = "iot设备类型名称")
|
||||||
|
private String iotTypeName;
|
||||||
|
|
||||||
|
/** iot设备编码 */
|
||||||
|
@ApiModelProperty(value = "iot设备编码")
|
||||||
|
private String iotCode;
|
||||||
|
|
||||||
|
/** iot设备状态 (0 在线, 1 下线)*/
|
||||||
|
@ApiModelProperty(value = "iot设备状态 (0 在线, 1 下线)")
|
||||||
|
private int iotStatus;
|
||||||
|
|
||||||
|
/** iot设备二维码 */
|
||||||
|
@ApiModelProperty(value = "iot设备二维码")
|
||||||
|
private String qrCode;
|
||||||
|
|
||||||
|
/** iot设备绑定状态 (0 已绑定、1 未绑定)*/
|
||||||
|
@ApiModelProperty(value = "iot设备绑定状态 (0 已绑定、1 未绑定)")
|
||||||
|
private int bindStatus;
|
||||||
|
|
||||||
|
/** 绑定人 */
|
||||||
|
@ApiModelProperty(value = "绑定人")
|
||||||
|
private String binder;
|
||||||
|
|
||||||
|
/** 绑定时间 */
|
||||||
|
@ApiModelProperty(value = "绑定时间")
|
||||||
|
private String bindTime;
|
||||||
|
|
||||||
|
/** 解绑人 */
|
||||||
|
@ApiModelProperty(value = "解绑人")
|
||||||
|
private String unBinder;
|
||||||
|
|
||||||
|
/** 解绑时间 */
|
||||||
|
@ApiModelProperty(value = "解绑时间")
|
||||||
|
private String unBindTime;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
package com.bonus.sgzb.material.mapper;
|
||||||
|
|
||||||
|
import com.bonus.sgzb.material.domain.*;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/4 16:28
|
||||||
|
* iot设备管理mapper层
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface IotMachineMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iotCode查询iotCode是否存在
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IotVo selectIotCode(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据qrCode查询qrCode是否存在
|
||||||
|
* @param qrCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int selectQrCode(String qrCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加iot设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int add(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改iot设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int update(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iotCode查询iotCode是否存在
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotVo> getIotList(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iotId查询iotId是否存在
|
||||||
|
* @param iotId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
IotVo selectById(Long iotId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iotId删除iot设备
|
||||||
|
* @param iotId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deleteById(Long iotId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定iot设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int bind(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新绑定状态
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int updateBindStatus(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解绑iot设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int unbind(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新解绑状态
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int updateUnBindStatus(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型id查询设备绑定列表
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotVo> getTypeList(IotDto iotDto);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备类型
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotTypeVo> selectList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iotTypeId查询设备编码
|
||||||
|
* @param iotTypeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotCodeVo> selectCodeList(String iotTypeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iotTypeId查询设备编码
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotRecordVo> getRecordList(IotDto iotDto);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.bonus.sgzb.material.service;
|
||||||
|
|
||||||
|
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.sgzb.material.domain.IotDto;
|
||||||
|
import com.bonus.sgzb.material.domain.IotRecordVo;
|
||||||
|
import com.bonus.sgzb.material.domain.IotVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ma_sh
|
||||||
|
* @create 2024/7/4 16:25
|
||||||
|
* iot设备管理服务层
|
||||||
|
*/
|
||||||
|
public interface IotMachineService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult add(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult update(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备列表
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotVo> getIotList(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备
|
||||||
|
* @param iotId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult deleteById(Long iotId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult bind(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解绑设备
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult unbind(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型id查询设备绑定列表
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotVo> getTypeList(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iot设备类型查询设备编码
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
AjaxResult selectList(IotDto iotDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备记录列表
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<IotRecordVo> getRecordList(IotDto iotDto);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,268 @@
|
||||||
|
package com.bonus.sgzb.material.service.impl;
|
||||||
|
|
||||||
|
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||||
|
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||||
|
import com.bonus.sgzb.material.config.ExceptionEnum;
|
||||||
|
import com.bonus.sgzb.material.config.FieldGenerator;
|
||||||
|
import com.bonus.sgzb.material.domain.*;
|
||||||
|
import com.bonus.sgzb.material.mapper.IotMachineMapper;
|
||||||
|
import com.bonus.sgzb.material.service.IotMachineService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iot设备管理实现层
|
||||||
|
* @author ma_sh
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class IotMachineServiceImpl implements IotMachineService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IotMachineMapper iotMachineMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加设备-保存
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult add(IotDto iotDto) {
|
||||||
|
if (iotDto == null || iotDto.getIotCode() == null || iotDto.getIotType() == null) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
|
||||||
|
}
|
||||||
|
//根据前端传入设备编号判重
|
||||||
|
IotVo iotVo = iotMachineMapper.selectIotCode(iotDto);
|
||||||
|
if (iotVo != null) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(), ExceptionEnum.IOT_CODE_DUPLICATE.getMsg());
|
||||||
|
}
|
||||||
|
//后端生成二维码编号,需判重,确保表中数据唯一性
|
||||||
|
String qrCode = FieldGenerator.generateField();
|
||||||
|
// 设置最大尝试次数10,避免无限循环
|
||||||
|
int maxAttempts = 10;
|
||||||
|
for (int attempt = 0; attempt < maxAttempts; attempt++) {
|
||||||
|
if (iotMachineMapper.selectQrCode(qrCode) == 0) {
|
||||||
|
iotDto.setQrCode(qrCode);
|
||||||
|
// 找到唯一的qrCode,退出循环
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// 生成新的qrCode
|
||||||
|
qrCode = FieldGenerator.generateField();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iotDto.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString());
|
||||||
|
try {
|
||||||
|
// 进行设备添加
|
||||||
|
int res = iotMachineMapper.add(iotDto);
|
||||||
|
if (res == 0) {
|
||||||
|
// 如果添加失败,返回保存到数据库异常的错误信息
|
||||||
|
throw new RuntimeException(ExceptionEnum.SAVE_TO_DATABASE.getMsg());
|
||||||
|
} else {
|
||||||
|
// 添加成功,返回成功的消息和新增的记录数
|
||||||
|
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error saving to database: " + e.getMessage());
|
||||||
|
// 捕获所有异常,返回通用的数据库操作异常信息
|
||||||
|
return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备管理-修改
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult update(IotDto iotDto) {
|
||||||
|
if (iotDto == null || iotDto.getIotId() == null) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
|
||||||
|
}
|
||||||
|
IotVo iotVo = iotMachineMapper.selectIotCode(iotDto);
|
||||||
|
if (iotVo != null && !iotVo.getIotId().equals(iotDto.getIotId())) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(), ExceptionEnum.IOT_CODE_DUPLICATE.getMsg());
|
||||||
|
}
|
||||||
|
iotDto.setUpdateBy(SecurityUtils.getLoginUser().getUserid().toString());
|
||||||
|
try {
|
||||||
|
//设备修改
|
||||||
|
int res = iotMachineMapper.update(iotDto);
|
||||||
|
if (res == 0) {
|
||||||
|
// 如果修改失败,返回修改到数据库异常的错误信息
|
||||||
|
throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||||
|
} else {
|
||||||
|
// 修改成功,返回成功的消息和修改的记录数
|
||||||
|
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error updating to database: " + e.getMessage());
|
||||||
|
//捕获异常
|
||||||
|
return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备列表
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<IotVo> getIotList(IotDto iotDto) {
|
||||||
|
return iotMachineMapper.getIotList(iotDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备
|
||||||
|
*
|
||||||
|
* @param iotId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult deleteById(Long iotId) {
|
||||||
|
//先进行判断,绑定设备的iot设备无法删除
|
||||||
|
IotVo iotVo = iotMachineMapper.selectById(iotId);
|
||||||
|
if (iotVo.getBindStatus() == 0) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.IOT_TO_DELETE.getCode(), ExceptionEnum.IOT_TO_DELETE.getMsg());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 执行设备删除操作
|
||||||
|
int res = iotMachineMapper.deleteById(iotId);
|
||||||
|
if (res == 0) {
|
||||||
|
// 如果删除操作未成功,返回删除数据库异常的错误信息
|
||||||
|
return AjaxResult.error(ExceptionEnum.DELETE_TO_DATABASE.getCode(), ExceptionEnum.DELETE_TO_DATABASE.getMsg());
|
||||||
|
} else {
|
||||||
|
// 删除成功,返回成功的消息和受影响的记录数
|
||||||
|
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error deleting from database: " + e.getMessage());
|
||||||
|
// 捕获所有异常,返回通用的数据库操作异常信息
|
||||||
|
return AjaxResult.error(ExceptionEnum.DELETE_TO_DATABASE.getCode(), ExceptionEnum.DELETE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绑定设备
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult bind(IotDto iotDto) {
|
||||||
|
if (iotDto == null || iotDto.getIotId() == null || iotDto.getMaCode() == null) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
|
||||||
|
}
|
||||||
|
iotDto.setBinder(SecurityUtils.getLoginUser().getUserid().toString());
|
||||||
|
int res;
|
||||||
|
try {
|
||||||
|
//绑定设备
|
||||||
|
res = iotMachineMapper.bind(iotDto);
|
||||||
|
if (res == 0) {
|
||||||
|
throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
//更新绑定状态
|
||||||
|
res = iotMachineMapper.updateBindStatus(iotDto);
|
||||||
|
if (res == 0) {
|
||||||
|
throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("设备绑定异常:{}", e.getMessage());
|
||||||
|
// 添加事务回滚逻辑,保证全部成功或者全部失败
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解绑设备
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult unbind(IotDto iotDto) {
|
||||||
|
if (iotDto == null || iotDto.getIotId() == null || iotDto.getMaCode() == null) {
|
||||||
|
return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
|
||||||
|
}
|
||||||
|
iotDto.setUnBinder(SecurityUtils.getLoginUser().getUserid().toString());
|
||||||
|
int res;
|
||||||
|
try {
|
||||||
|
//解绑设备
|
||||||
|
res = iotMachineMapper.unbind(iotDto);
|
||||||
|
if (res == 0) {
|
||||||
|
throw new RuntimeException(ExceptionEnum.UN_BIND_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
//更新绑定状态
|
||||||
|
res = iotMachineMapper.updateUnBindStatus(iotDto);
|
||||||
|
if (res == 0) {
|
||||||
|
throw new RuntimeException(ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("设备解绑异常:{}", e.getMessage());
|
||||||
|
// 添加事务回滚逻辑,保证入库全部成功或者全部失败
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||||
|
}
|
||||||
|
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据类型id查询设备绑定列表
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<IotVo> getTypeList(IotDto iotDto) {
|
||||||
|
if (iotDto == null || iotDto.getMaCode() == null) {
|
||||||
|
throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
|
||||||
|
}
|
||||||
|
List<IotVo> iotVoList = iotMachineMapper.getTypeList(iotDto);
|
||||||
|
return iotVoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据iot设备类型查询设备编码
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult selectList(IotDto iotDto) {
|
||||||
|
if (iotDto != null && iotDto.getIotTypeId() != null) {
|
||||||
|
// 如果传入了iot设备类型,根据iot设备类型查询设备编码
|
||||||
|
List<IotCodeVo> iotCodeList = iotMachineMapper.selectCodeList(iotDto.getIotTypeId());
|
||||||
|
return AjaxResult.success(iotCodeList);
|
||||||
|
} else {
|
||||||
|
// 如果iotDto为null或者iotDto的iotType为null,单独查询iot设备类型列表
|
||||||
|
List<IotTypeVo> iotTypeList = iotMachineMapper.selectList();
|
||||||
|
return AjaxResult.success(iotTypeList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询iot绑定记录
|
||||||
|
*
|
||||||
|
* @param iotDto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<IotRecordVo> getRecordList(IotDto iotDto) {
|
||||||
|
if (iotDto == null || iotDto.getIotId() == null) {
|
||||||
|
throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
|
||||||
|
}
|
||||||
|
List<IotRecordVo> iotRecordList = iotMachineMapper.getRecordList(iotDto);
|
||||||
|
return iotRecordList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,207 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.bonus.sgzb.material.mapper.IotMachineMapper">
|
||||||
|
|
||||||
|
<insert id="add">
|
||||||
|
insert into iot_machine
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="iotType != null">iot_type,</if>
|
||||||
|
<if test="iotCode != null and iotCode != ''">iot_code,</if>
|
||||||
|
iot_status,
|
||||||
|
<if test="qrCode != null">qr_code,</if>
|
||||||
|
bind_status,
|
||||||
|
del_flag,
|
||||||
|
<if test="createBy != null">create_by,</if>
|
||||||
|
create_time
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="iotType != null">#{iotType},</if>
|
||||||
|
<if test="iotCode != null and iotCode != ''">#{iotCode},</if>
|
||||||
|
0,
|
||||||
|
<if test="qrCode != null">#{qrCode},</if>
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
<if test="createBy != null">#{createBy},</if>
|
||||||
|
NOW()
|
||||||
|
</trim>
|
||||||
|
|
||||||
|
</insert>
|
||||||
|
<insert id="bind">
|
||||||
|
insert into iot_machine_bind
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="iotId != null">iot_id,</if>
|
||||||
|
<if test="typeId != null and typeId != ''">type_id,</if>
|
||||||
|
<if test="maCode != null">ma_code,</if>
|
||||||
|
<if test="binder != null">binder,</if>
|
||||||
|
bind_time
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="iotId != null">#{iotId},</if>
|
||||||
|
<if test="typeId != null and typeId != ''">#{typeId},</if>
|
||||||
|
<if test="maCode != null">#{maCode},</if>
|
||||||
|
<if test="binder != null">#{binder},</if>
|
||||||
|
NOW()
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="update">
|
||||||
|
UPDATE iot_machine
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="iotType != null ">iot_type = #{iotType},</if>
|
||||||
|
<if test="iotCode != null">iot_code = #{iotCode},</if>
|
||||||
|
<if test="iotStatus != null">iot_status = #{iotStatus},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
update_time = NOW()
|
||||||
|
</trim>
|
||||||
|
WHERE id = #{iotId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="deleteById">
|
||||||
|
UPDATE iot_machine SET del_flag = '2' WHERE id = #{iotId}
|
||||||
|
</update>
|
||||||
|
<update id="updateBindStatus">
|
||||||
|
UPDATE iot_machine SET bind_status = '0', update_time = NOW() WHERE id = #{iotId}
|
||||||
|
</update>
|
||||||
|
<update id="unbind">
|
||||||
|
UPDATE iot_machine_bind SET unbinder = #{unBinder}, unbind_time = NOW() WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
<update id="updateUnBindStatus">
|
||||||
|
UPDATE iot_machine SET bind_status = '1', update_time = NOW() WHERE id = #{iotId}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="selectQrCode" resultType="java.lang.Integer">
|
||||||
|
SELECT
|
||||||
|
COUNT(*)
|
||||||
|
FROM
|
||||||
|
iot_machine
|
||||||
|
WHERE
|
||||||
|
del_flag = '0'
|
||||||
|
AND qr_code = #{qrCode}
|
||||||
|
</select>
|
||||||
|
<select id="selectIotCode" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||||
|
SELECT
|
||||||
|
id AS iotId,
|
||||||
|
iot_code AS iotCode,
|
||||||
|
iot_type AS iotType,
|
||||||
|
iot_status AS iotStatus,
|
||||||
|
qr_code AS qrCode
|
||||||
|
FROM
|
||||||
|
iot_machine
|
||||||
|
WHERE
|
||||||
|
del_flag = '0'
|
||||||
|
AND iot_type = #{iotType}
|
||||||
|
AND iot_code = #{iotCode}
|
||||||
|
</select>
|
||||||
|
<select id="getIotList" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||||
|
SELECT
|
||||||
|
im.id AS iotId,
|
||||||
|
im.iot_code AS iotCode,
|
||||||
|
im.iot_type AS iotType,
|
||||||
|
im.iot_status AS iotStatus,
|
||||||
|
sd.name AS iotTypeName,
|
||||||
|
im.qr_code AS qrCode,
|
||||||
|
im.bind_status AS bindStatus
|
||||||
|
FROM
|
||||||
|
iot_machine im
|
||||||
|
LEFT JOIN sys_dic sd on im.iot_type = sd.id
|
||||||
|
WHERE
|
||||||
|
del_flag = '0'
|
||||||
|
<if test="keyWord != null and keyWord != ''">
|
||||||
|
AND (iot_type like concat('%', #{keyWord}, '%') or
|
||||||
|
iot_code like concat('%', #{keyWord}, '%')
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
<select id="selectById" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||||
|
SELECT
|
||||||
|
id AS iotId,
|
||||||
|
iot_code AS iotCode,
|
||||||
|
iot_type AS iotType,
|
||||||
|
iot_status AS iotStatus,
|
||||||
|
qr_code AS qrCode,
|
||||||
|
bind_status AS bindStatus
|
||||||
|
FROM
|
||||||
|
iot_machine
|
||||||
|
WHERE
|
||||||
|
del_flag = '0'
|
||||||
|
AND id = #{iotId}
|
||||||
|
</select>
|
||||||
|
<select id="getTypeList" resultType="com.bonus.sgzb.material.domain.IotVo">
|
||||||
|
SELECT
|
||||||
|
imb.id AS id,
|
||||||
|
im.iot_type AS iotType,
|
||||||
|
sd.name AS iotTypeName,
|
||||||
|
im.iot_code AS iotCode,
|
||||||
|
im.iot_status AS iotStatus,
|
||||||
|
imb.iot_id AS iotId,
|
||||||
|
imb.bind_time AS bindTime,
|
||||||
|
im.bind_status AS bindStatus
|
||||||
|
FROM
|
||||||
|
iot_machine im
|
||||||
|
LEFT JOIN sys_dic sd on im.iot_type = sd.id
|
||||||
|
LEFT JOIN iot_machine_bind imb ON im.id = imb.iot_id
|
||||||
|
WHERE
|
||||||
|
im.del_flag = '0'
|
||||||
|
AND im.bind_status = '0'
|
||||||
|
AND imb.unbind_time IS NULL
|
||||||
|
AND imb.ma_code = #{maCode}
|
||||||
|
<if test="keyWord != null and keyWord != ''">
|
||||||
|
AND (
|
||||||
|
im.iot_type like concat('%', #{keyWord}, '%') or
|
||||||
|
im.iot_code like concat('%', #{keyWord}, '%')
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectList" resultType="com.bonus.sgzb.material.domain.IotTypeVo">
|
||||||
|
SELECT
|
||||||
|
id AS iotTypeId,
|
||||||
|
p_id AS pId,
|
||||||
|
name AS iotTypeName
|
||||||
|
FROM
|
||||||
|
sys_dic
|
||||||
|
WHERE
|
||||||
|
status = '0'
|
||||||
|
AND p_id = '124'
|
||||||
|
</select>
|
||||||
|
<select id="selectCodeList" resultType="com.bonus.sgzb.material.domain.IotCodeVo">
|
||||||
|
SELECT
|
||||||
|
id AS iotId,
|
||||||
|
iot_code AS iotCode
|
||||||
|
FROM
|
||||||
|
iot_machine
|
||||||
|
WHERE
|
||||||
|
del_flag = '0'
|
||||||
|
AND iot_status = '0'
|
||||||
|
AND bind_status = '1'
|
||||||
|
AND iot_type = #{iotType}
|
||||||
|
</select>
|
||||||
|
<select id="getRecordList" resultType="com.bonus.sgzb.material.domain.IotRecordVo">
|
||||||
|
SELECT
|
||||||
|
imb.id AS id,
|
||||||
|
mt1.type_name AS typeName,
|
||||||
|
imb.ma_code AS maCode,
|
||||||
|
imb.type_id AS typeId,
|
||||||
|
imb.bind_time AS bindTime,
|
||||||
|
imb.unbind_time AS unBindTime
|
||||||
|
FROM
|
||||||
|
iot_machine_bind imb
|
||||||
|
LEFT JOIN ma_type mt ON imb.type_id = mt.type_id
|
||||||
|
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id
|
||||||
|
LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id
|
||||||
|
LEFT JOIN ma_type mt3 ON mt2.parent_id = mt3.type_id
|
||||||
|
LEFT JOIN iot_machine im ON imb.iot_id = im.id
|
||||||
|
WHERE
|
||||||
|
im.del_flag = '0'
|
||||||
|
AND im.id = #{iotId}
|
||||||
|
<if test="keyWord != null and keyWord != ''">
|
||||||
|
AND (
|
||||||
|
mt1.type_name like concat('%', #{keyWord}, '%') or
|
||||||
|
imb.ma_code like concat('%', #{keyWord}, '%')
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue