分页查询客户

This commit is contained in:
2025-07-03 10:08:09 +08:00
parent fe6de8f5bc
commit abe9dc2fe8
13 changed files with 305 additions and 4 deletions

View File

@ -159,6 +159,9 @@ public class SysLoginService {
loginUser.setUserType(user.getUserType());
// 用户级别
loginUser.setUserLevel(user.getUserLevel());
// pid
loginUser.setPid(user.getPid());
loginUser.setMenuPermission(permissionService.getMenuPermission(userId));
loginUser.setRolePermission(permissionService.getRolePermission(userId));
if (ObjectUtil.isNotNull(user.getDeptId())) {
@ -244,7 +247,7 @@ public class SysLoginService {
log.info("登录租户:{} 已被停用.", tenantId);
throw new TenantException("tenant.blocked");
} else if (ObjectUtil.isNotNull(tenant.getExpireTime())
&& new Date().after(tenant.getExpireTime())) {
&& new Date().after(tenant.getExpireTime())) {
log.info("登录租户:{} 已超过有效期.", tenantId);
throw new TenantException("tenant.expired");
}

View File

@ -32,6 +32,7 @@ public class LoginUser implements Serializable {
* 用户ID
*/
private Long userId;
private Long pid;
/**
* 部门ID

View File

@ -1,10 +1,13 @@
package com.fuyuanshen.fyscustomer.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.fyscustomer.domain.Customer;
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
import com.fuyuanshen.fyscustomer.domain.vo.ConsumerVo;
import com.fuyuanshen.fyscustomer.service.CustomerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -31,6 +34,21 @@ public class CustomerController {
private final CustomerService customerService;
/**
* 分页查询客户(限制子客户)
*
* @param criteria
* @return
*/
@Operation(summary = "分页查询客户")
@GetMapping(value = "/customer")
public ResponseVO<PageResult<ConsumerVo>> queryCustomer(UserQueryCriteria criteria) {
Page<Customer> page = new Page<>(criteria.getPage(), criteria.getSize());
PageResult<ConsumerVo> pageUsers = customerService.queryCustomers(criteria, page);
return ResponseVO.success(pageUsers);
}
@GetMapping(value = "/allCustomer")
@Operation(summary = "查询所有客户")
public ResponseVO<List<Customer>> queryAllCustomer(UserQueryCriteria criteria) {

View File

@ -37,6 +37,9 @@ public class UserQueryCriteria implements Serializable {
@Schema(name = "ids")
private Set<Long> ids;
@Schema(name = "pid")
private Long pid;
@Schema(name = "多个ID")
private Set<Long> deptIds = new HashSet<>();

View File

@ -0,0 +1,97 @@
package com.fuyuanshen.fyscustomer.domain.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
/**
* @author: 默苍璃
* @date: 2025-06-1211:34
*/
@Getter
@Setter
public class ConsumerVo implements Serializable {
@Schema(name = "ID", hidden = true)
private Long id;
@Schema(hidden = true)
private Long deptId;
@Schema(hidden = true)
private Long pid;
@Schema(hidden = true)
private Byte userLevel;
@Schema(name = "账号")
private String username;
@Schema(name = "用户昵称")
private String nickName;
@Schema(name = "邮箱")
private String email;
@Schema(name = "电话号码")
private String phone;
@Schema(name = "用户性别")
private String gender;
@Schema(name = "头像真实名称", hidden = true)
private String avatarName;
@Schema(name = "头像存储的路径", hidden = true)
private String avatarPath;
@Schema(name = "密码")
private String password;
@Schema(name = "是否启用")
private Boolean enabled;
@Schema(name = "是否为admin账号", hidden = true)
private Boolean isAdmin = false;
@Schema(name = "最后修改密码的时间", hidden = true)
private Date pwdResetTime;
/**
* 租户ID
*/
@Schema(hidden = true)
private Long tenantId;
private List<ConsumerVo> children;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConsumerVo consumer = (ConsumerVo) o;
return Objects.equals(id, consumer.id) && Objects.equals(username, consumer.username);
}
@Override
public int hashCode() {
return Objects.hash(id, username);
}
}

View File

@ -15,6 +15,23 @@ import java.util.List;
@Mapper
public interface CustomerMapper extends BaseMapper<Customer> {
/**
* 分页查询客户
*
* @param criteria
* @return
*/
List<Customer> findCustomers(@Param("criteria") UserQueryCriteria criteria);
/**
* 获取分页总数
*
* @param criteria
* @return
*/
Long countCustomers(@Param("criteria") UserQueryCriteria criteria);
/**
* 查询所有客户
*
@ -23,7 +40,6 @@ public interface CustomerMapper extends BaseMapper<Customer> {
*/
List<Customer> queryAllCustomers(@Param("criteria") UserQueryCriteria criteria);
/**
* 根据条件查询客户
*
@ -32,5 +48,13 @@ public interface CustomerMapper extends BaseMapper<Customer> {
*/
List<Customer> queryCustomers(@Param("criteria") UserQueryCriteria criteria);
/**
* 根据id查询客户
*
* @param customerId
* @return
*/
Customer queryCustomerById(@Param("customerId") Long customerId, @Param("pid") Long pid);
}

View File

@ -1,7 +1,10 @@
package com.fuyuanshen.fyscustomer.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.fyscustomer.domain.Customer;
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
import com.fuyuanshen.fyscustomer.domain.vo.ConsumerVo;
import io.undertow.util.BadRequestException;
import java.util.List;
@ -13,6 +16,17 @@ import java.util.Set;
*/
public interface CustomerService {
/**
* 分页查询客户
*
* @param criteria
* @param page
* @return
*/
PageResult<ConsumerVo> queryCustomers(UserQueryCriteria criteria, Page<Customer> page);
/**
* 查询所有客户
*

View File

@ -1,10 +1,15 @@
package com.fuyuanshen.fyscustomer.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.common.core.domain.model.LoginUser;
import com.fuyuanshen.common.core.utils.PageUtil;
import com.fuyuanshen.common.satoken.utils.LoginHelper;
import com.fuyuanshen.fyscustomer.domain.Customer;
import com.fuyuanshen.fyscustomer.domain.query.UserQueryCriteria;
import com.fuyuanshen.fyscustomer.domain.vo.ConsumerVo;
import com.fuyuanshen.fyscustomer.mapper.CustomerMapper;
import com.fuyuanshen.fyscustomer.service.CustomerService;
import io.undertow.util.BadRequestException;
@ -26,6 +31,24 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
private final CustomerMapper customerMapper;
/**
* 分页查询客户
*
* @param criteria
* @param page
* @return
*/
@Override
public PageResult<ConsumerVo> queryCustomers(UserQueryCriteria criteria, Page<Customer> page) {
criteria.setOffset(page.offset());
criteria.setPid(LoginHelper.getUserId());
List<Customer> users = customerMapper.findCustomers(criteria);
List<ConsumerVo> consumerVoList = BeanUtil.copyToList(users, ConsumerVo.class);
Long total = customerMapper.countCustomers(criteria);
return PageUtil.toPage(consumerVoList, total);
}
/**
* 查询所有客户
*

View File

@ -91,6 +91,64 @@
</sql>
<!-- 分页查询客户 -->
<select id="findCustomers" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
select
u.user_id as id, u.nick_name , u.username, u.enabled, u.create_time
from sys_user u
<where>
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
and u.pid IN
<foreach item="item" collection="criteria.ids" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="criteria.pid != null">
and u.pid = #{criteria.pid}
</if>
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
</if>
<if test="criteria.enabled != null">
and u.enabled = #{criteria.enabled}
</if>
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
and u.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
</if>
</where>
order by u.user_id desc
<if test="criteria.offset != null">
limit #{criteria.offset}, #{criteria.size}
</if>
</select>
<!-- 获取分页总数 -->
<select id="countCustomers" resultType="java.lang.Long">
select count(*)
from sys_user u
<where>
<if test="criteria.ids != null and !criteria.ids.isEmpty()">
and u.pid IN
<foreach item="item" collection="criteria.ids" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="criteria.pid != null">
and u.pid = #{criteria.pid}
</if>
<if test="criteria.blurry != null and criteria.blurry.trim() != ''">
and u.nick_name like concat('%', TRIM(#{criteria.blurry}), '%')
</if>
<if test="criteria.enabled != null">
and u.enabled = #{criteria.enabled}
</if>
<if test="criteria.createTime != null and criteria.createTime.size() != 0">
and u.create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]}
</if>
</where>
</select>
<!-- 查询所有客户 -->
<select id="queryAllCustomers" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
select u.user_id as customerId,
@ -127,5 +185,20 @@
</where>
</select>
<!-- 根据id查询客户 -->
<select id="queryCustomerById" resultType="com.fuyuanshen.fyscustomer.domain.Customer">
select u.*
from sys_user u
<where>
<if test="customerId!= null">
and u.user_id = customerId)
</if>
<if test="pid != null">
and u.pid = pid)
</if>
</where>
</select>
</mapper>

View File

@ -101,6 +101,12 @@
<artifactId>fys-common-sse</artifactId>
</dependency>
<!-- 客户管理模块 -->
<dependency>
<groupId>com.fuyuanshen</groupId>
<artifactId>fys-customer</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>

View File

@ -38,6 +38,9 @@ public class Device extends TenantEntity {
@Schema(name = "客户号")
private Long customerId;
@Schema(name = "所属客户")
private String customerName;
/**
* 当前所有者
* current_owner_id
@ -52,8 +55,6 @@ public class Device extends TenantEntity {
@Schema(name = "原始所有者(创建者)")
private Long originalOwnerId;
@Schema(name = "所属客户")
private String customerName;
/*@Schema( name = "设备编号")
private String deviceNo;*/

View File

@ -17,6 +17,8 @@ import com.fuyuanshen.equipment.domain.vo.CustomerVo;
import com.fuyuanshen.equipment.mapper.DeviceMapper;
import com.fuyuanshen.equipment.mapper.DeviceTypeMapper;
import com.fuyuanshen.equipment.service.DeviceService;
import com.fuyuanshen.fyscustomer.domain.Customer;
import com.fuyuanshen.fyscustomer.mapper.CustomerMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@ -49,6 +51,8 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private final DeviceMapper deviceMapper;
private final DeviceTypeMapper deviceTypeMapper;
private final CustomerMapper customerMapper;
/**
* 分页查询设备
@ -219,7 +223,40 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
@Override
@Transactional(rollbackFor = Exception.class)
public void assignCustomer(CustomerVo customerVo) {
List<Long> deviceIds = customerVo.getDeviceIds();
Long customerId = customerVo.getCustomerId();
Customer customer = customerMapper.queryCustomerById(customerId, LoginHelper.getLoginUser().getPid());
if (customer == null) {
throw new RuntimeException("待分配的客户不存在!!!");
}
List<Long> invalidIds = new ArrayList<>();
List<Device> devices = new ArrayList<>();
for (Long id : deviceIds) {
Device device = deviceMapper.selectById(id);
if (device == null || !Objects.equals(device.getCurrentOwnerId(), LoginHelper.getUserId())) {
invalidIds.add(id);
continue;
}
device.setCustomerId(customerId);
device.setCustomerName(customer.getNickName());
devices.add(device);
}
if (!invalidIds.isEmpty()) {
throw new RuntimeException("以下设备无法分配ID 不存在或无权限): " + invalidIds);
}
devices.forEach((device) -> {
deviceMapper.updateById(device);
device.setId( null);
device.setCurrentOwnerId(customerId);
deviceMapper.insert( device);
});
}
public void assign(List<Long> deviceIds) {
}

View File

@ -32,6 +32,7 @@ public class SysUserVo implements Serializable {
* 用户ID
*/
private Long userId;
private Long pid;
/**
* 租户ID