package com.ischoolbar.programmer.controller.admin; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.ischoolbar.programmer.entity.admin.Log; import com.ischoolbar.programmer.page.admin.Page; import com.ischoolbar.programmer.service.admin.LogService; @RequestMapping("/admin/log") @Controller public class LogController { @Autowired private LogService logService; @RequestMapping(value="/list",method=RequestMethod.GET) public ModelAndView list(ModelAndView model){ model.setViewName("log/list"); return model; } @RequestMapping(value="/list",method=RequestMethod.POST) @ResponseBody public Map getList(Page page, @RequestParam(name="content",required=false,defaultValue="") String content ){ Map ret = new HashMap(); Map queryMap = new HashMap(); queryMap.put("content", content); queryMap.put("offset", page.getOffset()); queryMap.put("pageSize", page.getRows()); ret.put("rows", logService.findList(queryMap)); ret.put("total", logService.getTotal(queryMap)); return ret; } @RequestMapping(value="/add",method=RequestMethod.POST) @ResponseBody public Map add(Log log){ Map ret = new HashMap(); if(log == null){ ret.put("type", "error"); ret.put("msg", "错误"); return ret; } if(StringUtils.isEmpty(log.getContent())){ ret.put("type", "error"); ret.put("msg", "错误"); return ret; } log.setCreateTime(new Date()); if(logService.add(log) <= 0){ ret.put("type", "error"); ret.put("msg", "错误"); return ret; } ret.put("type", "success"); ret.put("msg", "成功"); return ret; } @RequestMapping(value="/delete",method=RequestMethod.POST) @ResponseBody public Map delete(String ids){ Map ret = new HashMap(); if(StringUtils.isEmpty(ids)){ ret.put("type", "error"); ret.put("msg", "错误"); return ret; } if(ids.contains(",")){ ids = ids.substring(0,ids.length()-1); } if(logService.delete(ids) <= 0){ ret.put("type", "error"); ret.put("msg", "错误"); return ret; } ret.put("type", "success"); ret.put("msg", "成功"); return ret; } }