Compare commits
3 Commits
3278b789dd
...
a72f606b36
Author | SHA1 | Date | |
---|---|---|---|
a72f606b36 | |||
dcbe9c4dd2 | |||
a13df9bfa6 |
@ -141,17 +141,11 @@ public class AuthController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Log("app用户登录")
|
@Log("app用户登录")
|
||||||
@ApiOperation("app用户登录")
|
@ApiOperation("app用户登录")
|
||||||
@AnonymousPostMapping(value = "/app/login")
|
@AnonymousPostMapping(value = "/app/login")
|
||||||
public ResponseEntity<Object> APPLogin(@Validated @RequestBody AppAuthUserDto authUser, HttpServletRequest request) throws Exception {
|
public ResponseEntity<Object> APPLogin(@Validated @RequestBody AppAuthUserDto authUser, HttpServletRequest request) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
// 1. 构建查询参数
|
// 1. 构建查询参数
|
||||||
APPUserQuery appUserQuery = new APPUserQuery();
|
APPUserQuery appUserQuery = new APPUserQuery();
|
||||||
appUserQuery.setPhoneNumber(authUser.getPhoneNumber());
|
appUserQuery.setPhoneNumber(authUser.getPhoneNumber());
|
||||||
@ -172,7 +166,6 @@ public class AuthController {
|
|||||||
throw new BadRequestException("登录密码错误");
|
throw new BadRequestException("登录密码错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 4. 加载用户详情
|
// 4. 加载用户详情
|
||||||
JwtUserDto jwtUser = userDetailsService.loadUserByUsername(appUser.getUsername(),appUser.getUserType());
|
JwtUserDto jwtUser = userDetailsService.loadUserByUsername(appUser.getUsername(),appUser.getUserType());
|
||||||
|
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.fuyuanshen.modules.system.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应消息常量类
|
||||||
|
*
|
||||||
|
* @author: 默苍璃
|
||||||
|
* @date: 2025-06-2117:21
|
||||||
|
*/
|
||||||
|
public class ResponseMessageConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除操作成功提示
|
||||||
|
*/
|
||||||
|
public static final String DELETE_SUCCESS = "删除成功!";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增操作成功提示
|
||||||
|
*/
|
||||||
|
public static final String SAVE_SUCCESS = "新增成功!";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新操作成功提示
|
||||||
|
*/
|
||||||
|
public static final String UPDATE_SUCCESS = "更新成功!";
|
||||||
|
|
||||||
|
// 可根据业务需求继续扩展其他常用提示信息
|
||||||
|
|
||||||
|
}
|
@ -26,6 +26,10 @@ public class Device extends BaseEntity implements Serializable {
|
|||||||
@ApiModelProperty(value = "ID")
|
@ApiModelProperty(value = "ID")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "设备记录ID")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private Long assignId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "设备类型")
|
@ApiModelProperty(value = "设备类型")
|
||||||
private Long deviceType;
|
private Long deviceType;
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ public class DeviceExcelExportDTO {
|
|||||||
@ColumnWidth(20)
|
@ColumnWidth(20)
|
||||||
private String deviceMac;
|
private String deviceMac;
|
||||||
|
|
||||||
@ExcelProperty("设备SN")
|
@ExcelProperty("设备IMEI")
|
||||||
@ColumnWidth(20)
|
@ColumnWidth(20)
|
||||||
private String deviceSn;
|
private String deviceImei;
|
||||||
|
|
||||||
@ExcelProperty("经度")
|
@ExcelProperty("经度")
|
||||||
private String longitude;
|
private String longitude;
|
||||||
|
@ -3,6 +3,7 @@ package com.fuyuanshen.modules.system.listener.excel;
|
|||||||
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
||||||
|
import com.fuyuanshen.modules.system.service.DeviceAssignmentsService;
|
||||||
import com.fuyuanshen.modules.system.service.DeviceService;
|
import com.fuyuanshen.modules.system.service.DeviceService;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@ -19,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
public class DeviceImportParams {
|
public class DeviceImportParams {
|
||||||
|
|
||||||
private DeviceService deviceService;
|
private DeviceService deviceService;
|
||||||
|
private DeviceAssignmentsService deviceAssignmentsService;
|
||||||
private DeviceMapper deviceMapper;
|
private DeviceMapper deviceMapper;
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
private DeviceTypeMapper deviceTypeMapper;
|
private DeviceTypeMapper deviceTypeMapper;
|
||||||
|
@ -7,9 +7,13 @@ import com.alibaba.excel.context.AnalysisContext;
|
|||||||
import com.alibaba.excel.read.listener.ReadListener;
|
import com.alibaba.excel.read.listener.ReadListener;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.fuyuanshen.modules.system.domain.DeviceAssignments;
|
||||||
import com.fuyuanshen.modules.system.domain.DeviceType;
|
import com.fuyuanshen.modules.system.domain.DeviceType;
|
||||||
|
import com.fuyuanshen.modules.system.domain.User;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
||||||
|
import com.fuyuanshen.modules.system.enums.DeviceActiveStatusEnum;
|
||||||
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
||||||
|
import com.fuyuanshen.utils.SecurityUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import com.fuyuanshen.constants.DeviceConstants;
|
import com.fuyuanshen.constants.DeviceConstants;
|
||||||
import com.fuyuanshen.modules.system.domain.Device;
|
import com.fuyuanshen.modules.system.domain.Device;
|
||||||
@ -24,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -149,6 +154,7 @@ public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportD
|
|||||||
|
|
||||||
|
|
||||||
private void processDataRowByRow() {
|
private void processDataRowByRow() {
|
||||||
|
User currentUser = params.getUserMapper().findByUsername(SecurityUtils.getCurrentUsername());
|
||||||
for (Integer rowIndex : rowIndexList) {
|
for (Integer rowIndex : rowIndexList) {
|
||||||
Device device = rowDeviceMap.get(rowIndex);
|
Device device = rowDeviceMap.get(rowIndex);
|
||||||
DeviceExcelImportDTO originalDto = rowDtoMap.get(rowIndex);
|
DeviceExcelImportDTO originalDto = rowDtoMap.get(rowIndex);
|
||||||
@ -171,6 +177,20 @@ public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportD
|
|||||||
device.setDeviceType(deviceTypes.get(0).getId());
|
device.setDeviceType(deviceTypes.get(0).getId());
|
||||||
}
|
}
|
||||||
params.getDeviceService().save(device);
|
params.getDeviceService().save(device);
|
||||||
|
|
||||||
|
// 新增设备类型记录
|
||||||
|
DeviceAssignments assignments = new DeviceAssignments();
|
||||||
|
assignments.setDeviceId(device.getId());
|
||||||
|
assignments.setAssignedAt(LocalDateTime.now());
|
||||||
|
// 分配者
|
||||||
|
assignments.setAssignerId(currentUser.getId());
|
||||||
|
// 接收者
|
||||||
|
assignments.setAssigneeId(currentUser.getId());
|
||||||
|
assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||||
|
String lever = currentUser.getId() + ":";
|
||||||
|
assignments.setLever(lever);
|
||||||
|
params.getDeviceAssignmentsService().save(assignments);
|
||||||
|
|
||||||
successCount++;
|
successCount++;
|
||||||
log.info("行 {} 数据插入成功", rowIndex);
|
log.info("行 {} 数据插入成功", rowIndex);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -2,35 +2,35 @@ package com.fuyuanshen.modules.system.rest;
|
|||||||
|
|
||||||
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.excel.EasyExcel;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.fuyuanshen.annotation.Log;
|
||||||
|
import com.fuyuanshen.exception.BadRequestException;
|
||||||
|
import com.fuyuanshen.modules.system.constant.ResponseMessageConstants;
|
||||||
import com.fuyuanshen.modules.system.constant.UserConstants;
|
import com.fuyuanshen.modules.system.constant.UserConstants;
|
||||||
|
import com.fuyuanshen.modules.system.domain.Device;
|
||||||
import com.fuyuanshen.modules.system.domain.User;
|
import com.fuyuanshen.modules.system.domain.User;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.DeviceExcelImportDTO;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
||||||
|
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
||||||
import com.fuyuanshen.modules.system.listener.excel.DeviceImportParams;
|
import com.fuyuanshen.modules.system.listener.excel.DeviceImportParams;
|
||||||
|
import com.fuyuanshen.modules.system.listener.excel.UploadDeviceDataListener;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
||||||
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
||||||
|
import com.fuyuanshen.modules.system.service.DeviceAssignmentsService;
|
||||||
|
import com.fuyuanshen.modules.system.service.DeviceService;
|
||||||
import com.fuyuanshen.modules.system.service.UserService;
|
import com.fuyuanshen.modules.system.service.UserService;
|
||||||
import com.fuyuanshen.modules.system.service.impl.app.APPUserServiceImpl;
|
import com.fuyuanshen.modules.system.service.impl.DeviceExportService;
|
||||||
|
import com.fuyuanshen.modules.utils.ResponseVO;
|
||||||
|
import com.fuyuanshen.modules.utils.excel.ImportResult;
|
||||||
|
import com.fuyuanshen.utils.FileUtil;
|
||||||
|
import com.fuyuanshen.utils.PageResult;
|
||||||
import com.fuyuanshen.utils.SecurityUtils;
|
import com.fuyuanshen.utils.SecurityUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import com.fuyuanshen.annotation.Log;
|
|
||||||
import com.fuyuanshen.domain.LocalStorage;
|
|
||||||
import com.fuyuanshen.exception.BadRequestException;
|
|
||||||
import com.fuyuanshen.modules.system.domain.Device;
|
|
||||||
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceExcelImportDTO;
|
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceQueryCriteria;
|
|
||||||
import com.fuyuanshen.modules.system.listener.excel.UploadDeviceDataListener;
|
|
||||||
import com.fuyuanshen.modules.system.service.DeviceService;
|
|
||||||
import com.fuyuanshen.modules.system.service.impl.DeviceExportService;
|
|
||||||
import com.fuyuanshen.modules.utils.ResponseVO;
|
|
||||||
import com.fuyuanshen.modules.utils.excel.ImportResult;
|
|
||||||
import com.fuyuanshen.utils.FileUtil;
|
|
||||||
import com.fuyuanshen.utils.PageResult;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@ -50,7 +50,6 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:
|
* @Description:
|
||||||
@ -65,6 +64,7 @@ import java.util.Map;
|
|||||||
public class DeviceController {
|
public class DeviceController {
|
||||||
|
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
|
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||||
private final DeviceExportService exportService;
|
private final DeviceExportService exportService;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
private final DeviceMapper deviceMapper;
|
private final DeviceMapper deviceMapper;
|
||||||
@ -158,13 +158,9 @@ public class DeviceController {
|
|||||||
@ApiOperation("删除设备")
|
@ApiOperation("删除设备")
|
||||||
@DeleteMapping(value = "/delete")
|
@DeleteMapping(value = "/delete")
|
||||||
public ResponseVO<Object> deleteDevice(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
|
public ResponseVO<Object> deleteDevice(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
|
||||||
try {
|
// deviceService.deleteAll(ids);
|
||||||
deviceService.deleteAll(ids);
|
deviceService.deleteAssign(ids);
|
||||||
} catch (Exception e) {
|
return ResponseVO.success(ResponseMessageConstants.DELETE_SUCCESS);
|
||||||
log.error("deleteDevice error: " + e.getMessage());
|
|
||||||
return ResponseVO.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
return ResponseVO.success(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,7 +172,8 @@ public class DeviceController {
|
|||||||
|
|
||||||
// 只能看到自己的创建的设备,以及被分配的设备。
|
// 只能看到自己的创建的设备,以及被分配的设备。
|
||||||
if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
if (onlineuser.getTenantId() != null && !onlineuser.getTenantId().equals(UserConstants.SUPER_ADMIN_ID)) {
|
||||||
criteria.setTenantId(onlineuser.getTenantId());
|
// criteria.setTenantId(onlineuser.getTenantId());
|
||||||
|
criteria.setCurrentOwnerId(onlineuser.getId());
|
||||||
}
|
}
|
||||||
exportService.export(deviceService.queryAll(criteria), response);
|
exportService.export(deviceService.queryAll(criteria), response);
|
||||||
}
|
}
|
||||||
@ -210,7 +207,7 @@ public class DeviceController {
|
|||||||
ImportResult result = new ImportResult();
|
ImportResult result = new ImportResult();
|
||||||
try {
|
try {
|
||||||
User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
User currentUser = userMapper.findByUsername(SecurityUtils.getCurrentUsername());
|
||||||
DeviceImportParams params = DeviceImportParams.builder().ip(ip).deviceService(deviceService).tenantId(currentUser.getTenantId()).file(file).filePath(filePath).deviceMapper(deviceMapper).deviceTypeMapper(deviceTypeMapper).userId(currentUser.getId()).build();
|
DeviceImportParams params = DeviceImportParams.builder().ip(ip).deviceService(deviceService).tenantId(currentUser.getTenantId()).file(file).filePath(filePath).deviceMapper(deviceMapper).deviceAssignmentsService(deviceAssignmentsService).deviceTypeMapper(deviceTypeMapper).userId(currentUser.getId()).userMapper(userMapper).build();
|
||||||
// 创建监听器
|
// 创建监听器
|
||||||
UploadDeviceDataListener listener = new UploadDeviceDataListener(params);
|
UploadDeviceDataListener listener = new UploadDeviceDataListener(params);
|
||||||
// 读取Excel
|
// 读取Excel
|
||||||
@ -236,7 +233,6 @@ public class DeviceController {
|
|||||||
try {
|
try {
|
||||||
// 解码Base64字符串
|
// 解码Base64字符串
|
||||||
byte[] data = Base64.getDecoder().decode(errorData);
|
byte[] data = Base64.getDecoder().decode(errorData);
|
||||||
|
|
||||||
return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"import_errors.xlsx\"").contentType(MediaType.APPLICATION_OCTET_STREAM).body(data);
|
return ResponseEntity.ok().header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"import_errors.xlsx\"").contentType(MediaType.APPLICATION_OCTET_STREAM).body(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("下载错误报告失败", e);
|
log.error("下载错误报告失败", e);
|
||||||
|
@ -80,6 +80,13 @@ public interface DeviceService extends IService<Device> {
|
|||||||
*/
|
*/
|
||||||
void deleteAll(List<Long> ids);
|
void deleteAll(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备分配记录
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteAssign(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出数据
|
* 导出数据
|
||||||
*
|
*
|
||||||
@ -103,4 +110,6 @@ public interface DeviceService extends IService<Device> {
|
|||||||
*/
|
*/
|
||||||
void unbindDevice(DeviceForm deviceForm);
|
void unbindDevice(DeviceForm deviceForm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,8 @@ public class DeviceExportService {
|
|||||||
dto.setCustomerName(device.getCustomerName());
|
dto.setCustomerName(device.getCustomerName());
|
||||||
dto.setDeviceName(device.getDeviceName());
|
dto.setDeviceName(device.getDeviceName());
|
||||||
dto.setDeviceMac(device.getDeviceMac());
|
dto.setDeviceMac(device.getDeviceMac());
|
||||||
dto.setDeviceSn(device.getDeviceSn());
|
// 设备IMEI
|
||||||
|
dto.setDeviceImei(device.getDeviceImei());
|
||||||
dto.setLongitude(device.getLongitude());
|
dto.setLongitude(device.getLongitude());
|
||||||
dto.setLatitude(device.getLatitude());
|
dto.setLatitude(device.getLatitude());
|
||||||
dto.setRemark(device.getRemark());
|
dto.setRemark(device.getRemark());
|
||||||
|
@ -2,11 +2,9 @@ package com.fuyuanshen.modules.system.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.fuyuanshen.constants.DeviceConstants;
|
import com.fuyuanshen.constants.DeviceConstants;
|
||||||
@ -14,7 +12,10 @@ import com.fuyuanshen.constants.ExceptionMessages;
|
|||||||
import com.fuyuanshen.exception.BadRequestException;
|
import com.fuyuanshen.exception.BadRequestException;
|
||||||
import com.fuyuanshen.modules.security.service.UserCacheManager;
|
import com.fuyuanshen.modules.security.service.UserCacheManager;
|
||||||
import com.fuyuanshen.modules.system.constant.UserConstants;
|
import com.fuyuanshen.modules.system.constant.UserConstants;
|
||||||
import com.fuyuanshen.modules.system.domain.*;
|
import com.fuyuanshen.modules.system.domain.Device;
|
||||||
|
import com.fuyuanshen.modules.system.domain.DeviceAssignments;
|
||||||
|
import com.fuyuanshen.modules.system.domain.DeviceTypeGrants;
|
||||||
|
import com.fuyuanshen.modules.system.domain.User;
|
||||||
import com.fuyuanshen.modules.system.domain.app.APPDevice;
|
import com.fuyuanshen.modules.system.domain.app.APPDevice;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
import com.fuyuanshen.modules.system.domain.dto.CustomerVo;
|
||||||
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
import com.fuyuanshen.modules.system.domain.dto.DeviceForm;
|
||||||
@ -484,18 +485,17 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteAll(List<Long> ids) {
|
public void deleteAll(List<Long> ids) {
|
||||||
|
|
||||||
|
SecurityUtils.getCurrentUserId();
|
||||||
|
|
||||||
// Step 1: 查询所有传入的设备(根据 ID)
|
// Step 1: 查询所有传入的设备(根据 ID)
|
||||||
List<Device> allDevices = deviceMapper.selectBatchIds(ids);
|
List<Device> allDevices = deviceMapper.selectBatchIds(ids);
|
||||||
|
|
||||||
// Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
// Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||||
Set<Long> nonNullCustomerIds = allDevices.stream().filter(device -> device.getCustomerId() != null && device.getDeviceStatus() == 1).map(Device::getId).collect(Collectors.toSet());
|
Set<Long> nonNullCustomerIds = allDevices.stream().filter(device -> device.getCustomerId() != null && device.getDeviceStatus() == 1).map(Device::getId).collect(Collectors.toSet());
|
||||||
|
|
||||||
// Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
// Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
||||||
List<Long> remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList());
|
List<Long> remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList());
|
||||||
if (CollectionUtil.isEmpty(remainingIds)) {
|
if (CollectionUtil.isEmpty(remainingIds)) {
|
||||||
throw new BadRequestException("已分配的设备不允许删除!!!");
|
throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Device> devices = deviceMapper.selectBatchIds(remainingIds);
|
List<Device> devices = deviceMapper.selectBatchIds(remainingIds);
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
String devicePic = device.getDevicePic();
|
String devicePic = device.getDevicePic();
|
||||||
@ -514,6 +514,58 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
|||||||
deviceMapper.deleteBatchIds(ids);
|
deviceMapper.deleteBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备分配记录(分配记录id)
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
public void deleteAssign1(List<Long> ids) {
|
||||||
|
Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
|
// Step 1: 查询所有传入的设备(根据 ID)
|
||||||
|
// List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||||
|
QueryWrapper<DeviceAssignments> wrapper = new QueryWrapper<>();
|
||||||
|
// wrapper.eq("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||||
|
wrapper.in("device_id", ids);
|
||||||
|
wrapper.eq("assigner_id", currentUserId);
|
||||||
|
List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectList(wrapper);
|
||||||
|
// Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||||
|
Set<Long> nonNullCustomerIds = deviceAssignments.stream().filter(device -> !StringUtils.isNotEmpty(device.getAssigneeName())).map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||||
|
if (CollectionUtil.isEmpty(nonNullCustomerIds)) {
|
||||||
|
throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryWrapper<DeviceAssignments> de = new QueryWrapper<>();
|
||||||
|
// wrapper.eq("active", DeviceActiveStatusEnum.INACTIVE.getCode());
|
||||||
|
// wrapper.in("device_id", ids);
|
||||||
|
// wrapper.eq("assignee_id", currentUserId);
|
||||||
|
// deviceAssignmentsMapper.delete(de);
|
||||||
|
|
||||||
|
deviceAssignmentsMapper.deleteBatchIds(nonNullCustomerIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备分配记录(分配记录id)
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteAssign(List<Long> ids) {
|
||||||
|
// Step 1: 查询所有传入的设备(根据 ID)
|
||||||
|
List<DeviceAssignments> deviceAssignments = deviceAssignmentsMapper.selectBatchIds(ids);
|
||||||
|
// Step 2: 使用 Java Stream 过滤出 customer_id 不为 null 的设备
|
||||||
|
Set<Long> nonNullCustomerIds = deviceAssignments.stream()
|
||||||
|
.filter(device -> !StringUtils.isNotEmpty(device.getAssigneeName()))
|
||||||
|
.map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||||
|
if (CollectionUtil.isEmpty(nonNullCustomerIds)) {
|
||||||
|
throw new BadRequestException("已分配的设备不允许删除!!!");
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceAssignmentsMapper.deleteBatchIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(List<Device> all, HttpServletResponse response) throws IOException {
|
public void download(List<Device> all, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
d.device_pic, d.device_mac, d.device_sn, d.update_by,d.device_imei,
|
d.device_pic, d.device_mac, d.device_sn, d.update_by,d.device_imei,
|
||||||
d.update_time, d.device_type, d.remark, d.binding_status,t.type_name,
|
d.update_time, d.device_type, d.remark, d.binding_status,t.type_name,
|
||||||
da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus,
|
da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus,
|
||||||
da.assigned_at AS create_time , da.assigner_name AS create_by
|
da.assigned_at AS create_time , da.assigner_name AS create_by , da.id AS assignId
|
||||||
from device d
|
from device d
|
||||||
LEFT JOIN device_type t ON d.device_type = t.id
|
LEFT JOIN device_type t ON d.device_type = t.id
|
||||||
LEFT JOIN device_assignments da ON da.device_id = d.id
|
LEFT JOIN device_assignments da ON da.device_id = d.id
|
||||||
@ -85,12 +85,11 @@
|
|||||||
<!-- AND tenant_id = #{criteria.tenantId} -->
|
<!-- AND tenant_id = #{criteria.tenantId} -->
|
||||||
<!-- </if> -->
|
<!-- </if> -->
|
||||||
</where>
|
</where>
|
||||||
|
ORDER BY create_time DESC
|
||||||
order by d.id desc
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findAll1" resultType="com.fuyuanshen.modules.system.domain.Device">
|
<select id="findAll1" resultType="com.fuyuanshen.modules.system.domain.Device">
|
||||||
select
|
SELECT
|
||||||
d.id, d.customer_id, d.customer_name, d.device_name,
|
d.id, d.customer_id, d.customer_name, d.device_name,
|
||||||
d.device_pic, d.device_mac, d.device_sn, d.create_by, d.update_by,
|
d.device_pic, d.device_mac, d.device_sn, d.create_by, d.update_by,
|
||||||
d.create_time, d.update_time, d.device_type, d.remark, d.device_status, t.type_name
|
d.create_time, d.update_time, d.device_type, d.remark, d.device_status, t.type_name
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
<!-- 查询所有设备类型 -->
|
<!-- 查询所有设备类型 -->
|
||||||
<select id="findAll" resultMap="BaseResultMap">
|
<select id="findAll" resultMap="BaseResultMap">
|
||||||
SELECT dt.*
|
SELECT DISTINCT dt.*
|
||||||
FROM device_type dt
|
FROM device_type dt
|
||||||
JOIN device_type_grants dg ON dt.id = dg.device_type_id
|
JOIN device_type_grants dg ON dt.id = dg.device_type_id
|
||||||
<where>
|
<where>
|
||||||
|
Reference in New Issue
Block a user