细节优化

This commit is contained in:
墨大叔 2024-09-28 17:14:43 +08:00
parent 0983df3a96
commit 16e2ead7e6
19 changed files with 156 additions and 19 deletions

View File

@ -82,6 +82,10 @@ public class IotConstants {
*/
public static final String COMMAND_SET_ELE = "mmney";
public static final String COMMAND_SET_SSID = "ssid";
public static final String COMMAND_SET_PASS = "pass";
/**----------------------------命令end----------------------------*/
}

View File

@ -212,4 +212,9 @@ public class SmUser extends BaseEntity
@Excel(name = "到账延迟时间", readConverterExp = "小=时")
@ApiModelProperty("到账延迟时间")
private Integer arrivalDelay;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "限制退款时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("限制退款时间")
private LocalDateTime limitRefundTime;
}

View File

@ -136,4 +136,13 @@ public interface IotService {
*/
CommandResponse trySetEle(String mac, BigDecimal ele, String productId, int tryCount);
/**
* 设置设备WIFI
* @param device 设备
* @param wifiName WIFI名称
* @param wifiPwd WIFI 密码
*/
CommandResponse setWifi(IotDevice device, String wifiName, String wifiPwd);
CommandResponse setWifi(String mac, String productId, String wifiName, String wifiPwd);
}

View File

@ -28,6 +28,8 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.bouncycastle.oer.its.Duration.seconds;
/**
* @author wjh
* 2024/3/20
@ -423,5 +425,31 @@ public class IotServiceImpl implements IotService {
return res;
}
@Override
public CommandResponse setWifi(IotDevice device, String wifiName, String wifiPwd) {
CommandResponse res = null;
if (StringUtils.hasText(device.iotMac1())) {
res = this.setWifi(device.iotMac1(), device.getProductId(), wifiName, wifiPwd);
}
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
res = this.setWifi(device.iotMac2(), device.getProductId(), wifiName, wifiPwd);
}
return res;
}
@Override
public CommandResponse setWifi(String mac, String productId, String wifiName, String wifiPwd) {
if (StringUtils.hasBlank(mac, productId)) {
return null;
}
CommandResponse res1 = sendCommand(mac, IotConstants.COMMAND_SET_SSID + wifiName + IotConstants.COMMAND_SEPARATOR, productId);
if (res1.isSuccess()) {
return sendCommand(mac, IotConstants.COMMAND_SET_PASS + wifiPwd + IotConstants.COMMAND_SEPARATOR, productId);
}
return null;
}
}

View File

@ -0,0 +1,16 @@
package com.ruoyi.ss.device.domain.dto;
import lombok.Data;
/**
* @author wjh
* 2024/9/28
*/
@Data
public class DeviceWifiDTO {
private Long deviceId;
private String wifiName;
private String wifiPwd;
}

View File

@ -6,6 +6,7 @@ import com.ruoyi.ss.device.domain.DeviceCountVO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO;
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
import com.ruoyi.ss.device.domain.enums.DevicePowerStatus;
import com.ruoyi.ss.device.domain.vo.DeviceMacSnVO;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
@ -348,4 +349,5 @@ public interface DeviceService
*/
int setTime(DeviceVO device, LocalDateTime expireTime, boolean withIot, int tryCount);
int setWifi(DeviceWifiDTO dto);
}

View File

@ -150,7 +150,7 @@ public class DeviceAssemblerImpl implements DeviceAssembler {
} else if (device.getUserServiceRate() != null) {
device.setRealServiceRate(device.getUserServiceRate());
} else {
ServiceUtil.assertion(sysServiceRate != null, "系统服务费率未配置,请联系管理员");
ServiceUtil.assertion(sysServiceRate == null, "系统服务费率未配置,请联系管理员");
device.setRealServiceRate(sysServiceRate);
}
}

View File

@ -5,6 +5,7 @@ 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.LoginType;
import com.ruoyi.common.enums.UserType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.*;
import com.ruoyi.common.utils.collection.CollectionUtils;
@ -18,6 +19,7 @@ import com.ruoyi.ss.device.domain.DeviceCountVO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO;
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
import com.ruoyi.ss.device.domain.enums.DevicePowerStatus;
import com.ruoyi.ss.device.domain.enums.DeviceStatus;
@ -346,8 +348,10 @@ public class DeviceServiceImpl implements DeviceService
if (ModelTag.isTwoMac(model.getTags())) {
if (device.getMac().endsWith(FOUR_G_MAC)) {
device.setMac2(StringUtils.replaceLast(device.getMac(), FOUR_G_MAC, WIFI_MAC));
} else if (device.getMac().endsWith(WIFI_MAC)) {
device.setMac2(StringUtils.replaceLast(device.getMac(), WIFI_MAC, FOUR_G_MAC));
} else {
// 替换最后两位为4G MAC
String substring = device.getMac().substring(0, device.getMac().length() - 2);
device.setMac2(substring + FOUR_G_MAC);
}
}
@ -591,6 +595,18 @@ public class DeviceServiceImpl implements DeviceService
return 0;
}
@Override
public int setWifi(DeviceWifiDTO dto) {
DeviceVO device = selectSmDeviceByDeviceId(dto.getDeviceId());
if (device == null) {
return 0;
}
CommandResponse res = iotService.setWifi(device, dto.getWifiName(), dto.getWifiPwd());
ServiceUtil.assertion(!res.isSuccess(), "设置WIFI失败" + res.getMsg());
return 1;
}
@Override
public boolean addTime(Long deviceId, long seconds, boolean withIot) {
@ -928,8 +944,8 @@ public class DeviceServiceImpl implements DeviceService
ServiceUtil.assertion(record != 1, "添加绑定记录失败");
// 用户设置为商户
// boolean changeType = userService.changeType(userId, UserType.MCH);
// ServiceUtil.assertion(record != 1, "修改用户类型失败");
int changeType = userService.changeType(userId, UserType.MCH);
ServiceUtil.assertion(changeType != 1, "修改用户类型失败");
return updateCount;
});

View File

@ -46,4 +46,7 @@ public class SmUserVo extends SmUser {
@ApiModelProperty("实际到账延迟")
private Integer realArrivalDelay;
@ApiModelProperty("实际服务费率")
private BigDecimal realServiceRate;
}

View File

@ -55,6 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.agent_service_rate,
su.arrival_delay,
su.type,
su.limit_refund_time,
if(su.is_real, su.real_name, su.user_name) as real_or_user_name,
(select sum(stb.money) from sm_transaction_bill stb where stb.user_id = su.user_id and stb.type = '1' and stb.status = '2') as recharge_amount,
(select sum(stb.arrival_amount) from sm_transaction_bill stb where stb.user_id = su.user_id and stb.type = '2' and stb.status = '14') as with_drawl_amount,
@ -184,6 +185,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="arrivalDelay != null">arrival_delay,</if>
<if test="agentServiceRate != null">agent_service_rate,</if>
<if test="type != null">`type`,</if>
<if test="limitRefundTime != null">limit_refund_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userName != null and userName != ''">#{userName},</if>
@ -227,6 +229,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="arrivalDelay != null">arrival_delay,</if>
<if test="agentServiceRate != null">#{agentServiceRate},</if>
<if test="type != null">#{type},</if>
<if test="limitRefundTime != null">#{limitRefundTime},</if>
</trim>
</insert>
@ -286,6 +289,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="arrivalDelay != null">arrival_delay = #{arrivalDelay},</if>
<if test="agentServiceRate != null">agent_service_rate = #{agentServiceRate},</if>
<if test="type != null">`type` = #{type},</if>
<if test="limitRefundTime != null">limit_refund_time = #{limitRefundTime},</if>
</trim>
where user_id = #{userId}
</update>

View File

@ -97,10 +97,11 @@ public interface ISmUserService
/**
* 更换用户类型
*
* @param userType 类型
* @return
*/
boolean changeType(Long userId, UserType userType);
int changeType(Long userId, UserType userType);
/**
* 增加余额

View File

@ -24,4 +24,9 @@ public interface UserAssembler {
* 拼接用户实际到账延迟
*/
void assembleRealArrivalDelay(List<SmUserVo> userList);
/**
* 拼接用户实际服务费率
*/
void assembleRealServiceRate(List<SmUserVo> list);
}

View File

@ -149,14 +149,12 @@ public class SmUserServiceImpl implements ISmUserService
}
@Override
@Transactional
public boolean changeType(Long userId, UserType userType) {
public int changeType(Long userId, UserType userType) {
// 修改数据库中的数据
SmUser smUser = new SmUser();
smUser.setUserId(userId);
smUserMapper.updateSmUser(smUser);
return true;
smUser.setType(userType.getType());
return smUserMapper.updateSmUser(smUser);
}
@Override

View File

@ -1,5 +1,6 @@
package com.ruoyi.ss.user.service.impl;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.device.domain.DeviceCountVO;
import com.ruoyi.ss.device.domain.DeviceQuery;
@ -14,6 +15,7 @@ import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -98,4 +100,24 @@ public class UserAssemblerImpl implements UserAssembler {
}
}
@Override
public void assembleRealServiceRate(List<SmUserVo> list) {
if (CollectionUtils.isEmptyElement(list)) {
return;
}
BigDecimal sysServiceRate = sysConfigService.getBigDecimal(ConfigKey.SERVICE_FEE_RATE);
for (SmUserVo user : list) {
if (user == null) {
continue;
}
if (user.getServiceRate() != null) {
user.setRealServiceRate(user.getServiceRate());
} else {
ServiceUtil.assertion(sysServiceRate == null, "系统服务费率未配置,请联系管理员");
user.setRealServiceRate(sysServiceRate);
}
}
}
}

View File

@ -11,11 +11,13 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.OperatorType;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.iot.service.IotService;
import com.ruoyi.ss.device.domain.DeviceView;
import com.ruoyi.ss.device.domain.Device;
import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO;
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
import com.ruoyi.ss.device.domain.enums.DevicePowerStatus;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
@ -59,6 +61,9 @@ public class AppDeviceController extends BaseController {
@Autowired
private DeviceValidator deviceValidator;
@Autowired
private IotService iotService;
@Log(title = "商户修改设备信息", businessType = BusinessType.UPDATE, operatorType = OperatorType.MOBILE)
@ApiOperation("商户修改设备信息")
@PutMapping
@ -245,4 +250,11 @@ public class AppDeviceController extends BaseController {
return success(smDeviceService.selectUsingDevice(getUserId()));
}
@ApiOperation("设置设备WIFI密码")
@PutMapping("/setWifi")
public AjaxResult setWifi(@RequestBody DeviceWifiDTO dto) {
return toAjax(smDeviceService.setWifi(dto));
}
}

View File

@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.ss.dashboard.vo.BillCountVo;
@ -245,10 +246,19 @@ public class AppTransactionBillController extends BaseController
if (!Objects.equals(bill.getMchId(), userId )) {
return error("您无权操作退款");
}
// 判断是否限制退款
SmUserVo user = userService.selectSmUserByUserId(userId);
if (user.getLimitRefund() != null && user.getLimitRefund()) {
return error("退款失败:" + user.getLimitRefundReason());
boolean limitRefund = user.getLimitRefund() != null && user.getLimitRefund();
if (limitRefund) {
LocalDateTime limitRefundTime = user.getLimitRefundTime();
if (limitRefundTime == null) {
throw new ServiceException("您被永久限制退款:" + user.getLimitRefundReason());
} else {
throw new ServiceException("您被限制退款至" + DateUtils.format(limitRefundTime, DateUtils.YYYY_MM_DD_HH_MM_SS) + ":" + user.getLimitRefundReason() );
}
}
LoginUser loginUser = getLoginUser();
dto.setUserName(loginUser.getUsername());
dto.setUserType(loginUser.getLoginType().getType());

View File

@ -70,12 +70,6 @@ public class AppUserController extends BaseController {
return AjaxResult.success(user);
}
@ApiOperation("修改用户类型")
@PutMapping("/changeType")
public AjaxResult changeRole(String userType) {
return AjaxResult.success(userService.changeType(getUserId(), UserType.parse(userType)));
}
@ApiOperation("使用旧密码修改密码")
@PutMapping("/updatePassword")
public AjaxResult updatePassword( @RequestBody @Validated UserUpdatePasswordDTO dto) {

View File

@ -10,6 +10,7 @@ import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
@ -35,6 +36,9 @@ public class SmDeviceController extends BaseController
@Autowired
private DeviceService deviceService;
@Autowired
private DeviceAssembler deviceAssembler;
/**
* 查询设备列表
*/
@ -44,6 +48,7 @@ public class SmDeviceController extends BaseController
{
startPage();
List<DeviceVO> list = deviceService.selectSmDeviceList(smDevice);
deviceAssembler.assembleRealServiceRate(list);
return getDataTable(list);
}
@ -79,6 +84,7 @@ public class SmDeviceController extends BaseController
@GetMapping(value = "/{deviceId}")
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) {
DeviceVO device = deviceService.selectSmDeviceByDeviceId(deviceId);
deviceAssembler.assembleRealServiceRate(device);
return success(device);
}

View File

@ -58,6 +58,7 @@ public class SmUserController extends BaseController
List<SmUserVo> list = smUserService.selectSmUserList(smUser);
userAssembler.assembleStoreCount(list);
userAssembler.assembleDeviceCount(list);
userAssembler.assembleRealServiceRate(list);
smUserService.desensitization(list);
return getDataTable(list);
}
@ -97,6 +98,7 @@ public class SmUserController extends BaseController
List<SmUserVo> list = Collections.singletonList(user);
userAssembler.assembleStoreCount(list);
userAssembler.assembleDeviceCount(list);
userAssembler.assembleRealServiceRate(list);
smUserService.desensitization(list);
return success(user);
}