代理商设备商户是否允许开启

This commit is contained in:
磷叶 2024-11-08 15:17:35 +08:00
parent 5184b06bd4
commit 0109e30920
14 changed files with 127 additions and 32 deletions

View File

@ -239,4 +239,6 @@ public class SmUser extends BaseEntity
@JsonView(JsonViewProfile.AppMch.class)
private BigDecimal agentDeviceService;
@ApiModelProperty("代理商是否允许商户开关设备")
private Boolean agentAllowMchSwitch;
}

View File

@ -97,6 +97,13 @@ public class DeviceVO extends Device implements IotDevice {
@ApiModelProperty("正在使用中的订单数量")
private Integer usingBillCount;
@ApiModelProperty("代理商是否允许商户开关设备")
private Boolean agentAllowMchSwitch;
@ApiModelProperty("是否允许当前用户开关设备")
@JsonView(JsonViewProfile.App.class)
private Boolean allowSwitch;
@Override
public String iotMac1() {
return getMac();

View File

@ -77,7 +77,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.show_bill_mobile as mch_show_bill_mobile,
if(sua.is_real, sua.real_name, sua.user_name) as agent_name,
sua.phonenumber as agent_mobile,
sua.agent_service_rate as agent_user_service_rate
sua.agent_service_rate as agent_user_service_rate,
sua.agent_allow_mch_switch as agent_allow_mch_switch
<include refid="searchTables"/>
</sql>

View File

@ -3,6 +3,7 @@ package com.ruoyi.ss.device.service;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import java.util.Collections;
import java.util.List;
/**
@ -41,4 +42,13 @@ public interface DeviceAssembler {
* 拼接正在使用中的订单数量
*/
void assembleUsingBillCount(List<DeviceVO> list);
/**
* 拼接是否允许切换开关设备
*/
void assembleAllowSwitch(List<DeviceVO> list, Long userId);
default void assembleAllowSwitch(DeviceVO device, Long userId) {
assembleAllowSwitch(Collections.singletonList(device), userId);
}
}

View File

@ -98,10 +98,11 @@ public interface DeviceService
/**
* 切换设备通电状态/断电
* @param deviceId 设备id
*
* @param device 设备id
* @param status 通电状态
*/
boolean changePowerStatus(Long deviceId, DevicePowerStatus status);
boolean changePowerStatus(DeviceVO device, DevicePowerStatus status);
/**
* 拉取设备信息并保存到数据库

View File

@ -23,9 +23,14 @@ public interface DeviceValidator {
* @param deviceId 设备id
* @param userId 用户id
*/
boolean isBelong(Long deviceId, Long userId);
boolean isMch(Long deviceId, Long userId);
boolean isBelong(Collection<Long> deviceIds, Long userId);
boolean isMch(Collection<Long> deviceIds, Long userId);
/**
* 判断是否设备的商户
*/
boolean isMch(DeviceVO device, Long userId);
/**
* 创建前校验
@ -88,4 +93,9 @@ public interface DeviceValidator {
* @param deviceNo
*/
void checkSn(Long deviceId, String deviceNo);
/**
* 判断代理商是否允许商户开关
*/
boolean isAgentAllowMchSwitch(DeviceVO device);
}

View File

@ -1,12 +1,13 @@
package com.ruoyi.ss.device.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.domain.vo.CommonCountVO;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.dashboard.domain.vo.BillCountVo;
import com.ruoyi.ss.device.domain.enums.DeviceServiceMode;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.deviceSuit.domain.DeviceSuitQuery;
import com.ruoyi.ss.deviceSuit.domain.DeviceSuitVO;
import com.ruoyi.ss.deviceSuit.service.DeviceSuitService;
@ -46,6 +47,9 @@ public class DeviceAssemblerImpl implements DeviceAssembler {
@Autowired
private ISysConfigService sysConfigService;
@Autowired
private DeviceValidator deviceValidator;
/**
* 拼接套餐列表
*
@ -183,4 +187,35 @@ public class DeviceAssemblerImpl implements DeviceAssembler {
}
}
@Override
public void assembleAllowSwitch(List<DeviceVO> list, Long userId) {
if (CollectionUtils.isEmptyElement(list)) {
return;
}
for (DeviceVO device : list) {
// 直营模式
if (DeviceServiceMode.DIRECT.getMode().equals(device.getServiceMode())) {
// 是商户
if (deviceValidator.isMch(device, userId)) {
device.setAllowSwitch(true);
continue;
}
}
// 代理模式
else if (DeviceServiceMode.AGENT.getMode().equals(device.getServiceMode())) {
// 是代理
if (deviceValidator.isAgent(device, userId)) {
device.setAllowSwitch(true);
continue;
}
// 是商户并且代理允许
if (deviceValidator.isMch(device, userId) && device.getAgentAllowMchSwitch()) {
device.setAllowSwitch(true);
continue;
}
}
device.setAllowSwitch(false);
}
}
}

View File

@ -978,15 +978,13 @@ public class DeviceServiceImpl implements DeviceService
/**
* 切换设备通电状态/断电
* @param deviceId 设备id
*
* @param device 设备id
* @param status 通电状态
*/
@Override
public boolean changePowerStatus(Long deviceId, DevicePowerStatus status) {
DeviceVO device = deviceMapper.selectSmDeviceByDeviceId(deviceId);
public boolean changePowerStatus(DeviceVO device, DevicePowerStatus status) {
ServiceUtil.assertion(device == null || device.getDeleted(), "设备不存在");
ServiceUtil.assertion(!StringUtils.hasText(device.getMac()), "设备Mac号为空");
ServiceUtil.assertion(!UserUtil.hasFrontUser(device.getUserId()), "该设备不是您的,无法进行该操作" );
if (DevicePowerStatus.ON.equals(status)) {
iotService.open(device);
@ -998,7 +996,7 @@ public class DeviceServiceImpl implements DeviceService
// 修改数据库通断电状态
Device changePowerForm = new Device();
changePowerForm.setDeviceId(deviceId);
changePowerForm.setDeviceId(device.getDeviceId());
changePowerForm.setPowerStatus(status.getStatus());
deviceMapper.updateSmDevice(changePowerForm);

View File

@ -13,13 +13,14 @@ import com.ruoyi.ss.device.domain.enums.DeviceServiceMode;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.model.domain.enums.ModelTag;
import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.suit.service.SuitValidator;
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType;
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
import org.eclipse.jetty.util.StringUtil;
import com.ruoyi.ss.user.domain.SmUserVO;
import com.ruoyi.ss.user.service.ISmUserService;
import com.ruoyi.ss.user.service.impl.SmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -44,6 +45,9 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
@Autowired
private TransactionBillService transactionBillService;
@Autowired
private ISmUserService userService;
/**
* 设备编号是否存在
*
@ -66,16 +70,16 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
* @param userId 用户id
*/
@Override
public boolean isBelong(Long deviceId, Long userId) {
public boolean isMch(Long deviceId, Long userId) {
if (deviceId == null || userId == null) {
return false;
}
DeviceVO device = deviceService.selectById(deviceId);
return device != null && Objects.equals(device.getUserId(), userId);
return this.isMch(device, userId);
}
@Override
public boolean isBelong(Collection<Long> deviceIds, Long userId) {
public boolean isMch(Collection<Long> deviceIds, Long userId) {
if (CollectionUtils.isEmptyElement(deviceIds) || userId == null) {
return false;
}
@ -83,7 +87,17 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
query.setDeviceIds(new ArrayList<>(deviceIds));
query.setUserId(userId);
List<DeviceVO> deviceList = deviceService.selectSmDeviceList(query);
return deviceList.size() == deviceIds.size();
for (DeviceVO device : deviceList) {
if (!isMch(device, userId)) {
return false;
}
}
return true;
}
@Override
public boolean isMch(DeviceVO device, Long userId) {
return device != null && userId != null && Objects.equals(device.getUserId(), userId);
}
/**
@ -131,7 +145,7 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
Long userId = SecurityUtils.getUserId();
// 判断是否有权限更改
if (!isBelong(data.getDeviceId(), userId)) {
if (!isMch(data.getDeviceId(), userId)) {
return error("这不是您的设备,您无权更改");
}
// 判断套餐
@ -233,4 +247,13 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
public void checkSn(Long deviceId, String deviceNo) {
ServiceUtil.assertion(isRepeatSn(deviceId, deviceNo), "SN重复", ServiceCode.DEVICE_SN_REPEAT.getCode());
}
@Override
public boolean isAgentAllowMchSwitch(DeviceVO device) {
if (device != null && DeviceServiceMode.AGENT.getMode().equals(device.getServiceMode()) && device.getAgentId() != null) {
SmUserVO agent = userService.selectSimpleById(device.getAgentId());
return agent == null || agent.getAgentAllowMchSwitch();
}
return true;
}
}

View File

@ -92,7 +92,7 @@ public class SuitValidatorImpl extends BaseValidator implements SuitValidator {
}
// 设备校验
if (CollectionUtils.isNotEmptyElement(suit.getDeviceIds()) && !deviceValidator.isBelong(suit.getDeviceIds(), SecurityUtils.getUserId())) {
if (CollectionUtils.isNotEmptyElement(suit.getDeviceIds()) && !deviceValidator.isMch(suit.getDeviceIds(), SecurityUtils.getUserId())) {
return error("有设备不属于该用户");
}
@ -121,7 +121,7 @@ public class SuitValidatorImpl extends BaseValidator implements SuitValidator {
}
// 设备校验
if (CollectionUtils.isNotEmptyElement(suit.getDeviceIds()) && !deviceValidator.isBelong(suit.getDeviceIds(), SecurityUtils.getUserId())) {
if (CollectionUtils.isNotEmptyElement(suit.getDeviceIds()) && !deviceValidator.isMch(suit.getDeviceIds(), SecurityUtils.getUserId())) {
return error("有设备不属于该用户");
}

View File

@ -59,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.show_bill_mobile,
su.show_bill_mobile_price,
su.agent_device_service,
su.agent_allow_mch_switch,
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,
@ -89,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="readMchLicence != null "> and read_mch_licence = #{readMchLicence}</if>
<if test="showBillMobile != null "> and show_bill_mobile = #{showBillMobile}</if>
<if test="excludeUserId != null">and su.user_id != #{excludeUserId}</if>
<if test="agentAllowMchSwitch != null">and su.agent_allow_mch_switch != #{agentAllowMchSwitch}</if>
<if test="realOrUserName != null and realOrUserName != ''">and if(su.is_real, su.real_name, su.user_name) like concat('%', #{realOrUserName}, '%')</if>
<if test="tenantDeviceId != null">
and su.user_id in (
@ -197,6 +199,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="showBillMobile != null">show_bill_mobile,</if>
<if test="showBillMobilePrice != null">show_bill_mobile_price,</if>
<if test="agentDeviceService != null">agent_device_service,</if>
<if test="agentAllowMchSwitch != null">agent_allow_mch_switch,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userName != null and userName != ''">#{userName},</if>
@ -244,6 +247,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="showBillMobile != null">#{showBillMobile},</if>
<if test="showBillMobilePrice != null">#{showBillMobilePrice},</if>
<if test="agentDeviceService != null">#{agentDeviceService},</if>
<if test="agentAllowMchSwitch != null">#{agentAllowMchSwitch},</if>
</trim>
</insert>
@ -307,6 +311,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="showBillMobile != null">show_bill_mobile = #{showBillMobile},</if>
<if test="showBillMobilePrice != null">show_bill_mobile_price = #{showBillMobilePrice},</if>
<if test="agentDeviceService != null">agent_device_service = #{agentDeviceService},</if>
<if test="agentAllowMchSwitch != null">agent_allow_mch_switch = #{agentAllowMchSwitch},</if>
</trim>
where user_id = #{userId}
</update>

View File

@ -9,7 +9,6 @@ import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.OperatorType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.iot.service.IotService;
@ -40,7 +39,6 @@ import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* 设备Controller
@ -114,6 +112,7 @@ public class AppDeviceController extends BaseController {
DeviceVO device = smDeviceService.selectById(deviceId);
List<DeviceVO> list = Collections.singletonList(device);
deviceAssembler.assembleOrderCountInfo(list); // 订单统计信息
deviceAssembler.assembleAllowSwitch(list, getUserId());
return success(device);
}
@ -121,8 +120,13 @@ public class AppDeviceController extends BaseController {
@ApiOperation("设备通断电")
@PutMapping("/{deviceId}/changePower")
public AjaxResult close(@PathVariable @ApiParam("设备id") Long deviceId, String status) {
DeviceVO device = smDeviceService.selectById(deviceId);
ServiceUtil.assertion(device == null, "设备不存在");
deviceAssembler.assembleAllowSwitch(device, getUserId());
ServiceUtil.assertion(!device.getAllowSwitch(), "您无权操作此设备");
DevicePowerStatus powerStatus = DevicePowerStatus.parse(status);
return success(smDeviceService.changePowerStatus(deviceId, powerStatus ));
return success(smDeviceService.changePowerStatus(device, powerStatus ));
}
@Log(title = "绑定设备", businessType = BusinessType.OTHER, operatorType = OperatorType.MOBILE)
@ -143,7 +147,7 @@ public class AppDeviceController extends BaseController {
@ApiOperation("解除设备绑定")
@DeleteMapping("/mch/unbind/{deviceId}")
public AjaxResult mchUnbind(@PathVariable @ApiParam("设备id") Long deviceId) {
ServiceUtil.assertion(!deviceValidator.isBelong(deviceId, getUserId()), "这不是您的设备");
ServiceUtil.assertion(!deviceValidator.isMch(deviceId, getUserId()), "这不是您的设备");
return toAjax(smDeviceService.unbind(deviceId));
}
@ -169,9 +173,10 @@ public class AppDeviceController extends BaseController {
@ApiParam("单位") @RequestParam(required = false, defaultValue = "3") String timeUnit,
@ApiParam("是否操作物联网设备") @RequestParam(required = false, defaultValue = "true") Boolean withIot
) {
ServiceUtil.assertion(!deviceValidator.isBelong(deviceId, getUserId()), "这不是您的设备");
DeviceVO device = smDeviceService.selectById(deviceId);
ServiceUtil.assertion(device == null || !getUserId().equals(device.getUserId()), "设备不存在或您无权充值");
ServiceUtil.assertion(device == null, "设备不存在");
deviceAssembler.assembleAllowSwitch(device, getUserId());
ServiceUtil.assertion(!device.getAllowSwitch(), "您无权操作此设备");
// 电量
if ( "0".equals(timeUnit)) {

View File

@ -14,7 +14,6 @@ import com.ruoyi.ss.suit.domain.Suit;
import com.ruoyi.ss.suit.domain.SuitBO;
import com.ruoyi.ss.suit.domain.SuitQuery;
import com.ruoyi.ss.suit.domain.SuitVO;
import com.ruoyi.ss.suit.domain.dto.SuitCopyDTO;
import com.ruoyi.ss.suit.service.SuitAssembler;
import com.ruoyi.ss.suit.service.SuitService;
import com.ruoyi.ss.suit.service.SuitValidator;
@ -24,7 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -55,7 +53,7 @@ public class AppSuitController extends BaseController {
@JsonView(JsonViewProfile.AppMch.class)
@GetMapping("/listByDeviceId/{deviceId}")
public AjaxResult list(@PathVariable Long deviceId) {
ServiceUtil.assertion(!deviceValidator.isBelong(deviceId, getUserId()), "这不是您的设备,无法查看");
ServiceUtil.assertion(!deviceValidator.isMch(deviceId, getUserId()), "这不是您的设备,无法查看");
List<SuitVO> list = suitService.selectByDeviceId(deviceId);
suitAssembler.assembleDeviceList(list);
return success(list);
@ -109,7 +107,7 @@ public class AppSuitController extends BaseController {
@ApiOperation("将指定设备的套餐清空")
@DeleteMapping("/delByDevice/{deviceId}")
public AjaxResult delByDevice(@PathVariable Long deviceId) {
if (!deviceValidator.isBelong(deviceId, getUserId())) {
if (!deviceValidator.isMch(deviceId, getUserId())) {
return error("这不是您的设备,无法清空套餐");
}
return toAjax(deviceSuitService.deleteByDeviceId(deviceId));

View File

@ -222,7 +222,7 @@ public class AppTransactionBillController extends BaseController
@GetMapping("/rechargeListByDevice")
@JsonView(JsonViewProfile.AppMch.class)
public TableDataInfo getDeviceRechargeList(@RequestParam @ApiParam("设备id") Long deviceId) {
ServiceUtil.assertion(!deviceValidator.isBelong(deviceId, getUserId()), "这不是您的设备,无法查询");
ServiceUtil.assertion(!deviceValidator.isMch(deviceId, getUserId()), "这不是您的设备,无法查询");
TransactionBillQuery query = new TransactionBillQuery();
query.setDeviceId(deviceId);
query.setMchId(getUserId());