add: 习惯curd
This commit is contained in:
@@ -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 '习惯记录表';
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
10
src/main/java/com/dota/nexus/entity/HabitRecord.java
Normal file
10
src/main/java/com/dota/nexus/entity/HabitRecord.java
Normal 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;
|
||||
}
|
@@ -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> {
|
||||
}
|
@@ -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);
|
||||
|
@@ -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> {
|
||||
}
|
@@ -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) {
|
||||
|
@@ -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 {
|
||||
}
|
Reference in New Issue
Block a user