Parcourir la source

Merge branch 'master' of http://121.5.58.50:3000/finikes/ocv1-server

finikes il y a 2 ans
Parent
commit
112126e6f7
27 fichiers modifiés avec 791 ajouts et 25 suppressions
  1. 52 0
      src/main/java/com/finikes/oc/base/controller/NoticeController.java
  2. 17 0
      src/main/java/com/finikes/oc/base/dao/NoticeDao.java
  3. 64 0
      src/main/java/com/finikes/oc/base/dto/NoticeCreateDto.java
  4. 41 0
      src/main/java/com/finikes/oc/base/dto/NoticeSearchDto.java
  5. 75 0
      src/main/java/com/finikes/oc/base/dto/NoticeUpdateDto.java
  6. 60 0
      src/main/java/com/finikes/oc/base/dto/NoticeViewDto.java
  7. 32 0
      src/main/java/com/finikes/oc/base/dto/PageResponse.java
  8. 67 0
      src/main/java/com/finikes/oc/base/entity/Notice.java
  9. 21 0
      src/main/java/com/finikes/oc/base/mapper/NoticeMapper.java
  10. 43 0
      src/main/java/com/finikes/oc/base/service/NoticeService.java
  11. 87 0
      src/main/java/com/finikes/oc/base/service/NoticeServiceImpl.java
  12. 1 1
      src/main/java/com/finikes/oc/common/ApiResponse.java
  13. 1 1
      src/main/java/com/finikes/oc/common/BaseDao.java
  14. 1 1
      src/main/java/com/finikes/oc/common/LockService.java
  15. 1 1
      src/main/java/com/finikes/oc/common/LockServiceImpl.java
  16. 1 1
      src/main/java/com/finikes/oc/common/PassportHelper.java
  17. 1 1
      src/main/java/com/finikes/oc/common/exception/BusinessException.java
  18. 1 1
      src/main/java/com/finikes/oc/vote/controller/VoteController.java
  19. 3 1
      src/main/java/com/finikes/oc/vote/dao/ChoiceDao.java
  20. 1 0
      src/main/java/com/finikes/oc/vote/dao/OptionDao.java
  21. 1 0
      src/main/java/com/finikes/oc/vote/dao/VoteActivityDao.java
  22. 2 1
      src/main/java/com/finikes/oc/vote/dao/VoteDao.java
  23. 44 16
      src/main/java/com/finikes/oc/vote/service/VoteServiceImpl.java
  24. 2 0
      src/main/resources/application.yml
  25. 10 0
      src/main/resources/mapper/ChoiceMapper.xml
  26. 76 0
      src/main/resources/mapper/NoticeMapper.xml
  27. 86 0
      src/test/java/com/finikes/oc/base/dao/NoticeDaoTest.java

+ 52 - 0
src/main/java/com/finikes/oc/base/controller/NoticeController.java

@@ -0,0 +1,52 @@
+package com.finikes.oc.base.controller;
+
+import com.finikes.oc.base.dto.*;
+import com.finikes.oc.base.service.NoticeService;
+import com.finikes.oc.common.ApiResponse;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+
+/**
+ * 通知控制器
+ */
+@RestController
+public class NoticeController {
+
+    private final NoticeService noticeService;
+
+    public NoticeController(NoticeService noticeService) {
+        this.noticeService = noticeService;
+    }
+
+    @PutMapping("notice")
+    public ApiResponse<Integer> createNotice(@RequestBody @Valid NoticeCreateDto dto) {
+        int noticeId = noticeService.createNotice(dto);
+        return ApiResponse.successful(noticeId);
+    }
+
+    @PostMapping("notice")
+    public ApiResponse<Integer> updateNotice(@RequestBody @Valid NoticeUpdateDto dto) {
+        noticeService.updateNotice(dto);
+        return ApiResponse.successful();
+    }
+
+    @GetMapping("notice")
+    public ApiResponse<NoticeViewDto> peekNotice(@RequestParam(name = "noticeId") Integer noticeId) {
+        NoticeViewDto dto = noticeService.peekNotice(noticeId);
+        return ApiResponse.successful(dto);
+    }
+
+    @GetMapping("notices")
+    public ApiResponse<PageResponse<NoticeViewDto>> searchNotice(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                 @RequestParam(value = "pageCapacity", defaultValue = "10") int pageCapacity,
+                                                                 @RequestParam(value = "type", required = false) Integer type) {
+        NoticeSearchDto searchDto = new NoticeSearchDto();
+        searchDto.setPage(pageNum);
+        searchDto.setPageCapacity(pageCapacity);
+        searchDto.setType(type);
+        PageResponse<NoticeViewDto> pageResponse = noticeService.searchNotice(searchDto);
+        return ApiResponse.successful(pageResponse);
+    }
+
+}

+ 17 - 0
src/main/java/com/finikes/oc/base/dao/NoticeDao.java

@@ -0,0 +1,17 @@
+package com.finikes.oc.base.dao;
+
+import com.finikes.oc.base.entity.Notice;
+import com.finikes.oc.common.BaseDao;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface NoticeDao extends BaseDao<Notice, Integer> {
+
+
+    int updateSelective(Notice entity);
+
+    List<Notice> selectByType(@Param("type") Integer type);
+}

+ 64 - 0
src/main/java/com/finikes/oc/base/dto/NoticeCreateDto.java

@@ -0,0 +1,64 @@
+package com.finikes.oc.base.dto;
+
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+public class NoticeCreateDto {
+    @Size(min = 1, max = 2)
+    @NotNull
+    private Integer type;
+    @NotBlank
+    @Max(256)
+    private String title;
+    @NotBlank
+    @Max(256)
+    private String secondTitle;
+    @NotBlank
+    @Max(256)
+    private String content;
+
+    @Override
+    public String toString() {
+        return "NoticeCreateDto{" +
+                "type=" + type +
+                ", title='" + title + '\'' +
+                ", secondTitle='" + secondTitle + '\'' +
+                ", content='" + content + '\'' +
+                '}';
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getSecondTitle() {
+        return secondTitle;
+    }
+
+    public void setSecondTitle(String secondTitle) {
+        this.secondTitle = secondTitle;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

+ 41 - 0
src/main/java/com/finikes/oc/base/dto/NoticeSearchDto.java

@@ -0,0 +1,41 @@
+package com.finikes.oc.base.dto;
+
+public class NoticeSearchDto {
+    private Integer type;
+
+    private Integer page;
+    private Integer pageCapacity;
+
+    @Override
+    public String toString() {
+        return "NoticeSearchDto{" +
+                "type=" + type +
+                ", page=" + page +
+                ", pageCapacity=" + pageCapacity +
+                '}';
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public Integer getPage() {
+        return page;
+    }
+
+    public void setPage(Integer page) {
+        this.page = page;
+    }
+
+    public Integer getPageCapacity() {
+        return pageCapacity;
+    }
+
+    public void setPageCapacity(Integer pageCapacity) {
+        this.pageCapacity = pageCapacity;
+    }
+}

+ 75 - 0
src/main/java/com/finikes/oc/base/dto/NoticeUpdateDto.java

@@ -0,0 +1,75 @@
+package com.finikes.oc.base.dto;
+
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+public class NoticeUpdateDto {
+    @NotNull
+    private Integer id;
+    @Size(min = 1, max = 2)
+    @NotNull
+    private Integer type;
+    @NotBlank
+    @Max(256)
+    private String title;
+    @NotBlank
+    @Max(256)
+    private String secondTitle;
+    @NotBlank
+    @Max(256)
+    private String content;
+
+    @Override
+    public String toString() {
+        return "NoticeUpdateDto{" +
+                "id=" + id +
+                ", type=" + type +
+                ", title='" + title + '\'' +
+                ", secondTitle='" + secondTitle + '\'' +
+                ", content='" + content + '\'' +
+                '}';
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getSecondTitle() {
+        return secondTitle;
+    }
+
+    public void setSecondTitle(String secondTitle) {
+        this.secondTitle = secondTitle;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

+ 60 - 0
src/main/java/com/finikes/oc/base/dto/NoticeViewDto.java

@@ -0,0 +1,60 @@
+package com.finikes.oc.base.dto;
+
+public class NoticeViewDto {
+    private Integer id;
+    private Integer type;
+    private String title;
+    private String secondTitle;
+    private String content;
+
+    @Override
+    public String toString() {
+        return "NoticeViewDto{" +
+                "id=" + id +
+                ", type=" + type +
+                ", title='" + title + '\'' +
+                ", secondTitle='" + secondTitle + '\'' +
+                ", content='" + content + '\'' +
+                '}';
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getSecondTitle() {
+        return secondTitle;
+    }
+
+    public void setSecondTitle(String secondTitle) {
+        this.secondTitle = secondTitle;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

+ 32 - 0
src/main/java/com/finikes/oc/base/dto/PageResponse.java

@@ -0,0 +1,32 @@
+package com.finikes.oc.base.dto;
+
+import java.util.List;
+
+public class PageResponse<T> {
+    private Integer pageQuantity;
+    private List<T> list;
+
+    @Override
+    public String toString() {
+        return "PageResponse{" +
+                "pageQuantity=" + pageQuantity +
+                ", list=" + list +
+                '}';
+    }
+
+    public Integer getPageQuantity() {
+        return pageQuantity;
+    }
+
+    public void setPageQuantity(Integer pageQuantity) {
+        this.pageQuantity = pageQuantity;
+    }
+
+    public List<T> getList() {
+        return list;
+    }
+
+    public void setList(List<T> list) {
+        this.list = list;
+    }
+}

+ 67 - 0
src/main/java/com/finikes/oc/base/entity/Notice.java

@@ -11,6 +11,33 @@ public class Notice {
     private String content; // 内容
     private long publishTime; // 发布时间
 
+    private Long createTime;
+
+    private Long updateTime;
+
+    private Integer cid; // 创建人 ID
+
+    private Integer uid; //修改人 ID
+
+    private Integer state;
+
+    @Override
+    public String toString() {
+        return "Notice{" +
+                "id=" + id +
+                ", type=" + type +
+                ", title='" + title + '\'' +
+                ", secondTitle='" + secondTitle + '\'' +
+                ", content='" + content + '\'' +
+                ", publishTime=" + publishTime +
+                ", createTime=" + createTime +
+                ", updateTime=" + updateTime +
+                ", cid=" + cid +
+                ", uid=" + uid +
+                ", state=" + state +
+                '}';
+    }
+
     public int getType() {
         return type;
     }
@@ -58,4 +85,44 @@ public class Notice {
     public void setId(int id) {
         this.id = id;
     }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+
+    public Long getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Integer getCid() {
+        return cid;
+    }
+
+    public void setCid(Integer cid) {
+        this.cid = cid;
+    }
+
+    public Integer getUid() {
+        return uid;
+    }
+
+    public void setUid(Integer uid) {
+        this.uid = uid;
+    }
+
+    public Integer getState() {
+        return state;
+    }
+
+    public void setState(Integer state) {
+        this.state = state;
+    }
 }

+ 21 - 0
src/main/java/com/finikes/oc/base/mapper/NoticeMapper.java

@@ -0,0 +1,21 @@
+package com.finikes.oc.base.mapper;
+
+import com.finikes.oc.base.dto.NoticeCreateDto;
+import com.finikes.oc.base.dto.NoticeUpdateDto;
+import com.finikes.oc.base.dto.NoticeViewDto;
+import com.finikes.oc.base.entity.Notice;
+import org.mapstruct.Mapper;
+import org.mapstruct.factory.Mappers;
+
+@Mapper
+public interface NoticeMapper {
+
+    NoticeMapper INSTANCE = Mappers.getMapper(NoticeMapper.class);
+
+    Notice noticeCreateDtoToNotice(NoticeCreateDto dto);
+
+    Notice noticeUpdateDtoToNotice(NoticeUpdateDto dto);
+
+    NoticeViewDto noticeToNoticeViewDto(Notice entity);
+
+}

+ 43 - 0
src/main/java/com/finikes/oc/base/service/NoticeService.java

@@ -0,0 +1,43 @@
+package com.finikes.oc.base.service;
+
+import com.finikes.oc.base.dto.*;
+
+import java.util.List;
+
+/**
+ * 通知服务
+ */
+public interface NoticeService {
+
+    /**
+     * 创建通知
+     *
+     * @param dto 通知创建数据传输对象
+     * @return 主键
+     */
+    int createNotice(NoticeCreateDto dto);
+
+    /**
+     * 更新通知
+     *
+     * @param dto 通知更新数据传输对象
+     */
+    void updateNotice(NoticeUpdateDto dto);
+
+    /**
+     * 查看通知
+     *
+     * @param noticeId 通知 ID
+     * @return 通知视图数据传输对象
+     */
+    NoticeViewDto peekNotice(Integer noticeId);
+
+    /**
+     * 检索通知
+     *
+     * @param dto 通知检索数据传输对象
+     * @return 通知视图数据传输对象列表
+     */
+    PageResponse<NoticeViewDto> searchNotice(NoticeSearchDto dto);
+
+}

+ 87 - 0
src/main/java/com/finikes/oc/base/service/NoticeServiceImpl.java

@@ -0,0 +1,87 @@
+package com.finikes.oc.base.service;
+
+import com.finikes.oc.base.dao.NoticeDao;
+import com.finikes.oc.base.dto.*;
+import com.finikes.oc.base.entity.Notice;
+import com.finikes.oc.base.entity.Passport;
+import com.finikes.oc.base.mapper.NoticeMapper;
+import com.finikes.oc.common.PassportHelper;
+import com.finikes.oc.common.exception.BusinessException;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class NoticeServiceImpl implements NoticeService {
+
+    private final NoticeDao noticeDao;
+
+    public NoticeServiceImpl(NoticeDao noticeDao) {
+        this.noticeDao = noticeDao;
+    }
+
+    @Override
+    public int createNotice(NoticeCreateDto dto) {
+        Passport passport = PassportHelper.currentPassport();
+        if (passport == null) {
+            throw new BusinessException("获取登录状态异常");
+        }
+
+        long now = System.currentTimeMillis();
+
+        Notice notice = NoticeMapper.INSTANCE.noticeCreateDtoToNotice(dto);
+        notice.setPublishTime(now);
+        notice.setCreateTime(now);
+        notice.setUpdateTime(now);
+        notice.setCid(passport.getId());
+        notice.setUid(passport.getId());
+
+        noticeDao.insert(notice);
+        return notice.getId();
+    }
+
+    @Override
+    public void updateNotice(NoticeUpdateDto dto) {
+        Passport passport = PassportHelper.currentPassport();
+        if (passport == null) {
+            throw new BusinessException("获取登录状态异常");
+        }
+
+        Notice notice = NoticeMapper.INSTANCE.noticeUpdateDtoToNotice(dto);
+        notice.setUid(passport.getId());
+        notice.setUpdateTime(System.currentTimeMillis());
+        int effectRow = noticeDao.updateSelective(notice);
+        if (effectRow != 1) {
+            throw new BusinessException("无此通知");
+        }
+    }
+
+    @Override
+    public NoticeViewDto peekNotice(Integer noticeId) {
+        Notice notice = noticeDao.selectByPrimaryKey(noticeId);
+        if (notice == null) {
+            throw new BusinessException("无此通知");
+        }
+        return NoticeMapper.INSTANCE.noticeToNoticeViewDto(notice);
+    }
+
+    @Override
+    public PageResponse<NoticeViewDto> searchNotice(NoticeSearchDto dto) {
+        try (Page<Notice> page = PageHelper.startPage(dto.getPage(), dto.getPageCapacity())){
+            List<Notice> notices = noticeDao.selectByType(dto.getType());
+
+            List<NoticeViewDto> list = notices.stream()
+                    .map(NoticeMapper.INSTANCE::noticeToNoticeViewDto)
+                    .collect(Collectors.toList());
+
+            PageResponse<NoticeViewDto> response = new PageResponse<>();
+            response.setList(list);
+            response.setPageQuantity(page.getPageNum());
+
+            return response;
+        }
+    }
+}

+ 1 - 1
src/main/java/com/finikes/oc/vote/ApiResponse.java → src/main/java/com/finikes/oc/common/ApiResponse.java

@@ -1,4 +1,4 @@
-package com.finikes.oc.vote;
+package com.finikes.oc.common;
 
 /**
  * 接口返回对象

+ 1 - 1
src/main/java/com/finikes/oc/vote/dao/BaseDao.java → src/main/java/com/finikes/oc/common/BaseDao.java

@@ -1,4 +1,4 @@
-package com.finikes.oc.vote.dao;
+package com.finikes.oc.common;
 
 /**
  * 基础数据访问对象

+ 1 - 1
src/main/java/com/finikes/oc/vote/LockService.java → src/main/java/com/finikes/oc/common/LockService.java

@@ -1,4 +1,4 @@
-package com.finikes.oc.vote;
+package com.finikes.oc.common;
 
 import java.util.concurrent.TimeUnit;
 

+ 1 - 1
src/main/java/com/finikes/oc/vote/LockServiceImpl.java → src/main/java/com/finikes/oc/common/LockServiceImpl.java

@@ -1,4 +1,4 @@
-package com.finikes.oc.vote;
+package com.finikes.oc.common;
 
 import org.springframework.stereotype.Component;
 

+ 1 - 1
src/main/java/com/finikes/oc/vote/PassportHelper.java → src/main/java/com/finikes/oc/common/PassportHelper.java

@@ -1,4 +1,4 @@
-package com.finikes.oc.vote;
+package com.finikes.oc.common;
 
 import com.finikes.oc.Passports;
 import com.finikes.oc.base.entity.Passport;

+ 1 - 1
src/main/java/com/finikes/oc/vote/exception/BusinessException.java → src/main/java/com/finikes/oc/common/exception/BusinessException.java

@@ -1,4 +1,4 @@
-package com.finikes.oc.vote.exception;
+package com.finikes.oc.common.exception;
 
 /**
  * 业务异常

+ 1 - 1
src/main/java/com/finikes/oc/vote/controller/VoteController.java

@@ -1,6 +1,6 @@
 package com.finikes.oc.vote.controller;
 
-import com.finikes.oc.vote.ApiResponse;
+import com.finikes.oc.common.ApiResponse;
 import com.finikes.oc.vote.dao.VoteActivityDao;
 import com.finikes.oc.vote.dto.*;
 import com.finikes.oc.vote.service.VoteService;

+ 3 - 1
src/main/java/com/finikes/oc/vote/dao/ChoiceDao.java

@@ -1,11 +1,13 @@
 package com.finikes.oc.vote.dao;
 
+import com.finikes.oc.common.BaseDao;
 import com.finikes.oc.vote.entity.Choice;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 @Mapper
 public interface ChoiceDao extends BaseDao<Choice, Long> {
 
-
+    boolean isHouseHolderInThisVote(@Param("voteId") Integer voteId, @Param("certificateNo") String certificateNo);
 
 }

+ 1 - 0
src/main/java/com/finikes/oc/vote/dao/OptionDao.java

@@ -1,5 +1,6 @@
 package com.finikes.oc.vote.dao;
 
+import com.finikes.oc.common.BaseDao;
 import com.finikes.oc.vote.entity.Option;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;

+ 1 - 0
src/main/java/com/finikes/oc/vote/dao/VoteActivityDao.java

@@ -1,5 +1,6 @@
 package com.finikes.oc.vote.dao;
 
+import com.finikes.oc.common.BaseDao;
 import com.finikes.oc.vote.entity.VoteActivity;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;

+ 2 - 1
src/main/java/com/finikes/oc/vote/dao/VoteDao.java

@@ -1,5 +1,6 @@
 package com.finikes.oc.vote.dao;
 
+import com.finikes.oc.common.BaseDao;
 import com.finikes.oc.vote.entity.Vote;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -7,7 +8,7 @@ import org.apache.ibatis.annotations.Param;
 import java.util.List;
 
 @Mapper
-public interface VoteDao extends BaseDao<Vote, Integer>{
+public interface VoteDao extends BaseDao<Vote, Integer> {
 
     List<Vote> selectByVoteActivityId(@Param("voteActivityId") Integer voteActivityId);
 

+ 44 - 16
src/main/java/com/finikes/oc/vote/service/VoteServiceImpl.java

@@ -1,8 +1,10 @@
 package com.finikes.oc.vote.service;
 
 import com.finikes.oc.base.entity.Passport;
-import com.finikes.oc.vote.LockService;
-import com.finikes.oc.vote.PassportHelper;
+import com.finikes.oc.management.dao.HouseRelationDAO;
+import com.finikes.oc.management.entity.HouseRelation;
+import com.finikes.oc.common.LockService;
+import com.finikes.oc.common.PassportHelper;
 import com.finikes.oc.vote.dao.ChoiceDao;
 import com.finikes.oc.vote.dao.OptionDao;
 import com.finikes.oc.vote.dao.VoteActivityDao;
@@ -12,7 +14,7 @@ import com.finikes.oc.vote.entity.Choice;
 import com.finikes.oc.vote.entity.Option;
 import com.finikes.oc.vote.entity.Vote;
 import com.finikes.oc.vote.entity.VoteActivity;
-import com.finikes.oc.vote.exception.BusinessException;
+import com.finikes.oc.common.exception.BusinessException;
 import com.finikes.oc.vote.mapper.VoteActivityMapper;
 import com.finikes.oc.vote.mapper.VoteMapper;
 import com.github.pagehelper.Page;
@@ -23,7 +25,6 @@ import org.springframework.transaction.annotation.Transactional;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -39,13 +40,16 @@ public class VoteServiceImpl implements VoteService {
 
     private final LockService lockService;
 
+    private final HouseRelationDAO houseRelationDAO;
+
     public VoteServiceImpl(ChoiceDao choiceDao, OptionDao optionDao, VoteActivityDao voteActivityDao, VoteDao voteDao,
-                           LockService lockService) {
+                           LockService lockService, HouseRelationDAO houseRelationDAO) {
         this.choiceDao = choiceDao;
         this.optionDao = optionDao;
         this.voteActivityDao = voteActivityDao;
         this.voteDao = voteDao;
         this.lockService = lockService;
+        this.houseRelationDAO = houseRelationDAO;
     }
 
     @Override
@@ -226,17 +230,26 @@ public class VoteServiceImpl implements VoteService {
         if (passport == null) {
             throw new BusinessException("获取登录状态异常");
         }
-        // TODO 需要方法获取登录用户信息
-
-        // TODO 这里需要锁住 用户ID 防止单个用户的并发调用, 锁住用户具有的房产主键已达到一房一票的需求.
-        String resourceId = "vote:" + passport.getId();
+        String voteResourceId = "vote:" + passport.getId();
         String ownerId = UUID.randomUUID().toString();
-        boolean locked = lockService.lock(resourceId, ownerId, 60, TimeUnit.SECONDS);
+        boolean locked = lockService.lock(voteResourceId, ownerId, 60, TimeUnit.SECONDS);
         if (!locked) {
             throw new BusinessException("请稍后再试");
         }
-
+        String houseResourceId = null;
         try {
+
+            HouseRelation houseRelation = houseRelationDAO.findByPassport(passport.getId());
+            if (houseRelation == null || houseRelation.getState() != 1) {
+                throw new BusinessException("无投票资格, 请绑定房产");
+            }
+
+            houseResourceId = "vote:house:" + houseRelation.getCertificateNo();
+            boolean secondLock = lockService.lock(houseResourceId, ownerId, 60, TimeUnit.SECONDS);
+            if (!secondLock) {
+                throw new BusinessException("请稍后再试");
+            }
+
             long now = System.currentTimeMillis();
 
             Option option = optionDao.selectByPrimaryKey(dto.getOptionId());
@@ -262,7 +275,9 @@ public class VoteServiceImpl implements VoteService {
                 throw new BusinessException("投票日期已过");
             }
 
-            // TODO 检查此登录人员的房产下的绑定人员是否参与过此抽奖.
+            if (choiceDao.isHouseHolderInThisVote(vote.getId(), houseRelation.getCertificateNo())) {
+                throw new BusinessException("此房产已经参与过投票了");
+            }
 
             Choice choice = new Choice();
             choice.setAssigneeId(passport.getId());
@@ -272,7 +287,8 @@ public class VoteServiceImpl implements VoteService {
 
             choiceDao.insert(choice);
         } finally {
-            lockService.unlock(resourceId, ownerId);
+            lockService.unlock(voteResourceId, ownerId);
+            lockService.unlock(houseResourceId, ownerId);
         }
     }
 
@@ -282,16 +298,23 @@ public class VoteServiceImpl implements VoteService {
         if (passport == null) {
             throw new BusinessException("获取登录状态异常");
         }
-        String resourceId = "vote:" + passport.getId();
+        String voteResourceId = "vote:" + passport.getId();
         String ownerId = UUID.randomUUID().toString();
-        boolean locked = lockService.lock(resourceId, ownerId, 60, TimeUnit.SECONDS);
+        boolean locked = lockService.lock(voteResourceId, ownerId, 60, TimeUnit.SECONDS);
         if (!locked) {
             throw new BusinessException("请稍后再试");
         }
+        String houseResourceId = null;
 
         try {
             long now = System.currentTimeMillis();
 
+            HouseRelation houseRelation = houseRelationDAO.findByPassport(passport.getId());
+            if (houseRelation == null || houseRelation.getState() != 1) {
+                throw new BusinessException("无投票资格, 请绑定房产");
+            }
+            houseResourceId = "vote:house:" + houseRelation.getCertificateNo();
+
             Option option = optionDao.selectByPrimaryKey(dto.getOptionId());
             if (option == null) {
                 throw new BusinessException("参与的投票不存在");
@@ -315,6 +338,10 @@ public class VoteServiceImpl implements VoteService {
                 throw new BusinessException("投票日期已过");
             }
 
+            if (choiceDao.isHouseHolderInThisVote(vote.getId(), houseRelation.getCertificateNo())) {
+                throw new BusinessException("此房产已经参与过投票了");
+            }
+
             Choice choice = new Choice();
             choice.setAssigneeId(dto.getPrincipalId());
             choice.setOptionId(dto.getOptionId());
@@ -324,7 +351,8 @@ public class VoteServiceImpl implements VoteService {
 
             choiceDao.insert(choice);
         } finally {
-            lockService.unlock(resourceId, ownerId);
+            lockService.unlock(voteResourceId, ownerId);
+            lockService.unlock(houseResourceId, ownerId);
         }
     }
 }

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

@@ -20,5 +20,7 @@ logging:
     com:
       finikes:
         oc:
+          base:
+            dao: debug
           vote:
             dao: debug

+ 10 - 0
src/main/resources/mapper/ChoiceMapper.xml

@@ -20,6 +20,16 @@
         FROM t_choice
         WHERE id = #{primaryKey}
     </select>
+    <select id="isHouseHolderInThisVote" resultType="java.lang.Boolean">
+        SELECT count(1)
+        FROM t_option vote_option,
+        t_choice choice,
+        t_house_relation relation
+        WHERE vote_option.vote_id = #{voteId}
+        AND choice.assignee_id = relation.passportId
+        AND certificateNo = #{certificateNo}
+        AND state = 1
+    </select>
 
     <delete id="deleteByPrimaryKey" parameterType="integer">
         DELETE

+ 76 - 0
src/main/resources/mapper/NoticeMapper.xml

@@ -0,0 +1,76 @@
+<?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.base.dao.NoticeDao">
+
+    <insert id="insert" useGeneratedKeys="true" keyProperty="id" keyColumn="id"
+            parameterType="com.finikes.oc.base.entity.Notice">
+        INSERT INTO t_notice (type, title ,
+        second_title, content,
+        publish_time, create_time, update_time, cid, uid)
+        VALUES (#{type}, #{title} ,
+        #{secondTitle}, #{content},
+        #{publishTime}, #{createTime}, #{updateTime}, #{cid}, #{uid})
+    </insert>
+
+    <update id="update" parameterType="com.finikes.oc.base.entity.Notice">
+        UPDATE t_notice SET type = #{type}, title = #{title},
+        second_title = #{secondTitle}, content = #{content}, publish_time = #{publishTime},
+        create_time = #{createTime}, update_time = #{updateTime}, cid = #{cid}, uid = #{uid}
+        WHERE id = #{id}
+    </update>
+    <update id="updateSelective">
+        UPDATE t_notice
+        <set>
+            <if test="type != null">
+                type = #{type},
+            </if>
+            <if test="title != null">
+                title = #{title},
+            </if>
+            <if test="secondTitle != null">
+                second_title = #{secondTitle},
+            </if>
+            <if test="content != null">
+                content = #{content},
+            </if>
+            <if test="publishTime != null">
+                publish_time = #{publishTime},
+            </if>
+            <if test="createTime != null">
+                create_time = #{createTime},
+            </if>
+            <if test="updateTime != null">
+                update_time = #{updateTime},
+            </if>
+            <if test="cid">
+                cid = #{cid},
+            </if>
+            <if test="uid">
+                uid = #{uid}
+            </if>
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <select id="selectByPrimaryKey" parameterType="integer" resultType="com.finikes.oc.base.entity.Notice">
+        SELECT id, type, title , second_title, content, publish_time, create_time, update_time, cid, uid
+        FROM t_notice
+        WHERE id = #{primaryKey}
+    </select>
+    <select id="selectByType" resultType="com.finikes.oc.base.entity.Notice">
+        SELECT id, type, title , second_title, content, publish_time, create_time, update_time, cid, uid
+        FROM t_notice
+        <where>
+            <if test="type != null">
+                type = #{type}
+            </if>
+        </where>
+    </select>
+
+    <delete id="deleteByPrimaryKey" parameterType="integer">
+        DELETE
+        FROM t_notice
+        WHERE id = #{primaryKey}
+    </delete>
+
+</mapper>

+ 86 - 0
src/test/java/com/finikes/oc/base/dao/NoticeDaoTest.java

@@ -0,0 +1,86 @@
+package com.finikes.oc.base.dao;
+
+import com.finikes.oc.App;
+import com.finikes.oc.base.entity.Notice;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.List;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = App.class)
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class NoticeDaoTest {
+
+    @Autowired
+    private NoticeDao noticeDao;
+
+    private static Integer noticeId = 0;
+
+    @Order(1)
+    @Test
+    void insert() {
+        Notice notice = new Notice();
+        notice.setTitle(UUID.randomUUID().toString());
+        notice.setSecondTitle(UUID.randomUUID().toString());
+        notice.setContent(UUID.randomUUID().toString());
+        noticeDao.insert(notice);
+        noticeId = notice.getId();
+    }
+
+    @Order(2)
+    @Test
+    void selectByPrimaryKey() {
+        Notice notice = noticeDao.selectByPrimaryKey(noticeId);
+        assertNotNull(notice);
+    }
+
+    @Order(3)
+    @Test
+    public void update() {
+        Notice notice = noticeDao.selectByPrimaryKey(noticeId);
+        notice.setTitle(UUID.randomUUID().toString());
+        notice.setSecondTitle(UUID.randomUUID().toString());
+        notice.setContent(UUID.randomUUID().toString());
+        notice.setUid(null);
+        notice.setCid(null);
+        int i = noticeDao.update(notice);
+        assertEquals(i, 1);
+    }
+
+    @Order(4)
+    @Test
+    void updateSelective() {
+        Notice notice = noticeDao.selectByPrimaryKey(noticeId);
+        notice.setTitle(UUID.randomUUID().toString());
+        notice.setSecondTitle(UUID.randomUUID().toString());
+        notice.setContent(UUID.randomUUID().toString());
+        int i = noticeDao.updateSelective(notice);
+        assertEquals(i, 1);
+    }
+
+    @Order(5)
+    @Test
+    void selectByType() {
+        List<Notice> list = noticeDao.selectByType(null);
+        assertNotEquals(list.size(), 0);
+        noticeDao.selectByType(1);
+    }
+
+    @Order(6)
+    @Test
+    void deleteByPrimaryKey(){
+        int i = noticeDao.deleteByPrimaryKey(noticeId);
+        assertEquals(i, 1);
+    }
+
+}