Helius
2021-03-17 8f9e3814fd49efd763f06305ffbfff6d87012627
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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);
    }
 
 
}