public PageResult orderList(String mobile, String openid, PageResult result) {
   Employer employer = null;
   List<ServiceOrderView> view = new ArrayList<ServiceOrderView>();
   if (StringUtils.isEmpty(openid)) {
     String mobileHql = "from Employer t where t.ovld = true and t.mobilePhone = ?";
     employer = dao.getSingleResultByHQL(Employer.class, mobileHql, mobile);
   } else {
     String openidHql = "from Employer t where t.ovld = true and t.openid = ?";
     List<Employer> listEmployers = dao.getListResultByHQL(Employer.class, openidHql, openid);
     if (listEmployers == null || listEmployers.size() == 0) {
       result.setResult(ResultInfo.SUCCESS);
       result.put("result", view);
       return result;
     }
     if (listEmployers.size() > 1) {
       result.setResult(ResultInfo.MULTI_EMPLYER);
       List<EmployerView> listViews = new ArrayList<EmployerView>();
       for (Employer e : listEmployers) {
         listViews.add(e.view());
       }
       result.put("result", listViews);
       return result;
     } else {
       employer = listEmployers.get(0);
     }
   }
   if (employer == null) {
     result.setResult(ResultInfo.SUCCESS);
     result.put("result", view);
     return result;
   }
   String hql = "from ServiceOrder t where t.ovld = true and t.employer.id=?";
   List<ServiceOrder> orders = dao.getListResultByHQL(ServiceOrder.class, hql, employer.getId());
   if (orders == null) orders = new ArrayList<ServiceOrder>();
   for (ServiceOrder order : orders) {
     view.add(order.view());
   }
   result.setResult(ResultInfo.SUCCESS);
   result.put("result", view);
   return result;
 }
  public List<BabysitterView> getPanicBabysitters(String serviceOrderId) {
    long serviceOrderIdl = Long.valueOf(serviceOrderId);
    String hql =
        "from PanicBuyingOrder t where t.ovld = true and t.serviceOrder.id = ? and t.serviceOrder.orderGuid is null";
    List<PanicBuyingOrder> orders =
        dao.getListResultByHQL(PanicBuyingOrder.class, hql, serviceOrderIdl);
    List<BabysitterView> views = new ArrayList<BabysitterView>();
    for (PanicBuyingOrder order : orders) {
      views.add(order.getBabysitter().view());
    }

    return views;
  }
 @Transactional
 public void addBabysitterAdvice(
     String countyGuid, ServiceOrder order, Map<String, Date> expectedDate) {
   // 添加需要通知的月嫂
   // CountyLevel countyLevel = dao.getResultByGUID(CountyLevel.class,
   // countyLevelGuid);
   String hql =
       "from Babysitter b where b.county.guid=? and b.level.level.money>=? and b.state = 1 ";
   List<Babysitter> babysitters =
       dao.getListResultByHQL(Babysitter.class, hql, countyGuid, order.getOrderPrice());
   // 添加可以抢单月嫂策略,SQL已经判断了所属城市、级别、审核状态三个条件
   // 1.排除最低薪水不符合条件的
   List<Babysitter> removeBabysitters = new ArrayList<Babysitter>();
   if (babysitters.size() == 0) return;
   BigDecimal salary = new BigDecimal(order.getOrderPrice());
   salary = salary.add(new BigDecimal(-1000));
   double rate = 1;
   if (order.getRate() != 0) rate = order.getRate();
   salary = salary.multiply(new BigDecimal(rate));
   long salaryLong = salary.longValue();
   for (Babysitter babysitter : babysitters) {
     if (babysitter.getLowerSalary() > salaryLong) removeBabysitters.add(babysitter);
   }
   babysitters.removeAll(removeBabysitters);
   // 2.排除档期不符合条件
   if (babysitters.size() == 0) return;
   if (removeBabysitters.size() != 0) removeBabysitters.clear();
   for (Babysitter babysitter : babysitters) {
     if (!ExpectedDateCreate.checkBabysitterOrder(babysitter, expectedDate)) {
       removeBabysitters.add(babysitter);
     }
   }
   babysitters.removeAll(removeBabysitters);
   // 添加月嫂通知
   if (babysitters.size() == 0) return;
   for (Babysitter babysitter : babysitters) {
     PanicBuyingBabysitterAdvice advice = PanicBuyingBabysitterAdvice.getInstance();
     advice.setBabysitter(babysitter);
     advice.setServiceOrder(order);
     advice.setIsAdvice(false);
     advice.setIsOver(false);
     dao.add(advice);
   }
 }
 @Transactional
 public void addServiceOrderAdvice(String id) {
   long idl = Long.valueOf(id);
   ServiceOrder order = dao.getResultById(ServiceOrder.class, idl);
   // 更新所有通知为已通知
   String hql = "from PanicBuyingBabysitterAdvice t where t.ovld = true and t.serviceOrder.id = ?";
   List<PanicBuyingBabysitterAdvice> advices =
       dao.getListResultByHQL(PanicBuyingBabysitterAdvice.class, hql, order.getId());
   for (PanicBuyingBabysitterAdvice advice : advices) {
     advice.setIsAdvice(true);
     dao.update(advice);
   }
   Map<String, Date> dateMap = new HashMap<String, Date>();
   dateMap.put(ExpectedDateCreate.BEGIN_DATE, order.getServiceBeginDate());
   dateMap.put(ExpectedDateCreate.END_DATE, order.getServiceEndDate());
   // 重新加入月嫂通知
   addBabysitterAdvice(order.getCounty().getGuid(), order, dateMap);
   // 更新雇主订单没有完成抢单
   order.setOver(true);
   dao.update(order);
 }
  private BabysitterOrder updateBabysitterOrder(
      String orderGuid, Babysitter babysitter, ServiceOrder serviceOrder) {
    // 添加月嫂订单
    BabysitterOrder babysitterOrder = BabysitterOrder.getInstance();
    babysitterOrder.setBabysitter(babysitter);
    babysitterOrder.setEmployer(serviceOrder.getEmployer());
    babysitterOrder.setEmployerAddress(serviceOrder.getAddress());
    babysitterOrder.setEmployerName(serviceOrder.getEmployerName());
    babysitterOrder.setEmployerTelephone(serviceOrder.getMobilePhone());
    babysitterOrder.setOrderId(recordService.createOrderId());
    babysitterOrder.setOrderPrice(serviceOrder.getOrderPrice());
    long frontPrice = getFrontPrice(serviceOrder.getOrderPrice());
    babysitterOrder.setOrderFrontPrice(frontPrice);
    babysitterOrder.setServiceBeginDate(serviceOrder.getServiceBeginDate());
    babysitterOrder.setServiceEndDate(serviceOrder.getServiceEndDate());
    babysitterOrder.setState(Constants.NEW_ORDER);
    dao.add(babysitterOrder);
    // 添加月嫂订单变更信息
    BabysitterOrderRecordInfo recordInfo = BabysitterOrderRecordInfo.getInstance();
    recordInfo.setBabysitterOrder(babysitterOrder);
    recordInfo.setState(babysitterOrder.getState());
    dao.add(recordInfo);

    // 更新雇主订单
    serviceOrder.setOrderGuid(babysitterOrder.getGuid());
    dao.update(serviceOrder);

    // 更新月嫂抢单通知表中该订单的所有记录为不可用即订单已经被抢
    String hql =
        "from PanicBuyingBabysitterAdvice t where t.ovld = true and t.serviceOrder.guid = ?";
    List<PanicBuyingBabysitterAdvice> list =
        dao.getListResultByHQL(PanicBuyingBabysitterAdvice.class, hql, orderGuid);
    for (PanicBuyingBabysitterAdvice advice : list) {
      advice.setIsOver(true);
      dao.update(advice);
    }
    return babysitterOrder;
  }
예제 #6
0
 public List<Role> roleList() {
   String hql = "from Role r ";
   List<Role> list = dao.getListResultByHQL(Role.class, hql);
   return list;
 }