package com.bcxin.ars.export;

import com.bcxin.ars.enums.SignType;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author linqinglin
 * @date 2020/09/11 0011 16:30
 */
public class OldDataTrainIdExportWhereStrategy implements ExportWhereStrategy {
    @Override
    public String spliceWhereStr(SignType signType, Map<String, String> columnMap, Map<Object, Object> searchParams, Object key) {
        StringBuilder columnStr = new StringBuilder();

        if("oldData".equals(key.toString())){
            return "";
        }

        if(StringUtils.isEmpty(searchParams.get("oldData"))){
            columnStr.append(" and (trainId = "+searchParams.get("trainId")+" or isolddata =1) ");
        }else if("1".equals(searchParams.get("oldData"))){
            columnStr.append(" and isolddata =1 ");
        }else{
            columnStr.append(" and trainId = "+searchParams.get("trainId")+" ");
            columnStr.append(" and ifnull(isolddata,0)=0 ");
        }

        return columnStr.toString();
    }
}
