Commit 4c6a24a7 authored by AfirSraftGarrier's avatar AfirSraftGarrier

连接鉴权增加参数

parent 12e91be8
......@@ -69,18 +69,21 @@ public class AuthManager {
if (!allApply.containsKey(appId)) {
return false;
}
if (!deviceManager.getContainSn(sn)) {
return false;
}
DeviceVo device = deviceManager.getDevice(sn);
// 未绑定
if (device.getSnBind() == null) {
return false;
}
int deviceId = device.getDeviceId();
if(deviceBlackMap.containsKey(deviceId)){
if (deviceBlackMap.containsKey(deviceId)) {
return false;
}
Apply apply = allApply.get(appId);
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();
if (CommonUtil.toUpperCaseByEnglish(sign).equals(CommonUtil.toUpperCaseByEnglish(valSHA1))) {
return true;
......
package iot.sixiang.license.mapper;
import iot.sixiang.license.entity.Device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
* Mapper 接口
*
* @author m33
* @since 2022-06-08
*/
public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName);
boolean addDevice(String sn, String appId);
......
......@@ -11,7 +11,6 @@ import java.util.Date;
*/
@Data
public class DeviceVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("设备Id")
......@@ -26,13 +25,15 @@ public class DeviceVo implements Serializable {
@ApiModelProperty("设备编号")
private String sn;
@ApiModelProperty("绑定的设备编号")
private String snBind;
@ApiModelProperty("设备状态 0:正常 1:禁用")
private int blackFlag;
private int blackFlag;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
}
......@@ -6,15 +6,12 @@ import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceVo;
/**
* <p>
* 服务类
* </p>
* 服务类
*
* @author m33
* @since 2022-06-08
*/
public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName);
boolean addDevice(String appId, int count);
......
......@@ -21,25 +21,22 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
* 服务实现类
*
* @author m33
* @since 2022-06-08
*/
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
@Resource
private DeviceMapper deviceMapper;
@Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName) {
if(pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg());
if (pageNo == 0 || pageSize == 0) {
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());
List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......@@ -54,8 +51,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override
public boolean addDevice(String appId, int count) {
if(StringUtils.isEmpty(appId) || count == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMsg());
if (StringUtils.isEmpty(appId) || count == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
for (int i = 0; i < count; i++) {
String sn = CommonUtil.genRandomNum(18);
......
......@@ -3,7 +3,8 @@
<mapper namespace="iot.sixiang.license.mapper.DeviceMapper">
<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 USER AS us ON us.user_id = app.user_id
where 1=1
......@@ -16,7 +17,8 @@
</select>
<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>
</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