Commit dc9ff49d authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master' into for-yx

parents f725f03f 239c324e
......@@ -7,6 +7,7 @@ import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.service.TerminalDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -41,4 +42,16 @@ public class TerminalDeviceController {
public BaseResult terminalDevieBind(@RequestBody TerminalDevieBindDTO terminalDevieBindDTO) {
return terminalDeviceService.terminalDeviceBind(terminalDevieBindDTO);
}
@PostMapping("/unbind")
@ApiOperation(value = "终端设备解绑接口", notes = "终端设备解绑接口")
public BaseResult terminalDevieunBind(@RequestBody TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
return terminalDeviceService.terminalDeviceunBind(terminalDevieUnBindDTO);
}
@GetMapping("/get_bind_status")
@ApiOperation(value = "获取终端设备绑定状态接口", notes = "获取终端设备绑定状态接口")
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
return terminalDeviceService.getBindStatus(terminalDevieUnBindDTO);
}
}
......@@ -35,6 +35,7 @@ public class JwtFilter implements Filter {
private static final String url11 = "/get_token";
private static final String url12 = "/report_error_msg";
private static final String url13 = "/bind";
private static final String url14 = "/get_bind_status";
@Override
public void init(FilterConfig filterConfig) {
......@@ -89,7 +90,7 @@ public class JwtFilter implements Filter {
return;
}
// 终端设备放行
if (uri.contains(url12) || uri.contains(url13)) {
if (uri.contains(url12) || uri.contains(url13) || uri.contains(url14)) {
filterChain.doFilter(request, response);
return;
}
......
......@@ -16,4 +16,6 @@ public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName, String sn, Integer status);
boolean addDevice(String sn, String appId);
int updateDeviceById(Device device);
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class TerminalDevieUnBindDTO {
@ApiModelProperty("设备SN")
private String snBind;
}
......@@ -28,6 +28,9 @@ public class ResourceVo {
@ApiModelProperty("设备编号")
private String sn;
@ApiModelProperty("绑定的SN")
private String snBind;
@ApiModelProperty("设备状态")
private String status;
......
......@@ -83,6 +83,10 @@ public class ResourceManager {
cell = row.createCell((short)5); //第六个单元格
cell.setCellValue("状态");
cell.setCellStyle(styleRow);
cell = row.createCell((short)6); //第七个单元格
cell.setCellValue("设备编码");
cell.setCellStyle(styleRow);
//第五步插入数据
List<ResourceVo> resourceList = resourceService.getResource(userId);
for (int i = 0; i < resourceList.size(); i++) {
......@@ -114,9 +118,13 @@ public class ResourceManager {
cell = row.createCell((short)5); // 第六个单元格
cell.setCellValue(resourceVo.getStatus());
cell.setCellStyle(style);
cell = row.createCell((short)6); // 第七个单元格
cell.setCellValue(resourceVo.getSnBind());
cell.setCellStyle(style);
}
//在填完所有值以后,对每一列设置自适应宽度
for (int n = 0; n < 6; n++) {
for (int n = 0; n < 7; n++) {
sheet.autoSizeColumn(n);
}
wb.write(os);
......
......@@ -3,7 +3,9 @@ package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
/**
......@@ -18,4 +20,8 @@ public interface DeviceService extends IService<Device> {
boolean addDevice(String appId, int count);
Boolean terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO);
Boolean terminalDevieunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
}
......@@ -5,6 +5,7 @@ import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import java.util.List;
......@@ -14,4 +15,8 @@ public interface TerminalDeviceService {
BaseResult reportErrorMsg(List<ReportErrorMsgDTO> reportErrorMsgDTO);
BaseResult terminalDeviceBind(TerminalDevieBindDTO terminalDevieBindDTO);
BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
}
......@@ -8,7 +8,9 @@ import iot.sixiang.license.entity.Device;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.util.CommonUtil;
......@@ -73,6 +75,16 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
public Boolean terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO) {
String sn = terminalDevieBindDTO.getSn();
String snBind = terminalDevieBindDTO.getSnBind();
LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Device::getSnBind, snBind).last("limit 1");
Device deviceTemp = deviceMapper.selectOne(wrapper);
if (deviceTemp != null) {
if (deviceTemp.getSn().equals(sn)) {
return true;
} else {
throw new IotLicenseException(403, "该设备已绑定了" + deviceTemp.getSn());
}
}
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Device::getSn, sn).last("limit 1");
Device device = deviceMapper.selectOne(queryWrapper);
......@@ -88,7 +100,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
device.setStatus(1);
device.setUpdateTime(new Date());
int res = deviceMapper.updateById(device);
if (res >= 0) {
if (res > 0) {
return true;
} else {
return false;
......@@ -96,4 +108,33 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
}
return false;
}
@Override
public Boolean terminalDevieunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
String snBind = terminalDevieUnBindDTO.getSnBind();
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Device::getSnBind, snBind).last("limit 1");
Device device = deviceMapper.selectOne(queryWrapper);
if (device != null) {
device.setSnBind(null);
device.setStatus(0);
device.setUpdateTime(new Date());
int res = deviceMapper.updateDeviceById(device);
return res > 0;
}
return false;
}
@Override
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
String snBind = terminalDevieUnBindDTO.getSnBind();
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Device::getSnBind, snBind).last("limit 1");
Device device = deviceMapper.selectOne(queryWrapper);
if (device != null) {
return ResResult.success().record(device.getSn());
} else {
return new ResResult(405, "未绑定");
}
}
}
......@@ -10,6 +10,7 @@ import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.TerminalDeviceService;
......@@ -107,4 +108,28 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
return BaseResult.failed();
}
}
@Override
public BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
String snBind = terminalDevieUnBindDTO.getSnBind();
if (StringUtils.isEmpty(snBind)) {
return BaseResult.validate_failed();
}
Boolean res = deviceService.terminalDevieunBind(terminalDevieUnBindDTO);
if (res) {
deviceManager.initDevices();
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
@Override
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
String snBind = terminalDevieUnBindDTO.getSnBind();
if (StringUtils.isEmpty(snBind)) {
return ResResult.validate_failed();
}
return deviceService.getBindStatus(terminalDevieUnBindDTO);
}
}
......@@ -6,7 +6,7 @@
SELECT de.device_id,app_name,user_name,sn,sn_bind,de.status,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
JOIN `user` AS us ON us.user_id = app.user_id
where 1=1
<if test="null != appName and '' != appName">
and app_name like concat('%',#{appName},'%')
......@@ -27,4 +27,8 @@
values (#{sn}, #{appId}, now(), now())
</insert>
<update id="updateDeviceById" parameterType="iot.sixiang.license.entity.Device">
update device set sn_bind = #{snBind}, status = #{status}, update_time = #{updateTime} where device_id = #{deviceId}
</update>
</mapper>
......@@ -3,7 +3,7 @@
<mapper namespace="iot.sixiang.license.mapper.ResourceMapper">
<select id="getResource" resultType="iot.sixiang.license.model.vo.ResourceVo">
SELECT a.user_name,a.password,a.company,b.app_name,b.app_key,c.sn, b.app_id,
SELECT a.user_name,a.password,a.company,b.app_name,b.app_key,c.sn, c.sn_bind, b.app_id,
(CASE c.`status` WHEN 1 THEN '已使用' WHEN 2 THEN '失效' ELSE '未使用' END) `status`
FROM USER a, apply b, device c WHERE a.user_id = b.user_id
AND b.app_id = c.app_id AND a.user_id = #{userId}
......
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