PoolQueryDTO.java 4.95 KB
package cn.fw.dalaran.domain.dto;

import cn.fw.common.page.BasePageQuery;
import cn.fw.common.web.annotation.LoginContextField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 查询条件
 *
 * @author kurisu
 */

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class PoolQueryDTO extends BasePageQuery {
    /**
     * 平台类型
     */
    private Integer platform;
    /**
     * 账号
     */
    private String account;
    /**
     * 门店id
     */
    private String shopIds;
    /**
     * 门店
     */
    private String shopName;
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 用户
     */
    private String userName;
    /**
     * 时间(区间)
     */
    private String dateStr;
    private LocalDate endDate;
    /**
     * 1升序 2降序
     */
    private Integer order;
    private String orderAtt;

    /**
     * 是否有效
     */
    private Boolean valid;
    /**
     * 主题id
     */
    private Long themeId;
    /**
     * 主题名
     */
    private String theme;
    /**
     * 日期类型
     */
    private Integer dateType;
    /**
     * 最佳直播
     */
    private Boolean bestLive;

    /**
     * 重写valid的get方法
     *
     * @return valid ? 1 : 0
     */
    public List<Integer> getValid() {
        if (Objects.isNull(this.valid))
            return null;
        return valid ? (Objects.nonNull(this.bestLive) && bestLive ? Collections.singletonList(11) : Arrays.asList(1, 11)) : Arrays.asList(0, -1, -2);
    }

    /**
     * 3月16日访问视频池传参数
     * &_s=1647361106415
     * &current=1
     * &pageSize=50
     * &dateType=20
     * &beginDate=1646064000000  2022-03-01 00:00:00
     * &endDate=1647273600000  2022-03-15 00:00:00
     * &shopIds=11,54,155,156,12,57,18,41,20,14,13,53,154,23,39,147,150,153,157
     * &delay=false
     * &reportType=Dalaran001M
     * &reportDate=1647273600000  2022-03-15 00:00:00
     * &startTime=1646064000000,1647273600000  2022-03-01 00:00:00  2022-03-15 00:00:00
     * &dateStr=1646064000000,1647273600000  2022-03-01 00:00:00  2022-03-15 00:00:00
     * &systemType=23
     */

    /**
     * 服务端自己处理的参数
     */
    private String orderString;
    @LoginContextField(LoginContextField.Name.GROUP_ID)
    private Long groupId;

    /**
     * 关联发布时间/开播时间
     *
     * @return
     */
    public LocalDate getDate1() {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        String[] times = dateStr.split(",");
        if (StringUtils.isNotBlank(times[0]) && NumberUtils.isDigits(times[0])) {
            return Instant.ofEpochMilli(NumberUtils.toLong(times[0])).atZone(ZoneId.systemDefault()).toLocalDate();
        }
        return null;
    }

    /**
     * 关联发布时间/开播时间
     *
     * @return
     */
    public LocalDate getDate2() {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        String[] times = dateStr.split(",");
        if (times.length > 1 && StringUtils.isNotBlank(times[1]) && NumberUtils.isDigits(times[1])) {
            final LocalDate date = Instant.ofEpochMilli(NumberUtils.toLong(times[1])).atZone(ZoneId.systemDefault()).toLocalDate();
            if (Objects.equals(dateType, 10))
                return date;
            if (displayYesterday(date))
                return date.minusDays(1);
            else
                return date;
        }
        return null;
    }

    public List<Long> getShopIds() {
        if (StringUtils.isBlank(shopIds)) {
            return null;
        }
        return Arrays.stream(shopIds.split(",")).filter(NumberUtils::isDigits).map(Long::valueOf).collect(Collectors.toList());
    }

    /**
     * 关联创建时间
     *
     * @return
     */
    public LocalDate getEndDate() {
        if (Objects.isNull(endDate)) {
            return null;
        }
        if (Objects.equals(dateType, 10))
            return endDate.plusDays(1);
        if (displayYesterday(endDate))
            return endDate;
        else
            return endDate.plusDays(1);
    }

    /**
     * 是否展示昨天数据
     *
     * @return
     */
    public boolean displayYesterday(LocalDate date) {
        final LocalDate now = LocalDate.now();
        final boolean isSameMonth = Objects.equals(date.withDayOfMonth(1), now.withDayOfMonth(1));
        if (isSameMonth) {
            final LocalDateTime extraTime = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 13, 33, 0);
            return LocalDateTime.now().compareTo(extraTime) <= 0;
        }
        return false;
    }
}