|
@@ -1,5 +1,6 @@
|
|
package com.citu.module.menduner.system.service.person.skill;
|
|
package com.citu.module.menduner.system.service.person.skill;
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.citu.framework.common.pojo.PageResult;
|
|
import com.citu.framework.common.pojo.PageResult;
|
|
import com.citu.framework.common.util.object.BeanUtils;
|
|
import com.citu.framework.common.util.object.BeanUtils;
|
|
@@ -88,15 +89,29 @@ public class PersonSkillServiceImpl implements PersonSkillService {
|
|
@DSTransactional // 单机+多数据源方案,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
|
@DSTransactional // 单机+多数据源方案,使用 @DSTransactional 保证本地事务,以及数据源的切换
|
|
public Boolean savePersonSkill(AppPersonSkillSaveReqVO reqVO) {
|
|
public Boolean savePersonSkill(AppPersonSkillSaveReqVO reqVO) {
|
|
Long userId = LoginUserContext.getUserId();
|
|
Long userId = LoginUserContext.getUserId();
|
|
- if (personSkillMapper.existByUserIdAndSkillId(userId, reqVO.getId(), reqVO.getSkillId())) {
|
|
|
|
- throw exception(MDE_USER_SKILL_EXISTS);
|
|
|
|
- }
|
|
|
|
PersonSkillDO personSkillDO = BeanUtils.toBean(reqVO, PersonSkillDO.class);
|
|
PersonSkillDO personSkillDO = BeanUtils.toBean(reqVO, PersonSkillDO.class);
|
|
personSkillDO.setUserId(userId);
|
|
personSkillDO.setUserId(userId);
|
|
if (null == reqVO.getId()) {
|
|
if (null == reqVO.getId()) {
|
|
|
|
+ if (personSkillMapper.existByUserIdAndSkillId(userId, reqVO.getId(), reqVO.getSkillId())) {
|
|
|
|
+ throw exception(MDE_USER_SKILL_EXISTS);
|
|
|
|
+ }
|
|
personSkillMapper.insert(personSkillDO);
|
|
personSkillMapper.insert(personSkillDO);
|
|
} else {
|
|
} else {
|
|
personSkillDO.setId(reqVO.getId());
|
|
personSkillDO.setId(reqVO.getId());
|
|
|
|
+ // 获取现有的记录
|
|
|
|
+ PersonSkillDO existingPersonSkill = personSkillMapper.selectById(reqVO.getId());
|
|
|
|
+ if (existingPersonSkill == null) {
|
|
|
|
+ throw exception(MDE_USER_SKILL_NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检查 skillId 是否发生了变化
|
|
|
|
+ if (!ObjectUtil.equals(existingPersonSkill.getSkillId(), reqVO.getSkillId())) {
|
|
|
|
+ // 如果 skillId 发生了变化,需要重新检查唯一性约束
|
|
|
|
+ if (personSkillMapper.existByUserIdAndSkillId(userId, reqVO.getId(), reqVO.getSkillId())) {
|
|
|
|
+ throw exception(MDE_USER_SKILL_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
personSkillMapper.updateById(personSkillDO);
|
|
personSkillMapper.updateById(personSkillDO);
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|