|
|
@@ -0,0 +1,61 @@
|
|
|
+package com.etotem.cfc.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.etotem.cfc.entity.FatGoal;
|
|
|
+import com.etotem.cfc.mapper.FatGoalMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class FatGoalService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FatGoalMapper fatGoalMapper;
|
|
|
+
|
|
|
+ public FatGoal getActive(Long memberId) {
|
|
|
+ return fatGoalMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<FatGoal>()
|
|
|
+ .eq(FatGoal::getMemberId, memberId)
|
|
|
+ .eq(FatGoal::getStatus, "active")
|
|
|
+ .orderByDesc(FatGoal::getCreatedAt)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public FatGoal create(FatGoal goal) {
|
|
|
+ goal.setStatus("active");
|
|
|
+ goal.setCreatedAt(new Date());
|
|
|
+ goal.setUpdatedAt(new Date());
|
|
|
+ fatGoalMapper.insert(goal);
|
|
|
+ return goal;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FatGoal update(FatGoal goal) {
|
|
|
+ goal.setUpdatedAt(new Date());
|
|
|
+ fatGoalMapper.updateById(goal);
|
|
|
+ return goal;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 完成目标 */
|
|
|
+ public FatGoal complete(Long id) {
|
|
|
+ FatGoal goal = fatGoalMapper.selectById(id);
|
|
|
+ if (goal != null) {
|
|
|
+ goal.setStatus("completed");
|
|
|
+ goal.setUpdatedAt(new Date());
|
|
|
+ fatGoalMapper.updateById(goal);
|
|
|
+ }
|
|
|
+ return goal;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 放弃目标 */
|
|
|
+ public FatGoal abandon(Long id) {
|
|
|
+ FatGoal goal = fatGoalMapper.selectById(id);
|
|
|
+ if (goal != null) {
|
|
|
+ goal.setStatus("abandoned");
|
|
|
+ goal.setUpdatedAt(new Date());
|
|
|
+ fatGoalMapper.updateById(goal);
|
|
|
+ }
|
|
|
+ return goal;
|
|
|
+ }
|
|
|
+}
|