Compare commits
5 Commits
9e20d0f5f8
...
82e1f2deb4
Author | SHA1 | Date | |
---|---|---|---|
![]() |
82e1f2deb4 | ||
![]() |
affb754ae4 | ||
![]() |
79c0e37b87 | ||
![]() |
b9cb079139 | ||
![]() |
f86462bb24 |
@@ -1,16 +1,28 @@
|
||||
drop table if exists `goals`;
|
||||
drop table if exists `goal`;
|
||||
|
||||
CREATE TABLE if not exists `goals`
|
||||
CREATE TABLE if not exists `goal`
|
||||
(
|
||||
id INT auto_increment NOT NULL PRIMARY KEY,
|
||||
status tinyint default 0 COMMENT '0:进行中,1:已完成,2已取消',
|
||||
create_time DATETIME NULL,
|
||||
update_time DATETIME NULL,
|
||||
name varchar(100) NOT NULL,
|
||||
tag varchar(100) NULL,
|
||||
detail varchar(100) NULL
|
||||
id INT unsigned auto_increment PRIMARY KEY,
|
||||
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,
|
||||
name varchar(100) NOT NULL,
|
||||
tag varchar(100) NULL,
|
||||
detail varchar(100) NULL,
|
||||
root_id int unsigned null,
|
||||
parent_id int unsigned null
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_0900_ai_ci
|
||||
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 '习惯记录表';
|
64
src/main/java/com/dota/nexus/controller/GoalController.java
Normal file
64
src/main/java/com/dota/nexus/controller/GoalController.java
Normal file
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
|
||||
@RestController("goal")
|
||||
public class GoalController {
|
||||
GoalService goalService;
|
||||
|
||||
public GoalController(GoalService goalService) {
|
||||
this.goalService = goalService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增目标
|
||||
*/
|
||||
@GetMapping
|
||||
public R addGoal(Goal goal) {
|
||||
goalService.save(goal);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除目标
|
||||
*/
|
||||
@DeleteMapping
|
||||
public R deleteGoal(Integer id) {
|
||||
goalService.removeById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成目标
|
||||
*/
|
||||
@PostMapping("done")
|
||||
public R doneGoal(Integer id) {
|
||||
goalService.doneGoal(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标进行中
|
||||
*/
|
||||
@PostMapping("doing")
|
||||
public R doingGoal(Integer id) {
|
||||
goalService.doingGoal(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消目标
|
||||
*/
|
||||
@PostMapping("cancel")
|
||||
public R cancelGoal(Integer id) {
|
||||
goalService.cancelGoal(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
@@ -1,15 +1,16 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Entity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
Integer id;
|
||||
|
||||
Integer status;
|
||||
|
||||
LocalDateTime createTime;
|
||||
|
||||
LocalDateTime updateTime;
|
||||
|
@@ -6,9 +6,17 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Goal extends Entity {
|
||||
private GoalStatusEnum status;
|
||||
|
||||
private GoalTypeEnum type;
|
||||
|
||||
private String name;
|
||||
|
||||
private String tag;
|
||||
|
||||
private String detail;
|
||||
|
||||
private Integer rootId;
|
||||
|
||||
private Integer parentId;
|
||||
}
|
||||
|
16
src/main/java/com/dota/nexus/entity/GoalStatusEnum.java
Normal file
16
src/main/java/com/dota/nexus/entity/GoalStatusEnum.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum GoalStatusEnum {
|
||||
DOING("进行中"),
|
||||
DONE("完成"),
|
||||
CANCEL("已取消");
|
||||
|
||||
private final String value;
|
||||
|
||||
GoalStatusEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
13
src/main/java/com/dota/nexus/entity/GoalTypeEnum.java
Normal file
13
src/main/java/com/dota/nexus/entity/GoalTypeEnum.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
public enum GoalTypeEnum {
|
||||
GOAL("目标"),
|
||||
TASK("任务"),
|
||||
HABIT("习惯");
|
||||
|
||||
private String value;
|
||||
|
||||
GoalTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
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;
|
||||
}
|
22
src/main/java/com/dota/nexus/entity/R.java
Normal file
22
src/main/java/com/dota/nexus/entity/R.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.dota.nexus.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class R {
|
||||
private Integer code;
|
||||
private String msg;
|
||||
private Object 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;
|
||||
}
|
||||
}
|
@@ -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,4 +4,11 @@ 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);
|
||||
|
||||
void cancelGoal(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,10 +1,53 @@
|
||||
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) {
|
||||
updateStatus(id, GoalStatusEnum.DONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doingGoal(Integer id) {
|
||||
updateStatus(id, GoalStatusEnum.DOING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelGoal(Integer id) {
|
||||
updateStatus(id, GoalStatusEnum.CANCEL);
|
||||
}
|
||||
|
||||
private void updateStatus(Integer id, GoalStatusEnum status) {
|
||||
var update = new LambdaUpdateWrapper<Goal>();
|
||||
update.eq(Goal::getId, id);
|
||||
update.set(Goal::getStatus, status);
|
||||
this.baseMapper.update(update);
|
||||
}
|
||||
}
|
@@ -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 {
|
||||
}
|
@@ -1,10 +1,9 @@
|
||||
package com.dota.nexus.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.dota.nexus.entity.Goal;
|
||||
import com.dota.nexus.entity.GoalStatusEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -21,7 +20,7 @@ public class GoalMapperTest {
|
||||
@Test
|
||||
public void testInsert() {
|
||||
var g = new Goal();
|
||||
g.setStatus(1);
|
||||
g.setStatus(GoalStatusEnum.DONE);
|
||||
g.setCreateTime(LocalDateTime.now());
|
||||
g.setTag("test");
|
||||
g.setName("测试");
|
||||
|
Reference in New Issue
Block a user