套餐低功率关闭

This commit is contained in:
墨大叔 2024-09-19 16:10:04 +08:00
parent e8d8f01bc4
commit c9859e4b78
25 changed files with 285 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package com.ruoyi.common.pay.syb.service;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.pay.syb.config.SybConfig;
import com.ruoyi.common.pay.syb.enums.SybTrxStatus;
import com.ruoyi.common.pay.syb.util.SybUtil;
import com.ruoyi.common.pay.wx.domain.Payable;
import com.ruoyi.common.pay.wx.domain.RefundAble;
@ -58,9 +59,13 @@ public class SybPayService {
);
if (result != null) {
String payInfo = result.get("payinfo");
if (StringUtils.hasText(payInfo)) {
return JSON.parseObject(payInfo, PrepayWithRequestPaymentResponse.class);
if (SybTrxStatus.isSuccess(result)) {
String payInfo = result.get("payinfo");
if (StringUtils.hasText(payInfo)) {
return JSON.parseObject(payInfo, PrepayWithRequestPaymentResponse.class);
}
} else {
throw new ServiceException(result.get("errmsg"));
}
}
throw new ServiceException("支付数据为空");

View File

@ -20,7 +20,8 @@ public enum ConfigKey {
DAILY_WITHDRAW_AMOUNT("daily.withdraw.amount", "单日单用户提现限额(元)"),
DAILY_WITHDRAW_COUNT("daily.withdraw.count", "单日单用户提现次数(次)"),
NOVERIFY_WITHDRAW_SINGLE("noverify.withdraw.single", "提现单笔免审核额度(元)"),
RECHARGE_MIN_SERVICE("recharge.min.service","充值最低服务费(元)");
RECHARGE_MIN_SERVICE("recharge.min.service","充值最低服务费(元)"),
ORDER_AUTO_CLOSE_CD("order.auto.close.cd", "订单自动关闭冷却时间(分)");
private final String key;
private final String msg;

View File

@ -103,8 +103,13 @@ public interface ISysConfigService
*/
boolean getBoolean(ConfigKey key);
/**
* 获取int类型配置
*/
int getInt(ConfigKey key);
List<SysConfig> selectByIds(List<Long> configIds);
int batchUpdateValue(List<SysConfig> list);
}

View File

@ -10,6 +10,7 @@ import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.system.domain.dto.SysConfigQuery;
import com.ruoyi.system.domain.enums.config.ConfigKey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.annotation.DataSource;
@ -31,6 +32,7 @@ import org.springframework.transaction.support.TransactionTemplate;
* @author ruoyi
*/
@Service
@Slf4j
public class SysConfigServiceImpl implements ISysConfigService
{
@Autowired
@ -244,6 +246,20 @@ public class SysConfigServiceImpl implements ISysConfigService
return "true".equals(selectConfigByKey(key.getKey()));
}
@Override
public int getInt(ConfigKey key) {
String s = selectConfigByKey(key.getKey());
try {
if (StringUtils.hasText(s)) {
return Integer.parseInt(s);
}
return 0;
} catch (Exception e) {
log.warn("获取配置{}值失败:{}", key.getKey(), e.getMessage());
return 0;
}
}
@Override
public List<SysConfig> selectByIds(List<Long> configIds) {
if (CollectionUtils.isEmptyElement(configIds)) {

View File

@ -24,7 +24,7 @@ public class IotDeviceInfo {
private Date at; // 时间
private BigDecimal v; // 电压
private BigDecimal p; // 功率
private BigDecimal p; // 功率
private BigDecimal a; // 电流
private BigDecimal w; // 总用电量
private String s; // 开关状态0不通电1闭合通电

View File

@ -30,6 +30,7 @@ import com.ruoyi.ss.deviceBindRecord.service.ISmDeviceBindRecordService;
import com.ruoyi.ss.deviceSuit.service.DeviceSuitConverter;
import com.ruoyi.ss.deviceSuit.service.DeviceSuitService;
import com.ruoyi.ss.model.domain.SmModelVO;
import com.ruoyi.ss.model.domain.enums.ModelTag;
import com.ruoyi.ss.model.service.ModelService;
import com.ruoyi.ss.record.time.domain.enums.RecordTimeType;
import com.ruoyi.ss.record.time.service.IRecordTimeService;
@ -735,17 +736,27 @@ public class DeviceServiceImpl implements DeviceService
data.setTotalElectriQuantity(deviceInfo.getW());
data.setPowerStatus(deviceInfo.getS());
data.setRemainTime(deviceInfo.getTime());
data.setWifi(deviceInfo.getWifi());
data.setSurplusEle(deviceInfo.getM());
// 是否有WIFI
if (ModelTag.hasTag(device.getModelTags(), ModelTag.WIFI)) {
data.setWifi(deviceInfo.getWifi());
}
// 是否有电量
if (ModelTag.hasTag(device.getModelTags(), ModelTag.ELE)) {
data.setSurplusEle(deviceInfo.getM());
} else {
data.setSurplusEle(BigDecimal.ZERO);
}
}
// 判断设备是否正在使用
// 时长优先级最高若当前设备过期时间 > 当前时间则正在使用
// 设备过期时间 > 当前时间则正在使用
boolean hasTime = device.getExpireTime().isAfter(now);
// 若当前设备有电量则正在使用
boolean hasEle = device.getSurplusEle().compareTo(BigDecimal.ZERO) > 0;
boolean hasEle = data.getSurplusEle().compareTo(BigDecimal.ZERO) > 0;
// 若开关开启则正在使用
boolean hasOpen = DevicePowerStatus.ON.getStatus().equals(device.getPowerStatus());
boolean hasOpen = DevicePowerStatus.ON.getStatus().equals(data.getPowerStatus());
if (hasTime || hasEle || hasOpen) {
data.setStatus(DeviceStatus.USING.getStatus());
} else {

View File

@ -20,7 +20,8 @@ public enum ModelTag {
BLUETOOTH("1", "蓝牙"),
WIFI("2", "WIFI"),
FOUR_G("3", "4G"),
GPS("4", "GPS");
GPS("4", "GPS"),
ELE("5", "电量");
private final String tag;
private final String msg;
@ -37,4 +38,13 @@ public enum ModelTag {
public static boolean contains(List<String> tags) {
return new HashSet<>(Arrays.stream(ModelTag.values()).map(ModelTag::getTag).collect(Collectors.toList())).containsAll(tags);
}
// 判断列表中是否包含目标标签
public static boolean hasAllTag(List<String> tags, ModelTag ...modelTags) {
return new HashSet<>(Arrays.stream(modelTags).map(ModelTag::getTag).collect(Collectors.toList())).containsAll(tags);
}
public static boolean hasTag(List<String> modelTags, ModelTag modelTag) {
return modelTags.contains(modelTag.getTag());
}
}

View File

@ -28,4 +28,7 @@ public class PayBillQuery extends PayBill{
@ApiModelProperty("创建时间(结束)")
private LocalDateTime endCreateTime;
@ApiModelProperty("支付订单ID列表")
private List<Long> payIds;
}

View File

@ -43,6 +43,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item}
</foreach>
</if>
<if test="query.payIds != null and query.payIds.size() > 0">
and spb.pay_id in
<foreach item="item" index="index" collection="query.payIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</sql>
<select id="selectPayBillList" parameterType="PayBillQuery" resultMap="PayBillResult">

View File

@ -194,6 +194,13 @@ public class PayBillServiceImpl implements PayBillService
PayBillQuery query = new PayBillQuery();
query.setBstId(bstId);
query.setBstType(bstType);
return this.closePayBill(query);
}
private boolean closePayBill(PayBillQuery query) {
if (query == null) {
query = new PayBillQuery();
}
query.setStatusList(PayBillStatus.getCanCancelList());
List<PayBillVO> payingList = this.selectPayBillList(query);
if (CollectionUtils.isEmpty(payingList)) {
@ -205,7 +212,10 @@ public class PayBillServiceImpl implements PayBillService
// 修改状态
PayBill closeData = new PayBillVO();
closeData.setStatus(PayBillStatus.CANCEL.getStatus());
int update = this.updateByQuery(closeData, query);
PayBillQuery updateQuery = new PayBillQuery();
updateQuery.setStatusList(PayBillStatus.getCanCancelList());
updateQuery.setPayIds(CollectionUtils.map(payingList, PayBillVO::getPayId));
int update = this.updateByQuery(closeData, updateQuery);
ServiceUtil.assertion(update != payingList.size(), "修改订单状态失败");
// 关闭订单
@ -430,10 +440,12 @@ public class PayBillServiceImpl implements PayBillService
@Override
public void refreshPayResultMaxCount(PayBillVO pay, long delay, TimeUnit timeUnit, int count) {
if (count <= 0) {
if (pay == null) {
return;
}
if (pay == null) {
if (count <= 0) {
this.closeById(pay.getPayId());
return;
}
@ -456,6 +468,16 @@ public class PayBillServiceImpl implements PayBillService
}
}
private boolean closeById(Long payId) {
if (payId == null) {
return false;
}
// 查询未支付支付中的订单
PayBillQuery query = new PayBillQuery();
query.setPayId(payId);
return this.closePayBill(query);
}
/**
* 获取支付结果
*/

View File

@ -45,7 +45,7 @@ public class RefundConverterImpl implements RefundConverter {
// 按比例计算退款金额
String refundReason = dto.getRefundReason();
if (StringUtils.isBlank(refundReason)) {
refundReason = String.format("支付订单%s退款", payBill.getPayNo());
refundReason = String.format("支付订单退款:%s", payBill.getPayNo());
}
Refund refund = new Refund();

View File

@ -101,4 +101,14 @@ public class Suit extends BaseEntity
@AllowSize(sizes = {0, 24}, message = "时段档位必须填入24个")
private List<Integer> gearTime;
@Excel(name = "是否开启低功率关闭订单")
@ApiModelProperty("是否开启低功率关闭订单")
@JsonView(JsonViewProfile.App.class)
private Boolean enabledLowPowerClose;
@Excel(name = "低功率关闭订单的功率值(瓦)")
@ApiModelProperty("低功率关闭订单的功率值")
@Min(value = 0, message = "低功率关闭订单的功率值不允许小于0")
@JsonView(JsonViewProfile.App.class)
private BigDecimal lowPower;
}

View File

@ -33,6 +33,8 @@ public class SuitBO extends Suit {
bo.setFeeType(getFeeType());
bo.setGearAmount(getGearAmount());
bo.setGearTime(getGearTime());
bo.setEnabledLowPowerClose(getEnabledLowPowerClose());
bo.setLowPower(getLowPower());
return bo;
}
@ -53,6 +55,8 @@ public class SuitBO extends Suit {
bo.setFeeType(getFeeType());
bo.setGearAmount(getGearAmount());
bo.setGearTime(getGearTime());
bo.setEnabledLowPowerClose(getEnabledLowPowerClose());
bo.setLowPower(getLowPower());
return bo;
}
}

View File

@ -28,6 +28,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ss.fee_type,
ss.gear_amount,
ss.gear_time,
ss.enabled_low_power_close,
ss.low_power,
su.user_name as user_name
from <include refid="searchTables"/>
</sql>
@ -48,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="userId != null"> and ss.user_id = #{userId}</if>
<if test="feeMode != null and feeMode != ''"> and fee_mode = #{feeMode}</if>
<if test="feeType != null and feeType != ''"> and fee_type = #{feeType}</if>
<if test="enabledLowPowerClose != null "> and enabled_low_power_close = #{enabledLowPowerClose}</if>
<if test="deviceId != null">
and ss.suit_id in (
select distinct sds.suit_id from ss_device_suit sds where sds.device_id = #{deviceId}
@ -120,6 +123,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="feeType != null and feeType != ''">fee_type,</if>
<if test="gearAmount != null">gear_amount,</if>
<if test="gearTime != null">gear_time,</if>
<if test="enabledLowPowerClose != null">enabled_low_power_close,</if>
<if test="lowPower != null">low_power,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
@ -138,6 +143,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="feeType != null and feeType != ''">#{feeType},</if>
<if test="gearAmount != null">#{gearAmount,typeHandler=com.ruoyi.system.mapper.typehandler.DecimalSplitListTypeHandler},</if>
<if test="gearTime != null">#{gearTime,typeHandler=com.ruoyi.system.mapper.typehandler.IntegerSplitListTypeHandler},</if>
<if test="enabledLowPowerClose != null">#{enabledLowPowerClose},</if>
<if test="lowPower != null">#{lowPower},</if>
</trim>
</insert>
@ -163,6 +170,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="feeType != null and feeType != ''">fee_type = #{feeType},</if>
<if test="gearAmount != null">gear_amount = #{gearAmount,typeHandler=com.ruoyi.system.mapper.typehandler.DecimalSplitListTypeHandler},</if>
<if test="gearTime != null">gear_time = #{gearTime,typeHandler=com.ruoyi.system.mapper.typehandler.IntegerSplitListTypeHandler},</if>
<if test="enabledLowPowerClose != null">enabled_low_power_close = #{enabledLowPowerClose},</if>
<if test="lowPower != null">low_power = #{lowPower},</if>
</sql>
<update id="logicDel">

View File

@ -2,6 +2,7 @@ package com.ruoyi.ss.suit.service;
import com.ruoyi.common.core.domain.ValidateResult;
import com.ruoyi.ss.suit.domain.SuitBO;
import com.ruoyi.ss.suit.domain.SuitVO;
import java.util.Collection;
import java.util.List;
@ -43,4 +44,9 @@ public interface SuitValidator {
* 创建更新公共校验
*/
ValidateResult preCreateOrUpdate(SuitBO suit);
/**
* 后校验
*/
void afterCheck(SuitVO vo, SuitVO old);
}

View File

@ -14,6 +14,7 @@ import com.ruoyi.ss.suit.domain.SuitVO;
import com.ruoyi.ss.suit.mapper.SuitMapper;
import com.ruoyi.ss.suit.service.SuitConverter;
import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.suit.service.SuitValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;
@ -49,6 +50,9 @@ public class SuitServiceImpl implements SuitService
@Autowired
private DeviceSuitConverter deviceSuitConverter;
@Autowired
private SuitValidator suitValidator;
/**
* 查询套餐
*
@ -85,12 +89,18 @@ public class SuitServiceImpl implements SuitService
this.preInsert(suit);
Integer result = transactionTemplate.execute(status -> {
// 新增
int insert = suitMapper.insertSuit(suit);
ServiceUtil.assertion(insert != 1, "新增套餐失败");
// 新增关联
int batchInsert = deviceSuitService.batchInsert(deviceSuitConverter.toPo(suit));
ServiceUtil.assertion(batchInsert != suit.getDeviceIds().size(), "新增关联失败");
// 后校验
SuitVO vo = selectSuitBySuitId(suit.getSuitId());
suitValidator.afterCheck(vo, null);
return insert;
});
@ -137,6 +147,10 @@ public class SuitServiceImpl implements SuitService
deviceSuitService.batchInsert(deviceSuitConverter.toPo(suit));
}
// 后校验
SuitVO vo = selectSuitBySuitId(suit.getSuitId());
suitValidator.afterCheck(vo, old);
return update;
});

View File

@ -2,6 +2,7 @@ package com.ruoyi.ss.suit.service.impl;
import com.ruoyi.common.core.domain.BaseValidator;
import com.ruoyi.common.core.domain.ValidateResult;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
@ -180,4 +181,11 @@ public class SuitValidatorImpl extends BaseValidator implements SuitValidator {
return success();
}
@Override
public void afterCheck(SuitVO vo, SuitVO old) {
ServiceUtil.assertion (vo.getEnabledLowPowerClose() != null && vo.getEnabledLowPowerClose() && vo.getLowPower() == null, "最低功率阈值不允许为空");
}
}

View File

@ -249,6 +249,18 @@ public class TransactionBill extends BaseEntity implements Payable
@ApiModelProperty("支付成功的支付订单ID")
private Long payId;
@Excel(name = "订单是否开启低功率自动关闭")
@ApiModelProperty("订单是否开启低功率自动关闭")
private Boolean suitEnableLowPowerClose;
@Excel(name = "订单低功率自动关闭值", readConverterExp = "瓦=")
@ApiModelProperty("订单低功率自动关闭值")
private BigDecimal suitLowPower;
@Excel(name = "设备产品ID")
@ApiModelProperty("设备产品ID")
private String deviceProductId;
/**
* 获取价格
*/

View File

@ -120,4 +120,8 @@ public class TransactionBillQuery extends TransactionBill {
@ApiModelProperty("渠道ID列表")
private List<Long> channelIds;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间(结束)")
private LocalDateTime createTimeEnd;
}

View File

@ -61,6 +61,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
stb.offline_image,
stb.deposit_pay_id,
stb.pay_id,
stb.suit_enable_low_power_close,
stb.suit_low_power,
stb.device_product_id,
</sql>
<sql id="selectSmTransactionBillVo">
@ -170,8 +173,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="query.money != null"> and stb.money = #{query.money}</if>
<if test="query.deviceNo != null and query.deviceNo != ''"> and sd.device_no like concat('%', #{query.deviceNo}, '%')</if>
<if test="query.userMobile != null and query.userMobile != ''"> and su.phonenumber like concat('%', #{query.userMobile}, '%')</if>
<if test="query.suitFeeMode != null and query.suitFeeMode != ''"> and suit_fee_mode = #{query.suitFeeMode}</if>
<if test="query.suitFeeType != null and query.suitFeeType != ''"> and suit_fee_type = #{query.suitFeeType}</if>
<if test="query.suitFeeMode != null and query.suitFeeMode != ''"> and stb.suit_fee_mode = #{query.suitFeeMode}</if>
<if test="query.suitFeeType != null and query.suitFeeType != ''"> and stb.suit_fee_type = #{query.suitFeeType}</if>
<if test="query.suitEnableLowPowerClose != null "> and stb.suit_enable_low_power_close = #{query.suitEnableLowPowerClose}</if>
<if test="query.createTimeEnd != null "> and stb.create_time &lt;= #{query.createTimeEnd}</if>
<if test="query.deviceProductId != null and query.deviceProductId != ''"> and device_product_id = #{query.deviceProductId}</if>
<if test="query.isUsing != null">
<if test="query.isUsing">
and <include refid="isUsing"/>
@ -435,6 +441,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="offlineImage != null">offline_image,</if>
<if test="depositPayId != null">deposit_pay_id,</if>
<if test="payId != null">pay_id,</if>
<if test="suitEnableLowPowerClose != null">suit_enable_low_power_close,</if>
<if test="suitLowPower != null">suit_low_power,</if>
<if test="deviceProductId != null">device_product_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="billNo != null">#{billNo},</if>
@ -485,6 +494,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="offlineImage != null">#{offlineImage},</if>
<if test="depositPayId != null">#{depositPayId},</if>
<if test="payId != null">#{payId},</if>
<if test="suitEnableLowPowerClose != null">#{suitEnableLowPowerClose},</if>
<if test="suitLowPower != null">#{suitLowPower},</if>
<if test="deviceProductId != null">#{deviceProductId},</if>
</trim>
</insert>
@ -553,6 +565,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="data.offlineImage != null">stb.offline_image = #{data.offlineImage},</if>
<if test="data.depositPayId != null">stb.deposit_pay_id = #{data.depositPayId},</if>
<if test="data.payId != null">stb.pay_id = #{data.payId},</if>
<if test="data.suitEnableLowPowerClose != null">suit_enable_low_power_close = #{data.suitEnableLowPowerClose},</if>
<if test="data.suitLowPower != null">suit_low_power = #{data.suitLowPower},</if>
<if test="data.deviceProductId != null">device_product_id = #{data.deviceProductId},</if>
</sql>
<update id="updateByQuery">

View File

@ -6,6 +6,7 @@ import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
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.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;
@ -282,6 +283,11 @@ public interface TransactionBillService
*/
int endUse(EndUseBO bo, boolean withDevice);
/**
* 结束使用订单
*/
int endUse(EndUseDTO dto, boolean withDevice);
/**
* 查询所有关于金额的总和
*/

View File

@ -374,6 +374,8 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
order.setSuitGearAmount(suit.getGearAmount());
order.setSuitGearTime(suit.getGearTime());
order.setSuitName(suit.getName());
order.setSuitEnableLowPowerClose(suit.getEnabledLowPowerClose());
order.setSuitLowPower(suit.getLowPower());
// 设备信息
order.setDeviceNo(dto.getDeviceNo());
@ -381,6 +383,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
order.setMchId(mch.getUserId());
order.setDeviceName(device.getDeviceName());
order.setDeviceMac(device.getMac());
order.setDeviceProductId(device.getModelProductId());
// 店铺信息
if (store != null) {
@ -1585,6 +1588,12 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return 0;
}
@Override
public int endUse(EndUseDTO dto, boolean withDevice) {
EndUseBO bo = transactionBillConverter.toEndUseBO(dto);
return this.endUse(bo, withDevice);
}
@Override
public <T> List<TransactionAmountVO<T>> selectCommonSumOfMoney(TransactionBillQuery query, String groupBy) {
return transactionBillMapper.selectCommonSumOfMoney(query, groupBy);

View File

@ -0,0 +1,90 @@
package com.ruoyi.task.bill;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.iot.domain.IotDeviceInfo;
import com.ruoyi.iot.service.IotService;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.bo.EndUseBO;
import com.ruoyi.ss.transactionBill.domain.dto.EndUseDTO;
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.system.domain.SysConfig;
import com.ruoyi.system.domain.enums.config.ConfigKey;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author wjh
* 2024/9/19
*/
@Component
@Slf4j
public class BillLowPowerTask {
@Autowired
private TransactionBillService transactionBillService;
@Autowired
private ISysConfigService sysConfigService;
@Autowired
private IotService iotService;
/**
* 关闭低功率的订单
*/
public void autoClose() {
// 获取关闭冷却时间
int cd = sysConfigService.getInt(ConfigKey.ORDER_AUTO_CLOSE_CD);
LocalDateTime createTimeEnd = LocalDateTime.now().minusMinutes(cd); // 获取冷却时间之前的时间
// 获取开启了低功率关闭且未结束的订单
TransactionBillQuery query = new TransactionBillQuery();
query.setSuitEnableLowPowerClose(true);
query.setType(TransactionBillType.RECHARGE.getType());
query.setStatusList(TransactionBillStatus.canClose());
query.setCreateTimeEnd(createTimeEnd);
query.setIsFinished(false);
List<TransactionBillVO> list = transactionBillService.selectSmTransactionBillList(query);
// 从OneNet获取设备信息
if (CollectionUtils.isEmptyElement(list)) {
log.info("无低功率订单");
return;
}
for (TransactionBillVO bill : list) {
if (bill.getSuitLowPower() == null) {
log.warn("关闭低功率订单时,订单最低功率值为空:{}", bill.getBillNo());
continue;
}
try {
// 判断设备是否在线
DeviceOnlineStatus online = iotService.getOnlineStatus(bill.getDeviceMac(), bill.getDeviceProductId());
if (!DeviceOnlineStatus.ONLINE.equals(online)) {
log.warn("关闭低功率订单{}时,设备未在线", bill.getBillNo());
continue;
}
IotDeviceInfo deviceInfo = iotService.getDeviceInfo(bill.getDeviceMac(), bill.getDeviceProductId());
// 判断是否低功率若低于指定功率则关闭订单
if (deviceInfo != null && deviceInfo.getP() != null && deviceInfo.getP().compareTo(bill.getSuitLowPower()) < 0) {
EndUseDTO dto = new EndUseDTO();
dto.setBillId(bill.getBillId());
dto.setTotalEle(deviceInfo.getW());
transactionBillService.endUse(dto, true);
}
} catch (Exception e) {
log.warn("关闭低功率订单{}出错:{}", bill.getBillNo(), e.getMessage());
}
}
}
}

View File

@ -253,7 +253,7 @@ public class AppTransactionBillController extends BaseController
dto.setUserName(loginUser.getUsername());
dto.setUserType(loginUser.getLoginType().getType());
dto.setUserId(getUserId());
dto.setRefundReason(String.format("充值订单%s退款", bill.getBillNo()));
dto.setRefundReason(String.format("充值订单退款:%s", bill.getBillNo()));
return toAjax(transactionBillService.refund(dto));
}

View File

@ -180,7 +180,7 @@ public class SmTransactionBillController extends BaseController
dto.setUserName(loginUser.getUsername());
dto.setUserType(loginUser.getLoginType().getType());
dto.setUserId(getUserId());
dto.setRefundReason(String.format("充值订单%s退款", bill.getBillNo()));
dto.setRefundReason(String.format("充值订单退款:%s", bill.getBillNo()));
return toAjax(transactionBillService.refund(dto));
}