투표 추가
This commit is contained in:
parent
9c61c36928
commit
5d791bbb3e
@ -0,0 +1,80 @@
|
||||
package io.company.localhost.controller.api;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import io.company.localhost.common.annotation.Member;
|
||||
import io.company.localhost.common.annotation.ParameterCheck;
|
||||
import io.company.localhost.common.annotation.ReqMap;
|
||||
import io.company.localhost.common.dto.ApiResponse;
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
import io.company.localhost.service.localvoteService;
|
||||
import io.company.localhost.utils.AuthUtil;
|
||||
import io.company.localhost.vo.MemberVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@RequestMapping("/api/vote")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class VoteBoardController {
|
||||
|
||||
private final localvoteService localvoteservice;
|
||||
|
||||
/**
|
||||
* 투표목록조회
|
||||
* @param page 페이지번호 , 내가한투표 :0 투표안한것 :1 , 전체:0,투표마감:1,투표중:2
|
||||
* @return
|
||||
*/
|
||||
@Member
|
||||
@ParameterCheck
|
||||
@GetMapping("getVoteList")
|
||||
public ApiResponse<PageInfo<MapDto>> getVoteList(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) {
|
||||
|
||||
//userId
|
||||
Long userId = AuthUtil.getUser().getId();
|
||||
map.put("userId", userId);
|
||||
PageInfo<MapDto> VoteList = localvoteservice.getVoteList(map);
|
||||
|
||||
|
||||
return ApiResponse.ok(VoteList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 투표 등록
|
||||
* @param title 제목 ,endDate 종료날짜 ,itemList 항목리스트(항목,링크) ,addvoteIs 항목추가여부, votemMltiIs 다중투표 허용여부
|
||||
* @return
|
||||
*/
|
||||
@Member
|
||||
@PostMapping("insertWord")
|
||||
public ApiResponse<Long> insertWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) {
|
||||
|
||||
//userId
|
||||
Long userId = AuthUtil.getUser().getId();
|
||||
map.put("userId", userId);
|
||||
Long result = localvoteservice.insertVote(map);
|
||||
return ApiResponse.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 투표 선택
|
||||
* @param title 제목 ,endDate 종료날짜 ,itemList 항목리스트(항목,링크) ,addvoteIs 항목추가여부, votemMltiIs 다중투표 허용여부
|
||||
* @return
|
||||
*/
|
||||
@Member
|
||||
@PostMapping("insertCheckedNums")
|
||||
public ApiResponse<Long> insertCheckedNums(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) {
|
||||
|
||||
Long userId = AuthUtil.getUser().getId();
|
||||
map.put("userId", userId);
|
||||
return ApiResponse.ok(localvoteservice.insertCheckedNums(map));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -30,7 +30,6 @@ import io.company.localhost.common.dto.ApiResponse;
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
import io.company.localhost.service.commoncodService;
|
||||
import io.company.localhost.service.worddictyService;
|
||||
import io.company.localhost.utils.AuthUtil;
|
||||
import io.company.localhost.vo.MemberVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package io.company.localhost.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
|
||||
@Mapper
|
||||
public interface VotDetailMapper {
|
||||
|
||||
Long insertdetail(MapDto map);
|
||||
|
||||
List<MapDto> getVoteDetails(int locvotSeq);
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package io.company.localhost.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
|
||||
@Mapper
|
||||
public interface VotMemberMapper {
|
||||
|
||||
void insertmem(MapDto map);
|
||||
|
||||
List<MapDto> getVoteMember(Integer locvotSeq);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package io.company.localhost.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
|
||||
@Mapper
|
||||
public interface VotRecordMapper {
|
||||
|
||||
int yesVotetotal(MapDto map);
|
||||
|
||||
Long insertCheckedNums(MapDto map);
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package io.company.localhost.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
|
||||
@Mapper
|
||||
public interface VotchoiceMapper {
|
||||
|
||||
void insertChoice(MapDto map);
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package io.company.localhost.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
|
||||
@Mapper
|
||||
public interface localvoteMapper {
|
||||
|
||||
Long insertVote(MapDto map);
|
||||
|
||||
List<MapDto> getVoteList(MapDto map);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package io.company.localhost.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
import io.company.localhost.mapper.VotDetailMapper;
|
||||
import io.company.localhost.mapper.VotMemberMapper;
|
||||
import io.company.localhost.mapper.VotRecordMapper;
|
||||
import io.company.localhost.mapper.VotchoiceMapper;
|
||||
import io.company.localhost.mapper.localvoteMapper;
|
||||
import io.company.localhost.utils.PageUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class localvoteService {
|
||||
|
||||
private final localvoteMapper localvotemapper;
|
||||
private final VotMemberMapper votmembermapper;
|
||||
private final VotDetailMapper votdetailmapper;
|
||||
private final VotRecordMapper votrecordmapper;
|
||||
private final VotchoiceMapper votchoicemapper;
|
||||
|
||||
public Long insertVote(MapDto map) {
|
||||
|
||||
Long result = 0L;
|
||||
|
||||
int voteIdInt = (int) map.get("voteId");
|
||||
if(voteIdInt != 0) {
|
||||
result = votdetailmapper.insertdetail(map);
|
||||
}else {
|
||||
result = localvotemapper.insertVote(map);
|
||||
if(result == 1) {
|
||||
//투표 가능 멤버 등록
|
||||
votmembermapper.insertmem(map);
|
||||
//투표 항목,링크 등록
|
||||
votdetailmapper.insertdetail(map);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public PageInfo<MapDto> getVoteList(MapDto map) {
|
||||
//투표 목록조회
|
||||
int page = map.getString("page") != null ? Integer.parseInt(map.getString("page")) : 1;
|
||||
PageHelper.startPage(page, 10);
|
||||
PageInfo<MapDto> localvote = PageUtil.redefineNavigation(new PageInfo<>(localvotemapper.getVoteList(map),10));
|
||||
List<MapDto> resultList = new ArrayList<>();
|
||||
|
||||
List<MapDto> voteList = localvote.getList();
|
||||
|
||||
for (MapDto vote : voteList) {
|
||||
MapDto voteMap = new MapDto();
|
||||
voteMap.put("localVote", vote);
|
||||
Integer locvotSeq = (Integer) vote.get("LOCVOTSEQ");
|
||||
//투표 항목조회
|
||||
List<MapDto> voteDetails = votdetailmapper.getVoteDetails(locvotSeq);
|
||||
//투표 가능 멤버 조회
|
||||
List<MapDto> voteMembers = votmembermapper.getVoteMember(locvotSeq);
|
||||
voteMap.put("voteDetails", voteDetails);
|
||||
voteMap.put("voteMembers", voteMembers);
|
||||
|
||||
map.put("id",locvotSeq);
|
||||
//투표 여부
|
||||
int yesVotetotal = votrecordmapper.yesVotetotal(map);
|
||||
voteMap.put("yesVotetotal", yesVotetotal);
|
||||
|
||||
resultList.add(voteMap);
|
||||
}
|
||||
localvote.setList(resultList);
|
||||
|
||||
return localvote;
|
||||
|
||||
}
|
||||
|
||||
public Long insertCheckedNums(MapDto map) {
|
||||
Long result = votrecordmapper.insertCheckedNums(map);
|
||||
if(result == 1) {
|
||||
votchoicemapper.insertChoice(map);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
28
src/main/resources/mapper/VotDetailMapper.xml
Normal file
28
src/main/resources/mapper/VotDetailMapper.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?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="io.company.localhost.mapper.VotDetailMapper">
|
||||
<insert id="insertdetail" parameterType="map">
|
||||
INSERT INTO votdetail
|
||||
(LOCVOTSEQ
|
||||
,LOCVOTCON
|
||||
,LOCVOTLIK
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="itemList" item="item" separator=",">
|
||||
(
|
||||
#{voteId}
|
||||
,#{item.content}
|
||||
,#{item.url}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="getVoteDetails" parameterType="int" >
|
||||
select
|
||||
*
|
||||
from
|
||||
votdetail
|
||||
where
|
||||
LOCVOTSEQ = #{LOCVOTSEQ}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
22
src/main/resources/mapper/VotMemberMapper.xml
Normal file
22
src/main/resources/mapper/VotMemberMapper.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?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="io.company.localhost.mapper.VotMemberMapper">
|
||||
<insert id="insertmem" parameterType="map">
|
||||
INSERT INTO votmember
|
||||
(LOCVOTSEQ
|
||||
, MEMBERSEQ
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="activeUserList" item="user" separator=",">
|
||||
(#{voteId}, #{user.id})
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="getVoteMember" parameterType="int" >
|
||||
select
|
||||
*
|
||||
from
|
||||
votdetail
|
||||
where
|
||||
LOCVOTSEQ = #{LOCVOTSEQ}
|
||||
</select>
|
||||
</mapper>
|
||||
42
src/main/resources/mapper/VotRecordMapper.xml
Normal file
42
src/main/resources/mapper/VotRecordMapper.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?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="io.company.localhost.mapper.VotRecordMapper">
|
||||
<select id="yesVotetotal" parameterType="map">
|
||||
select count(*) as yesvote
|
||||
from
|
||||
votrecord
|
||||
where
|
||||
LOCVOTSEQ = #{id}
|
||||
and
|
||||
VOTRECMEM = #{userId}
|
||||
</select>
|
||||
<insert id="insertCheckedNums" parameterType="map">
|
||||
INSERT INTO votrecord
|
||||
(
|
||||
LOCVOTSEQ
|
||||
,VOTRECMEM
|
||||
,VOTRECRDT
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
#{votenum}
|
||||
,#{userId}
|
||||
,now()
|
||||
)
|
||||
|
||||
</insert>
|
||||
|
||||
<!-- <insert id="insertCheckedNums" parameterType="map">
|
||||
INSERT INTO votrecord
|
||||
(
|
||||
LOCVOTSEQ
|
||||
,VOTRECMEM
|
||||
,VOTRECRDT
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="checkedList" item="item" separator=",">
|
||||
(#{item.LOCVOTSEQ}, #{userId} ,now())
|
||||
</foreach>
|
||||
</insert>-->
|
||||
|
||||
</mapper>
|
||||
20
src/main/resources/mapper/VotchoiceMapper.xml
Normal file
20
src/main/resources/mapper/VotchoiceMapper.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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="io.company.localhost.mapper.VotchoiceMapper">
|
||||
|
||||
<insert id="insertChoice" parameterType="map">
|
||||
INSERT INTO votchoice
|
||||
(
|
||||
LOCVOTSEQ
|
||||
,VOTDETSEQ
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="checkedList" item="item" separator=",">
|
||||
(
|
||||
#{item.LOCVOTSEQ}
|
||||
,#{item.VOTDETSEQ}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
38
src/main/resources/mapper/localvoteMapper.xml
Normal file
38
src/main/resources/mapper/localvoteMapper.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?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="io.company.localhost.mapper.localvoteMapper">
|
||||
|
||||
<insert id="insertVote" parameterType="map" useGeneratedKeys="true" keyProperty="voteId">
|
||||
insert into localvote
|
||||
(
|
||||
LOCVOTREG
|
||||
,LOCVOTRDT
|
||||
,LOCVOTEDT
|
||||
,LOCVOTTTL
|
||||
,LOCVOTADD
|
||||
,LOCVOTMUL
|
||||
)
|
||||
values
|
||||
(
|
||||
#{userId}
|
||||
,now()
|
||||
,#{endDate}
|
||||
,#{title}
|
||||
,#{addvoteIs}
|
||||
,#{votemMltiIs}
|
||||
)
|
||||
</insert>
|
||||
<select id="getVoteList" parameterType="map">
|
||||
select
|
||||
a.*
|
||||
,DATE_FORMAT(a.LOCVOTRDT, '%Y-%m-%d %H:%i') AS formatted_LOCVOTRDT
|
||||
,DATE_FORMAT(a.LOCVOTEDT, '%Y-%m-%d %H:%i') AS formatted_LOCVOTEDT
|
||||
,b.*
|
||||
from
|
||||
localvote a
|
||||
LEFT JOIN
|
||||
netmember b
|
||||
on
|
||||
a.LOCVOTREG = b.MEMBERSEQ
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user