refactor: 目标,任务,习惯都放一张表中
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
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,
|
||||
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
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_0900_ai_ci
|
||||
COMMENT ='目标管理表';
|
||||
COMMENT ='目标管理表';
|
@@ -6,7 +6,9 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class Goal extends Entity {
|
||||
private GoalEnum status;
|
||||
private GoalStatusEnum status;
|
||||
|
||||
private GoalTypeEnum type;
|
||||
|
||||
private String name;
|
||||
|
||||
|
@@ -3,14 +3,14 @@ package com.dota.nexus.entity;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum GoalEnum {
|
||||
public enum GoalStatusEnum {
|
||||
DOING("进行中"),
|
||||
DONE("完成"),
|
||||
CANCEL("已取消");
|
||||
|
||||
private final String value;
|
||||
|
||||
GoalEnum(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;
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@ package com.dota.nexus.service.impl;
|
||||
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.GoalEnum;
|
||||
import com.dota.nexus.entity.GoalStatusEnum;
|
||||
import com.dota.nexus.mapper.GoalMapper;
|
||||
import com.dota.nexus.service.GoalService;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,20 +13,20 @@ public class GoalServiceImpl extends ServiceImpl<GoalMapper, Goal> implements Go
|
||||
|
||||
@Override
|
||||
public void doneGoal(Integer id) {
|
||||
updateStatus(id, GoalEnum.DONE);
|
||||
updateStatus(id, GoalStatusEnum.DONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doingGoal(Integer id) {
|
||||
updateStatus(id, GoalEnum.DOING);
|
||||
updateStatus(id, GoalStatusEnum.DOING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelGoal(Integer id) {
|
||||
updateStatus(id, GoalEnum.CANCEL);
|
||||
updateStatus(id, GoalStatusEnum.CANCEL);
|
||||
}
|
||||
|
||||
private void updateStatus(Integer id, GoalEnum status) {
|
||||
private void updateStatus(Integer id, GoalStatusEnum status) {
|
||||
var update = new LambdaUpdateWrapper<Goal>();
|
||||
update.eq(Goal::getId, id);
|
||||
update.set(Goal::getStatus, status);
|
||||
|
@@ -3,7 +3,7 @@ package com.dota.nexus.mapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.dota.nexus.entity.Goal;
|
||||
import com.dota.nexus.entity.GoalEnum;
|
||||
import com.dota.nexus.entity.GoalStatusEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -20,7 +20,7 @@ public class GoalMapperTest {
|
||||
@Test
|
||||
public void testInsert() {
|
||||
var g = new Goal();
|
||||
g.setStatus(GoalEnum.DONE);
|
||||
g.setStatus(GoalStatusEnum.DONE);
|
||||
g.setCreateTime(LocalDateTime.now());
|
||||
g.setTag("test");
|
||||
g.setName("测试");
|
||||
|
Reference in New Issue
Block a user