add: 习惯curd

This commit is contained in:
kkunkka
2025-10-10 14:49:34 +08:00
parent 79c0e37b87
commit affb754ae4
8 changed files with 100 additions and 2 deletions

View File

@@ -6,9 +6,21 @@ CREATE TABLE if not exists `goal`
status enum ('DOING', 'DONE', 'CANCEL') default 'DOING' not null,
create_time DATETIME NULL,
update_time DATETIME NULL,
type enum('GOAL', 'TASK', 'HABIT') default 'TASK' NOT NULL ,
type enum ('GOAL', 'TASK', 'HABIT') default 'TASK' NOT NULL,
name varchar(100) NOT NULL,
tag varchar(100) NULL,
detail varchar(100) NULL
)
COMMENT ='目标管理表';
COMMENT ='目标管理表';
drop table if exists `habit_record`;
create table habit_record
(
id int unsigned auto_increment
primary key,
create_time datetime null,
update_time datetime null,
goal_id int unsigned not null
)
comment '习惯记录表';

View File

@@ -0,0 +1,29 @@
package com.dota.nexus.controller;
import com.dota.nexus.entity.HabitRecord;
import com.dota.nexus.entity.R;
import com.dota.nexus.service.HabitRecordService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
@RestController("habit_record")
public class HabitRecordController {
HabitRecordService habitRecordService;
public HabitRecordController(HabitRecordService habitRecordService) {
this.habitRecordService = habitRecordService;
}
@PostMapping()
public R addHabitRecord(Integer id) {
var habit = new HabitRecord();
habit.setCreateTime(LocalDateTime.now());
habit.setUpdateTime(LocalDateTime.now());
habit.setGoalId(id);
habitRecordService.save(habit);
return R.ok();
}
}

View File

@@ -0,0 +1,10 @@
package com.dota.nexus.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class HabitRecord extends Entity {
private Integer goalId;
}

View File

@@ -0,0 +1,9 @@
package com.dota.nexus.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dota.nexus.entity.HabitRecord;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface HabitRecordMapper extends BaseMapper<HabitRecord> {
}

View File

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.dota.nexus.entity.Goal;
public interface GoalService extends IService<Goal> {
void delGoal(Integer id);
void doneGoal(Integer id);
void doingGoal(Integer id);

View File

@@ -0,0 +1,7 @@
package com.dota.nexus.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.dota.nexus.entity.HabitRecord;
public interface HabitRecordService extends IService<HabitRecord> {
}

View File

@@ -1,15 +1,33 @@
package com.dota.nexus.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dota.nexus.entity.Goal;
import com.dota.nexus.entity.GoalStatusEnum;
import com.dota.nexus.entity.HabitRecord;
import com.dota.nexus.mapper.GoalMapper;
import com.dota.nexus.mapper.HabitRecordMapper;
import com.dota.nexus.service.GoalService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class GoalServiceImpl extends ServiceImpl<GoalMapper, Goal> implements GoalService {
HabitRecordMapper habitRecordMapper;
public GoalServiceImpl(HabitRecordMapper habitRecordMapper) {
this.habitRecordMapper = habitRecordMapper;
}
@Override
@Transactional
public void delGoal(Integer id) {
removeById(id);
var q = new LambdaQueryWrapper<HabitRecord>();
q.eq(HabitRecord::getGoalId, id);
habitRecordMapper.delete(q);
}
@Override
public void doneGoal(Integer id) {

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.HabitRecord;
import com.dota.nexus.mapper.HabitRecordMapper;
import com.dota.nexus.service.HabitRecordService;
import org.springframework.stereotype.Service;
@Service
public class HabitRecordServiceImpl extends ServiceImpl<HabitRecordMapper, HabitRecord> implements HabitRecordService {
}