Forráskód Böngészése

征信认证功能

liuam 7 éve
szülő
commit
d66a678f5f

+ 54 - 0
src/main/java/com/uas/credit/config/AuthorizeInterceptor.java

@@ -0,0 +1,54 @@
+package com.uas.credit.config;
+
+import com.uas.credit.dao.UserDao;
+import com.uas.credit.model.User;
+import com.uas.credit.util.ContextUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
+
+/**
+ * @author liuam
+ * @since 2018/6/25 0025 下午 18:27
+ */
+public class AuthorizeInterceptor extends HandlerInterceptorAdapter {
+
+    private UserDao userDao;
+    {
+        userDao = ContextUtils.getBean(UserDao.class);
+    }
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        String userUUString = request.getParameter("userUU");
+        String enUUString = request.getParameter("enUU");
+        String password = request.getParameter("password");
+        // 判断 userUUString、enUUString、passwordString 是否为数字
+        if (!StringUtils.isNumeric(userUUString) || !StringUtils.isNumeric(enUUString)) {
+            PrintWriter writer = response.getWriter();
+            writer.print("userUU 和 enUU 只能为数字 ");
+            writer.flush();
+            return false;
+        }
+        if (password == null) {
+            PrintWriter writer = response.getWriter();
+            writer.print("password 不能为空");
+            writer.flush();
+            return false;
+        }
+        long userUU = Long.parseLong(userUUString);
+        long enUU = Long.parseLong(enUUString);
+        User user = userDao.findByUserUUAndEnUUAndPassword(userUU, enUU, password);
+        if (user == null) {
+            PrintWriter writer = response.getWriter();
+            writer.print("用户不存在!");
+            writer.flush();
+            return false;
+        }
+        return true;
+    }
+
+}

+ 19 - 0
src/main/java/com/uas/credit/config/InterceptorConfig.java

@@ -0,0 +1,19 @@
+package com.uas.credit.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * @author liuam
+ * @since 2018/6/25 0025 下午 18:56
+ */
+@Configuration
+public class InterceptorConfig extends WebMvcConfigurerAdapter {
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        registry.addInterceptor(new AuthorizeInterceptor()).addPathPatterns("/**");
+        super.addInterceptors(registry);
+    }
+}

+ 5 - 3
src/main/java/com/uas/credit/controller/ErpQueryController.java

@@ -3,9 +3,9 @@ package com.uas.credit.controller;
 import com.uas.credit.model.EnterpriseQuery;
 import com.uas.credit.model.PersonQuery;
 import com.uas.credit.service.*;
+import com.uas.credit.util.FlexJsonUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
-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;
@@ -40,7 +40,8 @@ public class ErpQueryController {
      * ERP对企业进行查询
      */
     @RequestMapping(value = "/queryEn", method = RequestMethod.POST)
-    public ModelMap queryEn(@RequestBody EnterpriseQuery erpQuery) {
+    public ModelMap queryEn(String data) {
+        EnterpriseQuery erpQuery = FlexJsonUtils.fromJson(data, EnterpriseQuery.class);
         ModelMap modelMap = new ModelMap();
         if (erpQuery != null) {
             // 查询企业债务信息
@@ -63,7 +64,8 @@ public class ErpQueryController {
      * erp对个人进行查询
      */
     @RequestMapping(value = "/queryPe", method = RequestMethod.POST)
-    public ModelMap queryPerson(@RequestBody PersonQuery erpQuery) {
+    public ModelMap queryPerson(String data) {
+        PersonQuery erpQuery = FlexJsonUtils.fromJson(data, PersonQuery.class);
         ModelMap modelMap = new ModelMap();
         if (erpQuery != null) {
             // 查询个人身份信息

+ 16 - 0
src/main/java/com/uas/credit/dao/UserDao.java

@@ -0,0 +1,16 @@
+package com.uas.credit.dao;
+
+import com.uas.credit.model.User;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author liuam
+ * @since 2018/6/25 0025 下午 18:48
+ */
+@Repository
+public interface UserDao extends JpaRepository<User, Long> {
+
+    User findByUserUUAndEnUUAndPassword(Long userUU, Long enUU, String password);
+
+}

+ 71 - 0
src/main/java/com/uas/credit/model/User.java

@@ -0,0 +1,71 @@
+package com.uas.credit.model;
+
+import javax.persistence.*;
+
+/**
+ * 用户信息,认证用户
+ * @author liuam
+ * @since 2018/6/25 0025 下午 18:18
+ */
+@Entity
+@Table(name = "user")
+public class User {
+
+    /**
+     * user id
+     */
+    @Id
+    @Column(name = "id")
+    @GeneratedValue
+    private Long id;
+
+    /**
+     * erp userUU
+     */
+    @Column(name = "userUU")
+    private Long userUU;
+
+    /**
+     * erp enUU
+     */
+    @Column(name = "enUU")
+    private Long enUU;
+
+    /**
+     * erp password
+     */
+    @Column(name = "password")
+    private String password;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getUserUU() {
+        return userUU;
+    }
+
+    public void setUserUU(Long userUU) {
+        this.userUU = userUU;
+    }
+
+    public Long getEnUU() {
+        return enUU;
+    }
+
+    public void setEnUU(Long enUU) {
+        this.enUU = enUU;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+}