套餐修改

This commit is contained in:
墨大叔 2024-08-16 22:20:53 +08:00
parent 50741928a5
commit 6b1f38f07a
22 changed files with 393 additions and 158 deletions

View File

@ -6,7 +6,7 @@ import com.ruoyi.iot.domain.ReceiveBody;
import com.ruoyi.iot.domain.ReceiveMsg;
import com.ruoyi.iot.service.IotReceiveService;
import com.ruoyi.iot.service.IotService;
import com.ruoyi.iot.util.Util;
import com.ruoyi.iot.util.IotUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -51,10 +51,10 @@ public class ReceiveController {
@Anonymous
public ResponseEntity<String> receive(@RequestBody String body){
log.info("receive方法接收到参数: body String --- {}", body);
ReceiveBody obj = Util.resolveBody(body, false);
ReceiveBody obj = IotUtil.resolveBody(body, false);
log.info("receive方法解析对象: body Object --- {}", JSON.toJSONString(obj));
if (obj != null){
if (Util.checkSignature(obj, token)){
if (IotUtil.checkSignature(obj, token)){
log.info("receive方法验证签名正确: content {}", JSON.toJSONString(obj));
Object msg = obj.getMsg();
log.info("receive方法-获取到消息体: msg--- {}", JSON.toJSONString(msg));
@ -86,7 +86,7 @@ public class ReceiveController {
@RequestParam(value = "signature") String signature) throws UnsupportedEncodingException {
log.info("check方法接收到参数: msg:{} nonce{} signature:{}",msg,nonce,signature);
if (Util.checkToken(msg,nonce,signature,token)){
if (IotUtil.checkToken(msg,nonce,signature,token)){
return msg;
}else {
return "error";

View File

@ -9,6 +9,7 @@ import com.ruoyi.iot.domain.response.CommandResponse;
import com.ruoyi.ss.device.domain.Device;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import java.math.BigDecimal;
import java.util.List;
/**
@ -137,12 +138,12 @@ public interface IotService {
int create(String mac, String productId);
/**
* 设备添加电量
* 设备添加电量
*/
CommandResponse addEle(String deviceName, int ele, String productId);
CommandResponse addEle(String deviceName, BigDecimal ele, String productId);
/**
* 直接设置设备电量
* 直接设置设备电量
*/
CommandResponse setEle(String deviceName, int ele, String productId);
CommandResponse setEle(String deviceName, BigDecimal ele, String productId);
}

View File

@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
@ -192,19 +193,19 @@ public class IotServiceImpl implements IotService {
@Override
public CommandResponse addEle(String deviceName, int ele, String productId) {
if (ele < 0) {
public CommandResponse addEle(String deviceName, BigDecimal ele, String productId) {
if (ele == null || ele.compareTo(BigDecimal.ZERO) < 0) {
throw new ServiceException("充值电量错误充值电量不允许小于0");
}
return sendCommand(deviceName, IotConstants.COMMAND_ADD_ELE + ele + IotConstants.COMMAND_SEPARATOR, 5, productId);
return sendCommand(deviceName, IotConstants.COMMAND_ADD_ELE + ele.multiply(BigDecimal.valueOf(1000)) + IotConstants.COMMAND_SEPARATOR, 5, productId);
}
@Override
public CommandResponse setEle(String deviceName, int ele, String productId) {
if (ele < 0) {
throw new ServiceException("充值电量错误充值电量不允许小于0");
public CommandResponse setEle(String deviceName, BigDecimal ele, String productId) {
if (ele == null) {
throw new ServiceException("设置电量错误:不允许为空");
}
return sendCommand(deviceName, IotConstants.COMMAND_SET_ELE + ele + IotConstants.COMMAND_SEPARATOR, 5, productId);
return sendCommand(deviceName, IotConstants.COMMAND_SET_ELE + ele.multiply(BigDecimal.valueOf(1000)) + IotConstants.COMMAND_SEPARATOR, 5, productId);
}
/**

View File

@ -11,7 +11,12 @@ import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.security.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
@ -20,9 +25,9 @@ import java.security.*;
* Created by Roy on 2017/5/17.
*
*/
public class Util {
public class IotUtil {
private static Logger logger = LoggerFactory.getLogger(Util.class);
private static Logger logger = LoggerFactory.getLogger(IotUtil.class);
private static MessageDigest mdInst;
@ -137,5 +142,33 @@ public class Util {
return len;
}
/**
* 解析设备字符串
*/
public static Map<String, BigDecimal> parseDeviceStr(String str) {
// 使用 @ 符号分割字符串
String[] parts = str.split("@");
// 创建一个 Map 来存储结果
Map<String, BigDecimal> resultMap = new HashMap<>();
// 正则表达式用于匹配数字
Pattern pattern = Pattern.compile("[-+]?\\d*\\.\\d+|\\d+");
for (String part : parts) {
Matcher matcher = pattern.matcher(part);
if (matcher.find()) {
// 提取第一个匹配到的数字
BigDecimal number = new BigDecimal(matcher.group());
// 从子字符串中提取键
String key = part.substring(0, 1); // 假设键是子字符串的第一个字符
// 存储到 Map
resultMap.put(key, number);
}
}
return resultMap;
}
}

View File

@ -285,15 +285,20 @@ public interface DeviceService
/**
* 清空设备时长电量
*/
int clearTimeAndEle(DeviceVO device);
int clearTimeAndEle(DeviceVO device, boolean required);
/**
* 设备归零时长
*/
int resetTime(DeviceVO device);
int resetTime(DeviceVO device, boolean required);
/**
* 设备归零电量
*/
int resetEle(DeviceVO device);
int resetEle(DeviceVO device, boolean required);
/**
* 归零电量
*/
int resetEle(Long deviceId, boolean required);
}

View File

@ -24,10 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -64,6 +61,7 @@ public class DeviceAssemblerImpl implements DeviceAssembler {
for (DeviceVO device : list) {
List<DeviceSuitVO> deviceSuitList = group.get(device.getDeviceId());
if (deviceSuitList != null) {
deviceSuitList.sort(Comparator.comparing(o -> o.getSuit().getSort()));
device.setSuitList(deviceSuitList.stream().map(DeviceSuitVO::getSuit).collect(Collectors.toList()));
} else {
device.setSuitList(Collections.emptyList());

View File

@ -409,22 +409,22 @@ public class DeviceServiceImpl implements DeviceService
}
@Override
public int clearTimeAndEle(DeviceVO device) {
public int clearTimeAndEle(DeviceVO device, boolean required) {
if (device == null) {
return 0;
}
// 归零时长
int resetTime = resetTime(device);
int resetTime = this.resetTime(device, required);
// 归零剩余电量
int resetEle = this.resetEle(device);
int resetEle = this.resetEle(device, required);
return 1;
}
@Override
public int resetTime(DeviceVO device) {
public int resetTime(DeviceVO device, boolean required) {
LocalDateTime now = LocalDateTime.now();
Integer result = transactionTemplate.execute(status -> {
// 归零时间将过期时间设置为现在
@ -436,8 +436,14 @@ public class DeviceServiceImpl implements DeviceService
ServiceUtil.assertion(update != 1, "修改设备时间失败");
// 物联网设备归零
CommandResponse res = iotService.setTime(device.getMac(), 1L, device.getModelProductId());
ServiceUtil.assertion(!res.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员");
try {
CommandResponse res = iotService.setTime(device.getMac(), 1L, device.getModelProductId());
ServiceUtil.assertion( !res.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员");
} catch (Exception e) {
if (required) {
throw e;
}
}
return update;
});
@ -455,7 +461,7 @@ public class DeviceServiceImpl implements DeviceService
}
@Override
public int resetEle(DeviceVO device) {
public int resetEle(DeviceVO device, boolean required) {
if (device == null) {
return 0;
}
@ -473,8 +479,14 @@ public class DeviceServiceImpl implements DeviceService
ServiceUtil.assertion(update != 1, "更新剩余电量失败");
// 直接设置电量为0
CommandResponse res = iotService.setEle(device.getMac(), 0, device.getModelProductId());
ServiceUtil.assertion(!res.isSuccess(), "归零电量失败,请检查设备是否在线或联系管理员");
try {
CommandResponse res = iotService.setEle(device.getMac(), BigDecimal.valueOf(0), device.getModelProductId());
ServiceUtil.assertion(!res.isSuccess(), "归零电量失败,请检查设备是否在线或联系管理员");
} catch (Exception e) {
if (required) {
throw e;
}
}
return update;
});
@ -488,6 +500,12 @@ public class DeviceServiceImpl implements DeviceService
return result == null ? 0 : result;
}
@Override
public int resetEle(Long deviceId, boolean required) {
DeviceVO device = selectSmDeviceByDeviceId(deviceId);
return resetEle(device, required);
}
@Override
public boolean addTime(Long deviceId, long seconds, boolean withIot) {
@ -790,7 +808,7 @@ public class DeviceServiceImpl implements DeviceService
// 关闭该设备未结束的所有订单
transactionBillService.batchEndBillByDevice(deviceId);
int reset = this.resetTime(device);
int reset = this.resetTime(device, true);
ServiceUtil.assertion(reset != 1, "归零失败");
return reset;

View File

@ -61,6 +61,12 @@ public class PayBill extends BaseEntity implements Payable
@ApiModelProperty("渠道成本")
private BigDecimal channelCost;
@ApiModelProperty("已退款金额")
private BigDecimal refundAmount;
@ApiModelProperty("退款中金额")
private BigDecimal refundingAmount;
/**
* 获取价格
*/

View File

@ -1,5 +1,6 @@
package com.ruoyi.ss.payBill.mapper;
import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.ss.payBill.domain.PayBill;
import com.ruoyi.ss.payBill.domain.PayBillVO;
@ -77,5 +78,16 @@ public interface PayBillMapper
*/
int updatePayQuery(@Param("data") PayBill data, @Param("query") PayBillQuery query);
/**
* 增加退款金额
*
* @param payId 支付订单ID
* @param amount 增加的退款金额
*/
int addRefundingAmount(@Param("payId") Long payId, @Param("amount") BigDecimal amount);
/**
* 记录转移已退款金额
*/
int recordRefundAmount(@Param("payId") Long payId, @Param("amount") BigDecimal amount);
}

View File

@ -4,7 +4,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.ss.payBill.mapper.PayBillMapper">
<resultMap type="PayBillVO" id="PayBillResult" autoMapping="true"/>
<resultMap type="PayBillVO" id="PayBillResult" autoMapping="true">
<result property="refundAmount" column="refund_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
<result property="refundingAmount" column="refunding_amount" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<sql id="selectPayBillVo">
select
@ -19,7 +22,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
spb.create_time,
spb.description,
spb.account,
spb.channel_cost
spb.channel_cost,
spb.refund_amount,
spb.refunding_amount
from ss_pay_bill spb
</sql>
@ -32,6 +37,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.status != null and query.status != ''"> and spb.status = #{query.status}</if>
<if test="query.startCreateTime != null">and spb.create_time >= #{query.startCreateTime}</if>
<if test="query.endCreateTime != null">and spb.create_time &lt;= #{query.endCreateTime}</if>
<if test="query.bstIds != null and query.bstIds.size() > 0">
and spb.bst_id in
<foreach item="item" index="index" collection="query.bstIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</sql>
<select id="selectPayBillList" parameterType="PayBillQuery" resultMap="PayBillResult">
@ -70,6 +81,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="description != null">`description`,</if>
<if test="account != null">`account`,</if>
<if test="channelCost != null">channel_cost,</if>
<if test="refundAmount != null">refund_amount,</if>
<if test="refundingAmount != null">refunding_amount,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="payNo != null and payNo != ''">#{payNo},</if>
@ -83,9 +96,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="description != null">#{description},</if>
<if test="account != null">#{account},</if>
<if test="channelCost != null">#{channelCost},</if>
<if test="refundAmount != null">#{refundAmount},</if>
<if test="refundingAmount != null">#{refundingAmount},</if>
</trim>
</insert>
<insert id="addRefundingAmount">
update ss_pay_bill
set refunding_amount = refunding_amount + #{amount}
where pay_id = #{payId} and amount >= refunding_amount + refund_amount + #{amount}
</insert>
<update id="recordRefundAmount">
update ss_pay_bill
set refunding_amount = refunding_amount - #{amount},
refund_amount = refund_amount + #{amount}
where pay_id = #{payId} and refunding_amount - #{amount} >= 0
</update>
<update id="updatePayBill" parameterType="PayBill">
update ss_pay_bill
<trim prefix="SET" suffixOverrides=",">
@ -106,6 +134,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.description != null">`description` = #{data.description},</if>
<if test="data.account != null">`account` = #{data.account},</if>
<if test="data.channelCost != null">channel_cost = #{data.channelCost},</if>
<if test="data.refundAmount != null">refund_amount = #{data.refundAmount},</if>
<if test="data.refundingAmount != null">refunding_amount = #{data.refundingAmount},</if>
</sql>
<update id="updatePayQuery">

View File

@ -3,7 +3,6 @@ package com.ruoyi.ss.payBill.service.impl;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -27,18 +26,10 @@ import com.ruoyi.ss.payBill.domain.vo.PayResultVO;
import com.ruoyi.ss.payBill.interfaces.AfterPay;
import com.ruoyi.ss.payBill.interfaces.AfterRefund;
import com.ruoyi.ss.payBill.service.PayBillConverter;
import com.ruoyi.ss.recordBalance.domain.enums.RecordBalanceBstType;
import com.ruoyi.ss.refund.domain.Refund;
import com.ruoyi.ss.refund.domain.RefundVO;
import com.ruoyi.ss.refund.service.RefundConverter;
import com.ruoyi.ss.refund.service.RefundService;
import com.ruoyi.ss.timeBill.service.TimeBillService;
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillPayType;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
import com.ruoyi.ss.user.service.ISmUserService;
import com.ruoyi.common.pay.wx.service.WxPayService;
import com.wechat.pay.java.service.payments.model.Transaction;
import lombok.extern.slf4j.Slf4j;
@ -343,7 +334,8 @@ public class PayBillServiceImpl implements PayBillService
bo.setDto(dto);
bo.setPayBill(bill);
ServiceUtil.assertion(dto.getRefundAmount().compareTo(bill.getAmount()) > 0, "退款金额不允许大于订单金额");
BigDecimal totalRefundAmount = dto.getRefundAmount().add(bill.getRefundAmount()).add(bill.getRefundingAmount());
ServiceUtil.assertion(totalRefundAmount.compareTo(bill.getAmount()) > 0, "总退款金额不允许大于订单金额");
ServiceUtil.assertion(!PayBillStatus.PAY_SUCCESS.getStatus().equals(bill.getStatus()), "当前状态不允许退款");
Integer result = transactionTemplate.execute(status -> {
@ -356,6 +348,10 @@ public class PayBillServiceImpl implements PayBillService
int updateBill = this.updateByQuery(data, billQuery);
ServiceUtil.assertion(updateBill != 1, "修改支付订单状态失败");
// 增加退款中金额
int addRefunding = payBillMapper.addRefundingAmount(dto.getPayId(), dto.getRefundAmount());
ServiceUtil.assertion(addRefunding != 1, "记录退款中的金额失败");
// 创建退款订单
int refund = refundService.createRefund(refundConverter.toPo(bo));
ServiceUtil.assertion(refund != 1, "申请退款失败");
@ -382,6 +378,10 @@ public class PayBillServiceImpl implements PayBillService
int update = this.updateByQuery(data, query);
ServiceUtil.assertion(update != 1, "支付订单状态已发生变化,请刷新后重试");
// 记录已退款金额并修改状态
int recordAmount = payBillMapper.recordRefundAmount(refund.getBillId(), refund.getAmount());
ServiceUtil.assertion(recordAmount != 1, "修改退款金额失败");
// 修改业务
PayBillVO pay = this.selectPayBillByPayId(refund.getBillId());
PayBillBstType bstType = PayBillBstType.parse(pay.getBstType());

View File

@ -77,9 +77,6 @@ public class TransactionBillQuery extends TransactionBill {
@ApiModelProperty("设备ID列表")
private List<Long> deviceIds;
@ApiModelProperty("是否使用中")
private Boolean using;
@ApiModelProperty("套餐结束时间(结束)")
private LocalDateTime endSuitEndTime;

View File

@ -8,6 +8,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author
* 2024/3/4
@ -31,14 +33,18 @@ public class TransactionBillVO extends TransactionBill {
@JsonView(JsonViewProfile.AppMch.class)
private String mchMobile;
@ApiModelProperty("设备编号")
@JsonView(JsonViewProfile.App.class)
private String deviceNo;
@ApiModelProperty("用户手机号")
@JsonView(JsonViewProfile.App.class)
private String userMobile;
@ApiModelProperty("设备总用电量")
@JsonView(JsonViewProfile.App.class)
private BigDecimal deviceTotalEle;
@ApiModelProperty("是否使用中")
@JsonView(JsonViewProfile.App.class)
private Boolean isUsing;
/**
* 获取套餐时长
*/

View File

@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="transferIds" column="transfer_ids" typeHandler="com.ruoyi.system.mapper.typehandler.StringListTypeHandler"/>
<result property="suitGearAmount" column="suit_gear_amount" typeHandler="com.ruoyi.system.mapper.typehandler.DecimalSplitListTypeHandler"/>
<result property="suitGearTime" column="suit_gear_time" typeHandler="com.ruoyi.system.mapper.typehandler.IntegerSplitListTypeHandler"/>
<result property="deviceTotalEle" column="device_total_ele" typeHandler="com.ruoyi.system.mapper.typehandler.NonNullDecimalTypeHandler"/>
</resultMap>
<sql id="BaseColumns">
@ -65,10 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectSmTransactionBillVo">
select
<include refid="BaseColumns"/>
if(<include refid="isUsing"/>, true, false) as is_using,
su.user_name as user_name,
su1.user_name as mch_name,
su1.phonenumber as mch_mobile,
sd.device_no as device_no,
sd.total_electri_quantity as device_total_ele,
su.phonenumber as user_mobile
from <include refid="rechargeTables"/>
</sql>
@ -96,6 +99,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join ss_channel_withdraw sc on sc.channel_id = stb.channel_id
</sql>
<sql id="isUsing">
(
(
stb.suit_start_time is not null
and stb.suit_start_time &lt; now()
and (stb.suit_end_time is null or stb.suit_end_time > now())
)
or
(
stb.suit_fee_type in ('2', '3')
and stb.suit_start_ele is not null
and stb.suit_start_ele &lt; sd.total_electri_quantity
and (stb.suit_end_ele is null or stb.suit_end_ele > sd.total_electri_quantity)
)
)
</sql>
<sql id="searchCondition">
<if test="query.userId != null "> and stb.user_id = #{query.userId}</if>
<if test="query.billNo != null and query.billNo != ''"> and stb.bill_no like concat('%', #{query.billNo}, '%')</if>
@ -130,10 +150,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.suitFeeType != null and query.suitFeeType != ''"> and suit_fee_type = #{query.suitFeeType}</if>
<if test="query.isUsing != null">
<if test="query.isUsing">
and (suit_start_time is not null and suit_start_time &lt;= now() and (suit_end_time is null or suit_end_time >= now()))
and <include refid="isUsing"/>
</if>
<if test="!query.isUsing">
and (suit_start_time is null or suit_start_time > now() or (suit_end_time is not null and suit_end_time &lt;= now()))
and !<include refid="isUsing"/>
</if>
</if>
<if test="query.keyword != null and query.keyword != ''">
@ -144,14 +164,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
or su.phonenumber like concat('%', #{query.keyword}, '%')
)
</if>
<if test="query.using != null">
<if test="query.using">
and now() >= stb.suit_start_time and now() &lt;= stb.suit_end_time and now() &lt;= stb.suit_expire_time
</if>
<if test="!query.using">
and ( now() &lt;= stb.suit_start_time or now() >= stb.suit_end_time or now() >= stb.suit_expire_time)
</if>
</if>
<if test="query.suitFeeTypes != null and query.suitFeeTypes.size() > 0">
and stb.suit_fee_type in
<foreach item="item" collection="query.suitFeeTypes" open="(" separator="," close=")">

View File

@ -13,6 +13,7 @@ import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@ -265,4 +266,14 @@ public interface TransactionBillService
* 提前结束智能订单
*/
int endSmartUse(EndSmartUseBO bo);
/**
* 查询未支付的分时段订单
*/
List<TransactionBillVO> selectUnpaidTimingBill(TransactionBillQuery query);
/**
* 计算订单金额
*/
BigDecimal calcAmount(Long billId, LocalDateTime now, BigDecimal totalEle);
}

View File

@ -45,6 +45,8 @@ public class RechargeDepositAfterPay implements AfterPay {
ServiceUtil.assertion(bill == null, "订单不存在");
ServiceUtil.assertion(!TransactionBillStatus.UNPAID_DEPOSIT.getStatus().equals(bill.getStatus()), "订单状态非待支付押金");
deviceService.pullDeviceInfo(bill.getDeviceId());
DeviceVO device = deviceService.selectSmDeviceByDeviceId(bill.getDeviceId());
ServiceUtil.assertion(device == null, "设备不存在");
@ -52,6 +54,7 @@ public class RechargeDepositAfterPay implements AfterPay {
// 修改订单信息
TransactionBill data = new TransactionBill();
data.setSuitStartTime(LocalDateTime.now());
data.setSuitStartEle(device.getTotalElectriQuantity());
data.setStatus(TransactionBillStatus.SUCCESS_DEPOSIT.getStatus());
data.setDepositPayId(payBill.getPayId());
data.setPayTime(DateUtils.toDate(payBill.getPayTime()));

View File

@ -119,7 +119,6 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
Integer result = transactionTemplate.execute(status -> {
TransactionBill billData = new TransactionBill();
billData.setStatus(TransactionBillStatus.REFUNDED.getStatus());
TransactionBillQuery billQuery = new TransactionBillQuery();
billQuery.setBillId(pay.getBstId());
billQuery.setStatus(TransactionBillStatus.REFUNDING.getStatus());

View File

@ -1,7 +1,6 @@
package com.ruoyi.ss.transactionBill.service.impl;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.core.redis.enums.RedisLockKey;
import com.ruoyi.common.enums.WithdrawServiceType;
@ -29,8 +28,6 @@ import com.ruoyi.ss.receiveBill.service.ReceiveBillService;
import com.ruoyi.ss.record.time.service.IRecordTimeService;
import com.ruoyi.ss.record.time.service.RecordTimeConverter;
import com.ruoyi.ss.recordBalance.domain.enums.RecordBalanceBstType;
import com.ruoyi.ss.refund.domain.Refund;
import com.ruoyi.ss.refund.domain.RefundVO;
import com.ruoyi.ss.refund.service.RefundConverter;
import com.ruoyi.ss.refund.service.RefundService;
import com.ruoyi.ss.store.domain.StoreVo;
@ -655,8 +652,13 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 设备充值时长
return deviceService.addTime(bill.getDeviceId(), bill.toSecondSuitTime(), true);
} else if (SuitFeeType.COUNT.getType().equals(bill.getSuitFeeType())) {
// 若设备剩余时长为负数则补偿设备时长
BigDecimal openTime = BigDecimal.valueOf(bill.getSuitTime());
if (device.getSurplusEle() != null && device.getSurplusEle().compareTo(BigDecimal.ZERO) < 0) {
openTime = openTime.add(device.getSurplusEle().abs());
}
// 设备充值电量
CommandResponse res = iotService.addEle(device.getMac(), bill.getSuitTime(), device.getModelProductId());
CommandResponse res = iotService.addEle(device.getMac(), openTime, device.getModelProductId());
ServiceUtil.assertion(!res.isSuccess(), "设备充值失败:" + res.getMsg());
return true;
} else {
@ -787,27 +789,15 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
LocalDateTime endTime = LocalDateTime.now(); // 结束使用的时间
// 结束使用的电量若蓝牙传过来的值为空或者小于当前电量则使用当前电量否则使用蓝牙传输的电量
BigDecimal totalEle;
if (dto.getTotalEle() == null || dto.getTotalEle().compareTo(device.getTotalElectriQuantity()) < 0) {
totalEle = device.getTotalElectriQuantity();
} else {
totalEle = dto.getTotalEle();
}
BigDecimal totalEle = this.calcTotalEle(device, dto.getTotalEle());
// 计算金额
BigDecimal money;
if (SuitFeeType.TIMING_TIME.getType().equals(order.getSuitFeeType())) {
money = this.calcTimingTimeAmount(order, endTime);
} else if (SuitFeeType.TIMING_COUNT.getType().equals(order.getSuitFeeType())) {
money = this.calcTimingCountAmount(order, endTime, totalEle);
} else {
throw new ServiceException("计算金额出错,套餐收费类型不支持");
}
BigDecimal money = this.calcTimingAmount(order, endTime, totalEle);
Integer result = transactionTemplate.execute(status -> {
// 修改订单信息
TransactionBill data = new TransactionBill();
data.setSuitEndEle(dto.getTotalEle());
data.setSuitEndEle(totalEle);
data.setSuitEndTime(endTime);
data.setStatus(TransactionBillStatus.UNPAID.getStatus());
data.setMoney(money);
@ -823,6 +813,11 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 尝试关闭设备
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.getMac(), device.getModelProductId());
} catch (Exception e) {
log.error("尝试关闭设备失败");
@ -832,9 +827,33 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return result == null ? 0 : result;
}
private BigDecimal calcTotalEle(DeviceVO device, BigDecimal totalEle) {
if (totalEle == null || totalEle.compareTo(device.getTotalElectriQuantity()) < 0) {
return device.getTotalElectriQuantity();
} else {
return totalEle;
}
}
private BigDecimal calcTimingAmount(TransactionBillVO order, LocalDateTime endTime, BigDecimal totalEle) {
ServiceUtil.assertion(order == null, "计算金额出错,订单不存在");
BigDecimal totalAmount;
if (SuitFeeType.TIMING_TIME.getType().equals(order.getSuitFeeType())) {
totalAmount = this.calcTimingTimeAmount(order, endTime);
} else if (SuitFeeType.TIMING_COUNT.getType().equals(order.getSuitFeeType())) {
totalAmount = this.calcTimingCountAmount(order, endTime, totalEle);
} else {
throw new ServiceException("计算金额出错,套餐收费类型不支持");
}
// 最低0.01元
if (totalAmount.compareTo(BigDecimal.valueOf(0.01)) < 0) {
totalAmount = BigDecimal.valueOf(0.01);
}
return totalAmount;
}
@Override
public int endSmartUse(EndSmartUseBO bo) {
// TODO
if (bo == null) {
return 0;
}
@ -849,27 +868,14 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
LocalDateTime endTime = LocalDateTime.now(); // 结束使用的时间
// 结束使用的电量若蓝牙传过来的值为空或者小于当前电量则使用当前电量否则使用蓝牙传输的电量谁大用谁
BigDecimal totalEle;
if (dto.getTotalEle() == null || dto.getTotalEle().compareTo(device.getTotalElectriQuantity()) < 0) {
totalEle = device.getTotalElectriQuantity();
} else {
totalEle = dto.getTotalEle();
}
BigDecimal totalEle = this.calcTotalEle(device, dto.getTotalEle());
// 若结束时间 > 订单结束时间 或者 结束电量 > 订单结束电量则表示已经结束使用
ServiceUtil.assertion(endTime.isAfter(order.getSuitEndTime()), "当前订单已结束,无法操作");
ServiceUtil.assertion(order.getSuitEndTime() != null && endTime.isAfter(order.getSuitEndTime()), "当前订单已结束,无法操作");
ServiceUtil.assertion(order.getSuitEndEle() != null && totalEle.compareTo(order.getSuitEndEle()) > 0, "当前订单已结束,无法操作");
// 计算需要退款的金额
BigDecimal refundAmount;
// 智能收费时长计费
if (SuitFeeType.TIME.getType().equals(order.getSuitFeeType())) {
refundAmount = this.calcTimeRefund(order, endTime);
} else if (SuitFeeType.COUNT.getType().equals(order.getSuitFeeType())) {
refundAmount = this.calcCountRefund(order, totalEle);
} else {
throw new ServiceException("不支持的智能收费方式");
}
BigDecimal refundAmount = this.calcRefundAmount(order, endTime, totalEle);
Integer result = transactionTemplate.execute(status -> {
@ -887,8 +893,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
int update = this.updateByQuery(data, query);
ServiceUtil.assertion(update != 1, "修改订单信息失败");
// 若金额 > 0 则申请退款并清零设备
if (BigDecimal.ZERO.compareTo(refundAmount) < 0) {
// 若金额 > 0.01 则申请退款
if (BigDecimal.valueOf(0.01).compareTo(refundAmount) < 0) {
// 申请退款
BillRefundDTO refundDto = new BillRefundDTO();
refundDto.setBillId(order.getBillId());
@ -896,18 +902,77 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
refundDto.setRefundReason(String.format("充值订单%s智能退款%s元", order.getBillNo(), refundAmount));
int refund = this.refund(refundDto);
ServiceUtil.assertion(refund != 1, "申请退款失败");
// 设备清零时长电量
int clear = deviceService.clearTimeAndEle(device);
ServiceUtil.assertion(clear != 1, "设备清零失败");
}
return update;
});
// 若金额 > 0.01 清零设备
if (BigDecimal.valueOf(0.01).compareTo(refundAmount) < 0) {
try {
// 尝试设备清零时长电量
int clear = deviceService.clearTimeAndEle(device, false);
ServiceUtil.assertion(clear != 1, "设备归零失败");
} catch (Exception e) {
log.warn("设备归零失败");
}
}
return result == null ? 0 : result;
}
@Override
public BigDecimal calcAmount(Long billId, LocalDateTime endTime, BigDecimal totalEle) {
TransactionBillVO bill = selectSmTransactionBillByBillId(billId);
ServiceUtil.assertion(bill == null, "计算金额出错,订单不存在");
if(SuitFeeType.COUNT.getType().equals(bill.getSuitFeeType()) || SuitFeeType.TIMING_COUNT.getType().equals(bill.getSuitFeeType())) {
DeviceVO device = deviceService.selectSmDeviceByDeviceId(bill.getDeviceId());
totalEle = this.calcTotalEle(device, totalEle);
}
BigDecimal totalAmount = BigDecimal.ZERO;
// 智能计费
if (SuitFeeMode.SMART.getMode().equals(bill.getSuitFeeMode())) {
if (SuitFeeType.timingList().contains(bill.getSuitFeeType())) {
// 分时段计费
totalAmount = this.calcTimingAmount(bill, endTime, totalEle);
} else {
// 非分时段计费
BigDecimal refundAmount = this.calcRefundAmount(bill, endTime, totalEle);
totalAmount = bill.getMoney().subtract(refundAmount);
}
}
// 非智能计费
else {
totalAmount = bill.getMoney();
}
return totalAmount;
}
private BigDecimal calcRefundAmount(TransactionBillVO order, LocalDateTime endTime, BigDecimal totalEle) {
// 智能收费时长计费
if (SuitFeeType.TIME.getType().equals(order.getSuitFeeType())) {
return this.calcTimeRefund(order, endTime);
}
// 智能收费计量收费
else if (SuitFeeType.COUNT.getType().equals(order.getSuitFeeType())) {
return this.calcCountRefund(order, totalEle);
} else {
throw new ServiceException("不支持的智能收费方式");
}
}
@Override
public List<TransactionBillVO> selectUnpaidTimingBill(TransactionBillQuery query) {
query.setStatus(TransactionBillStatus.UNPAID.getStatus());
query.setSuitFeeTypes(SuitFeeType.timingList());
query.setSuitFeeMode(SuitFeeMode.SMART.getMode());
return this.selectSmTransactionBillList(query);
}
// 计算智能计量收费需要退款的金额
private BigDecimal calcCountRefund(TransactionBillVO order, BigDecimal totalEle) {
BigDecimal startEle = order.getSuitStartEle();
@ -918,7 +983,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
// 退款金额 = 订单金额 * 未使用的电量 / 套餐总电量
return order.getMoney()
.multiply(noUsedEle)
.divide(totalEle, 2, RoundingMode.HALF_UP);
.divide(suitTotalEle, 2, RoundingMode.HALF_UP);
}
// 计算智能时长收费需要退款的金额
@ -947,7 +1012,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
hours = 1;
}
BigDecimal startEle = order.getSuitStartEle() == null ? BigDecimal.ZERO : order.getSuitStartEle();
BigDecimal avgEle = (totalEle.subtract(startEle)).divide(BigDecimal.valueOf(hours), 2, RoundingMode.HALF_UP);
BigDecimal usedEle = totalEle == null ? BigDecimal.ZERO : totalEle.subtract(startEle);
BigDecimal avgEle = usedEle.divide(BigDecimal.valueOf(hours), 2, RoundingMode.HALF_UP);
// 计算金额
return this.calcTimingTimeAmount(order, endTime).multiply(avgEle);
@ -1288,8 +1354,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
@Override
public List<TransactionBillVO> selectUsingBill(TransactionBillQuery query) {
query.setUsing(true);
query.setStatus(TransactionBillStatus.SUCCESS.getStatus());
query.setIsUsing(true);
query.setStatusList(TransactionBillStatus.asList(TransactionBillStatus.SUCCESS, TransactionBillStatus.SUCCESS_DEPOSIT));
query.setType(TransactionBillType.RECHARGE.getType());
return this.selectSmTransactionBillList(query);
}

View File

@ -6,6 +6,7 @@ import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.channel.domain.ChannelVO;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.model.domain.enums.ModelTag;
@ -85,10 +86,14 @@ public class TransactionBillValidatorImpl extends BaseValidator implements Trans
if (StringUtils.isEmpty(device.getMac())) {
return error("当前设备Mac为空无法充值");
}
// TODO 判断设备是否有正在使用中的智能订单
if (device.getLockUserId() != null && !device.getLockUserId().equals(user.getUserId())) {
return error("该设备正在被他人使用中,无法充值");
// 判断设备是否有正在使用中的智能订单
TransactionBillQuery query = new TransactionBillQuery();
query.setDeviceId(device.getDeviceId());
query.setSuitFeeMode(SuitFeeMode.SMART.getMode());
List<TransactionBillVO> usingBill = transactionBillService.selectUsingBill(query);
if (CollectionUtils.isNotEmptyElement(usingBill)) {
return error("设备有正在使用中的智能订单,暂时无法下单");
}
// 店铺
@ -141,20 +146,16 @@ public class TransactionBillValidatorImpl extends BaseValidator implements Trans
return error("套餐收费方式已发生变化,请重新下单");
}
if (SuitFeeMode.SMART.getMode().equals(suit.getFeeMode())
&& ( (device.getSurplusEle() != null && device.getSurplusEle().compareTo(BigDecimal.ZERO) > 0)
|| (device.getExpireTime() != null && device.getExpireTime().isAfter(LocalDateTime.now()))
)) {
return error("当前设备还有余额,无法选择智能收费方式下单");
if (SuitFeeMode.SMART.getMode().equals(suit.getFeeMode())) {
if (device.getExpireTime() != null && device.getExpireTime().isAfter(LocalDateTime.now())) {
return error("当前设备还有剩余时长,无法选择智能收费方式下单");
}
if (DeviceOnlineStatus.ONLINE.getStatus().equals(device.getOnlineStatus())
&& device.getSurplusEle() != null
&& device.getSurplusEle().compareTo(BigDecimal.ZERO) > 0) {
return error("当前设备还有剩余电量,无法选择智能收费方式下单");
}
}
// 价格计算
// Channel channel = bo.getChannel();
// if (channel == null || channel.getEnabled() == null || !channel.getEnabled()) {
// return error("不支持的支付方式");
// }
return success();
}
@ -166,11 +167,10 @@ public class TransactionBillValidatorImpl extends BaseValidator implements Trans
return false;
}
TransactionBillQuery query = new TransactionBillQuery();
query.setType(TransactionBillType.RECHARGE.getType());
query.setUserId(userId);
query.setSuitFeeMode(SuitFeeMode.SMART.getMode());
query.setIsUsing(true);
return transactionBillService.selectSimpleCount(query) > 0;
List<TransactionBillVO> list = transactionBillService.selectUsingBill(query);
return CollectionUtils.isNotEmptyElement(list);
}
/**

View File

@ -33,6 +33,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@ -50,7 +51,7 @@ import java.util.Objects;
public class AppTransactionBillController extends BaseController
{
@Autowired
private TransactionBillService smTransactionBillService;
private TransactionBillService transactionBillService;
@Autowired
private TransactionAssembler transactionAssembler;
@ -63,8 +64,6 @@ public class AppTransactionBillController extends BaseController
@Autowired
private TransactionBillConverter transactionBillConverter;
@Autowired
private TransactionBillServiceImpl transactionBillService;
/**
* 查询充值记录列表
@ -77,7 +76,7 @@ public class AppTransactionBillController extends BaseController
smTransactionBill.setUserId(getUserId());
smTransactionBill.setType(TransactionBillType.RECHARGE.getType());
startPage();
List<TransactionBillVO> list = smTransactionBillService.selectSmTransactionBillList(smTransactionBill);
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(smTransactionBill);
transactionAssembler.assembleChannelName(list);
return getDataTable(list);
}
@ -92,7 +91,7 @@ public class AppTransactionBillController extends BaseController
startPage();
smTransactionBill.setUserId(getUserId());
smTransactionBill.setType(TransactionBillType.WITHDRAW.getType());
List<TransactionBillVO> list = smTransactionBillService.selectSmTransactionBillList(smTransactionBill);
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(smTransactionBill);
return getDataTable(list);
}
@ -107,7 +106,7 @@ public class AppTransactionBillController extends BaseController
{
startPage();
smTransactionBill.setUserId(getUserId());
List<TransactionBillVO> list = smTransactionBillService.selectSmTransactionBillList(smTransactionBill);
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(smTransactionBill);
transactionAssembler.assembleChannelName(list);
return getDataTable(list);
}
@ -120,7 +119,7 @@ public class AppTransactionBillController extends BaseController
startPage();
query.setMchId(getUserId());
query.setType(TransactionBillType.RECHARGE.getType());
List<TransactionBillVO> list = smTransactionBillService.selectSmTransactionBillList(query);
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(query);
transactionAssembler.assembleChannelName(list);
return getDataTable(list);
}
@ -130,7 +129,7 @@ public class AppTransactionBillController extends BaseController
@JsonView(JsonViewProfile.AppUser.class)
public AjaxResult detail(@PathVariable Long billId) {
ServiceUtil.assertion(transactionBillValidator.preGetDetailByApp(billId, getUserId()));
TransactionBillVO bill = smTransactionBillService.selectSmTransactionBillByBillId(billId);
TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillId(billId);
transactionAssembler.assembleChannelName(Collections.singletonList(bill));
return AjaxResult.success(bill);
}
@ -139,7 +138,7 @@ public class AppTransactionBillController extends BaseController
@GetMapping("/byNo/{billNo}")
@JsonView(JsonViewProfile.AppUser.class)
public AjaxResult detail(@PathVariable String billNo) {
TransactionBillVO bill = smTransactionBillService.selectSmTransactionBillByBillNo(billNo);
TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillNo(billNo);
if (!transactionBillValidator.isUser(bill, getUserId())) {
return success();
}
@ -164,12 +163,12 @@ public class AppTransactionBillController extends BaseController
}
dto.setMchId(getUserId());
dto.setStatus(TransactionBillStatus.SUCCESS.getStatus());
AjaxResult ajax = AjaxResult.success(smTransactionBillService.selectLandlordCount(dto));
AjaxResult ajax = AjaxResult.success(transactionBillService.selectLandlordCount(dto));
// 总收入
TransactionBillQuery allQuery = new TransactionBillQuery();
allQuery.setMchId(getUserId());
List<BillCountVo> totalList = smTransactionBillService.selectCount(allQuery);
List<BillCountVo> totalList = transactionBillService.selectCount(allQuery);
if (CollectionUtils.isEmpty(totalList)) {
ajax.put("totalRecharge", 0);
} else {
@ -183,7 +182,7 @@ public class AppTransactionBillController extends BaseController
@ApiOperation("创建订单")
@PostMapping("/recharge")
public AjaxResult addRecharge(@RequestBody @Validated RechargeDTO dto) {
return AjaxResult.success("操作成功", smTransactionBillService.addOrder(transactionBillConverter.toRechargeBO(dto)));
return AjaxResult.success("操作成功", transactionBillService.addOrder(transactionBillConverter.toRechargeBO(dto)));
}
@ApiOperation("取消充值订单")
@ -193,7 +192,7 @@ public class AppTransactionBillController extends BaseController
if (!transactionBillValidator.isMch(bill, getUserId())) {
return error("这不是您的订单,无法取消");
}
return AjaxResult.success(smTransactionBillService.cancelRecharge(billNo, TransactionBillStatus.CANCELED));
return AjaxResult.success(transactionBillService.cancelRecharge(billNo, TransactionBillStatus.CANCELED));
}
// @MchRequired
@ -201,13 +200,13 @@ public class AppTransactionBillController extends BaseController
@PostMapping("/withdraw")
public AjaxResult withdraw(@RequestBody @Validated WithdrawDTO dto) {
dto.setUserId(getUserId());
return AjaxResult.success("操作成功", smTransactionBillService.addWithdraw(transactionBillConverter.toWithdrawBO(dto)));
return AjaxResult.success("操作成功", transactionBillService.addWithdraw(transactionBillConverter.toWithdrawBO(dto)));
}
@ApiOperation("查询设备充值失败列表")
@GetMapping("/recharge/device/fail/list")
public AjaxResult selectDeviceRechargeFailList() {
return AjaxResult.success(smTransactionBillService.selectDeviceRechargeFailList(getUserId()));
return AjaxResult.success(transactionBillService.selectDeviceRechargeFailList(getUserId()));
}
// @MchRequired
@ -221,20 +220,20 @@ public class AppTransactionBillController extends BaseController
query.setType(TransactionBillType.RECHARGE.getType());
query.setStatus(TransactionBillStatus.SUCCESS.getStatus());
startPage();
return getDataTable(smTransactionBillService.selectSmTransactionBillList(query));
return getDataTable(transactionBillService.selectSmTransactionBillList(query));
}
@ApiOperation("蓝牙充值成功回调")
@GetMapping("/recharge/{billNo}/bluetoothSuccess")
public AjaxResult bluetoothRechargeSuccess(@PathVariable String billNo) {
return success(smTransactionBillService.bluetoothRechargeSuccess(billNo));
return success(transactionBillService.bluetoothRechargeSuccess(billNo));
}
@ApiOperation("订单退款")
@PutMapping("/refund")
public AjaxResult refund(@RequestBody @Validated BillRefundDTO dto) {
// 判断用户是否订单收款人
TransactionBillVO bill = smTransactionBillService.selectSmTransactionBillByBillId(dto.getBillId());
TransactionBillVO bill = transactionBillService.selectSmTransactionBillByBillId(dto.getBillId());
if (bill == null) {
return error("订单不存在");
}
@ -246,25 +245,25 @@ public class AppTransactionBillController extends BaseController
dto.setUserType(loginUser.getLoginType().getType());
dto.setUserId(getUserId());
dto.setRefundReason(String.format("充值订单%s退款", bill.getBillNo()));
return toAjax(smTransactionBillService.refund(dto));
return toAjax(transactionBillService.refund(dto));
}
@ApiOperation("刷新支付结果")
@PutMapping("/{billNo}/refreshPayResult")
public AjaxResult refreshPayResult(@PathVariable String billNo ) {
return toAjax(smTransactionBillService.refreshPayResult(billNo));
return toAjax(transactionBillService.refreshPayResult(billNo));
}
@ApiOperation("获取用户提现手续费")
@GetMapping("/getWithdrawService")
public AjaxResult getWithdrawService(@RequestParam @ApiParam("渠道ID") Long channelId) {
return success(smTransactionBillService.getUserWithdrawService(getUserId(), channelId));
return success(transactionBillService.getUserWithdrawService(getUserId(), channelId));
}
@ApiOperation("支付押金")
@PutMapping("/payDeposit")
public AjaxResult payDeposit(@RequestBody @Validated PayDepositDTO dto) {
return success(smTransactionBillService.payDeposit(transactionBillConverter.toRechargePayDepositBO(dto)));
return success(transactionBillService.payDeposit(transactionBillConverter.toRechargePayDepositBO(dto)));
}
@ApiOperation("结束使用分时段订单")
@ -274,7 +273,7 @@ public class AppTransactionBillController extends BaseController
if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) {
return error("您不是该订单的用户或商户,无法结束订单");
}
return toAjax(smTransactionBillService.endTimingUse(bo));
return toAjax(transactionBillService.endTimingUse(bo));
}
@ApiOperation("提前结束使用智能订单")
@ -284,14 +283,28 @@ public class AppTransactionBillController extends BaseController
if (!transactionBillValidator.isUser(bo.getOrder(), getUserId()) && !transactionBillValidator.isMch(bo.getOrder(), getUserId())) {
return error("您不是该订单的用户或商户,无法结束订单");
}
return toAjax(smTransactionBillService.endSmartUse(bo));
return toAjax(transactionBillService.endSmartUse(bo));
}
@ApiOperation("获取分时段订单预估金额")
@GetMapping("/{}/calcPrice")
public AjaxResult calcPrice() {
return success();
@ApiOperation("获取订单预估金额")
@GetMapping("/calcPrice")
public AjaxResult calcPrice(@RequestParam Long billId, @RequestParam(required = false) BigDecimal totalEle) {
return success(transactionBillService.calcAmount(billId, LocalDateTime.now(), totalEle));
}
@ApiOperation("获取本人使用中的订单列表")
@GetMapping("/usingList")
@JsonView(JsonViewProfile.App.class)
public AjaxResult getUsingList(TransactionBillQuery query) {
query.setUserId(getUserId());
return success(transactionBillService.selectUsingBill(query));
}
@ApiOperation("获取本人未支付的分时段订单列表")
@GetMapping("/unpaidTimingList")
@JsonView(JsonViewProfile.App.class)
public AjaxResult getUnpaidTimingList(TransactionBillQuery query) {
query.setUserId(getUserId());
return success(transactionBillService.selectUnpaidTimingBill(query));
}
}

View File

@ -2,6 +2,8 @@ package com.ruoyi.web.controller.ss;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -104,4 +106,17 @@ public class PayBillController extends BaseController
{
return toAjax(payBillService.deletePayBillByPayIds(payIds));
}
/**
* 退款
*/
@PreAuthorize("@ss.hasPermi('ss:payBill:refund')")
@Log(title = "支付订单退款", businessType = BusinessType.OTHER)
@PutMapping("/refund")
public AjaxResult refund(@RequestBody PayBillRefundDTO dto)
{
return toAjax(payBillService.refund(dto));
}
}

View File

@ -152,12 +152,19 @@ public class SmDeviceController extends BaseController
@ApiOperation("设备时长归零")
@PreAuthorize("@ss.hasPermi('system:device:reset')")
@Log(title = "设备", businessType = BusinessType.OTHER)
@Log(title = "设备时长归零", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/reset")
public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) {
return success(deviceService.resetTimeWithBill(deviceId));
}
@PreAuthorize("@ss.hasPermi('system:device:resetEle')")
@Log(title = "设备清空电量", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/resetEle")
public AjaxResult resetEle(@PathVariable @ApiParam("设备id") Long deviceId) {
return toAjax(deviceService.resetEle(deviceId, true));
}
@ApiOperation("设备开关")
@PreAuthorize("@ss.hasPermi('system:device:switch')")
@Log(title = "设备", businessType = BusinessType.OTHER)
@ -189,4 +196,5 @@ public class SmDeviceController extends BaseController
public AjaxResult updateServiceRate(@RequestBody @Validated DeviceVO data) {
return toAjax(deviceService.updateServiceRate(data));
}
}