@Transactional
 public ResultInfo manageEditOrder(
     String id, String employerAddress, String price, String beginDate, String endDate) {
   try {
     long idl = Long.valueOf(id);
     ServiceOrder order = dao.getResultById(ServiceOrder.class, idl);
     if (order == null) return ResultInfo.SERVICE_ORDER_NULL;
     // String hql =
     // "from Employer e where e.ovld = true and e.mobilePhone = ?";
     // Employer employer = dao.getSingleResultByHQL(Employer.class, hql,
     // employerTelephone);
     // if (employer == null)
     // return ResultInfo.EMPLOYER_NULL;
     // if (!StringUtils.isEmpty(employerName))
     // employer.setUsername(employerName);
     // if (!StringUtils.isEmpty(employerTelephone))
     // employer.setMobilePhone(employerTelephone);
     if (!StringUtils.isEmpty(employerAddress)) order.setAddress(employerAddress);
     if (!StringUtils.isEmpty(price)) order.setOrderPrice(Long.parseLong(price));
     if (!StringUtils.isEmpty(beginDate))
       order.setServiceBeginDate(ExpectedDateCreate.parseDate(beginDate));
     if (!StringUtils.isEmpty(endDate))
       order.setServiceEndDate(ExpectedDateCreate.parseDate(endDate));
     // order.setEmployer(employer);
     order.setUpdateDate(new Date());
     dao.update(order);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return ResultInfo.SUCCESS;
 }
 @Transactional
 public ResultInfo manageAddOrder(
     String guid,
     String beginDate,
     String endDate,
     String price,
     String address,
     String employerName,
     String telephone,
     String rate,
     String countyGuid) {
   try {
     String hql = "from Employer e where e.ovld = true and e.guid = ?";
     Employer employer = dao.getSingleResultByHQL(Employer.class, hql, guid);
     County county = dao.getResultByGUID(County.class, countyGuid);
     ServiceOrder order = ServiceOrder.getInstance();
     order.setAddress(address);
     order.setEmployer(employer);
     order.setMobilePhone(telephone);
     order.setOrderPrice(Long.valueOf(price));
     order.setRate(Double.valueOf(rate));
     order.setCounty(county);
     order.setServiceBeginDate(ExpectedDateCreate.parseDate(beginDate));
     order.setServiceEndDate(
         ExpectedDateCreate.addDays(
             ExpectedDateCreate.parseDate(beginDate), Integer.valueOf(endDate)));
     dao.add(order);
     return ResultInfo.SUCCESS;
   } catch (Exception e) {
     e.printStackTrace();
     return ResultInfo.BAD_REQUEST;
   }
 }
  /** 雇主添加订单,需要根据订单的开始结束时间、订单所属地区查找符合要求的月嫂添加到需要通知的月嫂的数据表中 */
  @Transactional
  public PageResult wechatAddServiceOrder(
      String date,
      String countyLevelGuid,
      String countyGuid,
      String address,
      String name,
      String mobile,
      String checkCode,
      String openid,
      PageResult result,
      String isNotAdvice) {
    try {
      // boolean flag = codeService.updateCheckCode(mobile, checkCode,
      // CheckCodeService.PUBLISH_ORDER);
      // if (!flag) {
      // throw new CheckErrorException();
      // }

      // 添加雇主订单
      ServiceOrder order =
          addEmployerServiceOrder(
              date, countyLevelGuid, countyGuid, address, name, mobile, checkCode, openid);
      if (order == null) {
        result.setResult(ResultInfo.COUNTY_LEVEL_NULL);
        return result;
      }
      Map<String, Date> expectedDate = ExpectedDateCreate.getExpectedDate(date);
      if (StringUtils.isEmpty(isNotAdvice)) {
        addBabysitterAdvice(countyGuid, order, expectedDate);
      }
      result.setResult(ResultInfo.SUCCESS);
      result.put("result", order.view());
      // 短信通知客户经理
      String telephone = Constants.MSG_TEMPLATE_ADVICE_PHONE;
      String telephones[] = telephone.split(",");
      for (String phone : telephones) {
        CheckCodeUtil.sendMessage(
            phone,
            Constants.MSG_TEMPLATE_ADVICE,
            ExpectedDateCreate.formatDateTime(new Date()),
            String.valueOf(order.getId()));
      }
      return result;
    } catch (CheckErrorException e) {
      result.setResult(ResultInfo.CHECK_CODE_ERROR);
      return result;
    } catch (Exception e) {
      e.printStackTrace();
    }
    result.setResult(ResultInfo.BAD_REQUEST);
    return result;
  }
 @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 ResultInfo addServiceOrder(
     String date,
     String price,
     String countyGuid,
     String address,
     String name,
     String mobile,
     String checkCode) {
   try {
     // boolean flag = codeService.updateCheckCode(mobile, checkCode,
     // CheckCodeService.PUBLISH_ORDER);
     // if (!flag) {
     // throw new CheckErrorException();
     // }
     Employer employer = employerService.getEmployerByMobile(mobile);
     // County county = dao.getResultByGUID(County.class, countyGuid);
     if (employer == null) {
       employer = Employer.getInstance();
       employer.setMobilePhone(mobile.replace(" ", ""));
       // employer.setCounty(county);
       employer.setAddress(address);
       employer.setUsername(name);
       employerService.addEmployer(employer);
     }
     // 月嫂提交私单不需要向月嫂抢单表中添加数据正常添加私单。
     ServiceOrder order = ServiceOrder.getInstance();
     order.setEmployer(employer);
     order.setOrderPrice(Long.valueOf(price));
     order.setAddress(address);
     // order.setCounty(county);
     order.setMobilePhone(mobile.replace(" ", ""));
     Map<String, Date> expectedDate = ExpectedDateCreate.getExpectedDate(date);
     order.setServiceBeginDate(expectedDate.get(ExpectedDateCreate.BEGIN_DATE));
     order.setServiceEndDate(expectedDate.get(ExpectedDateCreate.END_DATE));
     dao.add(order);
   } catch (CheckErrorException e) {
     return ResultInfo.CHECK_CODE_ERROR;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return ResultInfo.SUCCESS;
 }
 @Transactional
 public ServiceOrder addEmployerServiceOrder(
     String date,
     String countyLevelGuid,
     String countyGuid,
     String address,
     String name,
     String mobile,
     String checkCode,
     String openid) {
   Employer employer = employerService.getEmployerByMobile(mobile);
   County county = dao.getResultByGUID(County.class, countyGuid);
   CountyLevel countyLevel = dao.getResultByGUID(CountyLevel.class, countyLevelGuid);
   if (countyLevel == null) return null;
   if (employer == null) {
     employer = Employer.getInstance();
     employer.setMobilePhone(mobile.replace(" ", ""));
     // employer.setCounty(county);
     employer.setAddress(address);
     employer.setUsername(name);
     employer.setOpenid(openid);
     employerService.addEmployer(employer);
   }
   // 添加雇主订单
   ServiceOrder order = ServiceOrder.getInstance();
   order.setEmployer(employer);
   order.setCounty(county);
   order.setOrderPrice(Long.valueOf(countyLevel.getMoney()));
   order.setRate(countyLevel.getRate());
   order.setAddress(address);
   order.setMobilePhone(mobile);
   order.setEmployerName(name);
   order.setMobilePhone(mobile);
   Map<String, Date> expectedDate = ExpectedDateCreate.getExpectedDate(date);
   order.setServiceBeginDate(expectedDate.get(ExpectedDateCreate.BEGIN_DATE));
   order.setServiceEndDate(expectedDate.get(ExpectedDateCreate.END_DATE));
   dao.add(order);
   return order;
 }