/**
  * 添加线路模板
  *
  * @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 = "/shop_cart.htm")
  public ModelAndView shop_cart(ModelAndView mav, Long id) {
    TravelGiftDO giftDO = integralService.getTravelGiftById(id.intValue());
    mav.addObject("gift", giftDO);
    TravelIntegralQuery integralQuery = new TravelIntegralQuery();
    integralQuery.setcId(WebUserTools.getCid());
    integralQuery.setmId(WebUserTools.getMid());

    TravelIntegralDO integralDO = integralService.queryBala(integralQuery);
    mav.addObject("integralDO", integralDO);

    List<TravelGiftClassDO> classDOs = integralService.list(new TravelGiftClassQuery());
    mav.addObject("gClassList", classDOs);
    mav.setViewName("cms/1409/shop_cart");
    return mav;
  }
 /**
  * 添加交通模板页面
  *
  * @param traffic
  * @return
  */
 @AuthorityPolicy(authorityTypes = {Right.CREATE_TRAFFIC_TEMPLATE})
 @RequestMapping(value = "/addtraffic.htm", method = RequestMethod.POST)
 @ResponseBody
 public JsonResult addTraffic(TravelTrafficDO traffic) {
   traffic.setcId(WebUserTools.getCid());
   int i = lineService.insertTravelTraffic(traffic);
   return JsonResultUtils.success(null, i != 0 ? "添加成功!" : "添加失败!");
 }
 /**
  * * 交通列表
  *
  * @param mav
  * @param query
  * @param page
  * @param pagesize
  * @return
  */
 @RequestMapping(value = "/trafficpage.htm")
 public ModelAndView traffic(
     ModelAndView mav, TravelTrafficQuery query, Integer page, Integer pagesize) {
   query.setcId(WebUserTools.getCid());
   query.setPageSize(Argument.isNotPositive(pagesize) ? 15 : pagesize);
   query.setNowPageIndex(Argument.isNotPositive(page) ? 0 : page - 1);
   // 分页查询
   PaginationList<TravelTrafficDO> trafficlist =
       lineService.listPagination(query, new DefaultIpageUrl());
   // 转成VOList
   List<TravelTrafficVO> trafficlistvo = BeanUtils.convert(TravelTrafficVO.class, trafficlist);
   mav.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false");
   mav.addObject("traffic", trafficlistvo);
   mav.addObject("pagination", trafficlist.getQuery());
   mav.setViewName("account/line/trafficpage");
   return mav;
 }
 /**
  * 模板显示list
  *
  * @param mv
  * @param query
  * @param page
  * @param pagesize
  * @return
  */
 @RequestMapping(value = "/templatepage.htm")
 public ModelAndView template(
     ModelAndView mv, TravelLineQuery query, Integer page, Integer pagesize) {
   if (query.getzId() != null) {
     query.setzIds(query.getzId());
   }
   query.setlTemplateState(1);
   query.setcId(WebUserTools.getCid());
   query.setPageSize(Argument.isNotPositive(pagesize) ? 15 : pagesize);
   query.setNowPageIndex(Argument.isNotPositive(page) ? 0 : page - 1);
   // 查询线路模板
   PaginationList<TravelLineDO> list = lineService.listPagination(query, new DefaultIpageUrl());
   List<TravelLineVO> lists = BeanUtils.convert(TravelLineVO.class, list);
   mv.addObject("pagination", list.getQuery());
   mv.addObject("template", lists);
   mv.setViewName("account/line/templatepage");
   return mv;
 }
 /**
  * 修改线路模板
  *
  * @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("修改失败!");
 }
  @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, "下单成功!");
    }
  }