导入导出设备数据
This commit is contained in:
@ -5,6 +5,7 @@ import com.alibaba.excel.util.DateUtils;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.dto.DeviceExcelExportDTO;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -20,6 +21,7 @@ import java.util.stream.Collectors;
|
||||
* @date: 2025-06-0618:22
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceExportService {
|
||||
|
||||
public void export(List<Device> devices, HttpServletResponse response) {
|
||||
@ -36,22 +38,22 @@ public class DeviceExportService {
|
||||
// 转换为DTO列表
|
||||
List<DeviceExcelExportDTO> dtoList = devices.stream().map(device -> {
|
||||
DeviceExcelExportDTO dto = new DeviceExcelExportDTO();
|
||||
dto.setId(device.getId());
|
||||
dto.setDeviceType(device.getDeviceType());
|
||||
dto.setCustomerName(device.getCustomerName());
|
||||
// dto.setId(device.getId());
|
||||
// dto.setDeviceType(device.getDeviceType());
|
||||
// dto.setCustomerName(device.getCustomerName());
|
||||
dto.setDeviceName(device.getDeviceName());
|
||||
dto.setDeviceMac(device.getDeviceMac());
|
||||
// 设备IMEI
|
||||
dto.setDeviceImei(device.getDeviceImei());
|
||||
// 蓝牙名称
|
||||
dto.setBluetoothName(device.getBluetoothName());
|
||||
dto.setLongitude(device.getLongitude());
|
||||
dto.setLatitude(device.getLatitude());
|
||||
// dto.setLongitude(device.getLongitude());
|
||||
// dto.setLatitude(device.getLatitude());
|
||||
dto.setRemark(device.getRemark());
|
||||
dto.setTypeName(device.getTypeName());
|
||||
dto.setCreateBy(device.getCreateByName());
|
||||
Integer deviceStatus = device.getDeviceStatus();
|
||||
dto.setDeviceStatus(deviceStatus == 1 ? "正常" : "失效");
|
||||
// dto.setDeviceStatus(deviceStatus == 1 ? "正常" : "失效");
|
||||
// 时间戳转换
|
||||
dto.setCreateTime(DateUtils.format(device.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
||||
|
||||
@ -72,17 +74,31 @@ public class DeviceExportService {
|
||||
|
||||
private void handleDevicePic(Device device, DeviceExcelExportDTO dto) {
|
||||
String picUrl = device.getDevicePic();
|
||||
log.info("处理设备图片,设备ID: {}, 图片URL: {}", device.getId(), picUrl);
|
||||
|
||||
if (picUrl != null && !picUrl.trim().isEmpty()) {
|
||||
try {
|
||||
// 自动将HTTP转换为HTTPS以避免重定向问题
|
||||
if (picUrl.startsWith("http://")) {
|
||||
picUrl = "https://" + picUrl.substring(7);
|
||||
log.info("自动将HTTP转换为HTTPS: {}", picUrl);
|
||||
}
|
||||
|
||||
// 尝试创建URL对象(会自动验证格式)
|
||||
dto.setDevicePic(new URL(picUrl));
|
||||
} catch (MalformedURLException e) {
|
||||
URL url = new URL(picUrl);
|
||||
|
||||
dto.setDevicePic(url);
|
||||
log.info("成功设置设备图片URL到DTO");
|
||||
} catch (Exception e) {
|
||||
// 不是有效URL时设置为null
|
||||
log.info("设置设备图片失败,设备ID: {}, URL: {}, 错误: {}", device.getId(), picUrl, e.getMessage());
|
||||
dto.setDevicePic(null);
|
||||
}
|
||||
} else {
|
||||
log.info("设备没有设置图片,设备ID: {}", device.getId());
|
||||
dto.setDevicePic(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -139,8 +139,27 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
|
||||
@Override
|
||||
public List<Device> queryAll(DeviceQueryCriteria criteria) {
|
||||
criteria.setCurrentOwnerId(LoginHelper.getUserId());
|
||||
|
||||
// 角色管理员
|
||||
Long userId = LoginHelper.getUserId();
|
||||
List<SysRoleVo> roles = roleService.selectRolesAuthByUserId(userId);
|
||||
boolean isAdmin = false;
|
||||
if (CollectionUtil.isNotEmpty(roles)) {
|
||||
for (SysRoleVo role : roles) {
|
||||
if (role.getRoleKey().equals("admin")) {
|
||||
isAdmin = true;
|
||||
criteria.setIsAdmin(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 只有非admin用户才设置当前用户ID条件
|
||||
if (!isAdmin) {
|
||||
criteria.setCurrentOwnerId(LoginHelper.getUserId());
|
||||
}
|
||||
return deviceMapper.findAll(criteria);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -136,7 +136,23 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
@Override
|
||||
public DeviceType queryByName(String typeName) {
|
||||
DeviceTypeQueryCriteria criteria = new DeviceTypeQueryCriteria();
|
||||
criteria.setCustomerId(LoginHelper.getUserId());
|
||||
|
||||
// 角色管理员
|
||||
Long userId = LoginHelper.getUserId();
|
||||
List<SysRoleVo> roles = roleService.selectRolesAuthByUserId(userId);
|
||||
boolean isAdmin = false;
|
||||
if (CollectionUtil.isNotEmpty(roles)) {
|
||||
for (SysRoleVo role : roles) {
|
||||
if (role.getRoleKey().contains("admin")) {
|
||||
isAdmin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isAdmin) {
|
||||
criteria.setCustomerId(LoginHelper.getUserId());
|
||||
}
|
||||
|
||||
criteria.setTypeName(typeName);
|
||||
DeviceType deviceType = deviceTypeMapper.queryByName(criteria);
|
||||
return deviceType;
|
||||
|
||||
Reference in New Issue
Block a user