package com.org.web.person.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.org.web.person.domain.BcPersonFamily;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BcPersonFamilyMapper extends BaseMapper<BcPersonFamily> {

    @Select("select * " +
            "from bc_person_family " +
            "where is_delete = 0 " +
            "and person_id = #{personId} ")
    List<BcPersonFamily> listByPersonId(@Param("personId") Long personId);

    @Update("update bc_person_family set is_delete = 1, delete_by = #{deleteBy}, delete_time = now() " +
            "where is_delete = 0 " +
            "and person_id = #{personId} ")
    void deleteByPersonId(@Param("personId") Long personId, @Param("deleteBy") Long deleteBy);

    @Update("<script>" +
            "update bc_person_family set is_delete = 1, delete_by = #{deleteBy}, delete_time = now() " +
            "where is_delete = 0 " +
            "and person_id = #{personId} " +

            "  <if test = 'idList != null and idList.size() > 0'> " +
            "   and id not in " +
            "       <foreach item='item' collection='idList' separator=',' open='(' close=')' index='index'> " +
            "           #{item} " +
            "       </foreach> "  +
            "  </if> " +

            "</script>")
    void deleteWithout(@Param("personId") Long personId, @Param("idList") List<Long> idList, @Param("deleteBy") Long deleteBy);
    
}
