package com.huatek.frame.base.user.controller.remote;

import java.util.Map;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.frame.base.entity.User;
import com.huatek.frame.base.service.UserService;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "sysUserRemoter")
public class SysUserRemoteController {

	

	@Reference(check = false)
	private UserService userService;

	/**
	 * 新增用户
	 * 
	 * @param user
	 * @return
	 */
	@ApiOperation(value = "新增用户",httpMethod="POST")
	@RequestMapping(value = "/addUser",method = RequestMethod.POST)
	public Map<String, Object> addUser(@RequestBody Map<String,Object> param) {
		User user = new User();
		
		String userName = param.get("userName").toString();
		String userCode = userName;
		if(userName.length()>8)
		{
			userCode= userName.substring(0,7);
		}
		user.setUserCode(userCode);
		user.setUserName(param.get("userName").toString());
		user.setPassword(param.get("password").toString());
		if(param.get("email")!=null)
		{
			user.setUserEmail(param.get("email").toString());
		}
		if(param.get("phone")!=null)
		{
			user.setUserMobile(param.get("phone").toString());
		}
		
		System.out.println("-----------------------------------------------------");
		Map<String, Object> map = userService.addRemoteUser(user);
		return map;
	}
}
