Quellcode durchsuchen

日常获取用户信息和企业信息

ZhangWenQiang vor 6 Jahren
Ursprung
Commit
fcfa07ec9a

+ 33 - 0
happy-boot-module-hppay/src/main/java/org/jeecg/modules/api/sys/LoginAppControllerAPI.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.api.sys;
 
+import com.alibaba.fastjson.JSONObject;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -157,4 +158,36 @@ public class LoginAppControllerAPI extends BaseAppController {
         return view;
     }
 
+    /**
+     * 获取用户信息
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @ApiOperation(notes = "getUserInfo", httpMethod = "GET", value = "获取用户信息")
+    @GetMapping(value = "/getUserInfo")
+    public ModelAndView getUserInfo(HttpServletRequest request, HttpServletResponse response) {
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.setHeader("Access-Control-Allow-Method", "POST,GET");
+        Map<String, Object> obj = null;
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        Map<String, String> requestMap = findRequestMap(request);
+        try {
+            returnMap = userService.getUserInfo(requestMap);
+            if ("1004".equals(returnMap.get("success"))) {
+                obj = errorResult(ErrorCode.code_2008, "用户信息验证失败");
+            } else {
+                obj = successResult(ErrorCode.code_1000, "", returnMap);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            obj = errorResult(ErrorCode.code_2006, "获取数据失败");
+            logError(request, e.getMessage(), e);
+        }
+
+        ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
+        return view;
+    }
+
 }

+ 2 - 0
happy-boot-module-hppay/src/main/java/org/jeecg/modules/user/service/IUserService.java

@@ -32,4 +32,6 @@ public interface IUserService extends IService<User> {
     Map<String,Object> userAudit(HttpServletRequest request);
 
     boolean updateByUserId(User user);
+
+    Map<String,Object> getUserInfo(Map<String,String> requestMap);
 }

+ 31 - 0
happy-boot-module-hppay/src/main/java/org/jeecg/modules/user/service/impl/UserServiceImpl.java

@@ -12,6 +12,7 @@ import org.jeecg.common.util.OtherException;
 import org.jeecg.common.util.RedisUtil;
 import org.jeecg.common.util.StringUtils;
 import org.jeecg.modules.company.entity.CompanyAuthentication;
+import org.jeecg.modules.company.mapper.CompanyAuthenticationMapper;
 import org.jeecg.modules.message.entity.Message;
 import org.jeecg.modules.message.service.IMessageService;
 import org.jeecg.modules.user.entity.User;
@@ -47,6 +48,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     public static final String USERFILES_BASE_URL = "uploadfiles";
     @Resource
     private IMessageService messageService;
+    @Resource
+    private CompanyAuthenticationMapper companyAuthenticationMapper;
 
 
     @Override
@@ -261,6 +264,34 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
         return result;
     }
 
+    /**
+     * 获取用户信息
+     *
+     * @param requestMap
+     * @return
+     */
+    @Override
+    public Map<String, Object> getUserInfo(Map<String, String> requestMap) {
+        Map<String, Object> returnMap = new HashMap<String, Object>();
+        String userId = requestMap.get("user_id");
+        String userToken = requestMap.get("user_token");
+        //验证用户合法性
+        if (TokenUtil.validateToken(userId, userToken)) {
+            User user = this.getById(userId);
+            CompanyAuthentication companyAuthentication = new CompanyAuthentication();
+            companyAuthentication.setUserId(Integer.parseInt(userId));
+            List<CompanyAuthentication> companyAuthenticationList = companyAuthenticationMapper.getEnterpriseList(companyAuthentication);
+            if (companyAuthenticationList.size() > 0) {
+                companyAuthentication = companyAuthenticationList.get(0);
+            }
+            returnMap.put("userInfo", user);
+            returnMap.put("companyAuthentication", companyAuthentication);
+        } else {
+            returnMap.put("success", "1004");
+        }
+        return returnMap;
+    }
+
     @Override
     public User getByPhone(String phone) {
         User user = userMapper.getByPhone(phone);