/**
 * IndexController.java
 * Create on 2016-1-27
 * Copyright 2016 Forwave All Rights Reserved
 */
package com.biotherapy.ehbh.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.biotherapy.ehbh.model.User;
import com.biotherapy.ehbh.model.json.DatatablesPage;
import com.biotherapy.ehbh.service.impl.UserServiceImpl;

/**
 * 
 * 人员管理控制器
 *  
 * @author Foolish
 * @DateTime 2016-1-30 14:48:07
 * @version 2.0
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
	@Resource
	UserServiceImpl userService;
	
	@ResponseBody
	@RequestMapping(params = "fn=add")
	public Map<String, Object> add(User user,HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		
		User loginUser = (User) request.getSession().getAttribute("user");
		map = userService.add(user,loginUser);
		
		return map;
	}
	
	@ResponseBody
	@RequestMapping(params = "fn=edit")
	public Map<String, Object> edit(User user,HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		User loginUser = (User) request.getSession().getAttribute("user");

		map = userService.update(user,loginUser);
		
		return map;
	}
	
	@ResponseBody
	@RequestMapping(params = "fn=del")
	public Map<String, Object> del(@RequestBody List<String> userAccounts,HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		User loginUser = (User) request.getSession().getAttribute("user");
		map = userService.deleteList(userAccounts,loginUser);
		
		return map;
	}
	
	@ResponseBody
	@RequestMapping(params = "fn=list")
	public Map<String, Object> list(@RequestBody DatatablesPage dtPage) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<User> patients = userService.searchUserList(dtPage.getSearch().getValue(),dtPage.getStart(), dtPage.getLength());
		int total = userService.getTotalCount();
		map.put("drap", 1);
		map.put("recordsTotal", total);
		map.put("recordsFiltered", total);
		map.put("data", patients);
		return map;
	}

}
