package com.engine.htxc.tycgsqehy.service.impl;

import com.engine.core.impl.Service;
import com.engine.htxc.tycgsqehy.entity.TycgsqEntity;
import com.engine.htxc.tycgsqehy.service.TycgsqehyService;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.interfaces.htsc.comInfo.PropBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810027
 * @version: 1.0
 * @CreateDate: 2022-09-14 15:52
 * @Description:通用采购二合一的相关实现
 * @ModifyLog:
 **/
public class TycgsqehyServiceImpl extends Service implements TycgsqehyService {

    @Override
    public List<TycgsqEntity> getRequestIdByXmbh(String xmbh) {
        ArrayList<TycgsqEntity> list = new ArrayList<>();
        //171数据库链接
        RecordSetDataSource rsds = new RecordSetDataSource("tycgsq171");
        PropBean pb = new PropBean();
        //171it采购的表名
        String tableSql = "select * from workflow_bill where id = (select formid from workflow_base where unnumber ='itcgsq' and ISVALID = 1) ";
        rsds.execute(tableSql);
        boolean next = rsds.next();
//        System.out.println(next);
        String TycgsqItTableName = rsds.getString("tablename");
        String itSql  = "select a.*,b.* from "+TycgsqItTableName+" a ,workflow_requestbase b where a.requestid = b.requestid and  a.xmbh ='"+xmbh+"'";
        rsds.execute(itSql);
        while(rsds.next()){
            String requestId = rsds.getString("requestid");
            TycgsqEntity entity = new TycgsqEntity();
            entity.setRequestId(requestId);
            entity.setSystem("htoa");
            entity.setLcbh(rsds.getString("lcbh"));
            entity.setRequestName(rsds.getString("requestname"));
            list.add(entity);
        }
        RecordSet rs = new RecordSet();
        String sql = "select * from workflow_bill where id = (select formid from workflow_base where unnumber ='cgsq') ";
        rs.execute(sql);
        if(rs.next()){
            String tablename = rs.getString("tablename");
            sql = "select a.*,b.* from " +tablename+" a ,workflow_requestbase b where a.requestid = b.requestid and  a.xmbh = ?";
            rs.execute(sql,xmbh);
            while(rs.next()){
                String requestId = rs.getString("requestid");
                TycgsqEntity entity = new TycgsqEntity();
                entity.setRequestId(requestId);
                entity.setSystem("xcoa");
                entity.setRequestName(rs.getString("requestname"));
                entity.setLcbh(rs.getString("lcbh"));
                list.add(entity);
            }
        }
//        System.out.println(list.toString());
        return list;
    }
}
