# CompRoomOrderByFieldEnum.java

    package cloud.wconnect.frontoffice.cons.comproom;

    import cloud.wconnect.frontoffice.entity.comproom.RqCompRoomForm;
    import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
    import lombok.AllArgsConstructor;
    import lombok.Getter;

    import java.util.Arrays;
    import java.util.Optional;

    /**
     * 排序字段
     */
    @Getter
    @AllArgsConstructor
    public enum CompRoomOrderByFieldEnum {

        /**
         * 客户名称
         */
        GUEST_NAME(1, RqCompRoomForm::getGuestName),
        /**
         * 入住日期
         */
        CHECKINDATE(2, RqCompRoomForm::getCheckInDate),
        /**
         * 离店日期
         */
        CHECKOUTDATE(3, RqCompRoomForm::getCheckOutDate),
        /**
         * 主键ID
         */
        ID(4, RqCompRoomForm::getId);

        private final int fieldId;

        private final SFunction<RqCompRoomForm, Object> SFunction;

        /**
         * 根据字段ID获取SFunction
         *
         * @param fieldId 字段ID
         * @return com.baomidou.mybatisplus.core.toolkit.support.SFunction<cloud.wconnect.frontoffice.entity.comproom.RqCompRoomForm,java.lang.Object>
         * @author lichen
         * @date 2024/6/19
         */
        public static SFunction<RqCompRoomForm, Object> getSFunction(int fieldId) {
            Optional<CompRoomOrderByFieldEnum> optional = Arrays.stream(CompRoomOrderByFieldEnum.values())
                    .filter(item -> item.getFieldId() == fieldId).findAny();
            return optional.isPresent() ? optional.get().getSFunction() : CompRoomOrderByFieldEnum.ID.SFunction;
        }

    }