Sfoglia il codice sorgente

添加企业,用户部分接口
企业注册未开通应用bug

wangmh 7 anni fa
parent
commit
fcc80c9985

+ 87 - 435
sso-common/src/main/java/com/uas/sso/util/AccountUtils.java

@@ -1,5 +1,15 @@
 package com.uas.sso.util;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.sso.AccountConfig;
+import com.uas.sso.ResultWrap;
+import com.uas.sso.common.util.HttpUtil;
+import com.uas.sso.entity.UserSpaceView;
+import com.uas.sso.entity.UserView;
+import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
+
 /**
  * 客户端使用,操作企业资料、用户资料
  *
@@ -8,442 +18,84 @@ package com.uas.sso.util;
  */
 public class AccountUtils {
 
+    /**
+     * 企业解除绑定的应用
+     * 
+     * @author wangmh
+     * @date 2018/1/26 16:34
+     * @param spaceUU 企业uu号
+     * @param appId 应用id
+     * @throws Exception
+     */
+	public static void unbindApp(Long spaceUU, String appId) throws Exception {
+		String saveUrl = AccountConfig.getSpaceSaveUrl();
+		if (!StringUtils.isEmpty(saveUrl)) {
+            ModelMap formData = new ModelMap();
+			formData.put("_operate", "unbind");
+			formData.put("spaceUU", spaceUU);
+			formData.put("appId", appId);
+			HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+			if (!res.isSuccess()) {
+                throw new Exception(res.getContent());
+            } else {
+                ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+                if (!result.isSuccess()) {
+                    throw new Exception(result.getErrMsg());
+                }
+            }
+		}
+	}
+
+    /**
+     * 企业开通应用
+     * @param spaceUU 企业uu号
+     * @param appId 应用id
+     * @throws Exception
+     */
+    public static void bindApp(Long spaceUU, String appId) throws Exception {
+        String saveUrl = AccountConfig.getSpaceSaveUrl();
+        if (!StringUtils.isEmpty(saveUrl)) {
+            ModelMap formData = new ModelMap();
+            formData.put("_operate", "bind");
+            formData.put("spaceUU", spaceUU);
+            formData.put("appId", appId);
+            HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+            if (!res.isSuccess()) {
+                throw new Exception(res.getContent());
+            } else {
+                ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+                if (!result.isSuccess()) {
+                    throw new Exception(result.getErrMsg());
+                }
+            }
+        }
+    }
+
+    /**
+     * 用户解除绑定企业
+     * @param userUU 用户uu号
+     * @param spaceUU 企业uu号
+     * @throws Exception
+     */
+    public static void unbindUserSpace(Long userUU, Long spaceUU) throws Exception {
+        String saveUrl = AccountConfig.getUserSaveUrl();
+        if (!StringUtils.isEmpty(saveUrl)) {
+            ModelMap formData = new ModelMap();
+            formData.put("_operate", "unbind");
+            formData.put("userUU", userUU);
+            formData.put("spaceUU", spaceUU);
+            HttpUtil.ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
+            if (!res.isSuccess()) {
+                throw new Exception(res.getContent());
+            } else {
+                ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
+                if (!result.isSuccess()) {
+                    throw new Exception(result.getErrMsg());
+                }
+            }
+        }
+    }
 /// 之后方法会恢复并修改
-//	/**
-//	 * 修改用户信息
-//	 *
-//	 * @param user
-//	 * @param userDetail
-//	 * @return
-//	 * @throws Exception
-//	 */
-//	public static List<User> saveUser(User user, UserDetail userDetail) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = new JSONObject();
-//			if (userDetail != null) {
-//				formData = JSON.parseObject(JSON.toJSONString(userDetail));
-//			}
-//			if (user != null) {
-//				if (user.getUid() == null) {
-//					user.setUid(userDetail.getMobile());
-//				}
-//				if (user.getSecondUID() == null) {
-//					user.setSecondUID(userDetail.getEmail());
-//				}
-//				if (user.getAppId() != null && user.getDialectUID() != null) {
-//					if (user.getAppId().equals("b2b") || user.getAppId().equals("mall")) {
-//						user.setSalt(user.getDialectUID());
-//					}
-//				}
-//				formData.putAll(JSON.parseObject(JSON.toJSONString(user)));
-//			}
-//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//			else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (result.isError()) {
-//					throw new Exception(result.getErrMsg());
-//				} else {
-//					return JSON.parseArray(JSON.toJSONString(result.getContent()), User.class);
-//				}
-//			}
-//		}
-//		return null;
-//	}
-//
-//	/**
-//	 * 修改用户信息
-//	 *
-//	 * @param dialectUID
-//	 *            个人唯一标识
-//	 * @param spaceDialectUID
-//	 *            企业唯一标识
-//	 * @param userDetail
-//	 *            个人详细信息
-//	 * @return
-//	 * @throws Exception
-//	 */
-//	public static List<User> saveUser(Object dialectUID, Object spaceDialectUID, UserDetail userDetail) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setDialectUID(dialectUID.toString());
-//		if (spaceDialectUID != null) {
-//			user.setSpaceDialectUID(spaceDialectUID.toString());
-//		}
-//		return saveUser(user, userDetail);
-//	}
-//
-//	/**
-//	 * 保存与当前应用无关的用户信息,借用appId=sso
-//	 *
-//	 * @param uid
-//	 * @param spaceUID
-//	 * @param userDetail
-//	 * @return
-//	 * @throws Exception
-//	 */
-//	public static List<User> saveCustUser(Object uid, Object spaceUID, UserDetail userDetail) throws Exception {
-//		User user = new User();
-//		user.setAppId(AccountConfig.ACCOUNT_CENTER);
-//		user.setDialectUID(uid.toString());
-//		user.setSpaceUID(spaceUID.toString());
-//		return saveUser(user, userDetail);
-//	}
-//
-//	/**
-//	 * 添加用户信息
-//	 *
-//	 * @param dialectUID
-//	 *            个人唯一标识
-//	 * @param spaceDialectUID
-//	 *            企业唯一标识
-//	 * @param userDetail
-//	 *            个人详细信息
-//	 * @param noEncryPwd
-//	 *            明文密码
-//	 * @return
-//	 * @throws Exception
-//	 */
-//	public static List<User> addUser(Object dialectUID, Object spaceDialectUID, UserDetail userDetail, String noEncryPwd) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setDialectUID(dialectUID.toString());
-//		if (spaceDialectUID != null) {
-//			user.setSpaceDialectUID(spaceDialectUID.toString());
-//		}
-//		user.setPassword(noEncryPwd);
-//		return saveUser(user, userDetail);
-//	}
-//
-//	/**
-//	 * 修改手机号
-//	 * @param oldTel
-//	 * @param newTel
-//	 * @return
-//	 * @throws Exception
-//	 */
-//	public static List<User> updateTel (String oldTel, String newTel) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			saveUrl = saveUrl + "/updateTel";
-//			JSONObject formData = new JSONObject();
-//			formData.put("oldTel", oldTel);
-//			formData.put("newTel", newTel);
-//			formData.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
-//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
-//			if (!res.isSuccess()) {
-//				throw new Exception(res.getContent());
-//			} else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (result.isError()) {
-//					throw new Exception(result.getErrMsg());
-//				} else {
-//					return JSON.parseArray(JSON.toJSONString(result.getContent()), User.class);
-//				}
-//			}
-//		}
-//		return null;
-//	}
-//
-//	/**
-//	 * 修改邮箱
-//	 * @param oldTel
-//	 * @param newEmail
-//	 * @return
-//	 * @throws Exception
-//	 */
-//	public static List<User> updateEmail (String oldTel, String newEmail) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			saveUrl = saveUrl + "/updateEmail";
-//			JSONObject formData = new JSONObject();
-//			formData.put("oldTel", oldTel);
-//			formData.put("newEmail", newEmail);
-//			formData.put("appId", SSOHelper.getSSOService().getConfig().getAppName());
-//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
-//			if (!res.isSuccess()) {
-//				throw new Exception(res.getContent());
-//			} else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (result.isError()) {
-//					throw new Exception(result.getErrMsg());
-//				} else {
-//					return JSON.parseArray(JSON.toJSONString(result.getContent()), User.class);
-//				}
-//			}
-//		}
-//		return null;
-//	}
-//
-//	public static List<UserSpace> saveUserSpace(UserSpace space, UserSpaceDetail spaceDetail) throws Exception {
-//		String saveUrl = AccountConfig.getSpaceSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = new JSONObject();
-//			if (spaceDetail != null) {
-//				formData = JSON.parseObject(JSON.toJSONString(spaceDetail));
-//			}
-//			if (space != null) {
-//				if (space.getUid() == null) {
-//					space.setUid(spaceDetail.getBusinessCode());
-//				}
-//				formData.putAll(JSON.parseObject(JSON.toJSONString(space)));
-//			}
-//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//			else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (result.isError()) {
-//					throw new Exception(result.getErrMsg());
-//				} else {
-//					return JSON.parseArray(JSON.toJSONString(result.getContent()), UserSpace.class);
-//				}
-//			}
-//		}
-//		return null;
-//	}
-//
-//	public static List<UserSpace> saveUserSpace(Object dialectUID, UserSpaceDetail spaceDetail) throws Exception {
-//		UserSpace userSpace = new UserSpace();
-//		userSpace.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		userSpace.setDialectUID(dialectUID.toString());
-//		return saveUserSpace(userSpace, spaceDetail);
-//	}
-//
-//	/**
-//	 * 解除绑定的应用
-//	 *
-//	 * @param userSpace
-//	 * @throws Exception
-//	 */
-//	public static void unbindUserSpace(UserSpace userSpace) throws Exception {
-//		String saveUrl = AccountConfig.getSpaceSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = JSON.parseObject(JSON.toJSONString(userSpace));
-//			formData.put("_operate", "unbind");
-//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//		}
-//	}
-//
-//	/**
-//	 * 解除绑定的应用
-//	 *
-//	 * @param uid
-//	 * @throws Exception
-//	 */
-//	public static void unbindUserSpace(String uid) throws Exception {
-//		unbindUserSpace(SSOHelper.getSSOService().getConfig().getAppName(), uid);
-//	}
-//
-//	/**
-//	 * 解除绑定的应用
-//	 *
-//	 * @param appId
-//     * @param uid
-//	 * @throws Exception
-//	 */
-//	public static void unbindUserSpace(String appId, String uid) throws Exception {
-//		UserSpace userSpace = new UserSpace();
-//		userSpace.setAppId(appId);
-//		userSpace.setUid(uid);
-//		unbindUserSpace(userSpace);
-//	}
-//
-//	/**
-//	 * 解除绑定的云账号
-//	 *
-//	 * @param user
-//	 * @throws Exception
-//	 */
-//	public static void unbindUser(User user) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
-//			formData.put("_operate", "unbind");
-//			ResponseWrap res = HttpUtil.doPost(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//		}
-//	}
-//
-//	/**
-//	 * 解除绑定的云账号
-//	 *
-//	 * @param dialectUID
-//     * @param spaceDialectUID
-//	 * @throws Exception
-//	 */
-//	public static void unbindUser(Object dialectUID, Object spaceDialectUID) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setDialectUID(dialectUID.toString());
-//		if (spaceDialectUID != null) {
-//			user.setSpaceDialectUID(spaceDialectUID.toString());
-//		}
-//		unbindUser(user);
-//	}
-//
-//	/**
-//	 * 校验密码
-//	 *
-//	 * @param user
-//	 * @throws Exception
-//	 */
-//	public static boolean checkPassword(User user) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
-//			formData.put("_operate", "check");
-//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//			else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (!result.isSuccess())
-//					throw new Exception(result.getErrMsg());
-//				else
-//					return true;
-//			}
-//		}
-//		return false;
-//	}
-//
-//	/**
-//	 * 校验密码
-//	 *
-//	 * @param dialectUID
-//	 * @param spaceDialectUID
-//	 * @param password
-//	 * @throws Exception
-//	 */
-//	public static boolean checkPassword(Object dialectUID, Object spaceDialectUID, String password) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setDialectUID(dialectUID.toString());
-//		if (spaceDialectUID != null) {
-//			user.setSpaceDialectUID(spaceDialectUID.toString());
-//		}
-//		user.setPassword(password);
-//		return checkPassword(user);
-//	}
-//
-//	/**
-//	 * 校验密码
-//	 *
-//	 * <pre>
-//	 * 全匹配模式
-//	 * </pre>
-//	 *
-//	 * @param user
-//	 * @throws Exception
-//	 */
-//	public static boolean fuzzyCheckPassword(User user) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
-//			formData.put("_operate", "fuzzyCheck");
-//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//			else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (!result.isSuccess())
-//					throw new Exception(result.getErrMsg());
-//				else
-//					return true;
-//			}
-//		}
-//		return false;
-//	}
-//
-//	/**
-//	 * 校验密码
-//	 *
-//	 * <pre>
-//	 * 全匹配模式
-//	 * </pre>
-//	 *
-//	 * @param dialectUID
-//	 * @param spaceDialectUID
-//	 * @param password
-//	 * @throws Exception
-//	 */
-//	public static boolean fuzzyCheckPassword(Object dialectUID, Object spaceDialectUID, String password) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setDialectUID(dialectUID.toString());
-//		if (spaceDialectUID != null) {
-//			user.setSpaceDialectUID(spaceDialectUID.toString());
-//		}
-//		user.setPassword(password);
-//		return fuzzyCheckPassword(user);
-//	}
-//
-//	/**
-//	 * 重置密码
-//	 *
-//	 * @param user
-//	 * @throws Exception
-//	 */
-//	public static void resetPassword(User user) throws Exception {
-//		String saveUrl = AccountConfig.getUserSaveUrl();
-////		saveUrl = saveUrl + "/resetPwd";
-//		if (!StringUtils.isEmpty(saveUrl)) {
-//			JSONObject formData = JSON.parseObject(JSON.toJSONString(user));
-//			formData.put("_operate", "reset");
-//			ResponseWrap res = HttpUtil.doGet(saveUrl, formData);
-//			if (!res.isSuccess())
-//				throw new Exception(res.getContent());
-//			else {
-//				ResultWrap result = JSON.parseObject(res.getContent(), ResultWrap.class);
-//				if (!result.isSuccess())
-//					throw new Exception(result.getErrMsg());
-//			}
-//		}
-//	}
-//
-//	/**
-//	 * 重置密码
-//	 *
-//	 * @param dialectUID
-//	 *            应用自己的用户唯一标识
-//	 * @param spaceDialectUID
-//	 *            企业唯一标识
-//	 * @param noEncryPwd
-//	 *            新密码(明文)
-//	 * @throws Exception
-//	 */
-//	public static void resetPassword(Object dialectUID, Object spaceDialectUID, String noEncryPwd) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setDialectUID(dialectUID.toString());
-//		if (spaceDialectUID != null) {
-//			user.setSpaceDialectUID(spaceDialectUID.toString());
-//		}
-//		user.setPassword(noEncryPwd);
-//		resetPassword(user);
-//	}
-//
-//	/**
-//	 * 重置密码
-//	 *
-//	 * @param mobile
-//	 *            手机号
-//	 * @param noEncryPwd
-//	 *            新密码(明文)
-//	 * @throws Exception
-//	 */
-//	public static void resetPassword(String mobile, String noEncryPwd) throws Exception {
-//		User user = new User();
-//		user.setAppId(SSOHelper.getSSOService().getConfig().getAppName());
-//		user.setUid(mobile);
-//		user.setPassword(noEncryPwd);
-//		resetPassword(user);
-//	}
 //
 //	/**
 //	 * 获取校验码

+ 28 - 1
sso-server/src/main/java/com/uas/sso/controller/UserManagerController.java

@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -50,10 +51,36 @@ public class UserManagerController extends BaseController {
      * @author wangmh
      * @date 2018/1/11 15:06
      * @param idCard 身份证号
-     * @return
+     * @return {"isValid", b} b为true说明已认证
      */
     @RequestMapping(value = "/idCard/valid", method = RequestMethod.GET)
     public ModelMap idCardIsValid(String idCard) {
         return success(new ModelMap("isValid", userService.idCardIsValid(idCard)));
     }
+
+    /**
+     * 根据企业uu号查询企业下所有用户信息
+     * @author wangmh
+     * @date 2018/1/26 14:43
+     * @param page 当前页数 (0开始)
+     * @param size 每页大小
+     * @param spaceUU 企业uu号
+     * @return org.springframework.data.domain.Page, content 为用户信息集合
+     */
+    @RequestMapping(value = "/find/member", method = RequestMethod.GET)
+    public ModelMap findMember(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "20") int size, Long spaceUU) {
+        return success(userService.findMemberBySpaceUU(page, size, spaceUU));
+    }
+
+    /**
+     * 根据用户uu号查询用户信息
+     * @author wangmh
+     * @date 2018/1/26 14:46
+     * @param userUU 用户uu号
+     * @return 用户信息
+     */
+    @RequestMapping(value = "/info", method = RequestMethod.GET)
+    public ModelMap findOne(@RequestParam Long userUU) {
+        return success(userService.findOne(userUU));
+    }
 }

+ 34 - 1
sso-server/src/main/java/com/uas/sso/controller/UserspaceManageController.java → sso-server/src/main/java/com/uas/sso/controller/UserspaceManagerController.java

@@ -1,6 +1,7 @@
 package com.uas.sso.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.uas.sso.entity.Userspace;
 import com.uas.sso.service.ApplyUserSpaceService;
 import com.uas.sso.service.UserspaceService;
 import com.uas.sso.util.FastjsonUtils;
@@ -20,7 +21,7 @@ import org.springframework.web.multipart.MultipartFile;
  */
 @RestController
 @RequestMapping("/api/userspace")
-public class UserspaceManageController extends BaseController {
+public class UserspaceManagerController extends BaseController {
 
     @Autowired
     private UserspaceService userspaceService;
@@ -122,4 +123,36 @@ public class UserspaceManageController extends BaseController {
     public ModelMap applyCount(Long spaceUU) {
         return success(applyUserSpaceService.applyCount(spaceUU));
     }
+
+    /**
+     * 企业解除绑定应用
+     * @param spaceUU 企业uu号
+     * @param appId 应用id
+     * @return
+     */
+    @RequestMapping(params = "_operate=unbind", method = RequestMethod.POST)
+    public ModelMap unbindApp(Long spaceUU, String appId) {
+        if (StringUtils.isEmpty(spaceUU) || StringUtils.isEmpty(appId)) {
+            return error("参数错误");
+        }
+
+        userspaceService.unbindApp(spaceUU, appId);
+        return success();
+    }
+
+    /**
+     * 企业开通应用
+     * @param spaceUU 企业uu号
+     * @param appId 应用id
+     * @return
+     */
+    @RequestMapping(params = "_operate=bind", method = RequestMethod.POST)
+    public ModelMap bindApp(Long spaceUU, String appId) {
+        if (StringUtils.isEmpty(spaceUU) || StringUtils.isEmpty(appId)) {
+            return error("参数错误");
+        }
+
+        userspaceService.bindApp(spaceUU, appId);
+        return success();
+    }
 }

+ 7 - 0
sso-server/src/main/java/com/uas/sso/dao/AppDao.java

@@ -21,4 +21,11 @@ public interface AppDao extends JpaRepository<App, String>, JpaSpecificationExec
      */
     @Query("select t.uid from App t")
     List<String> findUid();
+
+    /**
+     * 查询默认开通的应用
+     * @return
+     */
+    @Query("select t from App t where t.defaultUse = 1")
+    List<App> findByDefaultUse();
 }

+ 22 - 6
sso-server/src/main/java/com/uas/sso/entity/App.java

@@ -93,13 +93,13 @@ public class App implements Serializable {
      * 绑定企业数
      */
     @Column(name = "us_count")
-    private String usCount;
+    private Integer usCount;
 
     /**
      * 是否默认开通
      */
     @Column(name = "default_use")
-    private String defaultUse;
+    private Short defaultUse;
 
     /**
      * 是否支持个人账号
@@ -195,19 +195,19 @@ public class App implements Serializable {
         this.publicKey = publicKey;
     }
 
-    public String getUsCount() {
+    public Integer getUsCount() {
         return usCount;
     }
 
-    public void setUsCount(String usCount) {
+    public void setUsCount(Integer usCount) {
         this.usCount = usCount;
     }
 
-    public String getDefaultUse() {
+    public Short getDefaultUse() {
         return defaultUse;
     }
 
-    public void setDefaultUse(String defaultUse) {
+    public void setDefaultUse(Short defaultUse) {
         this.defaultUse = defaultUse;
     }
 
@@ -218,4 +218,20 @@ public class App implements Serializable {
     public void setPersonalEnable(int personalEnable) {
         this.personalEnable = personalEnable;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        App app = (App) o;
+
+        return uid.equals(app.uid);
+
+    }
+
+    @Override
+    public int hashCode() {
+        return uid.hashCode();
+    }
 }

+ 16 - 0
sso-server/src/main/java/com/uas/sso/entity/Userspace.java

@@ -453,4 +453,20 @@ public class Userspace implements Serializable {
         userSpaceView.setTelephone(this.getTelephone());
         return userSpaceView;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        Userspace userspace = (Userspace) o;
+
+        return spaceUU.equals(userspace.spaceUU);
+
+    }
+
+    @Override
+    public int hashCode() {
+        return spaceUU.hashCode();
+    }
 }

+ 6 - 0
sso-server/src/main/java/com/uas/sso/service/AppService.java

@@ -39,4 +39,10 @@ public interface AppService {
      * @return
      */
     List<String> findUid();
+
+    /**
+     * 查询所有默认开通的应用
+     * @return
+     */
+    List<App> findDefaultUseApp();
 }

+ 14 - 0
sso-server/src/main/java/com/uas/sso/service/UserspaceService.java

@@ -96,4 +96,18 @@ public interface UserspaceService {
      * @return
      */
     Set<Userspace> findBySpaceName(String spaceName);
+
+    /**
+     * 企业解除绑定应用
+     * @param spaceUU 企业uu号
+     * @param appId 应用id
+     */
+    void unbindApp(Long spaceUU, String appId);
+
+    /**
+     * 企业开通应用
+     * @param spaceUU 企业uu号
+     * @param appId 应用id
+     */
+    void bindApp(Long spaceUU, String appId);
 }

+ 6 - 0
sso-server/src/main/java/com/uas/sso/service/impl/AppServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.sso.service.impl;
 
+import com.uas.sso.core.Const;
 import com.uas.sso.dao.AppDao;
 import com.uas.sso.entity.App;
 import com.uas.sso.service.AppService;
@@ -39,4 +40,9 @@ public class AppServiceImpl implements AppService {
     public List<String> findUid() {
         return appDao.findUid();
     }
+
+    @Override
+    public List<App> findDefaultUseApp() {
+        return appDao.findByDefaultUse();
+    }
 }

+ 5 - 5
sso-server/src/main/java/com/uas/sso/service/impl/UserServiceImpl.java

@@ -15,10 +15,7 @@ import com.uas.sso.exception.VisibleError;
 import com.uas.sso.logging.LoggerManager;
 import com.uas.sso.logging.SyncBufferedLogger;
 import com.uas.sso.logging.UserBufferedLogger;
-import com.uas.sso.service.AppService;
-import com.uas.sso.service.UserService;
-import com.uas.sso.service.UserValidService;
-import com.uas.sso.service.UserspaceService;
+import com.uas.sso.service.*;
 import com.uas.sso.util.AccountTypeUtils;
 import com.uas.sso.util.ExecuteUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -62,6 +59,9 @@ public class UserServiceImpl implements UserService {
     @Autowired
     private AppService appService;
 
+    @Autowired
+    private UserQuestionService userQuestionService;
+
     private UserBufferedLogger userLog = LoggerManager.getLogger(UserBufferedLogger.class);
 
     private SyncBufferedLogger syncLog = LoggerManager.getLogger(SyncBufferedLogger.class);
@@ -371,7 +371,7 @@ public class UserServiceImpl implements UserService {
 
         // 保存并添加日志
         user = userDao.save(user);
-        userLog.info(user, Type.UPDATE_QUESTION.getValue());
+        userLog.info(user, Type.UPDATE_QUESTION.getValue(), JSON.toJSONString(user.getQuestions()));
     }
 
     /**

+ 41 - 0
sso-server/src/main/java/com/uas/sso/service/impl/UserspaceServiceImpl.java

@@ -98,6 +98,7 @@ public class UserspaceServiceImpl implements UserspaceService {
         userspace.setRegisterDate(new Timestamp(System.currentTimeMillis()));
 
         // 注册企业
+        userspace.setApps(appService.findDefaultUseApp());
         userspace = userspaceDao.save(userspace);
 
         // 开通应用
@@ -238,4 +239,44 @@ public class UserspaceServiceImpl implements UserspaceService {
         userspaceDao.findBySpaceName(spaceName);
         return null;
     }
+
+    @Override
+    public void unbindApp(Long spaceUU, String appId) {
+        // 获取企业信息和应用信息,并校验
+        Userspace userspace = userspaceDao.findOne(spaceUU);
+        if (userspace == null) {
+            throw new VisibleError("该企业不存在");
+        }
+        App app = appService.findOne(appId);
+        if (app == null) {
+            throw new VisibleError("该应用不存在");
+        }
+
+        // 解除绑定
+        if (userspace.getApps().contains(app)) {
+            userspace.getApps().remove(app);
+        }
+        userspaceDao.save(userspace);
+
+    }
+
+    @Override
+    public void bindApp(Long spaceUU, String appId) {
+        // 获取企业信息和应用信息,并校验
+        Userspace userspace = userspaceDao.findOne(spaceUU);
+        if (userspace == null) {
+            throw new VisibleError("该企业不存在");
+        }
+        App app = appService.findOne(appId);
+        if (app == null) {
+            throw new VisibleError("该应用不存在");
+        }
+
+        // 开通应用
+        if (userspace.getApps().contains(app)) {
+            throw new VisibleError(String.format("该企业已开通%s应用", app.getUid()));
+        }
+        userspace.getApps().add(app);
+        userspaceDao.save(userspace);
+    }
 }