package com.xiaoniu.system.pointsgoods.dto;

import com.xiaoniu.common.core.resdata.BaseQueryDTO;
import com.xiaoniu.common.core.utils.StringUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author haoxuyang
 * @Date 2024/10/29 18:24
 */
@Data
@Schema(description = "积分商品列表查询参数DTO")
public class PointsGoodsQueryDTO extends BaseQueryDTO {

    @Schema(description = "商品类型")
    private Long goodsType;

    @Schema(description = "商品名称")
    private String goodsName;

    @Schema(description = "状态(1-已上架 2-已下架)")
    private Integer status;

    @Schema(description = "开始时间")
    private String beginTime;

    @Schema(description = "结束时间")
    private String endTime;

    @Schema(description = "排序字段")
    private String sortCol;

    @Schema(description = "排序类型 1升序 2降序")
    private String sortType;

    public String getSortCol() {
        if (StringUtils.isNotNull(sortCol)) {
            String regex = "([A-Z])";
            Matcher matcher = Pattern.compile(regex).matcher(sortCol);
            while (matcher.find()) {
                String target = matcher.group();
                sortCol = sortCol.replaceAll(target, "_" + target.toLowerCase());
            }
        }
        return sortCol;
    }
}
