设备归零

This commit is contained in:
墨大叔 2024-10-14 14:20:32 +08:00
parent 4cc8ab112c
commit b994a52f13
4 changed files with 64 additions and 24 deletions

View File

@ -147,17 +147,7 @@ public interface DeviceService
* *
* @param deviceId 设备id * @param deviceId 设备id
*/ */
default int resetWithBill(Long deviceId) { int resetWithBill(Long deviceId);
return resetWithBill(deviceId, true);
}
/**
* 归零电表并关闭订单
*
* @param deviceId 设备id
* @param requiredIot 是否操作设备
*/
int resetWithBill(Long deviceId, boolean requiredIot);
/** /**
* 设备是否已经被绑定 * 设备是否已经被绑定
@ -316,11 +306,12 @@ public interface DeviceService
int resetEle(Long deviceId, boolean required); int resetEle(Long deviceId, boolean required);
/** /**
* 电量归零并关闭订单 * 时长归零并关闭订单
* @param deviceId
* @param requiredIot
* @return
*/ */
default int resetEleWithBill(Long deviceId) { int resetTimeWithBill(Long deviceId, boolean requiredIot);
return resetEleWithBill(deviceId, true);
}
/** /**
* 电量归零并关闭订单 * 电量归零并关闭订单

View File

@ -68,6 +68,8 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static net.sf.jsqlparser.parser.feature.Feature.reset;
/** /**
* 设备Service业务层处理 * 设备Service业务层处理
* *
@ -555,6 +557,38 @@ public class DeviceServiceImpl implements DeviceService
return resetEle(device, required); return resetEle(device, required);
} }
@Override
public int resetTimeWithBill(Long deviceId, boolean requiredIot) {
if (deviceId == null) {
return 0;
}
// 拉取设备信息
pullDeviceInfo(deviceId);
DeviceVO device = selectById(deviceId);
ServiceUtil.assertion(device == null, "设备不存在");
// 尝试关闭该设备未结束的所有订单
TransactionBillQuery query = new TransactionBillQuery();
query.setStatusList(TransactionBillStatus.canClose());
query.setDeviceId(device.getDeviceId());
query.setIsFinished(false); // 未结束的订单都会被关闭
query.setSuitFeeTypes(SuitFeeType.rechargeTimeList());
List<TransactionBillVO> billList = transactionBillService.selectSmTransactionBillList(query);
try {
int closeCount = transactionBillService.batchCloseBillByDevice(billList, false, device);
ServiceUtil.assertion(closeCount != billList.size(), "关闭订单失败:closeCount =" + closeCount);
} catch (Exception e) {
log.error("关闭订单失败:{}" , e.getMessage());
}
// 发送命令
int reset = this.resetTime(device, requiredIot);
ServiceUtil.assertion(reset != 1, "设备时长归零失败");
return 1;
}
@Override @Override
public int resetEleWithBill(Long deviceId, boolean requiredIot) { public int resetEleWithBill(Long deviceId, boolean requiredIot) {
if (deviceId == null) { if (deviceId == null) {
@ -1088,7 +1122,7 @@ public class DeviceServiceImpl implements DeviceService
} }
@Override @Override
public int resetWithBill(Long deviceId, boolean requiredIot) { public int resetWithBill(Long deviceId) {
ServiceUtil.assertion(deviceId == null, "设备id不能为空"); ServiceUtil.assertion(deviceId == null, "设备id不能为空");
// 拉取最新设备信息 // 拉取最新设备信息
@ -1120,10 +1154,20 @@ public class DeviceServiceImpl implements DeviceService
ServiceUtil.assertion(eleUpdate != 1, "修改设备电量失败"); ServiceUtil.assertion(eleUpdate != 1, "修改设备电量失败");
// 发送命令 // 发送命令
int reset = iotService.setTimeAndEle(device, 0L, BigDecimal.ZERO); // int reset = iotService.setTimeAndEle(device, 0L, BigDecimal.ZERO);
ServiceUtil.assertion(reset != 1, "归零失败"); // ServiceUtil.assertion(reset != 1, "归零失败");
CommandResponse res1 = iotService.setTime(device, 0L);
ServiceUtil.assertion(!res1.isSuccess(), "设备时长归零失败:" + res1.getMsg());
try {
Thread.sleep(1000);
} catch (Exception e) {
log.error("设备归零等待时间异常:{}", e.getMessage());
throw new ServiceException(e.getMessage());
}
CommandResponse res2 = iotService.setEle(device, BigDecimal.ZERO);
ServiceUtil.assertion(!res2.isSuccess(), "设备电量归零失败:" + res2.getMsg());
return reset; return 1;
}); });
if (result != null && result == 1) { if (result != null && result == 1) {

View File

@ -9,6 +9,7 @@ import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.OperatorType; import com.ruoyi.common.enums.OperatorType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.ServiceUtil; import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.iot.service.IotService; import com.ruoyi.iot.service.IotService;
@ -37,6 +38,8 @@ import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/** /**
* 设备Controller * 设备Controller
@ -63,6 +66,9 @@ public class AppDeviceController extends BaseController {
@Autowired @Autowired
private IotService iotService; private IotService iotService;
@Autowired
private ScheduledExecutorService scheduledExecutorService;
@Log(title = "商户修改设备信息", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE) @Log(title = "商户修改设备信息", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE)
@ApiOperation("商户修改设备信息") @ApiOperation("商户修改设备信息")
@PutMapping @PutMapping
@ -139,9 +145,8 @@ public class AppDeviceController extends BaseController {
@Log(title = "设备归零", businessType = BusinessType.OTHER, operatorType = OperatorType.MOBILE) @Log(title = "设备归零", businessType = BusinessType.OTHER, operatorType = OperatorType.MOBILE)
@ApiOperation("设备归零") @ApiOperation("设备归零")
@PutMapping("{deviceId}/reset") @PutMapping("{deviceId}/reset")
public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId, public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) {
@RequestParam(required = false, defaultValue = "true") Boolean requiredIot) { return toAjax(smDeviceService.resetWithBill(deviceId));
return success(smDeviceService.resetWithBill(deviceId, requiredIot));
} }
@ApiOperation("获取设备用电量分析") @ApiOperation("获取设备用电量分析")

View File

@ -176,14 +176,14 @@ public class SmDeviceController extends BaseController
@Log(title = "设备时长归零", businessType = BusinessType.OTHER) @Log(title = "设备时长归零", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/reset") @PutMapping("/{deviceId}/reset")
public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) { public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) {
return toAjax(deviceService.resetWithBill(deviceId)); return toAjax(deviceService.resetTimeWithBill(deviceId, true));
} }
@PreAuthorize("@ss.hasPermi('system:device:resetEle')") @PreAuthorize("@ss.hasPermi('system:device:resetEle')")
@Log(title = "设备清空电量", businessType = BusinessType.OTHER) @Log(title = "设备清空电量", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/resetEle") @PutMapping("/{deviceId}/resetEle")
public AjaxResult resetEle(@PathVariable @ApiParam("设备id") Long deviceId) { public AjaxResult resetEle(@PathVariable @ApiParam("设备id") Long deviceId) {
return toAjax(deviceService.resetEleWithBill(deviceId)); return toAjax(deviceService.resetEleWithBill(deviceId, true));
} }
@ApiOperation("设备开关") @ApiOperation("设备开关")