/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.mongo.web;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.mongo.document.User;
import com.jeeplus.modules.mongo.service.UserMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 采购申请Controller
 * @author liuw
 * @version 2018-01-16
 */
@Controller
@RequestMapping(value = "${adminPath}/mongo/user")
public class UserMongoController extends BaseController {
	@Autowired
	private UserMongoService userMongoService;

	@ModelAttribute
	public User get(@RequestParam(required=false) String id) {
		User entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = userMongoService.findById(id);
		}
		if (entity == null){
			entity = new User();
		}
		return entity;
	}

	/**
	 * 查看用户最新版本信息
	 * @return json数据
	 */
	@RequestMapping(value = "getAppversion", method=RequestMethod.GET)
	@ResponseBody
	public AjaxJson save(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		AjaxJson j = new AjaxJson();
		User user = new User();
		user.setId(System.currentTimeMillis()+"");
		user.setAge(30);
		user.setName("付光裕");
		userMongoService.insert(user);
		j.setMsg("233");
		return j;
	}
}