This commit is contained in:
墨大叔 2024-09-29 18:15:57 +08:00
parent 3960f10abf
commit bbb29ccc21
21 changed files with 298 additions and 123 deletions

View File

@ -158,7 +158,7 @@ public class IotServiceImpl implements IotService {
throw new ServiceException("mac1断电失败"); throw new ServiceException("mac1断电失败");
} }
} catch (Exception e) { } catch (Exception e) {
log.info("mac1断电失败尝试用mac2断电"); log.info("mac1断电失败:{}尝试用mac2断电", e.getMessage());
result = this.close(device.iotMac2(), device.getProductId()); result = this.close(device.iotMac2(), device.getProductId());
} }
@ -340,8 +340,8 @@ public class IotServiceImpl implements IotService {
return null; return null;
} }
CurrentDeviceData data1 = getCurrentDataPoint(device.getMac1(), device.getProductId()); CurrentDeviceData data1 = getCurrentDataPoint(device.iotMac1(), device.getProductId());
CurrentDeviceData data2 = getCurrentDataPoint(device.getMac2(), device.getProductId()); CurrentDeviceData data2 = getCurrentDataPoint(device.iotMac2(), device.getProductId());
return iotConverter.toIotDeviceInfo(data1, data2); return iotConverter.toIotDeviceInfo(data1, data2);
} }

View File

@ -2,6 +2,7 @@ package com.ruoyi.ss.businessRecord.service;
import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.UserType;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecord; import com.ruoyi.ss.businessRecord.domain.SmBusinessRecord;
import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordQuery; import com.ruoyi.ss.businessRecord.domain.SmBusinessRecordQuery;
@ -185,14 +186,19 @@ public class SmBusinessRecordServiceImpl implements ISmBusinessRecordService
// 商户总数 // 商户总数
SmUserQuery userDto = new SmUserQuery(); SmUserQuery userDto = new SmUserQuery();
userDto.setIsMch(true); userDto.setType(UserType.MCH.getType());
brief.setUserCount(userService.selectCount(userDto)); brief.setUserCount(userService.selectCount(userDto));
// 户总数 // 普通用户总数
SmUserQuery tenantDto = new SmUserQuery(); SmUserQuery tenantDto = new SmUserQuery();
tenantDto.setIsMch(false); userDto.setType(UserType.USER.getType());
brief.setTenantCount(userService.selectCount(tenantDto)); brief.setTenantCount(userService.selectCount(tenantDto));
// 代理商总数
SmUserQuery agentQuery = new SmUserQuery();
agentQuery.setType(UserType.AGENT.getType());
brief.setAgentCount(userService.selectCount(agentQuery));
// 充值金额总数 // 充值金额总数
TransactionBillQuery rechargeDto = new TransactionBillQuery(); TransactionBillQuery rechargeDto = new TransactionBillQuery();
rechargeDto.setStatus(TransactionBillStatus.SUCCESS.getStatus()); rechargeDto.setStatus(TransactionBillStatus.SUCCESS.getStatus());

View File

@ -20,7 +20,8 @@ public class BriefVo {
private Integer totalOnlineCount; // 总设备在线数量 private Integer totalOnlineCount; // 总设备在线数量
private Integer userCount; // 商户用户数量 private Integer userCount; // 商户用户数量
private Integer tenantCount; // 租户用户数量 private Integer tenantCount; // 普通用户数量
private Integer agentCount; // 代理商数量
private Integer rechargeCount; // 充值订单数量 private Integer rechargeCount; // 充值订单数量
private Integer todayRechargeCount; // 今日充值订单数量 private Integer todayRechargeCount; // 今日充值订单数量

View File

@ -84,6 +84,9 @@ public class DeviceVO extends Device implements IotDevice {
@ApiModelProperty("代理名称") @ApiModelProperty("代理名称")
private String agentName; private String agentName;
@ApiModelProperty("代理商手机号")
private String agentMobile;
@Override @Override
public String iotMac1() { public String iotMac1() {
return getMac(); return getMac();

View File

@ -157,7 +157,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.phonenumber as user_mobile, su.phonenumber as user_mobile,
su.user_name as user_name, su.user_name as user_name,
su.service_rate as user_service_rate, 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 from sm_device sd
left join sm_model sm on sm.model_id = sd.model_id 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_store ss on ss.store_id = sd.store_id

View File

@ -13,6 +13,7 @@ import com.ruoyi.iot.domain.IotDeviceInfo;
import com.ruoyi.iot.domain.response.CommandResponse; import com.ruoyi.iot.domain.response.CommandResponse;
import com.ruoyi.iot.enums.IotHttpStatus; import com.ruoyi.iot.enums.IotHttpStatus;
import com.ruoyi.iot.service.IotService; 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.Device;
import com.ruoyi.ss.device.domain.DeviceBO; import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.DeviceCountVO; 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.timeBill.service.TimeBillService;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery; import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; 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.domain.vo.TransactionBillVO;
import com.ruoyi.ss.transactionBill.service.TransactionBillService; import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import com.ruoyi.ss.user.domain.SmUserVo; import com.ruoyi.ss.user.domain.SmUserVo;
@ -281,9 +283,18 @@ public class DeviceServiceImpl implements DeviceService
for (Long deviceId : deviceIds) { for (Long deviceId : deviceIds) {
DeviceVO device = deviceMap.get(deviceId); DeviceVO device = deviceMap.get(deviceId);
ServiceUtil.assertion(device == null, String.format("设备“%s”不存在请刷新后重试", 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 { try {
CommandResponse res = iotService.setTime(device, 0L); CommandResponse res = iotService.setTime(device, 0L);
ServiceUtil.assertion( !res.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员"); ServiceUtil.assertion(res == null, "设备归零失败,返回值为空");
ServiceUtil.assertion(!res.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员");
boolean close = iotService.close(device); // boolean close = iotService.close(device);
ServiceUtil.assertion( !close, "设备关闭失败,请检查设备是否在线或联系管理员"); // ServiceUtil.assertion( !close, "设备关闭失败,请检查设备是否在线或联系管理员");
} catch (Exception e) { } catch (Exception e) {
log.warn("设备归零失败:{}, {}, {}", device.getDeviceId(), device.getDeviceNo(), e.getMessage());
if (required) { if (required) {
throw e; throw e;
} }
@ -481,12 +494,14 @@ public class DeviceServiceImpl implements DeviceService
// 归零记录 // 归零记录
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
scheduledExecutorService.schedule(() -> { if (result != null && result == 1 ) {
// 设备剩余时长 scheduledExecutorService.schedule(() -> {
Duration duration = Duration.between(now, device.getExpireTime()); // 设备剩余时长
long seconds = duration.getSeconds() > 0 ? duration.getSeconds() : 0; Duration duration = Duration.between(now, device.getExpireTime());
recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, -seconds, "设备归零", loginUser, RecordTimeType.TIME.getType())); long seconds = duration.getSeconds() > 0 ? duration.getSeconds() : 0;
}, 0, TimeUnit.SECONDS); recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, -seconds, "设备归零", loginUser, RecordTimeType.TIME.getType()));
}, 0, TimeUnit.SECONDS);
}
return result == null ? 0 : result; return result == null ? 0 : result;
} }
@ -521,9 +536,11 @@ public class DeviceServiceImpl implements DeviceService
// 归零记录 // 归零记录
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
scheduledExecutorService.schedule(() -> { if (result != null && result == 1 ) {
recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, device.getSurplusEle().negate().intValue(), "设备归零", loginUser, RecordTimeType.ELE.getType())); scheduledExecutorService.schedule(() -> {
}, 0, TimeUnit.SECONDS); recordTimeService.insertRecordTime(recordTimeConverter.toRecordTime(device, device.getSurplusEle().negate().intValue(), "设备归零", loginUser, RecordTimeType.ELE.getType()));
}, 0, TimeUnit.SECONDS);
}
return result == null ? 0 : result; return result == null ? 0 : result;
} }
@ -996,7 +1013,7 @@ public class DeviceServiceImpl implements DeviceService
int reset = this.resetTime(device, requiredIot); int reset = this.resetTime(device, requiredIot);
ServiceUtil.assertion(reset != 1, "归零失败"); ServiceUtil.assertion(reset != 1, "归零失败");
return 1; return reset;
} }
/** /**

View File

@ -71,10 +71,8 @@ public interface ReceiveBillService
* *
* @param mch 商户信息 * @param mch 商户信息
* @param device 设备信息 * @param device 设备信息
* @param orderArrivalAmount 订单到账金额
* @param amount 月费收取的金额
*/ */
int genBillByMonthAndPay(SmUserVo mch, DeviceVO device, BigDecimal orderArrivalAmount, BigDecimal amount); int genBillByMonthAndPay(SmUserVo mch, DeviceVO device);
/** /**
* 查询数量 * 查询数量

View File

@ -122,17 +122,21 @@ public class ReceiveBillServiceImpl implements ReceiveBillService
} }
@Override @Override
public int genBillByMonthAndPay(SmUserVo mch, DeviceVO device, BigDecimal orderArrivalAmount, BigDecimal amount) { public int genBillByMonthAndPay(SmUserVo mch, DeviceVO device) {
LocalDateTime billTime = LocalDateTime.now(); ServiceUtil.assertion(mch == null || mch.getUserId() == null, "商户不存在");
ServiceUtil.assertion(mch == null || mch.getUserId() == null, "用户不存在");
ServiceUtil.assertion(device == null || device.getDeviceId() == null, "设备不存在"); ServiceUtil.assertion(device == null || device.getDeviceId() == null, "设备不存在");
LocalDateTime billTime = LocalDateTime.now();
// 设备未过期则不生成账单 // 设备未过期则不生成账单
if (device.getRentTime() != null && device.getRentTime().isAfter(billTime)) { if (device.getRentTime() != null && device.getRentTime().isAfter(billTime)) {
return 1; return 1;
} }
// 设备月费若为空或者0则不收取
if (device.getMonthFee() == null || device.getMonthFee().compareTo(BigDecimal.ZERO) == 0) {
return 1;
}
// 判断商户余额 + 订单金额是否足够账单金额 BigDecimal amount = device.getMonthFee();
ServiceUtil.assertion(mch.getBalance().add(orderArrivalAmount).compareTo(amount) < 0, "设备到期,商家余额不足,请联系商家处理");
// 生成账单 // 生成账单
ReceiveBill bill = new ReceiveBill(); ReceiveBill bill = new ReceiveBill();

View File

@ -274,6 +274,22 @@ public class TransactionBill extends BaseEntity implements Payable
@ApiModelProperty("版本号") @ApiModelProperty("版本号")
private Integer version; 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;
/** /**
* 获取价格 * 获取价格
*/ */

View File

@ -18,4 +18,7 @@ public class EndUseDTO {
@ApiModelProperty("总用电量") @ApiModelProperty("总用电量")
private BigDecimal totalEle; private BigDecimal totalEle;
@ApiModelProperty("是否通过线上关闭设备")
private Boolean withIot;
} }

View File

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

View File

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

View File

@ -60,6 +60,9 @@ public class TransactionBillVO extends TransactionBill implements IotDevice {
@ApiModelProperty("分成列表") @ApiModelProperty("分成列表")
private List<BonusVO> bonusList; private List<BonusVO> bonusList;
@ApiModelProperty("总用电量(度)/时长(秒)")
private BigDecimal totalUse;
/** /**
* 获取套餐时长 * 获取套餐时长
*/ */

View File

@ -68,6 +68,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.device_product_id, stb.device_product_id,
stb.device_service_mode, stb.device_service_mode,
stb.version, stb.version,
stb.close_status,
stb.close_result,
stb.agent_id,
stb.agent_mobile,
</sql> </sql>
<sql id="selectSmTransactionBillVo"> <sql id="selectSmTransactionBillVo">
@ -184,7 +188,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.createTimeEnd != null "> and stb.create_time &lt;= #{query.createTimeEnd}</if> <if test="query.createTimeEnd != null "> and stb.create_time &lt;= #{query.createTimeEnd}</if>
<if test="query.deviceProductId != null and query.deviceProductId != ''"> and stb.device_product_id = #{query.deviceProductId}</if> <if test="query.deviceProductId != null and query.deviceProductId != ''"> and stb.device_product_id = #{query.deviceProductId}</if>
<if test="query.deviceServiceMode != null and query.deviceServiceMode != ''"> and stb.device_service_mode = #{query.deviceServiceMode}</if> <if test="query.deviceServiceMode != null and query.deviceServiceMode != ''"> and stb.device_service_mode = #{query.deviceServiceMode}</if>
<if test="query.version != null "> and version = #{query.version}</if> <if test="query.version != null "> and stb.version = #{query.version}</if>
<if test="query.closeStatus != null and query.closeStatus != ''"> and stb.close_status = #{query.closeStatus}</if>
<if test="query.agentId != null "> and stb.agent_id = #{query.agentId}</if>
<if test="query.agentMobile != null and query.agentMobile != ''"> and stb.agent_mobile like concat('%', #{query.agentMobile}, '%')</if>
<if test="query.isUsing != null"> <if test="query.isUsing != null">
<if test="query.isUsing"> <if test="query.isUsing">
and <include refid="isUsing"/> and <include refid="isUsing"/>
@ -457,6 +464,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="suitLowPower != null">suit_low_power,</if> <if test="suitLowPower != null">suit_low_power,</if>
<if test="deviceProductId != null">device_product_id,</if> <if test="deviceProductId != null">device_product_id,</if>
<if test="version != null">version,</if> <if test="version != null">version,</if>
<if test="closeStatus != null">close_status,</if>
<if test="closeResult != null">close_result,</if>
<if test="agentId != null">agent_id,</if>
<if test="agentMobile != null">agent_mobile,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="billNo != null">#{billNo},</if> <if test="billNo != null">#{billNo},</if>
@ -513,6 +524,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="suitLowPower != null">#{suitLowPower},</if> <if test="suitLowPower != null">#{suitLowPower},</if>
<if test="deviceProductId != null">#{deviceProductId},</if> <if test="deviceProductId != null">#{deviceProductId},</if>
<if test="version != null">#{version},</if> <if test="version != null">#{version},</if>
<if test="closeStatus != null">#{closeStatus},</if>
<if test="closeResult != null">#{closeResult},</if>
<if test="agentId != null">#{agentId},</if>
<if test="agentMobile != null">#{agentMobile},</if>
</trim> </trim>
</insert> </insert>
@ -587,6 +602,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.deviceRechargeStatus != null">stb.device_recharge_status = #{data.deviceRechargeStatus},</if> <if test="data.deviceRechargeStatus != null">stb.device_recharge_status = #{data.deviceRechargeStatus},</if>
<if test="data.deviceServiceMode != null">stb.device_service_mode = #{data.deviceServiceMode},</if> <if test="data.deviceServiceMode != null">stb.device_service_mode = #{data.deviceServiceMode},</if>
<if test="data.version != null">stb.version = #{data.version},</if> <if test="data.version != null">stb.version = #{data.version},</if>
<if test="data.closeStatus != null">stb.close_status = #{data.closeStatus},</if>
<if test="data.closeResult != null">stb.close_result = #{data.closeResult},</if>
<if test="data.agentId != null">stb.agent_id = #{data.agentId},</if>
<if test="data.agentMobile != null">stb.agent_mobile = #{data.agentMobile},</if>
</sql> </sql>
<update id="updateByQuery"> <update id="updateByQuery">

View File

@ -31,4 +31,10 @@ public interface TransactionAssembler {
* @param list * @param list
*/ */
void assembleBonusList(List<TransactionBillVO> list); void assembleBonusList(List<TransactionBillVO> list);
/**
* 拼接总用电量时长
* @param list
*/
void assembleTotalUse(List<TransactionBillVO> list);
} }

View File

@ -8,14 +8,10 @@ import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.bo.*; import com.ruoyi.ss.transactionBill.domain.bo.*;
import com.ruoyi.ss.transactionBill.domain.dto.EndUseDTO; import com.ruoyi.ss.transactionBill.domain.dto.EndUseDTO;
import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO; import com.ruoyi.ss.transactionBill.domain.dto.RechargePayBO;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.*;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO;
import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO; import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus; 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.math.BigDecimal;
import java.time.LocalDateTime; 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);
/** /**
* 查询所有关于金额的总和 * 查询所有关于金额的总和

View File

@ -122,4 +122,23 @@ public class TransactionAssemblerImpl implements TransactionAssembler {
} }
} }
@Override
public void assembleTotalUse(List<TransactionBillVO> 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()));
}
}
}
} }

View File

@ -22,7 +22,6 @@ import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO;
import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService; import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService;
import com.ruoyi.ss.dashboard.vo.BillCountVo; import com.ruoyi.ss.dashboard.vo.BillCountVo;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus; 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.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceService; import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.payBill.domain.PayBillQuery; 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.domain.vo.DoPayVO;
import com.ruoyi.ss.payBill.service.PayBillConverter; import com.ruoyi.ss.payBill.service.PayBillConverter;
import com.ruoyi.ss.payBill.service.PayBillService; 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.domain.enums.RecordTimeType;
import com.ruoyi.ss.record.time.service.IRecordTimeService; import com.ruoyi.ss.record.time.service.IRecordTimeService;
import com.ruoyi.ss.record.time.service.RecordTimeConverter; 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.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.bo.*; import com.ruoyi.ss.transactionBill.domain.bo.*;
import com.ruoyi.ss.transactionBill.domain.dto.*; import com.ruoyi.ss.transactionBill.domain.dto.*;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO; import com.ruoyi.ss.transactionBill.domain.vo.*;
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.enums.*; import com.ruoyi.ss.transactionBill.domain.enums.*;
import com.ruoyi.ss.transactionBill.mapper.TransactionBillMapper; import com.ruoyi.ss.transactionBill.mapper.TransactionBillMapper;
import com.ruoyi.ss.transactionBill.service.*; import com.ruoyi.ss.transactionBill.service.*;
@ -159,6 +156,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
@Autowired @Autowired
private TransactionAssembler transactionAssembler; private TransactionAssembler transactionAssembler;
@Autowired
private ReceiveBillService receiveBillService;
/** /**
* 查询充值记录 * 查询充值记录
* *
@ -261,9 +261,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
List<Bonus> bonusList = bonusConverter.toPo(bo); List<Bonus> bonusList = bonusConverter.toPo(bo);
bo.setBonusList(bonusList); bo.setBonusList(bonusList);
// TODO 收取月费
transactionTemplate.execute(status -> { transactionTemplate.execute(status -> {
// 收取月费
int monthFee = receiveBillService.genBillByMonthAndPay(bo.getMch(), bo.getDevice());
ServiceUtil.assertion(monthFee != 1, "月费收取失败,请联系商户处理");
// 新增订单 // 新增订单
int insert = this.insertSmTransactionBill(order); int insert = this.insertSmTransactionBill(order);
ServiceUtil.assertion(insert != 1, "下单失败"); ServiceUtil.assertion(insert != 1, "下单失败");
@ -455,6 +457,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
order.setDeviceMac2(device.getMac2()); order.setDeviceMac2(device.getMac2());
order.setDeviceProductId(device.getModelProductId()); order.setDeviceProductId(device.getModelProductId());
order.setDeviceServiceMode(device.getServiceMode()); order.setDeviceServiceMode(device.getServiceMode());
order.setAgentId(device.getAgentId());
order.setAgentMobile(device.getAgentMobile());
// 店铺信息 // 店铺信息
if (store != null) { 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) { if (bo == null) {
return 0; return EndUseVO.fail();
} }
TransactionBillVO order = bo.getOrder(); TransactionBillVO order = bo.getOrder();
DeviceVO device = bo.getDevice(); 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 { try {
if (SuitFeeType.TIMING_COUNT.getType().equals(order.getSuitFeeType())) { transactionTemplate.execute(status -> {
deviceService.resetEle(device, true); // 记录设备关闭状态
} else if(SuitFeeType.TIMING_TIME.getType().equals(order.getSuitFeeType())){ int update = this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.SUCCESS, "成功");
deviceService.resetTime(device, true); ServiceUtil.assertion(update != 1, "记录设备关闭状态失败,请刷新后重试");
}
iotService.close(device); 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) { } 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) { private BigDecimal calcTotalEle(DeviceVO device, BigDecimal totalEle) {
@ -1071,9 +1087,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return totalAmount; return totalAmount;
} }
public int endSmartUse(EndUseBO bo, boolean resetDevice) { public EndUseVO endSmartUse(EndUseBO bo, boolean withDevice) {
if (bo == null) { if (bo == null) {
return 0; return EndUseVO.fail();
} }
TransactionBillVO order = bo.getOrder(); TransactionBillVO order = bo.getOrder();
DeviceVO device = bo.getDevice(); 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); if (withDevice) {
ServiceUtil.assertion(clear != 1, "设备归零失败"); int clear = deviceService.clearTimeAndEle(device, false);
} catch (Exception e) { ServiceUtil.assertion(clear != 1, "设备归零失败");
log.warn("设备归零失败"); }
}
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 @Override
@ -1174,9 +1209,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return transactionBillMapper.selectSumOfMoney(query); return transactionBillMapper.selectSumOfMoney(query);
} }
public int endUseSingle(EndUseBO bo, boolean resetDevice) { public EndUseVO endUseSingle(EndUseBO bo, boolean withDevice) {
if (bo == null) { if (bo == null) {
return 0; return EndUseVO.fail();
} }
TransactionBillVO order = bo.getOrder(); TransactionBillVO order = bo.getOrder();
DeviceVO device = bo.getDevice(); 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 { try {
if (SuitFeeType.COUNT.getType().equals(order.getSuitFeeType())) { transactionTemplate.execute(status -> {
deviceService.resetEle(device, true); // 记录设备关闭状态成功
} else if(SuitFeeType.TIME.getType().equals(order.getSuitFeeType())){ int update = this.updateCloseStatus(order.getBillId(), RechargeCloseStatus.SUCCESS, "成功");
deviceService.resetTime(device, true); 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) { } 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) { private BigDecimal calcRefundAmount(TransactionBillVO order, LocalDateTime endTime, BigDecimal totalEle) {
@ -1770,9 +1819,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 关闭订单智能订单需要退款 // 关闭订单智能订单需要退款
for (TransactionBillVO bill : billList) { for (TransactionBillVO bill : billList) {
bo.setOrder(bill); bo.setOrder(bill);
int end = this.endUse(bo, withDevice); EndUseVO end = this.endUse(bo, withDevice);
ServiceUtil.assertion(end != 1, "关闭订单失败:" + bill.getBillNo()); ServiceUtil.assertion(end.getResult() != 1, "关闭订单失败:" + bill.getBillNo());
sum += end; sum += end.getResult();
} }
return sum; return sum;
@ -1786,9 +1835,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 结束使用订单 // 结束使用订单
@Override @Override
public int endUse(EndUseBO bo, boolean withDevice) { public EndUseVO endUse(EndUseBO bo, boolean withDevice) {
if (bo == null) { if (bo == null) {
return 0; return EndUseVO.fail();
} }
TransactionBillVO bill = bo.getOrder(); TransactionBillVO bill = bo.getOrder();
@ -1808,11 +1857,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return this.endUseSingle(bo, withDevice); return this.endUseSingle(bo, withDevice);
} }
return 0; return EndUseVO.fail();
} }
@Override @Override
public int endUse(EndUseDTO dto, boolean withDevice) { public EndUseVO endUse(EndUseDTO dto, boolean withDevice) {
EndUseBO bo = transactionBillConverter.toEndUseBO(dto); EndUseBO bo = transactionBillConverter.toEndUseBO(dto);
return this.endUse(bo, withDevice); return this.endUse(bo, withDevice);
} }

View File

@ -144,7 +144,7 @@ public class AppTransactionBillController extends BaseController
@JsonView(JsonViewProfile.AppUser.class) @JsonView(JsonViewProfile.AppUser.class)
public AjaxResult detail(@PathVariable String billNo) { public AjaxResult detail(@PathVariable String billNo) {
TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillNo(billNo); TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillNo(billNo);
if (!transactionBillValidator.isUser(bill, getUserId())) { if (!transactionBillValidator.isUser(bill, getUserId()) && !transactionBillValidator.isMch(bill, getUserId())) {
return success(); return success();
} }
transactionAssembler.assembleChannelName(Collections.singletonList(bill)); 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())) { if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) {
return error("您不是该订单的用户或商户,无法结束订单"); return error("您不是该订单的用户或商户,无法结束订单");
} }
return toAjax(transactionBillService.endUse(bo, true )); return success(transactionBillService.endUse(bo, true ));
} }
@ApiOperation("提前结束使用智能订单") @ApiOperation("提前结束使用智能订单")
@ -303,7 +303,7 @@ public class AppTransactionBillController extends BaseController
if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) { if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) {
return error("您不是该订单的用户或商户,无法结束订单"); 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())) { if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) {
return error("您不是该订单的用户或商户,无法结束订单"); return error("您不是该订单的用户或商户,无法结束订单");
} }
return toAjax(transactionBillService.endUse(bo, true )); return success(transactionBillService.endUse(bo, true ));
} }
@ApiOperation("获取订单预估金额") @ApiOperation("获取订单预估金额")

View File

@ -127,9 +127,9 @@ public class SmDeviceController extends BaseController
@PreAuthorize("@ss.hasPermi('system:device:remove')") @PreAuthorize("@ss.hasPermi('system:device:remove')")
@Log(title = "设备", businessType = BusinessType.LOGIC_DELETE) @Log(title = "设备", businessType = BusinessType.LOGIC_DELETE)
@DeleteMapping("/logic/{deviceIds}") @DeleteMapping("/logic/{deviceIds}")
public AjaxResult logicDel(@PathVariable Long[] deviceIds) public AjaxResult logicDel(@PathVariable List<Long> deviceIds)
{ {
return toAjax(deviceService.logicDel(Arrays.asList(deviceIds))); return toAjax(deviceService.logicDel(deviceIds));
} }
@ApiOperation("刷新设备信息") @ApiOperation("刷新设备信息")

View File

@ -1,5 +1,6 @@
package com.ruoyi.web.controller.ss; package com.ruoyi.web.controller.ss;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; 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.vo.TransactionBillVO;
import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO; import com.ruoyi.ss.transactionBill.domain.dto.BillRefundDTO;
import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO; import com.ruoyi.ss.transactionBill.domain.dto.WithdrawApprovalDTO;
import com.ruoyi.ss.transactionBill.service.TransactionAssembler;
import com.ruoyi.ss.transactionBill.service.TransactionBillConverter; import com.ruoyi.ss.transactionBill.service.TransactionBillConverter;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -48,6 +50,9 @@ public class SmTransactionBillController extends BaseController
@Autowired @Autowired
private TransactionBillConverter transactionBillConverter; private TransactionBillConverter transactionBillConverter;
@Autowired
private TransactionAssembler transactionAssembler;
/** /**
* 查询充值记录列表 * 查询充值记录列表
*/ */
@ -57,6 +62,7 @@ public class SmTransactionBillController extends BaseController
{ {
startPage(); startPage();
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(smTransactionBill); List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(smTransactionBill);
transactionAssembler.assembleTotalUse(list);
return getDataTable(list); return getDataTable(list);
} }
@ -80,40 +86,10 @@ public class SmTransactionBillController extends BaseController
@GetMapping(value = "/{billId}") @GetMapping(value = "/{billId}")
public AjaxResult getInfo(@PathVariable("billId") Long billId) public AjaxResult getInfo(@PathVariable("billId") Long billId)
{ {
return success(transactionBillService.selectSmTransactionBillByBillId(billId)); TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillId(billId);
} List<TransactionBillVO> list = Collections.singletonList(bill);
transactionAssembler.assembleTotalUse(list);
/** return success(bill);
* 新增充值记录
*/
@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));
} }
@PreAuthorize("@ss.hasPermi('system:bill:query')") @PreAuthorize("@ss.hasPermi('system:bill:query')")