feat:去除部分健康记录接口
This commit is contained in:
@@ -9,7 +9,6 @@ import com.fasterxml.jackson.annotation.JsonView;
|
|||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,26 +20,14 @@ public class HealthController {
|
|||||||
@Resource
|
@Resource
|
||||||
private HealthService healthService;
|
private HealthService healthService;
|
||||||
|
|
||||||
@Operation(summary = "新增锻炼记录")
|
@Operation(summary = "更新健康记录")
|
||||||
@PostMapping("")
|
|
||||||
public Boolean addExercise(@RequestBody @JsonView(WriteView.class) @Validated HealthRecordDto dto) {
|
|
||||||
return healthService.add(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "更新锻炼记录")
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public Boolean updateExercise(@PathVariable("id") long id,
|
public Boolean updateExercise(@PathVariable("id") long id,
|
||||||
@RequestBody @JsonView(WriteView.class) HealthRecordDto dto) {
|
@RequestBody @JsonView(WriteView.class) HealthRecordDto dto) {
|
||||||
return healthService.update(id, dto);
|
return healthService.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除锻炼记录")
|
@Operation(summary = "查询健康记录")
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
public Boolean deleteExercise(@PathVariable("id") long id) {
|
|
||||||
return healthService.delete(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "查询锻炼记录")
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public @JsonView(ReadView.class) List<HealthRecordDto> queryExercise(HealthQueryVo queryVo) {
|
public @JsonView(ReadView.class) List<HealthRecordDto> queryExercise(HealthQueryVo queryVo) {
|
||||||
return healthService.query(queryVo);
|
return healthService.query(queryVo);
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.cxx.home.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.cxx.framework.data.AbstractEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@TableName("exercise_record")
|
|
||||||
public class ExerciseRecord extends AbstractEntity {
|
|
||||||
@TableField("project")
|
|
||||||
private String project;
|
|
||||||
|
|
||||||
@TableField("duration")
|
|
||||||
private Integer duration;
|
|
||||||
|
|
||||||
@TableField("date")
|
|
||||||
private LocalDate date;
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.cxx.home.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.cxx.framework.data.AbstractEntity;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@TableName("weight_record")
|
|
||||||
public class WeightRecord extends AbstractEntity {
|
|
||||||
@TableField("value")
|
|
||||||
private Double value;
|
|
||||||
|
|
||||||
@TableField("date")
|
|
||||||
private LocalDate date;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.cxx.home.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.cxx.home.entity.ExerciseRecord;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface ExerciseRecordMapper extends BaseMapper<ExerciseRecord> {
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.cxx.home.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.cxx.home.entity.WeightRecord;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface WeightRecordMapper extends BaseMapper<WeightRecord> {
|
|
||||||
}
|
|
||||||
@@ -9,9 +9,5 @@ import java.util.List;
|
|||||||
public interface HealthService {
|
public interface HealthService {
|
||||||
List<HealthRecordDto> query(HealthQueryVo queryVo);
|
List<HealthRecordDto> query(HealthQueryVo queryVo);
|
||||||
|
|
||||||
Boolean add(HealthRecordDto dto);
|
|
||||||
|
|
||||||
Boolean update(Long id, HealthRecordDto dto);
|
Boolean update(Long id, HealthRecordDto dto);
|
||||||
|
|
||||||
Boolean delete(Long id);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.cxx.home.service.impl;
|
|||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.cxx.framework.web.CustomException;
|
|
||||||
import com.cxx.home.converter.HealthConverter;
|
import com.cxx.home.converter.HealthConverter;
|
||||||
import com.cxx.home.dto.health.HealthRecordDto;
|
import com.cxx.home.dto.health.HealthRecordDto;
|
||||||
import com.cxx.home.entity.HealthRecord;
|
import com.cxx.home.entity.HealthRecord;
|
||||||
@@ -37,30 +36,22 @@ public class HealthServiceImpl implements HealthService {
|
|||||||
return healthConverter.toDtos(healthRecordMapper.selectList(queryWrapper));
|
return healthConverter.toDtos(healthRecordMapper.selectList(queryWrapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean add(HealthRecordDto dto) {
|
|
||||||
HealthRecord healthRecord = new HealthRecord();
|
|
||||||
BeanUtils.copyProperties(dto, healthRecord);
|
|
||||||
|
|
||||||
return healthRecordMapper.insert(healthRecord) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean update(Long id, HealthRecordDto dto) {
|
public Boolean update(Long id, HealthRecordDto dto) {
|
||||||
if (!healthRecordMapper.exists(new LambdaQueryWrapper<HealthRecord>()
|
|
||||||
.eq(HealthRecord::getId, id))) {
|
|
||||||
throw new CustomException("记录不存在");
|
|
||||||
}
|
|
||||||
|
|
||||||
HealthRecord healthRecord = new HealthRecord();
|
HealthRecord healthRecord = new HealthRecord();
|
||||||
BeanUtils.copyProperties(dto, healthRecord);
|
|
||||||
healthRecord.setId(id);
|
|
||||||
|
|
||||||
return healthRecordMapper.updateById(healthRecord) == 1;
|
if (id == 0) {
|
||||||
}
|
BeanUtils.copyProperties(dto, healthRecord);
|
||||||
|
return healthRecordMapper.insert(healthRecord) == 1;
|
||||||
@Override
|
} else {
|
||||||
public Boolean delete(Long id) {
|
if ((dto.getSportProject() == null || dto.getSportProject().isEmpty())
|
||||||
return healthRecordMapper.deleteById(id) == 1;
|
&& dto.getSportDuration() == 0 && dto.getWeight() == 0) {
|
||||||
|
return healthRecordMapper.deleteById(id) == 1;
|
||||||
|
} else {
|
||||||
|
BeanUtils.copyProperties(dto, healthRecord);
|
||||||
|
healthRecord.setId(id);
|
||||||
|
return healthRecordMapper.updateById(healthRecord) == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user