From bbb29ccc2170f7eb57f8747da4166913e580e6d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Sun, 29 Sep 2024 18:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/service/impl/IotServiceImpl.java | 6 +- .../service/SmBusinessRecordServiceImpl.java | 12 +- .../com/ruoyi/ss/dashboard/vo/BriefVo.java | 3 +- .../ruoyi/ss/device/domain/vo/DeviceVO.java | 3 + .../ruoyi/ss/device/mapper/DeviceMapper.xml | 3 +- .../service/impl/DeviceServiceImpl.java | 45 ++++-- .../service/ReceiveBillService.java | 4 +- .../service/impl/ReceiveBillServiceImpl.java | 14 +- .../domain/TransactionBill.java | 16 ++ .../transactionBill/domain/dto/EndUseDTO.java | 3 + .../domain/enums/RechargeCloseStatus.java | 20 +++ .../transactionBill/domain/vo/EndUseVO.java | 38 +++++ .../domain/vo/TransactionBillVO.java | 3 + .../mapper/TransactionBillMapper.xml | 21 ++- .../service/TransactionAssembler.java | 6 + .../service/TransactionBillService.java | 10 +- .../impl/TransactionAssemblerImpl.java | 19 +++ .../impl/TransactionBillServiceImpl.java | 139 ++++++++++++------ .../app/AppTransactionBillController.java | 8 +- .../web/controller/ss/SmDeviceController.java | 4 +- .../ss/SmTransactionBillController.java | 44 ++---- 21 files changed, 298 insertions(+), 123 deletions(-) create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/RechargeCloseStatus.java create mode 100644 smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/EndUseVO.java diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java index 797a9cba..e7c7d477 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/impl/IotServiceImpl.java @@ -158,7 +158,7 @@ public class IotServiceImpl implements IotService { throw new ServiceException("mac1断电失败"); } } catch (Exception e) { - log.info("mac1断电失败,尝试用mac2断电"); + log.info("mac1断电失败:{},尝试用mac2断电", e.getMessage()); result = this.close(device.iotMac2(), device.getProductId()); } @@ -340,8 +340,8 @@ public class IotServiceImpl implements IotService { return null; } - CurrentDeviceData data1 = getCurrentDataPoint(device.getMac1(), device.getProductId()); - CurrentDeviceData data2 = getCurrentDataPoint(device.getMac2(), device.getProductId()); + CurrentDeviceData data1 = getCurrentDataPoint(device.iotMac1(), device.getProductId()); + CurrentDeviceData data2 = getCurrentDataPoint(device.iotMac2(), device.getProductId()); return iotConverter.toIotDeviceInfo(data1, data2); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java index b8db1bb2..b415ef82 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/businessRecord/service/SmBusinessRecordServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.ss.businessRecord.service; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.enums.UserType; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.ss.businessRecord.domain.SmBusinessRecord; import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordQuery; @@ -185,14 +186,19 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService // 商户总数 SmUserQuery userDto = new SmUserQuery(); - userDto.setIsMch(true); + userDto.setType(UserType.MCH.getType()); brief.setUserCount(userService.selectCount(userDto)); - // 租户总数 + // 普通用户总数 SmUserQuery tenantDto = new SmUserQuery(); - tenantDto.setIsMch(false); + userDto.setType(UserType.USER.getType()); brief.setTenantCount(userService.selectCount(tenantDto)); + // 代理商总数 + SmUserQuery agentQuery = new SmUserQuery(); + agentQuery.setType(UserType.AGENT.getType()); + brief.setAgentCount(userService.selectCount(agentQuery)); + // 充值金额总数 TransactionBillQuery rechargeDto = new TransactionBillQuery(); rechargeDto.setStatus(TransactionBillStatus.SUCCESS.getStatus()); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/vo/BriefVo.java b/smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/vo/BriefVo.java index 99e41e79..d5c037c5 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/vo/BriefVo.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/dashboard/vo/BriefVo.java @@ -20,7 +20,8 @@ public class BriefVo { private Integer totalOnlineCount; // 总设备在线数量 private Integer userCount; // 商户用户数量 - private Integer tenantCount; // 租户用户数量 + private Integer tenantCount; // 普通用户数量 + private Integer agentCount; // 代理商数量 private Integer rechargeCount; // 充值订单数量 private Integer todayRechargeCount; // 今日充值订单数量 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java index d1eff81c..5dea50c4 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java @@ -84,6 +84,9 @@ public class DeviceVO extends Device implements IotDevice { @ApiModelProperty("代理名称") private String agentName; + @ApiModelProperty("代理商手机号") + private String agentMobile; + @Override public String iotMac1() { return getMac(); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml index 6a5bf585..8ae4c1b3 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml @@ -157,7 +157,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" su.phonenumber as user_mobile, su.user_name as user_name, su.service_rate as user_service_rate, - sua.user_name as agent_name + sua.user_name as agent_name, + sua.phonenumber as agent_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 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java index 4d150779..018aed23 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java @@ -13,6 +13,7 @@ import com.ruoyi.iot.domain.IotDeviceInfo; import com.ruoyi.iot.domain.response.CommandResponse; import com.ruoyi.iot.enums.IotHttpStatus; import com.ruoyi.iot.service.IotService; +import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.device.domain.Device; import com.ruoyi.ss.device.domain.DeviceBO; import com.ruoyi.ss.device.domain.DeviceCountVO; @@ -46,6 +47,7 @@ import com.ruoyi.ss.timeBill.domain.TimeBillVO; import com.ruoyi.ss.timeBill.service.TimeBillService; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; +import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; import com.ruoyi.ss.transactionBill.service.TransactionBillService; import com.ruoyi.ss.user.domain.SmUserVo; @@ -281,9 +283,18 @@ public class DeviceServiceImpl implements DeviceService for (Long deviceId : deviceIds) { DeviceVO device = deviceMap.get(deviceId); ServiceUtil.assertion(device == null, String.format("设备“%s”不存在,请刷新后重试", deviceId)); - ServiceUtil.assertion(DeviceStatus.USING.getStatus().equals(device.getStatus()), String.format("设备“%s”正在使用中,无法删除", deviceId)); } + // 拉取最新数据 + this.pullDeviceInfo(deviceIds); + + // 查询是否有未完成的订单 + TransactionBillQuery query = new TransactionBillQuery(); + query.setDeviceIds(deviceIds); + query.setIsFinished(false); + query.setType(TransactionBillType.RECHARGE.getType()); + int billCount = transactionBillService.selectSimpleCount(query); + ServiceUtil.assertion(billCount > 0, "设备存在未完成订单,无法删除"); } /** @@ -466,11 +477,13 @@ public class DeviceServiceImpl implements DeviceService // 物联网设备归零 try { CommandResponse res = iotService.setTime(device, 0L); - ServiceUtil.assertion( !res.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员"); + ServiceUtil.assertion(res == null, "设备归零失败,返回值为空"); + ServiceUtil.assertion(!res.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员"); - boolean close = iotService.close(device); - ServiceUtil.assertion( !close, "设备关闭失败,请检查设备是否在线或联系管理员"); +// boolean close = iotService.close(device); +// ServiceUtil.assertion( !close, "设备关闭失败,请检查设备是否在线或联系管理员"); } catch (Exception e) { + log.warn("设备归零失败:{}, {}, {}", device.getDeviceId(), device.getDeviceNo(), e.getMessage()); if (required) { throw e; } @@ -481,12 +494,14 @@ public class DeviceServiceImpl implements DeviceService // 归零记录 LoginUser loginUser = SecurityUtils.getLoginUser(); - scheduledExecutorService.schedule(() -> { - // 设备剩余时长 - Duration duration = Duration.between(now, device.getExpireTime()); - long seconds = duration.getSeconds() > 0 ? duration.getSeconds() : 0; - recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, -seconds, "设备归零", loginUser, RecordTimeType.TIME.getType())); - }, 0, TimeUnit.SECONDS); + if (result != null && result == 1 ) { + scheduledExecutorService.schedule(() -> { + // 设备剩余时长 + Duration duration = Duration.between(now, device.getExpireTime()); + long seconds = duration.getSeconds() > 0 ? duration.getSeconds() : 0; + recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, -seconds, "设备归零", loginUser, RecordTimeType.TIME.getType())); + }, 0, TimeUnit.SECONDS); + } return result == null ? 0 : result; } @@ -521,9 +536,11 @@ public class DeviceServiceImpl implements DeviceService // 归零记录 LoginUser loginUser = SecurityUtils.getLoginUser(); - scheduledExecutorService.schedule(() -> { - recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, device.getSurplusEle().negate().intValue(), "设备归零", loginUser, RecordTimeType.ELE.getType())); - }, 0, TimeUnit.SECONDS); + if (result != null && result == 1 ) { + scheduledExecutorService.schedule(() -> { + recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, device.getSurplusEle().negate().intValue(), "设备归零", loginUser, RecordTimeType.ELE.getType())); + }, 0, TimeUnit.SECONDS); + } return result == null ? 0 : result; } @@ -996,7 +1013,7 @@ public class DeviceServiceImpl implements DeviceService int reset = this.resetTime(device, requiredIot); ServiceUtil.assertion(reset != 1, "归零失败"); - return 1; + return reset; } /** diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java index 11cb882c..67fcb82e 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/ReceiveBillService.java @@ -71,10 +71,8 @@ public interface ReceiveBillService * * @param mch 商户信息 * @param device 设备信息 - * @param orderArrivalAmount 订单到账金额 - * @param amount 月费收取的金额 */ - int genBillByMonthAndPay(SmUserVo mch, DeviceVO device, BigDecimal orderArrivalAmount, BigDecimal amount); + int genBillByMonthAndPay(SmUserVo mch, DeviceVO device); /** * 查询数量 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java index bc080310..5e4cfc7c 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/receiveBill/service/impl/ReceiveBillServiceImpl.java @@ -122,17 +122,21 @@ public class ReceiveBillServiceImpl implements ReceiveBillService } @Override - public int genBillByMonthAndPay(SmUserVo mch, DeviceVO device, BigDecimal orderArrivalAmount, BigDecimal amount) { - LocalDateTime billTime = LocalDateTime.now(); - ServiceUtil.assertion(mch == null || mch.getUserId() == null, "用户不存在"); + public int genBillByMonthAndPay(SmUserVo mch, DeviceVO device) { + ServiceUtil.assertion(mch == null || mch.getUserId() == null, "商户不存在"); ServiceUtil.assertion(device == null || device.getDeviceId() == null, "设备不存在"); + + LocalDateTime billTime = LocalDateTime.now(); // 设备未过期,则不生成账单 if (device.getRentTime() != null && device.getRentTime().isAfter(billTime)) { return 1; } + // 设备月费若为空或者0,则不收取 + if (device.getMonthFee() == null || device.getMonthFee().compareTo(BigDecimal.ZERO) == 0) { + return 1; + } - // 判断商户余额 + 订单金额是否足够账单金额 - ServiceUtil.assertion(mch.getBalance().add(orderArrivalAmount).compareTo(amount) < 0, "设备到期,商家余额不足,请联系商家处理"); + BigDecimal amount = device.getMonthFee(); // 生成账单 ReceiveBill bill = new ReceiveBill(); diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java index 402ae643..b9358453 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/TransactionBill.java @@ -274,6 +274,22 @@ public class TransactionBill extends BaseEntity implements Payable @ApiModelProperty("版本号") private Integer version; + @Excel(name = "设备关闭状态(1-已关闭,2-未关闭)") + @ApiModelProperty("设备关闭状态(1-已关闭,2-未关闭)") + private String closeStatus; + + @Excel(name = "设备关闭状态描述") + @ApiModelProperty("设备关闭状态描述") + private String closeResult; + + @Excel(name = "代理商ID") + @ApiModelProperty("代理商ID") + private Long agentId; + + @Excel(name = "代理商手机号") + @ApiModelProperty("代理商手机号") + private String agentMobile; + /** * 获取价格(分) */ diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/dto/EndUseDTO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/dto/EndUseDTO.java index 355ae320..ff4a9709 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/dto/EndUseDTO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/dto/EndUseDTO.java @@ -18,4 +18,7 @@ public class EndUseDTO { @ApiModelProperty("总用电量") private BigDecimal totalEle; + @ApiModelProperty("是否通过线上关闭设备") + private Boolean withIot; + } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/RechargeCloseStatus.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/RechargeCloseStatus.java new file mode 100644 index 00000000..efd25b04 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/enums/RechargeCloseStatus.java @@ -0,0 +1,20 @@ +package com.ruoyi.ss.transactionBill.domain.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author wjh + * 2024/9/29 + */ +@Getter +@AllArgsConstructor +public enum RechargeCloseStatus { + + SUCCESS("1", "成功关闭"), + FAIL("2", "关闭失败"); + + private final String status; + private final String msg; + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/EndUseVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/EndUseVO.java new file mode 100644 index 00000000..3f2e0ae5 --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/EndUseVO.java @@ -0,0 +1,38 @@ +package com.ruoyi.ss.transactionBill.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 提前结束订单VO + * @author wjh + * 2024/9/29 + */ +@Data +public class EndUseVO { + + @ApiModelProperty("订单关闭结果") + private Integer result; + + @ApiModelProperty("设备是否关闭") + private Boolean deviceResult; + + @ApiModelProperty("设备关闭结果描述") + private String deviceMsg; + + public static EndUseVO toResult(Integer result, boolean deviceResult, String deviceMsg){ + EndUseVO endUseVO = new EndUseVO(); + endUseVO.setResult(result == null ? 0 : result); + endUseVO.setDeviceResult(deviceResult); + endUseVO.setDeviceMsg(deviceMsg); + return endUseVO; + } + + public static EndUseVO fail() { + EndUseVO endUseVO = new EndUseVO(); + endUseVO.setResult(0); + return endUseVO; + } + + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionBillVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionBillVO.java index fbad80ca..57e520aa 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionBillVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/domain/vo/TransactionBillVO.java @@ -60,6 +60,9 @@ public class TransactionBillVO extends TransactionBill implements IotDevice { @ApiModelProperty("分成列表") private List bonusList; + @ApiModelProperty("总用电量(度)/时长(秒)") + private BigDecimal totalUse; + /** * 获取套餐时长(秒) */ diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml index 4331d4bc..5ac6a6ae 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/mapper/TransactionBillMapper.xml @@ -68,6 +68,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" stb.device_product_id, stb.device_service_mode, stb.version, + stb.close_status, + stb.close_result, + stb.agent_id, + stb.agent_mobile, @@ -184,7 +188,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and stb.create_time <= #{query.createTimeEnd} and stb.device_product_id = #{query.deviceProductId} and stb.device_service_mode = #{query.deviceServiceMode} - and version = #{query.version} + and stb.version = #{query.version} + and stb.close_status = #{query.closeStatus} + and stb.agent_id = #{query.agentId} + and stb.agent_mobile like concat('%', #{query.agentMobile}, '%') and @@ -457,6 +464,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" suit_low_power, device_product_id, version, + close_status, + close_result, + agent_id, + agent_mobile, #{billNo}, @@ -513,6 +524,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{suitLowPower}, #{deviceProductId}, #{version}, + #{closeStatus}, + #{closeResult}, + #{agentId}, + #{agentMobile}, @@ -587,6 +602,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" stb.device_recharge_status = #{data.deviceRechargeStatus}, stb.device_service_mode = #{data.deviceServiceMode}, stb.version = #{data.version}, + stb.close_status = #{data.closeStatus}, + stb.close_result = #{data.closeResult}, + stb.agent_id = #{data.agentId}, + stb.agent_mobile = #{data.agentMobile}, diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionAssembler.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionAssembler.java index 9a590946..ef25dbc1 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionAssembler.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionAssembler.java @@ -31,4 +31,10 @@ public interface TransactionAssembler { * @param list */ void assembleBonusList(List list); + + /** + * 拼接总用电量、时长 + * @param list + */ + void assembleTotalUse(List list); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java index 4a16302b..2b16dfa2 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/TransactionBillService.java @@ -8,14 +8,10 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.bo.*; import com.ruoyi.ss.transactionBill.domain.dto.EndUseDTO; import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO; -import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; -import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; +import com.ruoyi.ss.transactionBill.domain.vo.*; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO; import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; -import com.ruoyi.ss.transactionBill.domain.vo.UserRechargeServiceVO; -import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO; -import com.ruoyi.ss.user.domain.SmUserVo; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -284,12 +280,12 @@ public interface TransactionBillService /** * 结束使用订单 */ - int endUse(EndUseBO bo, boolean withDevice); + EndUseVO endUse(EndUseBO bo, boolean withDevice); /** * 结束使用订单 */ - int endUse(EndUseDTO dto, boolean withDevice); + EndUseVO endUse(EndUseDTO dto, boolean withDevice); /** * 查询所有关于金额的总和 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionAssemblerImpl.java index 018a92a0..0e5a835c 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionAssemblerImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionAssemblerImpl.java @@ -122,4 +122,23 @@ public class TransactionAssemblerImpl implements TransactionAssembler { } } + @Override + public void assembleTotalUse(List list) { + if (CollectionUtils.isEmptyElement(list)) { + return; + } + + for (TransactionBillVO bill : list) { + if (bill == null) { + continue; + } + if (SuitFeeType.rechargeTimeList().contains(bill.getSuitFeeType()) && bill.getSuitStartTime() != null && bill.getSuitEndTime() != null) { + Duration between = Duration.between(bill.getSuitStartTime(), bill.getSuitEndTime()); + bill.setTotalUse(new BigDecimal(between.getSeconds())); + } else if (SuitFeeType.rechargeCountList().contains(bill.getSuitFeeType()) && bill.getSuitStartEle() != null && bill.getSuitEndEle() != null) { + bill.setTotalUse(bill.getSuitEndEle().subtract(bill.getSuitStartEle())); + } + } + } + } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java index 01e65ce0..9b5bbeb9 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java @@ -22,7 +22,6 @@ import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO; import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService; import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus; -import com.ruoyi.ss.device.domain.enums.DeviceServiceMode; import com.ruoyi.ss.device.domain.vo.DeviceVO; import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.payBill.domain.PayBillQuery; @@ -32,6 +31,7 @@ import com.ruoyi.ss.payBill.domain.enums.PayBillBstType; import com.ruoyi.ss.payBill.domain.vo.DoPayVO; import com.ruoyi.ss.payBill.service.PayBillConverter; import com.ruoyi.ss.payBill.service.PayBillService; +import com.ruoyi.ss.receiveBill.service.ReceiveBillService; import com.ruoyi.ss.record.time.domain.enums.RecordTimeType; import com.ruoyi.ss.record.time.service.IRecordTimeService; import com.ruoyi.ss.record.time.service.RecordTimeConverter; @@ -45,10 +45,7 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBill; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.bo.*; import com.ruoyi.ss.transactionBill.domain.dto.*; -import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; -import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; -import com.ruoyi.ss.transactionBill.domain.vo.UserRechargeServiceVO; -import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO; +import com.ruoyi.ss.transactionBill.domain.vo.*; import com.ruoyi.ss.transactionBill.domain.enums.*; import com.ruoyi.ss.transactionBill.mapper.TransactionBillMapper; import com.ruoyi.ss.transactionBill.service.*; @@ -159,6 +156,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After @Autowired private TransactionAssembler transactionAssembler; + @Autowired + private ReceiveBillService receiveBillService; + /** * 查询充值记录 * @@ -261,9 +261,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After List bonusList = bonusConverter.toPo(bo); bo.setBonusList(bonusList); - // TODO 收取月费 - transactionTemplate.execute(status -> { + // 收取月费 + int monthFee = receiveBillService.genBillByMonthAndPay(bo.getMch(), bo.getDevice()); + ServiceUtil.assertion(monthFee != 1, "月费收取失败,请联系商户处理"); + // 新增订单 int insert = this.insertSmTransactionBill(order); ServiceUtil.assertion(insert != 1, "下单失败"); @@ -455,6 +457,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After order.setDeviceMac2(device.getMac2()); order.setDeviceProductId(device.getModelProductId()); order.setDeviceServiceMode(device.getServiceMode()); + order.setAgentId(device.getAgentId()); + order.setAgentMobile(device.getAgentMobile()); // 店铺信息 if (store != null) { @@ -992,9 +996,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After } } - public int endTimingUse(EndUseBO bo, boolean closeDevice) { + public EndUseVO endTimingUse(EndUseBO bo, boolean withDevice) { if (bo == null) { - return 0; + return EndUseVO.fail(); } TransactionBillVO order = bo.getOrder(); DeviceVO device = bo.getDevice(); @@ -1027,20 +1031,32 @@ public class TransactionBillServiceImpl implements TransactionBillService, After }); // 尝试关闭设备 - if (result != null && result == 1 && closeDevice) { + if (result != null && result == 1) { try { - if (SuitFeeType.TIMING_COUNT.getType().equals(order.getSuitFeeType())) { - deviceService.resetEle(device, true); - } else if(SuitFeeType.TIMING_TIME.getType().equals(order.getSuitFeeType())){ - deviceService.resetTime(device, true); - } - iotService.close(device); + transactionTemplate.execute(status -> { + // 记录设备关闭状态 + int update = this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.SUCCESS, "成功"); + ServiceUtil.assertion(update != 1, "记录设备关闭状态失败,请刷新后重试"); + + if (withDevice) { + if (SuitFeeType.TIMING_COUNT.getType().equals(order.getSuitFeeType())) { + deviceService.resetEle(device, true); + } else if(SuitFeeType.TIMING_TIME.getType().equals(order.getSuitFeeType())){ + deviceService.resetTime(device, true); + } + iotService.close(device); + } + + return update; + }); } catch (Exception e) { - log.error("尝试关闭设备失败"); + log.error("尝试关闭设备失败: {}", e.getMessage()); + this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.FAIL, e.getMessage()); + return EndUseVO.toResult(result, false, e.getMessage()); } } - return result == null ? 0 : result; + return EndUseVO.toResult(result, true, null); } private BigDecimal calcTotalEle(DeviceVO device, BigDecimal totalEle) { @@ -1071,9 +1087,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After return totalAmount; } - public int endSmartUse(EndUseBO bo, boolean resetDevice) { + public EndUseVO endSmartUse(EndUseBO bo, boolean withDevice) { if (bo == null) { - return 0; + return EndUseVO.fail(); } TransactionBillVO order = bo.getOrder(); DeviceVO device = bo.getDevice(); @@ -1125,17 +1141,36 @@ public class TransactionBillServiceImpl implements TransactionBillService, After } // 清零设备 - if (resetDevice) { - try { + try { + transactionTemplate.execute(status -> { + // 记录设备关闭状态:成功 + int update = this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.SUCCESS, "成功"); + ServiceUtil.assertion(update != 1, "更新设备关闭状态失败"); + // 尝试设备清零时长、电量 - int clear = deviceService.clearTimeAndEle(device, false); - ServiceUtil.assertion(clear != 1, "设备归零失败"); - } catch (Exception e) { - log.warn("设备归零失败"); - } + if (withDevice) { + int clear = deviceService.clearTimeAndEle(device, false); + ServiceUtil.assertion(clear != 1, "设备归零失败"); + } + + return update; + }); + } catch (Exception e) { + log.warn("设备归零失败: {}", e.getMessage()); + // 记录设备关闭状态 + this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.FAIL, e.getMessage()); + return EndUseVO.toResult(result, false, e.getMessage()); } - return result == null ? 0 : result; + return EndUseVO.toResult(result, true, null); + } + + private int updateCloseStatus(Long billId, RechargeCloseStatus status, String msg) { + TransactionBill data = new TransactionBill(); + data.setBillId(billId); + data.setCloseStatus(status.getStatus()); + data.setCloseResult(msg); + return transactionBillMapper.updateSmTransactionBill(data); } @Override @@ -1174,9 +1209,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After return transactionBillMapper.selectSumOfMoney(query); } - public int endUseSingle(EndUseBO bo, boolean resetDevice) { + public EndUseVO endUseSingle(EndUseBO bo, boolean withDevice) { if (bo == null) { - return 0; + return EndUseVO.fail(); } TransactionBillVO order = bo.getOrder(); DeviceVO device = bo.getDevice(); @@ -1211,19 +1246,33 @@ public class TransactionBillServiceImpl implements TransactionBillService, After }); // 尝试清零设备 - if (result != null && result == 1 && resetDevice) { + if (result != null && result == 1) { try { - if (SuitFeeType.COUNT.getType().equals(order.getSuitFeeType())) { - deviceService.resetEle(device, true); - } else if(SuitFeeType.TIME.getType().equals(order.getSuitFeeType())){ - deviceService.resetTime(device, true); - } + transactionTemplate.execute(status -> { + // 记录设备关闭状态:成功 + int update = this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.SUCCESS, "成功"); + ServiceUtil.assertion(update != 1, "更新设备关闭状态失败"); + + // 尝试设备清零时长、电量 + if (withDevice) { + if (SuitFeeType.COUNT.getType().equals(order.getSuitFeeType())) { + deviceService.resetEle(device, true); + } else if(SuitFeeType.TIME.getType().equals(order.getSuitFeeType())){ + deviceService.resetTime(device, true); + } + } + + return update; + }); } catch (Exception e) { - log.error("尝试清零设备失败"); + log.error("尝试清零设备失败: {}", e.getMessage()); + // 记录设备关闭状态 + this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.FAIL, e.getMessage()); + return EndUseVO.toResult(result, false, e.getMessage()); } } - return result == null ? 0 : result; + return EndUseVO.toResult(result, true, null); } private BigDecimal calcRefundAmount(TransactionBillVO order, LocalDateTime endTime, BigDecimal totalEle) { @@ -1770,9 +1819,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After // 关闭订单,智能订单需要退款 for (TransactionBillVO bill : billList) { bo.setOrder(bill); - int end = this.endUse(bo, withDevice); - ServiceUtil.assertion(end != 1, "关闭订单失败:" + bill.getBillNo()); - sum += end; + EndUseVO end = this.endUse(bo, withDevice); + ServiceUtil.assertion(end.getResult() != 1, "关闭订单失败:" + bill.getBillNo()); + sum += end.getResult(); } return sum; @@ -1786,9 +1835,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After // 结束使用订单 @Override - public int endUse(EndUseBO bo, boolean withDevice) { + public EndUseVO endUse(EndUseBO bo, boolean withDevice) { if (bo == null) { - return 0; + return EndUseVO.fail(); } TransactionBillVO bill = bo.getOrder(); @@ -1808,11 +1857,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After return this.endUseSingle(bo, withDevice); } - return 0; + return EndUseVO.fail(); } @Override - public int endUse(EndUseDTO dto, boolean withDevice) { + public EndUseVO endUse(EndUseDTO dto, boolean withDevice) { EndUseBO bo = transactionBillConverter.toEndUseBO(dto); return this.endUse(bo, withDevice); } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java index 94fd39a8..437c1c82 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppTransactionBillController.java @@ -144,7 +144,7 @@ public class AppTransactionBillController extends BaseController @JsonView(JsonViewProfile.AppUser.class) public AjaxResult detail(@PathVariable String billNo) { TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillNo(billNo); - if (!transactionBillValidator.isUser(bill, getUserId())) { + if (!transactionBillValidator.isUser(bill, getUserId()) && !transactionBillValidator.isMch(bill, getUserId())) { return success(); } transactionAssembler.assembleChannelName(Collections.singletonList(bill)); @@ -293,7 +293,7 @@ public class AppTransactionBillController extends BaseController if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) { return error("您不是该订单的用户或商户,无法结束订单"); } - return toAjax(transactionBillService.endUse(bo, true )); + return success(transactionBillService.endUse(bo, true )); } @ApiOperation("提前结束使用智能订单") @@ -303,7 +303,7 @@ public class AppTransactionBillController extends BaseController if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) { return error("您不是该订单的用户或商户,无法结束订单"); } - return toAjax(transactionBillService.endUse(bo, true )); + return success(transactionBillService.endUse(bo, true )); } @@ -314,7 +314,7 @@ public class AppTransactionBillController extends BaseController if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) { return error("您不是该订单的用户或商户,无法结束订单"); } - return toAjax(transactionBillService.endUse(bo, true )); + return success(transactionBillService.endUse(bo, true )); } @ApiOperation("获取订单预估金额") diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java index 96aaae75..eaa8bd9c 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java @@ -127,9 +127,9 @@ public class SmDeviceController extends BaseController @PreAuthorize("@ss.hasPermi('system:device:remove')") @Log(title = "设备", businessType = BusinessType.LOGIC_DELETE) @DeleteMapping("/logic/{deviceIds}") - public AjaxResult logicDel(@PathVariable Long[] deviceIds) + public AjaxResult logicDel(@PathVariable List deviceIds) { - return toAjax(deviceService.logicDel(Arrays.asList(deviceIds))); + return toAjax(deviceService.logicDel(deviceIds)); } @ApiOperation("刷新设备信息") diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmTransactionBillController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmTransactionBillController.java index e699c99b..cdd8e70f 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmTransactionBillController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmTransactionBillController.java @@ -1,5 +1,6 @@ package com.ruoyi.web.controller.ss; +import java.util.Collections; import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -9,6 +10,7 @@ import com.ruoyi.ss.transactionBill.domain.dto.EndUseDTO; import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO; +import com.ruoyi.ss.transactionBill.service.TransactionAssembler; import com.ruoyi.ss.transactionBill.service.TransactionBillConverter; import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiOperation; @@ -48,6 +50,9 @@ public class SmTransactionBillController extends BaseController @Autowired private TransactionBillConverter transactionBillConverter; + @Autowired + private TransactionAssembler transactionAssembler; + /** * 查询充值记录列表 */ @@ -57,6 +62,7 @@ public class SmTransactionBillController extends BaseController { startPage(); List list = transactionBillService.selectSmTransactionBillList(smTransactionBill); + transactionAssembler.assembleTotalUse(list); return getDataTable(list); } @@ -80,40 +86,10 @@ public class SmTransactionBillController extends BaseController @GetMapping(value = "/{billId}") public AjaxResult getInfo(@PathVariable("billId") Long billId) { - return success(transactionBillService.selectSmTransactionBillByBillId(billId)); - } - - /** - * 新增充值记录 - */ - @PreAuthorize("@ss.hasPermi('system:bill:add')") - @Log(title = "充值记录", businessType = BusinessType.INSERT) - @PostMapping - public AjaxResult add(@RequestBody TransactionBill transactionBill) - { - return toAjax(transactionBillService.insertSmTransactionBill(transactionBill)); - } - - /** - * 修改充值记录 - */ - @PreAuthorize("@ss.hasPermi('system:bill:edit')") - @Log(title = "充值记录", businessType = BusinessType.UPDATE) - @PutMapping - public AjaxResult edit(@RequestBody TransactionBill transactionBill) - { - return toAjax(transactionBillService.updateSmTransactionBill(transactionBill)); - } - - /** - * 删除充值记录 - */ - @PreAuthorize("@ss.hasPermi('system:bill:remove')") - @Log(title = "充值记录", businessType = BusinessType.DELETE) - @DeleteMapping("/{billIds}") - public AjaxResult remove(@PathVariable Long[] billIds) - { - return toAjax(transactionBillService.deleteSmTransactionBillByBillIds(billIds)); + TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillId(billId); + List list = Collections.singletonList(bill); + transactionAssembler.assembleTotalUse(list); + return success(bill); } @PreAuthorize("@ss.hasPermi('system:bill:query')")