Search in sources :

Example 51 with IPage

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) KmSearchResultObjVO(org.jeecg.common.system.vo.KmSearchResultObjVO) Date(java.util.Date) Result(org.jeecg.common.api.vo.Result) Field(java.lang.reflect.Field) IPage(com.baomidou.mybatisplus.core.metadata.IPage) JsonFormat(com.fasterxml.jackson.annotation.JsonFormat) JSONObject(com.alibaba.fastjson.JSONObject) Dict(org.jeecg.common.aspect.annotation.Dict) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 52 with IPage

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;
}
Also used : JeecgEntityExcelView(org.jeecgframework.poi.excel.view.JeecgEntityExcelView) ModelAndView(org.springframework.web.servlet.ModelAndView) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) LoginUser(org.jeecg.common.system.vo.LoginUser) ExportParams(org.jeecgframework.poi.excel.entity.ExportParams)

Example 53 with IPage

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);
        }
    });
}
Also used : EsGoodsIndex(cn.lili.modules.search.entity.dos.EsGoodsIndex) PromotionGoods(cn.lili.modules.promotion.entity.dos.PromotionGoods) SearchPage(org.springframework.data.elasticsearch.core.SearchPage) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ServiceException(cn.lili.common.exception.ServiceException) MyBatisSystemException(org.mybatis.spring.MyBatisSystemException) IOException(java.io.IOException) RetryException(cn.lili.common.exception.RetryException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ServiceException(cn.lili.common.exception.ServiceException)

Example 54 with IPage

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;
}
Also used : Pageable(org.springframework.data.domain.Pageable) SearchHit(org.springframework.data.elasticsearch.core.SearchHit) SystemLogVO(cn.lili.modules.permission.entity.vo.SystemLogVO) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)

Example 55 with 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);
}
Also used : Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SysContentEntity(com.company.project.entity.SysContentEntity) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) DataScope(com.company.project.common.aop.annotation.DataScope) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

IPage (com.baomidou.mybatisplus.core.metadata.IPage)197 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)152 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)73 ApiOperation (io.swagger.annotations.ApiOperation)28 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 PageDTO (com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 LoginUser (org.jeecg.common.system.vo.LoginUser)16 JSONObject (com.alibaba.fastjson.JSONObject)15 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 PageInfo (org.apache.dolphinscheduler.api.utils.PageInfo)13 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)11 Result (org.jeecg.common.api.vo.Result)10 List (java.util.List)9 User (org.apache.dolphinscheduler.dao.entity.User)9 Field (java.lang.reflect.Field)8 Date (java.util.Date)8 Collectors (java.util.stream.Collectors)7 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)7