zoukankan      html  css  js  c++  java
  • mongo的or拼接查询

    产品需求:环节1、2、3、4

    当前登录环节:2

    需求为:查询环节>=2,且环节2的用户只为当前登录人的数据

    参数:stepList,为>环节2的step集合

    private Query queryMarkHistory(String traceId, List<Integer> stepList, UserTaskFile userTaskFile) {
              Query query = new Query();
            Criteria criteria = new Criteria();
            criteria.andOperator(Criteria.where("traceId").is(traceId));
            Criteria gtStepCriteria = Criteria.where("step").in(stepList);
            Criteria contentNameCriteria = Criteria.where("step").is(userTaskFile.getStep()).and("userId").is(userTaskFile.getUserId());
            criteria.orOperator(gtStepCriteria, contentNameCriteria);
            query.addCriteria(criteria);
            query.with(Sort.by(Sort.Direction.DESC, "createTime"));
            return query;
        }

    需求为:查询环节>2,且环节2的用户只为当前登录人的记录 + 验收不合格记录或管理员打回记录

        private Query queryMarkHistory(String traceId, List<Integer> stepList, UserTaskFile userTaskFile) {
            Query query = new Query();
            Criteria criteria = new Criteria();
            criteria.andOperator(Criteria.where("traceId").is(traceId));
    // 后续环节 Criteria afterStepCriteria = Criteria.where("step").in(stepList); // 当前环节,包括:当前用户记录 + 管理员打回 + 公会任务验收不合格 Criteria curStepCriteria = new Criteria(); curStepCriteria.andOperator(Criteria.where("step").is(userTaskFile.getStep())); Criteria criteria1 = Criteria.where("userId").is(userTaskFile.getUserId()); Criteria criteria2 = Criteria.where("type").in(MarkHistoryConst.MARK_HISTORY_TYPE_BACK_MANAGER, MarkHistoryConst.MARK_HISTORY_TYPE_ACCEPTANCE_NOT_PASSED); curStepCriteria.orOperator(criteria1, criteria2); criteria.orOperator(afterStepCriteria, curStepCriteria); query.addCriteria(criteria); query.with(Sort.by(Sort.Direction.DESC, "createTime")); return query; }
  • 相关阅读:
    iphone dev 入门实例5:Get the User Location & Address in iPhone App
    iphone dev 入门实例4:CoreData入门
    iphone dev 入门实例3:Delete a Row from UITableView
    iphone dev 入门实例2:Pass Data Between View Controllers using segue
    iphone dev 入门实例1:Use Storyboards to Build Table View
    Learning Core Data 1
    Apple dev travel
    数字信封工作原理
    Linux编程概念
    ubuntu16.04 安装 libnfc
  • 原文地址:https://www.cnblogs.com/mabiao008/p/13880861.html
Copyright © 2011-2022 走看看