add: 周年纪念日

This commit is contained in:
jsh
2025-10-11 16:18:18 +08:00
parent 8a120a7223
commit ef224aa546
10 changed files with 136 additions and 14 deletions

View File

@@ -26,3 +26,16 @@ create table habit_record
goal_id int unsigned not null
)
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 '周年纪念日';

View File

@@ -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();
}
}

View File

@@ -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();

View File

@@ -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());

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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, "没有权限");
}
}

View File

@@ -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<Anniversary> {
}

View File

@@ -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<Anniversary> {
}

View File

@@ -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<AnniversaryMapper, Anniversary> implements AnniversaryService {
}