forked from dyf/fys-Multi-tenant
WEB:分页查询设备列表
This commit is contained in:
@ -57,6 +57,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||
*/
|
||||
@Override
|
||||
public List<Customer> queryAllCustomers(UserQueryCriteria criteria) {
|
||||
criteria.setPid(LoginHelper.getUserId());
|
||||
List<Customer> users = customerMapper.queryAllCustomers(criteria);
|
||||
return users;
|
||||
}
|
||||
|
@ -148,7 +148,6 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 查询所有客户 -->
|
||||
<select id="queryAllCustomers" resultType="com.fuyuanshen.customer.domain.Customer">
|
||||
select u.user_id as customerId,
|
||||
@ -165,6 +164,9 @@
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="criteria.pid != null">
|
||||
and u.pid = #{criteria.pid}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
@ -187,16 +189,15 @@
|
||||
|
||||
<!-- 根据id查询客户 -->
|
||||
<select id="queryCustomerById" resultType="com.fuyuanshen.customer.domain.Customer">
|
||||
select u.*
|
||||
select u.*,u.user_id as customerId
|
||||
from sys_user u
|
||||
<where>
|
||||
<if test="customerId!= null">
|
||||
and u.user_id = customerId)
|
||||
and u.user_id = #{customerId}
|
||||
</if>
|
||||
<if test="pid != null">
|
||||
and u.pid = pid)
|
||||
and u.pid = #{pid}
|
||||
</if>
|
||||
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
@ -133,9 +133,9 @@ public class DeviceController {
|
||||
// @Log("撤回设备")
|
||||
@Operation(summary = "撤回分配设备")
|
||||
@PostMapping(value = "/withdraw")
|
||||
public ResponseVO<Object> withdrawDevice(@Validated @ModelAttribute DeviceForm deviceForm) {
|
||||
public ResponseVO<Object> withdrawDevice(@RequestBody List<Long> ids) {
|
||||
try {
|
||||
deviceService.withdrawDevice(deviceForm);
|
||||
// deviceService.withdrawDevice(deviceForm);
|
||||
} catch (Exception e) {
|
||||
log.error("updateDevice error: " + e.getMessage());
|
||||
return ResponseVO.fail("出错了");
|
||||
|
@ -27,6 +27,14 @@ public class DeviceType extends TenantEntity {
|
||||
@Schema(name = "创建该类型的客户")
|
||||
private Long ownerCustomerId;
|
||||
|
||||
/**
|
||||
* 原始所有者(创建者)
|
||||
* original_owner_id
|
||||
*/
|
||||
@Schema(name = "原始所有者(创建者)")
|
||||
private Long originalOwnerId;
|
||||
|
||||
|
||||
@NotBlank(message = "设备类型名称不能为空")
|
||||
@Schema(name = "类型名称", required = true)
|
||||
private String typeName;
|
||||
|
@ -21,7 +21,7 @@ public class DeviceForm {
|
||||
private Long assignId;
|
||||
|
||||
@Schema(title = "设备类型")
|
||||
private Long deviceTypeId;
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(title = "客户号")
|
||||
private Long customerId;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fuyuanshen.equipment.domain.query;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@ -15,7 +16,7 @@ import java.util.Set;
|
||||
* @Date: 2025/5/16
|
||||
**/
|
||||
@Data
|
||||
public class DeviceQueryCriteria {
|
||||
public class DeviceQueryCriteria extends BaseEntity {
|
||||
|
||||
@Schema(name = "设备id")
|
||||
private Long deviceId;
|
||||
@ -24,7 +25,7 @@ public class DeviceQueryCriteria {
|
||||
private String deviceName;
|
||||
|
||||
@Schema(name = "设备类型")
|
||||
private Long deviceTypeId;
|
||||
private Long deviceType;
|
||||
|
||||
@Schema(name = "设备MAC")
|
||||
private String deviceMac;
|
||||
@ -43,9 +44,6 @@ public class DeviceQueryCriteria {
|
||||
@Schema(name = "设备状态 0 失效 1 正常 ")
|
||||
private Integer deviceStatus;
|
||||
|
||||
@Schema(name = "创建时间")
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer page = 1;
|
||||
|
||||
|
@ -31,4 +31,11 @@ public interface DeviceMapper extends BaseMapper<Device> {
|
||||
|
||||
List<Device> findAllDevices(@Param("criteria") DeviceQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 获取分配设备的客户
|
||||
*
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
Device getAssignCustomer(Long customerId);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.generator.SnowflakeGenerator;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -113,7 +114,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addDevice(DeviceForm deviceForm) throws Exception {
|
||||
DeviceTypeQueryCriteria queryCriteria = new DeviceTypeQueryCriteria();
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getId());
|
||||
queryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
queryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(queryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
@ -152,7 +153,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
public void update(DeviceForm deviceForm) throws Exception {
|
||||
|
||||
DeviceTypeQueryCriteria deviceTypeQueryCriteria = new DeviceTypeQueryCriteria();
|
||||
deviceTypeQueryCriteria.setDeviceTypeId(deviceForm.getId());
|
||||
deviceTypeQueryCriteria.setDeviceTypeId(deviceForm.getDeviceType());
|
||||
deviceTypeQueryCriteria.setCustomerId(LoginHelper.getUserId());
|
||||
List<DeviceType> deviceTypes = deviceTypeMapper.findAll(deviceTypeQueryCriteria);
|
||||
if (deviceTypes.isEmpty()) {
|
||||
@ -258,6 +259,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
invalidIds.add(id);
|
||||
continue;
|
||||
}
|
||||
Device assignCustomer = deviceMapper.getAssignCustomer(device.getId());
|
||||
if (assignCustomer != null) {
|
||||
invalidIds.add(id);
|
||||
continue;
|
||||
}
|
||||
device.setCustomerId(customerId);
|
||||
device.setCustomerName(customer.getNickName());
|
||||
devices.add(device);
|
||||
@ -268,14 +274,24 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
|
||||
}
|
||||
|
||||
devices.forEach((device) -> {
|
||||
deviceMapper.updateById(device);
|
||||
device.setId(null);
|
||||
device.setCurrentOwnerId(customerId);
|
||||
deviceMapper.insert(device);
|
||||
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
deviceType.setId(null);
|
||||
deviceMapper.updateById(device);
|
||||
device.setCurrentOwnerId(customerId);
|
||||
if (device.getDeviceType() == null) {
|
||||
throw new RuntimeException("设备类型有问题!!! ");
|
||||
}
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(device.getDeviceType());
|
||||
SnowflakeGenerator snowflakeGenerator = new SnowflakeGenerator();
|
||||
device.setOriginalOwnerId(device.getId());
|
||||
Long next = snowflakeGenerator.next();
|
||||
device.setId(next);
|
||||
device.setDeviceType(next);
|
||||
|
||||
deviceType.setOriginalOwnerId(deviceType.getId());
|
||||
deviceType.setId(next);
|
||||
deviceType.setOwnerCustomerId(customerId);
|
||||
|
||||
deviceMapper.insert(device);
|
||||
deviceTypeMapper.insert(deviceType);
|
||||
|
||||
});
|
||||
|
@ -125,11 +125,11 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
|
||||
List<Long> invalidId2 = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
DeviceType deviceType = deviceTypeMapper.selectById(id);
|
||||
if (deviceType == null || !Objects.equals(deviceType.getCustomerId(), LoginHelper.getUserId())) {
|
||||
if (deviceType == null || !Objects.equals(deviceType.getOwnerCustomerId(), LoginHelper.getUserId())) {
|
||||
invalidIds.add(id);
|
||||
}
|
||||
DeviceQueryCriteria deviceQueryCriteria = new DeviceQueryCriteria();
|
||||
deviceQueryCriteria.setDeviceTypeId(id);
|
||||
deviceQueryCriteria.setDeviceType(id);
|
||||
List<Device> devices = deviceMapper.findAll(deviceQueryCriteria);
|
||||
if (!devices.isEmpty()) {
|
||||
invalidId2.add(id);
|
||||
|
@ -38,7 +38,7 @@
|
||||
|
||||
<!-- 分页查询设备 -->
|
||||
<select id="findAll" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
select d.* ,t.type_name
|
||||
select d.* , t.type_name
|
||||
FROM device d
|
||||
LEFT JOIN device_type t ON d.device_type = t.id
|
||||
<where>
|
||||
@ -52,22 +52,23 @@
|
||||
<if test="criteria.deviceImei != null">
|
||||
and d.device_imei = #{criteria.deviceImei}
|
||||
</if>
|
||||
<if test="criteria.deviceTypeId != null">
|
||||
and d.device_type = #{criteria.deviceTypeId}
|
||||
<if test="criteria.deviceType != null">
|
||||
and d.device_type = #{criteria.deviceType}
|
||||
</if>
|
||||
<if test="criteria.deviceStatus != null">
|
||||
-- and da.active = #{criteria.deviceStatus}
|
||||
and d.device_status = #{criteria.deviceStatus}
|
||||
</if>
|
||||
<if test="criteria.currentOwnerId != null">
|
||||
d.current_owner_id = #{criteria.currentOwnerId}
|
||||
and d.current_owner_id = #{criteria.currentOwnerId}
|
||||
</if>
|
||||
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
|
||||
and d.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
|
||||
<if test="criteria.params.beginTime != null and criteria.params.endTime != null">
|
||||
and d.create_time between #{criteria.params.beginTime} and #{criteria.params.endTime}
|
||||
</if>
|
||||
<if test="criteria.tenantId != null">
|
||||
AND tenant_id = #{criteria.tenantId}
|
||||
</if>
|
||||
</where>
|
||||
order by d.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="findAllDevices" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
@ -93,4 +94,12 @@
|
||||
order by d.id desc
|
||||
</select>
|
||||
|
||||
<!-- 获取分配设备的客户 -->
|
||||
<select id="getAssignCustomer" resultType="com.fuyuanshen.equipment.domain.Device">
|
||||
SELECT *
|
||||
FROM device
|
||||
WHERE original_owner_id = #{customerId}
|
||||
AND device_status = 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user