package com.kamco.cd.kamcoback.postgres.repository.mapsheet;

import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx50kEntity.mapInkx50kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapInkx5kEntity.mapInkx5kEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetMngEntity.mapSheetMngEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetMngFileEntity.mapSheetMngFileEntity;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetMngHstEntity.mapSheetMngHstEntity;

import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.CaseBuilder;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberExpression;
import com.querydsl.core.types.dsl.StringExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.hibernate.query.Query;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;

public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
    implements MapSheetMngRepositoryCustom {

  private final JPAQueryFactory queryFactory;
  private final StringExpression NULL_STRING = Expressions.stringTemplate("cast(null as text)");

  @PersistenceContext private EntityManager em;

  public MapSheetMngRepositoryImpl(JPAQueryFactory queryFactory) {
    super(MapSheetMngHstEntity.class);
    this.queryFactory = queryFactory;
  }

  @Override
  public List<MapSheetMngDto.MngDto> findMapSheetMngList() {

    // Pageable pageable = searchReq.toPageable();
    BooleanBuilder whereBuilder = new BooleanBuilder();

    // if (searchReq.getMngYyyy() != null) {
    // whereBuilder.and(mapSheetMngEntity.mngYyyy.eq(searchReq.getMngYyyy()));
    // }

    NumberExpression<Long> totalCount = mapSheetMngHstEntity.count().as("syncTotCnt");

    NumberExpression<Long> doneCount =
        new CaseBuilder()
            .when(mapSheetMngHstEntity.dataState.eq("DONE"))
            .then(1L)
            .otherwise(0L)
            .sum()
            .as("syncStateDoneCnt");

    List<MapSheetMngDto.MngDto> foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.MngDto.class,
                    Expressions.numberTemplate(
                        Integer.class,
                        "row_number() over(order by {0} desc)",
                        mapSheetMngEntity.createdDttm),
                    mapSheetMngEntity.mngYyyy,
                    mapSheetMngEntity.mngState,
                    mapSheetMngEntity.syncState,
                    mapSheetMngEntity.syncCheckState,
                    mapSheetMngHstEntity.count(),
                    new CaseBuilder()
                        .when(mapSheetMngHstEntity.dataState.eq("DONE"))
                        .then(1L)
                        .otherwise(0L)
                        .sum()
                        .as("syncStateDoneCnt"),
                    new CaseBuilder()
                        .when(mapSheetMngHstEntity.syncState.ne("NOTYET"))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncState
                                .eq("NOFILE")
                                .or(mapSheetMngHstEntity.syncState.eq("NOTPAIR")))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncCheckState
                                .eq("DONE")
                                .and(
                                    mapSheetMngHstEntity
                                        .syncState
                                        .eq("NOFILE")
                                        .or(mapSheetMngHstEntity.syncState.eq("NOTPAIR"))))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(mapSheetMngHstEntity.syncState.eq("DUPLICATE"))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncCheckState
                                .eq("DONE")
                                .and(mapSheetMngHstEntity.syncState.eq("DUPLICATE")))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncState
                                .eq("TYPEERROR")
                                .or(mapSheetMngHstEntity.syncState.eq("SIZEERROR")))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncCheckState
                                .eq("DONE")
                                .and(
                                    mapSheetMngHstEntity
                                        .syncState
                                        .eq("TYPEERROR")
                                        .or(mapSheetMngHstEntity.syncState.eq("SIZEERROR"))))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    mapSheetMngEntity.createdDttm,
                    mapSheetMngHstEntity.syncEndDttm.max()))
            .from(mapSheetMngEntity)
            .leftJoin(mapSheetMngHstEntity)
            .on(mapSheetMngEntity.mngYyyy.eq(mapSheetMngHstEntity.mngYyyy))
            .where(whereBuilder)
            // .offset(pageable.getOffset())
            // .limit(pageable.getPageSize())
            .orderBy(mapSheetMngEntity.mngYyyy.desc())
            .groupBy(mapSheetMngEntity.mngYyyy)
            .fetch();

    Long countQuery =
        queryFactory
            .select(mapSheetMngEntity.mngYyyy.count())
            .from(mapSheetMngEntity)
            .where(whereBuilder)
            .fetchOne();

    return foundContent;
  }

  public List<Integer> findMapSheetMngYyyyList(){
    List<Integer> foundContent =
      queryFactory
        .select(mapSheetMngEntity.mngYyyy)
        .from(mapSheetMngEntity)
        .where(mapSheetMngEntity.mngState.ne("COMPLETE"))
        .orderBy(mapSheetMngEntity.mngYyyy.desc())
        .fetch();

    return foundContent;
  }

  public MapSheetMngDto.MngDto findMapSheetMng(int mngYyyy) {

    BooleanBuilder whereBuilder = new BooleanBuilder();
    whereBuilder.and(mapSheetMngEntity.mngYyyy.eq(mngYyyy));

    MapSheetMngDto.MngDto foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.MngDto.class,
                    Expressions.numberTemplate(
                        Integer.class,
                        "row_number() over(order by {0} desc)",
                        mapSheetMngEntity.createdDttm),
                    mapSheetMngEntity.mngYyyy,
                    mapSheetMngEntity.mngState,
                    mapSheetMngEntity.syncState,
                    mapSheetMngEntity.syncCheckState,
                    mapSheetMngHstEntity.count(),
                    new CaseBuilder()
                        .when(mapSheetMngHstEntity.dataState.eq("DONE"))
                        .then(1L)
                        .otherwise(0L)
                        .sum()
                        .as("syncStateDoneCnt"),
                    new CaseBuilder()
                        .when(mapSheetMngHstEntity.syncState.ne("NOTYET"))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncState
                                .eq("NOFILE")
                                .or(mapSheetMngHstEntity.syncState.eq("NOTPAIR")))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncCheckState
                                .eq("DONE")
                                .and(
                                    mapSheetMngHstEntity
                                        .syncState
                                        .eq("NOFILE")
                                        .or(mapSheetMngHstEntity.syncState.eq("NOTPAIR"))))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(mapSheetMngHstEntity.syncState.eq("DUPLICATE"))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncCheckState
                                .eq("DONE")
                                .and(mapSheetMngHstEntity.syncState.eq("DUPLICATE")))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncState
                                .eq("TYPEERROR")
                                .or(mapSheetMngHstEntity.syncState.eq("SIZEERROR")))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    new CaseBuilder()
                        .when(
                            mapSheetMngHstEntity
                                .syncCheckState
                                .eq("DONE")
                                .and(
                                    mapSheetMngHstEntity
                                        .syncState
                                        .eq("TYPEERROR")
                                        .or(mapSheetMngHstEntity.syncState.eq("SIZEERROR"))))
                        .then(1L)
                        .otherwise(0L)
                        .sum(),
                    mapSheetMngEntity.createdDttm,
                    mapSheetMngHstEntity.syncEndDttm.max()))
            .from(mapSheetMngEntity)
            .leftJoin(mapSheetMngHstEntity)
            .on(mapSheetMngEntity.mngYyyy.eq(mapSheetMngHstEntity.mngYyyy))
            .where(whereBuilder)
            .groupBy(mapSheetMngEntity.mngYyyy)
            .fetchOne();

    return foundContent;
  }

  @Override
  public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
      MapSheetMngDto.@Valid ErrorSearchReq searchReq) {

    Pageable pageable = PageRequest.of(searchReq.getPage(), searchReq.getSize());
    BooleanBuilder whereBuilder = new BooleanBuilder();

    whereBuilder.and(mapSheetMngHstEntity.mngYyyy.eq(searchReq.getMngYyyy()));
    whereBuilder.and(
        mapSheetMngHstEntity.syncState.ne("DONE").and(mapSheetMngHstEntity.syncState.ne("NOTYET")));

    if (searchReq.getSyncState() != null && !searchReq.getSyncState().isEmpty()) {
      if (searchReq.getSyncState().equals("NOTPAIR")) {
        whereBuilder.and(
            mapSheetMngHstEntity
                .syncState
                .eq("NOTPAIR")
                .or(mapSheetMngHstEntity.syncState.eq("NOFILE")));
      } else if (searchReq.getSyncState().equals("FAULT")) {
        whereBuilder.and(
            mapSheetMngHstEntity
                .syncState
                .eq("SIZEERROR")
                .or(mapSheetMngHstEntity.syncState.eq("TYPEERROR")));
      } else {
        whereBuilder.and(mapSheetMngHstEntity.syncState.eq(searchReq.getSyncState()));
      }
    }

    if (searchReq.getSyncCheckState() != null && !searchReq.getSyncCheckState().isEmpty()) {
      whereBuilder.and(mapSheetMngHstEntity.syncCheckState.eq(searchReq.getSyncCheckState()));
    }

    if (searchReq.getSearchValue() != null && !searchReq.getSearchValue().isEmpty()) {
      whereBuilder.and(
          mapSheetMngHstEntity
              .mapSheetNum
              .eq(searchReq.getSearchValue())
              .or(mapSheetMngHstEntity.refMapSheetNum.eq(searchReq.getSearchValue()))
              .or(
                  Expressions.stringTemplate(
                          "concat({0},substring({1}, 0, 6))",
                          mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                      .likeIgnoreCase("%" + searchReq.getSearchValue() + "%"))
              .or(
                  Expressions.stringTemplate(
                          "concat({0},substring({1}, 6, 8))",
                          mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                      .likeIgnoreCase("%" + searchReq.getSearchValue() + "%")));
    }

    List<MapSheetMngDto.ErrorDataDto> foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.ErrorDataDto.class,
                    mapSheetMngHstEntity.hstUid,
                    Expressions.stringTemplate(
                            "concat({0},substring({1}, 0, 6))",
                            mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                        .as("map50kName"),
                    Expressions.stringTemplate(
                            "concat({0},substring({1}, 6, 8))",
                            mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                        .as("map5kName"),
                    Expressions.stringTemplate(
                            "concat({0},substring({1}, 6, 8))",
                            mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                        .as("mapSrcName"),
                    mapInkx5kEntity.fid,
                    mapSheetMngHstEntity.createdDate,
                    mapSheetMngHstEntity.syncState,
                    mapSheetMngHstEntity.syncTfwFileName,
                    mapSheetMngHstEntity.syncTifFileName,
                    mapSheetMngHstEntity.syncCheckState,
                    mapSheetMngHstEntity.syncCheckTfwFileName,
                    mapSheetMngHstEntity.syncCheckTifFileName))
            .from(mapSheetMngHstEntity)
            .innerJoin(mapInkx5kEntity)
            .on(mapSheetMngHstEntity.mapSheetNum.eq(mapInkx5kEntity.mapidcdNo))
            .where(whereBuilder)
            .orderBy(mapSheetMngHstEntity.createdDate.desc())
            .offset(pageable.getOffset())
            .limit(pageable.getPageSize())
            .fetch();

    Long countQuery =
        queryFactory
            .select(mapSheetMngHstEntity.hstUid.count())
            .from(mapSheetMngHstEntity)
            .innerJoin(mapInkx5kEntity)
            .on(mapSheetMngHstEntity.mapSheetCode.eq(mapInkx5kEntity.fid))
            .leftJoin(mapInkx50kEntity)
            .on(mapInkx5kEntity.fidK50.eq(mapInkx50kEntity.fid.longValue()))
            .where(whereBuilder)
            .fetchOne();

    return new PageImpl<>(foundContent, pageable, countQuery);
  }

  @Override
  public MapSheetMngDto.ErrorDataDto findMapSheetError(Long hstUid) {

    BooleanBuilder whereBuilder = new BooleanBuilder();
    whereBuilder.and(mapSheetMngHstEntity.hstUid.eq(hstUid));

    MapSheetMngDto.ErrorDataDto foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.ErrorDataDto.class,
                    mapSheetMngHstEntity.hstUid,
                    mapSheetMngHstEntity.mapSheetNum,
                    Expressions.stringTemplate(
                            "concat({0},substring({1}, 0, 6))",
                            mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                        .as("map50kName"),
                    Expressions.stringTemplate(
                            "concat({0},substring({1}, 6, 8))",
                            mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                        .as("map5kName"),
                    Expressions.stringTemplate(
                            "concat({0},substring({1}, 6, 8))",
                            mapInkx5kEntity.mapidNm, mapSheetMngHstEntity.mapSheetNum)
                        .as("mapSrcName"),
                    mapInkx5kEntity.fid,
                    mapSheetMngHstEntity.createdDate,
                    mapSheetMngHstEntity.syncState,
                    mapSheetMngHstEntity.syncTfwFileName,
                    mapSheetMngHstEntity.syncTifFileName,
                    mapSheetMngHstEntity.syncCheckState,
                    mapSheetMngHstEntity.syncCheckTfwFileName,
                    mapSheetMngHstEntity.syncCheckTifFileName))
            .from(mapSheetMngHstEntity)
            .innerJoin(mapInkx5kEntity)
            .on(mapSheetMngHstEntity.mapSheetNum.eq(mapInkx5kEntity.mapidcdNo))
            .where(whereBuilder)
            .fetchOne();

    return foundContent;
  }

  @Override
  public List<MapSheetMngDto.MngFilesDto> findIdToMapSheetFileList(Long hstUid) {

    BooleanBuilder whereBuilder = new BooleanBuilder();
    whereBuilder.and(mapSheetMngFileEntity.hstUid.eq(hstUid));

    List<MapSheetMngDto.MngFilesDto> foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.MngFilesDto.class,
                    mapSheetMngFileEntity.fileUid,
                    mapSheetMngFileEntity.mngYyyy,
                    mapSheetMngFileEntity.mapSheetNum,
                    mapSheetMngFileEntity.refMapSheetNum,
                    mapSheetMngFileEntity.filePath,
                    mapSheetMngFileEntity.fileName,
                    mapSheetMngFileEntity.fileExt,
                    mapSheetMngFileEntity.hstUid,
                    mapSheetMngFileEntity.fileSize))
            .from(mapSheetMngFileEntity)
            .where(whereBuilder)
            .fetch();

    return foundContent;
  }

  @Override
  public List<MapSheetMngDto.MngFilesDto> findHstUidToMapSheetFileList(Long hstUid) {
    BooleanBuilder whereBuilder = new BooleanBuilder();
    whereBuilder.and(mapSheetMngFileEntity.hstUid.eq(hstUid));

    List<MapSheetMngDto.MngFilesDto> foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.MngFilesDto.class,
                    mapSheetMngFileEntity.fileUid,
                    mapSheetMngFileEntity.mngYyyy,
                    mapSheetMngFileEntity.mapSheetNum,
                    mapSheetMngFileEntity.refMapSheetNum,
                    mapSheetMngFileEntity.filePath,
                    mapSheetMngFileEntity.fileName,
                    mapSheetMngFileEntity.fileExt,
                    mapSheetMngFileEntity.hstUid,
                    mapSheetMngFileEntity.fileSize))
            .from(mapSheetMngFileEntity)
            .where(whereBuilder)
            .orderBy(mapSheetMngFileEntity.fileExt.desc())
            .fetch();

    return foundContent;
  }

  @Override
  public MapSheetMngDto.MngFilesDto findYyyyToMapSheetFilePath(int mngYyyy) {

    BooleanBuilder whereBuilder = new BooleanBuilder();
    whereBuilder.and(mapSheetMngFileEntity.mngYyyy.eq(mngYyyy));

    MapSheetMngDto.MngFilesDto foundContent =
        queryFactory
            .select(
                Projections.constructor(
                    MapSheetMngDto.MngFilesDto.class,
                    mapSheetMngFileEntity.fileUid,
                    mapSheetMngFileEntity.mngYyyy,
                    mapSheetMngFileEntity.mapSheetNum,
                    mapSheetMngFileEntity.refMapSheetNum,
                    mapSheetMngFileEntity.filePath,
                    mapSheetMngFileEntity.fileName,
                    mapSheetMngFileEntity.fileExt,
                    mapSheetMngFileEntity.hstUid,
                    mapSheetMngFileEntity.fileSize))
            .from(mapSheetMngFileEntity)
            .where(whereBuilder)
            .fetchOne();

    return foundContent;
  }

  public void MapSheetMngComplete(int mngYyyy) {
    long execCount =
        queryFactory
            .update(mapSheetMngEntity)
            .set(mapSheetMngEntity.mngState, "COMPLETE")
            .where(mapSheetMngEntity.mngYyyy.eq(mngYyyy))
            .execute();
  }

  @Override
  public void deleteByMngYyyyMngAll(int mngYyyy) {

    long deletedFileCount =
        queryFactory
            .delete(mapSheetMngFileEntity)
            .where(mapSheetMngFileEntity.mngYyyy.eq(mngYyyy))
            .execute();

    long deletedHisCount =
        queryFactory
            .delete(mapSheetMngHstEntity)
            .where(mapSheetMngHstEntity.mngYyyy.eq(mngYyyy))
            .execute();

    long deletedMngCount =
        queryFactory
            .delete(mapSheetMngEntity)
            .where(mapSheetMngEntity.mngYyyy.eq(mngYyyy))
            .execute();
  }

  @Override
  public void deleteByMngYyyyMng(int mngYyyy) {

    long deletedMngCount =
        queryFactory
            .delete(mapSheetMngEntity)
            .where(mapSheetMngEntity.mngYyyy.eq(mngYyyy))
            .execute();
  }

  @Override
  public void deleteByMngYyyyMngHst(int mngYyyy) {

    long deletedHisCount =
        queryFactory
            .delete(mapSheetMngHstEntity)
            .where(mapSheetMngHstEntity.mngYyyy.eq(mngYyyy))
            .execute();
  }

  @Override
  public void deleteByMngYyyyMngFile(int mngYyyy) {

    long deletedFileCount =
        queryFactory
            .delete(mapSheetMngFileEntity)
            .where(mapSheetMngFileEntity.mngYyyy.eq(mngYyyy))
            .execute();
  }

  @Override
  public void deleteByFileUidMngFile(Long fileUid) {
    long deletedFileCount =
        queryFactory
            .delete(mapSheetMngFileEntity)
            .where(mapSheetMngFileEntity.fileUid.eq(fileUid))
            .execute();
  }

  @Override
  public int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy) {

    String sql =
        """
            INSERT INTO tb_map_sheet_mng_hst
            (
              mng_yyyy
              ,map_sheet_code
              ,map_sheet_num
              ,map_sheet_name
              ,map_sheet_code_src
              ,scale_ratio
              ,ref_map_sheet_num
              ,use_inference
            )
            select
              :mngYyyy as mng_yyyy
              ,fid as map_sheet_code
              ,mapidcd_no::INTEGER as map_sheet_num
              ,mapid_nm as map_sheet_name
              ,fid as map_sheet_code_src
              ,5000 as scale_ratio
              ,((mapidcd_no::INTEGER)/1000) as ref_map_sheet_num
              ,use_inference
            from
              tb_map_inkx_5k
        """;

    // Native Query 생성 및 실행
    Query query = (Query) em.createNativeQuery(sql);
    query.setParameter("mngYyyy", mngYyyy);

    int exeCnt = query.executeUpdate(); // 실행 (영향받은 행의 개수 반환)

    return exeCnt;
  }

  @Override
  public Optional<MapSheetMngHstEntity> findMapSheetMngHstInfo(Long hstUid) {
    return Optional.ofNullable(
        queryFactory
            .selectFrom(mapSheetMngHstEntity)
            .where(mapSheetMngHstEntity.hstUid.eq(hstUid))
            .fetchOne());
  }

  @Override
  public void updateHstFileSizes(
      Long hstUid, long tifSizeBytes, long tfwSizeBytes, long totalSizeBytes) {
    String sql =
        "UPDATE tb_map_sheet_mng_hst SET tif_size_bytes = :tif, tfw_size_bytes = :tfw, total_size_bytes = :tot WHERE hst_uid = :uid";
    Query query = (Query) em.createNativeQuery(sql);
    query.setParameter("tif", tifSizeBytes);
    query.setParameter("tfw", tfwSizeBytes);
    query.setParameter("tot", totalSizeBytes);
    query.setParameter("uid", hstUid);
    query.executeUpdate();
  }

  private NumberExpression<Integer> rowNum() {
    return Expressions.numberTemplate(
        Integer.class, "row_number() over(order by {0} desc)", mapSheetMngHstEntity.createdDate);
  }

  private BooleanExpression mapSheetErrorSearchValue(MapSheetMngDto.ErrorSearchReq searchReq) {
    if (Objects.isNull(searchReq.getSearchValue())) {
      return null;
    }

    // 검색어 1개 값이 도엽명 or 도엽번호 like 검색
    return Expressions.booleanTemplate(
            "{0} like '%" + searchReq.getSearchValue() + "%'", mapSheetMngHstEntity.mapSheetName)
        .or(
            Expressions.booleanTemplate(
                "{0} like '%" + searchReq.getSearchValue() + "%'",
                mapSheetMngHstEntity.mapSheetNum));
  }
}
