public Map getMachineInfo(String machineId) {
   if (!WebUtil.isNumeric(machineId)) {
     return null;
   }
   List<Machine> l =
       this.getHibernateTemplate().find("from Machine m where m.id = ?", new Integer(machineId));
   if (WebUtil.isNullForList(l)) return null;
   Map<String, String> status = getMachineStatus();
   Machine m = l.get(0);
   Map<String, String> result = new HashMap();
   result.put("MachineId", m.getId().toString());
   result.put("MachineNo", m.getMachineNo());
   result.put("PpsNo", m.getPpsNo());
   result.put("ServiceFromDate", WebUtil.formatDateString(m.getServiceFromDate(), "yyyy-MM-dd"));
   result.put("ServiceEndDate", WebUtil.formatDateString(m.getServiceEndDate(), "yyyy-MM-dd"));
   result.put("OutDate", WebUtil.formatDateString(m.getOutDate(), "yyyy-MM-dd"));
   result.put("InvoiceDate", WebUtil.formatDateString(m.getInvoiceDate(), "yyyy-MM-dd"));
   result.put("PaymentStatus", m.getPaymentStatus());
   result.put("PaymentCompany", m.getPaymentCompany());
   result.put("PaymentCompanyCd", m.getPaymentCompanyCd());
   result.put("PaymentDate", WebUtil.formatDateString(m.getPaymentDate(), "yyyy-MM-dd"));
   if (WebUtil.isNotNull(m.getPaymentAmt()))
     result.put("PaymentAmt", m.getPaymentAmt().toString());
   result.put("LastTime", WebUtil.formatDateString(m.getLastTime(), "yyyy-MM-dd"));
   if (WebUtil.isNotNull(m.getLastCompanyId())) {
     List<Company> cl =
         this.getHibernateTemplate()
             .find("from Company where Status = 'NORMAL' and id = " + m.getLastCompanyId());
     if (!WebUtil.isNullForList(cl)) {
       Company c = cl.get(0);
       result.put("LastCompanyName", c.getCompanyName());
       result.put("LastCompanyId", m.getLastCompanyId().toString());
     }
   }
   result.put("MachineStatus", m.getStatus());
   result.put("MachineStatusName", status.get(m.getStatus()));
   if (m.getMachineTypeId() != null) {
     List<MachineType> mtList =
         this.getHibernateTemplate()
             .find("from MachineType where Status = 'NORMAL' and id = " + m.getMachineTypeId());
     if (!WebUtil.isNullForList(mtList)) {
       MachineType mt = mtList.get(0);
       result.put("MachineTypeId", m.getMachineTypeId().toString());
       result.put("MachineType", mt.getMachineType());
       result.put("MachineCd", mt.getMachineCd());
     }
   }
   result.put("Origin", m.getOrigin());
   result.put("CustomerNo", m.getCustomerNo());
   result.put("CustomerName", m.getCustomerName());
   return result;
 }
 public Map checkMachine(String machineNo, UserLogin ul) {
   Map result = new HashMap();
   List<Object[]> ml =
       this.getHibernateTemplate()
           .find(
               "from Machine m,MachineType mt where m.MachineTypeId = mt.id and m.MachineNo = ?",
               machineNo);
   if (WebUtil.isNullForList(ml)) {
     result.put("Flag", "ERROR");
     result.put("Message", "无理光公司出货信息");
     return result;
   }
   Object[] obj = ml.get(0);
   Machine m = (Machine) obj[0];
   MachineType mt = (MachineType) obj[1];
   int companyId = ul.getCompanyId();
   List<CompanyMachineTypeRef> cl =
       this.getHibernateTemplate()
           .find(
               "from CompanyMachineTypeRef where id.CompanyId = ? and id.MachineTypeId = ?",
               new Object[] {companyId, m.getMachineTypeId()});
   if (WebUtil.isNullForList(cl)) {
     result.put("Flag", "ERROR");
     result.put("Message", "贵公司没有该机型维护能力");
     return result;
   }
   if (WebUtil.isNotNull(m.getStatus()) && m.getStatus().equals("REPAIRING")) {
     result.put("Flag", "ERROR");
     result.put("Message", "该机器正在维修中...");
     return result;
   }
   if (WebUtil.isNotNull(m.getStatus()) && m.getStatus().equals("CHANGE")) {
     result.put("Flag", "ERROR");
     result.put("Message", "该机器已换货");
     return result;
   }
   result.put("Flag", "SUCCESS");
   Map mm = new HashMap();
   mm.put("MachineId", m.getId());
   mm.put("MachineNo", m.getMachineNo());
   mm.put("MachineTypeId", mt.getId());
   mm.put("MachineTypeName", mt.getMachineType());
   mm.put("MachineCat", mt.getMachineCat());
   mm.put("MachineCd", mt.getMachineCd());
   mm.put("PpsNo", m.getPpsNo());
   mm.put("PaymentStatus", m.getPaymentStatus());
   mm.put("PaymentCompany", m.getPaymentCompany());
   mm.put("PaymentCompanyCd", m.getPaymentCompanyCd());
   mm.put("ServiceFromDate", m.getServiceFromDate());
   mm.put("ServiceEndDate", m.getServiceEndDate());
   mm.put("InvoiceDate", m.getInvoiceDate());
   mm.put("OutDate", m.getOutDate());
   mm.put("LastTime", m.getLastTime());
   result.put("Machine", mm);
   return result;
 }
  public Map searchMachine(Map param, int currentPage, int pageRow) {
    StringBuffer hql = new StringBuffer();
    hql.append("from Machine m ,MachineType mt where m.MachineTypeId = mt.id ");
    StringBuffer con = new StringBuffer();
    List conList = new ArrayList();
    if (!WebUtil.isNull(param.get("MachineNo"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" m.MachineNo = :Condition" + conList.size());
      conList.add(param.get("MachineNo").toString());
    }
    if (!WebUtil.isNull(param.get("PpsNo"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" m.PpsNo like :Condition" + conList.size());
      conList.add("%" + param.get("PpsNo") + "%");
    }

    if (!WebUtil.isNull(param.get("CustomerName"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" m.CustomerName like :Condition" + conList.size());
      conList.add("%" + param.get("CustomerName") + "%");
    }
    if (!WebUtil.isNull(param.get("MachineTypeId"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" m.MachineTypeId = :Condition" + conList.size());
      conList.add(new Integer(param.get("MachineTypeId").toString()));
    }
    if (!WebUtil.isNull(param.get("MachineCd"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" mt.MachineCd = :Condition" + conList.size());
      conList.add(param.get("MachineCd"));
    }
    if (!WebUtil.isNull(param.get("FromOutDate"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" m.OutDate >= :Condition" + conList.size());
      conList.add(WebUtil.toDateForString(param.get("FromOutDate").toString(), "yyyy-MM-dd"));
    }
    if (!WebUtil.isNull(param.get("EndOutDate"))) {
      if (con.length() > 0) con.append(" and ");
      con.append(" m.OutDate < :Condition" + conList.size());
      conList.add(WebUtil.toDateForString(param.get("EndOutDate").toString(), "yyyy-MM-dd"));
    }
    if (con.length() > 0) hql.append(" and " + con.toString());

    Session session = this.getSession();
    Map result = null;
    try {
      Query q1 = session.createQuery("select count(*) " + hql.toString());
      // 查询条件
      for (int i = 0; i < conList.size(); i++) {
        q1.setParameter("Condition" + i, conList.get(i));
      }
      List<Long> countList = q1.list();
      int count = countList.get(0).intValue();
      Query q = session.createQuery(hql.toString());
      // 查询条件
      for (int i = 0; i < conList.size(); i++) {
        q.setParameter("Condition" + i, conList.get(i));
      }
      if (pageRow > 0) {
        q.setFirstResult((currentPage - 1) * pageRow);
        q.setMaxResults(pageRow);
      }
      result = new HashMap();
      List<Object[]> l = q.list();
      List<Map> r = new ArrayList();
      for (Object[] obj : l) {
        Machine mm = (Machine) obj[0];
        MachineType mt = (MachineType) obj[1];
        Map m = new HashMap();
        m.put("MachineId", mm.getId().toString());
        m.put("MachineNo", mm.getMachineNo());
        m.put("PpsNo", mm.getPpsNo());
        m.put("MachineTypeId", mm.getMachineTypeId());
        m.put("MachineType", mt.getMachineType());
        m.put("MachineCd", mt.getMachineCd());
        m.put("CustomerName", mm.getCustomerName());
        m.put("CustomerNo", mm.getCustomerNo());
        m.put("OuterDate", WebUtil.formatDateString(mm.getOutDate(), "yyyy-MM-dd"));
        m.put("ServiceFromDate", WebUtil.formatDateString(mm.getServiceFromDate(), "yyyy-MM-dd"));
        m.put("ServiceEndDate", WebUtil.formatDateString(mm.getServiceEndDate(), "yyyy-MM-dd"));
        m.put("PaymentStatus", mm.getPaymentStatus());
        r.add(m);
      }
      result.put("RESULT", r);
      result.put("COUNT_ROW", count);
    } catch (HibernateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (RuntimeException e) {
      result.put("Flag", "ERROR");
      result.put("Message", e.getMessage());
      logger.error(e.getMessage());
    } finally {
      if (session != null && session.isOpen()) session.close();
    }
    return result;
  }