提交
This commit is contained in:
parent
e01affeaae
commit
c513c23b21
|
@ -116,6 +116,11 @@ public class IotConstants {
|
|||
*/
|
||||
public static final String COMMAND_REBOOT = "reboot";
|
||||
|
||||
/**
|
||||
* 命令 设置电量系数
|
||||
*/
|
||||
public static final String COMMAND_SET_WXS = "w_xs";
|
||||
|
||||
/**----------------------------命令end----------------------------*/
|
||||
|
||||
|
||||
|
|
|
@ -34,8 +34,10 @@ public class ReceiveConstants {
|
|||
public static final String DS_VXS = "VXS";
|
||||
// 数据点ID:IMSI 物联网卡号IMSI
|
||||
public static final String DS_IMSI = "IMSI";
|
||||
// 数据点ID:WXS 电量系数
|
||||
public static final String DS_WXS = "WXS";
|
||||
|
||||
|
||||
|
||||
// 数据点ID:SSID的值:创特
|
||||
public static final String DSV_SSID_CT = "ChuangteA";
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class IotDeviceInfo {
|
|||
private String version; // 版本号
|
||||
private BigDecimal vxs; // 电压系数
|
||||
private String imsi; // 物联网卡号IMSI
|
||||
private BigDecimal wxs; // 电量系数
|
||||
|
||||
public static IotDeviceInfo newDefaultInstance() {
|
||||
IotDeviceInfo info = new IotDeviceInfo();
|
||||
|
@ -47,6 +48,7 @@ public class IotDeviceInfo {
|
|||
info.setVersion(null);
|
||||
info.setVxs(BigDecimal.ONE);
|
||||
info.setImsi(null);
|
||||
info.setWxs(null);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package com.ruoyi.iot.service;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.iot.domain.HistoryDeviceData;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
import com.ruoyi.iot.interfaces.IotDevice;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2024/3/20
|
||||
|
@ -150,4 +150,9 @@ public interface IotService {
|
|||
* 重启设备
|
||||
*/
|
||||
CommandResponse reboot(IotDevice device, String reason);
|
||||
|
||||
/**
|
||||
* 设置电量系数
|
||||
*/
|
||||
CommandResponse setWxs(IotDevice device, BigDecimal wxs, String reason);
|
||||
}
|
||||
|
|
|
@ -102,11 +102,14 @@ public class IotConverterImpl implements IotConverter {
|
|||
device.setVersion(value);
|
||||
break;
|
||||
case ReceiveConstants.DS_VXS:
|
||||
device.setVxs(NumberUtils.nonNullDecimal(value, BigDecimal.ZERO));
|
||||
device.setVxs(NumberUtils.nonNullDecimal(value, null));
|
||||
break;
|
||||
case ReceiveConstants.DS_IMSI:
|
||||
device.setImsi(value);
|
||||
break;
|
||||
case ReceiveConstants.DS_WXS:
|
||||
device.setWxs(NumberUtils.nonNullDecimal(value, null));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -737,4 +737,26 @@ public class IotServiceImpl implements IotService {
|
|||
return sendCommand(deviceName, command, productId, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResponse setWxs(IotDevice device, BigDecimal wxs, String reason) {
|
||||
if (device == null || wxs == null) {
|
||||
return null;
|
||||
}
|
||||
CommandResponse res = null;
|
||||
if (StringUtils.hasText(device.iotMac2())) {
|
||||
res = setWxs(device.iotMac2(), device.getProductId(), wxs, reason);
|
||||
}
|
||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||
res = setWxs(device.iotMac1(), device.getProductId(), wxs, reason);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private CommandResponse setWxs(String mac, String productId, BigDecimal wxs, String reason) {
|
||||
if (StringUtils.hasBlank(mac, productId)) {
|
||||
return null;
|
||||
}
|
||||
return sendCommand(mac, IotConstants.COMMAND_SET_WXS + wxs + IotConstants.COMMAND_SEPARATOR, productId, reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -278,4 +278,7 @@ public class Device extends BaseEntity
|
|||
@Excel(name = "物联网卡号IMSI")
|
||||
@ApiModelProperty("物联网卡号IMSI")
|
||||
private String imsi;
|
||||
|
||||
@ApiModelProperty("电量系数")
|
||||
private BigDecimal wxs;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.ss.device.domain.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.DecimalMax;
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
* 2025/3/1
|
||||
*/
|
||||
@Data
|
||||
public class DeviceWxsDTO {
|
||||
|
||||
@ApiModelProperty("设备ID")
|
||||
@NotNull(message = "设备ID不允许为空")
|
||||
private Long deviceId;
|
||||
|
||||
@ApiModelProperty("电量系数")
|
||||
@NotNull(message = "电量系数不允许为空")
|
||||
@DecimalMin(value = "0.02", message = "电量系数不允许小于0.02")
|
||||
@DecimalMax(value = "100", message = "电量系数不允许大于100")
|
||||
private BigDecimal wxs;
|
||||
}
|
|
@ -74,6 +74,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sd.user_opera_time,
|
||||
sd.user_opera_ele,
|
||||
sd.imsi,
|
||||
sd.wxs,
|
||||
sm.model_name as model,
|
||||
sm.picture as picture,
|
||||
sm.tags as model_tags,
|
||||
|
@ -416,6 +417,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="userOperaTime != null">user_opera_time,</if>
|
||||
<if test="userOperaEle != null">user_opera_ele,</if>
|
||||
<if test="imsi != null">imsi,</if>
|
||||
<if test="wxs != null">wxs,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="storeId != null">#{storeId},</if>
|
||||
|
@ -475,6 +477,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="userOperaTime != null">#{userOperaTime},</if>
|
||||
<if test="userOperaEle != null">#{userOperaEle},</if>
|
||||
<if test="imsi != null">#{imsi},</if>
|
||||
<if test="wxs != null">#{wxs},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
|
@ -567,6 +570,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="userOperaTime != null">user_opera_time = #{userOperaTime},</if>
|
||||
<if test="userOperaEle != null">user_opera_ele = #{userOperaEle},</if>
|
||||
<if test="imsi != null">imsi = #{imsi},</if>
|
||||
<if test="wxs != null">wxs = #{wxs},</if>
|
||||
</trim>
|
||||
where device_id = #{deviceId}
|
||||
</update>
|
||||
|
|
|
@ -441,4 +441,14 @@ public interface DeviceService
|
|||
* 根据mac修改在线状态
|
||||
*/
|
||||
int updateOnlineStatusByMac(String mac, String status);
|
||||
|
||||
/**
|
||||
* 设置电量系数
|
||||
*/
|
||||
boolean setWxs(Long deviceId, BigDecimal wxs, String reason);
|
||||
|
||||
/**
|
||||
* 设置电量系数
|
||||
*/
|
||||
boolean setWxs(DeviceVO device, BigDecimal wxs, String reason);
|
||||
}
|
||||
|
|
|
@ -940,7 +940,6 @@ public class DeviceServiceImpl implements DeviceService
|
|||
.findFirst().orElse(null);
|
||||
|
||||
// 更新设备信息
|
||||
device.setDeviceId(device.getDeviceId());
|
||||
this.setDeviceInfo(device, deviceInfo);
|
||||
|
||||
// 判断设备是否正在使用
|
||||
|
@ -974,43 +973,44 @@ public class DeviceServiceImpl implements DeviceService
|
|||
}
|
||||
}
|
||||
|
||||
private void setDeviceInfo(DeviceVO device, IotDeviceInfo deviceInfo) {
|
||||
if (device == null || deviceInfo == null) {
|
||||
private void setDeviceInfo(DeviceVO device, IotDeviceInfo iot) {
|
||||
if (device == null || iot == null) {
|
||||
return;
|
||||
}
|
||||
device.setLastPullTime(deviceInfo.getAt());
|
||||
device.setPowerStatus(deviceInfo.getS());
|
||||
device.setRemainTime(deviceInfo.getTime());
|
||||
device.setRealTimePower(deviceInfo.getP());
|
||||
device.setVoltage(deviceInfo.getV());
|
||||
device.setElectricity(deviceInfo.getA());
|
||||
device.setVersion(deviceInfo.getVersion());
|
||||
device.setVxs(deviceInfo.getVxs());
|
||||
device.setImsi(deviceInfo.getImsi());
|
||||
device.setSet(deviceInfo.getSet());
|
||||
device.setLastPullTime(iot.getAt());
|
||||
device.setPowerStatus(iot.getS());
|
||||
device.setRemainTime(iot.getTime());
|
||||
device.setRealTimePower(iot.getP());
|
||||
device.setVoltage(iot.getV());
|
||||
device.setElectricity(iot.getA());
|
||||
device.setVersion(iot.getVersion());
|
||||
device.setVxs(iot.getVxs());
|
||||
device.setImsi(iot.getImsi());
|
||||
device.setSet(iot.getSet());
|
||||
device.setWxs(iot.getWxs());
|
||||
|
||||
// 判断是否支持WIFI,支持则更新
|
||||
if (ModelTag.hasTag(device.getModelTags(), ModelTag.WIFI)) {
|
||||
device.setWifi(deviceInfo.getWifi());
|
||||
device.setWifi(iot.getWifi());
|
||||
}
|
||||
|
||||
// 判断是否支持电量,支持则更新
|
||||
if (ModelTag.hasTag(device.getModelTags(), ModelTag.ELE)) {
|
||||
device.setSurplusEle(deviceInfo.getM());
|
||||
device.setSurplusEle(iot.getM());
|
||||
} else {
|
||||
device.setSurplusEle(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
// 总用电量
|
||||
if (deviceInfo.getW() != null) {
|
||||
if (iot.getW() != null) {
|
||||
// 若有数据点中的值大于数据库中的值,则更新
|
||||
if (deviceInfo.getW().compareTo(device.getTotalElectriQuantity()) >= 0) {
|
||||
device.setTotalElectriQuantity(deviceInfo.getW());
|
||||
if (iot.getW().compareTo(device.getTotalElectriQuantity()) >= 0) {
|
||||
device.setTotalElectriQuantity(iot.getW());
|
||||
}
|
||||
// 若数据点小于数据库中的值,则发命令恢复物联网设备的总用电量
|
||||
else {
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
String reason = "拉取设备信息时,恢复总用电量,数据库值:" + device.getTotalElectriQuantity() + ",OneNet值:" + deviceInfo.getW();
|
||||
String reason = "拉取设备信息时,恢复总用电量,数据库值:" + device.getTotalElectriQuantity() + ",OneNet值:" + iot.getW();
|
||||
iotService.setTotalEle(device, device.getTotalElectriQuantity().multiply(new BigDecimal(1000)), reason);
|
||||
}, 0, TimeUnit.SECONDS);
|
||||
}
|
||||
|
@ -1065,6 +1065,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
data.setVersion(device.getVersion());
|
||||
data.setImsi(device.getImsi());
|
||||
data.setSet(device.getSet());
|
||||
data.setWxs(device.getWxs());
|
||||
return deviceMapper.updateSmDevice(data);
|
||||
}
|
||||
|
||||
|
@ -1630,4 +1631,25 @@ public class DeviceServiceImpl implements DeviceService
|
|||
}
|
||||
return deviceMapper.bindSn(deviceId, sn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setWxs(Long deviceId, BigDecimal wxs, String reason) {
|
||||
if (deviceId == null || wxs == null) {
|
||||
return false;
|
||||
}
|
||||
DeviceVO device = selectById(deviceId);
|
||||
ServiceUtil.assertion(device == null, "ID为" + deviceId + "的设备不存在");
|
||||
return setWxs(device, wxs, reason);
|
||||
}
|
||||
|
||||
public boolean setWxs(DeviceVO device, BigDecimal wxs, String reason) {
|
||||
if (device == null || wxs == null) {
|
||||
return false;
|
||||
}
|
||||
CommandResponse res = iotService.setWxs(device, wxs, reason);
|
||||
if (res == null || !res.isSuccess()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,4 +76,5 @@ public interface TransactionBillValidator {
|
|||
* 是否允许查看订单
|
||||
*/
|
||||
boolean canViewOrder(TransactionBillVO bill, Long userId);
|
||||
|
||||
}
|
||||
|
|
|
@ -425,5 +425,5 @@ public class TransactionBillValidatorImpl extends BaseValidator implements Trans
|
|||
|| this.isUser(bill, userId)
|
||||
|| this.isAgent(bill, userId)
|
||||
|| storeStaffValidator.hasStorePermission(bill.getStoreId(), userId, StoreStaffPermissions.ORDER_OPERA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.ruoyi.web.controller.app;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.ss.billEleRecord.domain.BillEleRecordQuery;
|
||||
import com.ruoyi.ss.billEleRecord.service.BillEleRecordService;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionBillValidator;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/billEleRecord")
|
||||
public class AppBillEleRecordController extends BaseController{
|
||||
|
||||
@Autowired
|
||||
private BillEleRecordService billEleRecordService;
|
||||
|
||||
@Autowired
|
||||
private TransactionBillValidator transactionBillValidator;
|
||||
|
||||
@Autowired
|
||||
private TransactionBillService transactionBillService;
|
||||
|
||||
@ApiOperation("查询订单电量记录")
|
||||
@GetMapping("/listByBill")
|
||||
public AjaxResult listByBill(Long billId) {
|
||||
TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillId(billId);
|
||||
if (!transactionBillValidator.canViewOrder(bill, getUserId())) {
|
||||
return error("您无权查看ID为" + billId + "的订单信息");
|
||||
}
|
||||
BillEleRecordQuery query = new BillEleRecordQuery();
|
||||
query.setBillId(billId);
|
||||
return success(billEleRecordService.selectBillEleRecordList(query));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.ruoyi.web.controller.app;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.ss.storeType.service.StoreTypeService;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/storeType")
|
||||
public class AppStoreTypeController extends BaseController{
|
||||
|
||||
@Autowired
|
||||
private StoreTypeService storeTypeService;
|
||||
|
||||
@ApiOperation("获取全部店铺类型")
|
||||
@GetMapping("/listAll")
|
||||
public AjaxResult listAll() {
|
||||
return success(storeTypeService.selectListAllName());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -59,6 +58,7 @@ import com.ruoyi.ss.user.service.UserService;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 充值记录Controller
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
package com.ruoyi.web.controller.mch;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceWxsDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
||||
import com.ruoyi.ss.device.service.DeviceService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.ss.device.service.DeviceValidator;
|
||||
|
||||
import java.util.List;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* @author wjh
|
||||
|
@ -24,6 +27,9 @@ public class MchDeviceController extends BaseController {
|
|||
@Autowired
|
||||
private DeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private DeviceValidator deviceValidator;
|
||||
|
||||
@ApiOperation("商户通过设备IDS查询")
|
||||
@GetMapping("/listByIds/{ids}")
|
||||
public AjaxResult listByIds(@PathVariable List<Long> ids)
|
||||
|
@ -32,4 +38,14 @@ public class MchDeviceController extends BaseController {
|
|||
return success(list);
|
||||
}
|
||||
|
||||
@ApiOperation("设置电量系数")
|
||||
@PutMapping("/setWxs")
|
||||
public AjaxResult setWxs(@RequestBody @Validated DeviceWxsDTO dto) {
|
||||
DeviceVO device = deviceService.selectById(dto.getDeviceId());
|
||||
if (deviceValidator.canOpera(device, getUserId())) {
|
||||
return error("您无权操作ID为" + dto.getDeviceId() + "的设备");
|
||||
}
|
||||
return toAjax(deviceService.setWxs(device, dto.getWxs(), "商户设置电量系数"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceWxsDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -269,4 +270,10 @@ public class SmDeviceController extends BaseController
|
|||
return toAjax(deviceService.initTotalEle(deviceId));
|
||||
}
|
||||
|
||||
@ApiOperation("设置电量系数")
|
||||
@PutMapping("/setWxs")
|
||||
public AjaxResult setWxs(@RequestBody @Validated DeviceWxsDTO dto) {
|
||||
return toAjax(deviceService.setWxs(dto.getDeviceId(), dto.getWxs(), "管理员设置电量系数"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user