| package com.matrix.system.hive.action; | 
|   | 
| import com.matrix.core.exception.GlobleException; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.system.common.bean.SysUsers; | 
| import com.matrix.system.hive.action.util.QueryUtil; | 
| import com.matrix.system.hive.bean.ShoppingGoodsCategory; | 
| import com.matrix.system.hive.bean.SysShopInfo; | 
| import com.matrix.system.hive.dao.SysShopInfoDao; | 
| import com.matrix.system.hive.service.ShoppingGoodsCategoryService; | 
| import org.apache.poi.ss.formula.functions.T; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Controller; | 
| import org.springframework.web.bind.annotation.RequestMapping; | 
| import org.springframework.web.bind.annotation.ResponseBody; | 
|   | 
| import javax.annotation.Resource; | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.util.Arrays; | 
| import java.util.List; | 
|   | 
|   | 
| /** | 
|  * @author jyy | 
|  * @description 商品目录管理 | 
|  * @email 820786562@qqcom | 
|  * @date 2016-08-21 | 
|  */ | 
| @Controller | 
| @RequestMapping(value = "/admin/shoppinggoodscategory") | 
| public class ShoppingGoodsCategoryController extends BaseController { | 
|   | 
|   | 
|     @Autowired | 
|     private ShoppingGoodsCategoryService goodsCategoryService; | 
|   | 
|     @Autowired | 
|     private SysShopInfoDao shopInfoDao; | 
|   | 
|   | 
|     /** | 
|      * 新增或修改页面 | 
|      */ | 
|     @RequestMapping(value = "/addOrModify") | 
|     public @ResponseBody | 
|     AjaxResult addOrModify(ShoppingGoodsCategory shoppingGoodsCategory) { | 
|         if (shoppingGoodsCategory.getId() != null) { | 
|   | 
|             // 自己不能是自己的父节点 | 
|             if (shoppingGoodsCategory.getParentId() != null && shoppingGoodsCategory.getParentId().equals(shoppingGoodsCategory.getId())) { | 
|                 throw new GlobleException("父级不能是自己"); | 
|             } | 
|   | 
|             return modify(goodsCategoryService, shoppingGoodsCategory, "商品类型"); | 
|         } else { | 
|             QueryUtil.setQueryLimit(shoppingGoodsCategory); | 
|             return add(goodsCategoryService, shoppingGoodsCategory, "商品类型"); | 
|         } | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/editForm") | 
|     public String editForm(Long id, HttpServletRequest request) { | 
|         ShoppingGoodsCategory shoppingGoodsCategory; | 
|         if (id != null) { | 
|             shoppingGoodsCategory = goodsCategoryService.findById(id); | 
|             request.setAttribute("obj", shoppingGoodsCategory); | 
|         } | 
|         return "admin/hive/shopping/goodsCategory-form"; | 
|     } | 
|   | 
|     @RequestMapping(value = "/editFormUderline") | 
|     public String editFormUderline(Long id, HttpServletRequest request) { | 
|   | 
|         ShoppingGoodsCategory shoppingGoodsCategory; | 
|         if (id != null) { | 
|             shoppingGoodsCategory = goodsCategoryService.findById(id); | 
|   | 
|   | 
|             request.setAttribute("obj", shoppingGoodsCategory); | 
|         } | 
|         return "admin/hive/products/goodsCategory-form"; | 
|     } | 
|   | 
|   | 
|     @RequestMapping(value = "/del") | 
|     public @ResponseBody | 
|     AjaxResult del(Long keys) { | 
|   | 
|         int i = goodsCategoryService.removeById(keys); | 
|         if (i > 0) { | 
|             return new AjaxResult(AjaxResult.STATUS_SUCCESS, "成功删除" + i + "条数据"); | 
|         } else { | 
|             return new AjaxResult(AjaxResult.STATUS_FAIL, "删除失败"); | 
|         } | 
|     } | 
|   | 
|     @RequestMapping(value = "/findById") | 
|     public @ResponseBody | 
|     AjaxResult findById(Long id) { | 
|   | 
|         ShoppingGoodsCategory shoppingGoodsCategory = super.findById(goodsCategoryService, id); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(shoppingGoodsCategory), 0); | 
|     } | 
|   | 
|     /** | 
|      * ======================================================= | 
|      * *******************公共的数据访问方法******************** | 
|      * ======================================================= | 
|      */ | 
|   | 
|     /** | 
|      * 如果客户端没有指定加载特定门店则当前登录用户所在门店 | 
|      * @param shoppingGoodsCategory | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/all") | 
|     public @ResponseBody | 
|     AjaxResult all(ShoppingGoodsCategory shoppingGoodsCategory) { | 
| //        SysUsers user = getMe(); | 
| //        if(shoppingGoodsCategory.getShopId()==null){ | 
| //            shoppingGoodsCategory.setShopId(user.getShopId()); | 
| //        } | 
| //        shoppingGoodsCategory.setCompanyId(user.getCompanyId()); | 
|         SysShopInfo zbShop = shopInfoDao.selectZbShop(getMe().getCompanyId()); | 
|         shoppingGoodsCategory.setShopId(zbShop.getId()); | 
|         QueryUtil.setQueryLimitCom(shoppingGoodsCategory); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, goodsCategoryService.findByModel(shoppingGoodsCategory), 0); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获取总部商品分类 | 
|      * | 
|      * @param shoppingGoodsCategory | 
|      * @return | 
|      */ | 
|     @RequestMapping(value = "/getZbCategory") | 
|     public @ResponseBody | 
|     AjaxResult getZbCategory(ShoppingGoodsCategory shoppingGoodsCategory) { | 
|         SysShopInfo zbShop = shopInfoDao.selectZbShop(getMe().getCompanyId()); | 
|         shoppingGoodsCategory.setShopId(zbShop.getId()); | 
|         QueryUtil.setQueryLimitCom(shoppingGoodsCategory); | 
|         return new AjaxResult(AjaxResult.STATUS_SUCCESS, goodsCategoryService.findByModel(shoppingGoodsCategory), 0); | 
|     } | 
|   | 
|   | 
| } |