Quellcode durchsuchen

Merge remote-tracking branch 'origin/master'

eric vor 2 Jahren
Ursprung
Commit
787fb4d1a7

+ 70 - 11
src/main/java/com/finikes/oc/base/controller/PassportController.java

@@ -3,19 +3,24 @@ package com.finikes.oc.base.controller;
 import com.finikes.oc.BaseDTO;
 import com.finikes.oc.BizException;
 import com.finikes.oc.base.dao.PassportDAO;
+import com.finikes.oc.base.dto.PassportHouseInfoResponseDTO;
 import com.finikes.oc.base.dto.RegisterResponseDTO;
 import com.finikes.oc.base.entity.Passport;
+import com.finikes.oc.estate.dao.EstateUnitDAO;
+import com.finikes.oc.estate.dao.HouseDAO;
+import com.finikes.oc.estate.entity.EstateUnit;
+import com.finikes.oc.estate.entity.House;
+import com.finikes.oc.management.dao.HouseRelationDAO;
+import com.finikes.oc.management.entity.HouseRelation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-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.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 @RequestMapping("/passport")
@@ -25,6 +30,15 @@ public class PassportController {
     @Autowired
     private PassportDAO passportDAO;
 
+    @Autowired
+    private HouseRelationDAO houseRelationDAO;
+
+    @Autowired
+    private HouseDAO houseDAO;
+
+    @Autowired
+    private EstateUnitDAO estateUnitDAO;
+
     @ResponseBody
     @RequestMapping(value = "/", method = RequestMethod.PUT)
     public BaseDTO register(@RequestBody Map<String, Object> map) {
@@ -42,7 +56,13 @@ public class PassportController {
         long veriCodeDeadline = now + 60 * 1000 * 5;
         int id = 0;
         if (tmp == null) {
-            id = passportDAO.insert(mobile, password, veriCode, veriCodeDeadline);
+            Passport p = new Passport();
+            p.setMobile(mobile);
+            p.setPassword(password);
+            p.setVeriCode(veriCode);
+            p.setVeriCodeDeadline(veriCodeDeadline);
+            passportDAO.insert(p);
+            id = p.getId();
         } else {
             passportDAO.updateVeriCode(mobile, veriCode, veriCodeDeadline);
             id = tmp.getId();
@@ -60,11 +80,8 @@ public class PassportController {
         String mobile = (String) map.get("mobile");
         String securityCode = (String) map.get("securityCode");
         String type = (String) map.get("type");
-        System.out.println(mobile + " ++++++");
         Passport tmp = passportDAO.findByMobile(mobile);
-        System.out.println(tmp);
         if (tmp == null || tmp.getState() != 1) {
-            System.out.println("00000000");
             return new BaseDTO(new BizException("101", "登录失败"));
         }
 
@@ -74,18 +91,60 @@ public class PassportController {
                 session.setAttribute("PASSPORT", tmp);
                 return new BaseDTO();
             } else {
-                System.out.println("1111111");
                 return new BaseDTO(new BizException("101", "登录失败"));
             }
         }
 
+
         if (securityCode.equals(tmp.getVeriCode()) && (System.currentTimeMillis() + 6000 * 5) <= tmp.getVeriCodeDeadline()) {
             HttpSession session = request.getSession();
             session.setAttribute("PASSPORT", tmp);
             return new BaseDTO();
         } else {
-            System.out.println("2222222222");
             return new BaseDTO(new BizException("101", "登录失败"));
         }
     }
+
+    @ResponseBody
+    @RequestMapping(value = "/", method = RequestMethod.GET)
+    public BaseDTO getPassportAndHouse(@RequestParam("id") String id) {
+        int _id = Integer.parseInt(id);
+        Passport passport = passportDAO.findById(_id);
+        if (passport == null || passport.getState() != 1) {
+            // 不能查看
+            return new BaseDTO("300", "没有用户");
+        }
+
+        PassportHouseInfoResponseDTO dto = new PassportHouseInfoResponseDTO();
+        dto.setMobile(passport.getMobile());
+        HouseRelation relation = houseRelationDAO.findByPassport(_id);
+        if (relation != null && relation.getState() == 1) {
+            House house = houseDAO.findById(relation.getHouseId());
+            String houseAddress = getHouseFullName(house);
+            dto.setArea(String.valueOf(house.getArea()));
+            dto.setCertificateNo(relation.getCertificateNo());
+            dto.setHouseAddress(houseAddress);
+            dto.setFunction(house.getFunction());
+            dto.setCertificateUrl(relation.getCertificateUrl());
+        }
+
+        return new BaseDTO().setContent(dto);
+    }
+
+    private String getHouseFullName(House house) {
+        StringBuilder builder = new StringBuilder(house.getName());
+        List<String> fullName = new ArrayList<>();
+        EstateUnit eu = estateUnitDAO.findById(house.getUnitId());
+        fullName.add(eu.getName() + eu.getExp());
+        while (eu.getId() != 1) {
+            eu = estateUnitDAO.findById(eu.getParentId());
+            fullName.add(eu.getName() + eu.getExp());
+        }
+
+        for (String name : fullName) {
+            builder = new StringBuilder(name).append(builder);
+        }
+
+        return builder.toString();
+    }
 }

+ 8 - 2
src/main/java/com/finikes/oc/base/controller/VerificationCodeController.java

@@ -32,7 +32,11 @@ public class VerificationCodeController {
         long veriCodeDeadline = now + 60 * 1000 * 5;
         int id = 0;
         if (tmp == null) {
-            id = passportDAO.insert(mobile, null, veriCode, veriCodeDeadline);
+            Passport p = new Passport();
+            p.setMobile(mobile);
+            p.setVeriCode(veriCode);
+            p.setVeriCodeDeadline(veriCodeDeadline);
+            id = passportDAO.insert(p);
         } else {
             passportDAO.updateVeriCode(mobile, veriCode, veriCodeDeadline);
             id = tmp.getId();
@@ -58,7 +62,9 @@ public class VerificationCodeController {
         String veriCode = tmp.getVeriCode();
         long now = System.currentTimeMillis();
         long veriCodeDeadline = now + 60 * 1000 * 5;
-        if (verificationCode.equals(veriCode) && veriCodeDeadline <= tmp.getVeriCodeDeadline()) {
+        System.out.println(veriCode);
+        System.out.println(verificationCode);
+        if (verificationCode.equals(veriCode) && veriCodeDeadline > tmp.getVeriCodeDeadline()) {
             passportDAO.updateState(mobile, 1, now);
             HttpSession session = request.getSession();
             session.setAttribute("PASSPORT", tmp);

+ 3 - 1
src/main/java/com/finikes/oc/base/dao/PassportDAO.java

@@ -8,9 +8,11 @@ import org.apache.ibatis.annotations.Param;
 public interface PassportDAO {
     Passport findByMobile(String mobile);
 
-    int insert(@Param("mobile") String mobile, @Param("password") String password, @Param("veriCode") String veriCode, @Param("veriCodeDeadline") long veriCodeDeadline);
+    int insert(Passport passport);
 
     void updateVeriCode(@Param("mobile") String mobile, @Param("veriCode") String veriCode, @Param("veriCodeDeadline") long veriCodeDeadline);
 
     void updateState(@Param("mobile") String mobile, @Param("state") int state, @Param("createTime") long createTime);
+
+    Passport findById(int id);
 }

+ 58 - 0
src/main/java/com/finikes/oc/base/dto/PassportHouseInfoResponseDTO.java

@@ -0,0 +1,58 @@
+package com.finikes.oc.base.dto;
+
+public class PassportHouseInfoResponseDTO {
+    private String mobile;
+    private String certificateNo;
+    private String certificateUrl;
+    private String houseAddress;
+    private String area;
+    private String function;
+
+    public String getMobile() {
+        return mobile;
+    }
+
+    public void setMobile(String mobile) {
+        this.mobile = mobile;
+    }
+
+    public String getCertificateNo() {
+        return certificateNo;
+    }
+
+    public void setCertificateNo(String certificateNo) {
+        this.certificateNo = certificateNo;
+    }
+
+    public String getCertificateUrl() {
+        return certificateUrl;
+    }
+
+    public void setCertificateUrl(String certificateUrl) {
+        this.certificateUrl = certificateUrl;
+    }
+
+    public String getHouseAddress() {
+        return houseAddress;
+    }
+
+    public void setHouseAddress(String houseAddress) {
+        this.houseAddress = houseAddress;
+    }
+
+    public String getArea() {
+        return area;
+    }
+
+    public void setArea(String area) {
+        this.area = area;
+    }
+
+    public String getFunction() {
+        return function;
+    }
+
+    public void setFunction(String function) {
+        this.function = function;
+    }
+}

+ 1 - 1
src/main/java/com/finikes/oc/estate/controller/EstateController.java

@@ -27,7 +27,7 @@ public class EstateController {
     @ResponseBody
     @RequestMapping(value = "/", method = RequestMethod.GET)
     public BaseDTO getEstatesByParent(@RequestParam String estateUnitId) {
-        EstateUnit eu = estateUnitDAO.findById(estateUnitId);
+        EstateUnit eu = estateUnitDAO.findById(Integer.parseInt(estateUnitId));
         if(eu.isLeaf()) {
             List<House> houses = houseDAO.findByUnitId(estateUnitId);
             EstatesResponseDTO dto = new EstatesResponseDTO();

+ 1 - 1
src/main/java/com/finikes/oc/estate/dao/EstateUnitDAO.java

@@ -7,7 +7,7 @@ import java.util.List;
 
 @Mapper
 public interface EstateUnitDAO {
-    EstateUnit findById(String id);
+    EstateUnit findById(int id);
 
     List<EstateUnit> findByParentId(String parentId);
 }

+ 2 - 0
src/main/java/com/finikes/oc/estate/dao/HouseDAO.java

@@ -8,4 +8,6 @@ import java.util.List;
 @Mapper
 public interface HouseDAO {
     List<House> findByUnitId(String estateUnitId);
+
+    House findById(int houseId);
 }

+ 72 - 0
src/main/java/com/finikes/oc/filter/AuthFilter.java

@@ -0,0 +1,72 @@
+package com.finikes.oc.filter;
+
+import com.finikes.oc.Passports;
+import com.finikes.oc.base.entity.Passport;
+import com.finikes.oc.management.dao.AuthorityDAO;
+import com.finikes.oc.management.dao.ManagerDAO;
+import com.finikes.oc.management.dao.ResourceDAO;
+import com.finikes.oc.management.entity.Authority;
+import com.finikes.oc.management.entity.Manager;
+import com.finikes.oc.management.entity.Resource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+//@Component
+public class AuthFilter implements Filter {
+    @Autowired
+    private ResourceDAO resourceDAO;
+
+    @Autowired
+    private ManagerDAO managerDAO;
+
+    @Autowired
+    private AuthorityDAO authorityDAO;
+
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
+        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+        Passport passport = Passports.getPassport(httpServletRequest);
+        String url = httpServletRequest.getRequestURI();
+        System.out.println("AAAA " + url);
+        String httpMethod = httpServletRequest.getMethod();
+        System.out.println("BBBB " + httpMethod);
+        if (!pass(passport, url, httpMethod)) {
+            response.setCharacterEncoding("UTF-8");
+            response.setContentType("application/json; charset=utf-8");
+            response.getWriter().print("{\"code\":\"200\", \"message\":\"没有权限\"}");
+            return;
+        }
+        chain.doFilter(request, httpServletResponse);
+    }
+
+    private boolean pass(Passport passport, String url, String httpMethod) {
+        if (passport == null) {
+            return false;
+        }
+
+        Resource resource = resourceDAO.findByUrlAndMethod(url, httpMethod);
+        if (resource == null) {
+            return false;
+        }
+
+        Manager manager = managerDAO.findByPassport(passport.getId());
+        if (manager == null) {
+            return false;
+        }
+
+        int roleId = manager.getRoleId();
+        int resourceId = resource.getId();
+        Authority authority = authorityDAO.findByRoleAndResource(roleId, resourceId);
+        if (authority == null) {
+            return false;
+        }
+
+        return authority.isState();
+    }
+}

+ 10 - 0
src/main/java/com/finikes/oc/management/dao/AuthorityDAO.java

@@ -0,0 +1,10 @@
+package com.finikes.oc.management.dao;
+
+import com.finikes.oc.management.entity.Authority;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface AuthorityDAO {
+    Authority findByRoleAndResource(@Param("roleId") int roleId, @Param("resourceId") int resourceId);
+}

+ 9 - 0
src/main/java/com/finikes/oc/management/dao/ManagerDAO.java

@@ -0,0 +1,9 @@
+package com.finikes.oc.management.dao;
+
+import com.finikes.oc.management.entity.Manager;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ManagerDAO {
+    Manager findByPassport(int id);
+}

+ 10 - 0
src/main/java/com/finikes/oc/management/dao/ResourceDAO.java

@@ -0,0 +1,10 @@
+package com.finikes.oc.management.dao;
+
+import com.finikes.oc.management.entity.Resource;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+@Mapper
+public interface ResourceDAO {
+    Resource findByUrlAndMethod(@Param("url") String url, @Param("httpMethod") String httpMethod);
+}

+ 45 - 0
src/main/java/com/finikes/oc/vote/controller/OptionController.java

@@ -0,0 +1,45 @@
+package com.finikes.oc.vote.controller;
+
+import com.finikes.oc.BaseDTO;
+import com.finikes.oc.BizException;
+import com.finikes.oc.base.dao.PassportDAO;
+import com.finikes.oc.base.dto.PassportHouseInfoResponseDTO;
+import com.finikes.oc.base.dto.RegisterResponseDTO;
+import com.finikes.oc.base.entity.Passport;
+import com.finikes.oc.estate.dao.EstateUnitDAO;
+import com.finikes.oc.estate.dao.HouseDAO;
+import com.finikes.oc.estate.entity.EstateUnit;
+import com.finikes.oc.estate.entity.House;
+import com.finikes.oc.management.dao.HouseRelationDAO;
+import com.finikes.oc.management.entity.HouseRelation;
+import com.finikes.oc.vote.dao.OptionDao;
+import com.finikes.oc.vote.entity.Option;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@RequestMapping("/option")
+@ResponseBody
+@Controller
+public class OptionController {
+    @Autowired
+    private OptionDao optionDao;
+
+    @ResponseBody
+    @RequestMapping(value = "/s", method = RequestMethod.GET)
+    public BaseDTO getPassportAndHouse(@RequestParam("voteId") String voteId) {
+        int _voteId = Integer.parseInt(voteId);
+        List<Integer> voteIds = new ArrayList<>();
+        voteIds.add(_voteId);
+        List<Option> options = optionDao.selectByVoteIds(voteIds);
+
+        return new BaseDTO().setContent(options);
+    }
+}

+ 2 - 0
src/main/resources/application.yml

@@ -7,6 +7,8 @@ spring:
     username: root
     password: 6bbd00bb4777fe30
     driver-class-name: com.mysql.cj.jdbc.Driver
+    hikari:
+      max-lifetime: 3000000
   main:
     allow-circular-references: true
 mybatis:

+ 11 - 0
src/main/resources/mapper/AuthorityMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.finikes.oc.management.dao.AuthorityDAO">
+
+    <select id="findByRoleAndResource" resultType="com.finikes.oc.management.entity.Authority">
+        SELECT roleId, resourceId, state
+        FROM t_authority
+        WHERE roleId = #{roleId} AND resourceId = #{resourceId}
+    </select>
+
+</mapper>

+ 4 - 4
src/main/resources/mapper/EstateUnitMapper.xml

@@ -3,14 +3,14 @@
 <mapper namespace="com.finikes.oc.estate.dao.EstateUnitDAO">
 
     <select id="findById" resultType="com.finikes.oc.estate.entity.EstateUnit">
-        SELECT id, unitId, name, area, function
-        FROM t_house
+        SELECT id, parentId, name, exp, leaf
+        FROM t_estate_unit
         WHERE id = #{id}
     </select>
 
     <select id="findByParentId" resultType="com.finikes.oc.estate.entity.EstateUnit">
-        SELECT id, unitId, name, area, function
-        FROM t_house
+        SELECT id, parentId, name, exp, leaf
+        FROM t_estate_unit
         WHERE unitId = #{unitId}
     </select>
 

+ 6 - 0
src/main/resources/mapper/HouseMapper.xml

@@ -8,4 +8,10 @@
         WHERE unitId = #{unitId}
     </select>
 
+    <select id="findById" resultType="com.finikes.oc.estate.entity.House">
+        SELECT id, unitId, name, area, function
+        FROM t_house
+        WHERE id = #{id}
+    </select>
+
 </mapper>

+ 7 - 1
src/main/resources/mapper/HouseRelationMapper.xml

@@ -11,7 +11,13 @@
     <select id="findByPassportAndHouse" resultType="com.finikes.oc.management.entity.HouseRelation">
         SELECT passportId, houseId, state, certificateNo, certificateUrl
         FROM t_house_relation
-        WHERE passportId = #{passportId} AND houseId = #{houseId}
+        WHERE passportId = #{id} AND houseId = #{houseId}
+    </select>
+
+    <select id="findByPassport" resultType="com.finikes.oc.management.entity.HouseRelation">
+        SELECT passportId, houseId, state, certificateNo, certificateUrl
+        FROM t_house_relation
+        WHERE passportId = #{id}
     </select>
 
     <update id="updateVeriCode" parameterType="com.finikes.oc.base.entity.Passport">

+ 11 - 0
src/main/resources/mapper/ManagerMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.finikes.oc.management.dao.ManagerDAO">
+
+    <select id="findByPassport" resultType="com.finikes.oc.management.entity.Manager">
+        SELECT roleId, passportId
+        FROM t_manager
+        WHERE passportId = #{passportId}
+    </select>
+
+</mapper>

+ 6 - 0
src/main/resources/mapper/PassportMapper.xml

@@ -14,6 +14,12 @@
         WHERE mobile = #{mobile}
     </select>
 
+    <select id="findById" parameterType="java.lang.Integer" resultType="com.finikes.oc.base.entity.Passport">
+        SELECT id, mobile, password, veriCode, state, veriCodeDeadline
+        FROM t_passport
+        WHERE id = #{id}
+    </select>
+
     <update id="updateVeriCode" parameterType="com.finikes.oc.base.entity.Passport">
         UPDATE t_passport
         SET veriCode         = #{veriCode},

+ 11 - 0
src/main/resources/mapper/ResourceMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.finikes.oc.management.dao.ResourceDAO">
+
+    <select id="findByUrlAndMethod" resultType="com.finikes.oc.management.entity.Resource">
+        SELECT id, url, httpMethod
+        FROM t_resource
+        WHERE url = #{url} AND httpMethod = #{httpMethod}
+    </select>
+
+</mapper>