Pārlūkot izejas kodu

content-service 添加 VoteController 及相关数据和接口

reghao 7 mēneši atpakaļ
vecāks
revīzija
dc013441d0

+ 58 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/controller/VoteController.java

@@ -0,0 +1,58 @@
+package cn.reghao.tnb.content.app.data.controller;
+
+import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.web.WebResult;
+import cn.reghao.tnb.content.app.data.model.dto.VoteDto;
+import cn.reghao.tnb.content.app.data.model.dto.VoteProgressDto;
+import cn.reghao.tnb.content.app.data.model.po.Vote;
+import cn.reghao.tnb.content.app.data.service.VoteService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:04:55
+ */
+@Tag(name = "投票接口")
+@RestController
+@RequestMapping("/api/content/vote")
+public class VoteController {
+    private final VoteService voteService;
+
+    public VoteController(VoteService voteService) {
+        this.voteService = voteService;
+    }
+
+    @Operation(summary = "添加新投票", description = "N")
+    @PostMapping("/add")
+    public String addVote(@RequestBody @Validated VoteDto voteDto) {
+        return WebResult.success();
+    }
+
+    @Operation(summary = "获取投票列表", description = "N")
+    @GetMapping("/list")
+    public String getVoteList(@RequestParam("pn") Integer pn) {
+        PageList<Vote> pageList = PageList.empty();
+        return WebResult.success(pageList);
+    }
+
+    @Operation(summary = "获取某项投票", description = "N")
+    @GetMapping("/get/{voteId}")
+    public String getVote(@PathVariable("voteId") Long voteId) {
+        return WebResult.success();
+    }
+
+    @Operation(summary = "进行投票", description = "N")
+    @PostMapping("/progress")
+    public String publishVote(@RequestBody @Validated VoteProgressDto voteProgressDto) {
+        return WebResult.success();
+    }
+
+    @Operation(summary = "获取某项投票结果", description = "N")
+    @GetMapping("/result/{voteId}")
+    public String getVoteResult(@PathVariable("voteId") Long voteId) {
+        return WebResult.success();
+    }
+}

+ 14 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/VoteMapper.java

@@ -0,0 +1,14 @@
+package cn.reghao.tnb.content.app.data.db.mapper;
+
+import cn.reghao.jutil.jdk.db.BaseMapper;
+import cn.reghao.tnb.content.app.data.model.po.Vote;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:17:16
+ */
+@Mapper
+public interface VoteMapper extends BaseMapper<Vote> {
+    Vote findByVoteId(long voteId);
+}

+ 16 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/VoteOptionMapper.java

@@ -0,0 +1,16 @@
+package cn.reghao.tnb.content.app.data.db.mapper;
+
+import cn.reghao.jutil.jdk.db.BaseMapper;
+import cn.reghao.tnb.content.app.data.model.po.VoteOption;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:25:29
+ */
+@Mapper
+public interface VoteOptionMapper extends BaseMapper<VoteOption> {
+    List<VoteOption> findByVoteId(long voteId);
+}

+ 14 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/db/mapper/VoteResultMapper.java

@@ -0,0 +1,14 @@
+package cn.reghao.tnb.content.app.data.db.mapper;
+
+import cn.reghao.jutil.jdk.db.BaseMapper;
+import cn.reghao.tnb.content.app.data.model.po.VoteResult;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:17:36
+ */
+@Mapper
+public interface VoteResultMapper extends BaseMapper<VoteResult> {
+    VoteResult findByVoteId(long voteId);
+}

+ 11 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/dto/VoteDto.java

@@ -0,0 +1,11 @@
+package cn.reghao.tnb.content.app.data.model.dto;
+
+import lombok.Getter;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:13:45
+ */
+@Getter
+public class VoteDto {
+}

+ 8 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/dto/VoteProgressDto.java

@@ -0,0 +1,8 @@
+package cn.reghao.tnb.content.app.data.model.dto;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:14:29
+ */
+public class VoteProgressDto {
+}

+ 20 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/Vote.java

@@ -0,0 +1,20 @@
+package cn.reghao.tnb.content.app.data.model.po;
+
+import cn.reghao.jutil.jdk.db.BaseObject;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:02:28
+ */
+public class Vote extends BaseObject<Integer> {
+    private Long voteId;
+    private String title;
+    private Integer expectNum;
+    private Integer actualNum;
+    private Long startTime;
+    private Long endTime;
+    private Integer status;
+    private String result;
+    private Long createAt;
+    private Long createBy;
+}

+ 13 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/VoteOption.java

@@ -0,0 +1,13 @@
+package cn.reghao.tnb.content.app.data.model.po;
+
+import cn.reghao.jutil.jdk.db.BaseObject;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:02:49
+ */
+public class VoteOption extends BaseObject<Integer> {
+    private Long voteId;
+    private Long optionId;
+    private String name;
+}

+ 14 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/model/po/VoteResult.java

@@ -0,0 +1,14 @@
+package cn.reghao.tnb.content.app.data.model.po;
+
+import cn.reghao.jutil.jdk.db.BaseObject;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:02:55
+ */
+public class VoteResult extends BaseObject<Integer> {
+    private Long voteId;
+    private Long optionId;
+    private Long voteAt;
+    private Long voteBy;
+}

+ 41 - 0
content/content-service/src/main/java/cn/reghao/tnb/content/app/data/service/VoteService.java

@@ -0,0 +1,41 @@
+package cn.reghao.tnb.content.app.data.service;
+
+import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.tnb.content.app.data.db.mapper.VoteMapper;
+import cn.reghao.tnb.content.app.data.db.mapper.VoteOptionMapper;
+import cn.reghao.tnb.content.app.data.db.mapper.VoteResultMapper;
+import cn.reghao.tnb.content.app.data.model.dto.VoteDto;
+import cn.reghao.tnb.content.app.data.model.dto.VoteProgressDto;
+import cn.reghao.tnb.content.app.data.model.po.Vote;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author reghao
+ * @date 2025-08-05 17:09:44
+ */
+@Service
+public class VoteService {
+    private VoteMapper voteMapper;
+    private VoteOptionMapper voteOptionMapper;
+    private VoteResultMapper voteResultMapper;
+
+    public VoteService(VoteMapper voteMapper, VoteOptionMapper voteOptionMapper, VoteResultMapper voteResultMapper) {
+        this.voteMapper = voteMapper;
+        this.voteOptionMapper = voteOptionMapper;
+        this.voteResultMapper = voteResultMapper;
+    }
+
+    public void createVote(VoteDto voteDto) {
+    }
+
+    public PageList<Vote> getVoteList(int pn) {
+        return PageList.empty();
+    }
+
+    public Vote getVote(long voteId) {
+        return null;
+    }
+
+    public void progressVote(VoteProgressDto voteProgressDto) {
+    }
+}

+ 23 - 0
content/content-service/src/main/resources/mapper/data/VoteMapper.xml

@@ -0,0 +1,23 @@
+<?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="cn.reghao.tnb.content.app.data.db.mapper.VoteMapper">
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        insert into aaa_vote
+        (`vote_id`,`title`,`expect_num`,`actual_num`,`start_time`,`end_time`,`status`,`result`,`create_at`,`create_by`)
+        values 
+        (#{voteId},#{title},#{expectNum},#{actualNum},#{startTime},#{endTime},#{status},#{result},#{createAt},#{createBy})
+    </insert>
+    
+    <select id="findAll" resultType="cn.reghao.tnb.content.app.data.model.po.Vote">
+        select *
+        from aaa_vote
+        where `status`=1
+        limit 10
+    </select>
+    <select id="findByVoteId" resultType="cn.reghao.tnb.content.app.data.model.po.Vote">
+        select *
+        from aaa_vote
+        where vote_id=#{voteId}
+    </select>
+</mapper>

+ 23 - 0
content/content-service/src/main/resources/mapper/data/VoteOptionMapper.xml

@@ -0,0 +1,23 @@
+<?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="cn.reghao.tnb.content.app.data.db.mapper.VoteOptionMapper">
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        insert into aaa_vote_option
+        (`vote_id`,`option_id`,`pos`,`name`)
+        values 
+        (#{voteId},#{optionId},#{pos},#{name})
+    </insert>
+    
+    <select id="findAll" resultType="cn.reghao.tnb.content.app.data.model.po.VoteOption">
+        select *
+        from aaa_vote_option
+        limit 10
+    </select>
+    <select id="findByVoteId" resultType="cn.reghao.tnb.content.app.data.model.po.VoteOption">
+        select *
+        from aaa_vote_option
+        where vote_id=#{voteId}
+        order by pos asc
+    </select>
+</mapper>

+ 22 - 0
content/content-service/src/main/resources/mapper/data/VoteResultMapper.xml

@@ -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="cn.reghao.tnb.content.app.data.db.mapper.VoteResultMapper">
+    <insert id="save" useGeneratedKeys="true" keyProperty="id">
+        insert into aaa_vote_result
+        (`vote_id`,`option_id`,`vote_at`,`vote_by`)
+        values 
+        (#{voteId},#{optionId},#{voteAt},#{voteBy})
+    </insert>
+    
+    <select id="findAll" resultType="cn.reghao.tnb.content.app.data.model.po.VoteResult">
+        select *
+        from aaa_vote_result
+        limit 10
+    </select>
+    <select id="findByVoteId" resultType="cn.reghao.tnb.content.app.data.model.po.VoteResult">
+        select *
+        from aaa_vote_result
+        where vote_id=#{voteId}
+    </select>
+</mapper>