# LogbookNotificationTargetServiceImpl.java

    package cloud.wconnect.frontoffice.service.logbook.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.frontoffice.entity.logbook.LogbookNotificationTarget;
    import cloud.wconnect.frontoffice.mapper.logbook.LogbookNotificationTargetMapper;
    import cloud.wconnect.frontoffice.pojo.dto.logbook.LogbookNotificationTargetDTO;
    import cloud.wconnect.frontoffice.service.logbook.ILogbookNotificationTargetService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.util.CollectionUtils;

    import java.util.Collections;
    import java.util.List;
    import java.util.Objects;

    /**
     * <p>
     *  服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-03-18
     */
    @Service
    @DS("logbook")
    public class LogbookNotificationTargetServiceImpl extends ServiceImpl<LogbookNotificationTargetMapper, LogbookNotificationTarget> implements ILogbookNotificationTargetService {

        @Autowired
        private BeanMapper beanMapper;

        /**
         * 批量添加
         *
         * @param id         notification id
         * @param propertyId 资产 id
         * @param users      通知用户
         * @author yyt
         * @date 2023/3/22
         */
        @Override
        public void saveBatch(Integer id, int propertyId, List<LogbookNotificationTargetDTO> users) {
            if (CollectionUtils.isEmpty(users)) {
                return;
            }

            List<LogbookNotificationTarget> notificationTargets = beanMapper.mapList(users, LogbookNotificationTarget.class,
                    item -> {
                        item.setNotificationId(id);
                        item.setPropertyId(propertyId);
                        item.setIdentityName(Objects.isNull(item.getIdentityName()) ? "" : item.getIdentityName());
                    });
            saveBatch(notificationTargets);
        }

        /**
         * 清除通知下配置的用户
         *
         * @param id notification id
         * @author yyt
         * @date 2023/3/22
         */
        @Override
        public void clearNotificationTarget(Integer id) {
            remove(new QueryWrapper<LogbookNotificationTarget>().lambda().eq(LogbookNotificationTarget::getNotificationId, id));
        }

        /**
         * 查询通知配置用户
         *
         * @param notificationIds notification id
         * @return 配置用户
         * @author yyt
         * @date 2023/3/22
         */
        @Override
        public List<LogbookNotificationTarget> listByNotificationIds(List<Integer> notificationIds) {
            if (CollectionUtils.isEmpty(notificationIds)) {
                return Collections.emptyList();
            }

            return baseMapper.selectList(new QueryWrapper<LogbookNotificationTarget>().lambda()
                    .in(LogbookNotificationTarget::getNotificationId, notificationIds));
        }

    }