绑定记录

This commit is contained in:
邱贞招 2025-01-14 09:31:52 +08:00
parent 2df11d8bf8
commit 371ae579df
22 changed files with 747 additions and 56 deletions

View File

@ -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<DeviceBindRecordVO> 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<DeviceBindRecordVO> list = deviceBindRecordService.selectSmDeviceBindRecordList(deviceBindRecord);
ExcelUtil<DeviceBindRecordVO> util = new ExcelUtil<DeviceBindRecordVO>(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));
}
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -6,36 +6,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="CommandLog" id="EtCommandLogResult">
<result property="id" column="id" />
<result property="url" column="url" />
<result property="command" column="command" />
<result property="type" column="type" />
<result property="mac" column="mac" />
<result property="sn" column="sn" />
<result property="result" column="result" />
<result property="longitude" column="longitude" />
<result property="latitude" column="latitude" />
<result property="callStatus" column="call_status" />
<result property="orderNo" column="order_no" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
</resultMap>
<sql id="selectEtCommandLogVo">
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
</sql>
<select id="selectEtCommandLogList" parameterType="CommandLog" resultMap="EtCommandLogResult">
<include refid="selectEtCommandLogVo"/>
<where>
<if test="url != null and url != ''"> and url like concat('%', #{url}, '%')</if>
<if test="command != null and command != ''"> and command like concat('%', #{command}, '%')</if>
<if test="mac != null and mac != ''"> and mac like concat('%', #{mac}, '%')</if>
<if test="sn != null and sn != ''"> and sn like concat('%', #{sn}, '%')</if>
<if test="type != null and type != ''"> and type like concat('%', #{type}, '%')</if>
<if test="result != null and result != ''"> and result like concat('%', #{result}, '%')</if>
<if test="orderNo != null and orderNo != ''"> and order_no like concat('%', #{orderNo}, '%')</if>
<if test="callStatus != null and callStatus != ''"> and call_status = #{callStatus}</if>
<if test="userId != null"> and user_id = #{userId}</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
</where>
order by create_time desc
</select>
@ -48,31 +44,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertEtCommandLog" parameterType="CommandLog" useGeneratedKeys="true" keyProperty="id">
insert into ss_command_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="url != null">url,</if>
<if test="command != null">command,</if>
<if test="type != null">type,</if>
<if test="mac != null">mac,</if>
<if test="sn != null">sn,</if>
<if test="result != null">result,</if>
<if test="latitude != null">latitude,</if>
<if test="longitude != null">longitude,</if>
<if test="callStatus != null">call_status,</if>
<if test="orderNo != null">order_no,</if>
<if test="createBy != null">create_by,</if>
<if test="userId != null">user_id,</if>
<if test="userName != null">user_name,</if>
create_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="url != null">#{url},</if>
<if test="command != null">#{command},</if>
<if test="type != null">#{type},</if>
<if test="mac != null">#{mac},</if>
<if test="sn != null">#{sn},</if>
<if test="result != null">#{result},</if>
<if test="latitude != null">#{latitude},</if>
<if test="longitude != null">#{longitude},</if>
<if test="callStatus != null">#{callStatus},</if>
<if test="orderNo != null">#{orderNo},</if>
<if test="createBy != null">#{createBy},</if>
<if test="userId != null">#{userId},</if>
<if test="userName != null">#{userName},</if>
sysdate()
</trim>
</insert>
@ -80,16 +70,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateEtCommandLog" parameterType="CommandLog">
update ss_command_log
<trim prefix="SET" suffixOverrides=",">
<if test="url != null">url = #{url},</if>
<if test="command != null">command = #{command},</if>
<if test="type != null">type = #{type},</if>
<if test="mac != null">mac = #{mac},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="result != null">result = #{result},</if>
<if test="latitude != null">latitude = #{latitude},</if>
<if test="longitude != null">longitude = #{longitude},</if>
<if test="callStatus != null">call_status = #{callStatus},</if>
<if test="orderNo != null">order_no = #{orderNo},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="userName != null">user_name = #{userName},</if>
</trim>
where id = #{id}
</update>

View File

@ -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);
}

View File

@ -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<CommandLog> 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);
}
}

View File

@ -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;
}
}

View File

@ -86,6 +86,11 @@ public interface DeviceMapper
*/
int logicDel(@Param("deviceIds") List<Long> 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);
}

View File

@ -303,6 +303,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="selectSnByMac" resultType="java.lang.String">
select sd.sn from ss_device sd where sd.mac = #{mac} and sd.deleted = false
</select>
<insert id="insertSmDevice" parameterType="Device" useGeneratedKeys="true" keyProperty="deviceId">
<selectKey resultType="Long" order="AFTER" keyProperty="deviceId">
select LAST_INSERT_ID()
@ -490,6 +494,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where device_id = #{deviceId}
</update>
<update id="cleanPlacementStatus">
update ss_device
set placement_status = 0,
placement_type = null
where device_id = #{deviceId}
</update>
<update id="logicDel">
update ss_device
set deleted = true

View File

@ -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);
}

View File

@ -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;
});

View File

@ -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;
}

View File

@ -0,0 +1,11 @@
package com.ruoyi.ss.deviceBindRecord.domain;
import lombok.Data;
/**
* @author wjh
* 2024/10/15
*/
@Data
public class DeviceBindRecordQuery extends DeviceBindRecordVO {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<DeviceBindRecordVO> 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);
}

View File

@ -0,0 +1,84 @@
<?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.ruoyi.ss.deviceBindRecord.mapper.DeviceBindRecordMapper">
<resultMap type="DeviceBindRecordVO" id="SmDeviceBindRecordResult" autoMapping="true">
</resultMap>
<sql id="selectSmDeviceBindRecordVo">
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
</sql>
<select id="selectSmDeviceBindRecordList" parameterType="DeviceBindRecordQuery" resultMap="SmDeviceBindRecordResult">
<include refid="selectSmDeviceBindRecordVo"/>
<where>
<if test="deviceId != null "> and sdbr.device_id = #{deviceId}</if>
<if test="userId != null "> and sdbr.user_id = #{userId}</if>
<if test="type != null and type != ''"> and sdbr.type = #{type}</if>
<if test="userType != null and userType != ''"> and sdbr.user_type = #{userType}</if>
<if test="deviceNo != null and deviceNo != ''"> and sd.device_no like concat('%',#{deviceNo},'%')</if>
<if test="userName != null and userName != ''"> and su.user_name like concat('%',#{userName},'%')</if>
</where>
</select>
<select id="selectSmDeviceBindRecordByRecordId" parameterType="Long" resultMap="SmDeviceBindRecordResult">
<include refid="selectSmDeviceBindRecordVo"/>
where record_id = #{recordId}
</select>
<insert id="insertSmDeviceBindRecord" parameterType="DeviceBindRecord">
insert into ss_device_bind_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="recordId != null">record_id,</if>
<if test="deviceId != null">device_id,</if>
<if test="userId != null">user_id,</if>
<if test="createTime != null">create_time,</if>
<if test="type != null and type != ''">type,</if>
<if test="userType != null and userType != ''">user_type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="recordId != null">#{recordId},</if>
<if test="deviceId != null">#{deviceId},</if>
<if test="userId != null">#{userId},</if>
<if test="createTime != null">#{createTime},</if>
<if test="type != null and type != ''">#{type},</if>
<if test="userType != null and userType != ''">#{userType},</if>
</trim>
</insert>
<update id="updateSmDeviceBindRecord" parameterType="DeviceBindRecord">
update ss_device_bind_record
<trim prefix="SET" suffixOverrides=",">
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="userType != null and userType != ''">user_type = #{userType},</if>
</trim>
where record_id = #{recordId}
</update>
<delete id="deleteSmDeviceBindRecordByRecordId" parameterType="Long">
delete from ss_device_bind_record where record_id = #{recordId}
</delete>
<delete id="deleteSmDeviceBindRecordByRecordIds" parameterType="String">
delete from ss_device_bind_record where record_id in
<foreach item="recordId" collection="array" open="(" separator="," close=")">
#{recordId}
</foreach>
</delete>
</mapper>

View File

@ -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<DeviceBindRecordVO> 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);
}

View File

@ -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<DeviceBindRecordVO> 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);
}
}

View File

@ -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) {

View File

@ -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);
}