package com.blueland.bpm.manage.log.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.blueland.bpm.common.base.BaseSpringController;
import com.blueland.bpm.common.page.Page;
import com.blueland.bpm.common.util.DateUtil;
import com.blueland.bpm.common.util.HttpUtils;
/**
 * @author lw
 * @version 1.0
 * @since  
 */
 



import java.text.ParseException;
import java.util.*;

import com.blueland.bpm.log.model.*;
import com.blueland.bpm.log.service.*;

@Controller
@RequestMapping(value = "tlogUserOperate")
public class TlogUserOperateController extends BaseSpringController{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	@Autowired
	private TlogUserOperateManager tlogUserOperateManager;
	
	private final String LIST_ACTION = "redirect:/tlogUserOperate/list.do";
	
	public TlogUserOperateController() {
	}
	

	/**
	 * 增加了@ModelAttribute的方法可以在本controller的方法调用前执行,可以存放一些共享变量,如枚举值
	 */
	@ModelAttribute
	public void init(ModelMap model) {
		//model.put("now", new java.sql.Timestamp(System.currentTimeMillis()));
	}
	
	/** 
	 * 执行搜索 
	 * @throws Exception 
	 **/
	@RequestMapping(value = "list")
	public ModelAndView list(HttpServletRequest request,TlogUserOperate query,
			String startOperateTimeStr,String endOperateTimeStr) throws Exception {
		if(null!=startOperateTimeStr && !"".equals(startOperateTimeStr)){
			query.setStartOperateTime(DateUtil.convertStringToDate("yyyy-MM-dd HH:mm:ss", 
					startOperateTimeStr + " 00:00:00"));
		}
		if(null!=endOperateTimeStr && !"".equals(endOperateTimeStr)){
			query.setEndOperateTime(DateUtil.convertStringToDate("yyyy-MM-dd HH:mm:ss",
					endOperateTimeStr + " 23:59:59"));
		}
		Page page = this.tlogUserOperateManager.findPage(query);
		ModelAndView result = new ModelAndView("/tlogUserOperate/list");
		result.addAllObjects(toModelMap(page, query));
		result.addObject("startOperateTimeStr", startOperateTimeStr);
		result.addObject("endOperateTimeStr",endOperateTimeStr);
		return result;
	}
	
	/** 
	 * 查看对象
	 **/
	@RequestMapping(value = "show")
	public ModelAndView show(HttpServletRequest request)  {
		String id = new String(request.getParameter("logId"));
		TlogUserOperate tlogUserOperate = (TlogUserOperate)tlogUserOperateManager.getById(id);
		return new ModelAndView("/tlogUserOperate/show","tlogUserOperate",tlogUserOperate);
	}
	
	/** 
	 * 进入新增页面
	 **/
	@RequestMapping(value = "create")
	public ModelAndView create(HttpServletRequest request,TlogUserOperate tlogUserOperate)  {
		return new ModelAndView("/tlogUserOperate/create","tlogUserOperate",tlogUserOperate);
	}
	
	/** 
	 * 保存新增对象
	 **/
	@RequestMapping(value = "save")
	public ModelAndView save(HttpServletRequest request,TlogUserOperate tlogUserOperate,RedirectAttributes redirectAttributes)  {
		tlogUserOperateManager.save(tlogUserOperate);
		redirectAttributes.addFlashAttribute(ACTION_MESSAGE, CREATED_SUCCESS);
		return new ModelAndView(LIST_ACTION);
	}
	
	/**
	 * 进入更新页面
	 **/
	@RequestMapping(value = "edit")
	public ModelAndView edit(HttpServletRequest request)  {
		String id = new String(request.getParameter("logId"));
		TlogUserOperate tlogUserOperate = (TlogUserOperate)tlogUserOperateManager.getById(id);
		return new ModelAndView("/tlogUserOperate/edit","tlogUserOperate",tlogUserOperate);
	}
	
	/**
	 * 保存更新对象
	 **/
	@RequestMapping(value = "update")
	public ModelAndView update(HttpServletRequest request,TlogUserOperate tlogUserOperate,RedirectAttributes redirectAttributes)  {
		String id = new String(request.getParameter("logId"));
		tlogUserOperateManager.update(tlogUserOperate);
		redirectAttributes.addFlashAttribute(ACTION_MESSAGE, UPDATE_SUCCESS);
		return new ModelAndView(LIST_ACTION);
	}
	
	/**
	 *删除对象
	 **/
	@RequestMapping(value = "delete")
	public ModelAndView delete(HttpServletRequest request,RedirectAttributes redirectAttributes) {
		String[] items = request.getParameterValues("items");
		for(int i = 0; i < items.length; i++) {
			Hashtable params = HttpUtils.parseQueryString(items[i]);
			
			String id = new String((String)params.get("logId"));
			
			tlogUserOperateManager.removeById(id);
		}
		redirectAttributes.addFlashAttribute(ACTION_MESSAGE, DELETE_SUCCESS);
		return new ModelAndView(LIST_ACTION);
	}
	
}

