设备类型导出
This commit is contained in:
@ -141,17 +141,11 @@ public class AuthController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Log("app用户登录")
|
||||
@ApiOperation("app用户登录")
|
||||
@AnonymousPostMapping(value = "/app/login")
|
||||
public ResponseEntity<Object> APPLogin(@Validated @RequestBody AppAuthUserDto authUser, HttpServletRequest request) throws Exception {
|
||||
|
||||
|
||||
// 1. 构建查询参数
|
||||
APPUserQuery appUserQuery = new APPUserQuery();
|
||||
appUserQuery.setPhoneNumber(authUser.getPhoneNumber());
|
||||
@ -172,7 +166,6 @@ public class AuthController {
|
||||
throw new BadRequestException("登录密码错误");
|
||||
}
|
||||
|
||||
|
||||
// 4. 加载用户详情
|
||||
JwtUserDto jwtUser = userDetailsService.loadUserByUsername(appUser.getUsername(),appUser.getUserType());
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.fuyuanshen.modules.system.listener.excel;
|
||||
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.modules.system.mapper.UserMapper;
|
||||
import com.fuyuanshen.modules.system.service.DeviceAssignmentsService;
|
||||
import com.fuyuanshen.modules.system.service.DeviceService;
|
||||
import lombok.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -19,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class DeviceImportParams {
|
||||
|
||||
private DeviceService deviceService;
|
||||
private DeviceAssignmentsService deviceAssignmentsService;
|
||||
private DeviceMapper deviceMapper;
|
||||
private UserMapper userMapper;
|
||||
private DeviceTypeMapper deviceTypeMapper;
|
||||
|
@ -7,9 +7,13 @@ import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.read.listener.ReadListener;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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.User;
|
||||
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.utils.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.fuyuanshen.constants.DeviceConstants;
|
||||
import com.fuyuanshen.modules.system.domain.Device;
|
||||
@ -24,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -149,6 +154,7 @@ public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportD
|
||||
|
||||
|
||||
private void processDataRowByRow() {
|
||||
User currentUser = params.getUserMapper().findByUsername(SecurityUtils.getCurrentUsername());
|
||||
for (Integer rowIndex : rowIndexList) {
|
||||
Device device = rowDeviceMap.get(rowIndex);
|
||||
DeviceExcelImportDTO originalDto = rowDtoMap.get(rowIndex);
|
||||
@ -171,6 +177,20 @@ public class UploadDeviceDataListener implements ReadListener<DeviceExcelImportD
|
||||
device.setDeviceType(deviceTypes.get(0).getId());
|
||||
}
|
||||
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++;
|
||||
log.info("行 {} 数据插入成功", rowIndex);
|
||||
} catch (Exception e) {
|
||||
|
@ -2,36 +2,35 @@ package com.fuyuanshen.modules.system.rest;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
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.domain.Device;
|
||||
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.UploadDeviceDataListener;
|
||||
import com.fuyuanshen.modules.system.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.modules.system.mapper.DeviceTypeMapper;
|
||||
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.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 io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@ -51,7 +50,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
@ -66,6 +64,7 @@ import java.util.Map;
|
||||
public class DeviceController {
|
||||
|
||||
private final DeviceService deviceService;
|
||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||
private final DeviceExportService exportService;
|
||||
private final UserMapper userMapper;
|
||||
private final DeviceMapper deviceMapper;
|
||||
@ -208,7 +207,7 @@ public class DeviceController {
|
||||
ImportResult result = new ImportResult();
|
||||
try {
|
||||
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);
|
||||
// 读取Excel
|
||||
|
@ -516,22 +516,52 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备分配记录
|
||||
* 删除设备分配记录(分配记录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 -> device.getActive() == 1).map(DeviceAssignments::getId).collect(Collectors.toSet());
|
||||
// Step 3: 从原始 ids 中“去掉”这些非空 customer_id 的设备 ID
|
||||
List<Long> remainingIds = ids.stream().filter(id -> !nonNullCustomerIds.contains(id)).collect(Collectors.toList());
|
||||
if (CollectionUtil.isEmpty(remainingIds)) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
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,
|
||||
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.id AS assignId
|
||||
da.assigned_at AS create_time , da.assigner_name AS create_by , da.id AS assignId
|
||||
from device d
|
||||
LEFT JOIN device_type t ON d.device_type = t.id
|
||||
LEFT JOIN device_assignments da ON da.device_id = d.id
|
||||
@ -85,12 +85,11 @@
|
||||
<!-- AND tenant_id = #{criteria.tenantId} -->
|
||||
<!-- </if> -->
|
||||
</where>
|
||||
|
||||
order by d.id desc
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="findAll1" resultType="com.fuyuanshen.modules.system.domain.Device">
|
||||
select
|
||||
SELECT
|
||||
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.create_time, d.update_time, d.device_type, d.remark, d.device_status, t.type_name
|
||||
|
@ -44,8 +44,8 @@
|
||||
|
||||
<!-- 查询所有设备类型 -->
|
||||
<select id="findAll" resultMap="BaseResultMap">
|
||||
SELECT dt.*
|
||||
FROM device_type dt
|
||||
SELECT DISTINCT dt.*
|
||||
FROM device_type dt
|
||||
JOIN device_type_grants dg ON dt.id = dg.device_type_id
|
||||
<where>
|
||||
<if test="criteria.typeName != null and criteria.typeName.trim() != ''">
|
||||
|
Reference in New Issue
Block a user