package com.engine.salary.entity.datacollection.param;

import com.engine.salary.common.BaseQueryParam;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.stream.Collectors;

/**
 * 数据采集-考勤引用字段
 * <p>Copyright: Copyright (c) 2022</p>
 * <p>Company: 泛微软件</p>
 *
 * @author qiantao
 * @version 1.0
 **/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
//数据采集-考勤引用字段查询参数")
public class AttendQuoteFieldQueryParam extends BaseQueryParam {

    private Collection<Long> ids;

    private Long id;

    //字段名称
    private String fieldName;

    //根据编码删除
    private Collection<String> codes;
    //来源。1：自定义、2：考勤模块
    private Integer sourceType;

    private Integer enableStatus;

    /**
     * 查询where语句
     *
     * @param queryParam
     */
    public static String genWhereSql(AttendQuoteFieldQueryParam queryParam) {
        String whereSQl = "t1.delete_type = 0 ";
        Collection<Long> ids = queryParam.getIds();
        if (CollectionUtils.isNotEmpty(ids)) {
            String idsStr = ids.stream().map(String::valueOf).collect(Collectors.joining(","));
            whereSQl += " AND t1.id IN (" + idsStr + ")";
        }
        String fieldName = queryParam.getFieldName();
        if (StringUtils.isNotBlank(fieldName)) {
            whereSQl += " AND t1.field_name like '%" + fieldName + "%'";
        }

        return whereSQl;
    }
}
