优化行为
This commit is contained in:
1 parent
1ed38c6648
commit
80c73fd46c
44 files changed
+2742
-198
No files matched your search
@@ -55,6 +55,20 @@ public class BabyService {
|
||||
return BabyConvert.toVOList(babies);
|
||||
}
|
||||
|
||||
public List<BabyVO> listBabies(String familyId) {
|
||||
if (familyId == null || familyId.trim().isEmpty()) {
|
||||
return listBabies();
|
||||
}
|
||||
List<BabyProfile> babies = babyMapper.selectList(
|
||||
new LambdaQueryWrapper<BabyProfile>()
|
||||
.eq(BabyProfile::getFamilyId, familyId)
|
||||
.eq(BabyProfile::getStatus, "active")
|
||||
.orderByDesc(BabyProfile::getIsDefault)
|
||||
.orderByAsc(BabyProfile::getBabyId)
|
||||
);
|
||||
return BabyConvert.toVOList(babies);
|
||||
}
|
||||
|
||||
public BabyVO updateCurrentBaby(UpdateBabyRO request) {
|
||||
BabyProfile currentBaby = getCurrentBabyEntity();
|
||||
return updateBaby(currentBaby.getBabyId(), request);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.babytracker.module.family;
|
||||
|
||||
import com.babytracker.common.model.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("care_quick_rule")
|
||||
public class CareQuickRule extends BaseEntity {
|
||||
/**
|
||||
* 常用补记规则ID,雪花ID字符串
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
private String ruleId;
|
||||
|
||||
/**
|
||||
* 家庭ID
|
||||
*/
|
||||
@TableField("family_id")
|
||||
private String familyId;
|
||||
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 动作列表,英文逗号分隔: diaper,feeding,sleep
|
||||
*/
|
||||
@TableField("actions")
|
||||
private String actions;
|
||||
|
||||
/**
|
||||
* 尿布动作相对起点偏移分钟
|
||||
*/
|
||||
@TableField("diaper_offset_minutes")
|
||||
private Integer diaperOffsetMinutes;
|
||||
|
||||
/**
|
||||
* 喂奶动作相对起点偏移分钟
|
||||
*/
|
||||
@TableField("feeding_offset_minutes")
|
||||
private Integer feedingOffsetMinutes;
|
||||
|
||||
/**
|
||||
* 喂奶结束后多久开始睡眠
|
||||
*/
|
||||
@TableField("sleep_after_feeding_minutes")
|
||||
private Integer sleepAfterFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@TableField("enabled")
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
package com.babytracker.module.family;
|
||||
|
||||
import com.babytracker.common.response.ApiResponse;
|
||||
import com.babytracker.module.family.ro.CreateFamilyRO;
|
||||
import com.babytracker.module.family.ro.CreateMemberRO;
|
||||
import com.babytracker.module.family.ro.DeleteCareQuickRuleRO;
|
||||
import com.babytracker.module.family.ro.DeleteMemberRO;
|
||||
import com.babytracker.module.family.ro.JoinFamilyRO;
|
||||
import com.babytracker.module.family.ro.SaveCareQuickRuleRO;
|
||||
import com.babytracker.module.family.ro.UpdateFamilyRO;
|
||||
import com.babytracker.module.family.ro.UpdateMemberRO;
|
||||
import com.babytracker.module.family.vo.CareQuickRuleVO;
|
||||
import com.babytracker.module.family.vo.FamilyContextVO;
|
||||
import com.babytracker.module.family.vo.FamilyMemberVO;
|
||||
import com.babytracker.module.family.vo.FamilyVO;
|
||||
@@ -16,8 +21,11 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Validated
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -26,8 +34,18 @@ public class FamilyController {
|
||||
private final FamilyService familyService;
|
||||
|
||||
@GetMapping("/current-context")
|
||||
public ApiResponse<FamilyContextVO> currentContext() {
|
||||
return ApiResponse.ok(familyService.getCurrentContext());
|
||||
public ApiResponse<FamilyContextVO> currentContext(@RequestParam(required = false) String familyId) {
|
||||
return ApiResponse.ok(familyService.getCurrentContext(familyId));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ApiResponse<FamilyContextVO> createFamily(@Valid @RequestBody CreateFamilyRO request) {
|
||||
return ApiResponse.ok(familyService.createFamily(request));
|
||||
}
|
||||
|
||||
@PostMapping("/join")
|
||||
public ApiResponse<FamilyContextVO> joinFamily(@Valid @RequestBody JoinFamilyRO request) {
|
||||
return ApiResponse.ok(familyService.joinFamily(request));
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@@ -50,4 +68,20 @@ public class FamilyController {
|
||||
familyService.deleteMember(request.getFamilyId(), request.getMemberId());
|
||||
return ApiResponse.ok(null);
|
||||
}
|
||||
|
||||
@GetMapping("/quick-rules")
|
||||
public ApiResponse<List<CareQuickRuleVO>> listQuickRules(@RequestParam(required = false) String familyId) {
|
||||
return ApiResponse.ok(familyService.listQuickRules(familyId));
|
||||
}
|
||||
|
||||
@PostMapping("/quick-rules")
|
||||
public ApiResponse<CareQuickRuleVO> saveQuickRule(@Valid @RequestBody SaveCareQuickRuleRO request) {
|
||||
return ApiResponse.ok(familyService.saveQuickRule(request));
|
||||
}
|
||||
|
||||
@PostMapping("/quick-rules/delete")
|
||||
public ApiResponse<Void> deleteQuickRule(@Valid @RequestBody DeleteCareQuickRuleRO request) {
|
||||
familyService.deleteQuickRule(request);
|
||||
return ApiResponse.ok(null);
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,15 @@ import com.babytracker.module.baby.BabyService;
|
||||
import com.babytracker.module.family.dto.FamilyConvert;
|
||||
import com.babytracker.module.family.mapper.FamilyMapper;
|
||||
import com.babytracker.module.family.mapper.FamilyMemberMapper;
|
||||
import com.babytracker.module.family.mapper.CareQuickRuleMapper;
|
||||
import com.babytracker.module.family.ro.CreateFamilyRO;
|
||||
import com.babytracker.module.family.ro.DeleteCareQuickRuleRO;
|
||||
import com.babytracker.module.family.ro.SaveCareQuickRuleRO;
|
||||
import com.babytracker.module.family.ro.CreateMemberRO;
|
||||
import com.babytracker.module.family.ro.JoinFamilyRO;
|
||||
import com.babytracker.module.family.ro.UpdateFamilyRO;
|
||||
import com.babytracker.module.family.ro.UpdateMemberRO;
|
||||
import com.babytracker.module.family.vo.CareQuickRuleVO;
|
||||
import com.babytracker.module.family.vo.FamilyContextVO;
|
||||
import com.babytracker.module.family.vo.FamilyMemberVO;
|
||||
import com.babytracker.module.family.vo.FamilyVO;
|
||||
@@ -17,21 +23,77 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FamilyService {
|
||||
private final FamilyMapper familyMapper;
|
||||
private final FamilyMemberMapper familyMemberMapper;
|
||||
private final CareQuickRuleMapper careQuickRuleMapper;
|
||||
private final BabyService babyService;
|
||||
private final SnowflakeIdGenerator idGenerator;
|
||||
|
||||
public FamilyContextVO getCurrentContext() {
|
||||
FamilyInfo family = getDefaultFamily();
|
||||
return getCurrentContext(null);
|
||||
}
|
||||
|
||||
public FamilyContextVO getCurrentContext(String familyId) {
|
||||
FamilyInfo family = resolveFamily(familyId);
|
||||
return buildContext(family);
|
||||
}
|
||||
|
||||
public FamilyContextVO createFamily(CreateFamilyRO request) {
|
||||
FamilyInfo family = new FamilyInfo();
|
||||
family.setFamilyId(idGenerator.nextId());
|
||||
family.setName(request.getName().trim());
|
||||
family.setInviteCode(resolveInviteCode(request.getInviteCode()));
|
||||
family.setStatus("active");
|
||||
familyMapper.insert(family);
|
||||
|
||||
FamilyMember member = new FamilyMember();
|
||||
member.setMemberId(idGenerator.nextId());
|
||||
member.setFamilyId(family.getFamilyId());
|
||||
member.setRoleName(request.getRoleName().trim());
|
||||
member.setRoleType("owner");
|
||||
member.setDefaultOperator(true);
|
||||
member.setStatus("active");
|
||||
familyMemberMapper.insert(member);
|
||||
|
||||
return buildContext(family);
|
||||
}
|
||||
|
||||
public FamilyContextVO joinFamily(JoinFamilyRO request) {
|
||||
String inviteCode = normalizeInviteCode(request.getInviteCode());
|
||||
FamilyInfo family = familyMapper.selectOne(
|
||||
new LambdaQueryWrapper<FamilyInfo>()
|
||||
.eq(FamilyInfo::getInviteCode, inviteCode)
|
||||
.eq(FamilyInfo::getStatus, "active")
|
||||
.last("LIMIT 1")
|
||||
);
|
||||
if (family == null) {
|
||||
throw new BusinessException("FAMILY_INVITE_CODE_INVALID", "未找到对应家庭");
|
||||
}
|
||||
|
||||
FamilyMember member = new FamilyMember();
|
||||
member.setMemberId(idGenerator.nextId());
|
||||
member.setFamilyId(family.getFamilyId());
|
||||
member.setRoleName(request.getRoleName().trim());
|
||||
member.setRoleType("caregiver");
|
||||
member.setDefaultOperator(false);
|
||||
member.setStatus("active");
|
||||
familyMemberMapper.insert(member);
|
||||
|
||||
return buildContext(family);
|
||||
}
|
||||
|
||||
private FamilyContextVO buildContext(FamilyInfo family) {
|
||||
FamilyContextVO context = new FamilyContextVO();
|
||||
context.setFamily(FamilyConvert.toVO(family));
|
||||
context.setBabies(babyService.listBabies());
|
||||
context.setBabies(babyService.listBabies(family.getFamilyId()));
|
||||
context.setMembers(FamilyConvert.toMemberVOList(listMembers(family.getFamilyId())));
|
||||
return context;
|
||||
}
|
||||
@@ -135,6 +197,62 @@ public class FamilyService {
|
||||
familyMemberMapper.deleteById(memberId);
|
||||
}
|
||||
|
||||
public List<CareQuickRuleVO> listQuickRules(String familyId) {
|
||||
if (familyId == null || familyId.trim().isEmpty()) {
|
||||
familyId = getDefaultFamily().getFamilyId();
|
||||
}
|
||||
List<CareQuickRule> rules = careQuickRuleMapper.selectList(
|
||||
new LambdaQueryWrapper<CareQuickRule>()
|
||||
.eq(CareQuickRule::getFamilyId, familyId)
|
||||
.orderByAsc(CareQuickRule::getSortOrder)
|
||||
.orderByAsc(CareQuickRule::getRuleId)
|
||||
);
|
||||
List<CareQuickRuleVO> result = new ArrayList<>(rules.size());
|
||||
for (CareQuickRule rule : rules) {
|
||||
result.add(toQuickRuleVO(rule));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public CareQuickRuleVO saveQuickRule(SaveCareQuickRuleRO request) {
|
||||
String familyId = request.getFamilyId();
|
||||
if (familyId == null || familyId.trim().isEmpty()) {
|
||||
familyId = getDefaultFamily().getFamilyId();
|
||||
}
|
||||
CareQuickRule rule;
|
||||
if (request.getRuleId() == null || request.getRuleId().trim().isEmpty()) {
|
||||
rule = new CareQuickRule();
|
||||
rule.setRuleId(idGenerator.nextId());
|
||||
rule.setFamilyId(familyId);
|
||||
} else {
|
||||
rule = careQuickRuleMapper.selectById(request.getRuleId());
|
||||
if (rule == null) {
|
||||
throw new BusinessException("QUICK_RULE_NOT_FOUND", "常用补记不存在");
|
||||
}
|
||||
}
|
||||
rule.setName(request.getName().trim());
|
||||
rule.setActions(String.join(",", request.getActions()));
|
||||
rule.setDiaperOffsetMinutes(request.getDiaperOffsetMinutes() == null ? 0 : request.getDiaperOffsetMinutes());
|
||||
rule.setFeedingOffsetMinutes(request.getFeedingOffsetMinutes() == null ? 5 : request.getFeedingOffsetMinutes());
|
||||
rule.setSleepAfterFeedingMinutes(request.getSleepAfterFeedingMinutes() == null ? 5 : request.getSleepAfterFeedingMinutes());
|
||||
rule.setEnabled(request.getEnabled() == null || request.getEnabled());
|
||||
rule.setSortOrder(request.getSortOrder() == null ? 100 : request.getSortOrder());
|
||||
if (request.getRuleId() == null || request.getRuleId().trim().isEmpty()) {
|
||||
careQuickRuleMapper.insert(rule);
|
||||
} else {
|
||||
careQuickRuleMapper.updateById(rule);
|
||||
}
|
||||
return toQuickRuleVO(rule);
|
||||
}
|
||||
|
||||
public void deleteQuickRule(DeleteCareQuickRuleRO request) {
|
||||
CareQuickRule rule = careQuickRuleMapper.selectById(request.getRuleId());
|
||||
if (rule == null) {
|
||||
throw new BusinessException("QUICK_RULE_NOT_FOUND", "常用补记不存在");
|
||||
}
|
||||
careQuickRuleMapper.deleteById(request.getRuleId());
|
||||
}
|
||||
|
||||
public FamilyInfo getDefaultFamily() {
|
||||
FamilyInfo family = familyMapper.selectOne(
|
||||
new LambdaQueryWrapper<FamilyInfo>()
|
||||
@@ -152,6 +270,59 @@ public class FamilyService {
|
||||
return defaultFamily;
|
||||
}
|
||||
|
||||
private FamilyInfo resolveFamily(String familyId) {
|
||||
if (familyId != null && !familyId.trim().isEmpty()) {
|
||||
FamilyInfo family = familyMapper.selectById(familyId.trim());
|
||||
if (family == null) {
|
||||
throw new BusinessException("FAMILY_NOT_FOUND", "家庭不存在");
|
||||
}
|
||||
return family;
|
||||
}
|
||||
return getDefaultFamily();
|
||||
}
|
||||
|
||||
private String resolveInviteCode(String inviteCode) {
|
||||
String normalized = normalizeInviteCode(inviteCode);
|
||||
if (!normalized.isEmpty()) {
|
||||
ensureInviteCodeUnused(normalized);
|
||||
return normalized;
|
||||
}
|
||||
String generated;
|
||||
do {
|
||||
generated = randomInviteCode();
|
||||
} while (inviteCodeExists(generated));
|
||||
return generated;
|
||||
}
|
||||
|
||||
private String normalizeInviteCode(String inviteCode) {
|
||||
return inviteCode == null ? "" : inviteCode.trim().toUpperCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private void ensureInviteCodeUnused(String inviteCode) {
|
||||
if (inviteCodeExists(inviteCode)) {
|
||||
throw new BusinessException("FAMILY_INVITE_CODE_EXISTS", "成员加入码已被使用");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inviteCodeExists(String inviteCode) {
|
||||
Long count = familyMapper.selectCount(
|
||||
new LambdaQueryWrapper<FamilyInfo>()
|
||||
.eq(FamilyInfo::getInviteCode, inviteCode)
|
||||
);
|
||||
return count != null && count > 0;
|
||||
}
|
||||
|
||||
private String randomInviteCode() {
|
||||
String chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
StringBuilder code = new StringBuilder("BT");
|
||||
long seed = Math.abs(idGenerator.nextId().hashCode());
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int index = (int) ((seed + i * 17) % chars.length());
|
||||
code.append(chars.charAt(index));
|
||||
}
|
||||
return code.toString();
|
||||
}
|
||||
|
||||
public List<FamilyMember> listMembers(String familyId) {
|
||||
List<FamilyMember> members = familyMemberMapper.selectList(
|
||||
new LambdaQueryWrapper<FamilyMember>()
|
||||
@@ -175,4 +346,21 @@ public class FamilyService {
|
||||
mom.setDefaultOperator(true);
|
||||
return List.of(mom);
|
||||
}
|
||||
|
||||
private CareQuickRuleVO toQuickRuleVO(CareQuickRule rule) {
|
||||
CareQuickRuleVO vo = new CareQuickRuleVO();
|
||||
vo.setRuleId(rule.getRuleId());
|
||||
vo.setFamilyId(rule.getFamilyId());
|
||||
vo.setName(rule.getName());
|
||||
vo.setActions(Arrays.stream(rule.getActions().split(","))
|
||||
.map(String::trim)
|
||||
.filter(item -> !item.isEmpty())
|
||||
.toList());
|
||||
vo.setDiaperOffsetMinutes(rule.getDiaperOffsetMinutes());
|
||||
vo.setFeedingOffsetMinutes(rule.getFeedingOffsetMinutes());
|
||||
vo.setSleepAfterFeedingMinutes(rule.getSleepAfterFeedingMinutes());
|
||||
vo.setEnabled(rule.getEnabled());
|
||||
vo.setSortOrder(rule.getSortOrder());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.babytracker.module.family.mapper;
|
||||
|
||||
import com.babytracker.module.family.CareQuickRule;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface CareQuickRuleMapper extends BaseMapper<CareQuickRule> {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.babytracker.module.family.ro;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateFamilyRO {
|
||||
/**
|
||||
* 家庭名称,必填
|
||||
*/
|
||||
@NotBlank(message = "家庭名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 当前用户在家庭里的称谓,必填,如宝妈、宝爸、奶奶
|
||||
*/
|
||||
@NotBlank(message = "成员称谓不能为空")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 家庭成员加入码,选填;为空时由后端生成
|
||||
*/
|
||||
private String inviteCode;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.babytracker.module.family.ro;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeleteCareQuickRuleRO {
|
||||
/**
|
||||
* 规则ID
|
||||
*/
|
||||
@NotBlank(message = "规则ID不能为空")
|
||||
private String ruleId;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.babytracker.module.family.ro;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class JoinFamilyRO {
|
||||
/**
|
||||
* 家庭成员加入码,必填
|
||||
*/
|
||||
@NotBlank(message = "成员加入码不能为空")
|
||||
private String inviteCode;
|
||||
|
||||
/**
|
||||
* 当前用户在家庭里的称谓,必填,如宝妈、宝爸、奶奶
|
||||
*/
|
||||
@NotBlank(message = "成员称谓不能为空")
|
||||
private String roleName;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.babytracker.module.family.ro;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SaveCareQuickRuleRO {
|
||||
/**
|
||||
* 规则ID,新增时为空,更新时必填
|
||||
*/
|
||||
private String ruleId;
|
||||
|
||||
/**
|
||||
* 家庭ID,可为空,默认使用当前家庭
|
||||
*/
|
||||
private String familyId;
|
||||
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
@NotBlank(message = "规则名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 动作列表: diaper, feeding, sleep
|
||||
*/
|
||||
@NotEmpty(message = "至少选择一个照护动作")
|
||||
private List<String> actions;
|
||||
|
||||
/**
|
||||
* 尿布动作相对起点偏移分钟
|
||||
*/
|
||||
private Integer diaperOffsetMinutes;
|
||||
|
||||
/**
|
||||
* 喂奶动作相对起点偏移分钟
|
||||
*/
|
||||
private Integer feedingOffsetMinutes;
|
||||
|
||||
/**
|
||||
* 喂奶结束后多久开始睡眠
|
||||
*/
|
||||
private Integer sleepAfterFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.babytracker.module.family.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CareQuickRuleVO {
|
||||
/**
|
||||
* 规则ID
|
||||
*/
|
||||
private String ruleId;
|
||||
|
||||
/**
|
||||
* 家庭ID
|
||||
*/
|
||||
private String familyId;
|
||||
|
||||
/**
|
||||
* 规则名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 动作列表
|
||||
*/
|
||||
private List<String> actions;
|
||||
|
||||
/**
|
||||
* 尿布动作相对起点偏移分钟
|
||||
*/
|
||||
private Integer diaperOffsetMinutes;
|
||||
|
||||
/**
|
||||
* 喂奶动作相对起点偏移分钟
|
||||
*/
|
||||
private Integer feedingOffsetMinutes;
|
||||
|
||||
/**
|
||||
* 喂奶结束后多久开始睡眠
|
||||
*/
|
||||
private Integer sleepAfterFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
}
|
||||
@@ -70,6 +70,18 @@ public class CareRecord extends BaseEntity {
|
||||
@TableField("right_duration_minutes")
|
||||
private Integer rightDurationMinutes;
|
||||
|
||||
/**
|
||||
* 有效喂养时长(分钟,不含暂停,仅喂养记录使用)
|
||||
*/
|
||||
@TableField("effective_feeding_minutes")
|
||||
private Integer effectiveFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 暂停片段JSON(记录暂停开始、结束与持续秒数)
|
||||
*/
|
||||
@TableField("pause_segments_json")
|
||||
private String pauseSegmentsJson;
|
||||
|
||||
/**
|
||||
* 喂奶方式: breastfeed(亲喂), bottle(瓶喂), formula(配方奶), mixed(混合喂养), other(其他)
|
||||
*/
|
||||
|
||||
@@ -69,6 +69,8 @@ public class CareRecordService {
|
||||
record.setEndTime(endTime);
|
||||
record.setLeftDurationMinutes(request.getLeftDurationMinutes());
|
||||
record.setRightDurationMinutes(request.getRightDurationMinutes());
|
||||
record.setEffectiveFeedingMinutes(resolveEffectiveFeedingMinutes(request.getEffectiveFeedingMinutes(), request.getLeftDurationMinutes(), request.getRightDurationMinutes(), duration));
|
||||
record.setPauseSegmentsJson(normalizeBlank(request.getPauseSegmentsJson()));
|
||||
if (duration != null) {
|
||||
record.setDurationMinutes(duration);
|
||||
} else if (record.getStartTime() != null && record.getEndTime() != null) {
|
||||
@@ -87,6 +89,8 @@ public class CareRecordService {
|
||||
record.setFeedingMethod("breastfeed");
|
||||
record.setLeftDurationMinutes(request.getLeftDurationMinutes());
|
||||
record.setRightDurationMinutes(request.getRightDurationMinutes());
|
||||
record.setEffectiveFeedingMinutes(request.getEffectiveFeedingMinutes());
|
||||
record.setPauseSegmentsJson(normalizeBlank(request.getPauseSegmentsJson()));
|
||||
careRecordMapper.insert(record);
|
||||
return CareRecordConvert.toVO(record);
|
||||
}
|
||||
@@ -107,6 +111,12 @@ public class CareRecordService {
|
||||
if (request.getRightDurationMinutes() != null) {
|
||||
activeFeeding.setRightDurationMinutes(request.getRightDurationMinutes());
|
||||
}
|
||||
if (request.getEffectiveFeedingMinutes() != null) {
|
||||
activeFeeding.setEffectiveFeedingMinutes(request.getEffectiveFeedingMinutes());
|
||||
}
|
||||
if (request.getPauseSegmentsJson() != null) {
|
||||
activeFeeding.setPauseSegmentsJson(normalizeBlank(request.getPauseSegmentsJson()));
|
||||
}
|
||||
if (request.getRemark() != null) {
|
||||
activeFeeding.setRemark(request.getRemark().trim().isEmpty() ? null : request.getRemark().trim());
|
||||
}
|
||||
@@ -114,6 +124,9 @@ public class CareRecordService {
|
||||
if (request.getLeftDurationMinutes() != null || request.getRightDurationMinutes() != null) {
|
||||
int sumSplit = (activeFeeding.getLeftDurationMinutes() == null ? 0 : activeFeeding.getLeftDurationMinutes())
|
||||
+ (activeFeeding.getRightDurationMinutes() == null ? 0 : activeFeeding.getRightDurationMinutes());
|
||||
if (activeFeeding.getEffectiveFeedingMinutes() == null && sumSplit > 0) {
|
||||
activeFeeding.setEffectiveFeedingMinutes(sumSplit);
|
||||
}
|
||||
if (sumSplit > 0 && (activeFeeding.getDurationMinutes() == null || activeFeeding.getDurationMinutes() < sumSplit)) {
|
||||
activeFeeding.setDurationMinutes(sumSplit);
|
||||
}
|
||||
@@ -177,6 +190,8 @@ public class CareRecordService {
|
||||
record.setFeedingMethod(request.getFeedingMethod());
|
||||
record.setLeftDurationMinutes(request.getLeftDurationMinutes());
|
||||
record.setRightDurationMinutes(request.getRightDurationMinutes());
|
||||
record.setEffectiveFeedingMinutes(resolveEffectiveFeedingMinutes(request.getEffectiveFeedingMinutes(), request.getLeftDurationMinutes(), request.getRightDurationMinutes(), request.getDurationMinutes()));
|
||||
record.setPauseSegmentsJson(normalizeBlank(request.getPauseSegmentsJson()));
|
||||
record.setAmountMl(request.getAmountMl());
|
||||
record.setExcretionType(request.getExcretionType());
|
||||
record.setOperatorName(request.getOperatorName() == null || request.getOperatorName().trim().isEmpty() ? "宝妈" : request.getOperatorName().trim());
|
||||
@@ -219,6 +234,14 @@ public class CareRecordService {
|
||||
if (request.getRightDurationMinutes() != null) {
|
||||
record.setRightDurationMinutes(request.getRightDurationMinutes());
|
||||
}
|
||||
if (request.getEffectiveFeedingMinutes() != null) {
|
||||
record.setEffectiveFeedingMinutes(request.getEffectiveFeedingMinutes());
|
||||
} else if (request.getLeftDurationMinutes() != null || request.getRightDurationMinutes() != null) {
|
||||
record.setEffectiveFeedingMinutes(resolveEffectiveFeedingMinutes(null, record.getLeftDurationMinutes(), record.getRightDurationMinutes(), record.getDurationMinutes()));
|
||||
}
|
||||
if (request.getPauseSegmentsJson() != null) {
|
||||
record.setPauseSegmentsJson(normalizeBlank(request.getPauseSegmentsJson()));
|
||||
}
|
||||
if (request.getAmountMl() != null) {
|
||||
record.setAmountMl(request.getAmountMl());
|
||||
}
|
||||
@@ -284,6 +307,27 @@ public class CareRecordService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Integer resolveEffectiveFeedingMinutes(Integer effectiveMinutes, Integer leftMinutes, Integer rightMinutes, Integer fallbackDuration) {
|
||||
if (effectiveMinutes != null) {
|
||||
return effectiveMinutes;
|
||||
}
|
||||
if (leftMinutes != null || rightMinutes != null) {
|
||||
int sum = (leftMinutes == null ? 0 : leftMinutes) + (rightMinutes == null ? 0 : rightMinutes);
|
||||
if (sum > 0) {
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
return fallbackDuration;
|
||||
}
|
||||
|
||||
private String normalizeBlank(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
return trimmed.isEmpty() ? null : trimmed;
|
||||
}
|
||||
|
||||
private CareRecordVO createExcretion(ExcretionRO request, String excretionType) {
|
||||
CareRecord record = baseRecord(request.getBabyId(), "excretion", request.getTime(), request.getOperatorName(), request.getRemark());
|
||||
record.setExcretionType(excretionType);
|
||||
|
||||
@@ -25,6 +25,8 @@ public final class CareRecordConvert {
|
||||
vo.setDurationMinutes(entity.getDurationMinutes());
|
||||
vo.setLeftDurationMinutes(entity.getLeftDurationMinutes());
|
||||
vo.setRightDurationMinutes(entity.getRightDurationMinutes());
|
||||
vo.setEffectiveFeedingMinutes(entity.getEffectiveFeedingMinutes());
|
||||
vo.setPauseSegmentsJson(entity.getPauseSegmentsJson());
|
||||
vo.setFeedingMethod(entity.getFeedingMethod());
|
||||
vo.setAmountMl(entity.getAmountMl());
|
||||
vo.setExcretionType(entity.getExcretionType());
|
||||
@@ -66,6 +68,8 @@ public final class CareRecordConvert {
|
||||
dto.setDurationMinutes(entity.getDurationMinutes());
|
||||
dto.setLeftDurationMinutes(entity.getLeftDurationMinutes());
|
||||
dto.setRightDurationMinutes(entity.getRightDurationMinutes());
|
||||
dto.setEffectiveFeedingMinutes(entity.getEffectiveFeedingMinutes());
|
||||
dto.setPauseSegmentsJson(entity.getPauseSegmentsJson());
|
||||
dto.setFeedingMethod(entity.getFeedingMethod());
|
||||
dto.setAmountMl(entity.getAmountMl());
|
||||
dto.setExcretionType(entity.getExcretionType());
|
||||
|
||||
@@ -51,6 +51,16 @@ public class CareRecordDTO {
|
||||
*/
|
||||
private Integer rightDurationMinutes;
|
||||
|
||||
/**
|
||||
* 有效喂养时长(分钟,不含暂停,仅喂养记录使用)
|
||||
*/
|
||||
private Integer effectiveFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 暂停片段JSON(记录暂停开始、结束与持续秒数)
|
||||
*/
|
||||
private String pauseSegmentsJson;
|
||||
|
||||
/**
|
||||
* 喂奶方式: breastfeed(亲喂), bottle(瓶喂), formula(配方奶), mixed(混合喂养), other(其他)
|
||||
*/
|
||||
|
||||
@@ -54,6 +54,16 @@ public class CreateFeedingRO {
|
||||
*/
|
||||
private Integer rightDurationMinutes;
|
||||
|
||||
/**
|
||||
* 有效喂养时长(分钟,不含暂停)
|
||||
*/
|
||||
private Integer effectiveFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 暂停片段JSON
|
||||
*/
|
||||
private String pauseSegmentsJson;
|
||||
|
||||
/**
|
||||
* 记录人称谓(如: 宝妈、宝爸、月嫂)
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,16 @@ public class CreateManualRecordRO {
|
||||
*/
|
||||
private Integer rightDurationMinutes;
|
||||
|
||||
/**
|
||||
* 有效喂养时长(分钟,不含暂停)
|
||||
*/
|
||||
private Integer effectiveFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 暂停片段JSON
|
||||
*/
|
||||
private String pauseSegmentsJson;
|
||||
|
||||
/**
|
||||
* 喂奶方式: breastfeed(亲喂), bottle(瓶喂), formula(配方奶), mixed(混合喂养), other(其他)
|
||||
*/
|
||||
|
||||
@@ -43,6 +43,16 @@ public class UpdateCareRecordRO {
|
||||
*/
|
||||
private Integer rightDurationMinutes;
|
||||
|
||||
/**
|
||||
* 有效喂养时长(分钟,不含暂停)
|
||||
*/
|
||||
private Integer effectiveFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 暂停片段JSON
|
||||
*/
|
||||
private String pauseSegmentsJson;
|
||||
|
||||
/**
|
||||
* 喂奶方式: breastfeed(亲喂), bottle(瓶喂), formula(配方奶), mixed(混合喂养), other(其他)
|
||||
*/
|
||||
|
||||
@@ -51,6 +51,16 @@ public class CareRecordVO {
|
||||
*/
|
||||
private Integer rightDurationMinutes;
|
||||
|
||||
/**
|
||||
* 有效喂养时长(分钟,不含暂停,仅喂养记录使用)
|
||||
*/
|
||||
private Integer effectiveFeedingMinutes;
|
||||
|
||||
/**
|
||||
* 暂停片段JSON(记录暂停开始、结束与持续秒数)
|
||||
*/
|
||||
private String pauseSegmentsJson;
|
||||
|
||||
/**
|
||||
* 喂奶方式: breastfeed(亲喂), bottle(瓶喂), formula(配方奶), mixed(混合喂养), other(其他)
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ spring:
|
||||
application:
|
||||
name: baby-tracker-server
|
||||
datasource:
|
||||
url: ${DB_URL:jdbc:mysql://39.107.119.209:3306/yyyy?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai}
|
||||
url: ${DB_URL:jdbc:mysql://39.107.119.209:3306/yyyy2?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai}
|
||||
username: ${DB_USER:yy_u}
|
||||
password: ${DB_PASSWORD:BBp5pjWr9LFiqua}
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
Reference in new issue
Block a user