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 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 map = new HashMap(); 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())); } } }