diff --git a/smart-switch-service/src/main/java/com/ruoyi/common/constants/DictTypeConstants.java b/smart-switch-service/src/main/java/com/ruoyi/common/constants/DictTypeConstants.java index b5c484e6..00df14f7 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/common/constants/DictTypeConstants.java +++ b/smart-switch-service/src/main/java/com/ruoyi/common/constants/DictTypeConstants.java @@ -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"; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/common/validRule/apiPriceExist/ApiPriceExist.java b/smart-switch-service/src/main/java/com/ruoyi/common/validRule/apiPriceExist/ApiPriceExist.java new file mode 100644 index 00000000..01431bfb --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/common/validRule/apiPriceExist/ApiPriceExist.java @@ -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[] 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(); + } +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/common/validRule/apiPriceExist/ApiPriceExistValidator.java b/smart-switch-service/src/main/java/com/ruoyi/common/validRule/apiPriceExist/ApiPriceExistValidator.java new file mode 100644 index 00000000..bac221ec --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/common/validRule/apiPriceExist/ApiPriceExistValidator.java @@ -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 { + + 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); + } + } +} + diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java index ee68e8fb..f7a9e9fa 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java @@ -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); /** * 获取设备在线状态 diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java index 2fe9f2d2..7b631051 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java @@ -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; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/access/domain/Access.java b/smart-switch-service/src/main/java/com/ruoyi/ss/access/domain/Access.java index 871aec08..a4f84074 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/access/domain/Access.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/access/domain/Access.java @@ -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; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/access/mapper/AccessMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/access/mapper/AccessMapper.xml index 308f0fb3..5620420c 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/access/mapper/AccessMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/access/mapper/AccessMapper.xml @@ -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" access_key, access_secret, create_time, + expire_time, + surplus_count, #{userId}, #{accessKey}, #{accessSecret}, #{createTime}, + #{expireTime}, + #{surplusCount}, @@ -74,6 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" access_key = #{accessKey}, access_secret = #{accessSecret}, create_time = #{createTime}, + expire_time = #{expireTime}, + surplus_count = #{surplusCount}, where access_id = #{accessId} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessValidator.java b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessValidator.java new file mode 100644 index 00000000..b085591c --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessValidator.java @@ -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); + +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessValidatorImpl.java new file mode 100644 index 00000000..db1612ce --- /dev/null +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessValidatorImpl.java @@ -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); + } +} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/domain/ApiPrice.java b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/domain/ApiPrice.java index d90de0b9..4f9438bf 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/domain/ApiPrice.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/domain/ApiPrice.java @@ -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; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.java index fec1ccb3..45c39084 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.java @@ -61,4 +61,14 @@ public interface ApiPriceMapper * @return 结果 */ public int deleteApiPriceByIds(Long[] ids); + + /** + * 逻辑删除 + */ + int logicDel(@Param("ids") List ids); + + /** + * 查询一个 + */ + ApiPriceVO selectOne(@Param("query") ApiPriceQuery query); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.xml index 066cd3fc..20e52f06 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/mapper/ApiPriceMapper.xml @@ -8,31 +8,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 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 - and id = #{query.id} - and type = #{query.type} - and unit = #{query.unit} - and name like concat('%', #{query.name}, '%') - and description like concat('%', #{query.description}, '%') - and price = #{query.price} - and create_by like concat('%', #{query.createBy}, '%') - and update_by like concat('%', #{query.updateBy}, '%') - and deleted = #{query.deleted} + and sap.id = #{query.id} + and sap.type = #{query.type} + and sap.`name` like concat('%', #{query.name}, '%') + and sap.`description` like concat('%', #{query.description}, '%') + and sap.price = #{query.price} + and sap.create_by like concat('%', #{query.createBy}, '%') + and sap.update_by like concat('%', #{query.updateBy}, '%') + and sap.deleted = #{query.deleted} + and sap.deleted = false + + insert into ss_api_price type, num, - unit, - name, - description, + `name`, + `description`, price, create_time, create_by, @@ -65,7 +71,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{type}, #{num}, - #{unit}, #{name}, #{description}, #{price}, @@ -82,9 +87,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" type = #{data.type}, num = #{data.num}, - unit = #{data.unit}, - name = #{data.name}, - description = #{data.description}, + `name` = #{data.name}, + `description` = #{data.description}, price = #{data.price}, create_time = #{data.createTime}, create_by = #{data.createBy}, @@ -95,6 +99,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{data.id} + + update ss_api_price + set deleted = true + where id in + + #{id} + + + delete from ss_api_price where id = #{id} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/IApiPriceService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/ApiPriceService.java similarity index 87% rename from smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/IApiPriceService.java rename to smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/ApiPriceService.java index f845dd90..e6d7f7e4 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/IApiPriceService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/ApiPriceService.java @@ -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 ids); + + /** + * 查询一个 + */ + ApiPriceVO selectOne(ApiPriceQuery query); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/impl/ApiPriceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/impl/ApiPriceServiceImpl.java index b0fdfb6f..a371f099 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/impl/ApiPriceServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/apiPrice/service/impl/ApiPriceServiceImpl.java @@ -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 ids) { + return apiPriceMapper.logicDel(ids); + } + + @Override + public ApiPriceVO selectOne(ApiPriceQuery query) { + return apiPriceMapper.selectOne(query); + } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml index 3279c315..a1366bcc 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml @@ -28,10 +28,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and sd.device_no like concat('%', #{deviceNo}, '%') - and sd.rent_time is null or sd.rent_time <= now() + and (sd.rent_time is null or sd.rent_time <= now()) - and sd.rent_time is not null and sd.rent_time > now() + and (sd.rent_time is not null and sd.rent_time > now()) diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java index a321facb..f665b3cb 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java @@ -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; diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java index b91c5dcf..b78bee29 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java @@ -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 diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java index 9462dfd3..5369d142 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java @@ -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)); + } + } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppApiPriceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppApiPriceController.java new file mode 100644 index 00000000..8ad8aade --- /dev/null +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppApiPriceController.java @@ -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)); + } + + +} diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/ApiPriceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/ApiPriceController.java index 89792e51..943ac703 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/ApiPriceController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/ApiPriceController.java @@ -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 ids) { - return toAjax(apiPriceService.deleteApiPriceByIds(ids)); + return toAjax(apiPriceService.logicDel(ids)); } } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java index aa6a32ac..1b3d6984 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/SmDeviceController.java @@ -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 list = smDeviceService.selectSmDeviceList(smDevice); - deviceAssembler.assembleIotDeviceInfo(list); + List 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 list = smDeviceService.selectListByIds(Arrays.asList(ids)); + List 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 list = smDeviceService.selectSmDeviceList(smDevice); + List list = deviceService.selectSmDeviceList(smDevice); ExcelUtil util = new ExcelUtil(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 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)); } }