diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/dao/PsychologistTitleRelationDao.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/dao/PsychologistTitleRelationDao.java index 90a017a..5b6e778 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/dao/PsychologistTitleRelationDao.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/dao/PsychologistTitleRelationDao.java @@ -20,6 +20,9 @@ package com.elink.esua.epdc.modules.psychology.dao; import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; import com.elink.esua.epdc.modules.psychology.entity.PsychologistTitleRelationEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 心理咨询师头衔表 @@ -30,4 +33,23 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface PsychologistTitleRelationDao extends BaseDao { + /** + * 咨询师列表 + * + * @return java.util.List + * @params [id] + * @author zhangyuan + * @since 2020/5/21 14:54 + */ + List selectTitles(@Param("id") String id); + + /** + * 清空关联 + * + * @return boolean + * @params [id] + * @author zhangyuan + * @since 2020/5/21 14:54 + */ + boolean clearRelation(@Param("id") String id); } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/service/impl/PsychologistServiceImpl.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/service/impl/PsychologistServiceImpl.java index 8ed70bf..3a1748b 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/service/impl/PsychologistServiceImpl.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/psychology/service/impl/PsychologistServiceImpl.java @@ -36,6 +36,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -82,7 +83,10 @@ public class PsychologistServiceImpl extends BaseServiceImpl titles = psychologistTitleRelationDao.selectTitles(id); + dto.setTitles(titles == null ? new ArrayList<>() : titles); + return dto; } @Override @@ -104,8 +108,18 @@ public class PsychologistServiceImpl extends BaseServiceImpl relation = dto.getTitles(); PsychologistEntity entity = ConvertUtils.sourceToTarget(dto, PsychologistEntity.class); - updateById(entity); + boolean updFlag = updateById(entity); + if (updFlag && relation != null && relation.size() > 0) { + psychologistTitleRelationDao.clearRelation(entity.getId()); + relation.forEach(item -> { + PsychologistTitleRelationEntity psychologistTitleRelationEntity = new PsychologistTitleRelationEntity(); + psychologistTitleRelationEntity.setPsychologistId(entity.getId()); + psychologistTitleRelationEntity.setTitleId(item); + psychologistTitleRelationDao.insert(psychologistTitleRelationEntity); + }); + } } @Override diff --git a/epdc-cloud-property/src/main/resources/mapper/psychology/PsychologistTitleRelationDao.xml b/epdc-cloud-property/src/main/resources/mapper/psychology/PsychologistTitleRelationDao.xml index 735dbeb..6602d4d 100644 --- a/epdc-cloud-property/src/main/resources/mapper/psychology/PsychologistTitleRelationDao.xml +++ b/epdc-cloud-property/src/main/resources/mapper/psychology/PsychologistTitleRelationDao.xml @@ -15,5 +15,23 @@ - + + + DELETE + FROM + epdc_psychologist_title_relation + WHERE + PSYCHOLOGIST_ID = #{id} + \ No newline at end of file