package com.chinacreator.process.dao;

import com.chinacreator.process.bean.BoYuanBean;
import com.chinacreator.process.bean.BoYuanLogBean;
import com.chinacreator.process.util.DataSource;
import com.frameworkset.common.poolman.SQLExecutor;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@Component
public class BoYuanSyncDao {

//    public List<Map> findSyncData() throws SQLException {
//        String sql="select t.* ,s.PRICE　from TD_BAOYUAN_SYNC_ORDER t join  tb_sp_info s on  t.spid=s.spid where  STATUS in ('1','3') and  SYNCCNT<3 and rownum < 100";
//        return  SQLExecutor.queryListWithDBName(Map.class,DataSource.NET3G,sql);
//
//    }

    public List<BoYuanBean> findSyncData() throws SQLException {
        String sql="select t.* ,s.PRICE　from TD_BAOYUAN_SYNC_ORDER t join  tb_sp_info s on  t.spid=s.spid " +
                "where  STATUS in ('1','3') and  SYNCCNT<4 and rownum < 100";
        return  SQLExecutor.queryListWithDBName(BoYuanBean.class,DataSource.NET3G,sql);

    }

    /**
     * 修改主表数据
     * @param bean
     * @throws SQLException
     */
    public void  updateBoYuan(BoYuanBean bean) throws SQLException {
        String sql="update  TD_BAOYUAN_SYNC_ORDER  t set t.SYNCTIME=to_date(#[synctime],'yyyymmddhh24miss')," +
                "t.status=#[status], t.synccnt=t.synccnt+1,t.inputparams=#[inputparams], " +
                "t.outparams=#[outparams]  where t.id=#[id] ";
        SQLExecutor.updateBean(DataSource.NET3G,sql,bean);
    }

    public void  insertBoYuanLogBean(BoYuanLogBean bean) throws SQLException {
        String sql="insert into TL_BAOYUAN_SYNC_ORDER_LOG(id,syncid,userid,cpid,spid,type,synctime,inputtime," +
                "inputparams,outparams,inputparamsback) " +
                " values(to_char(sysdate,'yyyyMMddhh24miss')||SEQ_COMMON6.nextval,#[syncid],#[userid],#[cpid], " +
                " #[spid],#[type],to_date(#[synctime],'yyyymmddhh24miss'),to_date(#[inputtime],'yyyymmddhh24miss')," +
                "#[inputparams],#[outparams],#[inputparamsback])";
        SQLExecutor.insertBean(DataSource.NET3G, sql, bean);
    }
}
