|
|
@ -17,10 +17,13 @@ |
|
|
|
|
|
|
|
package com.elink.esua.epdc.modules.psychology.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.enums.EpdcDelFlagEnum; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
@ -105,18 +108,28 @@ public class PsychologistServiceImpl extends BaseServiceImpl<PsychologistDao, Ps |
|
|
|
return dto; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isPsychologist(String userId, String psychologistId) { |
|
|
|
QueryWrapper<PsychologistEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq("USER_ID", userId) |
|
|
|
.eq(FieldConstant.DEL_FLAG, EpdcDelFlagEnum.NORMAL.value()) |
|
|
|
.ne(StringUtils.isNotBlank(psychologistId), FieldConstant.ID, psychologistId); |
|
|
|
return baseDao.selectCount(wrapper) > NumConstant.ZERO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(PsychologistDTO dto) { |
|
|
|
List<PsychologistEntity> check = baseDao.checkPsychiatrist(dto); |
|
|
|
if (check.size() > 0) { |
|
|
|
|
|
|
|
if (isPsychologist(dto.getUserId(), null)) { |
|
|
|
throw new RenException("该用户已经注册心理咨询师"); |
|
|
|
} |
|
|
|
|
|
|
|
List<String> relation = dto.getTitles(); |
|
|
|
PsychologistEntity entity = ConvertUtils.sourceToTarget(dto, PsychologistEntity.class); |
|
|
|
int num = baseDao.insert(entity); |
|
|
|
if (num > 0 && relation != null && relation.size() > 0) { |
|
|
|
|
|
|
|
List<String> relation = dto.getTitles(); |
|
|
|
if (num > NumConstant.ZERO && CollUtil.isNotEmpty(relation)) { |
|
|
|
relation.forEach(item -> { |
|
|
|
PsychologistTitleRelationEntity psychologistTitleRelationEntity = new PsychologistTitleRelationEntity(); |
|
|
|
psychologistTitleRelationEntity.setPsychologistId(entity.getId()); |
|
|
@ -129,10 +142,15 @@ public class PsychologistServiceImpl extends BaseServiceImpl<PsychologistDao, Ps |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(PsychologistDTO dto) { |
|
|
|
|
|
|
|
if (isPsychologist(dto.getUserId(), dto.getId())) { |
|
|
|
throw new RenException("该用户已经注册心理咨询师"); |
|
|
|
} |
|
|
|
|
|
|
|
List<String> relation = dto.getTitles(); |
|
|
|
PsychologistEntity entity = ConvertUtils.sourceToTarget(dto, PsychologistEntity.class); |
|
|
|
boolean updFlag = updateById(entity); |
|
|
|
if (updFlag && relation != null && relation.size() > 0) { |
|
|
|
|
|
|
|
if (updateById(entity) && CollUtil.isNotEmpty(relation)) { |
|
|
|
psychologistTitleRelationDao.clearRelation(entity.getId()); |
|
|
|
relation.forEach(item -> { |
|
|
|
PsychologistTitleRelationEntity psychologistTitleRelationEntity = new PsychologistTitleRelationEntity(); |
|
|
|