# ShiftOperationRecordServiceImpl.java

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

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.pojo.dto.UserDTO;
    import cloud.wconnect.commonlib.service.UserInternalService;
    import cloud.wconnect.frontoffice.entity.endofshift.ShiftOperationRecord;
    import cloud.wconnect.frontoffice.mapper.endofshift.ShiftOperationRecordMapper;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftOperationRecordDTO;
    import cloud.wconnect.frontoffice.service.endofshift.IShiftOperationRecordService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.google.common.collect.Lists;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.util.CollectionUtils;

    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;

    /**
     * <p>
     * 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2023-03-07
     */
    @Service
    @DS("ratelog_manage")
    public class ShiftOperationRecordServiceImpl extends ServiceImpl<ShiftOperationRecordMapper, ShiftOperationRecord> implements IShiftOperationRecordService {

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

        /**
         * 查询指定排班指定类型的操作日志
         *
         * @param tenantId   租户id
         * @param propertyId 资产id
         * @param shiftId    排班id
         * @param type       类型
         * @return java.util.List<cloud.wconnect.frontoffice.pojo.dto.endofshift.ShiftOperationRecordDTO>
         * @author lichen
         * @date 2025/6/20
         */
        @Override
        public List<ShiftOperationRecordDTO> list(Integer tenantId, int propertyId, Integer shiftId, Integer type) {
            //查询操作记录
            LambdaQueryWrapper<ShiftOperationRecord> shiftOperationRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
            shiftOperationRecordLambdaQueryWrapper.eq(ShiftOperationRecord::getShiftId, shiftId);
            shiftOperationRecordLambdaQueryWrapper.eq(ShiftOperationRecord::getOperationType, type);
            shiftOperationRecordLambdaQueryWrapper.orderByDesc(ShiftOperationRecord::getOperationTime);

            List<ShiftOperationRecord> operationRecords = list(shiftOperationRecordLambdaQueryWrapper);
            List<ShiftOperationRecordDTO> shiftOperationRecordDtoList = Lists.newArrayListWithExpectedSize(operationRecords.size());
            //填充OperationName
            if (!CollectionUtils.isEmpty(operationRecords)) {
                List<Integer> userIds = operationRecords.stream().map(ShiftOperationRecord::getOperationBy).distinct()
                        .collect(Collectors.toList());
                //获取用户信息
                Map<Integer, UserDTO> userId2DTO = userInternalService.getUserMapByIds(tenantId, userIds);
                for (ShiftOperationRecord operationRecord : operationRecords) {
                    ShiftOperationRecordDTO shiftOperationRecordDTO = beanMapper.map(operationRecord, ShiftOperationRecordDTO.class);
                    UserDTO userDTO = userId2DTO.getOrDefault(operationRecord.getOperationBy(), new UserDTO());
                    shiftOperationRecordDTO.setOperationName(userDTO.getName());
                    shiftOperationRecordDTO.setAvatar(userDTO.getAvatar());
                    shiftOperationRecordDtoList.add(shiftOperationRecordDTO);
                }
            }
            return shiftOperationRecordDtoList;
        }
    }