From ef224aa546a27ceeed07c7cd099ccee4bbd80b7f Mon Sep 17 00:00:00 2001 From: jsh <1209700525@qq.com> Date: Sat, 11 Oct 2025 16:18:18 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=91=A8=E5=B9=B4=E7=BA=AA=E5=BF=B5?= =?UTF-8?q?=E6=97=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/schema.sql | 15 +++++++- .../controller/AnniversaryController.java | 34 +++++++++++++++++++ .../dota/nexus/controller/GoalController.java | 10 +++--- .../controller/HabitRecordController.java | 6 ++-- .../com/dota/nexus/entity/Anniversary.java | 14 ++++++++ .../dota/nexus/entity/AnniversaryEnum.java | 15 ++++++++ src/main/java/com/dota/nexus/entity/R.java | 29 +++++++++++++--- .../dota/nexus/mapper/AnniversaryMapper.java | 9 +++++ .../nexus/service/AnniversaryService.java | 7 ++++ .../service/impl/AnniversaryServiceImpl.java | 11 ++++++ 10 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/dota/nexus/controller/AnniversaryController.java create mode 100644 src/main/java/com/dota/nexus/entity/Anniversary.java create mode 100644 src/main/java/com/dota/nexus/entity/AnniversaryEnum.java create mode 100644 src/main/java/com/dota/nexus/mapper/AnniversaryMapper.java create mode 100644 src/main/java/com/dota/nexus/service/AnniversaryService.java create mode 100644 src/main/java/com/dota/nexus/service/impl/AnniversaryServiceImpl.java diff --git a/db/schema.sql b/db/schema.sql index ac8c105..c768053 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -25,4 +25,17 @@ create table habit_record update_time datetime null, goal_id int unsigned not null ) - comment '习惯记录表'; \ No newline at end of file + comment '习惯记录表'; + + drop table if exists `anniversary` + + create table `anniversary` + ( + id int unsigned auto_increment, + create_time datetime null, + update_time datetime null, + date date not null comment '重要的日期', + type enum ('anniversary', 'commemoration') default 'anniversary' not null + ) + comment '周年纪念日'; + diff --git a/src/main/java/com/dota/nexus/controller/AnniversaryController.java b/src/main/java/com/dota/nexus/controller/AnniversaryController.java new file mode 100644 index 0000000..80454d7 --- /dev/null +++ b/src/main/java/com/dota/nexus/controller/AnniversaryController.java @@ -0,0 +1,34 @@ +package com.dota.nexus.controller; + +import com.dota.nexus.entity.Anniversary; +import com.dota.nexus.entity.R; +import com.dota.nexus.service.AnniversaryService; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("anniversary") +public class AnniversaryController { + AnniversaryService anniversaryService; + + public AnniversaryController(AnniversaryService anniversaryService) { + this.anniversaryService = anniversaryService; + } + + @PostMapping + public R add(Anniversary anniversary) { + anniversaryService.save(anniversary); + return R.ok(); + } + + @DeleteMapping + public R del(Integer id) { + anniversaryService.removeById(id); + return R.ok(); + } + + @PutMapping + public R update(Anniversary anniversary) { + anniversaryService.saveOrUpdate(anniversary); + return R.ok(); + } +} diff --git a/src/main/java/com/dota/nexus/controller/GoalController.java b/src/main/java/com/dota/nexus/controller/GoalController.java index 4fe93de..63fce52 100644 --- a/src/main/java/com/dota/nexus/controller/GoalController.java +++ b/src/main/java/com/dota/nexus/controller/GoalController.java @@ -3,12 +3,10 @@ package com.dota.nexus.controller; import com.dota.nexus.entity.Goal; import com.dota.nexus.entity.R; import com.dota.nexus.service.GoalService; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; -@RestController("goal") +@RestController +@RequestMapping("goal") public class GoalController { GoalService goalService; @@ -19,7 +17,7 @@ public class GoalController { /** * 新增目标 */ - @GetMapping + @PostMapping public R addGoal(Goal goal) { goalService.save(goal); return R.ok(); diff --git a/src/main/java/com/dota/nexus/controller/HabitRecordController.java b/src/main/java/com/dota/nexus/controller/HabitRecordController.java index 3d6e7ac..94068bd 100644 --- a/src/main/java/com/dota/nexus/controller/HabitRecordController.java +++ b/src/main/java/com/dota/nexus/controller/HabitRecordController.java @@ -5,11 +5,13 @@ import com.dota.nexus.entity.R; import com.dota.nexus.service.HabitRecordService; 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 java.time.LocalDateTime; -@RestController("habit_record") +@RestController +@RequestMapping("habit") public class HabitRecordController { HabitRecordService habitRecordService; @@ -25,7 +27,7 @@ public class HabitRecordController { return R.ok(habitRecordService.getHabitRecordsByGoalId(id)); } - @PostMapping() + @PostMapping public R addHabitRecord(Integer id) { var habit = new HabitRecord(); habit.setCreateTime(LocalDateTime.now()); diff --git a/src/main/java/com/dota/nexus/entity/Anniversary.java b/src/main/java/com/dota/nexus/entity/Anniversary.java new file mode 100644 index 0000000..c1ce082 --- /dev/null +++ b/src/main/java/com/dota/nexus/entity/Anniversary.java @@ -0,0 +1,14 @@ +package com.dota.nexus.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDate; + +@Data +@EqualsAndHashCode(callSuper = true) +public class Anniversary extends Entity{ + private LocalDate date; + + private type; +} diff --git a/src/main/java/com/dota/nexus/entity/AnniversaryEnum.java b/src/main/java/com/dota/nexus/entity/AnniversaryEnum.java new file mode 100644 index 0000000..6d0fc92 --- /dev/null +++ b/src/main/java/com/dota/nexus/entity/AnniversaryEnum.java @@ -0,0 +1,15 @@ +package com.dota.nexus.entity; + +import lombok.Getter; + +@Getter +public enum AnniversaryEnum { + ANNIVERSARY("周年日"), + COMMEMORATION("纪念日"); + + private String value; + + AnniversaryEnum(String value) { + this.value = value; + } +} diff --git a/src/main/java/com/dota/nexus/entity/R.java b/src/main/java/com/dota/nexus/entity/R.java index 897dabd..1771b85 100644 --- a/src/main/java/com/dota/nexus/entity/R.java +++ b/src/main/java/com/dota/nexus/entity/R.java @@ -8,15 +8,34 @@ public class R { private String msg; private Object data; + public R(Integer code, String msg){ + this.code = code; + this.msg = msg; + } + + public R (Integer code, String msg, Object data) { + this.code = code; + this.msg = msg; + this.data = data; + } + public static R ok() { return ok(null); } public static R ok(Object data) { - var r = new R(); - r.setCode(200); - r.setMsg("ok"); - r.setData(data); - return r; + return new R(200, "ok", data); } + + public static R error(){ + return new R(500, "服务端发生未知错误"); + } + + public static R unauthorized() { + return new R(401, "未授权,客户端没有提供认证信息"); + } + + public static R forbidden(){ + return new R(403, "没有权限"); + } } diff --git a/src/main/java/com/dota/nexus/mapper/AnniversaryMapper.java b/src/main/java/com/dota/nexus/mapper/AnniversaryMapper.java new file mode 100644 index 0000000..612981b --- /dev/null +++ b/src/main/java/com/dota/nexus/mapper/AnniversaryMapper.java @@ -0,0 +1,9 @@ +package com.dota.nexus.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.dota.nexus.entity.Anniversary; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface AnniversaryMapper extends BaseMapper { +} diff --git a/src/main/java/com/dota/nexus/service/AnniversaryService.java b/src/main/java/com/dota/nexus/service/AnniversaryService.java new file mode 100644 index 0000000..16c43b3 --- /dev/null +++ b/src/main/java/com/dota/nexus/service/AnniversaryService.java @@ -0,0 +1,7 @@ +package com.dota.nexus.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.dota.nexus.entity.Anniversary; + +public interface AnniversaryService extends IService { +} diff --git a/src/main/java/com/dota/nexus/service/impl/AnniversaryServiceImpl.java b/src/main/java/com/dota/nexus/service/impl/AnniversaryServiceImpl.java new file mode 100644 index 0000000..8e7ad45 --- /dev/null +++ b/src/main/java/com/dota/nexus/service/impl/AnniversaryServiceImpl.java @@ -0,0 +1,11 @@ +package com.dota.nexus.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.dota.nexus.entity.Anniversary; +import com.dota.nexus.mapper.AnniversaryMapper; +import com.dota.nexus.service.AnniversaryService; +import org.springframework.stereotype.Service; + +@Service +public class AnniversaryServiceImpl extends ServiceImpl implements AnniversaryService { +}