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 javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import com.yeshi.buwan.util.SystemUtil; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.yeshi.buwan.domain.AdminInfo; import com.yeshi.buwan.domain.system.DetailSystem; import com.yeshi.buwan.domain.system.SystemInfo; import com.yeshi.buwan.service.imp.SystemService; import com.yeshi.buwan.util.Constant; import com.yeshi.buwan.web.tag.PageEntity; @Controller @RequestMapping("admin/new/api/system") public class SystemController { @Resource private SystemService systemService; /** * 子系统列表 * * @return */ @RequestMapping("detailSystemList") public void detailSystemList(int pageIndex, String key, HttpSession session, PrintWriter out) { pageIndex = pageIndex <= 0 ? 1 : pageIndex; List list = systemService.getDetailSystemList(key, SystemUtil.getAdminSelectedSystem(session).getId(), pageIndex); long count = systemService.getDetailSystemListCount(key,SystemUtil.getAdminSelectedSystem(session).getId()); PageEntity pe = new PageEntity(); pe.setPageIndex(pageIndex); pe.setPageSize(Constant.pageCount); Map map = new HashMap(); map.put("key", key); pe.setParams(map); pe.setTotalCount((int) count); JSONObject json =new JSONObject(); json.put("code", "0"); json.put("pageEntity", pe); Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); json.put("detailSystemList", gson.toJson(list)); out.print(json); return; } @RequestMapping("getSystemForAddDetailSystem") public void getSystemForAddDetailSystem(PrintWriter out) { List list = systemService.getSystemList(); JSONObject json =new JSONObject(); json.put("code", "0"); Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); json.put("SystemInfoList", gson.toJson(list)); out.print(json); return ; } /** * 添加详细的系统 * * @return */ @RequestMapping("addDetailSystem") public void addDetailSystem(@RequestBody DetailSystem detailSystem,HttpServletRequest request,PrintWriter out) { DetailSystem ds = new DetailSystem(); ds.setCreatetime(System.currentTimeMillis() + ""); ds.setAppName(detailSystem.getAppName()); ds.setBeizhu(detailSystem.getBeizhu()); ds.setInfo((AdminInfo) request.getAttribute("ADMIN_USER")); ds.setIosUmengAppKey(detailSystem.getIosUmengAppKey()); ds.setIosUmengMasterKey(detailSystem.getIosUmengMasterKey()); ds.setPackageName(detailSystem.getPackageName()); ds.setPlatform(detailSystem.getPlatform()); ds.setSystem(new SystemInfo(detailSystem.getSystem().getId())); ds.setUmengAppKey(detailSystem.getUmengAppKey());//iosUmengAppKey ds.setUmengMasterKey(detailSystem.getUmengMasterKey());//iosUmengMasterKey ds.setSohuKey(detailSystem.getSohuKey()); ds.setSohuPartner(detailSystem.getSohuPartner()); // if (StringUtil.isNullOrEmpty(String.valueOf(detailSystem.isAppStoreIng()))){ // ds.setAppStoreIng(false); // } // else { // ds.setAppStoreIng(true); // ds.setAppStoreVersion(detailSystem.getAppStoreVersion()); // } System.out.println("detailSystem=="+ds.toString()); systemService.addDetailSystem(ds); out.print("yes"); return ; } @RequestMapping("getDetailSystem") public void getDetailSystem(String id,PrintWriter out) { DetailSystem ds = systemService.getDetailSystemById(id); JSONObject json =new JSONObject(); json.put("code", "0"); json.put("detailSystem",new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(ds)); out.print(json); return ; } @RequestMapping("updateDetailSystem") public void updateDetailSystem(@RequestBody DetailSystem detailSystem,HttpServletRequest request,PrintWriter out) { DetailSystem ds = systemService.getDetailSystemById(detailSystem.getId()); ds.setAppName(detailSystem.getAppName()); ds.setBeizhu(detailSystem.getBeizhu()); ds.setInfo((AdminInfo) request.getAttribute("ADMIN_USER")); ds.setIosUmengAppKey(detailSystem.getIosUmengAppKey()); ds.setIosUmengMasterKey(detailSystem.getIosUmengMasterKey()); ds.setPackageName(detailSystem.getPackageName()); ds.setPlatform(detailSystem.getPlatform()); ds.setSystem(new SystemInfo(detailSystem.getSystem().getId())); ds.setUmengAppKey(detailSystem.getUmengAppKey());//iosUmengAppKey ds.setUmengMasterKey(detailSystem.getUmengMasterKey());//iosUmengMasterKey ds.setSohuKey(detailSystem.getSohuKey()); ds.setSohuPartner(detailSystem.getSohuPartner()); System.out.println("detailSystem=="+ds.toString()); systemService.updateDetailSystem(ds); out.print("yes"); return ; } @RequestMapping("deleteDetailSystemList") public void deleteDetailSystemList(String ids,PrintWriter out) { if(ids == null || "".equals(ids.trim())){ out.print("no"); return; } String[] idArr = ids.split(","); for (String st : idArr) { System.out.println("id--"+st); systemService.deleteDetailSystem(st); } out.print("yes"); return; } }