package com.engine.htxc.contract.dao;

import com.engine.htxc.contract.entity.UfProduct;
import com.engine.htxc.contract.entity.UfProductCounterParty;
import org.apache.commons.lang.StringUtils;
import weaver.conn.RecordSet;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810050
 * @version: 1.0
 * @CreateDate: 2022/8/2315:55
 * @Description: 产品信息dao
 * @ModifyLog:
 **/
public class ProductDao {
    public static  UfProduct selectProductByProductId(String productId){
        if (StringUtils.isEmpty(productId)) {
            return null;
        }
        String sql="select id,requestid,productid,productname from uf_product where productid=?";
        final RecordSet recordSet = new RecordSet();
        recordSet.executeQuery(sql,productId);
        if(recordSet.next()){
            return null;
        }
        final UfProduct ufProduct = new UfProduct();
        ufProduct.setId(recordSet.getInt("id"));
        ufProduct.setProductname(recordSet.getString("productname"));
        ufProduct.setProductid(recordSet.getString("productid"));
        return ufProduct;
    }

    public static  UfProductCounterParty selectUfProductCounterpartyByProductid(String productid){
        if(StringUtils.isBlank(productid)){
            return null;
        }
        String sql="select id,requestid,productid,socialcreditcode from uf_prodcontrelation where productid=?";
        final RecordSet recordSet = new RecordSet();
        recordSet.executeQuery(sql,productid);
        final boolean next = recordSet.next();
        if(!next){
            return null;
        }
        final UfProductCounterParty ufProductCounterParty = new UfProductCounterParty();
        ufProductCounterParty.setId(recordSet.getInt("id"));
        ufProductCounterParty.setRequestid(recordSet.getInt("requestid"));
        ufProductCounterParty.setProductid(recordSet.getString("productid"));
        ufProductCounterParty.setSocialcreditcode(recordSet.getString("socialcreditcode"));
        return ufProductCounterParty;
    }
}
