@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 void updateRole(Role role) {
   Role editRole = dao.getResultById(Role.class, role.getId());
   editRole.setName(role.getName());
   editRole.setUpdateDate(new Date());
   dao.update(editRole);
 }
 @Transactional
 public void deleteOrder(String ids) {
   String idArr[] = ids.split(",");
   for (String id : idArr) {
     long idl = Long.valueOf(id);
     ServiceOrder order = dao.getResultById(ServiceOrder.class, idl);
     order.setOvld(false);
     dao.update(order);
   }
 }
 @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);
 }
  @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;
  }
  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;
  }
 @Transactional
 public void grant(long id, long[] resourceTreeIds) {
   Role role = dao.getResultById(Role.class, id);
   Set<Long> menuIds = new HashSet<Long>();
   for (Long menuId : resourceTreeIds) {
     menuIds.add(menuId);
   }
   // List<Menu> menus = role.getMenus();
   // for (Menu menu : menus) {
   // menuIds.add(menu.getId());
   // }
   List<Menu> roleMenus = new ArrayList<Menu>();
   for (Iterator<Long> mid = menuIds.iterator(); mid.hasNext(); ) {
     Menu m = new Menu();
     m.setId(mid.next());
     roleMenus.add(m);
   }
   role.setMenus(roleMenus);
   dao.update(role);
 }