package com.yeshi.buwan.controller.admin.api; import java.io.PrintWriter; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.yeshi.buwan.domain.system.DetailSystem; import com.yeshi.buwan.domain.ShareContent; import com.yeshi.buwan.service.imp.ShareService; import com.yeshi.buwan.service.imp.SystemService; import com.yeshi.buwan.util.Constant; import com.yeshi.buwan.util.StringUtil; import com.yeshi.buwan.web.tag.PageEntity; @Controller @RequestMapping("admin/new/api/share") public class ShareController { @Resource private ShareService shareService; @Resource private SystemService systemService; @RequestMapping("shareList") public void shareList(String key,int pageIndex,PrintWriter out) { key = StringUtil.isNullOrEmpty(key) ? "" : key; pageIndex = pageIndex <= 0 ? 1 : pageIndex; List list = shareService.getShareContentList(key, pageIndex); long count = shareService.getShareContentListCount(key); PageEntity page = new PageEntity(); Map map = new HashMap(); map.put("key", key); page.setParams(map); page.setPageIndex(pageIndex); page.setPageSize(Constant.pageCount); page.setTotalCount((int) count); JSONObject json=new JSONObject(); json.put("code", "0"); json.put("pageEntity", page); Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); json.put("shareList", gson.toJson(list)); out.print(json); return; } @RequestMapping("addShare") public void addShare(String shareContent,String detailSystem,String shareUrl,PrintWriter out) { ShareContent sc = new ShareContent(); sc.setShareContent(shareContent); sc.setShareUrl(shareUrl); sc.setDetailSystem(new DetailSystem(detailSystem)); sc.setCreatetime(System.currentTimeMillis() + ""); shareService.addShareContent(sc); out.print("yes"); return ; } @RequestMapping("updateShare") public void updateShare(String id,String shareContent,String shareUrl,PrintWriter out) { ShareContent sc = shareService.getShareContentById(id); sc.setShareContent(shareContent); sc.setShareUrl(shareUrl); shareService.updateShareContent(sc); out.print("yes"); return ; } @RequestMapping("getShare") public void getShare(String id,PrintWriter out) { ShareContent sc = shareService.getShareContentById(id); Gson gson =new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); JSONObject json =new JSONObject(); json.put("code", "0"); json.put("share", gson.toJson(sc)); out.print(json); return ; } @RequestMapping("deleteShare") public void deleteShare(String ids,PrintWriter out) { if(ids == null || "".equals(ids.trim())){ out.print("no"); return; } String[] idArr = ids.split(","); for (String id : idArr) { System.out.println("id=="+id); shareService.deleteShareContent(new ShareContent(id)); } out.print("yes"); return ; } }