|
@@ -17,6 +17,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.zhentao.entity.Province;
|
|
|
|
|
+import com.zhentao.entity.City;
|
|
|
|
|
+import com.zhentao.entity.Area;
|
|
|
|
|
+import com.zhentao.mapper.ProvinceMapper;
|
|
|
|
|
+import com.zhentao.mapper.CityMapper;
|
|
|
|
|
+import com.zhentao.mapper.AreaMapper;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -38,6 +45,15 @@ public class MarrApplyServiceImpl extends ServiceImpl<MarrApplyMapper, MarrApply
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MatchmakerMapper matchmakerMapper;
|
|
private MatchmakerMapper matchmakerMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProvinceMapper provinceMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CityMapper cityMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AreaMapper areaMapper;
|
|
|
|
|
+
|
|
|
private final RestTemplate restTemplate = new RestTemplate();
|
|
private final RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
|
|
// websocket 服务的 IM 接口地址
|
|
// websocket 服务的 IM 接口地址
|
|
@@ -81,18 +97,46 @@ public class MarrApplyServiceImpl extends ServiceImpl<MarrApplyMapper, MarrApply
|
|
|
}
|
|
}
|
|
|
System.out.println("✅ 已更新 users 表,is_matchmaker = 1");
|
|
System.out.println("✅ 已更新 users 表,is_matchmaker = 1");
|
|
|
|
|
|
|
|
- // 4. 创建 matchmakers 记录
|
|
|
|
|
- Matchmaker matchmaker = new Matchmaker();
|
|
|
|
|
|
|
+ // 4. 创建或更新 matchmakers 记录
|
|
|
|
|
+ // 先检查该用户是否已经存在红娘记录
|
|
|
|
|
+ QueryWrapper<Matchmaker> matchmakerWrapper = new QueryWrapper<>();
|
|
|
|
|
+ matchmakerWrapper.eq("user_id", apply.getUserId());
|
|
|
|
|
+ Matchmaker existingMatchmaker = matchmakerMapper.selectOne(matchmakerWrapper);
|
|
|
|
|
|
|
|
- // 从 marr_apply 表获取数据
|
|
|
|
|
- matchmaker.setRealName(apply.getName()); // 真实姓名
|
|
|
|
|
|
|
+ Matchmaker matchmaker;
|
|
|
|
|
+ boolean isUpdate = false;
|
|
|
|
|
+
|
|
|
|
|
+ if (existingMatchmaker != null) {
|
|
|
|
|
+ // 如果已存在,则更新现有记录
|
|
|
|
|
+ matchmaker = existingMatchmaker;
|
|
|
|
|
+ isUpdate = true;
|
|
|
|
|
+ System.out.println("⚠️ 该用户已存在红娘记录,将更新现有记录,matchmaker_id = " + matchmaker.getMatchmakerId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 如果不存在,创建新记录
|
|
|
|
|
+ matchmaker = new Matchmaker();
|
|
|
|
|
+ matchmaker.setCreateTime(LocalDateTime.now());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 从 marr_apply 表获取数据(按照用户要求映射)
|
|
|
|
|
+ matchmaker.setUserId(apply.getUserId()); // 用户ID
|
|
|
|
|
+ matchmaker.setRealName(apply.getName()); // 姓名 -> 真实姓名
|
|
|
matchmaker.setPhone(apply.getPhone()); // 手机号
|
|
matchmaker.setPhone(apply.getPhone()); // 手机号
|
|
|
matchmaker.setEmail(apply.getEmail()); // 邮箱
|
|
matchmaker.setEmail(apply.getEmail()); // 邮箱
|
|
|
matchmaker.setGender(apply.getGender()); // 性别
|
|
matchmaker.setGender(apply.getGender()); // 性别
|
|
|
- matchmaker.setProfile(apply.getIntroduction()); // 个人简介
|
|
|
|
|
|
|
+ matchmaker.setProfile(apply.getExperience()); // 经验 -> 个人简介
|
|
|
|
|
+
|
|
|
|
|
+ // 解析地区信息:area 字段包含三级联动,需要解析为 provinceId, cityId, areaId
|
|
|
|
|
+ parseAreaToIds(apply.getArea(), matchmaker);
|
|
|
|
|
|
|
|
// 从 users 表获取数据
|
|
// 从 users 表获取数据
|
|
|
- matchmaker.setUsername(user.getNickname() != null ? user.getNickname() : user.getPhone()); // 用户名(优先使用昵称,否则使用手机号)
|
|
|
|
|
|
|
+ String baseUsername = user.getNickname() != null ? user.getNickname() : user.getPhone(); // 用户名(优先使用昵称,否则使用手机号)
|
|
|
|
|
+
|
|
|
|
|
+ // 检查用户名是否已存在(如果不存在记录或用户名发生变化)
|
|
|
|
|
+ if (!isUpdate || matchmaker.getUsername() == null || !baseUsername.equals(matchmaker.getUsername())) {
|
|
|
|
|
+ String finalUsername = generateUniqueUsername(baseUsername, matchmaker.getUserId());
|
|
|
|
|
+ matchmaker.setUsername(finalUsername);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
matchmaker.setPassword(user.getPassword()); // 密码(使用用户的密码)
|
|
matchmaker.setPassword(user.getPassword()); // 密码(使用用户的密码)
|
|
|
matchmaker.setBirthDate(user.getBirthDate()); // 出生日期(更准确)
|
|
matchmaker.setBirthDate(user.getBirthDate()); // 出生日期(更准确)
|
|
|
|
|
|
|
@@ -106,18 +150,28 @@ public class MarrApplyServiceImpl extends ServiceImpl<MarrApplyMapper, MarrApply
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 设置默认值(无法从其他表获取的字段)
|
|
// 设置默认值(无法从其他表获取的字段)
|
|
|
- matchmaker.setMatchmakerType(1); // 默认类型:1-普通红娘
|
|
|
|
|
- matchmaker.setLevel(1); // 默认等级:1级
|
|
|
|
|
- matchmaker.setSuccessCouples(0); // 初始成功撮合数:0
|
|
|
|
|
|
|
+ if (!isUpdate) {
|
|
|
|
|
+ matchmaker.setMatchmakerType(1); // 默认类型:1-普通红娘
|
|
|
|
|
+ matchmaker.setLevel(1); // 默认等级:1级
|
|
|
|
|
+ matchmaker.setSuccessCouples(0); // 初始成功撮合数:0
|
|
|
|
|
+ }
|
|
|
matchmaker.setStatus(1); // 状态:1-正常
|
|
matchmaker.setStatus(1); // 状态:1-正常
|
|
|
- matchmaker.setCreateTime(LocalDateTime.now());
|
|
|
|
|
matchmaker.setUpdateTime(LocalDateTime.now());
|
|
matchmaker.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
|
|
|
- int insertResult = matchmakerMapper.insert(matchmaker);
|
|
|
|
|
- if (insertResult <= 0) {
|
|
|
|
|
- throw new RuntimeException("创建红娘记录失败");
|
|
|
|
|
|
|
+ int result;
|
|
|
|
|
+ if (isUpdate) {
|
|
|
|
|
+ result = matchmakerMapper.updateById(matchmaker);
|
|
|
|
|
+ if (result <= 0) {
|
|
|
|
|
+ throw new RuntimeException("更新红娘记录失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("✅ 已更新 matchmakers 记录,matchmaker_id = " + matchmaker.getMatchmakerId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ result = matchmakerMapper.insert(matchmaker);
|
|
|
|
|
+ if (result <= 0) {
|
|
|
|
|
+ throw new RuntimeException("创建红娘记录失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("✅ 已创建 matchmakers 记录,matchmaker_id = " + matchmaker.getMatchmakerId());
|
|
|
}
|
|
}
|
|
|
- System.out.println("✅ 已创建 matchmakers 记录,matchmaker_id = " + matchmaker.getMatchmakerId());
|
|
|
|
|
|
|
|
|
|
// 5. 导入到腾讯云 IM(使用 m_ + matchmaker_id)
|
|
// 5. 导入到腾讯云 IM(使用 m_ + matchmaker_id)
|
|
|
String imUserId = "m_" + matchmaker.getMatchmakerId();
|
|
String imUserId = "m_" + matchmaker.getMatchmakerId();
|
|
@@ -141,7 +195,8 @@ public class MarrApplyServiceImpl extends ServiceImpl<MarrApplyMapper, MarrApply
|
|
|
// 导入失败不影响审核流程,只记录日志
|
|
// 导入失败不影响审核流程,只记录日志
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 6. 更新申请记录的更新人和更新时间
|
|
|
|
|
|
|
+ // 6. 更新申请记录的审核状态、更新人和更新时间
|
|
|
|
|
+ apply.setStatus(0); // 0-正常(审核通过)
|
|
|
apply.setUpdateTime(new Date());
|
|
apply.setUpdateTime(new Date());
|
|
|
apply.setUpdateMan("系统");
|
|
apply.setUpdateMan("系统");
|
|
|
this.updateById(apply);
|
|
this.updateById(apply);
|
|
@@ -153,7 +208,122 @@ public class MarrApplyServiceImpl extends ServiceImpl<MarrApplyMapper, MarrApply
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean delete(Long applyId) {
|
|
public boolean delete(Long applyId) {
|
|
|
- return this.removeById(applyId);
|
|
|
|
|
|
|
+ // 逻辑删除:将 idStatus 设置为 "1"(禁止状态)
|
|
|
|
|
+ MarrApply marrApply = new MarrApply();
|
|
|
|
|
+ marrApply.setApplyId(applyId);
|
|
|
|
|
+ marrApply.setIdStatus("1"); // 1-禁止(逻辑删除)
|
|
|
|
|
+ return this.updateById(marrApply);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析地区字符串,将省市区名称转换为对应的ID
|
|
|
|
|
+ * area 格式可能是:"北京市 北京市 朝阳区" 或 "北京市 北京市 朝阳区"(用空格分隔)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param area 地区字符串
|
|
|
|
|
+ * @param matchmaker 红娘对象,用于设置 provinceId, cityId, areaId
|
|
|
|
|
+ */
|
|
|
|
|
+ private void parseAreaToIds(String area, Matchmaker matchmaker) {
|
|
|
|
|
+ if (area == null || area.trim().isEmpty()) {
|
|
|
|
|
+ System.out.println("⚠️ 地区信息为空,跳过解析");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 按空格分割地区字符串
|
|
|
|
|
+ String[] areaParts = area.trim().split("\\s+");
|
|
|
|
|
+
|
|
|
|
|
+ if (areaParts.length >= 1 && provinceMapper != null) {
|
|
|
|
|
+ // 解析省份
|
|
|
|
|
+ String provinceName = areaParts[0].trim();
|
|
|
|
|
+ QueryWrapper<Province> provinceWrapper = new QueryWrapper<>();
|
|
|
|
|
+ provinceWrapper.eq("name", provinceName);
|
|
|
|
|
+ Province province = provinceMapper.selectOne(provinceWrapper);
|
|
|
|
|
+ if (province != null) {
|
|
|
|
|
+ matchmaker.setProvinceId(province.getId());
|
|
|
|
|
+ System.out.println("✅ 解析省份: " + provinceName + " -> " + province.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("⚠️ 未找到省份: " + provinceName);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (areaParts.length >= 2 && cityMapper != null && matchmaker.getProvinceId() != null) {
|
|
|
|
|
+ // 解析城市
|
|
|
|
|
+ String cityName = areaParts[1].trim();
|
|
|
|
|
+ QueryWrapper<City> cityWrapper = new QueryWrapper<>();
|
|
|
|
|
+ cityWrapper.eq("name", cityName);
|
|
|
|
|
+ cityWrapper.eq("province_id", matchmaker.getProvinceId());
|
|
|
|
|
+ City city = cityMapper.selectOne(cityWrapper);
|
|
|
|
|
+ if (city != null) {
|
|
|
|
|
+ matchmaker.setCityId(city.getId());
|
|
|
|
|
+ System.out.println("✅ 解析城市: " + cityName + " -> " + city.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("⚠️ 未找到城市: " + cityName);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (areaParts.length >= 3 && areaMapper != null && matchmaker.getCityId() != null) {
|
|
|
|
|
+ // 解析区域
|
|
|
|
|
+ String areaName = areaParts[2].trim();
|
|
|
|
|
+ QueryWrapper<Area> areaWrapper = new QueryWrapper<>();
|
|
|
|
|
+ areaWrapper.eq("name", areaName);
|
|
|
|
|
+ areaWrapper.eq("city_id", matchmaker.getCityId());
|
|
|
|
|
+ Area areaObj = areaMapper.selectOne(areaWrapper);
|
|
|
|
|
+ if (areaObj != null) {
|
|
|
|
|
+ matchmaker.setAreaId(areaObj.getId());
|
|
|
|
|
+ System.out.println("✅ 解析区域: " + areaName + " -> " + areaObj.getId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("⚠️ 未找到区域: " + areaName);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (areaParts.length < 3) {
|
|
|
|
|
+ System.out.println("⚠️ 地区信息不完整,只有 " + areaParts.length + " 部分: " + area);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ System.err.println("❌ 解析地区信息失败: " + e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ // 解析失败不影响审核流程,只记录日志
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 生成唯一的用户名
|
|
|
|
|
+ * 如果用户名已存在,则添加后缀(_1, _2, ...)直到找到不存在的用户名
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param baseUsername 基础用户名
|
|
|
|
|
+ * @param currentUserId 当前用户ID(如果更新现有记录,排除自己)
|
|
|
|
|
+ * @return 唯一的用户名
|
|
|
|
|
+ */
|
|
|
|
|
+ private String generateUniqueUsername(String baseUsername, Integer currentUserId) {
|
|
|
|
|
+ if (baseUsername == null || baseUsername.trim().isEmpty()) {
|
|
|
|
|
+ baseUsername = "user_" + System.currentTimeMillis();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String username = baseUsername.trim();
|
|
|
|
|
+ int suffix = 0;
|
|
|
|
|
+
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ QueryWrapper<Matchmaker> wrapper = new QueryWrapper<>();
|
|
|
|
|
+ wrapper.eq("username", username);
|
|
|
|
|
+ // 如果当前用户ID不为空,排除自己的记录(用于更新场景)
|
|
|
|
|
+ if (currentUserId != null) {
|
|
|
|
|
+ wrapper.ne("user_id", currentUserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Matchmaker existing = matchmakerMapper.selectOne(wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ if (existing == null) {
|
|
|
|
|
+ // 用户名不存在,可以使用
|
|
|
|
|
+ if (suffix > 0) {
|
|
|
|
|
+ System.out.println("⚠️ 用户名 '" + baseUsername + "' 已存在,使用新用户名: " + username);
|
|
|
|
|
+ }
|
|
|
|
|
+ return username;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 用户名已存在,添加后缀
|
|
|
|
|
+ suffix++;
|
|
|
|
|
+ username = baseUsername + "_" + suffix;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|