package com.engine.htsc.seal.web;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SealSync {

    public  void ismainyywjisnull(String reqid,int zzyy){
        RecordSet rs = new RecordSet();
        BaseBean blog=  new  BaseBean();
        synchronized(SealSync.class){
             /*  Lock lock= new ReentrantLock();
                 lock.lock();*/
            try {
                String formid = getMaintable(reqid);
                String formcount = "";
                String sqlvalue = "select count(*) as formcount from  " + formid + " " + " where dzyyj is not null and requestid=" + reqid;
                JAVATools.SetCmdwritelog("sqlmain是:" + sqlvalue + "req:" + reqid);
                rs.execute(sqlvalue);
                if (rs.next()) {
                    formcount = com.weaver.general.Util.null2String(rs.getString("formcount"));
                }
                if ("".equals(formcount) || "0".equals(formcount)) {
                    sqlvalue = "update " + formid + " set dzyyj='" + zzyy + "' where requestid=" + reqid;
                } else {
                    sqlvalue = "update " + formid + " set dzyyj=dzyyj||','||'" + zzyy + "' where requestid=" + reqid;
                }
                JAVATools.SetCmdwritelog("sqlmainupdate是:" + sqlvalue + "req:" + reqid);
                rs.execute(sqlvalue);
            }catch (Exception exo){

            }finally {
                // lock.unlock();
            }
        }



    }


    public String getMaintable(String reqid){
        RecordSet rs = new RecordSet();
        String sql = " select abs(t.formid) as formid \n" +
                " from workflow_base t\n" +
                " inner join workflow_requestbase l on l.workflowid = t.id\n" +
                " where l.requestid=" + reqid + "";
        rs.execute(sql);
        String formid = "formtable_main_";

        if (rs.next()) {
            formid = formid + com.weaver.general.Util.getIntValues(rs.getString("formid"));
        }
        return formid;
    }



}
