@Transactional
 public PageResult markBabysitter(String babysitterGuid, String orderGuid, PageResult result) {
   Babysitter babysitter = dao.getResultByGUID(Babysitter.class, babysitterGuid);
   ServiceOrder serviceOrder = dao.getResultByGUID(ServiceOrder.class, orderGuid);
   BabysitterOrder order = updateBabysitterOrder(orderGuid, babysitter, serviceOrder);
   result.setResult(ResultInfo.SUCCESS);
   result.put("result", order.view());
   return result;
 }
 public PageResult getBabysitterOrderInfo(String serviceOrderGuid, PageResult result) {
   ServiceOrder serviceOrder = dao.getResultByGUID(ServiceOrder.class, serviceOrderGuid);
   if (serviceOrder == null) {
     result.setResult(ResultInfo.SERVICE_ORDER_NULL);
     return result;
   }
   if (StringUtils.isEmpty(serviceOrder.getOrderGuid())) {
     result.setResult(ResultInfo.NO_BABYSITTER_SERVICE_ORDER);
     return result;
   }
   String orderGuid = serviceOrder.getOrderGuid();
   BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid);
   result.setResult(ResultInfo.SUCCESS);
   result.put("result", order.view());
   return result;
 }
 @Transactional
 public PageResult addMakeBabysitterOrder(
     String date,
     String address,
     String name,
     String mobile,
     String checkCode,
     String openid,
     String countyGuid,
     String babysitterGuid,
     PageResult result) {
   Babysitter babysitter = dao.getResultByGUID(Babysitter.class, babysitterGuid);
   if (babysitter == null) {
     result.setResult(ResultInfo.BABYSITTER_NULL);
     return result;
   }
   ServiceOrder order =
       addEmployerServiceOrder(
           date,
           babysitter.getLevel().getGuid(),
           countyGuid,
           address,
           name,
           mobile,
           checkCode,
           openid);
   if (order == null) {
     result.setResult(ResultInfo.COUNTY_LEVEL_NULL);
     return result;
   }
   result = markBabysitter(babysitterGuid, order.getGuid(), result);
   return result;
 }
 @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;
   }
 }
 public PageResult orderHistoryRecord(String orderGuid, PageResult result) {
   BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid);
   if (order == null) {
     result.setResult(ResultInfo.BABYSITTER_ORDER_NULL);
     return result;
   }
   result.setResult(ResultInfo.SUCCESS);
   result.put("result", order.getInfos());
   return result;
 }
  @Transactional
  public ResultInfo addBabysitterOrderEvaluate(String orderGuid, String msg, String score) {
    BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid);
    if (order == null) return ResultInfo.BABYSITTER_ORDER_NULL;
    Babysitter babysitter = dao.getResultByGUID(Babysitter.class, order.getBabysitter().getGuid());
    if (babysitter == null) return ResultInfo.BABYSITTER_NULL;
    order.setScore(Integer.valueOf(score));
    order.setEvaluation(msg);
    order.setState(Constants.ORDER_OVER);
    dao.update(order);
    BabysitterOrderRecordInfo info = BabysitterOrderRecordInfo.getInstance();
    info.setBabysitterOrder(order);
    info.setState(order.getState());
    dao.add(info);

    // BabysitterEvaluate evaluate = BabysitterEvaluate.getInstance();
    // evaluate.setBabysitter(babysitter);
    // evaluate.setEmployer(employer);
    // evaluate.setOrder(order);
    // evaluate.setMsg(msg);
    // evaluate.setScore(Integer.valueOf(score));
    // dao.add(evaluate);
    int sumSocre = 0;
    int count = 0;
    List<BabysitterOrder> orders = babysitter.getOrders();

    for (BabysitterOrder o : orders) {
      if (o.getState() == Constants.ORDER_OVER) {
        sumSocre += o.getScore();
        count += 1;
      }
    }
    int avg = 0;
    if (count != 0) {
      avg = sumSocre / count;
    }
    babysitter.setScore(avg);
    dao.update(babysitter);
    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;
 }
 @Transactional
 public PageResult serviceEnd(String orderGuid, PageResult result) {
   BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid);
   if (order == null) {
     result.setResult(ResultInfo.BABYSITTER_ORDER_NULL);
     return result;
   }
   order.setState(Constants.OUT_ORDER);
   // 设置订单日志
   BabysitterOrderRecordInfo info = BabysitterOrderRecordInfo.getInstance();
   info.setBabysitterOrder(order);
   info.setState(order.getState());
   dao.add(info);
   result.setResult(ResultInfo.SUCCESS);
   return result;
 }