|
|
@@ -0,0 +1,93 @@
|
|
|
+package com.usoft.sso.rest.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
+import com.sso.rest.utils.common.RespUtil;
|
|
|
+import com.sso.rest.utils.common.TypeChangeUtil;
|
|
|
+import com.sso.rest.utils.exception.SSORuntimeException;
|
|
|
+import com.usoft.protobuf.utils.ProtoBufUtil;
|
|
|
+import com.usoft.sso.rest.api.entity.RespHeader;
|
|
|
+import com.usoft.sso.rest.api.entity.UserInfo;
|
|
|
+import com.usoft.sso.rest.api.protobuf.BindUserInfoReq;
|
|
|
+import com.usoft.sso.rest.api.protobuf.BindUserInfoResp;
|
|
|
+import com.usoft.sso.rest.api.protobuf.SaveUserInfoReq;
|
|
|
+import com.usoft.sso.rest.api.protobuf.SaveUserInfoResp;
|
|
|
+import com.usoft.sso.rest.domain.SSODomain;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: huyy
|
|
|
+ * @date: 2018/8/21 16:32
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+public class UserController {
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SSODomain ssoDomain;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户中心保存用户信息接口-restAPI api/public/user, method:post, type:kv
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/api/public/user")
|
|
|
+ public String saveUserInfo(@RequestBody String json) throws UnsupportedEncodingException, InvalidProtocolBufferException {
|
|
|
+ //账户中心传过来的数据比较特别,需要特殊解码
|
|
|
+ JSONObject jsonObject = TypeChangeUtil.stringToJSONObj(json);
|
|
|
+ UserInfo.Builder userInfo = ProtoBufUtil.toProtoBuf(UserInfo.newBuilder(), jsonObject.toJSONString());
|
|
|
+ SaveUserInfoReq.Builder req = SaveUserInfoReq.newBuilder();
|
|
|
+ SaveUserInfoResp.Builder resp = SaveUserInfoResp.newBuilder();
|
|
|
+ req.setUserInfo(userInfo);
|
|
|
+ try {
|
|
|
+ resp = ssoDomain.save(req.build());
|
|
|
+ resp.setRespHeader(RespHeader.newBuilder());
|
|
|
+ LOGGER.info("保存用户信息[UserController.saveUserInfo]正常,参数:{}", ProtoBufUtil.toJSONHasTryCatch(req.build()));
|
|
|
+ } catch (SSORuntimeException e) {
|
|
|
+ LOGGER.warn("保存用户信息[UserController.saveUserInfo]告警,参数:{}", json, e);
|
|
|
+ RespHeader respHeader = RespUtil.getRespHeader(e.getErrorCode(), e.getErrorMessage());
|
|
|
+ resp.setRespHeader(respHeader);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("保存用户信息[UserController.saveUserInfo]异常,参数:{}", json, e);
|
|
|
+ RespHeader respHeader = RespUtil.getRespHeader(SSORuntimeException.ERROR_CODE_100, e.getMessage());
|
|
|
+ resp.setRespHeader(respHeader);
|
|
|
+ }
|
|
|
+ return ProtoBufUtil.toJSONHasTryCatch(resp.build());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户中心用户 绑定/解绑-restAPI /api/public/user/bindUser, method:post, type:json
|
|
|
+ *
|
|
|
+ * @param json
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @PostMapping(value = "/api/public/user/bindUser")
|
|
|
+ public String bindUserInfo(@RequestBody String json) throws UnsupportedEncodingException {
|
|
|
+ //账户中心传过来的数据比较特别,需要特殊解码
|
|
|
+ JSONObject object = TypeChangeUtil.stringToJSONObj(json);
|
|
|
+ BindUserInfoResp.Builder resp = BindUserInfoResp.newBuilder();
|
|
|
+ try {
|
|
|
+ BindUserInfoReq.Builder req = ProtoBufUtil.toProtoBuf(BindUserInfoReq.newBuilder(), object);
|
|
|
+ resp = ssoDomain.bindUser(req.build());
|
|
|
+ resp.setRespHeader(RespHeader.newBuilder());
|
|
|
+ LOGGER.info("账户中心用户 绑定/解绑[UserController.bindUserInfo]正常,参数:{}", ProtoBufUtil.toJSONHasTryCatch(req.build()));
|
|
|
+ } catch (SSORuntimeException e) {
|
|
|
+ LOGGER.warn("账户中心用户 绑定/解绑[UserController.bindUserInfo]告警,参数:{}", json, e);
|
|
|
+ RespHeader respHeader = RespUtil.getRespHeader(e.getErrorCode(), e.getErrorMessage());
|
|
|
+ resp.setRespHeader(respHeader);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("账户中心用户 绑定/解绑[UserController.bindUserInfo]异常,参数:{}", json, e);
|
|
|
+ RespHeader respHeader = RespUtil.getRespHeader(SSORuntimeException.ERROR_CODE_100, e.getMessage());
|
|
|
+ resp.setRespHeader(respHeader);
|
|
|
+ }
|
|
|
+ return ProtoBufUtil.toJSONHasTryCatch(resp.build());
|
|
|
+ }
|
|
|
+}
|