|
|
@@ -24,6 +24,9 @@ import org.springframework.util.DigestUtils;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import com.etotem.cfc.entity.UserProfileHistory;
|
|
|
+import com.etotem.cfc.mapper.UserProfileHistoryMapper;
|
|
|
+
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -59,6 +62,9 @@ private OnboardingService onboardingService;
|
|
|
@Resource
|
|
|
private FamilyInvitationService familyInvitationService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private UserProfileHistoryMapper userProfileHistoryMapper;
|
|
|
+
|
|
|
public LoginResultDTO wechatLogin(WechatLoginDTO dto) {
|
|
|
// 1. 通过code获取openid
|
|
|
Map<String, String> sessionData = wechatService.code2Session(dto.getCode());
|
|
|
@@ -1020,11 +1026,42 @@ private FamilyInvitationService familyInvitationService;
|
|
|
if (dto.getMascot() != null) {
|
|
|
user.setMascot(dto.getMascot());
|
|
|
}
|
|
|
+ // 更新兴趣爱好
|
|
|
+ if (dto.getHobbies() != null) {
|
|
|
+ String oldHobbies = user.getHobbies();
|
|
|
+ user.setHobbies(dto.getHobbies());
|
|
|
+ recordProfileChange(userId, "hobbies", oldHobbies, dto.getHobbies(), "user_edit");
|
|
|
+ }
|
|
|
+ // 更新饮食偏好
|
|
|
+ if (dto.getDietPreferences() != null) {
|
|
|
+ String oldDiet = user.getDietPreferences();
|
|
|
+ user.setDietPreferences(dto.getDietPreferences());
|
|
|
+ recordProfileChange(userId, "dietPreferences", oldDiet, dto.getDietPreferences(), "user_edit");
|
|
|
+ }
|
|
|
user.setUpdatedAt(new Date());
|
|
|
userMapper.updateById(user);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 记录用户信息变更历史(仅当新旧值不同时写入)
|
|
|
+ */
|
|
|
+ private void recordProfileChange(Long userId, String fieldName,
|
|
|
+ String oldValue, String newValue, String source) {
|
|
|
+ if (oldValue == null && newValue == null) return;
|
|
|
+ if (oldValue != null && oldValue.equals(newValue)) return;
|
|
|
+ if (newValue != null && newValue.equals(oldValue)) return;
|
|
|
+ UserProfileHistory history = new UserProfileHistory();
|
|
|
+ history.setUserId(userId);
|
|
|
+ history.setFieldName(fieldName);
|
|
|
+ history.setOldValue(oldValue);
|
|
|
+ history.setNewValue(newValue);
|
|
|
+ history.setSource(source);
|
|
|
+ history.setChangedAt(new Date());
|
|
|
+ history.setCreatedAt(new Date());
|
|
|
+ userProfileHistoryMapper.insert(history);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 从身份证号提取生日
|
|
|
* 15位:1985年07月08日 -> 1985-07-08
|