API收费及各种优化

This commit is contained in:
墨大叔 2024-08-08 17:54:35 +08:00
parent 50b70e14ce
commit 66b948e120
21 changed files with 350 additions and 79 deletions

View File

@ -13,4 +13,6 @@ public class DictTypeConstants {
public static final String SERVICE_TYPE = "service_type";
// 提现打款方式
public static final String WITHDRAW_TYPE = "withdraw_type";
// API收费标准类型
public static final String API_PRICE_TYPE = "api_price_type";
}

View File

@ -0,0 +1,35 @@
package com.ruoyi.common.validRule.apiPriceExist;
import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;
/**
* 判断设备是否存在
* @author wjh
* 2024/6/13
*/
@Documented
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(ApiPriceExist.List.class)
@Constraint(validatedBy = { ApiPriceExistValidator.class })
public @interface ApiPriceExist {
String message() default "{*.validation.constraint.Enum.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
/**
* 是否允许null值默认是允许
*/
boolean allowNull() default true;
@Documented
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE })
@Retention(RetentionPolicy.RUNTIME)
@interface List {
ApiPriceExist[] value();
}
}

View File

@ -0,0 +1,44 @@
package com.ruoyi.common.validRule.apiPriceExist;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.ss.apiPrice.domain.ApiPriceQuery;
import com.ruoyi.ss.apiPrice.service.ApiPriceService;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* 2023/10/20
* 枚举值校验
*/
public class ApiPriceExistValidator implements ConstraintValidator<ApiPriceExist, Long> {
private ApiPriceExist annotation;
@Override
public void initialize(ApiPriceExist constraintAnnotation) {
this.annotation = constraintAnnotation;
}
/**
* 判断是否校验成功
* @param value 待校验的值
* @return 校验结果
*/
@Override
public boolean isValid(Long value, ConstraintValidatorContext context) {
// 如果待校验的值为null是否校验通过
if (value == null) {
return annotation.allowNull();
}
try {
ApiPriceService service = SpringUtils.getBean(ApiPriceService.class);
ApiPriceQuery query = new ApiPriceQuery();
query.setId(value);
return service.selectOne(query) != null;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -22,7 +22,19 @@ public interface IotService {
* @param command 命令字符串
* @return
*/
CommandResponse sendCommand(String deviceName, String command);
default CommandResponse sendCommand(String deviceName, String command) {
return sendCommand(deviceName, command, null);
}
/**
* 向设备发送命令
*
* @param deviceName OneNet设备名称即设备表的MAC号
* @param command 命令字符串
* @param timeout
* @return
*/
CommandResponse sendCommand(String deviceName, String command, Integer timeout);
/**
* 获取设备在线状态

View File

@ -53,7 +53,7 @@ public class IotServiceImpl implements IotService {
private String accessKey;
@Value(value = "${sm.timeout}")
private String timeout;
private Integer timeout;
@Value(value = "${sm.daysToExpire}")
private Long daysToExpire;
@ -190,7 +190,7 @@ public class IotServiceImpl implements IotService {
if (seconds < 0) {
throw new ServiceException("设置剩余时长参数错误读数不允许小于0");
}
return sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR);
return sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR, 5);
}
/**
@ -256,7 +256,10 @@ public class IotServiceImpl implements IotService {
// 发送MQTT命令
@Override
public CommandResponse sendCommand(String deviceName, String command) {
public CommandResponse sendCommand(String deviceName, String command, Integer timeout) {
if (timeout == null) {
timeout = this.timeout;
}
String sendUrl = iotHost + IotConstants.ADDS_COMMAND;
String param = "device_name=" + deviceName + "&product_id=" + productId +"&timeout=" + timeout;
sendUrl = sendUrl + "?" + param;

View File

@ -2,12 +2,15 @@ package com.ruoyi.ss.access.domain;
import com.ruoyi.common.annotation.Sensitive;
import com.ruoyi.common.enums.DesensitizedType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import java.time.LocalDateTime;
/**
* 第三方API秘钥对对象 ss_access
*
@ -34,4 +37,10 @@ public class Access extends BaseEntity
@Excel(name = "秘钥")
@Sensitive(desensitizedType = DesensitizedType.PASSWORD)
private String accessSecret;
@ApiModelProperty("到期时间")
private LocalDateTime expireTime;
@ApiModelProperty("剩余调用次数")
private Integer surplusCount;
}

View File

@ -13,6 +13,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sa.access_key,
sa.access_secret,
sa.create_time,
sa.expire_time,
sa.surplus_count,
su.user_name as user_name
from ss_access sa
left join sm_user su on su.user_id = sa.user_id
@ -58,12 +60,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="accessKey != null and accessKey != ''">access_key,</if>
<if test="accessSecret != null and accessSecret != ''">access_secret,</if>
<if test="createTime != null">create_time,</if>
<if test="expireTime != null">expire_time,</if>
<if test="surplusCount != null">surplus_count,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if>
<if test="accessKey != null and accessKey != ''">#{accessKey},</if>
<if test="accessSecret != null and accessSecret != ''">#{accessSecret},</if>
<if test="createTime != null">#{createTime},</if>
<if test="expireTime != null">#{expireTime},</if>
<if test="surplusCount != null">#{surplusCount},</if>
</trim>
</insert>
@ -74,6 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="accessKey != null and accessKey != ''">access_key = #{accessKey},</if>
<if test="accessSecret != null and accessSecret != ''">access_secret = #{accessSecret},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="expireTime != null">expire_time = #{expireTime},</if>
<if test="surplusCount != null">surplus_count = #{surplusCount},</if>
</trim>
where access_id = #{accessId}
</update>

View File

@ -0,0 +1,16 @@
package com.ruoyi.ss.access.service;
import com.ruoyi.ss.access.domain.Access;
/**
* @author wjh
* 2024/8/8
*/
public interface AccessValidator {
/**
* 秘钥是否属于用户
*/
boolean isBelong(Access access, Long userId);
}

View File

@ -0,0 +1,26 @@
package com.ruoyi.ss.access.service.impl;
import com.ruoyi.ss.access.domain.Access;
import com.ruoyi.ss.access.service.AccessService;
import com.ruoyi.ss.access.service.AccessValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author wjh
* 2024/8/8
*/
@Service
public class AccessValidatorImpl implements AccessValidator {
@Autowired
private AccessService accessService;
/**
* 秘钥是否属于用户
*/
@Override
public boolean isBelong(Access access, Long userId) {
return access != null && access.getUserId() != null && access.getUserId().equals(userId);
}
}

View File

@ -1,6 +1,11 @@
package com.ruoyi.ss.apiPrice.domain;
import java.math.BigDecimal;
import com.ruoyi.common.constants.DictTypeConstants;
import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.validRule.apiPriceExist.ApiPriceExist;
import com.ruoyi.system.valid.DictValid;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
@ -8,6 +13,11 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* API收费标准对象 ss_api_price
*
@ -19,30 +29,36 @@ public class ApiPrice extends BaseEntity
{
private static final long serialVersionUID = 1L;
@ApiPriceExist(message = "API收费标准不存在", groups = {ValidGroup.Update.class})
private Long id;
@Excel(name = "类型")
@ApiModelProperty("类型")
@NotBlank(message = "类型不允许为空", groups = {ValidGroup.Create.class})
@DictValid(type = DictTypeConstants.API_PRICE_TYPE, message = "非法的类型")
private String type;
@Excel(name = "数值")
@ApiModelProperty("数值")
private Long num;
@Excel(name = "单位")
@ApiModelProperty("单位")
private String unit;
@Excel(name = "标准")
@ApiModelProperty("标准")
@NotNull(message = "标准不允许为空", groups = {ValidGroup.Create.class})
@Min(value = 0, message = "标准不允许小于0")
private Integer num;
@Excel(name = "标准名称")
@ApiModelProperty("标准名称")
@NotBlank(message = "标准名称不允许为空", groups = {ValidGroup.Create.class})
@Size(max = 50, message = "标准名称长度不能超过50个字符")
private String name;
@Excel(name = "标准描述")
@ApiModelProperty("标准描述")
@Size(max = 200, message = "标准描述长度不能超过200个字符")
private String description;
@Excel(name = "价格", readConverterExp = "元=")
@ApiModelProperty("价格")
@NotNull(message = "价格不允许为空", groups = {ValidGroup.Create.class})
@Min(value = 0, message = "价格不允许小于0")
private BigDecimal price;
}

View File

@ -61,4 +61,14 @@ public interface ApiPriceMapper
* @return 结果
*/
public int deleteApiPriceByIds(Long[] ids);
/**
* 逻辑删除
*/
int logicDel(@Param("ids") List<Long> ids);
/**
* 查询一个
*/
ApiPriceVO selectOne(@Param("query") ApiPriceQuery query);
}

View File

@ -8,31 +8,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectApiPriceVo">
select
id,
type,
num,
unit,
name,
description,
price,
create_time,
create_by,
update_time,
update_by,
deleted
from ss_api_price
sap.id,
sap.type,
sap.num,
sap.name,
sap.description,
sap.price,
sap.create_time,
sap.create_by,
sap.update_time,
sap.update_by,
sap.deleted
from ss_api_price sap
</sql>
<sql id="searchCondition">
<if test="query.id != null "> and id = #{query.id}</if>
<if test="query.type != null and query.type != ''"> and type = #{query.type}</if>
<if test="query.unit != null and query.unit != ''"> and unit = #{query.unit}</if>
<if test="query.name != null and query.name != ''"> and name like concat('%', #{query.name}, '%')</if>
<if test="query.description != null and query.description != ''"> and description like concat('%', #{query.description}, '%')</if>
<if test="query.price != null "> and price = #{query.price}</if>
<if test="query.createBy != null and query.createBy != ''"> and create_by like concat('%', #{query.createBy}, '%')</if>
<if test="query.updateBy != null "> and update_by like concat('%', #{query.updateBy}, '%')</if>
<if test="query.deleted != null "> and deleted = #{query.deleted}</if>
<if test="query.id != null "> and sap.id = #{query.id}</if>
<if test="query.type != null and query.type != ''"> and sap.type = #{query.type}</if>
<if test="query.name != null and query.name != ''"> and sap.`name` like concat('%', #{query.name}, '%')</if>
<if test="query.description != null and query.description != ''"> and sap.`description` like concat('%', #{query.description}, '%')</if>
<if test="query.price != null "> and sap.price = #{query.price}</if>
<if test="query.createBy != null and query.createBy != ''"> and sap.create_by like concat('%', #{query.createBy}, '%')</if>
<if test="query.updateBy != null "> and sap.update_by like concat('%', #{query.updateBy}, '%')</if>
<if test="query.deleted != null "> and sap.deleted = #{query.deleted}</if>
<if test="query.deleted == null "> and sap.deleted = false</if>
</sql>
<select id="selectApiPriceList" parameterType="ApiPriceQuery" resultMap="ApiPriceResult">
@ -47,14 +46,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</select>
<select id="selectOne" resultMap="ApiPriceResult">
<include refid="selectApiPriceVo"/>
<where>
<include refid="searchCondition"/>
</where>
limit 1
</select>
<insert id="insertApiPrice" parameterType="ApiPrice" useGeneratedKeys="true" keyProperty="id">
insert into ss_api_price
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="type != null">type,</if>
<if test="num != null">num,</if>
<if test="unit != null">unit,</if>
<if test="name != null">name,</if>
<if test="description != null">description,</if>
<if test="name != null">`name`,</if>
<if test="description != null">`description`,</if>
<if test="price != null">price,</if>
<if test="createTime != null">create_time,</if>
<if test="createBy != null">create_by,</if>
@ -65,7 +71,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="type != null">#{type},</if>
<if test="num != null">#{num},</if>
<if test="unit != null">#{unit},</if>
<if test="name != null">#{name},</if>
<if test="description != null">#{description},</if>
<if test="price != null">#{price},</if>
@ -82,9 +87,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=",">
<if test="data.type != null">type = #{data.type},</if>
<if test="data.num != null">num = #{data.num},</if>
<if test="data.unit != null">unit = #{data.unit},</if>
<if test="data.name != null">name = #{data.name},</if>
<if test="data.description != null">description = #{data.description},</if>
<if test="data.name != null">`name` = #{data.name},</if>
<if test="data.description != null">`description` = #{data.description},</if>
<if test="data.price != null">price = #{data.price},</if>
<if test="data.createTime != null">create_time = #{data.createTime},</if>
<if test="data.createBy != null">create_by = #{data.createBy},</if>
@ -95,6 +99,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{data.id}
</update>
<update id="logicDel">
update ss_api_price
set deleted = true
where id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="deleteApiPriceById" parameterType="Long">
delete from ss_api_price where id = #{id}
</delete>

View File

@ -11,7 +11,7 @@ import com.ruoyi.ss.apiPrice.domain.ApiPriceQuery;
* @author ruoyi
* @date 2024-08-08
*/
public interface IApiPriceService
public interface ApiPriceService
{
/**
* 查询API收费标准
@ -60,4 +60,14 @@ public interface IApiPriceService
* @return 结果
*/
public int deleteApiPriceById(Long id);
/**
* 逻辑删除
*/
int logicDel(List<Long> ids);
/**
* 查询一个
*/
ApiPriceVO selectOne(ApiPriceQuery query);
}

View File

@ -8,7 +8,7 @@ import com.ruoyi.ss.apiPrice.mapper.ApiPriceMapper;
import com.ruoyi.ss.apiPrice.domain.ApiPrice;
import com.ruoyi.ss.apiPrice.domain.ApiPriceVO;
import com.ruoyi.ss.apiPrice.domain.ApiPriceQuery;
import com.ruoyi.ss.apiPrice.service.IApiPriceService;
import com.ruoyi.ss.apiPrice.service.ApiPriceService;
/**
* API收费标准Service业务层处理
@ -17,7 +17,7 @@ import com.ruoyi.ss.apiPrice.service.IApiPriceService;
* @date 2024-08-08
*/
@Service
public class ApiPriceServiceImpl implements IApiPriceService
public class ApiPriceServiceImpl implements ApiPriceService
{
@Autowired
private ApiPriceMapper apiPriceMapper;
@ -95,4 +95,14 @@ public class ApiPriceServiceImpl implements IApiPriceService
{
return apiPriceMapper.deleteApiPriceById(id);
}
@Override
public int logicDel(List<Long> ids) {
return apiPriceMapper.logicDel(ids);
}
@Override
public ApiPriceVO selectOne(ApiPriceQuery query) {
return apiPriceMapper.selectOne(query);
}
}

View File

@ -28,10 +28,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceNo != null"> and sd.device_no like concat('%', #{deviceNo}, '%')</if>
<if test="isArrears != null">
<if test="isArrears">
and sd.rent_time is null or sd.rent_time &lt;= now()
and (sd.rent_time is null or sd.rent_time &lt;= now())
</if>
<if test="!isArrears">
and sd.rent_time is not null and sd.rent_time > now()
and (sd.rent_time is not null and sd.rent_time > now())
</if>
</if>
<if test="deviceIds != null and deviceIds.size() > 0">

View File

@ -423,7 +423,7 @@ public class DeviceServiceImpl implements DeviceService
long betweenSeconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds();
if (betweenSeconds > 0) {
CommandResponse rechargeResult = iotService.setTime(device.getMac(), betweenSeconds);
ServiceUtil.assertion(!rechargeResult.isSuccess(), "设备充值失败,请检查设备是否在线或联系管理员");
return rechargeResult.isSuccess();
}
}
return Boolean.TRUE;

View File

@ -12,6 +12,7 @@ import com.ruoyi.ss.channel.domain.ChannelVO;
import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO;
import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService;
import com.ruoyi.ss.dashboard.BillCountVo;
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.receiveBill.service.ReceiveBillService;
@ -615,8 +616,14 @@ public class TransactionBillServiceImpl implements TransactionBillService {
ServiceUtil.assertion(TransactionBillDeviceRechargeStatus.BLUETOOTH.getStatus().equals(bill.getDeviceRechargeStatus()), "设备已选择蓝牙充值,请使用蓝牙进行充值");
Boolean result = transactionTemplate.execute(status -> {
// 更新套餐生效时间
DeviceVO device = deviceService.selectSmDeviceByDeviceId(bill.getDeviceId());
// 如果设备离线则直接返回失败
if (DeviceOnlineStatus.OFFLINE.getStatus().equals(device.getOnlineStatus())) {
return false;
}
// 更新套餐生效时间
this.updateSuitTimeBeforeDevice(billId, device.getExpireTime());
// 修改设备充值状态成功
@ -694,7 +701,7 @@ public class TransactionBillServiceImpl implements TransactionBillService {
}
/**
* 充值成功
* 充值成功处理
* @param billNo 充值订单编号
*/
@Override

View File

@ -6,6 +6,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.access.domain.AccessQuery;
import com.ruoyi.ss.access.domain.AccessVO;
import com.ruoyi.ss.access.service.AccessService;
import com.ruoyi.ss.access.service.AccessValidator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -25,6 +26,9 @@ public class AppAccessController extends BaseController {
@Autowired
private AccessService accessService;
@Autowired
private AccessValidator accessValidator;
@ApiOperation("申请accessKey")
@PostMapping
public AjaxResult apply() {
@ -35,8 +39,8 @@ public class AppAccessController extends BaseController {
@PutMapping("/{accessId}/reset")
public AjaxResult reset(@PathVariable Long accessId) {
AccessVO access = accessService.selectAccessByAccessId(accessId);
if (access == null || !Objects.equals(access.getUserId(), getUserId())) {
return error("您无权操作");
if (!accessValidator.isBelong(access, getUserId())) {
return error("这不是您的秘钥,您无权操作");
}
return AjaxResult.success("操作成功", accessService.reset(accessId));
}
@ -50,4 +54,14 @@ public class AppAccessController extends BaseController {
return getDataTable(list);
}
@ApiOperation("删除秘钥")
@DeleteMapping("/{id}")
public AjaxResult del(@PathVariable Long id) {
AccessVO access = accessService.selectAccessByAccessId(id);
if (!accessValidator.isBelong(access, getUserId())) {
return error("这不是您的秘钥,无法删除");
}
return toAjax(accessService.deleteAccessByAccessId(id));
}
}

View File

@ -0,0 +1,37 @@
package com.ruoyi.web.controller.app;
import com.fasterxml.jackson.annotation.JsonView;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.JsonViewProfile;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.apiPrice.domain.ApiPriceQuery;
import com.ruoyi.ss.apiPrice.service.ApiPriceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author wjh
* 2024/8/8
*/
@RestController
@RequestMapping("/app/apiPrice")
public class AppApiPriceController extends BaseController {
@Autowired
private ApiPriceService apiPriceService;
@ApiOperation("获取API收费标准列表")
@GetMapping("/list")
@JsonView(JsonViewProfile.App.class)
@Anonymous
public TableDataInfo list(ApiPriceQuery query) {
startPage();
return getDataTable(apiPriceService.selectApiPriceList(query));
}
}

View File

@ -2,8 +2,11 @@ package com.ruoyi.web.controller.ss;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.domain.ValidGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
@ -19,7 +22,7 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.apiPrice.domain.ApiPrice;
import com.ruoyi.ss.apiPrice.domain.ApiPriceVO;
import com.ruoyi.ss.apiPrice.domain.ApiPriceQuery;
import com.ruoyi.ss.apiPrice.service.IApiPriceService;
import com.ruoyi.ss.apiPrice.service.ApiPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
@ -34,7 +37,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
public class ApiPriceController extends BaseController
{
@Autowired
private IApiPriceService apiPriceService;
private ApiPriceService apiPriceService;
/**
* 查询API收费标准列表
@ -78,8 +81,9 @@ public class ApiPriceController extends BaseController
@PreAuthorize("@ss.hasPermi('ss:apiPrice:add')")
@Log(title = "API收费标准", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ApiPrice apiPrice)
public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) ApiPrice apiPrice)
{
apiPrice.setCreateBy(getUsername());
return toAjax(apiPriceService.insertApiPrice(apiPrice));
}
@ -89,8 +93,9 @@ public class ApiPriceController extends BaseController
@PreAuthorize("@ss.hasPermi('ss:apiPrice:edit')")
@Log(title = "API收费标准", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ApiPrice apiPrice)
public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) ApiPrice apiPrice)
{
apiPrice.setUpdateBy(getUsername());
return toAjax(apiPriceService.updateApiPrice(apiPrice));
}
@ -100,8 +105,8 @@ public class ApiPriceController extends BaseController
@PreAuthorize("@ss.hasPermi('ss:apiPrice:remove')")
@Log(title = "API收费标准", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
public AjaxResult remove(@PathVariable List<Long> ids)
{
return toAjax(apiPriceService.deleteApiPriceByIds(ids));
return toAjax(apiPriceService.logicDel(ids));
}
}

View File

@ -34,10 +34,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
public class SmDeviceController extends BaseController
{
@Autowired
private DeviceService smDeviceService;
@Autowired
private DeviceAssembler deviceAssembler;
private DeviceService deviceService;
/**
* 查询设备列表
@ -47,8 +44,7 @@ public class SmDeviceController extends BaseController
public TableDataInfo list(DeviceQuery smDevice)
{
startPage();
List<DeviceVO> list = smDeviceService.selectSmDeviceList(smDevice);
deviceAssembler.assembleIotDeviceInfo(list);
List<DeviceVO> list = deviceService.selectSmDeviceList(smDevice);
return getDataTable(list);
}
@ -60,7 +56,7 @@ public class SmDeviceController extends BaseController
@GetMapping("/listByIds/{ids}")
public AjaxResult listByIds(@PathVariable Long[] ids)
{
List<DeviceVO> list = smDeviceService.selectListByIds(Arrays.asList(ids));
List<DeviceVO> list = deviceService.selectListByIds(Arrays.asList(ids));
return success(list);
}
@ -72,7 +68,7 @@ public class SmDeviceController extends BaseController
@PostMapping("/export")
public void export(HttpServletResponse response, DeviceQuery smDevice)
{
List<DeviceVO> list = smDeviceService.selectSmDeviceList(smDevice);
List<DeviceVO> list = deviceService.selectSmDeviceList(smDevice);
ExcelUtil<DeviceVO> util = new ExcelUtil<DeviceVO>(DeviceVO.class);
util.exportExcel(response, list, "设备数据");
}
@ -83,9 +79,7 @@ public class SmDeviceController extends BaseController
@PreAuthorize("@ss.hasPermi('system:device:query')")
@GetMapping(value = "/{deviceId}")
public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) {
DeviceVO device = smDeviceService.selectSmDeviceByDeviceId(deviceId);
List<DeviceVO> list = Collections.singletonList(device);
deviceAssembler.assembleIotDeviceInfo(list);
DeviceVO device = deviceService.selectSmDeviceByDeviceId(deviceId);
return success(device);
}
@ -98,7 +92,7 @@ public class SmDeviceController extends BaseController
public AjaxResult add(@RequestBody @Validated({ValidGroup.Create.class}) DeviceBO data)
{
data = data.filterCreate();
return toAjax(smDeviceService.insertSmDevice(data));
return toAjax(deviceService.insertSmDevice(data));
}
/**
@ -110,7 +104,7 @@ public class SmDeviceController extends BaseController
public AjaxResult edit(@RequestBody @Validated({ValidGroup.Update.class}) DeviceBO data)
{
data = data.filterUpdate();
return toAjax(smDeviceService.updateSmDevice(data));
return toAjax(deviceService.updateSmDevice(data));
}
/**
@ -121,7 +115,7 @@ public class SmDeviceController extends BaseController
@DeleteMapping("/{deviceIds}")
public AjaxResult remove(@PathVariable Long[] deviceIds)
{
return toAjax(smDeviceService.deleteSmDeviceByDeviceIds(deviceIds));
return toAjax(deviceService.deleteSmDeviceByDeviceIds(deviceIds));
}
@ApiOperation("逻辑删除设备")
@ -130,14 +124,14 @@ public class SmDeviceController extends BaseController
@DeleteMapping("/logic/{deviceIds}")
public AjaxResult logicDel(@PathVariable Long[] deviceIds)
{
return toAjax(smDeviceService.logicDel(Arrays.asList(deviceIds)));
return toAjax(deviceService.logicDel(Arrays.asList(deviceIds)));
}
@ApiOperation("刷新设备信息")
@Log(title = "设备", businessType = BusinessType.UPDATE)
@GetMapping("/{deviceId}/refreshIot")
public AjaxResult syncIot(@PathVariable @ApiParam("设备id") Long deviceId) {
smDeviceService.pullDeviceInfo(Collections.singletonList(deviceId));
deviceService.pullDeviceInfo(Collections.singletonList(deviceId));
return success();
}
@ -146,7 +140,7 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.UPDATE)
@PutMapping("/{deviceId}/bindSn/{sn}")
public AjaxResult bindSn(@PathVariable @ApiParam("设备ID") Long deviceId, @PathVariable @ApiParam("SN") String sn) {
return success(smDeviceService.bindSn(deviceId, sn));
return success(deviceService.bindSn(deviceId, sn));
}
@ApiOperation("设备充值时长")
@ -154,7 +148,7 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.OTHER)
@PutMapping("/addTime/{deviceId}")
public AjaxResult addTime(@PathVariable @ApiParam("设备id") Long deviceId, @ApiParam("时长(分)") Long amount) {
return toAjax(smDeviceService.addTimeByUser(deviceId, amount * 60, true, "管理员手动充值"));
return toAjax(deviceService.addTimeByUser(deviceId, amount * 60, true, "管理员手动充值"));
}
@ApiOperation("设备时长归零")
@ -162,7 +156,7 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/reset")
public AjaxResult reset(@PathVariable @ApiParam("设备id") Long deviceId) {
return success(smDeviceService.reset(deviceId));
return success(deviceService.reset(deviceId));
}
@ApiOperation("设备开关")
@ -170,7 +164,7 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.OTHER)
@PutMapping("/{deviceId}/switch")
public AjaxResult switchDevice(@PathVariable Long deviceId, @RequestParam Boolean open) {
return toAjax(smDeviceService.switchDevice(deviceId, open));
return toAjax(deviceService.switchDevice(deviceId, open));
}
@ApiOperation("设备批量修改型号")
@ -178,7 +172,7 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.UPDATE)
@PutMapping("/batchUpdateModel")
public AjaxResult batchUpdateModel(@RequestBody @Validated DeviceBatchUpdateModelDTO dto) {
return success(smDeviceService.batchUpdateModel(dto));
return success(deviceService.batchUpdateModel(dto));
}
@ApiOperation("解除设备绑定")
@ -186,7 +180,7 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.OTHER)
@DeleteMapping("/{deviceId}/unbind")
public AjaxResult unbind(@PathVariable @ApiParam("设备id") Long deviceId) {
return toAjax(smDeviceService.unbind(deviceId));
return toAjax(deviceService.unbind(deviceId));
}
@ApiOperation("修改服务费")
@ -194,6 +188,6 @@ public class SmDeviceController extends BaseController
@Log(title = "设备", businessType = BusinessType.UPDATE)
@PutMapping("/updateServiceRate")
public AjaxResult updateServiceRate(@RequestBody @Validated DeviceVO data) {
return toAjax(smDeviceService.updateServiceRate(data));
return toAjax(deviceService.updateServiceRate(data));
}
}