package com.matrix.system.hive.action; 
 | 
  
 | 
import com.matrix.core.constance.MatrixConstance; 
 | 
import com.matrix.core.exception.GlobleException; 
 | 
import com.matrix.core.pojo.AjaxResult; 
 | 
import com.matrix.core.tools.WebUtil; 
 | 
import com.matrix.system.common.bean.SysUsers; 
 | 
import com.matrix.system.hive.bean.SysGoodsType; 
 | 
import com.matrix.system.hive.bean.SysShopInfo; 
 | 
import com.matrix.system.hive.dao.SysShopInfoDao; 
 | 
import com.matrix.system.hive.service.SysGoodsTypeService; 
 | 
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; 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
/** 
 | 
 * @description 商品类型管理 
 | 
 * @author jyy 
 | 
 * @email 820786562@qqcom 
 | 
 * @date 2016-07-12 
 | 
 */ 
 | 
@Controller 
 | 
@RequestMapping(value = "/admin/goodstype") 
 | 
public class GoodsTypeController extends BaseController { 
 | 
  
 | 
  
 | 
    @Resource 
 | 
    private SysGoodsTypeService currentService; 
 | 
  
 | 
    @Autowired 
 | 
    private SysShopInfoDao shopInfoDao; 
 | 
  
 | 
    /** 
 | 
     * 新增或修改页面 
 | 
     */        
 | 
       @RequestMapping(value = "/addOrModify") 
 | 
    public @ResponseBody 
 | 
    AjaxResult addOrModify(SysGoodsType sysGoodsType) { 
 | 
           SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); 
 | 
        if (sysGoodsType.getId() != null) { 
 | 
            if (sysGoodsType.getParentId() != null && sysGoodsType.getParentId().equals(sysGoodsType.getId())) { 
 | 
                throw new GlobleException("父级不能是自己"); 
 | 
            } 
 | 
            return modify(currentService, sysGoodsType, "产品分类"); 
 | 
        } else { 
 | 
  
 | 
            sysGoodsType.setCompanyId(users.getCompanyId()); 
 | 
            return add(currentService, sysGoodsType, "产品分类"); 
 | 
        } 
 | 
    } 
 | 
        
 | 
  
 | 
    @RequestMapping(value = "/editForm") 
 | 
    public String editForm(Long id, HttpServletRequest request) { 
 | 
        SysGoodsType sysGoodsType; 
 | 
        if (id != null) { 
 | 
            sysGoodsType = currentService.findById(id); 
 | 
            request.setAttribute("obj", sysGoodsType); 
 | 
        } 
 | 
        return "admin/hive/instore/goodstype-form"; 
 | 
    } 
 | 
     
 | 
  
 | 
    @RequestMapping(value = "/del") 
 | 
    public @ResponseBody AjaxResult del(Long keys) { 
 | 
  
 | 
        int i = currentService.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) { 
 | 
        SysGoodsType sysGoodsType = super.findById(currentService, id); 
 | 
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(sysGoodsType), 0); 
 | 
    } 
 | 
     
 | 
    /** 
 | 
     * ======================================================= 
 | 
     * *******************公共的数据访问方法******************** 
 | 
     * ======================================================= 
 | 
     */ 
 | 
  
 | 
    /** 
 | 
     * 如果客户端没有指定加载特定门店则当前登录用户所在门店 
 | 
     * @param sysGoodsType 
 | 
     * @return 
 | 
     */ 
 | 
    @RequestMapping(value = "/all") 
 | 
    public @ResponseBody AjaxResult all(SysGoodsType sysGoodsType) { 
 | 
        SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); 
 | 
        sysGoodsType.setCompanyId(users.getCompanyId()); 
 | 
        List<SysGoodsType> list=currentService.findByModel(sysGoodsType); 
 | 
        return new AjaxResult(AjaxResult.STATUS_SUCCESS,    currentService.findByModel(sysGoodsType), 0); 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |