use of com.baomidou.mybatisplus.core.metadata.IPage in project jeecg-boot by jeecgboot.
the class SysDepartRoleController method queryPageList.
/**
* 分页列表查询
*
* @param sysDepartRole
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@ApiOperation(value = "部门角色-分页列表查询", notes = "部门角色-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(SysDepartRole sysDepartRole, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "deptId", required = false) String deptId, HttpServletRequest req) {
QueryWrapper<SysDepartRole> queryWrapper = QueryGenerator.initQueryWrapper(sysDepartRole, req.getParameterMap());
Page<SysDepartRole> page = new Page<SysDepartRole>(pageNo, pageSize);
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
List<String> deptIds = null;
// if(oConvertUtils.isEmpty(deptId)){
// if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals(CommonConstant.USER_IDENTITY_2) ){
// deptIds = sysDepartService.getMySubDepIdsByDepId(user.getDepartIds());
// }else{
// return Result.ok(null);
// }
// }else{
// deptIds = sysDepartService.getSubDepIdsByDepId(deptId);
// }
// queryWrapper.in("depart_id",deptIds);
// 我的部门,选中部门只能看当前部门下的角色
queryWrapper.eq("depart_id", deptId);
IPage<SysDepartRole> pageList = sysDepartRoleService.page(page, queryWrapper);
return Result.ok(pageList);
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project jeecg-boot by jeecgboot.
the class SysBaseApiImpl method queryAllUser.
@Override
public JSONObject queryAllUser(String userIds, Integer pageNo, Integer pageSize) {
JSONObject json = new JSONObject();
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().eq("status", 1).eq("del_flag", 0);
List<ComboModel> list = new ArrayList<ComboModel>();
Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
IPage<SysUser> pageList = userMapper.selectPage(page, queryWrapper);
for (SysUser user : pageList.getRecords()) {
ComboModel model = new ComboModel();
model.setUsername(user.getUsername());
model.setTitle(user.getRealname());
model.setId(user.getId());
model.setEmail(user.getEmail());
if (oConvertUtils.isNotEmpty(userIds)) {
String[] temp = userIds.split(",");
for (int i = 0; i < temp.length; i++) {
if (temp[i].equals(user.getId())) {
model.setChecked(true);
}
}
}
list.add(model);
}
json.put("list", list);
json.put("total", pageList.getTotal());
return json;
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project jeecg-boot by jeecgboot.
the class SysAnnouncementSendController method getMyAnnouncementSend.
/**
* @功能:获取我的消息
* @return
*/
@GetMapping(value = "/getMyAnnouncementSend")
public Result<IPage<AnnouncementSendModel>> getMyAnnouncementSend(AnnouncementSendModel announcementSendModel, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Result<IPage<AnnouncementSendModel>> result = new Result<IPage<AnnouncementSendModel>>();
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String userId = sysUser.getId();
announcementSendModel.setUserId(userId);
announcementSendModel.setPageNo((pageNo - 1) * pageSize);
announcementSendModel.setPageSize(pageSize);
Page<AnnouncementSendModel> pageList = new Page<AnnouncementSendModel>(pageNo, pageSize);
pageList = sysAnnouncementSendService.getMyAnnouncementSendPage(pageList, announcementSendModel);
result.setResult(pageList);
result.setSuccess(true);
return result;
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project jeecg-boot by jeecgboot.
the class DictAspect method parseDictText.
/**
* 本方法针对返回对象为Result 的IPage的分页列表数据进行动态字典注入
* 字典注入实现 通过对实体类添加注解@dict 来标识需要的字典内容,字典分为单字典code即可 ,table字典 code table text配合使用与原来jeecg的用法相同
* 示例为SysUser 字段为sex 添加了注解@Dict(dicCode = "sex") 会在字典服务立马查出来对应的text 然后在请求list的时候将这个字典text,已字段名称加_dictText形式返回到前端
* 例输入当前返回值的就会多出一个sex_dictText字段
* {
* sex:1,
* sex_dictText:"男"
* }
* 前端直接取值sext_dictText在table里面无需再进行前端的字典转换了
* customRender:function (text) {
* if(text==1){
* return "男";
* }else if(text==2){
* return "女";
* }else{
* return text;
* }
* }
* 目前vue是这么进行字典渲染到table上的多了就很麻烦了 这个直接在服务端渲染完成前端可以直接用
* @param result
*/
private void parseDictText(Object result) {
if (result instanceof Result) {
if (((Result) result).getResult() instanceof IPage) {
List<JSONObject> items = new ArrayList<>();
// step.1 筛选出加了 Dict 注解的字段列表
List<Field> dictFieldList = new ArrayList<>();
// 字典数据列表, key = 字典code,value=数据列表
Map<String, List<String>> dataListMap = new HashMap<>();
for (Object record : ((IPage) ((Result) result).getResult()).getRecords()) {
ObjectMapper mapper = new ObjectMapper();
String json = "{}";
try {
// 解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
json = mapper.writeValueAsString(record);
} catch (JsonProcessingException e) {
log.error("json解析失败" + e.getMessage(), e);
}
// update-begin--Author:scott -- Date:20211223 ----for:【issues/3303】restcontroller返回json数据后key顺序错乱 -----
JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
// 遍历所有字段,把字典Code取出来,放到 map 里
for (Field field : oConvertUtils.getAllFields(record)) {
String value = item.getString(field.getName());
if (oConvertUtils.isEmpty(value)) {
continue;
}
// update-end--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
if (field.getAnnotation(Dict.class) != null) {
if (!dictFieldList.contains(field)) {
dictFieldList.add(field);
}
String code = field.getAnnotation(Dict.class).dicCode();
String text = field.getAnnotation(Dict.class).dicText();
String table = field.getAnnotation(Dict.class).dictTable();
List<String> dataList;
String dictCode = code;
if (!StringUtils.isEmpty(table)) {
dictCode = String.format("%s,%s,%s", table, text, code);
}
dataList = dataListMap.computeIfAbsent(dictCode, k -> new ArrayList<>());
this.listAddAllDeduplicate(dataList, Arrays.asList(value.split(",")));
}
// date类型默认转换string格式化日期
if (field.getType().getName().equals("java.util.Date") && field.getAnnotation(JsonFormat.class) == null && item.get(field.getName()) != null) {
SimpleDateFormat aDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
}
}
items.add(item);
}
// step.2 调用翻译方法,一次性翻译
Map<String, List<DictModel>> translText = this.translateAllDict(dataListMap);
// step.3 将翻译结果填充到返回结果里
for (JSONObject record : items) {
for (Field field : dictFieldList) {
String code = field.getAnnotation(Dict.class).dicCode();
String text = field.getAnnotation(Dict.class).dicText();
String table = field.getAnnotation(Dict.class).dictTable();
String fieldDictCode = code;
if (!StringUtils.isEmpty(table)) {
fieldDictCode = String.format("%s,%s,%s", table, text, code);
}
String value = record.getString(field.getName());
if (oConvertUtils.isNotEmpty(value)) {
List<DictModel> dictModels = translText.get(fieldDictCode);
if (dictModels == null || dictModels.size() == 0) {
continue;
}
String textValue = this.translDictText(dictModels, value);
log.debug(" 字典Val : " + textValue);
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);
// TODO-sun 测试输出,待删
log.debug(" ---- dictCode: " + fieldDictCode);
log.debug(" ---- value: " + value);
log.debug(" ----- text: " + textValue);
log.debug(" ---- dictModels: " + JSON.toJSONString(dictModels));
record.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
}
}
}
((IPage) ((Result) result).getResult()).setRecords(items);
}
}
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project dynamic_dataSource by tianliuzhen.
the class TestController method testSelectPage.
@ApiOperation(value = "分页测试", notes = "插件测试")
@ApiImplicitParam(name = "page", value = "分页参数", required = true)
@PostMapping("/testSelectPage")
public ObjectResultResponse<?> testSelectPage(@RequestBody PageDto pageDto) {
Page page = new Page();
System.out.println("分页测试:::");
if (page == null) {
page = new Page();
}
// 每页数量、当前页
page.setSize(pageDto.getSize()).setCurrent(pageDto.getCurrent());
// 当 total 为小于 0 或者设置 setSearchCount(false) 分页插件不会进行 count 查询
IPage<User> iPage = user2Service.selectUserPage(page, "tom");
List<User> users = iPage.getRecords();
users.forEach(System.out::println);
log.info("1211");
return new ObjectResultResponse(page);
}
Aggregations