mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 23:23:55 +08:00
update:统一使用PageData返回分页
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
package xiaozhi.common.page;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 扩展的分页对象
|
||||
* @author zjy
|
||||
* @since 2025-4-2
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "分页数据")
|
||||
public class ExtendPageData<T> implements Serializable {
|
||||
@Schema(description = "总记录数")
|
||||
private int totalCount;
|
||||
|
||||
@Schema(description = "页数")
|
||||
private int totalPage;
|
||||
|
||||
@Schema(description = "列表数据")
|
||||
private List<T> list;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
* @param page 页数
|
||||
*/
|
||||
public ExtendPageData(List<T> list, long total, long page) {
|
||||
this.list = list;
|
||||
this.totalCount = (int) total;
|
||||
this.totalPage = (int) page;
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -4,19 +4,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.common.service.impl.BaseServiceImpl;
|
||||
import xiaozhi.modules.agent.dao.AgentDao;
|
||||
import xiaozhi.modules.agent.entity.AgentEntity;
|
||||
import xiaozhi.modules.agent.service.AgentService;
|
||||
import xiaozhi.modules.device.entity.DeviceEntity;
|
||||
|
||||
@Service
|
||||
public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> implements AgentService {
|
||||
|
||||
@@ -2,7 +2,7 @@ package xiaozhi.modules.device.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import xiaozhi.common.page.ExtendPageData;
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.modules.device.dto.DeviceBindDTO;
|
||||
import xiaozhi.modules.device.dto.DevicePageUserDTO;
|
||||
import xiaozhi.modules.device.dto.DeviceReportReqDTO;
|
||||
@@ -45,12 +45,14 @@ public interface DeviceService {
|
||||
|
||||
/**
|
||||
* 删除此用户的所有设备
|
||||
*
|
||||
* @param userId 用户id
|
||||
*/
|
||||
void deleteByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取指定用户的设备数量
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 设备数量
|
||||
*/
|
||||
@@ -62,5 +64,5 @@ public interface DeviceService {
|
||||
* @param dto 分页查找参数
|
||||
* @return 用户列表分页数据
|
||||
*/
|
||||
ExtendPageData<UserShowDeviceListVO> page(DevicePageUserDTO dto);
|
||||
PageData<UserShowDeviceListVO> page(DevicePageUserDTO dto);
|
||||
}
|
||||
+7
-9
@@ -8,7 +8,6 @@ import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -17,11 +16,12 @@ import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import xiaozhi.common.constant.Constant;
|
||||
import xiaozhi.common.exception.RenException;
|
||||
import xiaozhi.common.page.ExtendPageData;
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.common.service.impl.BaseServiceImpl;
|
||||
import xiaozhi.common.user.UserDetail;
|
||||
import xiaozhi.common.utils.ConvertUtils;
|
||||
@@ -46,13 +46,12 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
|
||||
private final String frontedUrl;
|
||||
|
||||
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
// 添加构造函数来初始化 deviceMapper
|
||||
public DeviceServiceImpl(DeviceDao deviceDao, SysUserUtilService sysUserUtilService,
|
||||
@Value("${app.fronted-url:http://localhost:8001}") String frontedUrl,
|
||||
RedisTemplate<String, Object> redisTemplate) {
|
||||
@Value("${app.fronted-url:http://localhost:8001}") String frontedUrl,
|
||||
RedisTemplate<String, Object> redisTemplate) {
|
||||
this.deviceDao = deviceDao;
|
||||
this.sysUserUtilService = sysUserUtilService;
|
||||
this.frontedUrl = frontedUrl;
|
||||
@@ -223,7 +222,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendPageData<UserShowDeviceListVO> page(DevicePageUserDTO dto) {
|
||||
public PageData<UserShowDeviceListVO> page(DevicePageUserDTO dto) {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put(Constant.PAGE, dto.getPage());
|
||||
params.put(Constant.LIMIT, dto.getLimit());
|
||||
@@ -243,9 +242,8 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||
vo.setDeviceType(device.getBoard());
|
||||
return vo;
|
||||
}).toList();
|
||||
//计算页数
|
||||
long num = page.getTotal() / Long.parseLong(dto.getPage());
|
||||
return new ExtendPageData<>(list, page.getTotal(), num);
|
||||
// 计算页数
|
||||
return new PageData<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
private DeviceReportRespDTO.ServerTime buildServerTime() {
|
||||
|
||||
-4
@@ -5,8 +5,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -37,8 +35,6 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
|
||||
private final ModelProviderService modelProviderService;
|
||||
private final TimbreService timbreService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ModelConfigServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public List<String> getModelCodeList(String modelType, String modelName) {
|
||||
return modelConfigDao.getModelCodeList(modelType, modelName);
|
||||
|
||||
@@ -17,7 +17,6 @@ import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import xiaozhi.common.constant.Constant;
|
||||
import xiaozhi.common.page.ExtendPageData;
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.common.utils.Result;
|
||||
import xiaozhi.common.validator.ValidatorUtils;
|
||||
@@ -51,7 +50,7 @@ public class AdminController {
|
||||
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
|
||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
||||
})
|
||||
public Result<ExtendPageData<AdminPageUserVO>> pageUser(
|
||||
public Result<PageData<AdminPageUserVO>> pageUser(
|
||||
@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
||||
AdminPageUserDTO dto = new AdminPageUserDTO();
|
||||
dto.setMobile((String) params.get("mobile"));
|
||||
@@ -59,8 +58,8 @@ public class AdminController {
|
||||
dto.setPage((String) params.get(Constant.PAGE));
|
||||
ValidatorUtils.validateEntity(dto);
|
||||
ValidatorUtils.validateEntity(dto);
|
||||
ExtendPageData<AdminPageUserVO> page = sysUserService.page(dto);
|
||||
return new Result<ExtendPageData<AdminPageUserVO>>().ok(page);
|
||||
PageData<AdminPageUserVO> page = sysUserService.page(dto);
|
||||
return new Result<PageData<AdminPageUserVO>>().ok(page);
|
||||
}
|
||||
|
||||
@PutMapping("/users/{id}")
|
||||
@@ -88,14 +87,14 @@ public class AdminController {
|
||||
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
|
||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
||||
})
|
||||
public Result<ExtendPageData<UserShowDeviceListVO>> pageDevice(
|
||||
public Result<PageData<UserShowDeviceListVO>> pageDevice(
|
||||
@Parameter(hidden = true) @RequestParam Map<String, Object> params) {
|
||||
DevicePageUserDTO dto = new DevicePageUserDTO();
|
||||
dto.setKeywords((String) params.get("keywords"));
|
||||
dto.setLimit((String) params.get(Constant.LIMIT));
|
||||
dto.setPage((String) params.get(Constant.PAGE));
|
||||
ValidatorUtils.validateEntity(dto);
|
||||
ExtendPageData<UserShowDeviceListVO> page = deviceService.page(dto);
|
||||
return new Result<ExtendPageData<UserShowDeviceListVO>>().ok(page);
|
||||
PageData<UserShowDeviceListVO> page = deviceService.page(dto);
|
||||
return new Result<PageData<UserShowDeviceListVO>>().ok(page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package xiaozhi.modules.sys.service;
|
||||
|
||||
import xiaozhi.common.page.ExtendPageData;
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.common.service.BaseService;
|
||||
import xiaozhi.modules.sys.dto.AdminPageUserDTO;
|
||||
import xiaozhi.modules.sys.dto.PasswordDTO;
|
||||
@@ -21,6 +21,7 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
||||
|
||||
/**
|
||||
* 删除指定用户,且有关联的数据设备和智能体
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
void deleteById(Long ids);
|
||||
@@ -55,5 +56,5 @@ public interface SysUserService extends BaseService<SysUserEntity> {
|
||||
* @param dto 分页查找参数
|
||||
* @return 用户列表分页数据
|
||||
*/
|
||||
ExtendPageData<AdminPageUserVO> page(AdminPageUserDTO dto);
|
||||
PageData<AdminPageUserVO> page(AdminPageUserDTO dto);
|
||||
}
|
||||
|
||||
+6
-11
@@ -18,7 +18,7 @@ import lombok.AllArgsConstructor;
|
||||
import xiaozhi.common.constant.Constant;
|
||||
import xiaozhi.common.exception.ErrorCode;
|
||||
import xiaozhi.common.exception.RenException;
|
||||
import xiaozhi.common.page.ExtendPageData;
|
||||
import xiaozhi.common.page.PageData;
|
||||
import xiaozhi.common.service.impl.BaseServiceImpl;
|
||||
import xiaozhi.common.utils.ConvertUtils;
|
||||
import xiaozhi.modules.agent.service.AgentService;
|
||||
@@ -99,7 +99,6 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||
deviceService.deleteByUserId(id);
|
||||
// 删除智能体
|
||||
agentService.deleteById(id);
|
||||
// TODO 除了要删除用户还要删除用户关联的对话
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,16 +150,14 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExtendPageData<AdminPageUserVO> page(AdminPageUserDTO dto) {
|
||||
public PageData<AdminPageUserVO> page(AdminPageUserDTO dto) {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put(Constant.PAGE, dto.getPage());
|
||||
params.put(Constant.LIMIT, dto.getLimit());
|
||||
IPage<SysUserEntity> page = baseDao.selectPage(
|
||||
getPage(params, "id", true),
|
||||
// 定义查询条件
|
||||
new QueryWrapper<SysUserEntity>()
|
||||
// 必须按照手机号码查找
|
||||
.eq(StringUtils.isNotBlank(dto.getMobile()), "username", dto.getMobile()));
|
||||
new QueryWrapper<SysUserEntity>().eq(StringUtils.isNotBlank(dto.getMobile()), "username",
|
||||
dto.getMobile()));
|
||||
// 循环处理page获取回来的数据,返回需要的字段
|
||||
List<AdminPageUserVO> list = page.getRecords().stream().map(user -> {
|
||||
AdminPageUserVO adminPageUserVO = new AdminPageUserVO();
|
||||
@@ -168,12 +165,10 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserDao, SysUserEntit
|
||||
adminPageUserVO.setMobile(user.getUsername());
|
||||
String deviceCount = deviceService.selectCountByUserId(user.getId()).toString();
|
||||
adminPageUserVO.setDeviceCount(deviceCount);
|
||||
adminPageUserVO.setStatus(user.getStatus().toString());
|
||||
adminPageUserVO.setStatus(user.getStatus());
|
||||
return adminPageUserVO;
|
||||
}).toList();
|
||||
//计算页数
|
||||
long num = page.getTotal() / Long.parseLong(dto.getPage());
|
||||
return new ExtendPageData<>(list, page.getTotal(),num);
|
||||
return new PageData<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
private boolean isStrongPassword(String password) {
|
||||
|
||||
@@ -23,7 +23,4 @@ public class AdminPageUserVO {
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private String userid;
|
||||
|
||||
@Schema(description = "用户状态")
|
||||
private String status;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user