Ejemplo n.º 1
0
 /**
  * 根据id读取记录
  *
  * @param id 主键
  * @param devShow 是否查询关联信息
  * @param obj
  */
 public HistoryDoorEntity getById(Integer id, Boolean devShow) {
   HistoryDoorEntity obj = null;
   if (id != null) {
     obj = (HistoryDoorEntity) dbManager.getById(id, HistoryDoorEntity.class);
     // 查询关联内容
     if (devShow != null && devShow.booleanValue() && obj != null && obj.getDevId() > 0) {
       DevEntity dev = (DevEntity) dbManager.getById(obj.getDevId(), DevEntity.class);
       obj.setDev(dev);
     }
   }
   return obj;
 }
Ejemplo n.º 2
0
 /**
  * 删除记录
  *
  * @param id 主键
  * @param obj
  */
 public boolean del(Integer id, Boolean delDev) {
   boolean result = false;
   if (id != null && id > 0) {
     TransactionManager tx = DbUtils.getTranManager();
     try {
       tx.beginTransaction();
       // 删除关联信息
       if (delDev != null && delDev.booleanValue()) {
         HistoryDoorEntity historyDoor =
             (HistoryDoorEntity) dbManager.getById(id, HistoryDoorEntity.class);
         if (historyDoor != null && historyDoor.getDevId() != null) {
           dbManager.delNoTransaction(historyDoor.getDevId(), DevEntity.class);
         }
       }
       result = dbManager.delNoTransaction(id, HistoryDoorEntity.class);
       tx.commitAndClose();
     } catch (Exception e) {
       logger.error("数据库提交失败!");
       logger.error(e);
       result = false;
       try {
         tx.rollbackAndClose();
       } catch (Exception ex) {
         logger.error("数据库回滚失败!");
         logger.error(ex);
       }
     }
   }
   return result;
 }
Ejemplo n.º 3
0
  /**
   * 根据条件查询记录集合(带分页 带排序 带级联查询)
   *
   * @param queryMap 查询条件集合
   * @param orderList 排序条件集合
   * @param pageno 查询页码
   * @param pagesize 查询每页记录条数
   * @param devShow 是否查询关联信息,默认false(当为true时注意效率)
   * @return
   */
  public PageList getListByCondition(
      Map<String, Object> queryMap,
      List<OrderVO> orderList,
      int pageno,
      int pagesize,
      Boolean devShow) {
    PageList pagelist = null;
    if (queryMap == null) {
      queryMap = new HashMap<String, Object>();
    }
    Object id = queryMap.get("id");
    Object id_gt = queryMap.get("id_gt");
    Object id_ge = queryMap.get("id_ge");
    Object id_lt = queryMap.get("id_lt");
    Object id_le = queryMap.get("id_le");
    Object id_in = queryMap.get("id_in");
    Object devId = queryMap.get("devId");
    Object devId_gt = queryMap.get("devId_gt");
    Object devId_ge = queryMap.get("devId_ge");
    Object devId_lt = queryMap.get("devId_lt");
    Object devId_le = queryMap.get("devId_le");
    Object devId_in = queryMap.get("devId_in");
    Object openclose = queryMap.get("openclose");
    Object openclose_like = queryMap.get("openclose_like");
    Object openclose_isNull = queryMap.get("openclose_isNull");
    Object openclose_isNotNull = queryMap.get("openclose_isNotNull");
    Object openclose_in = queryMap.get("openclose_in");
    Object level = queryMap.get("level");
    Object level_gt = queryMap.get("level_gt");
    Object level_ge = queryMap.get("level_ge");
    Object level_lt = queryMap.get("level_lt");
    Object level_le = queryMap.get("level_le");
    Object level_in = queryMap.get("level_in");
    Object alarmupdatetime_gt = queryMap.get("alarmupdatetime_gt");
    Object alarmupdatetime_ge = queryMap.get("alarmupdatetime_ge");
    Object alarmupdatetime_lt = queryMap.get("alarmupdatetime_lt");
    Object alarmupdatetime_le = queryMap.get("alarmupdatetime_le");

    QueryCondition qc = new QueryCondition(HistoryDoorEntity.ID, QueryCondition.gt, "0");
    if (id != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.ID, QueryCondition.eq, id));
    }
    if (id_gt != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.ID, QueryCondition.gt, id_gt));
    }
    if (id_ge != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.ID, QueryCondition.ge, id_ge));
    }
    if (id_lt != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.ID, QueryCondition.lt, id_lt));
    }
    if (id_le != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.ID, QueryCondition.le, id_le));
    }
    if (id_in != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.ID, QueryCondition.in, id_in));
    }
    if (devId != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.DEV_ID, QueryCondition.eq, devId));
    }
    if (devId_gt != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.DEV_ID, QueryCondition.gt, devId_gt));
    }
    if (devId_ge != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.DEV_ID, QueryCondition.ge, devId_ge));
    }
    if (devId_lt != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.DEV_ID, QueryCondition.lt, devId_lt));
    }
    if (devId_le != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.DEV_ID, QueryCondition.le, devId_le));
    }
    if (devId_in != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.DEV_ID, QueryCondition.in, devId_in));
    }
    if (openclose != null) {
      qc.andCondition(
          new QueryCondition(HistoryDoorEntity.OPENCLOSE, QueryCondition.eq, openclose));
    }
    if (openclose_like != null) {
      qc.andCondition(
          new QueryCondition(HistoryDoorEntity.OPENCLOSE, QueryCondition.like, openclose_like));
    }
    if (openclose_isNull != null) {
      qc.andCondition(
          new QueryCondition(HistoryDoorEntity.OPENCLOSE, QueryCondition.isNull, openclose_isNull));
    }
    if (openclose_isNotNull != null) {
      qc.andCondition(
          new QueryCondition(
              HistoryDoorEntity.OPENCLOSE, QueryCondition.isNotNull, openclose_isNotNull));
    }
    if (openclose_in != null) {
      qc.andCondition(
          new QueryCondition(HistoryDoorEntity.OPENCLOSE, QueryCondition.in, openclose_in));
    }
    if (level != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.LEVEL, QueryCondition.eq, level));
    }
    if (level_gt != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.LEVEL, QueryCondition.gt, level_gt));
    }
    if (level_ge != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.LEVEL, QueryCondition.ge, level_ge));
    }
    if (level_lt != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.LEVEL, QueryCondition.lt, level_lt));
    }
    if (level_le != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.LEVEL, QueryCondition.le, level_le));
    }
    if (level_in != null) {
      qc.andCondition(new QueryCondition(HistoryDoorEntity.LEVEL, QueryCondition.in, level_in));
    }
    if (alarmupdatetime_gt != null) {
      qc.andCondition(
          new QueryCondition(
              HistoryDoorEntity.ALARMUPDATETIME, QueryCondition.gt, alarmupdatetime_gt));
    }
    if (alarmupdatetime_ge != null) {
      qc.andCondition(
          new QueryCondition(
              HistoryDoorEntity.ALARMUPDATETIME, QueryCondition.ge, alarmupdatetime_ge));
    }
    if (alarmupdatetime_lt != null) {
      qc.andCondition(
          new QueryCondition(
              HistoryDoorEntity.ALARMUPDATETIME, QueryCondition.lt, alarmupdatetime_lt));
    }
    if (alarmupdatetime_le != null) {
      qc.andCondition(
          new QueryCondition(
              HistoryDoorEntity.ALARMUPDATETIME, QueryCondition.le, alarmupdatetime_le));
    }

    OrderByCondition oc = null;
    if (orderList != null && orderList.size() > 0) {
      for (int i = 0; i < orderList.size(); i++) {
        OrderVO order = orderList.get(i);
        String orderColumnt = null;
        String orderType = null;
        if (order.getName() != null && !"".equals(order.getName())) {
          orderColumnt = StringUtil.formatFieldToColumnt(order.getName());
          orderType = order.getOrderType();
          if (orderType == null || "".equals(orderType.trim())) {
            orderType = OrderByCondition.desc;
          }
          if (i == 0) {
            oc = new OrderByCondition(orderColumnt, orderType);
          } else {
            oc.orderByCondition(new OrderByCondition(orderColumnt, orderType));
          }
        }
      }
    }
    pagelist = dbManager.queryByConditions(HistoryDoorEntity.class, qc, oc, pageno, pagesize);
    int a = 0;
    if (devShow != null && devShow.booleanValue()) {
      a++;
    }
    if (a > 0
        && pagelist != null
        && pagelist.getResultList() != null
        && pagelist.getResultList().size() > 0) {
      List<Object> result = new ArrayList<Object>();
      for (int i = 0; i < pagelist.getResultList().size(); i++) {
        HistoryDoorEntity obj = (HistoryDoorEntity) pagelist.getResultList().get(i);
        // 查询关联内容
        if (devShow != null && devShow.booleanValue() && obj != null && obj.getDevId() > 0) {
          DevEntity dev = (DevEntity) dbManager.getById(obj.getDevId(), DevEntity.class);
          obj.setDev(dev);
        }
        result.add(obj);
      }
      pagelist.setResultList(result);
    }
    return pagelist;
  }