#update
This commit is contained in:
@@ -3,6 +3,7 @@ package com.maibu.controller;
|
||||
import com.maibu.annotation.Log;
|
||||
import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.dto.DeviceBindDTO;
|
||||
import com.maibu.core.controller.BaseController;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.page.TableDataInfo;
|
||||
@@ -14,13 +15,13 @@ import com.maibu.utils.StringUtils;
|
||||
import com.maibu.utils.poi.ExcelUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -228,4 +229,40 @@ public class DeviceController extends BaseController {
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("bind")
|
||||
public AjaxResult bind(@RequestBody DeviceBindDTO bindDTO) {
|
||||
|
||||
if (CollectionUtils.isEmpty(bindDTO.getDeviceIds())) {
|
||||
return AjaxResult.error("deviceIds为空!");
|
||||
}
|
||||
return AjaxResult.success(deviceService.bind(bindDTO, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@PostMapping("unbind")
|
||||
public AjaxResult unbind(@RequestBody DeviceBindDTO bindDTO) {
|
||||
if (CollectionUtils.isEmpty(bindDTO.getDeviceIds())) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
return AjaxResult.success(deviceService.unbind(bindDTO, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*/
|
||||
@GetMapping("/getSiteList")
|
||||
public TableDataInfo getSiteList(Device device) {
|
||||
startPage();
|
||||
return getDataTable(deviceService.getSiteList(getLoginUser(), device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表 分配页面
|
||||
*/
|
||||
@GetMapping("/getDeviceList")
|
||||
public TableDataInfo getDeviceList(Device device) {
|
||||
startPage();
|
||||
return getDataTable(deviceService.getDeviceList(getLoginUser(), device));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.maibu.mapper;
|
||||
|
||||
import com.maibu.core.business.uav.IotUAVDevice;
|
||||
import com.maibu.mybatis.mapper.BaseMapperX;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 设备历史状态
|
||||
*/
|
||||
@Repository
|
||||
public interface UAVDeviceMapper extends BaseMapperX<IotUAVDevice> {
|
||||
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.maibu.service;
|
||||
|
||||
import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.dto.DeviceBindDTO;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.domain.model.LoginUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -78,4 +80,15 @@ public interface IDeviceService {
|
||||
*/
|
||||
public List<String> selectSerialNumbersByProductId(Long productId);
|
||||
|
||||
|
||||
public boolean bind(DeviceBindDTO bindDTO, String username);
|
||||
|
||||
|
||||
public boolean unbind(DeviceBindDTO bindDTO, String username);
|
||||
|
||||
|
||||
public List<Device> getSiteList(LoginUser loginUser, Device device);
|
||||
|
||||
public List<Device> getDeviceList(LoginUser loginUser, Device device);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,10 @@ import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.DevicePlan;
|
||||
import com.maibu.core.business.DeviceRunningStatusHistory;
|
||||
import com.maibu.core.business.DeviceStatusRecordDTO;
|
||||
import com.maibu.core.business.dto.DeviceBindDTO;
|
||||
import com.maibu.core.business.uav.IotUAVDevice;
|
||||
import com.maibu.core.domain.AjaxResult;
|
||||
import com.maibu.core.domain.entity.SysRole;
|
||||
import com.maibu.core.domain.model.LoginUser;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
@@ -13,7 +16,9 @@ import com.maibu.mapper.DeviceMapper;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
import com.maibu.mapper.DeviceStatusHistoryMapper;
|
||||
import com.maibu.service.IDeviceService;
|
||||
import com.maibu.service.ISysRoleService;
|
||||
import com.maibu.utils.SecurityUtils;
|
||||
import com.maibu.utils.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,10 +27,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -50,6 +53,10 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
@Autowired
|
||||
private DeviceStatusHistoryMapper deviceStatusHistoryMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备
|
||||
@@ -218,4 +225,104 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
return deviceMapper.selectSerialNumbersByProductId(productId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean bind(DeviceBindDTO bindDTO,String username) {
|
||||
try {
|
||||
List<String> deviceIds = bindDTO.getDeviceIds();
|
||||
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(Device::getSerialNumber,deviceIds);
|
||||
List<Device> list =deviceMapper.selectList(queryWrapper);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return false;
|
||||
} else {
|
||||
list.forEach(device -> {
|
||||
if(bindDTO.getUserId()!=null){
|
||||
device.setTenantId(bindDTO.getUserId());
|
||||
}
|
||||
device.setOrgId(bindDTO.getOrgId());
|
||||
device.setSiteId(bindDTO.getSiteId());
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
device.setUpdateBy(username);
|
||||
});
|
||||
return deviceMapper.saveOrUpdateBatch(list);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("设备绑定失败: {}", e.getMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unbind(DeviceBindDTO dto,String username) {
|
||||
List<String> deviceIds = dto.getDeviceIds();
|
||||
if (!CollectionUtils.isEmpty(deviceIds)) {
|
||||
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(Device::getSerialNumber,deviceIds);
|
||||
List<Device> list = deviceMapper.selectList(queryWrapper);
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
list.forEach(x -> {
|
||||
x.setTenantId(-1L);
|
||||
if (dto.getType() == 2) {
|
||||
x.setSiteId(null);
|
||||
}
|
||||
if (dto.getType() == 3) {
|
||||
x.setSiteId(null);
|
||||
x.setOrgId(null);
|
||||
}
|
||||
});
|
||||
return deviceMapper.saveOrUpdateBatch(list);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getSiteList(LoginUser loginUser,Device device) {
|
||||
SysRole sysRole = roleService.selectRoleById(loginUser.getRoleId());
|
||||
List<Device> deviceList = new ArrayList<>();
|
||||
if (sysRole != null) {
|
||||
String roleKey = sysRole.getRoleKey();
|
||||
if (!StringUtils.isEmpty(roleKey)) {
|
||||
if ("manager".equals(roleKey) || "siteManager".equals(roleKey) || "admin".equals(roleKey)) {
|
||||
// device.setSiteId(siteId);
|
||||
} else {
|
||||
device.setTenantId(loginUser.getUserId());
|
||||
}
|
||||
deviceList = deviceMapper.selectDeviceList(device);
|
||||
}
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Device> getDeviceList(LoginUser loginUser,Device device) {
|
||||
SysRole sysRole = roleService.selectRoleById(loginUser.getRoleId());
|
||||
List<Device> deviceList = new ArrayList<>();
|
||||
if (sysRole != null) {
|
||||
String roleKey = sysRole.getRoleKey();
|
||||
if (!StringUtils.isEmpty(roleKey)) {
|
||||
if ("manager".equals(roleKey)) {
|
||||
device.setOrgId(loginUser.getOrgId());
|
||||
} else if ("siteManager".equals(roleKey)) {
|
||||
device.setSiteId(loginUser.getSiteId());
|
||||
} else if (!"admin".equals(roleKey)) {
|
||||
device.setTenantId(loginUser.getUserId());
|
||||
}
|
||||
// if ("admin".equals(roleKey)) {
|
||||
// deviceList = deviceMapper.selectList();
|
||||
// } else {
|
||||
// deviceList = deviceMapper.selectDeviceList(device);
|
||||
// }
|
||||
deviceList = deviceMapper.selectDeviceList(device);
|
||||
}
|
||||
}
|
||||
return deviceList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
<result property="serialNumber" column="serial_number"/>
|
||||
<result property="firmwareVersion" column="firmware_version"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="deviceType" column="device_type"/>
|
||||
<result property="rssi" column="rssi"/>
|
||||
<result property="isShadow" column="is_shadow"/>
|
||||
<result property="locationWay" column="location_way"/>
|
||||
@@ -72,8 +71,7 @@
|
||||
d.img_url,
|
||||
d.summary,
|
||||
d.remark,
|
||||
d.slave_id,
|
||||
p.device_type
|
||||
d.slave_id
|
||||
from iot_device d
|
||||
left join device_product p on d.product_id = p.id
|
||||
</sql>
|
||||
@@ -123,7 +121,6 @@
|
||||
<select id="selectDeviceList" parameterType="com.maibu.core.business.Device" resultMap="DeviceResult">
|
||||
<include refid="selectDeviceVo"/>
|
||||
<where>
|
||||
<if test="deviceType != null">and p.device_type = #{deviceType}</if>
|
||||
<if test="gwDevCode != null and gwDevCode != ''">and d.gw_dev_code = #{gwDevCode}</if>
|
||||
<if test="deviceName != null and deviceName != ''">and d.device_name like concat('%', #{deviceName}, '%')
|
||||
</if>
|
||||
@@ -204,7 +201,6 @@
|
||||
d.device_name,
|
||||
d.product_id,
|
||||
p.product_name,
|
||||
p.device_type,
|
||||
d.tenant_id,
|
||||
d.tenant_name,
|
||||
d.serial_number,
|
||||
|
||||
Reference in New Issue
Block a user