Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * 批量保存记录
  *
  * @param list
  */
 public boolean saveList(List<HistoryDoorEntity> historyDoorList) {
   boolean result = false;
   if (historyDoorList != null && historyDoorList.size() > 0) {
     TransactionManager tx = DbUtils.getTranManager();
     try {
       tx.beginTransaction();
       for (HistoryDoorEntity historyDoor : historyDoorList) {
         if (historyDoor != null) {
           // 关联信息保存
           DevEntity dev = historyDoor.getDev();
           if (dev != null) {
             dbManager.saveNoTransaction(dev);
             historyDoor.setDevId(dev.getId());
           }
           result = dbManager.saveNoTransaction(historyDoor);
         }
       }
       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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
  /**
   * 批量条件删除记录
   *
   * @param queryMap 查询条件集合
   */
  public boolean delList(Map<String, Object> queryMap, Boolean delDev) {
    boolean result = false;
    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));
    }

    if (qc.getQueryNextCondition() != null) {
      TransactionManager tx = DbUtils.getTranManager();
      try {
        tx.beginTransaction();
        // 删除关联信息
        if (delDev != null && delDev.booleanValue()) {
          List<Object> list = dbManager.queryByCondition(HistoryDoorEntity.class, qc);
          String strIds = "";
          if (list != null && list.size() > 0) {
            for (Object obj : list) {
              HistoryDoorEntity entity = (HistoryDoorEntity) obj;
              strIds += entity.getDevId() + ",";
            }
            strIds = strIds.substring(0, strIds.length() - 1);
          }
          if (strIds != null && !"".equals(strIds)) {
            QueryCondition qc1 = new QueryCondition(DevEntity.ID, QueryCondition.in, strIds);
            dbManager.delByConditionsNoTransaction(DevEntity.class, qc1);
          }
        }
        result = dbManager.delByConditionsNoTransaction(HistoryDoorEntity.class, qc);
        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;
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
0
  /**
   * 根据条件查询记录集合(带分页 不带排序 不级联查询)
   *
   * @param queryMap 查询条件集合
   * @param pageno 查询页码
   * @param pagesize 查询每页记录条数
   * @return
   */
  public PageList getListByCondition(Map<String, Object> queryMap, int pageno, int pagesize) {
    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));
    }

    pagelist = dbManager.queryByCondition(HistoryDoorEntity.class, qc, pageno, pagesize);
    return pagelist;
  }
Exemplo n.º 7
0
/**
 * @Title: Service @Description: 门磁历史信息服务类
 *
 * @author feng.gu
 * @date 2015-09-17 13:34:42
 * @version V1.0
 */
public class HistoryDoorService {
  private static Logger logger = Logger.getLogger(HistoryDoorService.class);
  private DBManager dbManager = DBManager.getInstance();

  private static HistoryDoorService historyDoorService;
  /**
   * 获取实例
   *
   * @return
   */
  public static HistoryDoorService getInstance() {
    if (historyDoorService == null) {
      historyDoorService = new HistoryDoorService();
    }
    return historyDoorService;
  }

  /**
   * 保存记录
   *
   * @param obj
   */
  public boolean save(HistoryDoorEntity historyDoor) {
    boolean result = false;
    if (historyDoor != null) {
      TransactionManager tx = DbUtils.getTranManager();
      try {
        tx.beginTransaction();
        // 关联信息保存
        DevEntity dev = historyDoor.getDev();
        if (dev != null) {
          dbManager.saveNoTransaction(dev);
          historyDoor.setDevId(dev.getId());
        }
        result = dbManager.saveNoTransaction(historyDoor);
        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;
  }

  /**
   * 批量保存记录
   *
   * @param list
   */
  public boolean saveList(List<HistoryDoorEntity> historyDoorList) {
    boolean result = false;
    if (historyDoorList != null && historyDoorList.size() > 0) {
      TransactionManager tx = DbUtils.getTranManager();
      try {
        tx.beginTransaction();
        for (HistoryDoorEntity historyDoor : historyDoorList) {
          if (historyDoor != null) {
            // 关联信息保存
            DevEntity dev = historyDoor.getDev();
            if (dev != null) {
              dbManager.saveNoTransaction(dev);
              historyDoor.setDevId(dev.getId());
            }
            result = dbManager.saveNoTransaction(historyDoor);
          }
        }
        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;
  }

  /**
   * 根据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;
  }

  /**
   * 根据条件查询记录集合(不分页 不带排序 不级联查询)
   *
   * @param queryMap 查询条件集合
   * @return
   */
  public List<Object> getListByCondition(Map<String, Object> queryMap) {
    List<Object> list = 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));
    }

    list = dbManager.queryByCondition(HistoryDoorEntity.class, qc);
    return list;
  }

  /**
   * 根据条件查询记录集合(不分页 带排序 带级联查询)
   *
   * @param queryMap 查询条件集合
   * @param orderList 排序条件集合
   * @param devShow 是否查询关联信息,默认false(当为true时注意效率)
   * @return
   */
  public List<Object> getListByCondition(
      Map<String, Object> queryMap, List<OrderVO> orderList, Boolean devShow) {
    List<Object> list = 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));
          }
        }
      }
    }
    list = dbManager.queryByConditions(HistoryDoorEntity.class, qc, oc);
    int a = 0;
    if (devShow != null && devShow.booleanValue()) {
      a++;
    }
    if (a > 0 && list != null && list.size() > 0) {
      List<Object> result = new ArrayList<Object>();
      for (int i = 0; i < list.size(); i++) {
        HistoryDoorEntity obj = (HistoryDoorEntity) list.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);
      }
      list = result;
    }
    return list;
  }

  /**
   * 根据条件查询记录集合(带分页 不带排序 不级联查询)
   *
   * @param queryMap 查询条件集合
   * @param pageno 查询页码
   * @param pagesize 查询每页记录条数
   * @return
   */
  public PageList getListByCondition(Map<String, Object> queryMap, int pageno, int pagesize) {
    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));
    }

    pagelist = dbManager.queryByCondition(HistoryDoorEntity.class, qc, pageno, pagesize);
    return pagelist;
  }

  /**
   * 根据条件查询记录集合(带分页 带排序 带级联查询)
   *
   * @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;
  }

  /**
   * 删除记录
   *
   * @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;
  }

  /**
   * 批量条件删除记录
   *
   * @param queryMap 查询条件集合
   */
  public boolean delList(Map<String, Object> queryMap, Boolean delDev) {
    boolean result = false;
    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));
    }

    if (qc.getQueryNextCondition() != null) {
      TransactionManager tx = DbUtils.getTranManager();
      try {
        tx.beginTransaction();
        // 删除关联信息
        if (delDev != null && delDev.booleanValue()) {
          List<Object> list = dbManager.queryByCondition(HistoryDoorEntity.class, qc);
          String strIds = "";
          if (list != null && list.size() > 0) {
            for (Object obj : list) {
              HistoryDoorEntity entity = (HistoryDoorEntity) obj;
              strIds += entity.getDevId() + ",";
            }
            strIds = strIds.substring(0, strIds.length() - 1);
          }
          if (strIds != null && !"".equals(strIds)) {
            QueryCondition qc1 = new QueryCondition(DevEntity.ID, QueryCondition.in, strIds);
            dbManager.delByConditionsNoTransaction(DevEntity.class, qc1);
          }
        }
        result = dbManager.delByConditionsNoTransaction(HistoryDoorEntity.class, qc);
        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;
  }
}