IOT定位设备
This commit is contained in:
parent
172ff1e0b9
commit
479e08dda0
|
|
@ -0,0 +1,38 @@
|
|||
package com.bonus.material.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 返回异常枚举类
|
||||
* @Author ma_sh
|
||||
* @create 2025/01/24
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ExceptionEnum {
|
||||
|
||||
PARAM_NULL(1001, "参数为空"),
|
||||
IOT_CODE_DUPLICATE(1002, "设备编号重复"),
|
||||
IOT_TO_DELETE(1003, "该iot设备绑定相关类型设备,无法删除"),
|
||||
SUCCESS(200, "操作成功"),
|
||||
SAVE_TO_DATABASE(500, "新增保存失败,请联系管理员!!!"),
|
||||
DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"),
|
||||
BIND_TO_DATABASE(500, "绑定失败,请联系管理员!!!"),
|
||||
UN_BIND_TO_DATABASE(500, "解绑失败,请联系管理员!!!"),
|
||||
UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!"),
|
||||
|
||||
RETURN_DATA_IS_EMPTY(501, "返回数据为空!!"),
|
||||
IOT_ENCODING_ERROR(502, "输入的IOT编码有误,请输入正确的编码!!!");
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
package com.bonus.material.device.controller;
|
||||
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.material.device.domain.IotDto;
|
||||
import com.bonus.material.device.domain.vo.IotRecordVo;
|
||||
import com.bonus.material.device.domain.vo.IotVo;
|
||||
import com.bonus.material.device.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 javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2024/01/24 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出绑定记录
|
||||
* @param response
|
||||
* @param iotDto
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, IotDto iotDto) {
|
||||
try {
|
||||
List<IotRecordVo> list = iotMachineService.getRecordList(iotDto);
|
||||
ExcelUtil<IotRecordVo> util = new ExcelUtil<>(IotRecordVo.class);
|
||||
util.exportExcel(response, list, "绑定明细数据");
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("获取定位")
|
||||
@PostMapping("/getLocation")
|
||||
public AjaxResult getLocation(@Validated @RequestBody IotDto iotDto) {
|
||||
log.info("获取定位接口:{}", iotDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation("查询行程")
|
||||
@PostMapping("/searchItinerary")
|
||||
public AjaxResult searchItinerary(@Validated @RequestBody IotDto iotDto) {
|
||||
log.info("查询行程接口:{}", iotDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation("查询停留点")
|
||||
@PostMapping("/reportParkDetailByTime")
|
||||
public AjaxResult reportParkDetailByTime(@Validated @RequestBody IotDto iotDto) {
|
||||
log.info("查询停留点接口:{}", iotDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@ApiOperation("报警记录")
|
||||
@PostMapping("/reportAlarm")
|
||||
public AjaxResult reportAlarm(@Validated @RequestBody IotDto iotDto) {
|
||||
log.info("报警记录接口:{}", iotDto);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package com.bonus.material.device.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2025/01/24
|
||||
* 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 typeName;
|
||||
|
||||
/** 被绑定机具编号 */
|
||||
@ApiModelProperty(value = "被绑定机具编号")
|
||||
private String maCode;
|
||||
|
||||
/** iot设备类型 */
|
||||
@ApiModelProperty(value = "iot设备类型")
|
||||
private String iotType;
|
||||
|
||||
@ApiModelProperty(value = "iot设备名称")
|
||||
private String iotName;
|
||||
|
||||
/** iot设备编码 */
|
||||
@ApiModelProperty(value = "iot设备编码")
|
||||
private String iotCode;
|
||||
|
||||
/** iot设备状态 (0 在线, 1 下线)*/
|
||||
@ApiModelProperty(value = "iot设备状态 (0 在线, 1 下线)")
|
||||
private int iotStatus;
|
||||
|
||||
@ApiModelProperty(value = "iot设备负责人")
|
||||
private String iotManager;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String address;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
/** 创建人 */
|
||||
@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,57 @@
|
|||
package com.bonus.material.device.domain.vo;
|
||||
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2025/01/24
|
||||
* @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 = "绑定的装备名称")
|
||||
@Excel(name = "装备名称")
|
||||
private String typeName;
|
||||
|
||||
@ApiModelProperty(value = "装备编码")
|
||||
@Excel(name = "装备编码")
|
||||
private String maCode;
|
||||
|
||||
@ApiModelProperty(value = "是否解绑")
|
||||
@Excel(name = "是否解绑", readConverterExp = "0=否,1=是")
|
||||
private String bindStatus;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
@Excel(name = "地址", width = 30)
|
||||
private String address;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
@Excel(name = "备注", width = 30)
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "iot设备负责人")
|
||||
@Excel(name = "设备负责人")
|
||||
private String iotManager;
|
||||
|
||||
@ApiModelProperty(value = "绑定时间")
|
||||
@Excel(name = "绑定时间")
|
||||
private String bindTime;
|
||||
|
||||
@ApiModelProperty(value = "解绑时间")
|
||||
@Excel(name = "解绑时间")
|
||||
private String unBindTime;
|
||||
|
||||
@ApiModelProperty(value = "绑定天数")
|
||||
@Excel(name = "绑定天数", cellType = Excel.ColumnType.NUMERIC)
|
||||
private String bindDays;
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.bonus.material.device.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2025/01/24
|
||||
* iot设备管理返回vo
|
||||
*/
|
||||
@Data
|
||||
public class IotVo {
|
||||
|
||||
@ApiModelProperty(value = "绑定明细id")
|
||||
private Long id;
|
||||
|
||||
/** iot设备ID */
|
||||
@ApiModelProperty(value = "iot设备ID")
|
||||
private Long iotId;
|
||||
|
||||
/** iot设备类型 */
|
||||
@ApiModelProperty(value = "iot设备类型")
|
||||
private String iotType;
|
||||
|
||||
@ApiModelProperty(value = "iot设备名称")
|
||||
private String iotName;
|
||||
|
||||
/** iot设备编码 */
|
||||
@ApiModelProperty(value = "iot设备编码")
|
||||
private String iotCode;
|
||||
|
||||
@ApiModelProperty(value = "装备名称")
|
||||
private String typeName;
|
||||
|
||||
@ApiModelProperty(value = "装备编码")
|
||||
private String maCode;
|
||||
|
||||
/** iot设备状态 (0 在线, 1 下线)*/
|
||||
@ApiModelProperty(value = "iot设备状态 (0 在线, 1 下线)")
|
||||
private int iotStatus;
|
||||
|
||||
@ApiModelProperty(value = "iot设备负责人")
|
||||
private String iotManager;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String address;
|
||||
|
||||
/** 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;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
package com.bonus.material.device.mapper;
|
||||
|
||||
import com.bonus.material.device.domain.IotDto;
|
||||
import com.bonus.material.device.domain.vo.IotRecordVo;
|
||||
import com.bonus.material.device.domain.vo.IotVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2025/01/24 16:28
|
||||
* iot设备管理mapper层
|
||||
*/
|
||||
@Mapper
|
||||
public interface IotMachineMapper {
|
||||
|
||||
/**
|
||||
* 根据iotCode查询iotCode是否存在
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
IotVo selectIotCode(IotDto iotDto);
|
||||
|
||||
/**
|
||||
* 添加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);
|
||||
|
||||
/**
|
||||
* 根据iotTypeId查询设备编码
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
List<IotRecordVo> getRecordList(IotDto iotDto);
|
||||
|
||||
/**
|
||||
* 保证设备名称不重复
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
IotVo selectByName(IotDto iotDto);
|
||||
|
||||
/**
|
||||
* 判断该装备是否已经绑定
|
||||
* @param maCode
|
||||
* @return
|
||||
*/
|
||||
List<IotVo> getInfoList(String maCode);
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package com.bonus.material.device.service;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.device.domain.IotDto;
|
||||
import com.bonus.material.device.domain.vo.IotRecordVo;
|
||||
import com.bonus.material.device.domain.vo.IotVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2025/01/24 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);
|
||||
|
||||
/**
|
||||
* 获取设备记录列表
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
List<IotRecordVo> getRecordList(IotDto iotDto);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,234 @@
|
|||
package com.bonus.material.device.service.impl;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.common.enums.ExceptionEnum;
|
||||
import com.bonus.material.device.domain.IotDto;
|
||||
import com.bonus.material.device.domain.vo.IotRecordVo;
|
||||
import com.bonus.material.device.domain.vo.IotVo;
|
||||
import com.bonus.material.device.mapper.IotMachineMapper;
|
||||
import com.bonus.material.device.service.IotMachineService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
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.getIotName() == null) {
|
||||
return AjaxResult.error(ExceptionEnum.PARAM_NULL.getCode(), ExceptionEnum.PARAM_NULL.getMsg());
|
||||
}
|
||||
//保证设备名称不重复
|
||||
IotVo nameInfo = iotMachineMapper.selectByName(iotDto);
|
||||
if (nameInfo != null) {
|
||||
return AjaxResult.error("iot设备名称不能重复");
|
||||
}
|
||||
IotVo iotVo = iotMachineMapper.selectIotCode(iotDto);
|
||||
if (iotVo != null) {
|
||||
return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getMsg());
|
||||
}
|
||||
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 nameInfo = iotMachineMapper.selectByName(iotDto);
|
||||
if (nameInfo != null && !nameInfo.getIotId().equals(iotDto.getIotId())) {
|
||||
return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(),"设备名称不能重复");
|
||||
}
|
||||
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());
|
||||
}
|
||||
// 先判断该iot设备是否已经绑定
|
||||
IotVo iotVo = iotMachineMapper.selectById(iotDto.getIotId());
|
||||
if (iotVo.getBindStatus() == 0) {
|
||||
return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(),"该iot设备已绑定相关设备,无法再次进行绑定");
|
||||
}
|
||||
// 判断该装备是否已经绑定iot设备
|
||||
List<IotVo> list = iotMachineMapper.getInfoList(iotDto.getMaCode());
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
return AjaxResult.error(ExceptionEnum.IOT_CODE_DUPLICATE.getCode(),"该装备已绑定其他iot设备,请勿重复绑定");
|
||||
}
|
||||
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());
|
||||
throw new RuntimeException(ExceptionEnum.BIND_TO_DATABASE.getMsg());
|
||||
}
|
||||
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑设备
|
||||
*
|
||||
* @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());
|
||||
throw new RuntimeException(ExceptionEnum.UN_BIND_TO_DATABASE.getMsg());
|
||||
}
|
||||
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询iot绑定记录
|
||||
*
|
||||
* @param iotDto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<IotRecordVo> getRecordList(IotDto iotDto) {
|
||||
if (iotDto == null || iotDto.getIotId() == null) {
|
||||
throw new RuntimeException(ExceptionEnum.PARAM_NULL.getMsg());
|
||||
}
|
||||
return iotMachineMapper.getRecordList(iotDto);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
<?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.material.device.mapper.IotMachineMapper">
|
||||
<insert id="add">
|
||||
insert into iot_machine
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="iotName != null and iotName != ''">iot_name,</if>
|
||||
<if test="iotCode != null and iotCode != ''">iot_code,</if>
|
||||
<if test="iotStatus != null">iot_status,</if>
|
||||
<if test="iotManager != null and iotManager != ''">iot_manager,</if>
|
||||
bind_status,
|
||||
del_flag,
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="address != null and address != ''">address,</if>
|
||||
create_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="iotName != null and iotName != ''">#{iotName},</if>
|
||||
<if test="iotCode != null and iotCode != ''">#{iotCode},</if>
|
||||
<if test="iotStatus != null">#{iotStatus},</if>
|
||||
<if test="iotManager != null and iotManager != ''">#{iotManager},</if>
|
||||
1,
|
||||
0,
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="address != null and address != ''">#{address},</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="typeName != null and typeName != ''">type_name,</if>
|
||||
<if test="maCode != null and maCode != ''">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="typeName != null and typeName != ''">#{typeName},</if>
|
||||
<if test="maCode != null and maCode != ''">#{maCode},</if>
|
||||
<if test="binder != null">#{binder},</if>
|
||||
NOW()
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE iot_machine
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="iotName != null and iotName != ''">iot_name = #{iotName},</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>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="iotManager != null and iotManager != ''">iot_manager = #{iotManager},</if>
|
||||
<if test="address != null and address != ''">address = #{address},</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="getIotList" resultType="com.bonus.material.device.domain.vo.IotVo">
|
||||
SELECT
|
||||
im.id AS iotId,
|
||||
im.iot_code AS iotCode,
|
||||
im.iot_name AS iotName,
|
||||
im.iot_status AS iotStatus,
|
||||
im.iot_manager AS iotManager,
|
||||
im.address AS address,
|
||||
im.bind_status AS bindStatus,
|
||||
MAX(imb.bind_time) AS bindTime,
|
||||
CASE
|
||||
WHEN MAX(imb.bind_time) IS NOT NULL THEN imb.unbind_time
|
||||
ELSE NULL
|
||||
END AS unBindTime,
|
||||
CASE
|
||||
WHEN MAX(imb.bind_time) IS NOT NULL AND im.bind_status = '0'
|
||||
THEN imb.type_name
|
||||
ELSE NULL
|
||||
END AS typeName,
|
||||
CASE
|
||||
WHEN MAX(imb.bind_time) IS NOT NULL AND im.bind_status = '0'
|
||||
THEN imb.ma_code
|
||||
ELSE NULL
|
||||
END AS maCode,
|
||||
CASE
|
||||
WHEN MAX(imb.bind_time) IS NOT NULL THEN imb.id
|
||||
ELSE NULL
|
||||
END AS id,
|
||||
im.remark AS remark
|
||||
FROM
|
||||
iot_machine im
|
||||
LEFT JOIN iot_machine_bind imb on im.id = imb.iot_id
|
||||
WHERE
|
||||
im.del_flag = '0'
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
AND (
|
||||
im.iot_name like concat('%', #{keyWord}, '%') OR
|
||||
im.iot_code like concat('%', #{keyWord}, '%') OR
|
||||
imb.type_name LIKE concat('%', #{keyWord}, '%') OR
|
||||
imb.ma_code LIKE concat('%', #{keyWord}, '%')
|
||||
)
|
||||
</if>
|
||||
GROUP BY
|
||||
im.id, im.iot_code
|
||||
ORDER BY
|
||||
im.create_time
|
||||
DESC
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="com.bonus.material.device.domain.vo.IotVo">
|
||||
SELECT
|
||||
id AS iotId,
|
||||
iot_code AS iotCode,
|
||||
iot_name AS iotName,
|
||||
iot_status AS iotStatus,
|
||||
bind_status AS bindStatus
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
AND id = #{iotId}
|
||||
</select>
|
||||
|
||||
<select id="getRecordList" resultType="com.bonus.material.device.domain.vo.IotRecordVo">
|
||||
SELECT
|
||||
imb.id AS id,
|
||||
imb.type_name AS typeName,
|
||||
imb.ma_code AS maCode,
|
||||
im.address AS address,
|
||||
im.remark AS remark,
|
||||
im.iot_manager AS iotManager,
|
||||
imb.bind_time AS bindTime,
|
||||
imb.unbind_time AS unBindTime,
|
||||
CASE
|
||||
WHEN imb.unbind_time IS NULL THEN 0
|
||||
ELSE 1
|
||||
END AS bindStatus,
|
||||
CASE
|
||||
WHEN imb.unbind_time IS NULL THEN 0
|
||||
ELSE TIMESTAMPDIFF(DAY, imb.bind_time, imb.unbind_time)
|
||||
END AS bindDays
|
||||
FROM
|
||||
iot_machine_bind imb
|
||||
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 (
|
||||
imb.type_name like concat('%', #{keyWord}, '%') or
|
||||
im.address like concat('%', #{keyWord}, '%') or
|
||||
im.remark like concat('%', #{keyWord}, '%') or
|
||||
im.iot_manager like concat('%', #{keyWord}, '%')
|
||||
)
|
||||
</if>
|
||||
ORDER BY
|
||||
imb.bind_time
|
||||
DESC
|
||||
</select>
|
||||
|
||||
<select id="selectIotCode" resultType="com.bonus.material.device.domain.vo.IotVo">
|
||||
SELECT
|
||||
id AS iotId,
|
||||
iot_code AS iotCode,
|
||||
iot_name AS iotName,
|
||||
iot_status AS iotStatus
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
<if test="iotCode != null and iotCode != ''" >
|
||||
AND iot_code = #{iotCode}
|
||||
</if>
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectByName" resultType="com.bonus.material.device.domain.vo.IotVo">
|
||||
SELECT
|
||||
id AS iotId,
|
||||
iot_code AS iotCode,
|
||||
iot_name AS iotName,
|
||||
iot_status AS iotStatus
|
||||
FROM
|
||||
iot_machine
|
||||
WHERE
|
||||
del_flag = '0'
|
||||
<if test="iotName != null and iotName != ''" >
|
||||
AND iot_name = #{iotName}
|
||||
</if>
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="getInfoList" resultType="com.bonus.material.device.domain.vo.IotVo">
|
||||
SELECT
|
||||
id AS id,
|
||||
type_name AS typeName,
|
||||
ma_code AS maCode
|
||||
FROM
|
||||
iot_machine_bind
|
||||
WHERE
|
||||
unbinder is null and unbind_time is null
|
||||
AND ma_code = #{maCode}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue