# BgOperateLogServiceImpl.java

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

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.pojo.bo.PropertyBO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.UserDTO;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.frontoffice.entity.badguest.BgOperateLog;
    import cloud.wconnect.frontoffice.mapper.badguest.BgOperateLogMapper;
    import cloud.wconnect.frontoffice.pojo.vo.badguest.BgOperateLogVO;
    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.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.*;

    /**
     * <p>
     * 黑名单操作日志表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2024-06-04
     */
    @Service
    @DS("logbook")
    public class BgOperateLogServiceImpl extends ServiceImpl<BgOperateLogMapper, BgOperateLog> implements IBgOperateLogService {

        @Autowired
        private UserInternalService userInternalService;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 保存操作日志
         *
         * @param propertyDTO 资产DTO
         * @param badGuestId  黑名单主键ID
         * @param userId      用户ID
         * @param operateType 操作类型
         * @param opinion     意见
         * @return void
         * @author lichen
         * @date 2024/6/4
         */
        @Override
        public void save(PropertyDTO propertyDTO, Long badGuestId, int userId, int operateType, String opinion) {
            save(new BgOperateLog().setTenantId(propertyDTO.getTenantId()).setPropertyId(propertyDTO.getId())
                    .setBadGuestId(badGuestId).setUserId(userId).setOperateType(operateType).setOperateTime(DateTimeUtils.nowTimestamp())
                    .setOpinion(opinion));
        }

        /**
         * 查询操作日志
         *
         * @param propertyDTO 资产
         * @param badGuestId  黑名单ID
         * @return java.util.List<cloud.wconnect.frontoffice.pojo.vo.badguest.BgOperateLogVO>
         * @author lichen
         * @date 2024/6/5
         */
        @Override
        public List<BgOperateLogVO> list(PropertyDTO propertyDTO, Long badGuestId) {
            //查询操作日志
            List<BgOperateLog> operateLogs = list(new LambdaQueryWrapper<BgOperateLog>()
                    .eq(BgOperateLog::getPropertyId, propertyDTO.getId())
                    .eq(BgOperateLog::getBadGuestId, badGuestId)
                    .orderByDesc(BgOperateLog::getOperateTime, BgOperateLog::getId));
            if (CollectionUtils.isEmpty(operateLogs)) return Collections.emptyList();

            //用户集合
            List<Integer> userIds = operateLogs.stream().map(BgOperateLog::getUserId).toList();
            Map<Integer, UserDTO> userId2UserDTO = userInternalService.getUserMapByIds(propertyDTO.getTenantId(), userIds);

            return beanMapper.mapList(operateLogs, BgOperateLogVO.class, (entity, vo) -> {
                UserDTO userDTO = userId2UserDTO.get(entity.getUserId());
                if (Objects.nonNull(userDTO)) {
                    vo.setUserName(userDTO.getName());
                    vo.setEmail(userDTO.getEmail());
                    vo.setAvatar(userDTO.getAvatar());
                }
            });
        }
    }