web:设备管理
This commit is contained in:
@ -44,7 +44,7 @@ import java.util.List;
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Slf4j
|
||||
@Tag(name = "设备管理", description = "设备:设备管理")
|
||||
@Tag(name = "web:设备管理", description = "web:设备管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/device")
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_assignments】的数据库操作Mapper
|
||||
* @createDate 2025-06-19 18:19:13
|
||||
* @Entity system.domain.DeviceAssignments
|
||||
*/
|
||||
@Mapper
|
||||
public interface DeviceAssignmentsMapper extends BaseMapper<DeviceAssignments> {
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_assignments】的数据库操作Service
|
||||
* @createDate 2025-06-19 18:19:13
|
||||
*/
|
||||
public interface DeviceAssignmentsService extends IService<DeviceAssignments> {
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 97433
|
||||
* @description 针对表【device_assignments】的数据库操作Service实现
|
||||
* @createDate 2025-06-19 18:19:13
|
||||
*/
|
||||
@Service
|
||||
public class DeviceAssignmentsServiceImpl extends ServiceImpl<DeviceAssignmentsMapper, DeviceAssignments> implements DeviceAssignmentsService {
|
||||
|
||||
}
|
@ -17,7 +17,9 @@ import com.fuyuanshen.customer.domain.Customer;
|
||||
import com.fuyuanshen.customer.mapper.CustomerMapper;
|
||||
import com.fuyuanshen.equipment.constants.DeviceConstants;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceAssignments;
|
||||
import com.fuyuanshen.equipment.domain.DeviceType;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import com.fuyuanshen.equipment.domain.dto.AppDeviceBo;
|
||||
import com.fuyuanshen.equipment.domain.form.DeviceForm;
|
||||
import com.fuyuanshen.equipment.domain.query.DeviceQueryCriteria;
|
||||
@ -26,9 +28,12 @@ import com.fuyuanshen.equipment.domain.vo.AppDeviceVo;
|
||||
import com.fuyuanshen.equipment.domain.vo.CustomerVo;
|
||||
import com.fuyuanshen.equipment.enums.BindingStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.CommunicationModeEnum;
|
||||
import com.fuyuanshen.equipment.enums.DeviceActiveStatusEnum;
|
||||
import com.fuyuanshen.equipment.enums.DeviceStatusEnum;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeGrantsMapper;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
|
||||
import com.fuyuanshen.equipment.service.DeviceAssignmentsService;
|
||||
import com.fuyuanshen.equipment.service.DeviceService;
|
||||
import com.fuyuanshen.system.domain.vo.SysOssVo;
|
||||
import com.fuyuanshen.system.service.ISysOssService;
|
||||
@ -42,6 +47,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@ -61,11 +67,13 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
|
||||
private final DeviceMapper deviceMapper;
|
||||
private final DeviceTypeMapper deviceTypeMapper;
|
||||
|
||||
private final CustomerMapper customerMapper;
|
||||
|
||||
private final ISysOssService ossService;
|
||||
|
||||
private final DeviceAssignmentsService deviceAssignmentsService;
|
||||
private final DeviceTypeGrantsMapper deviceTypeGrantsMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询设备
|
||||
@ -112,6 +120,43 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 新增设备
|
||||
// *
|
||||
// * @param deviceForm
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void addDevice(DeviceForm deviceForm) throws Exception {
|
||||
// DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
// queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
// queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
// List<DeviceType> deviceTypes = deviceTypeMapper.findAll(queryCriteria);
|
||||
// if (deviceTypes.isEmpty()) {
|
||||
// throw new Exception("设备类型不存在!!!");
|
||||
// }
|
||||
//
|
||||
// // 保存图片并获取URL
|
||||
// if (deviceForm.getFile() != null) {
|
||||
// SysOssVo upload = ossService.upload(deviceForm.getFile());
|
||||
// // 设置图片路径
|
||||
// deviceForm.setDevicePic(upload.getUrl());
|
||||
// }
|
||||
//
|
||||
// // 转换对象并插入数据库
|
||||
// Device device = new Device();
|
||||
// LoginUser loginUser = LoginHelper.getLoginUser();
|
||||
// device.setCurrentOwnerId(loginUser.getUserId());
|
||||
// device.setOriginalOwnerId(loginUser.getUserId());
|
||||
// device.setCreateByName(loginUser.getNickname());
|
||||
// device.setTypeName(deviceTypes.get(0).getTypeName());
|
||||
// BeanUtil.copyProperties(deviceForm, device, true);
|
||||
//
|
||||
// deviceMapper.insert(device);
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* 新增设备
|
||||
*
|
||||
@ -124,13 +169,13 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(queryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
DeviceTypeGrants typeGrants = deviceTypeGrantsMapper.selectById(queryCriteria.getDeviceTypeId());
|
||||
DeviceType deviceTypes = deviceTypeMapper.selectById(typeGrants.getDeviceTypeId());
|
||||
if (deviceTypes== null) {
|
||||
throw new Exception("设备类型不存在!!!");
|
||||
}
|
||||
|
||||
// 保存图片并获取URL
|
||||
// String imageUrl = saveDeviceImage(deviceForm.getFile(), deviceForm.getDeviceName());
|
||||
if (deviceForm.getFile() != null) {
|
||||
SysOssVo upload = ossService.upload(deviceForm.getFile());
|
||||
// 设置图片路径
|
||||
@ -143,11 +188,26 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
device.setCurrentOwnerId(loginUser.getUserId());
|
||||
device.setOriginalOwnerId(loginUser.getUserId());
|
||||
device.setCreateByName(loginUser.getNickname());
|
||||
device.setTypeName(deviceTypes.get(0).getTypeName());
|
||||
device.setTypeName(deviceTypes.getTypeName());
|
||||
device.setDeviceType(deviceTypes.getId());
|
||||
BeanUtil.copyProperties(deviceForm, device, true);
|
||||
|
||||
deviceMapper.insert(device);
|
||||
|
||||
// 新增设备类型记录
|
||||
DeviceAssignments assignments = new DeviceAssignments();
|
||||
assignments.setDeviceId(device.getId());
|
||||
assignments.setAssignedAt(LocalDateTime.now());
|
||||
// 分配者
|
||||
assignments.setAssignerId(loginUser.getUserId());
|
||||
assignments.setAssignerName(loginUser.getUsername());
|
||||
// 接收者
|
||||
assignments.setAssigneeId(loginUser.getUserId());
|
||||
assignments.setActive(DeviceActiveStatusEnum.ACTIVE.getCode());
|
||||
String lever = loginUser.getUserId() + ":";
|
||||
assignments.setLever(lever);
|
||||
deviceAssignmentsService.save(assignments);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -232,17 +292,20 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
public void deleteAll(List<Long> ids) {
|
||||
List<Long> invalidIds = new ArrayList<>();
|
||||
|
||||
for (Long id : ids) {
|
||||
Device deviceType = deviceMapper.selectById(id);
|
||||
if (deviceType == null || !Objects.equals(deviceType.getCurrentOwnerId(), LoginHelper.getUserId())) {
|
||||
invalidIds.add(id);
|
||||
}
|
||||
}
|
||||
if (!invalidIds.isEmpty()) {
|
||||
throw new RuntimeException("以下设备无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
}
|
||||
|
||||
deviceMapper.deleteByIds(ids);
|
||||
deviceTypeGrantsMapper.deleteByIds(ids);
|
||||
//
|
||||
// for (Long id : ids) {
|
||||
//
|
||||
// Device deviceType = deviceMapper.selectById(id);
|
||||
// if (deviceType == null || !Objects.equals(deviceType.getCurrentOwnerId(), LoginHelper.getUserId())) {
|
||||
// invalidIds.add(id);
|
||||
// }
|
||||
// }
|
||||
// if (!invalidIds.isEmpty()) {
|
||||
// throw new RuntimeException("以下设备无法删除(ID 不存在或无权限): " + invalidIds);
|
||||
// }
|
||||
//
|
||||
// deviceMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
|
@ -175,13 +175,20 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
*/
|
||||
@Override
|
||||
public DeviceType getCommunicationMode(Long id) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
|
||||
DeviceTypeGrants deviceTypeGrants = deviceTypeGrantsMapper.selectById(id);
|
||||
if (deviceTypeGrants == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(deviceTypeGrants.getDeviceTypeId());
|
||||
if (deviceType == null) {
|
||||
throw new RuntimeException("设备类型不存在");
|
||||
}
|
||||
if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
throw new RuntimeException("无权获取该设备类型通讯方式");
|
||||
}
|
||||
//
|
||||
// if (!Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
// throw new RuntimeException("无权获取该设备类型通讯方式");
|
||||
// }
|
||||
return deviceType;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.DeviceAssignments">
|
||||
<id property="id" column="id" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="fromCustomerId" column="from_customer_id" />
|
||||
<result property="toCustomerId" column="to_customer_id" />
|
||||
<result property="assignedAt" column="assigned_at" />
|
||||
<result property="deviceTypeGranted" column="device_type_granted" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,device_id,from_customer_id,to_customer_id,assigned_at,device_type_granted
|
||||
</sql>
|
||||
</mapper>
|
@ -37,7 +37,7 @@
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
<select id="findAll1" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select d.* , t.type_name
|
||||
FROM device d
|
||||
LEFT JOIN device_type t ON d.device_type = t.id
|
||||
@ -71,6 +71,44 @@
|
||||
order by d.create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select
|
||||
da.id AS id,d.device_name,
|
||||
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,d.type_name AS typeName,
|
||||
da.assignee_id AS customerId, da.assignee_name AS customerName, da.active AS deviceStatus,
|
||||
da.create_time AS create_time , da.assigner_name AS createByName , 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
|
||||
<where>
|
||||
<!-- 时间范围等其他条件保持原样 -->
|
||||
<if test="criteria.deviceName != null and criteria.deviceName.trim() != ''">
|
||||
and d.device_name like concat('%', TRIM(#{criteria.deviceName}), '%')
|
||||
</if>
|
||||
<if test="criteria.deviceMac != null">
|
||||
and d.device_mac = #{criteria.deviceMac}
|
||||
</if>
|
||||
<if test="criteria.deviceImei != null">
|
||||
and d.device_imei = #{criteria.deviceImei}
|
||||
</if>
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
<if test="criteria.deviceStatus != null">
|
||||
and da.active = #{criteria.deviceStatus}
|
||||
</if>
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and da.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
AND da.assignee_id = #{criteria.currentOwnerId}
|
||||
|
||||
</where>
|
||||
ORDER BY da.create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select
|
||||
d.id, d.customer_id, d.device_name,
|
||||
@ -93,12 +131,18 @@
|
||||
</where>
|
||||
order by d.id desc
|
||||
</select>
|
||||
|
||||
<select id="queryAppDeviceList" resultType="com.fuyuanshen.equipment.domain.vo.AppDeviceVo">
|
||||
select
|
||||
d.id, d.device_name, d.device_mac, d.device_sn,
|
||||
d.device_imei, d.device_mac ,dt.communication_mode
|
||||
from device d inner join device_type dt on d.device_type = dt.id
|
||||
where d.binding_user_id = #{criteria.bindingUserId}
|
||||
select d.id,
|
||||
d.device_name,
|
||||
d.device_mac,
|
||||
d.device_sn,
|
||||
d.device_imei,
|
||||
d.device_mac,
|
||||
dt.communication_mode
|
||||
from device d
|
||||
inner join device_type dt on d.device_type = dt.id
|
||||
where d.binding_user_id = #{criteria.bindingUserId}
|
||||
</select>
|
||||
|
||||
<!-- 获取分配设备的客户 -->
|
||||
|
Reference in New Issue
Block a user