jyy
2021-04-09 f96ad6ec73b3da7df5c08471f0d567d46fc767e8
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.matrix.system.shopXcx.action;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.shopXcx.bean.ShopProductAttrRef;
import com.matrix.system.shopXcx.dao.ShopProductAttrRefDao;
import org.springframework.stereotype.Controller;
import com.matrix.core.exception.GlobleException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
 
import java.util.List;
import java.util.Map;
 
import org.springframework.web.servlet.ModelAndView;
 
/**
 * @description 产品属性关联表
 * @author jyy
 * @date 2019-06-10 10:58
 */
@Controller
@RequestMapping(value = "admin/shopProductAttrRef")
public class ShopProductAttrRefAction {
 
    @Autowired
    private ShopProductAttrRefDao shopProductAttrRefDao;
    
    //记录编辑前的值Before_Edit_Value
    public static final String BEV="ShopProductAttrRef_BEV";
    
    
    /**
     * 列表显示
     */
    @RequestMapping(value =  "/showList")
    public @ResponseBody AjaxResult showList(ShopProductAttrRef shopProductAttrRef, PaginationVO pageVo) {
 
        List<ShopProductAttrRef> dataList = shopProductAttrRefDao.selectInPage(shopProductAttrRef, pageVo);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList,
                shopProductAttrRefDao.selectTotalRecord(shopProductAttrRef));
        return result;
    }
       
    /**
     * 新增
     */   
    @RemoveRequestToken    
       @RequestMapping(value =  "/addShopProductAttrRef")
    public @ResponseBody AjaxResult addShopProductAttrRef(ShopProductAttrRef shopProductAttrRef) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        shopProductAttrRef.setCreateBy(user.getSuName());
        shopProductAttrRef.setUpdateBy(user.getSuName());
         int i=shopProductAttrRefDao.insert(shopProductAttrRef);
         if(i > 0){
             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "产品属性关联表");
         }else {
            throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
        }
    }
    
    
    
    
    
    /**
     * 修改
     */   
    @RemoveRequestToken    
       @RequestMapping(value =  "/modifyShopProductAttrRef")
    public @ResponseBody AjaxResult modifyShopProductAttrRef(ShopProductAttrRef newShopProductAttrRef) {
           ShopProductAttrRef oldShopProductAttrRef = WebUtil.getSessionAttribute(BEV);
        int i = 0;
        Map<String, Object> modifyMap = null;
        try {
            if (!ModelUtils.isModified(oldShopProductAttrRef, newShopProductAttrRef)) {
                i = MatrixConstance.DML_SUCCESSS;
            }
            modifyMap = ModelUtils.comparePojo2Map(oldShopProductAttrRef, newShopProductAttrRef);
        } catch (Exception e) {
            throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopProductAttrRef);
        }
        if (modifyMap.size() > 0) {
            modifyMap.put("id", oldShopProductAttrRef.getId());
            shopProductAttrRefDao.updateByMap(modifyMap);
        }
        i = MatrixConstance.DML_SUCCESSS;
        WebUtil.removeSessionAttribute(BEV);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "产品属性关联表");
        } else {
            throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL);
        }
    }
    
    
    
    
       /**
     * 进入修改界面
     */   
    @SaveRequestToken
       @RequestMapping(value =  "/editForm")
    public ModelAndView editForm(Integer id) {
        ShopProductAttrRef shopProductAttrRef = new ShopProductAttrRef();
        ModelAndView modelAndView = new ModelAndView("admin/shopProductAttrRef-form");
        if (id != null) {
            shopProductAttrRef = shopProductAttrRefDao.selectById(id);
            WebUtil.setSessionAttribute(BEV, shopProductAttrRef);
        }
        modelAndView.addObject("obj",shopProductAttrRef);
        return modelAndView;
    }
       
       
       /**
     * 删除
     */  
     @RequestMapping(value = "/del")
    public @ResponseBody AjaxResult del(String keys) {
        List<String> ids = StringUtils.strToCollToString(keys, ",");
        int i =  shopProductAttrRefDao.deleteByIds(ids);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL);
        }
    }
  
}