package cn.gov.customs.data.timer;


import cn.gov.customs.data.entity.wxjy.bus.NewDeclaredGoods;
import cn.gov.customs.data.entity.wxjy.common.PubCustomsMapping;
import cn.gov.customs.data.repository.h2018.H2018Repository;
import cn.gov.customs.data.repository.wxjy.WxjyRepository;
import cn.gov.customs.data.repository.wxjy.bus.NewDeclaredGoodsRepository;
import cn.gov.customs.data.repository.wxjy.common.PubCustomsMappingRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.*;

/**
* @Description: * 1、危险货物：
 *  * 匹配字段：进口（经营单位）或出口（生产单位）、CIQ编码、UN编码
 *  * 提取维度：申报日期（进一年内、只提取命中查检的数据，ungid不为空）
 *  * 2、危化品：
 *  * 匹配字段：进口（经营单位）或出口（生产单位）、CIQ编码、规格型号提取CAS号（有就提取）
 *  * 提取维度：申报日期（进一年内、只提取命中查检的数据）、货物属性（31或32）
 *  * 新申报商品
* @Author wq
* @Date 2025-10-16 14:31:11
* @Version 1.0
*/
@Component
@Configuration
@PropertySource("classpath:data-acquisition.properties")
public class H2018NewDeclaredGoodsUtil {

   Logger logger = LoggerFactory.getLogger(H2018NewDeclaredGoodsUtil.class);

   @Autowired
   private H2018Repository h2018Dao;

   @Autowired
   private WxjyRepository dao;

    @Autowired
    private PubCustomsMappingRepository mappingRepository;

    @Autowired
    private NewDeclaredGoodsRepository newDeclaredGoodsRepository;

   @SuppressWarnings("unchecked")
   public void toDoDataMain(Date statBegin, List<String> list) {
       Date date = new Date();
       List<PubCustomsMapping> custMapping = mappingRepository.findAll();
       Map<String,String> map = new HashMap<String,String>();
       for (PubCustomsMapping m : custMapping) {
           String pCustomCode = m.getMappingCode();
           map.put(m.getCustomsCode(), pCustomCode);
       }
       dao.executeUpdate("delete from WXJY_NEW_DECLARED_GOODS");
       //危险货物
        toDoGoods(statBegin,date, list,map);
        //危化品
        toDoChemical(statBegin,date, list,map);
   }

   private void toDoGoods(Date statBegin, Date date, List<String> casList, Map<String,String> map){
       //危险货物可以直接sql语句捞取第一次申报商品，无须去重
       String sql = "select d.d_date,d.i_e_flag,d.i_e_port,d.decl_port,d.CONSIGN_SCC,d.CONSIGN_CODE,d.CONSIGN_NAME,l.ENTRY_ID,l.G_NO,l.CODE_TS," +
               "l.IQ_CODE,l.G_NAME,l.G_MODEL,l.IQ_G_NAME,l.G_NAME_FN,l.IQ_G_MODEL,l.G_COMPOSITION,l.PROD_VALIDATY,l.PROD_WARRANTY,l.DUTY_MODE,l.GTIN," +
               "l.G_QTY,l.G_UNIT,l.QTY_1,l.UNIT_1,l.QTY_2,l.UNIT_2,l.DECL_PRICE,l.DECL_TOTAL,l.TRADE_CURR,l.TRADE_TOTAL,l.DUTY_VALUE,l.RMB_PRICE,l.USD_PRICE," +
               "l.EXCHANGE_RATE,l.ORIGIN_COUNTRY,l.ORIGIN_REGION_CODE,l.DEST_COUNTRY,l.I_E_DISTRICT_CODE,l.IQ_I_E_DISTRICT_CODE,l.FRN_PRODUCER_NAME,l.PRODUCT_DATE," +
               "l.PRODUCT_BATCH,l.UNGID,PRODUCT_MODEL,l.PRODUCT_BRAND,l.UNG_FLAG,l.UNG_MODEL,l.UNG_CLASSIFY,l.UNG_G_NAME,l.PRODUCT_CHAR_CODE,l.GOODS_ID,l.USE_TO," +
               "l.G_CERT_FLAG,l.MNUFCTR_REG_NO from ENTRY_HEAD d, ENTRY_LIST l, `g_whdb_customs_inspection`.RSK_CHECK_FORM f,(" +
               "select h.CONSIGN_CODE,l.IQ_CODE,l.UNGID,count(h.CONSIGN_CODE),count(l.IQ_CODE),count(l.UNGID) from " +
               "ENTRY_HEAD h, ENTRY_LIST l, `g_whdb_customs_inspection`.RSK_CHECK_FORM f where h.ENTRY_ID = l.ENTRY_ID and h.ENTRY_ID = f.ENTRY_ID " +
               "and h.ENTRY_ID like '47%' and h.D_DATE >= ? and l.UNGID is not null group by h.CONSIGN_CODE,l.IQ_CODE,l.UNGID " +
               "having count(h.CONSIGN_CODE) = 1 and count(l.IQ_CODE) = 1 and count(l.UNGID) = 1) m " +
               "where d.ENTRY_ID = l.ENTRY_ID and d.ENTRY_ID = f.ENTRY_ID and d.CONSIGN_CODE = m.CONSIGN_CODE and l.IQ_CODE = m.IQ_CODE and l.UNGID = m.UNGID " +
               "and d.ENTRY_ID like '47%' and d.D_DATE >= ? and l.UNGID is not null and not exists(select d.entry_id from `g_whdb_riskh2000`.ENTRY_OP_LOG o " +
               "where substr(o.OP_TYPE,1,1) = '0' and d.ENTRY_ID = o.ENTRY_ID) and not exists(select d.entry_id from `g_whdb_riskh2000`.SPECIAL_ENTRY s " +
               "where d.ENTRY_ID = s.ENTRY_ID) ;";
       List<Object[]> list = (List<Object[]>) h2018Dao.getQueryBySql(sql,statBegin,statBegin);
       for (Object[] d : list) {
           Date dDate = (Date)d[0];//申报日期
           String ieFlag = (String)d[1];//进出口标识
           String iePort = (String)d[2];//进出境口岸
           String declPort = (String)d[3];//申报口岸
           String customsCode = map.get(declPort);
           String consignScc = (String)d[4];//申报口岸
           String consignCode = (String) d[5];
           String consignName = (String) d[6];
           String entryId = (String)d[7];//报关单编号
           BigDecimal gNo = (BigDecimal)d[8];//商品序号
           String codeTs = (String)d[9];//商品编号
           String iqCode = (String)d[10];//检验检疫编码
           String gName = (String)d[11];//商品名称
           String gModel = (String)d[12];//商品规格型号
           String iqGName = (String)d[13];//报检名称
           String gNameFn = (String)d[14];//商品英文名称
           String iqGModel = (String)d[15];//检验检疫货物规格
           String gComposition = (String)d[16];//产品保质期
           String prodValidaty = (String)d[17];//产品有效期
           BigDecimal prodWarranty = (BigDecimal)d[18];//产品保质期
           String dutyMode = (String)d[19];//征免方式
           String gtin = (String)d[20];//条形码
           BigDecimal gQty = (BigDecimal)d[21];//申报数量
           String gUnit = (String)d[22];//申报计量单位
           BigDecimal qty1 = (BigDecimal)d[23];//法定第一数量
           String unit1 = (String)d[24];//法定第一数量
           BigDecimal qty2 = (BigDecimal)d[25];//第二数量
           String unit2 = (String)d[26];//法定第二数量
           BigDecimal declPrice = (BigDecimal)d[27];//申报单价
           BigDecimal declTotal = (BigDecimal)d[28];//申报总价
           String tradeCurr = (String)d[29];//成交币制
           BigDecimal tradeTotal = (BigDecimal)d[30];//成交总价
           BigDecimal dutyValue = (BigDecimal)d[31];//完税价格
           BigDecimal rmbPrice = (BigDecimal)d[32];//统计人民币价
           BigDecimal usdPrice = (BigDecimal)d[33];//统计美元价
           BigDecimal exchangeRate = (BigDecimal)d[34];//成交汇率
           String originCountry = (String)d[35];//原产国（地区）
           String originRegionCode = (String)d[36];//原产地区代码
           String destCountry = (String)d[37];//最终目的国（地区）
           String ieDistrictCode = (String)d[38];//境内目的地/境内货源地
           String iqIeDistrictCode = (String)d[39];//目的地/货源地
           String frnProducerName = (String)d[40];//境外生产企业名称
           String productDate = (String)d[41];//生产日期
           String productBatch = (String)d[42];//生产日期
           String ungid = (String)d[43];//UN编码
           String productModel = (String)d[44];//货物型号
           String productBrand = (String)d[45];//境内目的地/境内货源地
           String ungFlag = (String)d[46];//非危险化学品
           String ungModel = (String)d[47];//危包规格
           String ungClassify = (String)d[48];//危包类别
           String ungGName = (String)d[49];//危险货物名称
           String productCharCode = (String)d[50];//货物属性代码
           String goodsId = (String)d[51];//货号
           String useTo = (String)d[52];//用途代码
           String gCertFlag = (String)d[53];//每项商品需要监管证件
           String mnufctrRegNo = (String)d[54];//生产单位注册号
           //使用java8 stream查找list中是否包含gModel的cas号,有返回cas号,无返回null
           String cas = casList.stream().filter(u -> gModel.contains(u)).findFirst().orElse(null);
           NewDeclaredGoods bus = new NewDeclaredGoods();
           bus.setDeclDate(dDate);
           bus.setIeFlag(ieFlag);
           bus.setIePort(iePort);
           bus.setDeclPort(declPort);
           bus.setCustomsCode(customsCode);
           bus.setConsignScc(consignScc);
           bus.setConsignCode(consignCode);
           bus.setConsignName(consignName);
           bus.setEntryId(entryId);
           bus.setGNo(gNo);
           bus.setCodeTs(codeTs);
           bus.setIqCode(iqCode);
           bus.setGName(gName);
           bus.setGModel(gModel);
           bus.setIqGName(iqGName);
           bus.setGNameFn(gNameFn);
           bus.setIqGModel(iqGModel);
           bus.setGComposition(gComposition);
           bus.setProdValidaty(prodValidaty);
           bus.setProdWarranty(prodWarranty);
           bus.setDutyMode(dutyMode);
           bus.setGtin(gtin);
           bus.setGQty(gQty);
           bus.setGUnit(gUnit);
           bus.setQty1(qty1);
           bus.setUnit1(unit1);
           bus.setQty2(qty2);
           bus.setUnit2(unit2);
           bus.setDeclPrice(declPrice);
           bus.setDeclTotal(declTotal);
           bus.setTradeCurr(tradeCurr);
           bus.setTradeTotal(tradeTotal);
           bus.setDutyValue(dutyValue);
           bus.setRmbPrice(rmbPrice);
           bus.setUsdPrice(usdPrice);
           bus.setExchangeRate(exchangeRate);
           bus.setOriginCountry(originCountry);
           bus.setOriginRegionCode(originRegionCode);
           bus.setDestCountry(destCountry);
           bus.setIeDistrictCode(ieDistrictCode);
           bus.setIqIeDistrictCode(iqIeDistrictCode);
           bus.setFrnProducerName(frnProducerName);
           bus.setProductDate(productDate);
           bus.setProductBatch(productBatch);
           bus.setUngid(ungid);
           bus.setProductModel(productModel);
           bus.setProductBrand(productBrand);
           bus.setUngFlag(ungFlag);
           bus.setUngModel(ungModel);
           bus.setUngClassify(ungClassify);
           bus.setUngGName(ungGName);
           bus.setProductCharCode(productCharCode);
           bus.setGoodsId(goodsId);
           bus.setUseTo(useTo);
           bus.setGCertFlag(gCertFlag);
           bus.setMnufctrRegNo(mnufctrRegNo);
           bus.setCas(cas);
           bus.setCreateTime(date);
           bus.setGoodsType("2");
           bus.setId(dao.getGuidStringBySql());
           newDeclaredGoodsRepository.save(bus);
       }
   }

    private void toDoChemical(Date statBegin, Date date, List<String> casList, Map<String,String> map){
        //危险化学品需要查询出来后再做进一步是否第一次申报判断，查出来的危化品可能也是危险货物
        String sql = "select d.d_date,d.i_e_flag,d.i_e_port,d.decl_port,d.CONSIGN_SCC,d.CONSIGN_CODE,d.CONSIGN_NAME,l.ENTRY_ID,l.G_NO,l.CODE_TS," +
                "l.IQ_CODE,l.G_NAME,l.G_MODEL,l.IQ_G_NAME,l.G_NAME_FN,l.IQ_G_MODEL,l.G_COMPOSITION,l.PROD_VALIDATY,l.PROD_WARRANTY,l.DUTY_MODE,l.GTIN," +
                "l.G_QTY,l.G_UNIT,l.QTY_1,l.UNIT_1,l.QTY_2,l.UNIT_2,l.DECL_PRICE,l.DECL_TOTAL,l.TRADE_CURR,l.TRADE_TOTAL,l.DUTY_VALUE,l.RMB_PRICE,l.USD_PRICE," +
                "l.EXCHANGE_RATE,l.ORIGIN_COUNTRY,l.ORIGIN_REGION_CODE,l.DEST_COUNTRY,l.I_E_DISTRICT_CODE,l.IQ_I_E_DISTRICT_CODE,l.FRN_PRODUCER_NAME,l.PRODUCT_DATE," +
                "l.PRODUCT_BATCH,l.UNGID,PRODUCT_MODEL,l.PRODUCT_BRAND,l.UNG_FLAG,l.UNG_MODEL,l.UNG_CLASSIFY,l.UNG_G_NAME,l.PRODUCT_CHAR_CODE,l.GOODS_ID,l.USE_TO," +
                "l.G_CERT_FLAG,l.MNUFCTR_REG_NO from ENTRY_HEAD d, ENTRY_LIST l, `g_whdb_customs_inspection`.RSK_CHECK_FORM f,(" +
                "select h.CONSIGN_CODE,l.IQ_CODE,l.PRODUCT_CHAR_CODE,count(h.CONSIGN_CODE),count(l.IQ_CODE),count(l.PRODUCT_CHAR_CODE) from " +
                "ENTRY_HEAD h, ENTRY_LIST l, `g_whdb_customs_inspection`.RSK_CHECK_FORM f where h.ENTRY_ID = l.ENTRY_ID and h.ENTRY_ID = f.ENTRY_ID " +
                "and h.ENTRY_ID like '47%' and h.D_DATE >= ? and (l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%31%') group by h.CONSIGN_CODE,l.IQ_CODE,l.PRODUCT_CHAR_CODE " +
                "having count(h.CONSIGN_CODE) = 1 and count(l.IQ_CODE) = 1 and count(l.PRODUCT_CHAR_CODE) = 1) m " +
                "where d.ENTRY_ID = l.ENTRY_ID and d.ENTRY_ID = f.ENTRY_ID and d.CONSIGN_CODE = m.CONSIGN_CODE and l.IQ_CODE = m.IQ_CODE and l.PRODUCT_CHAR_CODE = m.PRODUCT_CHAR_CODE " +
                "and d.ENTRY_ID like '47%' and d.D_DATE >= ? and (l.PRODUCT_CHAR_CODE like '%31%' or l.PRODUCT_CHAR_CODE like '%31%') and not exists(select d.entry_id from `g_whdb_riskh2000`.ENTRY_OP_LOG o " +
                "where substr(o.OP_TYPE,1,1) = '0' and d.ENTRY_ID = o.ENTRY_ID) and not exists(select d.entry_id from `g_whdb_riskh2000`.SPECIAL_ENTRY s " +
                "where d.ENTRY_ID = s.ENTRY_ID) ;";
        List<Object[]> list = (List<Object[]>) h2018Dao.getQueryBySql(sql,statBegin,statBegin);
        for (Object[] d : list) {
            Date dDate = (Date)d[0];//申报日期
            String ieFlag = (String)d[1];//进出口标识
            String iePort = (String)d[2];//进出境口岸
            String declPort = (String)d[3];//申报口岸
            String customsCode = map.get(declPort);
            String consignScc = (String)d[4];//申报口岸
            String consignCode = (String) d[5];
            String consignName = (String) d[6];
            String entryId = (String)d[7];//报关单编号
            BigDecimal gNo = (BigDecimal)d[8];//商品序号
            String codeTs = (String)d[9];//商品编号
            String iqCode = (String)d[10];//检验检疫编码
            String gName = (String)d[11];//商品名称
            String gModel = (String)d[12];//商品规格型号
            String iqGName = (String)d[13];//报检名称
            String gNameFn = (String)d[14];//商品英文名称
            String iqGModel = (String)d[15];//检验检疫货物规格
            String gComposition = (String)d[16];//产品保质期
            String prodValidaty = (String)d[17];//产品有效期
            BigDecimal prodWarranty = (BigDecimal)d[18];//产品保质期
            String dutyMode = (String)d[19];//征免方式
            String gtin = (String)d[20];//条形码
            BigDecimal gQty = (BigDecimal)d[21];//申报数量
            String gUnit = (String)d[22];//申报计量单位
            BigDecimal qty1 = (BigDecimal)d[23];//法定第一数量
            String unit1 = (String)d[24];//法定第一数量
            BigDecimal qty2 = (BigDecimal)d[25];//第二数量
            String unit2 = (String)d[26];//法定第二数量
            BigDecimal declPrice = (BigDecimal)d[27];//申报单价
            BigDecimal declTotal = (BigDecimal)d[28];//申报总价
            String tradeCurr = (String)d[29];//成交币制
            BigDecimal tradeTotal = (BigDecimal)d[30];//成交总价
            BigDecimal dutyValue = (BigDecimal)d[31];//完税价格
            BigDecimal rmbPrice = (BigDecimal)d[32];//统计人民币价
            BigDecimal usdPrice = (BigDecimal)d[33];//统计美元价
            BigDecimal exchangeRate = (BigDecimal)d[34];//成交汇率
            String originCountry = (String)d[35];//原产国（地区）
            String originRegionCode = (String)d[36];//原产地区代码
            String destCountry = (String)d[37];//最终目的国（地区）
            String ieDistrictCode = (String)d[38];//境内目的地/境内货源地
            String iqIeDistrictCode = (String)d[39];//目的地/货源地
            String frnProducerName = (String)d[40];//境外生产企业名称
            String productDate = (String)d[41];//生产日期
            String productBatch = (String)d[42];//生产日期
            String ungid = (String)d[43];//UN编码
            String productModel = (String)d[44];//货物型号
            String productBrand = (String)d[45];//境内目的地/境内货源地
            String ungFlag = (String)d[46];//非危险化学品
            String ungModel = (String)d[47];//危包规格
            String ungClassify = (String)d[48];//危包类别
            String ungGName = (String)d[49];//危险货物名称
            String productCharCode = (String)d[50];//货物属性代码
            String goodsId = (String)d[51];//货号
            String useTo = (String)d[52];//用途代码
            String gCertFlag = (String)d[53];//每项商品需要监管证件
            String mnufctrRegNo = (String)d[54];//生产单位注册号
            //使用java8 stream查找list中是否包含gModel的cas号,有返回cas号,无返回null
            String cas = casList.stream().filter(u -> gModel.contains(u)).findFirst().orElse(null);
            NewDeclaredGoods bus = new NewDeclaredGoods();
            bus.setDeclDate(dDate);
            bus.setIeFlag(ieFlag);
            bus.setIePort(iePort);
            bus.setDeclPort(declPort);
            bus.setCustomsCode(customsCode);
            bus.setConsignScc(consignScc);
            bus.setConsignCode(consignCode);
            bus.setConsignName(consignName);
            bus.setEntryId(entryId);
            bus.setGNo(gNo);
            bus.setCodeTs(codeTs);
            bus.setIqCode(iqCode);
            bus.setGName(gName);
            bus.setGModel(gModel);
            bus.setIqGName(iqGName);
            bus.setGNameFn(gNameFn);
            bus.setIqGModel(iqGModel);
            bus.setGComposition(gComposition);
            bus.setProdValidaty(prodValidaty);
            bus.setProdWarranty(prodWarranty);
            bus.setDutyMode(dutyMode);
            bus.setGtin(gtin);
            bus.setGQty(gQty);
            bus.setGUnit(gUnit);
            bus.setQty1(qty1);
            bus.setUnit1(unit1);
            bus.setQty2(qty2);
            bus.setUnit2(unit2);
            bus.setDeclPrice(declPrice);
            bus.setDeclTotal(declTotal);
            bus.setTradeCurr(tradeCurr);
            bus.setTradeTotal(tradeTotal);
            bus.setDutyValue(dutyValue);
            bus.setRmbPrice(rmbPrice);
            bus.setUsdPrice(usdPrice);
            bus.setExchangeRate(exchangeRate);
            bus.setOriginCountry(originCountry);
            bus.setOriginRegionCode(originRegionCode);
            bus.setDestCountry(destCountry);
            bus.setIeDistrictCode(ieDistrictCode);
            bus.setIqIeDistrictCode(iqIeDistrictCode);
            bus.setFrnProducerName(frnProducerName);
            bus.setProductDate(productDate);
            bus.setProductBatch(productBatch);
            bus.setUngid(ungid);
            bus.setProductModel(productModel);
            bus.setProductBrand(productBrand);
            bus.setUngFlag(ungFlag);
            bus.setUngModel(ungModel);
            bus.setUngClassify(ungClassify);
            bus.setUngGName(ungGName);
            bus.setProductCharCode(productCharCode);
            bus.setGoodsId(goodsId);
            bus.setUseTo(useTo);
            bus.setGCertFlag(gCertFlag);
            bus.setMnufctrRegNo(mnufctrRegNo);
            bus.setCas(cas);
            bus.setCreateTime(date);
            if(cas != null){
                //consignCode+IQ_CODE+cas号判断库里是否存在
                //危险货物是以consignCode+IQ_CODE+ungid唯一查询后续再讲解析的cas插入，所以可能存在consignCode+IQ_CODE+cas有相同情况但ungid不同
                //cas不为空此时consignCode+IQ_CODE+cas若查到数据说明既是危化品又是危险货物
                List<Object[]> obj = (List<Object[]>)dao.getQueryBySql("select entry_id,G_NO from WXJY_NEW_DECLARED_GOODS where CONSIGN_CODE = ? and IQ_CODE = ? and CAS = ? and UNGID is not null",bus.getConsignCode(),bus.getIqCode(),bus.getCas());
                //如果库中已存在并且g_no能对应上，此时将goods_type改为1,2,3,否则删除代表重复了
                if(obj != null && obj.size() >0){
                    dao.executeUpdate("update WXJY_NEW_DECLARED_GOODS set GOODS_TYPE = '1,2,3' where CONSIGN_CODE = ? and IQ_CODE = ? and CAS = ? and UNGID is not null",bus.getConsignCode(),bus.getIqCode(),bus.getCas());
                } else {
                    //只是危化品但存在相同cas号则删掉
                    List<Object[]> chemList = (List<Object[]>)dao.getQueryBySql("select entry_id,G_NO from WXJY_NEW_DECLARED_GOODS where CONSIGN_CODE = ? and IQ_CODE = ? and CAS = ? and UNGID is null",bus.getConsignCode(),bus.getIqCode(),bus.getCas());
                    if(chemList != null && chemList.size() >0){
                        dao.executeUpdate("delete from WXJY_NEW_DECLARED_GOODS where CONSIGN_CODE = ? and IQ_CODE = ? and CAS = ? and UNGID is null",bus.getConsignCode(),bus.getIqCode(),bus.getCas());
                    } else {
                        bus.setGoodsType("1");
                        bus.setId(dao.getGuidStringBySql());
                        newDeclaredGoodsRepository.save(bus);
                    }
                }
            } else {
                //危化品的填写不规范，很多规格型号中cas号为空,危化品31和32都属于危化品这时重复的consignCode+IQ_CODE删掉
                List<Object[]> obj = (List<Object[]>)dao.getQueryBySql("select * from WXJY_NEW_DECLARED_GOODS where CONSIGN_CODE = ? and IQ_CODE = ? and CAS is null and UNGID is null",bus.getConsignCode(),bus.getIqCode());
                if(obj !=null && obj.size() >0){
                    dao.executeUpdate("delete from WXJY_NEW_DECLARED_GOODS where CONSIGN_CODE = ? and IQ_CODE = ? and CAS is null and UNGID is null",bus.getConsignCode(),bus.getIqCode());
                } else {
                    bus.setGoodsType("1");
                    bus.setId(dao.getGuidStringBySql());
                    newDeclaredGoodsRepository.save(bus);
                }
            }
        }
    }
}
