diff --git a/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceBindRecordController.java b/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceBindRecordController.java new file mode 100644 index 0000000..a965a61 --- /dev/null +++ b/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceBindRecordController.java @@ -0,0 +1,66 @@ +package com.ruoyi.web.controller.system; + +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO; +import com.ruoyi.ss.deviceBindRecord.service.DeviceBindRecordService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +/** + * 设备绑定记录Controller + * + * @author ruoyi + * @date 2024-04-17 + */ +@RestController +@RequestMapping("/system/bindRecord") +public class DeviceBindRecordController extends BaseController +{ + @Autowired + private DeviceBindRecordService deviceBindRecordService; + + /** + * 查询设备绑定记录列表 + */ + @PreAuthorize("@ss.hasPermi('system:bindRecord:list')") + @GetMapping("/list") + public TableDataInfo list(DeviceBindRecordQuery deviceBindRecord) + { + startPage(); + List list = deviceBindRecordService.selectSmDeviceBindRecordList(deviceBindRecord); + return getDataTable(list); + } + + /** + * 导出设备绑定记录列表 + */ + @PreAuthorize("@ss.hasPermi('system:bindRecord:export')") + @Log(title = "设备绑定记录", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, DeviceBindRecordQuery deviceBindRecord) + { + List list = deviceBindRecordService.selectSmDeviceBindRecordList(deviceBindRecord); + ExcelUtil util = new ExcelUtil(DeviceBindRecordVO.class); + util.exportExcel(response, list, "设备绑定记录数据"); + } + + /** + * 获取设备绑定记录详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:bindRecord:query')") + @GetMapping(value = "/{recordId}") + public AjaxResult getInfo(@PathVariable("recordId") Long recordId) + { + return success(deviceBindRecordService.selectSmDeviceBindRecordByRecordId(recordId)); + } +} diff --git a/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceController.java b/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceController.java index b94422b..c9ae54f 100644 --- a/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceController.java +++ b/share-space-admin/src/main/java/com/ruoyi/web/controller/system/DeviceController.java @@ -97,7 +97,6 @@ public class DeviceController extends BaseController @GetMapping(value = "/{deviceId}") public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) { DeviceVO device = deviceService.selectById(deviceId); -// deviceAssembler.assemblePlacementStatus(device); deviceAssembler.assembleEquipment(device); return success(device); } diff --git a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/domain/CommandLog.java b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/domain/CommandLog.java index 38c33c5..6822044 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/domain/CommandLog.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/domain/CommandLog.java @@ -2,6 +2,7 @@ package com.ruoyi.ss.commandLog.domain; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -42,20 +43,17 @@ public class CommandLog extends BaseEntity @Excel(name = "响应") private String result; - /** 经度 */ - @Excel(name = "经度") - private String longitude; - - /** 纬度 */ - @Excel(name = "纬度") - private String latitude; - /** 回调状态 */ @Excel(name = "回调状态") private String callStatus; - /** 订单号 */ - @Excel(name = "订单号") - private String orderNo; + @Excel(name = "操作人") + @ApiModelProperty("操作人") + private Long userId; + + @Excel(name = "操作人名称") + @ApiModelProperty("操作人名称") + private String userName; + } diff --git a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/mapper/CommandLogMapper.xml b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/mapper/CommandLogMapper.xml index 87bd748..a7fdcc1 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/mapper/CommandLogMapper.xml +++ b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/mapper/CommandLogMapper.xml @@ -6,36 +6,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - + + - select id, url, command, type, mac, sn, result, longitude, latitude, call_status, create_by, create_time, - order_no from ss_command_log + select id, command, type, mac, sn, result,call_status, create_time, user_id, user_name from ss_command_log @@ -48,31 +44,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into ss_command_log - url, command, type, mac, sn, result, - latitude, - longitude, call_status, - order_no, - create_by, + user_id, + user_name, create_time - #{url}, #{command}, #{type}, #{mac}, #{sn}, #{result}, - #{latitude}, - #{longitude}, #{callStatus}, - #{orderNo}, - #{createBy}, + #{userId}, + #{userName}, sysdate() @@ -80,16 +70,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update ss_command_log - url = #{url}, command = #{command}, type = #{type}, mac = #{mac}, sn = #{sn}, result = #{result}, - latitude = #{latitude}, - longitude = #{longitude}, call_status = #{callStatus}, - order_no = #{orderNo}, + user_id = #{userId}, + user_name = #{userName}, where id = #{id} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/ICommandLogService.java b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/ICommandLogService.java index b1765e5..183e62b 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/ICommandLogService.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/ICommandLogService.java @@ -1,6 +1,7 @@ package com.ruoyi.ss.commandLog.service; +import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.ss.commandLog.domain.CommandLog; import java.util.List; @@ -60,4 +61,9 @@ public interface ICommandLogService * @return 结果 */ public int deleteEtCommandLogById(Long id); + + /** + * 异步保存日志 + */ + void asynchronousSaveLog(String command,String mac,String result,String type, LoginUser user); } diff --git a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java index a891580..f44a171 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java @@ -1,12 +1,21 @@ package com.ruoyi.ss.commandLog.service.impl; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.ss.commandLog.mapper.CommandLogMapper; import com.ruoyi.ss.commandLog.service.ICommandLogService; import com.ruoyi.ss.commandLog.domain.CommandLog; +import com.ruoyi.ss.device.domain.Device; +import com.ruoyi.ss.device.service.DeviceService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * 命令日志Service业务层处理 @@ -15,10 +24,17 @@ import java.util.List; * @date 2024-07-06 */ @Service +@Slf4j public class CommandLogServiceImpl implements ICommandLogService { @Autowired - private CommandLogMapper eCommandLogMapper; + private CommandLogMapper commandLogMapper; + + @Autowired + private ScheduledExecutorService scheduledExecutorService; + + @Autowired + private DeviceService deviceService; /** * 查询命令日志 @@ -29,7 +45,7 @@ public class CommandLogServiceImpl implements ICommandLogService @Override public CommandLog selectEtCommandLogById(Long id) { - return eCommandLogMapper.selectEtCommandLogById(id); + return commandLogMapper.selectEtCommandLogById(id); } /** @@ -41,7 +57,7 @@ public class CommandLogServiceImpl implements ICommandLogService @Override public List selectEtCommandLogList(CommandLog eCommandLog) { - return eCommandLogMapper.selectEtCommandLogList(eCommandLog); + return commandLogMapper.selectEtCommandLogList(eCommandLog); } /** @@ -53,7 +69,7 @@ public class CommandLogServiceImpl implements ICommandLogService @Override public int insertEtCommandLog(CommandLog eCommandLog) { - return eCommandLogMapper.insertEtCommandLog(eCommandLog); + return commandLogMapper.insertEtCommandLog(eCommandLog); } /** @@ -65,7 +81,7 @@ public class CommandLogServiceImpl implements ICommandLogService @Override public int updateEtCommandLog(CommandLog eCommandLog) { - return eCommandLogMapper.updateEtCommandLog(eCommandLog); + return commandLogMapper.updateEtCommandLog(eCommandLog); } /** @@ -77,7 +93,7 @@ public class CommandLogServiceImpl implements ICommandLogService @Override public int deleteEtCommandLogByIds(Long[] ids) { - return eCommandLogMapper.deleteEtCommandLogByIds(ids); + return commandLogMapper.deleteEtCommandLogByIds(ids); } /** @@ -89,6 +105,32 @@ public class CommandLogServiceImpl implements ICommandLogService @Override public int deleteEtCommandLogById(Long id) { - return eCommandLogMapper.deleteEtCommandLogById(id); + return commandLogMapper.deleteEtCommandLogById(id); + } + + /** + * 异步保存日志 + */ + @Override + public void asynchronousSaveLog(String command, String mac, String result, String type, LoginUser user) { + //异步保存发送命令日志 + scheduledExecutorService.schedule(() -> { + CommandLog etCommandLog = new CommandLog(); + etCommandLog.setCommand(command); + etCommandLog.setType(type); + etCommandLog.setMac(mac); + etCommandLog.setSn(deviceService.selectSnByMac(mac)); + etCommandLog.setResult(result); + etCommandLog.setCreateTime(DateUtils.getNowDate()); + JSONObject paramsObj = JSON.parseObject(result); + String code = paramsObj.getString("code"); + etCommandLog.setCallStatus(code); + etCommandLog.setUserId(user.getUserId()); + etCommandLog.setUserName(user.getUsername()); + int i = commandLogMapper.insertEtCommandLog(etCommandLog); + if(i>0){ + log.info("【发送命令】异步保存发送命令日志"); + } + }, 0, TimeUnit.SECONDS); } } diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/domain/enums/DeviceCommand.java b/share-space-system/src/main/java/com/ruoyi/ss/device/domain/enums/DeviceCommand.java new file mode 100644 index 0000000..cd7c805 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/device/domain/enums/DeviceCommand.java @@ -0,0 +1,55 @@ +package com.ruoyi.ss.device.domain.enums; + +public enum DeviceCommand { + + REBOOT("reboot", "重启设备"), + OPEN("open", "打开"), + CLOSE("close", "关闭"), + RECHARGE("time", "通电时长"), + REVERSE_RECHARGE("ttme", "断电时长"), + UPLOAD_DATA("111", "强制上报数据"); + + private final String command; + private final String desc; + + DeviceCommand(String command, String desc) { + this.command = command; + this.desc = desc; + } + + /** + * 根据命令获取描述 + * @param command 命令 + * @return 描述 + */ + public static String getDescByCommand(String command) { + for (DeviceCommand value : DeviceCommand.values()) { + if (value.getCommand().equals(command)) { + return value.getDesc(); + } + } + return ""; + } + + /** + * 检查命令是否有效 + * @param command 命令 + * @return true-有效,false-无效 + */ + public static boolean isValidCommand(String command) { + for (DeviceCommand value : DeviceCommand.values()) { + if (value.getCommand().equals(command)) { + return true; + } + } + return false; + } + + public String getCommand() { + return command; + } + + public String getDesc() { + return desc; + } +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.java b/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.java index 710363c..5477339 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.java @@ -86,6 +86,11 @@ public interface DeviceMapper */ int logicDel(@Param("deviceIds") List deviceIds); + /** + * 清除投放状态 + */ + int cleanPlacementStatus(Long deviceId); + /** * 查询简单数据,不联表 * @param dto @@ -210,4 +215,8 @@ public interface DeviceMapper */ int bindAgent(@Param("deviceId") Long deviceId,@Param("agentId") Long agentId, @Param("agentServiceRate") BigDecimal agentServiceRate); + /** + * 根据mac查SN + */ + String selectSnByMac(String mac); } diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml b/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml index 6e8cfe0..f128830 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml +++ b/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml @@ -303,6 +303,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + select LAST_INSERT_ID() @@ -490,6 +494,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where device_id = #{deviceId} + + update ss_device + set placement_status = 0, + placement_type = null + where device_id = #{deviceId} + + update ss_device set deleted = true diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java b/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java index 5a232f6..e473092 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java @@ -1,6 +1,7 @@ package com.ruoyi.ss.device.service; +import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.ss.device.domain.Device; import com.ruoyi.ss.device.domain.DeviceCountVO; import com.ruoyi.ss.device.domain.DeviceQuery; @@ -414,4 +415,8 @@ public interface DeviceService */ int roomAllSwitchDevice(Long roomId, Boolean open); + /** + * 根据mac查询设备SN + */ + String selectSnByMac(String mac); } diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java index 16068c1..30416fd 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java @@ -1,7 +1,9 @@ package com.ruoyi.ss.device.service.impl; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.constant.Constants; -import com.ruoyi.common.constant.IotConstants; +import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.redis.RedisLock; import com.ruoyi.common.core.redis.enums.RedisLockKey; import com.ruoyi.common.exception.ServiceException; @@ -9,10 +11,12 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.ss.clean.domain.CleanVO; import com.ruoyi.ss.device.domain.Device; import com.ruoyi.ss.device.domain.DeviceBO; import com.ruoyi.ss.device.domain.DeviceCountVO; import com.ruoyi.ss.device.domain.DeviceQuery; +import com.ruoyi.ss.commandLog.domain.CommandLog; import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO; import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO; import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO; @@ -27,6 +31,9 @@ import com.ruoyi.ss.device.service.DeviceAssembler; import com.ruoyi.ss.device.service.DeviceConverter; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.device.service.DeviceValidator; +import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType; +import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType; +import com.ruoyi.ss.deviceBindRecord.service.DeviceBindRecordService; import com.ruoyi.ss.equipment.domain.Equipment; import com.ruoyi.ss.equipment.domain.EquipmentVO; import com.ruoyi.ss.equipment.service.IEquipmentService; @@ -34,6 +41,7 @@ import com.ruoyi.ss.model.domain.ModelVO; import com.ruoyi.ss.model.domain.enums.ModelTag; import com.ruoyi.ss.model.service.IModelService; import com.ruoyi.ss.order.service.IOrderValidator; +import com.ruoyi.ss.room.domain.Room; import com.ruoyi.ss.room.domain.RoomVO; import com.ruoyi.ss.room.service.IRoomService; import com.ruoyi.ss.store.domain.Store; @@ -66,6 +74,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import static com.ruoyi.common.constant.ServiceConstants.*; +import static com.ruoyi.common.utils.SecurityUtils.getUserId; /** * 设备Service业务层处理 @@ -122,6 +131,9 @@ public class DeviceServiceImpl implements DeviceService @Autowired private IStoreService storeService; + @Autowired + private DeviceBindRecordService deviceBindRecordService; + /** * 查询设备 * @@ -710,7 +722,6 @@ public class DeviceServiceImpl implements DeviceService public int unbindAgent(Long deviceId) { DeviceVO device = selectById(deviceId); ServiceUtil.assertion(device == null, "设备不存在"); - ServiceUtil.assertion(device.getAgentId() == null, "设备没有代理商,无需解绑"); Integer result = transactionTemplate.execute(status -> { // 解绑 @@ -718,7 +729,7 @@ public class DeviceServiceImpl implements DeviceService ServiceUtil.assertion(unbind != 1, "解绑失败,请刷新后重试"); // 新增解绑记录 -// smDeviceBindRecordService.record(device.getAgentId(), deviceId, BindRecordType.UNBIND, BindRecordUserType.AGENT); + deviceBindRecordService.record(device.getUserId(), deviceId, BindRecordType.UNBIND, BindRecordUserType.MCH); return unbind; }); @@ -839,9 +850,20 @@ public class DeviceServiceImpl implements DeviceService device.setPlacementStatus(DEVICE_PLACEMENT_STATUS_PLACED); device.setPlacementType(dto.getType()); device.setDeviceId(dto.getDeviceId()); - int i = deviceMapper.updateSmDevice(device); - ServiceUtil.assertion(i == 0, "更新设备信息失败"); - return i; + + Boolean execute = transactionTemplate.execute(e -> { + + // 更新设备信息 + int i = deviceMapper.updateSmDevice(device); + ServiceUtil.assertion(i == 0, "更新设备信息失败"); + + //新增解绑记录 + int record = deviceBindRecordService.record(getUserId(), device.getDeviceId(), BindRecordType.PLACEMENT, BindRecordUserType.MCH); + ServiceUtil.assertion(record != 1, "添加绑定记录失败"); + return true; + }); + if(Boolean.FALSE.equals(execute))throw new ServiceException("【完成保洁】失败"); + return 1; } private int updateEquipment(Long equipmentId, Long deviceId, RoomVO room) { @@ -866,7 +888,13 @@ public class DeviceServiceImpl implements DeviceService boolean inProgressOrderByIds = orderValidator.getInProgressOrderByIds(roomIds); ServiceUtil.assertion(inProgressOrderByIds, "操作失败,该设备还有正在进行中订单"); - return offlineDevice(deviceId, deviceVO.getPlacementStatus()); + Boolean execute = transactionTemplate.execute(e -> { + int i = offlineDevice(deviceId, deviceVO.getPlacementType()); + ServiceUtil.assertion(i != 1, "设备下架失败,请刷新后重试"); + return true; + }); + if(Boolean.FALSE.equals(execute))throw new ServiceException("【设备下架】失败"); + return 1; } private int offlineDevice(Long deviceId, String placementType) { @@ -879,6 +907,15 @@ public class DeviceServiceImpl implements DeviceService i = equipmentService.offlineDeviceByDeviceId(deviceId); } ServiceUtil.assertion(i != 1, "设备解绑失败,请刷新后重试"); + + // 清除投放状态 + int i1 = deviceMapper.cleanPlacementStatus(deviceId); + ServiceUtil.assertion(i1 != 1, "【下架】清除投放状态失败"); + + //新增解绑记录 + int record = deviceBindRecordService.record(getUserId(), deviceId, BindRecordType.OFFLINE, BindRecordUserType.MCH); + ServiceUtil.assertion(record != 1, "添加绑定记录失败"); + return i; } @@ -895,6 +932,11 @@ public class DeviceServiceImpl implements DeviceService return 1; } + @Override + public String selectSnByMac(String mac) { + return deviceMapper.selectSnByMac(mac); + } + private int updateSurplusEle(Long deviceId, BigDecimal ele) { if (deviceId == null || ele == null) { return 0; @@ -1287,6 +1329,11 @@ public class DeviceServiceImpl implements DeviceService int i = userService.becomeMch(userId); ServiceUtil.assertion(i != 1, "更新商户失败"); } + + // 记录绑定记录 + int record = deviceBindRecordService.record(userId, device.getDeviceId(), BindRecordType.BIND, BindRecordUserType.MCH); + ServiceUtil.assertion(record != 1, "添加绑定记录失败"); + return updateCount; }); @@ -1521,10 +1568,10 @@ public class DeviceServiceImpl implements DeviceService ServiceUtil.assertion(updateCount != 1, "当前设备信息已变更,请刷新后重试"); // 删除设备与设施的关系(投放状态) - offlineDevice(deviceId, device.getPlacementStatus()); + offlineDevice(deviceId, device.getPlacementType()); -// // 新增解绑记录 -// smDeviceBindRecordService.record(device.getUserId(), deviceId, BindRecordType.UNBIND, BindRecordUserType.MCH); + // 新增解绑记录 + deviceBindRecordService.record(device.getUserId(), deviceId, BindRecordType.UNBIND, BindRecordUserType.MCH); return updateCount; }); diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecord.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecord.java new file mode 100644 index 0000000..71efc0f --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecord.java @@ -0,0 +1,38 @@ +package com.ruoyi.ss.deviceBindRecord.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 设备绑定记录对象 sm_device_bind_record + * + * @author ruoyi + * @date 2024-04-17 + */ +@Data +public class DeviceBindRecord extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 记录id */ + private Long recordId; + + /** 设备id */ + @Excel(name = "设备id") + private Long deviceId; + + /** 用户id */ + @Excel(name = "用户id") + private Long userId; + + @Excel(name = "类型:1-绑定,2-解绑") + @ApiModelProperty("类型:1-绑定,2-解绑") + private String type; + + @Excel(name = "用户类型:1-商户,2-代理商") + @ApiModelProperty("用户类型:1-商户,2-代理商") + private String userType; + +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecordQuery.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecordQuery.java new file mode 100644 index 0000000..e9e02f5 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecordQuery.java @@ -0,0 +1,11 @@ +package com.ruoyi.ss.deviceBindRecord.domain; + +import lombok.Data; + +/** + * @author wjh + * 2024/10/15 + */ +@Data +public class DeviceBindRecordQuery extends DeviceBindRecordVO { +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecordVO.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecordVO.java new file mode 100644 index 0000000..d316f3e --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/DeviceBindRecordVO.java @@ -0,0 +1,18 @@ +package com.ruoyi.ss.deviceBindRecord.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author wjh + * 2024/4/17 + */ +@Data +public class DeviceBindRecordVO extends DeviceBindRecord { + + @ApiModelProperty("用户名称") + private String userName; + + @ApiModelProperty("设备编号") + private String deviceNo; +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/enums/BindRecordType.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/enums/BindRecordType.java new file mode 100644 index 0000000..0ebffe0 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/enums/BindRecordType.java @@ -0,0 +1,24 @@ +package com.ruoyi.ss.deviceBindRecord.domain.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 设备绑定记录类型 + * @author wjh + * 2024/10/15 + */ +@Getter +@AllArgsConstructor +public enum BindRecordType { + + BIND("1", "绑定"), + UNBIND("2", "解绑"), + PLACEMENT("3", "投放"), + OFFLINE("4", "下架"); + + + private final String type; + private final String msg; + +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/enums/BindRecordUserType.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/enums/BindRecordUserType.java new file mode 100644 index 0000000..6889be4 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/domain/enums/BindRecordUserType.java @@ -0,0 +1,20 @@ +package com.ruoyi.ss.deviceBindRecord.domain.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author wjh + * 2024/10/15 + */ +@Getter +@AllArgsConstructor +public enum BindRecordUserType { + + MCH("01", "商户"), + SHOPOWNER("02", "店长"); + + private final String userType; + private final String msg; + +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/mapper/DeviceBindRecordMapper.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/mapper/DeviceBindRecordMapper.java new file mode 100644 index 0000000..9a4bc16 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/mapper/DeviceBindRecordMapper.java @@ -0,0 +1,64 @@ +package com.ruoyi.ss.deviceBindRecord.mapper; + +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO; + +import java.util.List; + +/** + * 设备绑定记录Mapper接口 + * + * @author ruoyi + * @date 2024-04-17 + */ +public interface DeviceBindRecordMapper +{ + /** + * 查询设备绑定记录 + * + * @param recordId 设备绑定记录主键 + * @return 设备绑定记录 + */ + public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId); + + /** + * 查询设备绑定记录列表 + * + * @param deviceBindRecord 设备绑定记录 + * @return 设备绑定记录集合 + */ + public List selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord); + + /** + * 新增设备绑定记录 + * + * @param deviceBindRecord 设备绑定记录 + * @return 结果 + */ + public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord); + + /** + * 修改设备绑定记录 + * + * @param deviceBindRecord 设备绑定记录 + * @return 结果 + */ + public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord); + + /** + * 删除设备绑定记录 + * + * @param recordId 设备绑定记录主键 + * @return 结果 + */ + public int deleteSmDeviceBindRecordByRecordId(Long recordId); + + /** + * 批量删除设备绑定记录 + * + * @param recordIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSmDeviceBindRecordByRecordIds(Long[] recordIds); +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/mapper/DeviceBindRecordMapper.xml b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/mapper/DeviceBindRecordMapper.xml new file mode 100644 index 0000000..3f62986 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/mapper/DeviceBindRecordMapper.xml @@ -0,0 +1,84 @@ + + + + + + + + + select + sdbr.record_id, + sdbr.device_id, + sdbr.user_id, + sdbr.create_time, + sdbr.type, + sdbr.user_type, + su.user_name as user_name, + sd.sn as device_no + from ss_device_bind_record sdbr + left join ss_user su on su.user_id = sdbr.user_id + left join ss_device sd on sd.device_id = sdbr.device_id + + + + + + + + insert into ss_device_bind_record + + record_id, + device_id, + user_id, + create_time, + type, + user_type, + + + #{recordId}, + #{deviceId}, + #{userId}, + #{createTime}, + #{type}, + #{userType}, + + + + + update ss_device_bind_record + + device_id = #{deviceId}, + user_id = #{userId}, + create_time = #{createTime}, + type = #{type}, + user_type = #{userType}, + + where record_id = #{recordId} + + + + delete from ss_device_bind_record where record_id = #{recordId} + + + + delete from ss_device_bind_record where record_id in + + #{recordId} + + + diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/service/DeviceBindRecordService.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/service/DeviceBindRecordService.java new file mode 100644 index 0000000..c6e916b --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/service/DeviceBindRecordService.java @@ -0,0 +1,71 @@ +package com.ruoyi.ss.deviceBindRecord.service; + +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO; +import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType; +import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType; + +import java.util.List; + +/** + * 设备绑定记录Service接口 + * + * @author ruoyi + * @date 2024-04-17 + */ +public interface DeviceBindRecordService +{ + /** + * 查询设备绑定记录 + * + * @param recordId 设备绑定记录主键 + * @return 设备绑定记录 + */ + public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId); + + /** + * 查询设备绑定记录列表 + * + * @param deviceBindRecord 设备绑定记录 + * @return 设备绑定记录集合 + */ + public List selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord); + + /** + * 新增设备绑定记录 + * + * @param deviceBindRecord 设备绑定记录 + * @return 结果 + */ + public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord); + + /** + * 修改设备绑定记录 + * + * @param deviceBindRecord 设备绑定记录 + * @return 结果 + */ + public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord); + + /** + * 批量删除设备绑定记录 + * + * @param recordIds 需要删除的设备绑定记录主键集合 + * @return 结果 + */ + public int deleteSmDeviceBindRecordByRecordIds(Long[] recordIds); + + /** + * 删除设备绑定记录信息 + * + * @param recordId 设备绑定记录主键 + * @return 结果 + */ + public int deleteSmDeviceBindRecordByRecordId(Long recordId); + + /** + * 绑定记录 + */ + int record(Long userId, Long deviceId, BindRecordType recordType, BindRecordUserType userType); +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/service/DeviceBindRecordServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/service/DeviceBindRecordServiceImpl.java new file mode 100644 index 0000000..c81ead1 --- /dev/null +++ b/share-space-system/src/main/java/com/ruoyi/ss/deviceBindRecord/service/DeviceBindRecordServiceImpl.java @@ -0,0 +1,109 @@ +package com.ruoyi.ss.deviceBindRecord.service; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery; +import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO; +import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType; +import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType; +import com.ruoyi.ss.deviceBindRecord.mapper.DeviceBindRecordMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 设备绑定记录Service业务层处理 + * + * @author ruoyi + * @date 2024-04-17 + */ +@Service +public class DeviceBindRecordServiceImpl implements DeviceBindRecordService +{ + @Autowired + private DeviceBindRecordMapper deviceBindRecordMapper; + + /** + * 查询设备绑定记录 + * + * @param recordId 设备绑定记录主键 + * @return 设备绑定记录 + */ + @Override + public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId) + { + return deviceBindRecordMapper.selectSmDeviceBindRecordByRecordId(recordId); + } + + /** + * 查询设备绑定记录列表 + * + * @param deviceBindRecord 设备绑定记录 + * @return 设备绑定记录 + */ + @Override + public List selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord) + { + return deviceBindRecordMapper.selectSmDeviceBindRecordList(deviceBindRecord); + } + + /** + * 新增设备绑定记录 + * + * @param deviceBindRecord 设备绑定记录 + * @return 结果 + */ + @Override + public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord) + { + deviceBindRecord.setCreateTime(DateUtils.getNowDate()); + return deviceBindRecordMapper.insertSmDeviceBindRecord(deviceBindRecord); + } + + /** + * 修改设备绑定记录 + * + * @param deviceBindRecord 设备绑定记录 + * @return 结果 + */ + @Override + public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord) + { + return deviceBindRecordMapper.updateSmDeviceBindRecord(deviceBindRecord); + } + + /** + * 批量删除设备绑定记录 + * + * @param recordIds 需要删除的设备绑定记录主键 + * @return 结果 + */ + @Override + public int deleteSmDeviceBindRecordByRecordIds(Long[] recordIds) + { + return deviceBindRecordMapper.deleteSmDeviceBindRecordByRecordIds(recordIds); + } + + /** + * 删除设备绑定记录信息 + * + * @param recordId 设备绑定记录主键 + * @return 结果 + */ + @Override + public int deleteSmDeviceBindRecordByRecordId(Long recordId) + { + return deviceBindRecordMapper.deleteSmDeviceBindRecordByRecordId(recordId); + } + + @Override + public int record(Long userId, Long deviceId, BindRecordType recordType, BindRecordUserType userType) { + DeviceBindRecord record = new DeviceBindRecord(); + record.setUserId(userId); + record.setDeviceId(deviceId); + record.setType(recordType.getType()); + record.setUserType(userType.getUserType()); + return this.insertSmDeviceBindRecord(record); + } +} diff --git a/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java index 40f5273..f3be943 100644 --- a/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java +++ b/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java @@ -9,6 +9,7 @@ import com.ruoyi.common.utils.map.GeoUtils; import com.ruoyi.ss.carousel.service.CarouselService; import com.ruoyi.ss.city.domain.City; import com.ruoyi.ss.city.service.ICityService; +import com.ruoyi.ss.device.domain.Device; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.equipment.domain.Equipment; @@ -310,7 +311,7 @@ public class StoreServiceImpl implements IStoreService deviceVO = smDeviceService.selectById(dto.getDeviceId()); } ServiceUtil.assertion(deviceVO == null, "设备不存在"); - ServiceUtil.assertion(!deviceVO.getUserId().equals(getUserId()), "不是您的设备请勿操作!"); + ServiceUtil.assertion(deviceVO.getUserId() != null && !deviceVO.getUserId().equals(getUserId()), "不是您的设备请勿操作!"); StoreVO storeVO = storeMapper.selectEStoreByStoreId(dto.getStoreId()); ServiceUtil.assertion(storeVO == null, "店铺不存在"); @@ -318,9 +319,25 @@ public class StoreServiceImpl implements IStoreService updateStore.setStoreId(storeVO.getStoreId()); updateStore.setGateId(deviceVO.getDeviceId()); updateStore.setGateSn(deviceVO.getSn()); - int i = storeMapper.updateEStore(updateStore); - ServiceUtil.assertion(i == 0, "绑定大门失败"); - return i; + + Device device = new Device(); + device.setPlacementStatus(DEVICE_PLACEMENT_STATUS_PLACED); + device.setPlacementType(FACILITY_TYPE_GATE); + device.setDeviceId(dto.getDeviceId()); + + Boolean execute = transactionTemplate.execute(e -> { + // 更新店铺 + int i = storeMapper.updateEStore(updateStore); + ServiceUtil.assertion(i == 0, "绑定大门失败"); + + // 更新设备 + int i1 = smDeviceService.updateSmDevice(device); + ServiceUtil.assertion(i1 == 0, "绑定大门更新设备失败"); + return Boolean.TRUE; + }); + if(Boolean.FALSE.equals(execute))throw new ServiceException("微信支付回调失败"); + + return 1; } private int createGate(Long storeId, String storeName) { diff --git a/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java index ed4c5b7..545f80e 100644 --- a/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java +++ b/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java @@ -5,17 +5,21 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.constant.IotConstants; +import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisLock; import com.ruoyi.common.core.redis.enums.RedisLockKey; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.onenet.CreateDeviceVo; import com.ruoyi.common.utils.onenet.Token; +import com.ruoyi.ss.commandLog.service.ICommandLogService; import com.ruoyi.ss.device.domain.Device; +import com.ruoyi.ss.device.domain.enums.DeviceCommand; import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus; import com.ruoyi.ss.device.domain.enums.DevicePowerStatus; import com.ruoyi.ss.device.domain.vo.DeviceVO; @@ -78,6 +82,9 @@ public class IotServiceImpl implements IotService { @Autowired private RedisCache redisCache; + @Autowired + private ICommandLogService commandLogService; + // 查询OneNet设备在线状态 @Override public String getOnlineStatus(String deviceName, String productId) { @@ -560,6 +567,8 @@ public class IotServiceImpl implements IotService { String token = Token.getToken(); String result = HttpUtils.sendPostWithToken(sendUrl, command, token); ServiceUtil.assertion(!StringUtils.hasText(result), "与OneNet通信异常"); + LoginUser loginUser = SecurityUtils.getLoginUser(); + commandLogService.asynchronousSaveLog(command,deviceName,result,DeviceCommand.getDescByCommand(command),loginUser); return JSON.parseObject(result, CommandResponse.class); }