use of com.baomidou.mybatisplus.core.metadata.IPage in project kykms by mahonelau.
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<>();
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);
}
JSONObject item = JSONObject.parseObject(json);
// for (Field field : record.getClass().getDeclaredFields()) {
for (Field field : oConvertUtils.getAllFields(record)) {
// update-end--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
if (field.getAnnotation(Dict.class) != null) {
String code = field.getAnnotation(Dict.class).dicCode();
String text = field.getAnnotation(Dict.class).dicText();
String table = field.getAnnotation(Dict.class).dictTable();
String key = String.valueOf(item.get(field.getName()));
// 翻译字典值对应的txt
String textValue = translateDictValue(code, text, table, key);
log.debug(" 字典Val : " + textValue);
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);
item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
}
// 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);
}
((IPage) ((Result) result).getResult()).setRecords(items);
} else if (((Result) result).getResult() instanceof KmSearchResultObjVO) {
List<JSONObject> items = new ArrayList<>();
for (Object record : ((KmSearchResultObjVO) ((Result) result).getResult()).getKmSearchResultVOPage().getRecords()) {
ObjectMapper mapper = new ObjectMapper();
String json = "{}";
try {
// 解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
json = mapper.writeValueAsString(record);
} catch (JsonProcessingException e) {
log.error("json解析失败" + e.getMessage(), e);
}
JSONObject item = JSONObject.parseObject(json);
// for (Field field : record.getClass().getDeclaredFields()) {
for (Field field : oConvertUtils.getAllFields(record)) {
// update-end--Author:scott -- Date:20190603 ----for:解决继承实体字段无法翻译问题------
if (field.getAnnotation(Dict.class) != null) {
String code = field.getAnnotation(Dict.class).dicCode();
String text = field.getAnnotation(Dict.class).dicText();
String table = field.getAnnotation(Dict.class).dictTable();
String key = String.valueOf(item.get(field.getName()));
// 翻译字典值对应的txt
String textValue = translateDictValue(code, text, table, key);
log.debug(" 字典Val : " + textValue);
log.debug(" __翻译字典字段__ " + field.getName() + CommonConstant.DICT_TEXT_SUFFIX + ": " + textValue);
item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
}
// 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);
}
((KmSearchResultObjVO) ((Result) result).getResult()).getKmSearchResultVOPage().setRecords(items);
}
}
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project kykms by mahonelau.
the class JeecgController method exportXlsSheet.
/**
* 根据每页sheet数量导出多sheet
*
* @param request
* @param object 实体类
* @param clazz 实体类class
* @param title 标题
* @param exportFields 导出字段自定义
* @param pageNum 每个sheet的数据条数
* @param request
*/
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields, Integer pageNum) {
// Step.1 组装查询条件
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// Step.2 计算分页sheet数据
double total = service.count();
int count = (int) Math.ceil(total / pageNum);
// Step.3 多sheet处理
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
for (int i = 1; i <= count; i++) {
Page<T> page = new Page<T>(i, pageNum);
IPage<T> pageList = service.page(page, queryWrapper);
List<T> records = pageList.getRecords();
List<T> exportList = null;
// 过滤选中数据
String selections = request.getParameter("selections");
if (oConvertUtils.isNotEmpty(selections)) {
List<String> selectionList = Arrays.asList(selections.split(","));
exportList = records.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList());
} else {
exportList = records;
}
Map<String, Object> map = new HashMap<String, Object>();
ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, upLoadPath);
exportParams.setType(ExcelType.XSSF);
// map.put("title",exportParams);//表格Title
// 表格Title
map.put(NormalExcelConstants.PARAMS, exportParams);
// 表格对应实体
map.put(NormalExcelConstants.CLASS, clazz);
// 数据集合
map.put(NormalExcelConstants.DATA_LIST, exportList);
listMap.add(map);
}
// Step.4 AutoPoi 导出Excel
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
// 此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(NormalExcelConstants.FILE_NAME, title);
mv.addObject(NormalExcelConstants.MAP_LIST, listMap);
return mv;
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project lilishop by lilishop.
the class EsGoodsIndexServiceImpl method init.
@Override
public void init() {
// 获取索引任务标识
Boolean flag = (Boolean) cache.get(CachePrefix.INIT_INDEX_FLAG.getPrefix());
// 为空则默认写入没有任务
if (flag == null) {
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
}
// 有正在初始化的任务,则提示异常
if (Boolean.TRUE.equals(flag)) {
throw new ServiceException(ResultCode.INDEX_BUILDING);
}
// 初始化标识
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null);
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), true);
ThreadUtil.execAsync(() -> {
try {
LambdaQueryWrapper<Goods> goodsQueryWrapper = new LambdaQueryWrapper<>();
goodsQueryWrapper.eq(Goods::getAuthFlag, GoodsAuthEnum.PASS.name());
goodsQueryWrapper.eq(Goods::getMarketEnable, GoodsStatusEnum.UPPER.name());
goodsQueryWrapper.eq(Goods::getDeleteFlag, false);
for (int i = 1; ; i++) {
List<EsGoodsIndex> esGoodsIndices = new ArrayList<>();
IPage<Goods> page = new Page<>(i, 1000);
IPage<Goods> goodsIPage = goodsService.page(page, goodsQueryWrapper);
if (goodsIPage == null || CollUtil.isEmpty(goodsIPage.getRecords())) {
break;
}
for (Goods goods : goodsIPage.getRecords()) {
LambdaQueryWrapper<GoodsSku> skuQueryWrapper = new LambdaQueryWrapper<>();
skuQueryWrapper.eq(GoodsSku::getGoodsId, goods.getId());
skuQueryWrapper.eq(GoodsSku::getAuthFlag, GoodsAuthEnum.PASS.name());
skuQueryWrapper.eq(GoodsSku::getMarketEnable, GoodsStatusEnum.UPPER.name());
skuQueryWrapper.eq(GoodsSku::getDeleteFlag, false);
for (int j = 1; ; j++) {
IPage<GoodsSku> skuPage = new Page<>(j, 100);
IPage<GoodsSku> skuIPage = goodsSkuService.page(skuPage, skuQueryWrapper);
if (skuIPage == null || CollUtil.isEmpty(skuIPage.getRecords())) {
break;
}
int skuSource = 100;
for (GoodsSku goodsSku : skuIPage.getRecords()) {
EsGoodsIndex esGoodsIndex = wrapperEsGoodsIndex(goodsSku, goods);
esGoodsIndex.setSkuSource(skuSource--);
esGoodsIndices.add(esGoodsIndex);
// 库存锁是在redis做的,所以生成索引,同时更新一下redis中的库存数量
cache.put(GoodsSkuService.getStockCacheKey(goodsSku.getId()), goodsSku.getQuantity());
}
}
}
this.initIndex(esGoodsIndices);
}
// 初始化商品索引
} catch (Exception e) {
log.error("商品索引生成异常:", e);
// 如果出现异常,则将进行中的任务标识取消掉,打印日志
cache.put(CachePrefix.INIT_INDEX_PROCESS.getPrefix(), null);
cache.put(CachePrefix.INIT_INDEX_FLAG.getPrefix(), false);
}
});
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project lilishop by lilishop.
the class SystemLogServiceImpl method queryLog.
@Override
public IPage<SystemLogVO> queryLog(String storeId, String operatorName, String key, SearchVO searchVo, PageVO pageVO) {
pageVO.setNotConvert(true);
IPage<SystemLogVO> iPage = new Page<>();
NativeSearchQueryBuilder nativeSearchQueryBuilder = new NativeSearchQueryBuilder();
if (pageVO.getPageNumber() != null && pageVO.getPageSize() != null) {
int pageNumber = pageVO.getPageNumber() - 1;
if (pageNumber < 0) {
pageNumber = 0;
}
Pageable pageable = PageRequest.of(pageNumber, pageVO.getPageSize());
// 分页
nativeSearchQueryBuilder.withPageable(pageable);
iPage.setCurrent(pageVO.getPageNumber());
iPage.setSize(pageVO.getPageSize());
}
if (CharSequenceUtil.isNotEmpty(storeId)) {
nativeSearchQueryBuilder.withFilter(QueryBuilders.matchQuery("storeId", storeId));
}
if (CharSequenceUtil.isNotEmpty(operatorName)) {
nativeSearchQueryBuilder.withFilter(QueryBuilders.wildcardQuery("username", "*" + operatorName + "*"));
}
if (CharSequenceUtil.isNotEmpty(key)) {
BoolQueryBuilder filterBuilder = new BoolQueryBuilder();
filterBuilder.should(QueryBuilders.wildcardQuery("requestUrl", "*" + key + "*")).should(QueryBuilders.wildcardQuery("requestParam", "*" + key + "*")).should(QueryBuilders.wildcardQuery("responseBody", "*" + key + "*")).should(QueryBuilders.wildcardQuery("name", "*" + key + "*"));
nativeSearchQueryBuilder.withFilter(filterBuilder);
}
// 时间有效性判定
if (searchVo.getConvertStartDate() != null && searchVo.getConvertEndDate() != null) {
BoolQueryBuilder filterBuilder = new BoolQueryBuilder();
// 大于方法
filterBuilder.must(QueryBuilders.rangeQuery("createTime").gte(DateUtil.format(searchVo.getConvertStartDate(), "dd/MM/yyyy")).lte(DateUtil.format(searchVo.getConvertEndDate(), "dd/MM/yyyy")).format("dd/MM/yyyy||yyyy"));
nativeSearchQueryBuilder.withFilter(filterBuilder);
}
if (CharSequenceUtil.isNotEmpty(pageVO.getOrder()) && CharSequenceUtil.isNotEmpty(pageVO.getSort())) {
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort(pageVO.getSort()).order(SortOrder.valueOf(pageVO.getOrder().toUpperCase())));
} else {
nativeSearchQueryBuilder.withSort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC));
}
SearchHits<SystemLogVO> searchResult = restTemplate.search(nativeSearchQueryBuilder.build(), SystemLogVO.class);
iPage.setTotal(searchResult.getTotalHits());
iPage.setRecords(searchResult.getSearchHits().stream().map(SearchHit::getContent).collect(Collectors.toList()));
return iPage;
}
use of com.baomidou.mybatisplus.core.metadata.IPage in project springboot-manager by aitangbao.
the class SysContentController method findListByPage.
@ApiOperation(value = "查询分页数据")
@PostMapping("/listByPage")
@RequiresPermissions("sysContent:list")
@DataScope
public DataResult findListByPage(@RequestBody SysContentEntity sysContent) {
Page page = new Page(sysContent.getPage(), sysContent.getLimit());
LambdaQueryWrapper<SysContentEntity> queryWrapper = Wrappers.lambdaQuery();
// 查询条件示例
if (!StringUtils.isEmpty(sysContent.getTitle())) {
queryWrapper.like(SysContentEntity::getTitle, sysContent.getTitle());
}
// 数据权限示例, 需手动添加此条件 begin
if (!CollectionUtils.isEmpty(sysContent.getCreateIds())) {
queryWrapper.in(SysContentEntity::getCreateId, sysContent.getCreateIds());
}
// 数据权限示例, 需手动添加此条件 end
IPage<SysContentEntity> iPage = sysContentService.page(page, queryWrapper);
return DataResult.success(iPage);
}
Aggregations