Commit 4c6a24a7 authored by AfirSraftGarrier's avatar AfirSraftGarrier

连接鉴权增加参数

parent 12e91be8
...@@ -69,18 +69,21 @@ public class AuthManager { ...@@ -69,18 +69,21 @@ public class AuthManager {
if (!allApply.containsKey(appId)) { if (!allApply.containsKey(appId)) {
return false; return false;
} }
if (!deviceManager.getContainSn(sn)) { if (!deviceManager.getContainSn(sn)) {
return false; return false;
} }
DeviceVo device = deviceManager.getDevice(sn); DeviceVo device = deviceManager.getDevice(sn);
// 未绑定
if (device.getSnBind() == null) {
return false;
}
int deviceId = device.getDeviceId(); int deviceId = device.getDeviceId();
if(deviceBlackMap.containsKey(deviceId)){ if (deviceBlackMap.containsKey(deviceId)) {
return false; return false;
} }
Apply apply = allApply.get(appId); Apply apply = allApply.get(appId);
String appKey = apply.getAppKey(); String appKey = apply.getAppKey();
String input = "app_id=" + appId + "&sn=" + sn; String input = "app_id=" + appId + "&sn=" + sn + "&sn_bind=" + device.getSnBind();
String valSHA1 = HmacUtil.encrypt(input, appKey, HmacUtil.HMAC_SHA1).toUpperCase(); String valSHA1 = HmacUtil.encrypt(input, appKey, HmacUtil.HMAC_SHA1).toUpperCase();
if (CommonUtil.toUpperCaseByEnglish(sign).equals(CommonUtil.toUpperCaseByEnglish(valSHA1))) { if (CommonUtil.toUpperCaseByEnglish(sign).equals(CommonUtil.toUpperCaseByEnglish(valSHA1))) {
return true; return true;
......
package iot.sixiang.license.mapper; package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.vo.DeviceVo; import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List; import java.util.List;
/** /**
* <p> * Mapper 接口
* Mapper 接口
* </p>
* *
* @author m33 * @author m33
* @since 2022-06-08 * @since 2022-06-08
*/ */
public interface DeviceMapper extends BaseMapper<Device> { public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName); List<DeviceVo> getDeviceList(String appName, String userName);
boolean addDevice(String sn, String appId); boolean addDevice(String sn, String appId);
......
...@@ -11,7 +11,6 @@ import java.util.Date; ...@@ -11,7 +11,6 @@ import java.util.Date;
*/ */
@Data @Data
public class DeviceVo implements Serializable { public class DeviceVo implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ApiModelProperty("设备Id") @ApiModelProperty("设备Id")
...@@ -26,13 +25,15 @@ public class DeviceVo implements Serializable { ...@@ -26,13 +25,15 @@ public class DeviceVo implements Serializable {
@ApiModelProperty("设备编号") @ApiModelProperty("设备编号")
private String sn; private String sn;
@ApiModelProperty("绑定的设备编号")
private String snBind;
@ApiModelProperty("设备状态 0:正常 1:禁用") @ApiModelProperty("设备状态 0:正常 1:禁用")
private int blackFlag; private int blackFlag;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
private Date createTime; private Date createTime;
@ApiModelProperty("更新时间") @ApiModelProperty("更新时间")
private Date updateTime; private Date updateTime;
} }
...@@ -6,15 +6,12 @@ import iot.sixiang.license.model.PageInfoModel; ...@@ -6,15 +6,12 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceVo; import iot.sixiang.license.model.vo.DeviceVo;
/** /**
* <p> * 服务类
* 服务类
* </p>
* *
* @author m33 * @author m33
* @since 2022-06-08 * @since 2022-06-08
*/ */
public interface DeviceService extends IService<Device> { public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName); PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName);
boolean addDevice(String appId, int count); boolean addDevice(String appId, int count);
......
...@@ -21,25 +21,22 @@ import java.util.List; ...@@ -21,25 +21,22 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* <p> * 服务实现类
* 服务实现类
* </p>
* *
* @author m33 * @author m33
* @since 2022-06-08 * @since 2022-06-08
*/ */
@Service @Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService { public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
@Resource @Resource
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
@Override @Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) { public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) {
if(pageNo == 0 || pageSize == 0) { if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName,userName); List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList()); deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>(); List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize; int begin = (pageNo - 1) * pageSize;
...@@ -54,8 +51,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -54,8 +51,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override @Override
public boolean addDevice(String appId, int count) { public boolean addDevice(String appId, int count) {
if(StringUtils.isEmpty(appId) || count == 0) { if (StringUtils.isEmpty(appId) || count == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg()); throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
String sn = CommonUtil.genRandomNum(18); String sn = CommonUtil.genRandomNum(18);
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<mapper namespace="iot.sixiang.license.mapper.DeviceMapper"> <mapper namespace="iot.sixiang.license.mapper.DeviceMapper">
<select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceVo"> <select id="getDeviceList" resultType="iot.sixiang.license.model.vo.DeviceVo">
SELECT de.device_id,app_name,user_name,sn,de.create_time,de.update_time,de.device_id IN (select device_id from device_black) AS blackFlag FROM device AS de SELECT de.device_id,app_name,user_name,sn,sn_bind,de.create_time,de.update_time,de.device_id IN (select
device_id from device_black) AS blackFlag FROM device AS de
JOIN apply AS app ON de.app_id = app.app_id JOIN apply AS app ON de.app_id = app.app_id
JOIN USER AS us ON us.user_id = app.user_id JOIN USER AS us ON us.user_id = app.user_id
where 1=1 where 1=1
...@@ -16,7 +17,8 @@ ...@@ -16,7 +17,8 @@
</select> </select>
<insert id="addDevice" parameterType="iot.sixiang.license.entity.Device"> <insert id="addDevice" parameterType="iot.sixiang.license.entity.Device">
insert into device(sn, app_id, create_time, update_time) values (#{sn},#{appId}, now(), now()) insert into device(sn, app_id, create_time, update_time)
values (#{sn}, #{appId}, now(), now())
</insert> </insert>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment