/**
  * 添加线路模板
  *
  * @param travelLineDO
  * @param mv
  * @param result
  * @return
  */
 @AuthorityPolicy(authorityTypes = {Right.CREATE_LINE_TEMPLATE})
 @RequestMapping(value = "/addtemplate.htm")
 @ResponseBody
 public JsonResult addtemplat(TravelLineVO travelLineVO, BindingResult result) {
   Result rs = showErrors(result);
   if (rs.isFailed()) {
     return JsonResultUtils.error(rs.getMessage());
   }
   // 添加线路模板
   travelLineVO.setlTemplateState(LineTemplateEnum.Template.getValue());
   TravelLineDO travelLineDO = new TravelLineDO();
   BeanUtils.copyProperties(travelLineDO, travelLineVO);
   // 设置添加线路的用户id
   travelLineDO.setmId(WebUserTools.getMid());
   travelLineDO.setcId(WebUserTools.getCid());
   int linebo = lineService.addTravelLine(travelLineDO);
   int routebo = 0;
   // 添加行程
   if (travelLineVO.getRoutelist() != null || travelLineVO.getRoutelist().size() != 0) {
     for (TravelRouteDO route : travelLineVO.getRoutelist()) {
       route.setlId(travelLineDO.getlId());
       routebo = lineService.addTravelRoute(route);
     }
   }
   boolean bool = linebo != 0 && routebo != 0;
   return bool ? JsonResultUtils.success("添加成功!") : JsonResultUtils.error(null, "添加失败!");
 }
  @RequestMapping(
      value = "/addGiftOrder.htm",
      produces = "application/json",
      method = RequestMethod.POST)
  @ResponseBody
  public JsonResult addGiftOrder(ModelAndView mav, final TravelGiftOrderDO giftOrderDO) {
    TravelIntegralQuery integralQuery = new TravelIntegralQuery();
    integralQuery.setcId(WebUserTools.getCid());
    integralQuery.setmId(WebUserTools.getMid());
    TravelIntegralDO integralDO = integralService.queryBala(integralQuery);
    if (integralDO == null) {
      return JsonResultUtils.error(giftOrderDO, "你暂时还没有积分,赶快去消费吧!");
    }
    mav.addObject("integralDO", integralDO);
    if (giftOrderDO.getGoIntegralCount() > integralDO.getiBalance())
      return JsonResultUtils.error(giftOrderDO, "积分不够,请改变兑换数量!");

    giftOrderDO.setcId(WebUserTools.getCid());
    giftOrderDO.setmId(WebUserTools.getMid());
    giftOrderDO.setGoState(0);
    Integer i = integralService.addTravelGiftOrder(giftOrderDO);
    if (i == 0) {
      return JsonResultUtils.error(giftOrderDO, "下单失败!");
    } else {
      TravelIntegralDO newACC = new TravelIntegralDO();
      newACC.setcId(WebUserTools.getCid());
      newACC.setmId(WebUserTools.getMid());
      newACC.setiSource(IntegralSourceEnum.consumer.value);
      newACC.setiAddintegral(0 - giftOrderDO.getGoIntegralCount());
      newACC.setiBalance(integralDO.getiBalance() + newACC.getiAddintegral());
      newACC.setiFrozen(integralDO.getiFrozen());
      newACC.setiAltogether(newACC.getiBalance() + newACC.getiFrozen());
      newACC.setiRemark("兑换积分产品");
      integralService.addTravelIntegral(newACC);
      return JsonResultUtils.success(giftOrderDO, "下单成功!");
    }
  }
 /**
  * 修改线路模板
  *
  * @param trDo
  * @return
  */
 @AuthorityPolicy(authorityTypes = {Right.MODIFY_LINE_TEMPLATE})
 @RequestMapping(value = "/updatetemplate.htm")
 @ResponseBody
 public JsonResult updateTemplate(TravelLineVO trDo) {
   // 设置最后修改人ID
   trDo.setlEditUserId(WebUserTools.getMid().intValue());
   boolean bool = lineService.updateTravelLine(trDo);
   // 删除行程
   lineService.deleteTravelRouteByLineid(trDo.getlId());
   // 添加行程
   boolean boo = true;
   if (trDo.getRoutelist() != null || trDo.getRoutelist().size() != 0) {
     for (TravelRouteDO route : trDo.getRoutelist()) {
       route.setlId(trDo.getlId());
       int roid = lineService.addTravelRoute(route);
       if (roid == 0) {
         boo = false;
       }
     }
   }
   return bool && boo ? JsonResultUtils.success(null, "修改成功!") : JsonResultUtils.error("修改失败!");
 }