# BadGuestCompanionServiceImpl.java

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

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.frontoffice.cons.badguest.BgOperateTypeEnum;
    import cloud.wconnect.frontoffice.entity.badguest.BadGuestCompanion;
    import cloud.wconnect.frontoffice.mapper.badguest.BadGuestCompanionMapper;
    import cloud.wconnect.frontoffice.pojo.dto.badguest.CompanionExtInfoDTO;
    import cloud.wconnect.frontoffice.pojo.query.badguest.BadGuestQuery;
    import cloud.wconnect.frontoffice.service.badguest.IBadGuestCompanionService;
    import cloud.wconnect.frontoffice.service.badguest.IBgOperateLogService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

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

    /**
     * <p>
     * 黑名单关联同伴表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2023-03-20
     */
    @Service
    @DS("logbook")
    public class BadGuestCompanionServiceImpl extends ServiceImpl<BadGuestCompanionMapper, BadGuestCompanion> implements IBadGuestCompanionService {

        @Autowired
        private BeanMapper beanMapper;
        @Autowired
        private IBgOperateLogService operateLogService;

        /**
         * 查询黑名单同伴信息
         *
         * @param badGuestIds 黑名单id集合
         * @return java.util.List<cloud.wconnect.frontoffice.entity.badguest.BadGuestCompanion>
         * @author lichen
         * @date 2023/9/26
         */
        @Override
        public List<BadGuestCompanion> listByBadGuestIds(List<Long> badGuestIds) {
            if (CollectionUtils.isEmpty(badGuestIds)) return Collections.emptyList();
            return list(new LambdaQueryWrapper<BadGuestCompanion>()
                    .in(BadGuestCompanion::getBadGuestId, badGuestIds));
        }

        /**
         * 查询黑名单同伴信息
         *
         * @param query 查询对象
         * @return java.util.List<cloud.wconnect.frontoffice.entity.badguest.BadGuestCompanion>
         * @author lichen
         * @date 2024/4/22
         */
        @Override
        public List<BadGuestCompanion> listByGuestInfo(List<Integer> queryPropertyIds, BadGuestQuery query) {
            if (CollectionUtils.isEmpty(queryPropertyIds)) return Collections.emptyList();
            return list(new LambdaQueryWrapper<BadGuestCompanion>()
                    .in(BadGuestCompanion::getPropertyId, queryPropertyIds)
                    .like(StringUtils.isNotBlank(query.getPhone()), BadGuestCompanion::getPhone, query.getPhone())
                    .like(StringUtils.isNotBlank(query.getAddress()), BadGuestCompanion::getAddress, query.getAddress())
                    .like(StringUtils.isNotBlank(query.getEmail()), BadGuestCompanion::getEmail, query.getEmail())
                    .like(StringUtils.isNotBlank(query.getMemberCardNum()), BadGuestCompanion::getMemberCardNum, query.getMemberCardNum())
                    .eq(StringUtils.isNotBlank(query.getFirstName()), BadGuestCompanion::getFirstName, query.getFirstName())
                    .eq(StringUtils.isNotBlank(query.getLastName()), BadGuestCompanion::getLastName, query.getLastName()));
        }

        /**
         * 校验黑名单同伴信息是否存在
         *
         * @param id 黑名单同伴ID
         * @return cloud.wconnect.frontoffice.entity.badguest.BadGuestCompanion
         * @author lichen
         * @date 2024/6/4
         */
        @Override
        public BadGuestCompanion checkExist(Long id) {
            BadGuestCompanion badGuestCompanion = getById(id);
            if (Objects.isNull(badGuestCompanion)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "id=" + id + " ,BadGuestCompanion not found");
            }
            return badGuestCompanion;
        }

        /**
         * 更新同伴扩展信息（手机号、地址、会员卡号、邮箱）
         *
         * @param propertyDTO          资产DTO
         * @param oriBadGuestCompanion 更新前的同伴信息
         * @param companionExtInfoDTO  扩展信息DTO
         * @param loginUserId          登录用户ID
         * @return void
         * @author lichen
         * @date 2024/6/5
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void updateCompanionExtInfo(PropertyDTO propertyDTO, BadGuestCompanion oriBadGuestCompanion, CompanionExtInfoDTO companionExtInfoDTO, int loginUserId) {
            //更新黑名单同伴扩展信息（手机号、地址、会员卡号、邮箱）
            BadGuestCompanion badGuestCompanion = beanMapper.map(companionExtInfoDTO, BadGuestCompanion.class);
            updateById(badGuestCompanion);

            //记录操作日志
            operateLogService.save(propertyDTO, oriBadGuestCompanion.getBadGuestId(), loginUserId,
                    BgOperateTypeEnum.UPDATE_COMPANION_EXT_INFO.getType(), "");
        }
    }