update 功能安全中心成员-删除联系人

This commit is contained in:
lijiarao
2024-07-02 17:41:43 +08:00
parent 9960414825
commit 4654404076
4 changed files with 41 additions and 0 deletions
@@ -2,6 +2,9 @@ package com.jero.functionalsafetycenter.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jero.functionalsafetycenter.entity.SafetyCenterSubitemContacts;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
*
@@ -9,4 +12,5 @@ import com.jero.functionalsafetycenter.entity.SafetyCenterSubitemContacts;
*@date 2024-06-12 15:13
*/
public interface SafetyCenterSubitemContactsMapper extends BaseMapper<SafetyCenterSubitemContacts> {
List<SafetyCenterSubitemContacts> listByParentIdAndContactIdList(@Param("parentId") String parentId, @Param("contactIdList") List<String> contactIdList);
}
@@ -21,4 +21,18 @@
id, project_id, subitem_id, company_id, contacts_id, remarks, order_num, create_by,
create_time, update_by, update_time
</sql>
<select id="listByParentIdAndContactIdList" resultMap="BaseResultMap">
select *
from pay_functional_safety_center_subitem_contacts pfscsc
left join pay_functional_safety_center_subitem pfscs on pfscsc.subitem_id = pfscs.id
left join pay_functional_safety_center pfsc on pfscs.project_id = pfsc.id
<where>
pfscs.project_id = #{parentId}
and pfscsc.contacts_id in
<foreach item="item" index="index" collection="contactIdList" open="(" separator="," close=")">
#{item}
</foreach>
</where>
</select>
</mapper>
@@ -29,4 +29,7 @@ public class SafetyCenterSubitemContactsService extends ServiceImpl<SafetyCenter
return this.list(wrapper);
}
public List<SafetyCenterSubitemContacts> listByParentIdAndContactIdList(String parentId, List<String> contactIdList){
return baseMapper.listByParentIdAndContactIdList(parentId,contactIdList);
}
}
@@ -134,6 +134,13 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
if (!parentContactIdList.containsAll(contactIdList)) {
throw new JeroBootException("联系人无法添加到当前项目");
}
//区分删除的联系人
List<SafetyCenterSubitemContacts> oldContactList = contactsService.listBySubitemId(subitemId);
List<String> oldContactIdList = oldContactList.stream().map(SafetyCenterSubitemContacts::getContactsId).distinct().collect(Collectors.toList());
//取差值,得到删除的联系人
oldContactIdList.removeAll(contactIdList);
//删除子项目的联系人
this.deleteChildrenByParentId(parentId,contactIdList);
}
this.updateById(safetyCenterSubitem);
//先删除之前保存的
@@ -210,4 +217,17 @@ public class SafetyCenterSubitemService extends ServiceImpl<SafetyCenterSubitemM
public List<SafetyCenterSubitem> listByParentIdAndCompanyId(String parentId,String companyId){
return baseMapper.listByParentIdAndCompanyId(parentId,companyId);
}
/**
* 删除子项目的联系人
*/
public void deleteChildrenByParentId(String parentId, List<String> contactIdList) {
List<SafetyCenterSubitemContacts> contactList = contactsService.listByParentIdAndContactIdList(parentId, contactIdList);
List<String> collect = contactList.stream().map(SafetyCenterSubitemContacts::getId).collect(Collectors.toList());
contactsService.removeByIds(collect);
List<String> projectIdList = contactList.stream().map(SafetyCenterSubitemContacts::getProjectId).distinct().collect(Collectors.toList());
for (String projectId : projectIdList) {
deleteChildrenByParentId(projectId,contactIdList);
}
}
}