绑定代理、商户

This commit is contained in:
墨大叔 2024-10-15 15:03:33 +08:00
parent dcc9cd845d
commit 5b2246c9d9
23 changed files with 504 additions and 175 deletions

View File

@ -229,4 +229,8 @@ public class SmUser extends BaseEntity
@Min(value = 0, message = "订单显示用户手机号单价不允许小于0元/单")
private BigDecimal showBillMobilePrice;
@Excel(name = "代理商默认设备服务费率")
@ApiModelProperty("代理商默认设备服务费率")
private BigDecimal agentDeviceService;
}

View File

@ -191,4 +191,23 @@ public interface DeviceMapper
* 根据任何一个MAC查询
*/
DeviceVO selectByAnyMac(@Param("mac") String mac);
/**
* 解绑代理商
*/
int unbindAgent(Long deviceId);
/**
* 查询设备最大的代理商服务费
*/
BigDecimal selectMaxAgentServiceRate(DeviceQuery query);
/**
* 绑定代理商
* @param deviceId 设备ID
* @param agentId 代理商ID
* @param agentServiceRate 代理商设备服务费
*/
int bindAgent(@Param("deviceId") Long deviceId,@Param("agentId") Long agentId, @Param("agentServiceRate") BigDecimal agentServiceRate);
}

View File

@ -166,6 +166,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sua.user_name as agent_name,
sua.phonenumber as agent_mobile,
sua.agent_service_rate as agent_user_service_rate
<include refid="searchTables"/>
</sql>
<sql id="searchTables">
from sm_device sd
left join sm_model sm on sm.model_id = sd.model_id
left join sm_store ss on ss.store_id = sd.store_id
@ -287,6 +291,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where sd.deleted = false and (sd.mac = #{mac} or sd.mac2 = #{mac})
</select>
<select id="selectMaxAgentServiceRate" resultType="java.math.BigDecimal">
select max(sd.agent_service_rate)
<include refid="searchTables"/>
<where>
<include refid="searchCondition"/>
</where>
</select>
<insert id="insertSmDevice" parameterType="Device" useGeneratedKeys="true" keyProperty="deviceId">
<selectKey resultType="Long" order="AFTER" keyProperty="deviceId">
select LAST_INSERT_ID()
@ -588,6 +600,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where device_id = #{deviceId}
</update>
<update id="unbindAgent">
update sm_device
set agent_id = null,
agent_service_rate = null,
service_mode = '1'
where device_id = #{deviceId} and agent_id is not null
</update>
<update id="bindAgent">
update sm_device
set agent_id = #{agentId},
agent_service_rate = #{agentServiceRate},
service_mode = '2'
where device_id = #{deviceId} and agent_id is null
</update>
<delete id="deleteSmDeviceByDeviceId" parameterType="Long">
delete from sm_device where device_id = #{deviceId}
</delete>

View File

@ -345,4 +345,27 @@ public interface DeviceService
* 拉取最新设备数据
*/
void pullDeviceInfo(DeviceVO device);
/**
* 解绑代理商
*/
int unbindAgent(Long deviceId);
/**
* 绑定商户
*/
String bindMch(Long deviceId, Long mchId);
/**
* 查询最大的代理商设备服务费
*/
BigDecimal selectMaxAgentServiceRate(DeviceQuery query);
/**
* 绑定代理商
* @param deviceId 设备ID
* @param agentId 代理商ID
* @param agentServiceRate 代理商设备服务费
*/
int bindAgent(Long deviceId, Long agentId, BigDecimal agentServiceRate);
}

View File

@ -57,6 +57,11 @@ public interface DeviceValidator {
*/
void afterCheck(DeviceVO vo);
/**
* 校验代理商
*/
void checkAgent(DeviceVO vo);
/**
* 判断用户是否设备的代理商
* @param device 设备

View File

@ -22,6 +22,7 @@ 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.DeviceServiceMode;
import com.ruoyi.ss.device.domain.enums.DeviceStatus;
import com.ruoyi.ss.device.domain.vo.DeviceMacSnVO;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
@ -29,7 +30,9 @@ import com.ruoyi.ss.device.mapper.DeviceMapper;
import com.ruoyi.ss.device.service.DeviceAssembler;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.device.service.DeviceValidator;
import com.ruoyi.ss.deviceBindRecord.service.ISmDeviceBindRecordService;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType;
import com.ruoyi.ss.deviceBindRecord.service.DeviceBindRecordService;
import com.ruoyi.ss.deviceSuit.service.DeviceSuitConverter;
import com.ruoyi.ss.deviceSuit.service.DeviceSuitService;
import com.ruoyi.ss.model.domain.SmModelVO;
@ -68,8 +71,6 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import static net.sf.jsqlparser.parser.feature.Feature.reset;
/**
* 设备Service业务层处理
*
@ -87,7 +88,7 @@ public class DeviceServiceImpl implements DeviceService
private IotService iotService;
@Autowired
private ISmDeviceBindRecordService smDeviceBindRecordService;
private DeviceBindRecordService smDeviceBindRecordService;
@Autowired
private ScheduledExecutorService scheduledExecutorService;
@ -197,6 +198,7 @@ public class DeviceServiceImpl implements DeviceService
code = iotService.create(data.getMac2(), model.getProductId());
ServiceUtil.assertion(!IotHttpStatus.SUCCESS.equalCode(code) && !IotHttpStatus.DEVICE_EXIST.equalCode(code), "MAC-2注册失败");
}
return insert;
});
return result == null ? 0 : result;
@ -706,6 +708,63 @@ public class DeviceServiceImpl implements DeviceService
this.pullDeviceInfoList(Collections.singletonList(device));
}
@Override
public int unbindAgent(Long deviceId) {
DeviceVO device = selectById(deviceId);
ServiceUtil.assertion(device == null, "设备不存在");
ServiceUtil.assertion(device.getAgentId() == null, "设备没有代理商,无需解绑");
Integer result = transactionTemplate.execute(status -> {
// 解绑
int unbind = deviceMapper.unbindAgent(deviceId);
ServiceUtil.assertion(unbind != 1, "解绑失败,请刷新后重试");
// 新增解绑记录
smDeviceBindRecordService.record(device.getAgentId(), deviceId, BindRecordType.UNBIND, BindRecordUserType.AGENT);
return unbind;
});
return result == null ? 0 : result;
}
@Override
public String bindMch(Long deviceId, Long mchId) {
DeviceVO device = this.selectById(deviceId);
return this.bind(null, mchId, device);
}
@Override
public BigDecimal selectMaxAgentServiceRate(DeviceQuery query) {
query.setServiceMode(DeviceServiceMode.AGENT.getMode());
return deviceMapper.selectMaxAgentServiceRate(query);
}
@Override
public int bindAgent(Long deviceId, Long agentId, BigDecimal agentServiceRate) {
if (deviceId == null || agentId == null || agentServiceRate == null) {
return 0;
}
Integer result = transactionTemplate.execute(status -> {
// 绑定
int bind = deviceMapper.bindAgent(deviceId, agentId, agentServiceRate);
ServiceUtil.assertion(bind != 1, "绑定代理商失败,请刷新后重试");
// 后校验
DeviceVO vo = this.selectById(deviceId);
deviceValidator.checkAgent(vo);
// 添加绑定记录
int record = smDeviceBindRecordService.record(agentId, deviceId, BindRecordType.BIND, BindRecordUserType.AGENT);
ServiceUtil.assertion(record != 1, "添加绑定记录失败");
return bind;
});
return result == null ? 0 : result;
}
@Override
public boolean addTime(Long deviceId, long seconds, boolean withIot) {
@ -1093,7 +1152,7 @@ public class DeviceServiceImpl implements DeviceService
ServiceUtil.assertion(updateCount != 1, "当前设备信息已变更,请刷新后重试");
// 记录绑定记录
int record = smDeviceBindRecordService.record(userId, device.getDeviceId());
int record = smDeviceBindRecordService.record(userId, device.getDeviceId(), BindRecordType.BIND, BindRecordUserType.MCH);
ServiceUtil.assertion(record != 1, "添加绑定记录失败");
// 用户设置为商户
@ -1337,6 +1396,9 @@ public class DeviceServiceImpl implements DeviceService
// 删除套餐关联关系
deviceSuitService.deleteByDeviceId(deviceId);
// 新增解绑记录
smDeviceBindRecordService.record(device.getUserId(), deviceId, BindRecordType.UNBIND, BindRecordUserType.MCH);
return updateCount;
});

View File

@ -178,13 +178,23 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
ServiceUtil.assertion(this.isRepeatMac(vo.getDeviceId(), vo.getMac2()), "MAC-2重复:" + vo.getMac2());
ServiceUtil.assertion(this.isRepeatSn(vo.getDeviceId(), vo.getDeviceNo()), "SN重复");
// 若是代理模式则代理商服务费不允许 小于 代理商本人的服务费
// 校验代理商
this.checkAgent(vo);
}
// 校验代理商
@Override
public void checkAgent(DeviceVO vo) {
if (vo == null) {
return;
}
if (DeviceServiceMode.AGENT.getMode().equals(vo.getServiceMode())) {
ServiceUtil.assertion(vo.getAgentId() == null, "代理商不允许为空");
ServiceUtil.assertion(vo.getAgentServiceRate() == null || vo.getAgentUserServiceRate() == null, "设备代理商服务费或平台代理商服务费不允许为空");
ServiceUtil.assertion(vo.getAgentServiceRate().compareTo(vo.getAgentUserServiceRate()) < 0, "设备服务费不允许小于平台收取代理商的服务费:" + vo.getAgentUserServiceRate() + "%");
ServiceUtil.assertion(vo.getAgentServiceRate().compareTo(vo.getAgentUserServiceRate()) < 0,
"设备服务费不允许小于平台收取代理商的服务费:" + vo.getAgentUserServiceRate() + "%");
}
}
@Override

View File

@ -2,6 +2,7 @@ package com.ruoyi.ss.deviceBindRecord.domain;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
@ -11,7 +12,7 @@ import lombok.Data;
* @date 2024-04-17
*/
@Data
public class SmDeviceBindRecord extends BaseEntity
public class DeviceBindRecord extends BaseEntity
{
private static final long serialVersionUID = 1L;
@ -26,4 +27,12 @@ public class SmDeviceBindRecord extends BaseEntity
@Excel(name = "用户id")
private Long userId;
@Excel(name = "类型1-绑定2-解绑")
@ApiModelProperty("类型1-绑定2-解绑")
private String type;
@Excel(name = "用户类型1-商户2-代理商")
@ApiModelProperty("用户类型1-商户2-代理商")
private String userType;
}

View File

@ -0,0 +1,11 @@
package com.ruoyi.ss.deviceBindRecord.domain;
import lombok.Data;
/**
* @author wjh
* 2024/10/15
*/
@Data
public class DeviceBindRecordQuery extends DeviceBindRecordVO {
}

View File

@ -8,8 +8,11 @@ import lombok.Data;
* 2024/4/17
*/
@Data
public class SmDeviceBindRecordVo extends SmDeviceBindRecord {
public class DeviceBindRecordVO extends DeviceBindRecord {
@ApiModelProperty("用户名称")
private String userName;
@ApiModelProperty("设备编号")
private String deviceNo;
}

View File

@ -0,0 +1,22 @@
package com.ruoyi.ss.deviceBindRecord.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
/**
* 设备绑定记录类型
* @author wjh
* 2024/10/15
*/
@Getter
@AllArgsConstructor
public enum BindRecordType {
BIND("1", "绑定"),
UNBIND("2", "解绑");
private final String type;
private final String msg;
}

View File

@ -0,0 +1,21 @@
package com.ruoyi.ss.deviceBindRecord.domain.enums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
/**
* @author wjh
* 2024/10/15
*/
@Getter
@AllArgsConstructor
public enum BindRecordUserType {
MCH("1", "商户"),
AGENT("2", "代理商");
private final String userType;
private final String msg;
}

View File

@ -1,6 +1,8 @@
package com.ruoyi.ss.deviceBindRecord.mapper;
import com.ruoyi.ss.deviceBindRecord.domain.SmDeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO;
import java.util.List;
@ -10,7 +12,7 @@ import java.util.List;
* @author ruoyi
* @date 2024-04-17
*/
public interface SmDeviceBindRecordMapper
public interface DeviceBindRecordMapper
{
/**
* 查询设备绑定记录
@ -18,31 +20,31 @@ public interface SmDeviceBindRecordMapper
* @param recordId 设备绑定记录主键
* @return 设备绑定记录
*/
public SmDeviceBindRecord selectSmDeviceBindRecordByRecordId(Long recordId);
public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId);
/**
* 查询设备绑定记录列表
*
* @param smDeviceBindRecord 设备绑定记录
* @param deviceBindRecord 设备绑定记录
* @return 设备绑定记录集合
*/
public List<SmDeviceBindRecord> selectSmDeviceBindRecordList(SmDeviceBindRecord smDeviceBindRecord);
public List<DeviceBindRecordVO> selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord);
/**
* 新增设备绑定记录
*
* @param smDeviceBindRecord 设备绑定记录
* @param deviceBindRecord 设备绑定记录
* @return 结果
*/
public int insertSmDeviceBindRecord(SmDeviceBindRecord smDeviceBindRecord);
public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord);
/**
* 修改设备绑定记录
*
* @param smDeviceBindRecord 设备绑定记录
* @param deviceBindRecord 设备绑定记录
* @return 结果
*/
public int updateSmDeviceBindRecord(SmDeviceBindRecord smDeviceBindRecord);
public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord);
/**
* 删除设备绑定记录

View File

@ -2,9 +2,9 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.ss.deviceBindRecord.mapper.SmDeviceBindRecordMapper">
<mapper namespace="com.ruoyi.ss.deviceBindRecord.mapper.DeviceBindRecordMapper">
<resultMap type="SmDeviceBindRecordVo" id="SmDeviceBindRecordResult" autoMapping="true">
<resultMap type="DeviceBindRecordVO" id="SmDeviceBindRecordResult" autoMapping="true">
</resultMap>
<sql id="selectSmDeviceBindRecordVo">
@ -13,16 +13,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sdbr.device_id,
sdbr.user_id,
sdbr.create_time,
su.user_name user_name
sdbr.type,
sdbr.user_type,
su.user_name as user_name,
sd.device_no as device_no
from sm_device_bind_record sdbr
left join sm_user su on su.user_id = sdbr.user_id
left join sm_device sd on sd.device_id = sdbr.device_id
</sql>
<select id="selectSmDeviceBindRecordList" parameterType="SmDeviceBindRecord" resultMap="SmDeviceBindRecordResult">
<select id="selectSmDeviceBindRecordList" parameterType="DeviceBindRecordQuery" resultMap="SmDeviceBindRecordResult">
<include refid="selectSmDeviceBindRecordVo"/>
<where>
<if test="deviceId != null "> and device_id = #{deviceId}</if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="deviceId != null "> and sdbr.device_id = #{deviceId}</if>
<if test="userId != null "> and sdbr.user_id = #{userId}</if>
<if test="type != null and type != ''"> and sdbr.type = #{type}</if>
<if test="userType != null and userType != ''"> and sdbr.user_type = #{userType}</if>
<if test="deviceNo != null and deviceNo != ''"> and sd.device_no like concat('%',#{deviceNo},'%')</if>
<if test="userName != null and userName != ''"> and su.user_name like concat('%',#{userName},'%')</if>
</where>
</select>
@ -31,28 +39,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where record_id = #{recordId}
</select>
<insert id="insertSmDeviceBindRecord" parameterType="SmDeviceBindRecord">
<insert id="insertSmDeviceBindRecord" parameterType="DeviceBindRecord">
insert into sm_device_bind_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="recordId != null">record_id,</if>
<if test="deviceId != null">device_id,</if>
<if test="userId != null">user_id,</if>
<if test="createTime != null">create_time,</if>
<if test="type != null and type != ''">type,</if>
<if test="userType != null and userType != ''">user_type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="recordId != null">#{recordId},</if>
<if test="deviceId != null">#{deviceId},</if>
<if test="userId != null">#{userId},</if>
<if test="createTime != null">#{createTime},</if>
<if test="type != null and type != ''">#{type},</if>
<if test="userType != null and userType != ''">#{userType},</if>
</trim>
</insert>
<update id="updateSmDeviceBindRecord" parameterType="SmDeviceBindRecord">
<update id="updateSmDeviceBindRecord" parameterType="DeviceBindRecord">
update sm_device_bind_record
<trim prefix="SET" suffixOverrides=",">
<if test="deviceId != null">device_id = #{deviceId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="userType != null and userType != ''">user_type = #{userType},</if>
</trim>
where record_id = #{recordId}
</update>

View File

@ -1,6 +1,10 @@
package com.ruoyi.ss.deviceBindRecord.service;
import com.ruoyi.ss.deviceBindRecord.domain.SmDeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType;
import java.util.List;
@ -10,7 +14,7 @@ import java.util.List;
* @author ruoyi
* @date 2024-04-17
*/
public interface ISmDeviceBindRecordService
public interface DeviceBindRecordService
{
/**
* 查询设备绑定记录
@ -18,31 +22,31 @@ public interface ISmDeviceBindRecordService
* @param recordId 设备绑定记录主键
* @return 设备绑定记录
*/
public SmDeviceBindRecord selectSmDeviceBindRecordByRecordId(Long recordId);
public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId);
/**
* 查询设备绑定记录列表
*
* @param smDeviceBindRecord 设备绑定记录
* @param deviceBindRecord 设备绑定记录
* @return 设备绑定记录集合
*/
public List<SmDeviceBindRecord> selectSmDeviceBindRecordList(SmDeviceBindRecord smDeviceBindRecord);
public List<DeviceBindRecordVO> selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord);
/**
* 新增设备绑定记录
*
* @param smDeviceBindRecord 设备绑定记录
* @param deviceBindRecord 设备绑定记录
* @return 结果
*/
public int insertSmDeviceBindRecord(SmDeviceBindRecord smDeviceBindRecord);
public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord);
/**
* 修改设备绑定记录
*
* @param smDeviceBindRecord 设备绑定记录
* @param deviceBindRecord 设备绑定记录
* @return 结果
*/
public int updateSmDeviceBindRecord(SmDeviceBindRecord smDeviceBindRecord);
public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord);
/**
* 批量删除设备绑定记录
@ -60,5 +64,8 @@ public interface ISmDeviceBindRecordService
*/
public int deleteSmDeviceBindRecordByRecordId(Long recordId);
int record(Long userId, Long deviceId);
/**
* 绑定记录
*/
int record(Long userId, Long deviceId, BindRecordType recordType, BindRecordUserType userType);
}

View File

@ -0,0 +1,109 @@
package com.ruoyi.ss.deviceBindRecord.service;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordType;
import com.ruoyi.ss.deviceBindRecord.domain.enums.BindRecordUserType;
import com.ruoyi.ss.deviceBindRecord.mapper.DeviceBindRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 设备绑定记录Service业务层处理
*
* @author ruoyi
* @date 2024-04-17
*/
@Service
public class DeviceBindRecordServiceImpl implements DeviceBindRecordService
{
@Autowired
private DeviceBindRecordMapper deviceBindRecordMapper;
/**
* 查询设备绑定记录
*
* @param recordId 设备绑定记录主键
* @return 设备绑定记录
*/
@Override
public DeviceBindRecordVO selectSmDeviceBindRecordByRecordId(Long recordId)
{
return deviceBindRecordMapper.selectSmDeviceBindRecordByRecordId(recordId);
}
/**
* 查询设备绑定记录列表
*
* @param deviceBindRecord 设备绑定记录
* @return 设备绑定记录
*/
@Override
public List<DeviceBindRecordVO> selectSmDeviceBindRecordList(DeviceBindRecordQuery deviceBindRecord)
{
return deviceBindRecordMapper.selectSmDeviceBindRecordList(deviceBindRecord);
}
/**
* 新增设备绑定记录
*
* @param deviceBindRecord 设备绑定记录
* @return 结果
*/
@Override
public int insertSmDeviceBindRecord(DeviceBindRecord deviceBindRecord)
{
deviceBindRecord.setCreateTime(DateUtils.getNowDate());
return deviceBindRecordMapper.insertSmDeviceBindRecord(deviceBindRecord);
}
/**
* 修改设备绑定记录
*
* @param deviceBindRecord 设备绑定记录
* @return 结果
*/
@Override
public int updateSmDeviceBindRecord(DeviceBindRecord deviceBindRecord)
{
return deviceBindRecordMapper.updateSmDeviceBindRecord(deviceBindRecord);
}
/**
* 批量删除设备绑定记录
*
* @param recordIds 需要删除的设备绑定记录主键
* @return 结果
*/
@Override
public int deleteSmDeviceBindRecordByRecordIds(Long[] recordIds)
{
return deviceBindRecordMapper.deleteSmDeviceBindRecordByRecordIds(recordIds);
}
/**
* 删除设备绑定记录信息
*
* @param recordId 设备绑定记录主键
* @return 结果
*/
@Override
public int deleteSmDeviceBindRecordByRecordId(Long recordId)
{
return deviceBindRecordMapper.deleteSmDeviceBindRecordByRecordId(recordId);
}
@Override
public int record(Long userId, Long deviceId, BindRecordType recordType, BindRecordUserType userType) {
DeviceBindRecord record = new DeviceBindRecord();
record.setUserId(userId);
record.setDeviceId(deviceId);
record.setType(recordType.getType());
record.setUserType(userType.getUserType());
return this.insertSmDeviceBindRecord(record);
}
}

View File

@ -1,103 +0,0 @@
package com.ruoyi.ss.deviceBindRecord.service;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.ss.deviceBindRecord.domain.SmDeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.mapper.SmDeviceBindRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 设备绑定记录Service业务层处理
*
* @author ruoyi
* @date 2024-04-17
*/
@Service
public class SmDeviceBindRecordServiceImpl implements ISmDeviceBindRecordService
{
@Autowired
private SmDeviceBindRecordMapper smDeviceBindRecordMapper;
/**
* 查询设备绑定记录
*
* @param recordId 设备绑定记录主键
* @return 设备绑定记录
*/
@Override
public SmDeviceBindRecord selectSmDeviceBindRecordByRecordId(Long recordId)
{
return smDeviceBindRecordMapper.selectSmDeviceBindRecordByRecordId(recordId);
}
/**
* 查询设备绑定记录列表
*
* @param smDeviceBindRecord 设备绑定记录
* @return 设备绑定记录
*/
@Override
public List<SmDeviceBindRecord> selectSmDeviceBindRecordList(SmDeviceBindRecord smDeviceBindRecord)
{
return smDeviceBindRecordMapper.selectSmDeviceBindRecordList(smDeviceBindRecord);
}
/**
* 新增设备绑定记录
*
* @param smDeviceBindRecord 设备绑定记录
* @return 结果
*/
@Override
public int insertSmDeviceBindRecord(SmDeviceBindRecord smDeviceBindRecord)
{
smDeviceBindRecord.setCreateTime(DateUtils.getNowDate());
return smDeviceBindRecordMapper.insertSmDeviceBindRecord(smDeviceBindRecord);
}
/**
* 修改设备绑定记录
*
* @param smDeviceBindRecord 设备绑定记录
* @return 结果
*/
@Override
public int updateSmDeviceBindRecord(SmDeviceBindRecord smDeviceBindRecord)
{
return smDeviceBindRecordMapper.updateSmDeviceBindRecord(smDeviceBindRecord);
}
/**
* 批量删除设备绑定记录
*
* @param recordIds 需要删除的设备绑定记录主键
* @return 结果
*/
@Override
public int deleteSmDeviceBindRecordByRecordIds(Long[] recordIds)
{
return smDeviceBindRecordMapper.deleteSmDeviceBindRecordByRecordIds(recordIds);
}
/**
* 删除设备绑定记录信息
*
* @param recordId 设备绑定记录主键
* @return 结果
*/
@Override
public int deleteSmDeviceBindRecordByRecordId(Long recordId)
{
return smDeviceBindRecordMapper.deleteSmDeviceBindRecordByRecordId(recordId);
}
@Override
public int record(Long userId, Long deviceId) {
SmDeviceBindRecord record = new SmDeviceBindRecord();
record.setUserId(userId);
record.setDeviceId(deviceId);
return this.insertSmDeviceBindRecord(record);
}
}

View File

@ -58,6 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.limit_refund_time,
su.show_bill_mobile,
su.show_bill_mobile_price,
su.agent_device_service,
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,
@ -70,6 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="nickName != null and nickName != ''"> and su.nick_name like concat('%', #{nickName}, '%')</if>
<if test="phonenumber != null and phonenumber != ''"> and su.phonenumber like concat('%', #{phonenumber}, '%')</if>
<if test="eqPhonenumber != null and eqPhonenumber != ''"> and su.phonenumber = #{eqPhonenumber}</if>
<if test="wxOpenId != null and wxOpenId != ''"> and su.wx_open_id = #{wxOpenId}</if>
<if test="sex != null and sex != ''"> and su.sex = #{sex}</if>
<if test="type != null and type != ''"> and su.type = #{type}</if>
<if test="status != null and status != ''"> and su.status = #{status}</if>
@ -192,6 +194,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="limitRefundTime != null">limit_refund_time,</if>
<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>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userName != null and userName != ''">#{userName},</if>
@ -238,6 +241,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="limitRefundTime != null">#{limitRefundTime},</if>
<if test="showBillMobile != null">#{showBillMobile},</if>
<if test="showBillMobilePrice != null">#{showBillMobilePrice},</if>
<if test="agentDeviceService != null">#{agentDeviceService},</if>
</trim>
</insert>
@ -300,6 +304,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="limitRefundTime != null">limit_refund_time = #{limitRefundTime},</if>
<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>
</trim>
where user_id = #{userId}
</update>

View File

@ -39,4 +39,9 @@ public interface UserValidator {
* @param vo
*/
void checkMobile(SmUserVo vo);
/**
* 后校验
*/
void afterCheck(SmUserVo vo);
}

View File

@ -583,8 +583,6 @@ public class SmUserServiceImpl implements ISmUserService
@Transactional
public int insertSmUser(SmUser smUser)
{
this.validate(smUser, false);
// 设置用户默认信息
if (StringUtils.hasText(smUser.getPassword())) {
smUser.setPassword(SecurityUtils.encryptPassword(smUser.getPassword()));
@ -596,31 +594,17 @@ public class SmUserServiceImpl implements ISmUserService
smUser.setServiceRate(serviceRate);
}
return smUserMapper.insertSmUser(smUser);
}
Integer result = transactionTemplate.execute(status -> {
int insert = smUserMapper.insertSmUser(smUser);
ServiceUtil.assertion(insert != 1, "新增用户失败,请刷新后重试");
/**
* 插入更新校验
* @param data 数据
* @param update 是否更新
*/
private void validate(SmUser data, boolean update) {
if (update) {
SmUserVo user = selectSmUserByUserId(data.getUserId());
ServiceUtil.assertion(user == null, "用户不存在");
}
SmUserVo vo = this.selectSmUserByUserId(smUser.getUserId());
userValidator.afterCheck(vo);
// 判断手机号是否重复
if (StringUtils.hasText(data.getPhonenumber())) {
SmUserVo repeatPhone = selectUserByPhone(data.getPhonenumber());
ServiceUtil.assertion(repeatPhone != null && !Objects.equals(repeatPhone.getUserId(), data.getUserId()), "用户手机号重复");
}
// 判断微信openId是否重复
SmUserVo repeatWxOpenId = selectUserByWxOpenId(data.getWxOpenId());
ServiceUtil.assertion(repeatWxOpenId != null && repeatWxOpenId.getWxOpenId() != null &&
!Objects.equals(repeatWxOpenId.getUserId(), data.getUserId()), "用户微信openId重复");
return insert;
});
return result == null ? 0 : result;
}
// 根据微信openId查询信息
@ -640,12 +624,22 @@ public class SmUserServiceImpl implements ISmUserService
@Override
public int updateSmUser(SmUser smUser)
{
this.validate(smUser, true);
if (StringUtils.hasText(smUser.getPassword())) {
smUser.setPassword(SecurityUtils.encryptPassword(smUser.getPassword()));
}
smUser.setUpdateTime(DateUtils.getNowDate());
return smUserMapper.updateSmUser(smUser);
Integer result = transactionTemplate.execute(status -> {
int update = smUserMapper.updateSmUser(smUser);
ServiceUtil.assertion(update != 1, "更新用户失败");
SmUserVo vo = this.selectSmUserByUserId(smUser.getUserId());
userValidator.afterCheck(vo);
return update;
});
return result == null ? 0 : result;
}
/**

View File

@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.ValidateResult;
import com.ruoyi.common.enums.UserStatus;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.user.domain.SmUserQuery;
import com.ruoyi.ss.user.domain.SmUserVo;
import com.ruoyi.ss.user.service.ISmUserService;
@ -13,8 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
/**
* @author wjh
@ -26,6 +30,9 @@ public class UserValidatorImpl extends BaseValidator implements UserValidator {
@Autowired
private ISmUserService userService;
@Autowired
private DeviceService deviceService;
/**
* 判断用户是否存在
*
@ -104,4 +111,53 @@ public class UserValidatorImpl extends BaseValidator implements UserValidator {
ServiceUtil.assertion(repeatCount > 1, "用户手机号重复");
}
}
@Override
public void afterCheck(SmUserVo vo) {
if (vo == null) {
return;
}
// 校验手机号
this.checkMobile(vo);
// 校验openId
this.checkOpenId(vo);
// 校验代理商服务费
this.checkAgentServiceRate(vo);
}
private void checkAgentServiceRate(SmUserVo vo) {
if (vo == null) {
return;
}
// 代理服务费不允许大于代理商默认设备服务费
BigDecimal agentRate = vo.getAgentServiceRate();
BigDecimal deviceRate = vo.getAgentDeviceService();
ServiceUtil.assertion(agentRate != null && deviceRate != null && agentRate.compareTo(deviceRate) > 0,
"代理服务费不允许大于代理默认设备服务费:" + deviceRate + "%");
// 代理服务费不允许大于目前最大的设备服务费
DeviceQuery query = new DeviceQuery();
query.setAgentId(vo.getUserId());
BigDecimal maxDeviceRate = deviceService.selectMaxAgentServiceRate(query);
ServiceUtil.assertion(maxDeviceRate != null && maxDeviceRate.compareTo(agentRate) < 0,
"代理服务费不允许大于目前最大的设备服务费:" + maxDeviceRate + "%");
}
// 判断微信openId是否重复
private void checkOpenId(SmUserVo vo) {
if (vo == null) {
return;
}
if (StringUtils.hasText(vo.getWxOpenId())) {
SmUserQuery query = new SmUserQuery();
query.setWxOpenId(vo.getWxOpenId());
Integer repeatCount = userService.selectCount(query);
ServiceUtil.assertion(repeatCount > 1, "用户微信OpenId重复");
}
}
}

View File

@ -2,6 +2,9 @@ package com.ruoyi.web.controller.ss;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordQuery;
import com.ruoyi.ss.deviceBindRecord.domain.DeviceBindRecordVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -13,8 +16,7 @@ import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.deviceBindRecord.domain.SmDeviceBindRecord;
import com.ruoyi.ss.deviceBindRecord.service.ISmDeviceBindRecordService;
import com.ruoyi.ss.deviceBindRecord.service.DeviceBindRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
@ -29,17 +31,17 @@ import com.ruoyi.common.core.page.TableDataInfo;
public class SmDeviceBindRecordController extends BaseController
{
@Autowired
private ISmDeviceBindRecordService smDeviceBindRecordService;
private DeviceBindRecordService smDeviceBindRecordService;
/**
* 查询设备绑定记录列表
*/
@PreAuthorize("@ss.hasPermi('system:bindRecord:list')")
@GetMapping("/list")
public TableDataInfo list(SmDeviceBindRecord smDeviceBindRecord)
public TableDataInfo list(DeviceBindRecordQuery deviceBindRecord)
{
startPage();
List<SmDeviceBindRecord> list = smDeviceBindRecordService.selectSmDeviceBindRecordList(smDeviceBindRecord);
List<DeviceBindRecordVO> list = smDeviceBindRecordService.selectSmDeviceBindRecordList(deviceBindRecord);
return getDataTable(list);
}
@ -49,10 +51,10 @@ public class SmDeviceBindRecordController extends BaseController
@PreAuthorize("@ss.hasPermi('system:bindRecord:export')")
@Log(title = "设备绑定记录", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SmDeviceBindRecord smDeviceBindRecord)
public void export(HttpServletResponse response, DeviceBindRecordQuery deviceBindRecord)
{
List<SmDeviceBindRecord> list = smDeviceBindRecordService.selectSmDeviceBindRecordList(smDeviceBindRecord);
ExcelUtil<SmDeviceBindRecord> util = new ExcelUtil<SmDeviceBindRecord>(SmDeviceBindRecord.class);
List<DeviceBindRecordVO> list = smDeviceBindRecordService.selectSmDeviceBindRecordList(deviceBindRecord);
ExcelUtil<DeviceBindRecordVO> util = new ExcelUtil<DeviceBindRecordVO>(DeviceBindRecordVO.class);
util.exportExcel(response, list, "设备绑定记录数据");
}

View File

@ -202,7 +202,7 @@ public class SmDeviceController extends BaseController
return success(deviceService.batchUpdateModel(dto));
}
@ApiOperation("解除设备绑定")
@ApiOperation("解除设备绑定商户")
@PreAuthorize("@ss.hasPermi('system:device:unbind')")
@Log(title = "设备", businessType = BusinessType.OTHER)
@DeleteMapping("/{deviceId}/unbind")
@ -218,4 +218,25 @@ public class SmDeviceController extends BaseController
return toAjax(deviceService.updateServiceRate(data));
}
@PreAuthorize("@ss.hasPermi('system:device:unbindAgent')")
@Log(title = "设备解绑代理商", businessType = BusinessType.OTHER)
@DeleteMapping("/{deviceId}/unbindAgent")
public AjaxResult unbindAgent(@PathVariable @ApiParam("设备id") Long deviceId) {
return toAjax(deviceService.unbindAgent(deviceId));
}
@PreAuthorize("@ss.hasPermi('system:device:bindMch')")
@Log(title = "设备绑定商户", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/bindMch")
public AjaxResult bindMch(@PathVariable @ApiParam("设备id") Long deviceId, @RequestParam Long mchId) {
return AjaxResult.success("操作成功", deviceService.bindMch(deviceId, mchId));
}
@PreAuthorize("@ss.hasPermi('system:device:binAgent')")
@Log(title = "设备绑定代理商", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/bindAgent")
public AjaxResult bindAgent(@PathVariable @ApiParam("设备id") Long deviceId, @RequestParam Long agentId, @RequestParam BigDecimal agentServiceRate) {
return toAjax(deviceService.bindAgent(deviceId, agentId, agentServiceRate));
}
}