/**
  * GoodsFloor列表页
  *
  * @param currentPage
  * @param orderBy
  * @param orderType
  * @param request
  * @return
  */
 @SecurityMapping(
     title = "楼层分类列表",
     value = "/admin/goods_floor_list.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_list.htm")
 public ModelAndView goods_floor_list(
     HttpServletRequest request,
     HttpServletResponse response,
     String currentPage,
     String orderBy,
     String orderType) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_list.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   String url = this.configService.getSysConfig().getAddress();
   if (url == null || url.equals("")) {
     url = CommUtil.getURL(request);
   }
   String params = "";
   GoodsFloorQueryObject qo = new GoodsFloorQueryObject(currentPage, mv, "gf_sequence", "asc");
   qo.addQuery("obj.gf_level", new SysMap("gf_level", 0), "=");
   IPageList pList = this.goodsfloorService.list(qo);
   CommUtil.saveIPageList2ModelAndView(url + "/admin/goods_floor_list.htm", "", params, pList, mv);
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板品牌加载",
     value = "/admin/goods_floor_brand_load.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_brand_load.htm")
 public ModelAndView goods_floor_brand_load(
     HttpServletRequest request, HttpServletResponse response, String currentPage, String name) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_brand_load.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsBrandQueryObject qo = new GoodsBrandQueryObject(currentPage, mv, "sequence", "asc");
   qo.addQuery("obj.audit", new SysMap("audit", 1), "=");
   if (!CommUtil.null2String(name).equals("")) {
     qo.addQuery("obj.name", new SysMap("name", "%" + name.trim() + "%"), "like");
   }
   IPageList pList = this.goodsBrandService.list(qo);
   CommUtil.saveIPageList2ModelAndView(
       CommUtil.getURL(request) + "/admin/goods_floor_brand_load.htm",
       "",
       "&name=" + CommUtil.null2String(name),
       pList,
       mv);
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板右下方广告编辑",
     value = "/admin/goods_floor_right_adv.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_right_adv.htm")
 public ModelAndView goods_floor_right_adv(
     HttpServletRequest request, HttpServletResponse response, String id) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_right_adv.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsFloor obj = this.goodsfloorService.getObjById(CommUtil.null2Long(id));
   Map params = new HashMap();
   params.put("ap_status", 1);
   params.put("ap_width", 205);
   params.put("ap_type", "img");
   List<AdvertPosition> aps =
       this.advertPositionService.query(
           "select obj from AdvertPosition obj where obj.ap_status=:ap_status and obj.ap_width=:ap_width and obj.ap_type=:ap_type order by obj.addTime desc",
           params,
           -1,
           -1);
   mv.addObject("aps", aps);
   mv.addObject("obj", obj);
   mv.addObject("gf_tools", this.gf_tools);
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板品牌编辑",
     value = "/admin/goods_floor_brand.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_brand.htm")
 public ModelAndView goods_floor_brand(
     HttpServletRequest request, HttpServletResponse response, String id) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_brand.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsFloor obj = this.goodsfloorService.getObjById(CommUtil.null2Long(id));
   GoodsBrandQueryObject qo = new GoodsBrandQueryObject("1", mv, "sequence", "asc");
   qo.addQuery("obj.audit", new SysMap("audit", 1), "=");
   IPageList pList = this.goodsBrandService.list(qo);
   CommUtil.saveIPageList2ModelAndView(
       CommUtil.getURL(request) + "/admin/goods_floor_brand_load.htm", "", "", pList, mv);
   mv.addObject("obj", obj);
   mv.addObject("gf_tools", this.gf_tools);
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板编辑",
     value = "/admin/goods_floor_template.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_template.htm")
 public ModelAndView goods_floor_template(
     HttpServletRequest request,
     HttpServletResponse response,
     String currentPage,
     String id,
     String tab) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_template.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsFloor obj = this.goodsfloorService.getObjById(CommUtil.null2Long(id));
   mv.addObject("obj", obj);
   mv.addObject("gf_tools", this.gf_tools);
   mv.addObject("currentPage", currentPage);
   mv.addObject("tab", tab);
   mv.addObject("url", CommUtil.getURL(request));
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板右侧商品列表编辑",
     value = "/admin/goods_floor_list_goods.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_list_goods.htm")
 public ModelAndView goods_floor_list_goods(
     HttpServletRequest request, HttpServletResponse response, String currentPage, String id) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_list_goods.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsFloor obj = this.goodsfloorService.getObjById(CommUtil.null2Long(id));
   List<GoodsClass> gcs =
       this.goodsClassService.query(
           "select obj from GoodsClass obj where obj.parent.id is null order by obj.sequence asc",
           null,
           -1,
           -1);
   mv.addObject("gcs", gcs);
   mv.addObject("obj", obj);
   mv.addObject("gf_tools", this.gf_tools);
   mv.addObject("currentPage", currentPage);
   return mv;
 }
 @SecurityMapping(
     title = "楼层分类下级加载",
     value = "/admin/goods_floor_data.htm*",
     rtype = "admin",
     rname = "分类管理",
     rcode = "goods_class",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_data.htm")
 public ModelAndView goods_floor_data(
     HttpServletRequest request, HttpServletResponse response, String pid, String currentPage) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_data.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   Map map = new HashMap();
   map.put("pid", Long.parseLong(pid));
   List<GoodsFloor> gfs =
       this.goodsfloorService.query(
           "select obj from GoodsFloor obj where obj.parent.id =:pid", map, -1, -1);
   mv.addObject("gfs", gfs);
   mv.addObject("currentPage", currentPage);
   return mv;
 }
 /**
  * goodsfloor编辑管理
  *
  * @param id
  * @param request
  * @return
  * @throws ParseException
  */
 @SecurityMapping(
     title = "楼层分类编辑",
     value = "/admin/goods_floor_edit.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_edit.htm")
 public ModelAndView goods_floor_edit(
     HttpServletRequest request, HttpServletResponse response, String id, String currentPage) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_add.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   if (id != null && !id.equals("")) {
     GoodsFloor goodsfloor = this.goodsfloorService.getObjById(Long.parseLong(id));
     Map params = new HashMap();
     params.put("gf_level", 0);
     List<GoodsFloor> gfs =
         this.goodsfloorService.query(
             "select obj from GoodsFloor obj where obj.gf_level=:gf_level", params, -1, -1);
     mv.addObject("gfs", gfs);
     mv.addObject("obj", goodsfloor);
     mv.addObject("currentPage", currentPage);
     mv.addObject("edit", true);
   }
   return mv;
 }
 /**
  * goodsfloor添加管理
  *
  * @param request
  * @return
  * @throws ParseException
  */
 @SecurityMapping(
     title = "楼层分类添加",
     value = "/admin/goods_floor_add.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_add.htm")
 public ModelAndView goods_floor_add(
     HttpServletRequest request, HttpServletResponse response, String currentPage, String pid) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_add.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   mv.addObject("currentPage", currentPage);
   Map params = new HashMap();
   params.put("gf_level", 0);
   List<GoodsFloor> gfs =
       this.goodsfloorService.query(
           "select obj from GoodsFloor obj where obj.gf_level=:gf_level", params, -1, -1);
   mv.addObject("gfs", gfs);
   GoodsFloor obj = new GoodsFloor();
   GoodsFloor parent = this.goodsfloorService.getObjById(CommUtil.null2Long(pid));
   obj.setParent(parent);
   if (parent != null) obj.setGf_level(parent.getGf_level() + 1);
   obj.setGf_display(true);
   mv.addObject("obj", obj);
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板分类商品编辑",
     value = "/admin/goods_floor_list_goods_load.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_list_goods_load.htm")
 public ModelAndView goods_floor_list_goods_load(
     HttpServletRequest request,
     HttpServletResponse response,
     String currentPage,
     String gc_id,
     String goods_name) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_list_goods_load.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsQueryObject qo = new GoodsQueryObject(currentPage, mv, "addTime", "desc");
   if (!CommUtil.null2String(gc_id).equals("")) {
     Set<Long> ids = this.genericIds(this.goodsClassService.getObjById(CommUtil.null2Long(gc_id)));
     Map paras = new HashMap();
     paras.put("ids", ids);
     qo.addQuery("obj.gc.id in (:ids)", paras);
   }
   if (!CommUtil.null2String(goods_name).equals("")) {
     qo.addQuery("obj.goods_name", new SysMap("goods_name", "%" + goods_name + "%"), "like");
   }
   qo.addQuery("obj.goods_status", new SysMap("goods_status", 0), "=");
   IPageList pList = this.goodsService.list(qo);
   CommUtil.saveIPageList2ModelAndView(
       CommUtil.getURL(request) + "/admin/goods_floor_list_goods_load.htm",
       "",
       "&gc_id=" + gc_id + "&goods_name=" + goods_name,
       pList,
       mv);
   return mv;
 }
 @SecurityMapping(
     title = "楼层模板商品分类加载",
     value = "/admin/goods_floor_class_load.htm*",
     rtype = "admin",
     rname = "首页楼层",
     rcode = "goods_floor",
     rgroup = "商品")
 @RequestMapping("/admin/goods_floor_class_load.htm")
 public ModelAndView goods_floor_class_load(
     HttpServletRequest request, HttpServletResponse response, String currentPage, String gc_id) {
   ModelAndView mv =
       new JModelAndView(
           "admin/blue/goods_floor_class_load.html",
           configService.getSysConfig(),
           this.userConfigService.getUserConfig(),
           0,
           request,
           response);
   GoodsClass gc = this.goodsClassService.getObjById(CommUtil.null2Long(gc_id));
   mv.addObject("gc", gc);
   return mv;
 }
  /**
   * goodsfloor保存管理
   *
   * @param id
   * @return
   */
  @SecurityMapping(
      title = "楼层分类保存",
      value = "/admin/goods_floor_save.htm*",
      rtype = "admin",
      rname = "首页楼层",
      rcode = "goods_floor",
      rgroup = "商品")
  @RequestMapping("/admin/goods_floor_save.htm")
  public ModelAndView goods_floor_save(
      HttpServletRequest request,
      HttpServletResponse response,
      String id,
      String currentPage,
      String pid,
      String list_url,
      String add_url) {
    WebForm wf = new WebForm();
    GoodsFloor goodsfloor = null;
    if (id.equals("")) {
      goodsfloor = wf.toPo(request, GoodsFloor.class);
      goodsfloor.setAddTime(new Date());
    } else {
      GoodsFloor obj = this.goodsfloorService.getObjById(Long.parseLong(id));
      goodsfloor = (GoodsFloor) wf.toPo(request, obj);
    }
    GoodsFloor parent = this.goodsfloorService.getObjById(CommUtil.null2Long(pid));
    if (parent != null) {
      goodsfloor.setParent(parent);
      goodsfloor.setGf_level(parent.getGf_level() + 1);
    }

    String uploadFilePath = ConfigContants.UPLOAD_IMAGE_MIDDLE_NAME;
    String saveFilePathName =
        TytsmsStringUtils.generatorImagesFolderServerPath(request)
            + uploadFilePath
            + File.separator
            + "floor";
    Map map = new HashMap();
    try {
      String fileName = goodsfloor.getIcon() == null ? "" : goodsfloor.getIcon().getName();
      map =
          CommUtil.saveFileToServer(
              configService, request, "icon_logo", saveFilePathName, fileName, null);
      if (fileName.equals("")) {
        if (map.get("fileName") != "" && map.get("fileName") != null) {
          Accessory icon = new Accessory();
          icon.setName(CommUtil.null2String(map.get("fileName")));
          icon.setExt((String) map.get("mime"));
          icon.setSize(BigDecimal.valueOf((CommUtil.null2Double(map.get("fileSize")))));
          icon.setPath(uploadFilePath + "/floor");
          icon.setWidth((Integer) map.get("width"));
          icon.setHeight((Integer) map.get("height"));
          icon.setAddTime(new Date());
          this.accessoryService.save(icon);
          goodsfloor.setIcon(icon);
        }
      } else {
        if (map.get("fileName") != "" && map.get("fileName") != null) {
          Accessory icon = goodsfloor.getIcon();
          icon.setName(CommUtil.null2String(map.get("fileName")));
          icon.setExt(CommUtil.null2String(map.get("mime")));
          icon.setSize(BigDecimal.valueOf((CommUtil.null2Double(map.get("fileSize")))));
          icon.setPath(uploadFilePath + "/floor");
          icon.setWidth(CommUtil.null2Int(map.get("width")));
          icon.setHeight(CommUtil.null2Int(map.get("height")));
          this.accessoryService.update(icon);
        }
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (id.equals("")) {
      this.goodsfloorService.save(goodsfloor);
    } else this.goodsfloorService.update(goodsfloor);
    ModelAndView mv =
        new JModelAndView(
            "admin/blue/success.html",
            configService.getSysConfig(),
            this.userConfigService.getUserConfig(),
            0,
            request,
            response);
    mv.addObject("list_url", list_url);
    mv.addObject("op_title", "保存首页楼层成功");
    if (add_url != null) {
      mv.addObject("add_url", add_url + "?currentPage=" + currentPage);
    }
    return mv;
  }