debug + 绑定操作修改
This commit is contained in:
parent
1e22037196
commit
8ebe489761
|
@ -36,6 +36,8 @@ public class CurrentDeviceData {
|
|||
|
||||
for (CurrentDatastream stream : datastreams) {
|
||||
String value = stream.getValue().toString();
|
||||
device.setAt(stream.getAt());
|
||||
|
||||
switch (stream.getId()) {
|
||||
case "V":
|
||||
device.setV(NumberUtils.nonNullDecimal(value));
|
||||
|
@ -62,6 +64,9 @@ public class CurrentDeviceData {
|
|||
case "TIME":
|
||||
device.setTime(NumberUtils.nonNullDecimal(value));
|
||||
break;
|
||||
case "FW":
|
||||
device.setModel(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public class IotDeviceInfo {
|
|||
private BigDecimal m; // 剩余电量(度)
|
||||
private String set; // 欠费断电方式
|
||||
private BigDecimal time; // 剩余时间(秒)
|
||||
private String model;
|
||||
|
||||
public static IotDeviceInfo newDefaultInstance() {
|
||||
return IotDeviceInfo.builder()
|
||||
|
@ -42,6 +43,7 @@ public class IotDeviceInfo {
|
|||
.m(BigDecimal.ZERO)
|
||||
.set(DeviceOutageWay.IMMEDIATE.getValue())
|
||||
.time(BigDecimal.ZERO)
|
||||
.model(null)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.ruoyi.iot.domain.response;
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 命令下发响应
|
||||
* @author wjh
|
||||
|
@ -12,4 +15,9 @@ public class CommandResponse extends BaseResponse {
|
|||
private Object data;
|
||||
private String cmdUuid;
|
||||
private String cmdResp;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return Objects.equals(HttpStatus.IOT_SUCCESS, this.getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public interface IotService {
|
|||
* @param deviceName 设备名称
|
||||
* @param seconds 时长(秒)
|
||||
*/
|
||||
boolean setTime(String deviceName, BigDecimal seconds);
|
||||
CommandResponse setTime(String deviceName, BigDecimal seconds);
|
||||
|
||||
/**
|
||||
* 更新设备信息
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
|
|||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
|
@ -182,17 +183,11 @@ public class IotServiceImpl implements IotService {
|
|||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean setTime(String deviceName, BigDecimal seconds) {
|
||||
public CommandResponse setTime(String deviceName, BigDecimal seconds) {
|
||||
if (seconds == null || BigDecimal.ZERO.compareTo(seconds) > 0) {
|
||||
log.error("设置剩余时长参数错误:读数不允许为空或者小于0");
|
||||
return false;
|
||||
throw new ServiceException("设置剩余时长参数错误:读数不允许为空或者小于0");
|
||||
}
|
||||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR);
|
||||
if (!Objects.equals(HttpStatus.IOT_SUCCESS, response.getCode())) {
|
||||
log.error("设置剩余时长发生异常:" + response.getMsg());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -128,6 +128,7 @@ public class SmDevice extends BaseEntity
|
|||
|
||||
@ApiModelProperty("上次拉取设备信息的时间")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date lastPullTime;
|
||||
|
||||
@ApiModelProperty("总电量初始读数")
|
||||
|
@ -141,6 +142,7 @@ public class SmDevice extends BaseEntity
|
|||
private LocalDateTime expireTime;
|
||||
|
||||
@ApiModelProperty("用户自定义图片")
|
||||
@JsonView(JsonViewProfile.App.class)
|
||||
private String customPicture;
|
||||
|
||||
@ApiModelProperty("服务费费率")
|
||||
|
@ -149,4 +151,7 @@ public class SmDevice extends BaseEntity
|
|||
|
||||
@ApiModelProperty("剩余时长(秒)")
|
||||
private BigDecimal remainTime;
|
||||
|
||||
@ApiModelProperty("所属用户ID")
|
||||
private Long userId;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,6 @@ public class SmDeviceVo extends SmDevice {
|
|||
@ApiModelProperty("是否默认")
|
||||
private Boolean isDefault; // 是否默认
|
||||
|
||||
@ApiModelProperty("所属用户ID")
|
||||
@NotNull(message = "用户不允许为空", groups = {ValidGroup.Create.class})
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("租户id列表")
|
||||
private List<Long> tenantIds; // 租户id列表
|
||||
|
||||
|
@ -37,9 +33,14 @@ public class SmDeviceVo extends SmDevice {
|
|||
@ApiModelProperty("型号")
|
||||
private String model;
|
||||
|
||||
@ApiModelProperty("商户名称")
|
||||
@ApiModelProperty("所属用户名称")
|
||||
@JsonView(DeviceView.SuitList.class)
|
||||
private String userName;
|
||||
|
||||
@ApiModelProperty("用户电话")
|
||||
@JsonView(DeviceView.SuitList.class)
|
||||
private String userMobile;
|
||||
|
||||
@ApiModelProperty("图片")
|
||||
@JsonView(JsonViewProfile.App.class)
|
||||
private String picture;
|
||||
|
@ -66,4 +67,13 @@ public class SmDeviceVo extends SmDevice {
|
|||
|
||||
@ApiModelProperty("订单总金额")
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
@ApiModelProperty("店铺联系人名称")
|
||||
@JsonView(DeviceView.SuitList.class)
|
||||
private String storeContactName;
|
||||
|
||||
@ApiModelProperty("店铺联系人电话")
|
||||
@JsonView(DeviceView.SuitList.class)
|
||||
private String storeContactMobile;
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public interface SmDeviceMapper
|
|||
* @param deviceId 设备id
|
||||
* @param storeId 店铺id
|
||||
*/
|
||||
int bindStore(@Param("deviceId") Long deviceId, @Param("storeId") Long storeId);
|
||||
int bindStore(@Param("deviceId") Long deviceId, @Param("storeId") Long storeId, @Param("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 解绑商户
|
||||
|
|
|
@ -90,16 +90,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sd.custom_picture,
|
||||
sd.service_rate,
|
||||
sd.remain_time,
|
||||
sd.user_id,
|
||||
sm.model_name as model,
|
||||
sm.picture as picture,
|
||||
sm.tags as model_tags,
|
||||
ss.user_id as user_id,
|
||||
ss.name as store_name,
|
||||
ss.contact_name as store_contact_name,
|
||||
ss.contact_mobile as store_contact_mobile,
|
||||
su.phonenumber as user_mobile,
|
||||
su.user_name as user_name
|
||||
from sm_device sd
|
||||
left join sm_model sm on sm.model_id = sd.model_id
|
||||
left join sm_store ss on ss.store_id = sd.store_id
|
||||
left join sm_user su on su.user_id = ss.user_id
|
||||
left join sm_user su on su.user_id = sd.user_id
|
||||
</sql>
|
||||
|
||||
<select id="selectSmDeviceList" parameterType="SmDeviceQuery" resultMap="SmDeviceResult">
|
||||
|
@ -225,6 +228,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="customPicture != null">custom_picture,</if>
|
||||
<if test="serviceRate != null">service_rate,</if>
|
||||
<if test="remainTime != null">remain_time,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="storeId != null">#{storeId},</if>
|
||||
|
@ -254,13 +258,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="customPicture != null">#{customPicture},</if>
|
||||
<if test="serviceRate != null">#{serviceRate},</if>
|
||||
<if test="remainTime != null">#{remainTime},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="addTime">
|
||||
update sm_device
|
||||
set expire_time = IF (
|
||||
expire_time is null or now() > expire_time,
|
||||
(expire_time is null) or (now() > expire_time),
|
||||
DATE_ADD(now(),INTERVAL #{num} MINUTE),
|
||||
DATE_ADD(expire_time,INTERVAL #{num} MINUTE)
|
||||
)
|
||||
|
@ -304,6 +309,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="customPicture != null">custom_picture = #{customPicture},</if>
|
||||
<if test="serviceRate != null">service_rate = #{serviceRate},</if>
|
||||
<if test="remainTime != null">remain_time = #{remainTime},</if>
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
</trim>
|
||||
where device_id = #{deviceId}
|
||||
</update>
|
||||
|
@ -319,13 +325,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<update id="bindStore">
|
||||
update sm_device
|
||||
set store_id = #{storeId}
|
||||
where device_id = #{deviceId} and store_id is null
|
||||
set store_id = #{storeId},
|
||||
user_id = #{userId}
|
||||
where device_id = #{deviceId} and user_id is null
|
||||
</update>
|
||||
|
||||
<update id="unbindStore">
|
||||
update sm_device
|
||||
set store_id = null
|
||||
set store_id = null,
|
||||
user_id = null
|
||||
where device_id = #{deviceId}
|
||||
</update>
|
||||
|
||||
|
|
|
@ -74,10 +74,12 @@ public interface ISmDeviceService
|
|||
|
||||
/**
|
||||
* 增加时间
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
* @param num 电量
|
||||
* @param num 电量
|
||||
* @param withIot
|
||||
*/
|
||||
boolean addTime(Long deviceId, BigDecimal num);
|
||||
boolean addTime(Long deviceId, BigDecimal num, boolean withIot);
|
||||
|
||||
/**
|
||||
* 逻辑删除
|
||||
|
@ -105,15 +107,17 @@ public interface ISmDeviceService
|
|||
|
||||
/**
|
||||
* 通过SN绑定设备
|
||||
* @param storeId 店铺ID
|
||||
*
|
||||
* @param storeId 店铺ID
|
||||
* @param userId
|
||||
* @param deviceNo 设备编号(SN)
|
||||
*/
|
||||
String bindBySn(Long storeId, String deviceNo);
|
||||
String bindBySn(Long storeId, Long userId, String deviceNo);
|
||||
|
||||
/**
|
||||
* 通过MAC绑定设备
|
||||
*/
|
||||
String bindByMac(Long storeId, String mac);
|
||||
String bindByMac(Long storeId, Long userId, String mac);
|
||||
|
||||
/**
|
||||
* 商户解绑设备
|
||||
|
@ -210,4 +214,6 @@ public interface ISmDeviceService
|
|||
* 设备心跳,用于检测是否在线
|
||||
*/
|
||||
void deviceHeartBeat();
|
||||
|
||||
boolean addTimeByUser(Long deviceId, BigDecimal amount, boolean b, String reason);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.ruoyi.ss.device.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.enums.LoginType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.*;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
import com.ruoyi.iot.service.IotService;
|
||||
import com.ruoyi.ss.device.domain.SmDevice;
|
||||
import com.ruoyi.ss.device.domain.SmDeviceCountVO;
|
||||
|
@ -17,14 +19,19 @@ import com.ruoyi.ss.device.mapper.SmDeviceMapper;
|
|||
import com.ruoyi.ss.device.service.DeviceAssembler;
|
||||
import com.ruoyi.ss.device.service.ISmDeviceService;
|
||||
import com.ruoyi.ss.deviceBindRecord.service.ISmDeviceBindRecordService;
|
||||
import com.ruoyi.ss.model.domain.SmModelVo;
|
||||
import com.ruoyi.ss.model.service.ISmModelService;
|
||||
import com.ruoyi.ss.record.time.service.IRecordTimeService;
|
||||
import com.ruoyi.ss.record.time.service.RecordTimeConverter;
|
||||
import com.ruoyi.ss.resetRecord.domain.SmResetRecord;
|
||||
import com.ruoyi.ss.resetRecord.service.ISmResetRecordService;
|
||||
import com.ruoyi.ss.store.domain.StoreVo;
|
||||
import com.ruoyi.ss.store.service.IStoreService;
|
||||
import com.ruoyi.ss.user.domain.SmUserVo;
|
||||
import com.ruoyi.ss.user.service.ISmUserService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -73,8 +80,17 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
@Autowired
|
||||
private IStoreService storeService;
|
||||
|
||||
@Value("${debug}")
|
||||
private Boolean debug;
|
||||
@Autowired
|
||||
private IRecordTimeService recordTimeService;
|
||||
|
||||
@Autowired
|
||||
private RecordTimeConverter recordTimeConverter;
|
||||
|
||||
@Autowired
|
||||
private ISmModelService smModelService;
|
||||
|
||||
@Autowired
|
||||
private ISmUserService userService;
|
||||
|
||||
/**
|
||||
* 查询设备
|
||||
|
@ -216,9 +232,25 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
return smDeviceMapper.selectSmDeviceList(dto);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean addTime(Long deviceId, BigDecimal num) {
|
||||
public boolean addTimeByUser(Long deviceId, BigDecimal amount, boolean withIot, String reason) {
|
||||
boolean b = this.addTime(deviceId, amount, withIot);
|
||||
|
||||
// 记录下操作日志
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
SmDeviceVo device = smDeviceMapper.selectSmDeviceByDeviceId(deviceId);
|
||||
recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, amount, reason, loginUser));
|
||||
}, 0, TimeUnit.SECONDS);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public boolean addTime(Long deviceId, BigDecimal num, boolean withIot) {
|
||||
ServiceUtil.assertion(num.compareTo(BigDecimal.ZERO) < 0, "增加的时长不允许小于0");
|
||||
|
||||
SmDeviceVo device = smDeviceMapper.selectSmDeviceByDeviceId(deviceId);
|
||||
|
@ -234,11 +266,13 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
changeStatus(deviceId, DeviceStatus.USING);
|
||||
|
||||
// 物联网设备增加时长
|
||||
SmDeviceVo newDevice = selectSmDeviceByDeviceId(deviceId);
|
||||
long seconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds();
|
||||
if (seconds > 0) {
|
||||
boolean rechargeResult = iotService.setTime(device.getMac(), new BigDecimal(seconds));
|
||||
ServiceUtil.assertion(!rechargeResult, "设备充值失败,请检查设备是否在线或联系管理员");
|
||||
if (withIot) {
|
||||
SmDeviceVo newDevice = selectSmDeviceByDeviceId(deviceId);
|
||||
long seconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds();
|
||||
if (seconds > 0) {
|
||||
CommandResponse rechargeResult = iotService.setTime(device.getMac(), new BigDecimal(seconds));
|
||||
ServiceUtil.assertion(!rechargeResult.isSuccess(), "设备充值失败,请检查设备是否在线或联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
// 拉取设备信息
|
||||
|
@ -252,6 +286,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void freshStatus(Long deviceId) {
|
||||
SmDeviceVo device = smDeviceMapper.selectSmDeviceByDeviceId(deviceId);
|
||||
freshStatus(device);
|
||||
|
@ -305,6 +340,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
log.info("update count: {}", i);
|
||||
}
|
||||
|
||||
|
||||
private int changeStatus(Long deviceId, DeviceStatus status) {
|
||||
SmDevice device = new SmDevice();
|
||||
device.setDeviceId(deviceId);
|
||||
|
@ -424,36 +460,54 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public String bindBySn(Long storeId, String deviceNo) {
|
||||
public String bindBySn(Long storeId, Long userId, String deviceNo) {
|
||||
SmDeviceVo device = selectByDeviceNo(deviceNo);
|
||||
return this.bind(storeId, device);
|
||||
return this.bindStore(storeId, userId, device);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String bindByMac(Long storeId, String mac) {
|
||||
public String bindByMac(Long storeId, Long userId, String mac) {
|
||||
SmDeviceVo device = selectByMac(mac);
|
||||
return this.bind(storeId, device);
|
||||
return this.bindStore(storeId, userId, device);
|
||||
}
|
||||
|
||||
private String bind(Long storeId, SmDeviceVo device) {
|
||||
// 如果绑定的店铺是原来的店铺,则直接返回MAC
|
||||
if (device.getStoreId() != null && device.getStoreId().equals(storeId)) {
|
||||
return device.getMac();
|
||||
}
|
||||
private String bindStore(Long storeId, Long userId, SmDeviceVo device) {
|
||||
ServiceUtil.assertion(device == null, "设备未录入");
|
||||
ServiceUtil.assertion(device.getStoreId() != null, "该设备已被绑定");
|
||||
// 如果绑定的用户是原来的用户,则直接返回MAC
|
||||
if (device.getUserId() != null) {
|
||||
if (Objects.equals(device.getUserId(), userId)) {
|
||||
return device.getMac();
|
||||
} else {
|
||||
throw new ServiceException("该设备已被绑定");
|
||||
}
|
||||
}
|
||||
// 如果绑定的是原来的店铺,则直接返回MAC
|
||||
if (device.getStoreId() != null) {
|
||||
if (Objects.equals(device.getStoreId(), storeId)) {
|
||||
return device.getMac();
|
||||
} else {
|
||||
throw new ServiceException("该设备已被绑定");
|
||||
}
|
||||
}
|
||||
|
||||
// 查询用户
|
||||
SmUserVo user = userService.selectSimpleById(userId);
|
||||
ServiceUtil.assertion(user == null, "用户不存在");
|
||||
|
||||
// 查询店铺
|
||||
StoreVo store = storeService.selectSmStoreById(storeId);
|
||||
ServiceUtil.assertion(store == null, "店铺不存在");
|
||||
if (storeId != null) {
|
||||
StoreVo store = storeService.selectSmStoreById(storeId);
|
||||
ServiceUtil.assertion(store == null, "店铺不存在");
|
||||
ServiceUtil.assertion(!Objects.equals(store.getUserId(), userId), "该店铺不属于该用户");
|
||||
}
|
||||
|
||||
// 绑定店铺
|
||||
int updateCount = smDeviceMapper.bindStore(device.getDeviceId(), storeId);
|
||||
// 绑定
|
||||
int updateCount = smDeviceMapper.bindStore(device.getDeviceId(), storeId, userId);
|
||||
ServiceUtil.assertion(updateCount != 1, "当前设备信息已变更,请刷新后重试");
|
||||
|
||||
// 记录设备绑定
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
smDeviceBindRecordService.record(store.getUserId(), device.getDeviceId());
|
||||
smDeviceBindRecordService.record(userId, device.getDeviceId());
|
||||
}, 0, TimeUnit.SECONDS);
|
||||
|
||||
return device.getMac();
|
||||
|
@ -487,7 +541,6 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
SmDeviceVo device = smDeviceMapper.selectSmDeviceByDeviceId(deviceId);
|
||||
ServiceUtil.assertion(device == null || device.getDeleted(), "设备不存在");
|
||||
ServiceUtil.assertion(!UserUtil.hasFrontUser(device.getUserId()), "您不是该设备的商户,无法进行该操作");
|
||||
ServiceUtil.assertion(device.getExpireTime() == null || device.getExpireTime().isBefore(now), "设备剩余时间不足,无需归零");
|
||||
|
||||
// 归零时间,将过期时间设置为现在
|
||||
SmDevice form = new SmDevice();
|
||||
|
@ -497,8 +550,8 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
smDeviceMapper.updateSmDevice(form);
|
||||
|
||||
// 物联网设备归零
|
||||
boolean b = iotService.setTime(device.getMac(), BigDecimal.ONE);
|
||||
ServiceUtil.assertion(!b, "操作设备发生异常");
|
||||
CommandResponse commandResponse = iotService.setTime(device.getMac(), BigDecimal.ONE);
|
||||
ServiceUtil.assertion(!commandResponse.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员");
|
||||
|
||||
// 归零记录
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
|
@ -525,7 +578,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
return false;
|
||||
}
|
||||
SmDeviceVo device = smDeviceMapper.selectSimpleSmDeviceByMac(mac);
|
||||
return device != null && device.getStoreId() != null;
|
||||
return device != null && device.getUserId() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,7 +593,7 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
return false;
|
||||
}
|
||||
SmDeviceVo device = smDeviceMapper.selectSimpleSmDeviceBySn(deviceNo);
|
||||
return device != null && device.getStoreId() != null;
|
||||
return device != null && device.getUserId() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -656,14 +709,45 @@ public class SmDeviceServiceImpl implements ISmDeviceService
|
|||
return 0;
|
||||
}
|
||||
try {
|
||||
|
||||
// 查询设备是否存在,存在则忽略
|
||||
SmDeviceVo device = selectByMac(smDevice.getMac());
|
||||
if (device != null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 查询设备的型号
|
||||
IotDeviceInfo deviceInfo = iotService.getDeviceInfo(smDevice.getMac());
|
||||
if (deviceInfo == null) {
|
||||
log.info("iot device info is null");
|
||||
return 0;
|
||||
}
|
||||
log.info("select model in:{}", deviceInfo.getModel());
|
||||
SmModelVo model = smModelService.selectByIotModel(deviceInfo.getModel());
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
SmModelVo finalModel = model;
|
||||
|
||||
// 如果设备型号为空,则添加新的设备型号
|
||||
if (finalModel == null) {
|
||||
log.info("model is null");
|
||||
int addModel = smModelService.addInitModel(deviceInfo);
|
||||
ServiceUtil.assertion(addModel != 1, "添加设备型号失败");
|
||||
finalModel = smModelService.selectByIotModel(deviceInfo.getModel());
|
||||
}
|
||||
|
||||
// 添加设备
|
||||
SmDeviceVo byMac = selectByMac(smDevice.getMac());
|
||||
if (byMac == null) {
|
||||
smDevice.setModelId(finalModel.getModelId());
|
||||
smDevice.setCreateTime(DateUtils.getNowDate());
|
||||
return smDeviceMapper.insertSmDevice(smDevice);
|
||||
int i = smDeviceMapper.insertSmDevice(smDevice); // 添加设备
|
||||
this.pullDeviceInfo(Collections.singletonList(smDevice.getDeviceId())); // 拉取设备信息
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return result == null ? 0 : result;
|
||||
} catch (Exception e) {
|
||||
log.error("add init device error: {}", e.getMessage());
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ruoyi.ss.model.service;
|
||||
|
||||
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.ss.model.domain.SmModelBO;
|
||||
import com.ruoyi.ss.model.domain.SmModelQuery;
|
||||
import com.ruoyi.ss.model.domain.SmModelVo;
|
||||
|
@ -74,4 +75,15 @@ public interface ISmModelService
|
|||
* 逻辑删除
|
||||
*/
|
||||
int logicDelete(List<Long> modelIds);
|
||||
|
||||
/**
|
||||
* 根据物联网的型号查询数据
|
||||
*/
|
||||
SmModelVo selectByIotModel(String model);
|
||||
|
||||
/**
|
||||
* 创建初始型号
|
||||
*/
|
||||
int addInitModel(IotDeviceInfo deviceInfo);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package com.ruoyi.ss.model.service.impl;
|
|||
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.ss.device.domain.vo.SmDeviceVo;
|
||||
import com.ruoyi.ss.device.service.ISmDeviceService;
|
||||
import com.ruoyi.ss.model.domain.SmModel;
|
||||
import com.ruoyi.ss.model.domain.SmModelBO;
|
||||
import com.ruoyi.ss.model.domain.SmModelQuery;
|
||||
import com.ruoyi.ss.model.domain.SmModelVo;
|
||||
|
@ -118,6 +121,31 @@ public class SmModelServiceImpl implements ISmModelService
|
|||
return smModelMapper.logicDeleteByIds(modelIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmModelVo selectByIotModel(String model) {
|
||||
if (!StringUtils.hasText(model)) {
|
||||
return null;
|
||||
}
|
||||
SmModelQuery query = new SmModelQuery();
|
||||
query.setModel(model);
|
||||
List<SmModelVo> list = smModelMapper.selectSmModelList(query);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addInitModel(IotDeviceInfo deviceInfo) {
|
||||
if (deviceInfo == null) {
|
||||
return 0;
|
||||
}
|
||||
SmModel data = new SmModel();
|
||||
data.setModelName("未命名");
|
||||
data.setModel(deviceInfo.getModel());
|
||||
return smModelMapper.insertSmModel(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除前校验
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.ruoyi.ss.record.time.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 设备时长变化记录对象 ss_record_time
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@Data
|
||||
public class RecordTime extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 记录id */
|
||||
private Long id;
|
||||
|
||||
/** 设备id */
|
||||
@Excel(name = "设备id")
|
||||
private Long deviceId;
|
||||
|
||||
/** 时长变化量(分钟) */
|
||||
@Excel(name = "时长变化量", readConverterExp = "分=钟")
|
||||
private BigDecimal amount;
|
||||
|
||||
/** 变化原因 */
|
||||
@Excel(name = "变化原因")
|
||||
private String reason;
|
||||
|
||||
/** 操作人id */
|
||||
@Excel(name = "操作人id")
|
||||
private Long operatorId;
|
||||
|
||||
/** 操作人名称 */
|
||||
@Excel(name = "操作人名称")
|
||||
private String operatorName;
|
||||
|
||||
/** 操作人类型 */
|
||||
@Excel(name = "操作人类型")
|
||||
private String operatorType;
|
||||
|
||||
/** 操作时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime operatorTime;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.ruoyi.ss.record.time.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/6/6
|
||||
*/
|
||||
@Data
|
||||
public class RecordTimeQuery extends RecordTime {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.ruoyi.ss.record.time.domain;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/6/6
|
||||
*/
|
||||
@Data
|
||||
public class RecordTimeVO extends RecordTime {
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.ruoyi.ss.record.time.domain.enums;
|
||||
|
||||
import com.ruoyi.common.enums.LoginType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/6/6
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OperatorType {
|
||||
|
||||
ADMIN("1", LoginType.ADMIN),
|
||||
USER("2", LoginType.FRONT);
|
||||
|
||||
private final String type;
|
||||
private final LoginType loginType;
|
||||
|
||||
public static OperatorType parse(LoginType type) {
|
||||
for (OperatorType operatorType : values()) {
|
||||
if (operatorType.getLoginType().equals(type)) {
|
||||
return operatorType;
|
||||
}
|
||||
}
|
||||
throw new ServiceException("不存在该枚举值");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.ruoyi.ss.record.time.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTime;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeQuery;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeVO;
|
||||
|
||||
/**
|
||||
* 设备时长变化记录Mapper接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
public interface RecordTimeMapper
|
||||
{
|
||||
/**
|
||||
* 查询设备时长变化记录
|
||||
*
|
||||
* @param id 设备时长变化记录主键
|
||||
* @return 设备时长变化记录
|
||||
*/
|
||||
public RecordTimeVO selectRecordTimeById(Long id);
|
||||
|
||||
/**
|
||||
* 查询设备时长变化记录列表
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 设备时长变化记录集合
|
||||
*/
|
||||
public List<RecordTimeVO> selectRecordTimeList(RecordTimeQuery recordTime);
|
||||
|
||||
/**
|
||||
* 新增设备时长变化记录
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRecordTime(RecordTime recordTime);
|
||||
|
||||
/**
|
||||
* 修改设备时长变化记录
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRecordTime(RecordTime recordTime);
|
||||
|
||||
/**
|
||||
* 删除设备时长变化记录
|
||||
*
|
||||
* @param id 设备时长变化记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordTimeById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除设备时长变化记录
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordTimeByIds(Long[] ids);
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?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.record.time.mapper.RecordTimeMapper">
|
||||
|
||||
<resultMap type="RecordTimeVO" id="RecordTimeResult" autoMapping="true"/>
|
||||
|
||||
<sql id="selectRecordTimeVo">
|
||||
select id, device_id, amount, reason, operator_id, operator_name, operator_type, operator_time from ss_record_time
|
||||
</sql>
|
||||
|
||||
<select id="selectRecordTimeList" parameterType="RecordTimeQuery" resultMap="RecordTimeResult">
|
||||
<include refid="selectRecordTimeVo"/>
|
||||
<where>
|
||||
<if test="deviceId != null "> and device_id = #{deviceId}</if>
|
||||
<if test="amount != null "> and amount = #{amount}</if>
|
||||
<if test="reason != null and reason != ''"> and reason = #{reason}</if>
|
||||
<if test="operatorId != null "> and operator_id = #{operatorId}</if>
|
||||
<if test="operatorName != null and operatorName != ''"> and operator_name like concat('%', #{operatorName}, '%')</if>
|
||||
<if test="operatorType != null and operatorType != ''"> and operator_type = #{operatorType}</if>
|
||||
<if test="operatorTime != null "> and operator_time = #{operatorTime}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectRecordTimeById" parameterType="Long" resultMap="RecordTimeResult">
|
||||
<include refid="selectRecordTimeVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertRecordTime" parameterType="RecordTime">
|
||||
insert into ss_record_time
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="deviceId != null">device_id,</if>
|
||||
<if test="amount != null">amount,</if>
|
||||
<if test="reason != null">reason,</if>
|
||||
<if test="operatorId != null">operator_id,</if>
|
||||
<if test="operatorName != null">operator_name,</if>
|
||||
<if test="operatorType != null">operator_type,</if>
|
||||
<if test="operatorTime != null">operator_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="deviceId != null">#{deviceId},</if>
|
||||
<if test="amount != null">#{amount},</if>
|
||||
<if test="reason != null">#{reason},</if>
|
||||
<if test="operatorId != null">#{operatorId},</if>
|
||||
<if test="operatorName != null">#{operatorName},</if>
|
||||
<if test="operatorType != null">#{operatorType},</if>
|
||||
<if test="operatorTime != null">#{operatorTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateRecordTime" parameterType="RecordTime">
|
||||
update ss_record_time
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="deviceId != null">device_id = #{deviceId},</if>
|
||||
<if test="amount != null">amount = #{amount},</if>
|
||||
<if test="reason != null">reason = #{reason},</if>
|
||||
<if test="operatorId != null">operator_id = #{operatorId},</if>
|
||||
<if test="operatorName != null">operator_name = #{operatorName},</if>
|
||||
<if test="operatorType != null">operator_type = #{operatorType},</if>
|
||||
<if test="operatorTime != null">operator_time = #{operatorTime},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRecordTimeById" parameterType="Long">
|
||||
delete from ss_record_time where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRecordTimeByIds" parameterType="String">
|
||||
delete from ss_record_time where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
|
@ -0,0 +1,63 @@
|
|||
package com.ruoyi.ss.record.time.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTime;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeQuery;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeVO;
|
||||
|
||||
/**
|
||||
* 设备时长变化记录Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
public interface IRecordTimeService
|
||||
{
|
||||
/**
|
||||
* 查询设备时长变化记录
|
||||
*
|
||||
* @param id 设备时长变化记录主键
|
||||
* @return 设备时长变化记录
|
||||
*/
|
||||
public RecordTimeVO selectRecordTimeById(Long id);
|
||||
|
||||
/**
|
||||
* 查询设备时长变化记录列表
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 设备时长变化记录集合
|
||||
*/
|
||||
public List<RecordTimeVO> selectRecordTimeList(RecordTimeQuery recordTime);
|
||||
|
||||
/**
|
||||
* 新增设备时长变化记录
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertRecordTime(RecordTime recordTime);
|
||||
|
||||
/**
|
||||
* 修改设备时长变化记录
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateRecordTime(RecordTime recordTime);
|
||||
|
||||
/**
|
||||
* 批量删除设备时长变化记录
|
||||
*
|
||||
* @param ids 需要删除的设备时长变化记录主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordTimeByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除设备时长变化记录信息
|
||||
*
|
||||
* @param id 设备时长变化记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRecordTimeById(Long id);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.ruoyi.ss.record.time.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.ss.device.domain.SmDevice;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTime;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/6/6
|
||||
*/
|
||||
public interface RecordTimeConverter {
|
||||
|
||||
RecordTime toRecordTime(SmDevice device, BigDecimal time, String reason, LoginUser loginUser);
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.ruoyi.ss.record.time.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.enums.LoginType;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.ss.device.domain.SmDevice;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTime;
|
||||
import com.ruoyi.ss.record.time.domain.enums.OperatorType;
|
||||
import com.ruoyi.ss.record.time.service.RecordTimeConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/6/6
|
||||
*/
|
||||
@Service
|
||||
public class RecordTimeConverterImpl implements RecordTimeConverter {
|
||||
@Override
|
||||
public RecordTime toRecordTime(SmDevice device, BigDecimal time, String reason, LoginUser loginUser) {
|
||||
RecordTime record = new RecordTime();
|
||||
record.setDeviceId(device == null ? null : device.getDeviceId());
|
||||
record.setAmount(time);
|
||||
record.setReason(reason);
|
||||
record.setOperatorId(loginUser.getUserId());
|
||||
record.setOperatorName(loginUser.getUsername());
|
||||
record.setOperatorType(toOperatorType(loginUser.getLoginType()));
|
||||
record.setOperatorTime(LocalDateTime.now());
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
private String toOperatorType(LoginType loginType) {
|
||||
return OperatorType.parse(loginType).getType();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.ruoyi.ss.record.time.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeQuery;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.ss.record.time.mapper.RecordTimeMapper;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTime;
|
||||
import com.ruoyi.ss.record.time.service.IRecordTimeService;
|
||||
|
||||
/**
|
||||
* 设备时长变化记录Service业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@Service
|
||||
public class RecordTimeServiceImpl implements IRecordTimeService
|
||||
{
|
||||
@Autowired
|
||||
private RecordTimeMapper recordTimeMapper;
|
||||
|
||||
/**
|
||||
* 查询设备时长变化记录
|
||||
*
|
||||
* @param id 设备时长变化记录主键
|
||||
* @return 设备时长变化记录
|
||||
*/
|
||||
@Override
|
||||
public RecordTimeVO selectRecordTimeById(Long id)
|
||||
{
|
||||
return recordTimeMapper.selectRecordTimeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备时长变化记录列表
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 设备时长变化记录
|
||||
*/
|
||||
@Override
|
||||
public List<RecordTimeVO> selectRecordTimeList(RecordTimeQuery recordTime)
|
||||
{
|
||||
return recordTimeMapper.selectRecordTimeList(recordTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备时长变化记录
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertRecordTime(RecordTime recordTime)
|
||||
{
|
||||
return recordTimeMapper.insertRecordTime(recordTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备时长变化记录
|
||||
*
|
||||
* @param recordTime 设备时长变化记录
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateRecordTime(RecordTime recordTime)
|
||||
{
|
||||
return recordTimeMapper.updateRecordTime(recordTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除设备时长变化记录
|
||||
*
|
||||
* @param ids 需要删除的设备时长变化记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRecordTimeByIds(Long[] ids)
|
||||
{
|
||||
return recordTimeMapper.deleteRecordTimeByIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备时长变化记录信息
|
||||
*
|
||||
* @param id 设备时长变化记录主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteRecordTimeById(Long id)
|
||||
{
|
||||
return recordTimeMapper.deleteRecordTimeById(id);
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ public class TransactionBill extends BaseEntity
|
|||
|
||||
/** 类型 */
|
||||
@ApiModelProperty("类型:1充值,2提现")
|
||||
@JsonView(JsonViewProfile.AppMch.class)
|
||||
@JsonView(JsonViewProfile.App.class)
|
||||
private String type;
|
||||
|
||||
/** 设备 */
|
||||
|
|
|
@ -181,10 +181,10 @@ public interface TransactionBillService
|
|||
|
||||
/**
|
||||
* 手动设备充值
|
||||
*
|
||||
* @param billId
|
||||
* @param validate 是否需要校验
|
||||
*/
|
||||
boolean rechargeDevice(Long billId, boolean validate);
|
||||
boolean rechargeDevice(Long billId);
|
||||
|
||||
/**
|
||||
* 查询设备充值失败列表
|
||||
|
|
|
@ -533,27 +533,26 @@ public class TransactionBillServiceImpl implements TransactionBillService {
|
|||
}
|
||||
|
||||
/**
|
||||
* 手动设备充值
|
||||
* 设备充值
|
||||
*
|
||||
* @param billId
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean rechargeDevice(Long billId, boolean validate) {
|
||||
public boolean rechargeDevice(Long billId) {
|
||||
ServiceUtil.assertion(billId == null, "参数错误,billId不允许为空");
|
||||
|
||||
TransactionBill bill = transactionBillMapper.selectSmTransactionBillByBillId(billId);
|
||||
|
||||
if (validate) {
|
||||
ServiceUtil.assertion(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()), "不存在的充值订单");
|
||||
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "订单未支付");
|
||||
ServiceUtil.assertion(TransactionBillDeviceRechargeStatus.SUCCESS.getStatus().equals(bill.getDeviceRechargeStatus()), "设备已充值成功,不允许再次充值");
|
||||
}
|
||||
ServiceUtil.assertion(bill == null || !TransactionBillType.RECHARGE.getType().equals(bill.getType()), "不存在的充值订单");
|
||||
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "订单未支付");
|
||||
ServiceUtil.assertion(TransactionBillDeviceRechargeStatus.SUCCESS.getStatus().equals(bill.getDeviceRechargeStatus()), "设备已充值成功,不允许再次充值");
|
||||
ServiceUtil.assertion(TransactionBillDeviceRechargeStatus.BLUETOOTH.getStatus().equals(bill.getDeviceRechargeStatus()), "设备已选择蓝牙充值,请使用蓝牙进行充值");
|
||||
|
||||
// 电表时长增加,四舍五入,保留1位小数
|
||||
boolean success = false;
|
||||
try {
|
||||
success = deviceService.addTime(bill.getDeviceId(), bill.getSuitTime());
|
||||
success = deviceService.addTime(bill.getDeviceId(), bill.getSuitTime(), true);
|
||||
} catch (Exception e) {
|
||||
this.handleDeviceRechargeFail(billId);
|
||||
}
|
||||
|
@ -614,13 +613,13 @@ public class TransactionBillServiceImpl implements TransactionBillService {
|
|||
// 商户余额增加
|
||||
userService.addBalance(bill.getMchId(), bill.getArrivalAmount());
|
||||
|
||||
// 设备充值
|
||||
rechargeDevice(bill.getBillId(), false);
|
||||
|
||||
// 记录下充值后的余额
|
||||
SmUserVo user = userService.selectSmUserByUserId(bill.getMchId());
|
||||
updateAfterBalance(bill.getBillId(), user.getBalance());
|
||||
|
||||
// 设备充值
|
||||
rechargeDevice(bill.getBillId());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -806,7 +805,13 @@ public class TransactionBillServiceImpl implements TransactionBillService {
|
|||
ServiceUtil.assertion(!TransactionBillType.RECHARGE.getType().equals(bill.getType()), "该订单不是充值订单", 10002);
|
||||
ServiceUtil.assertion(TransactionBillDeviceRechargeStatus.SUCCESS.getStatus().equals(bill.getDeviceRechargeStatus()), "设备已充值成功,请勿重复充值", 10003);
|
||||
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "订单尚未充值成功", 10004);
|
||||
return transactionBillMapper.bluetoothRechargeSuccess(billNo) == 1;
|
||||
boolean result = transactionBillMapper.bluetoothRechargeSuccess(billNo) == 1;
|
||||
ServiceUtil.assertion(!result, "蓝牙充值回调失败");
|
||||
|
||||
boolean addTime = deviceService.addTime(bill.getDeviceId(), bill.getSuitTime(), false);
|
||||
ServiceUtil.assertion(!addTime, "修改剩余时间失败");
|
||||
|
||||
return result;
|
||||
});
|
||||
|
||||
return execute != null && execute;
|
||||
|
|
|
@ -94,7 +94,6 @@ public class AppDeviceController extends BaseController {
|
|||
return success(device);
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("设备通断电")
|
||||
@PutMapping("/{deviceId}/changePower")
|
||||
public AjaxResult close(@PathVariable @ApiParam("设备id") Long deviceId, String status) {
|
||||
|
@ -102,7 +101,6 @@ public class AppDeviceController extends BaseController {
|
|||
return success(smDeviceService.changePowerStatus(deviceId, powerStatus ));
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("绑定设备")
|
||||
@PutMapping("/bind")
|
||||
public AjaxResult bind(@RequestBody SmDevice device) {
|
||||
|
@ -110,13 +108,12 @@ public class AppDeviceController extends BaseController {
|
|||
return error("设备编号和mac不能同时为空");
|
||||
}
|
||||
if (StringUtils.hasText(device.getDeviceNo())) {
|
||||
return AjaxResult.success("操作成功", smDeviceService.bindBySn(device.getStoreId(), device.getDeviceNo()));
|
||||
return AjaxResult.success("操作成功", smDeviceService.bindBySn(device.getStoreId(), getUserId(), device.getDeviceNo()));
|
||||
} else {
|
||||
return AjaxResult.success("操作成功", smDeviceService.bindByMac(device.getStoreId(), device.getMac()));
|
||||
return AjaxResult.success("操作成功", smDeviceService.bindByMac(device.getStoreId(), getUserId(), device.getMac()));
|
||||
}
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("商户解除设备绑定")
|
||||
@DeleteMapping("/mch/unbind/{deviceId}")
|
||||
public AjaxResult mchUnbind(@PathVariable @ApiParam("设备id") Long deviceId) {
|
||||
|
@ -124,14 +121,12 @@ public class AppDeviceController extends BaseController {
|
|||
return success(smDeviceService.unbindStore(deviceId));
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("设备电量归零")
|
||||
@PutMapping("{deviceId}/reset")
|
||||
public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) {
|
||||
return success(smDeviceService.reset(deviceId));
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("获取设备用电量分析")
|
||||
@GetMapping("/electric/count")
|
||||
public AjaxResult count(@Validated({ValidGroup.Query.class}) SmMeterReadingRecordQuery dto)
|
||||
|
@ -139,7 +134,6 @@ public class AppDeviceController extends BaseController {
|
|||
return success(smMeterReadingRecordService.selectCount(dto));
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("设备充值时长")
|
||||
@PutMapping("/addTime/{deviceId}")
|
||||
public AjaxResult addTime(@PathVariable @ApiParam("设备id") Long deviceId, @ApiParam("电量(度)") BigDecimal amount)
|
||||
|
@ -147,11 +141,10 @@ public class AppDeviceController extends BaseController {
|
|||
ServiceUtil.assertion(!deviceValidator.isBelong(deviceId, getUserId()), "这不是您的设备");
|
||||
SmDeviceVo device = smDeviceService.selectSmDeviceByDeviceId(deviceId);
|
||||
ServiceUtil.assertion(device == null || !getUserId().equals(device.getUserId()), "设备不存在或您无权充值");
|
||||
smDeviceService.addTime(deviceId, amount);
|
||||
smDeviceService.addTimeByUser(deviceId, amount, true, "商户手动充值");
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("刷新设备信息")
|
||||
@GetMapping("/{deviceId}/refreshIot")
|
||||
public AjaxResult syncIot(@PathVariable @ApiParam("设备id") Long deviceId) {
|
||||
|
|
|
@ -40,7 +40,6 @@ public class AppSuitController extends BaseController {
|
|||
private DeviceValidator deviceValidator;
|
||||
|
||||
@ApiOperation("查询设备套餐列表")
|
||||
@MchRequired
|
||||
@JsonView(JsonViewProfile.AppMch.class)
|
||||
@GetMapping("/listByDeviceId/{deviceId}")
|
||||
public AjaxResult list(@PathVariable Long deviceId)
|
||||
|
@ -52,7 +51,6 @@ public class AppSuitController extends BaseController {
|
|||
|
||||
@ApiOperation("获取套餐详细信息")
|
||||
@JsonView(JsonViewProfile.AppMch.class)
|
||||
@MchRequired
|
||||
@GetMapping("/{suitId}")
|
||||
public AjaxResult getInfo(@PathVariable("suitId") Long suitId) {
|
||||
return success(suitService.selectSuitBySuitId(suitId));
|
||||
|
@ -60,7 +58,6 @@ public class AppSuitController extends BaseController {
|
|||
|
||||
@ApiOperation("新增套餐")
|
||||
@PostMapping
|
||||
@MchRequired
|
||||
public AjaxResult add(@RequestBody @Validated({ValidGroup.FrontCreate.class}) SuitBO suit) {
|
||||
suit = suit.filterCreateByApp();
|
||||
ServiceUtil.assertion(suitValidator.preCreateByApp(suit));
|
||||
|
@ -68,7 +65,6 @@ public class AppSuitController extends BaseController {
|
|||
}
|
||||
|
||||
@ApiOperation("修改套餐")
|
||||
@MchRequired
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody @Validated({ValidGroup.FrontUpdate.class}) SuitBO suit)
|
||||
{
|
||||
|
@ -77,7 +73,6 @@ public class AppSuitController extends BaseController {
|
|||
return success(suitService.updateSuit(suit));
|
||||
}
|
||||
|
||||
@MchRequired
|
||||
@ApiOperation("删除套餐")
|
||||
@DeleteMapping("/{suitIds}")
|
||||
public AjaxResult remove(@PathVariable @ApiParam("套餐id列表") Long[] suitIds)
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
package com.ruoyi.web.controller.ss;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeQuery;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTimeVO;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.ss.record.time.domain.RecordTime;
|
||||
import com.ruoyi.ss.record.time.service.IRecordTimeService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 设备时长变化记录Controller
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ss/time")
|
||||
public class RecordTimeController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IRecordTimeService recordTimeService;
|
||||
|
||||
/**
|
||||
* 查询设备时长变化记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ss:time:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(RecordTimeQuery recordTime)
|
||||
{
|
||||
startPage();
|
||||
List<RecordTimeVO> list = recordTimeService.selectRecordTimeList(recordTime);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备时长变化记录列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ss:time:export')")
|
||||
@Log(title = "设备时长变化记录", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, RecordTimeQuery recordTime)
|
||||
{
|
||||
List<RecordTimeVO> list = recordTimeService.selectRecordTimeList(recordTime);
|
||||
ExcelUtil<RecordTimeVO> util = new ExcelUtil<RecordTimeVO>(RecordTimeVO.class);
|
||||
util.exportExcel(response, list, "设备时长变化记录数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备时长变化记录详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ss:time:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
return success(recordTimeService.selectRecordTimeById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增设备时长变化记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ss:time:add')")
|
||||
@Log(title = "设备时长变化记录", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody RecordTime recordTime)
|
||||
{
|
||||
return toAjax(recordTimeService.insertRecordTime(recordTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改设备时长变化记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ss:time:edit')")
|
||||
@Log(title = "设备时长变化记录", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody RecordTime recordTime)
|
||||
{
|
||||
return toAjax(recordTimeService.updateRecordTime(recordTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备时长变化记录
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('ss:time:remove')")
|
||||
@Log(title = "设备时长变化记录", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
return toAjax(recordTimeService.deleteRecordTimeByIds(ids));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.web.controller.ss;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -29,7 +30,6 @@ import com.ruoyi.common.annotation.Log;
|
|||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.ss.device.domain.SmDevice;
|
||||
import com.ruoyi.ss.device.service.ISmDeviceService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
@ -163,4 +163,15 @@ public class SmDeviceController extends BaseController
|
|||
return success(smDeviceService.bindSn(deviceId, sn));
|
||||
}
|
||||
|
||||
@ApiOperation("设备充值时长")
|
||||
@PutMapping("/addTime/{deviceId}")
|
||||
public AjaxResult addTime(@PathVariable @ApiParam("设备id") Long deviceId, @ApiParam("电量(度)") BigDecimal amount) {
|
||||
return toAjax(smDeviceService.addTimeByUser(deviceId, amount, true, "管理员手动充值"));
|
||||
}
|
||||
|
||||
@ApiOperation("设备时长归零")
|
||||
@PutMapping("/{deviceId}/reset")
|
||||
public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) {
|
||||
return success(smDeviceService.reset(deviceId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ public class SmTransactionBillController extends BaseController
|
|||
@Log(title = "手动设备充值", businessType = BusinessType.UPDATE)
|
||||
public AjaxResult rechargeDevice(@PathVariable Long billId)
|
||||
{
|
||||
smTransactionBillService.rechargeDevice(billId, true);
|
||||
smTransactionBillService.rechargeDevice(billId);
|
||||
return success();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.ruoyi.common.enums.UserType;
|
|||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.ss.user.domain.SmUserVo;
|
||||
import com.ruoyi.ss.user.service.ISmUserService;
|
||||
import com.ruoyi.web.core.annotation.MchRequired;
|
||||
|
@ -35,15 +36,12 @@ public class MchRequiredAspect {
|
|||
@Autowired
|
||||
private ISmUserService smUserService;
|
||||
|
||||
@Value("${debug}")
|
||||
private Boolean debug;
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
// 判断当前用户是否有权限访问
|
||||
@Before("@annotation(mchRequired)")
|
||||
public void doBefore(JoinPoint point, MchRequired mchRequired) {
|
||||
if (debug) {
|
||||
return;
|
||||
}
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
SmUser user = loginUser.getSmUser();
|
||||
ServiceUtil.assertion(user == null || user.getIsMch() == null, "获取用户信息异常");
|
||||
|
@ -52,6 +50,7 @@ public class MchRequiredAspect {
|
|||
if (!user.getIsMch()) {
|
||||
SmUserVo dbUser = smUserService.selectSmUserByUserId(user.getUserId());
|
||||
if (dbUser.getIsMch()) {
|
||||
tokenService.delLoginUser(loginUser.getToken());
|
||||
throw new ServiceException("用户信息已变更,请重新登录", HttpStatus.UNAUTHORIZED);
|
||||
} else {
|
||||
throw new ServiceException("仅商家可进行该操作,若您已成为商家,请重新登录后重试");
|
||||
|
|
|
@ -20,7 +20,7 @@ wx:
|
|||
# apiV3密钥
|
||||
apiV3Key: 49819e0f0abdb2df3246f7b27f264d75
|
||||
# 通知回调地址
|
||||
notifyUrl: http://124.221.246.124:2288/dev-api/app/pay/notify/wx # 内网穿透
|
||||
notifyUrl: http://124.221.246.124:2290/dev-api/app/pay/notify/wx # 内网穿透
|
||||
# 密钥所在位置
|
||||
privateKeyPath: D:/project/证书/wxpay/apiclient_key.pem
|
||||
# 证书序列号
|
||||
|
|
|
@ -20,7 +20,7 @@ wx:
|
|||
# apiV3密钥
|
||||
apiV3Key: 49819e0f0abdb2df3246f7b27f264d75
|
||||
# 通知回调地址
|
||||
notifyUrl: https://kaiguan.chuantewulian.cn/prod-api/app/pay/notify/wx # 测试环境
|
||||
notifyUrl: https://kg.chuantewulian.cn/prod-api/app/pay/notify/wx # 测试环境
|
||||
# 密钥所在位置
|
||||
privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem
|
||||
# 证书序列号
|
||||
|
|
|
@ -158,7 +158,9 @@ sm:
|
|||
# 物联网平台地址
|
||||
iotHost: https://iot-api.heclouds.com
|
||||
# 产品id 智能电表
|
||||
productId: SnDlte5gPh
|
||||
# productId: SnDlte5gPh
|
||||
# 新的id
|
||||
productId: 6EX6t0UH7g
|
||||
# 版本号 签名算法版本
|
||||
version: 2020-05-29
|
||||
# 用户资源信息 用户id
|
||||
|
|
Loading…
Reference in New Issue
Block a user