package com.steering.pss.ydm.pipeleavefactory;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

import java.util.ArrayList;

public class FrmReturnSub extends DBCommon {

    public CoreReturnObject getQueryReturnDataB(ArrayList<String> list,
            String orderNo, String billNo, String salog, String jubNo,String[] arr,String supplyUnit,String balYearMonth,String returnType,String returnCode) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("FrmReturnSub.getQueryReturnDataB");
        if (!orderNo.equals("")) {
            sql += " AND T.ORDER_NO LIKE '%'||'" + orderNo + "'||'%'";
        }
        if (!billNo.equals("")) {
            sql += " AND T.M_BILL_NO LIKE '%'||'" + billNo + "'||'%'";
        }
        if (!salog.equals("")) {
            sql += " AND T.BELONG_CODE ='" + salog + "'";
        }
        if (!jubNo.equals("")) {
            sql += " AND T.JUDGE_STOVE_NO ='" + jubNo + "'";
        }
        if(supplyUnit.equals("120501"))
        {
            sql += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
        }else if(supplyUnit.equals("120504")){
            sql += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
        }
        if (!balYearMonth.equals("")) {
            sql += " AND T.BAL_YEAR_MONTH = '" + balYearMonth + "'";
        }
        if (!returnType.equals("")) {
            sql += " AND T.RETURN_TYPE = '" + returnType + "'";
        }
        if (!returnCode.equals("")) {
            sql += " AND T.RETURN_CODE LIKE '%'||'" + returnCode + "'||'%'";
        }
        //2025-3-15 去掉数据权限
        //sql += CoreConverter.toSqlConditionString("T.BELONG_CODE",arr);
        sql += "   GROUP BY T.JUDGE_STOVE_NO, T.BATCH_NO, T.BATCH_GROUD_NO, T.ORDER_NO, "
                + " T.ORDER_SEQ, T.DELIVERY_NO, T.M_BILL_NO, T.MATERIAL_NAME, T.RECEIV_NM,T.MEMO,"
                + "T.PRODUCNAME, T.GRADENAME, T.STEELNAME, T.SPEC_NAME, T.MODEL_DESC,"
                + "T.STORAGE_NO, B.STORAGE_NAME, T.STD_NAME, T.STD_STYLE_DESC, T.BELONG_CODE, "
                + "T.BELONG_NAME, T.CREATE_NAME, T.ORD_LN_DLY_PK, T.ACT_LEN_MIN, T.ACT_LEN_MAX,T.IN_MOLD,T.FINISHPRO_MOLD, "
                + "T.RETURN_TYPE,T.RETURN_CODE,T.BAL_YEAR_MONTH "
                + "  ORDER BY CREATE_TIME DESC";
        return this.getData(sql, list.toArray());
    }
}
