Administrator
2018-10-30 7bf6a0582c7c62c90ee2ed8a88654f11d0479092
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
package com.yeshi.fanli.controller.admin;
 
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.fanli.entity.bus.clazz.GoodsSecondClass;
import com.yeshi.fanli.exception.NotExistObjectException;
import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import org.yeshi.utils.JsonUtil;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("admin/new/api/v1/secondclass")
public class GoodsSecondClassAdminController {
    
    @Resource
    private GoodsSecondClassService goodsSecondClassService;
    
    @RequestMapping(value="/getSecondClassList",method=RequestMethod.POST)
    public void getSecondClassList(int pageIndex,String key, long cid,PrintWriter out){
            List<GoodsSecondClass> secondClassList = goodsSecondClassService.getSecondClassList(pageIndex-1,key,cid);
             int count =goodsSecondClassService.getCount(cid,key);
             int totalPage = count % Constant.PAGE_SIZE == 0 ? count
                     / Constant.PAGE_SIZE : count / Constant.PAGE_SIZE + 1;
             PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count,
                     totalPage);
             Map<String, String> map = new HashMap<String, String>();
             map.put("key", key);
             pe.setParams(map);
             JSONObject data = new JSONObject();
             data.put("pe", pe);
             data.put("goodsSecondClassList", secondClassList);
             out.print(JsonUtil.loadTrueResult(data));
    }
    
    @RequestMapping(value="/addSecondClass",method=RequestMethod.POST)
    public void addSecondClass(GoodsSecondClass secondClass,PrintWriter out){
        
        goodsSecondClassService.addSecondClass(secondClass);
        out.print(JsonUtil.loadTrueResult("添加成功"));
    }
    
    @RequestMapping(value="/deleteSecondClass",method=RequestMethod.POST)
    public void deleteSecondClass(long[] sids,PrintWriter out){
        for (long sid : sids) {
            goodsSecondClassService.deleteSecondClass(sid);
        }
        out.print(JsonUtil.loadTrueResult("删除成功"));
    }
    
    @RequestMapping(value="/getSecondClass",method=RequestMethod.POST)
    public void getSecondClass(long scid,PrintWriter out){
            GoodsSecondClass secondClass = goodsSecondClassService.getSecondClass(scid);
            if(secondClass==null){
                out.print(JsonUtil.loadFalseResult("不存在该分类"));
            }
            out.print(JsonUtil.loadTrueResult(secondClass));
    }
    
    @RequestMapping(value="/updateSecondClass",method=RequestMethod.POST)
    public void updateSecondClass(GoodsSecondClass secondClass,PrintWriter out){
        try {
            goodsSecondClassService.updateSecondClass(secondClass);
            out.print(JsonUtil.loadTrueResult("修改成功"));
        } catch (NotExistObjectException e) {
            out.print(JsonUtil.loadFalseResult(e.getMessage()));
        }
    }
    
    
}