package com.uas.platform.b2b.v2.controller;

import com.uas.platform.b2b.model.User;
import com.uas.sso.entity.UserView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.uas.platform.b2b.v2.service.UserService;
import org.springframework.web.bind.annotation.RestController;

@RestController("v2.UserController")
@RequestMapping(value = "/public/user")
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping(method = RequestMethod.POST)
	@ResponseBody
	public User save(UserView user) {
		if (user != null) {
			return userService.save(user);
		}
		return null;
	}

	@RequestMapping(value = "/pwd", method = RequestMethod.POST)
	@ResponseBody
	public void changePassword(UserView user, String password) {
		if (user != null && password != null) {
			userService.changePassword(user, password);
		}
	}

	/**
	 * 用户绑定企业
	 * @param spaceUU 企业uu号
	 * @param userView 用户信息
	 */
	@RequestMapping(params = "type=bind", method = RequestMethod.POST)
	public void add(Long spaceUU, UserView userView) {
		userService.addUser(spaceUU, userView);
	}

	/**
	 * 用户绑定企业
	 * @param spaceUU 企业uu号
	 * @param userUU 用户uu号
	 */
	@RequestMapping(params = "type=unbind", method = RequestMethod.POST)
	public void remove(Long spaceUU, Long userUU) {
		userService.removeUser(spaceUU, userUU);
	}
}
