package weaver.interfaces.htsc.cgrwd;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

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

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-09-24
 * @Description: 申请节点提交后删除明细表数据
 * @ModifyLog:
 *
 * 总部重要事项 拟稿节点提交执行
 **/

public class cgrwdFsFjAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();

        String requestid = requestInfo.getRequestid();
        bb.writeLog( "----cgrwdTjFjAction-------" + requestid );
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表

        try {
            String sql = " update " + tablename + " set zdfj = fj where requestid='" + requestid + "' and zdfj is not null ";
            bb.writeLog( "----sql-------" + sql );
            boolean flag = rs.executeUpdate( sql );
            bb.writeLog( "----flag-------" + flag );
            if(!flag){
                requestInfo.getRequestManager().setMessageid( "111111" );
                requestInfo.getRequestManager().setMessagecontent( "更新附件信息失败" );
                return Action.FAILURE_AND_CONTINUE;
            }
        } catch (Exception e) {
            e.printStackTrace();
            writeLog( "异常参考:" + e );
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "流程提交失败" );
            return Action.FAILURE_AND_CONTINUE;
        }
        return Action.SUCCESS;
    }


    public List<String> getOtherDept(){
        PropBean pb = new PropBean();
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        String deptcode = pb.getPropName("ItlxlcQtBm");
        bb.writeLog("deptcode:"+deptcode);
        if(!"".equals(deptcode)){
            deptcode = "'"+deptcode.replaceAll(",","','")+"'";
        }
        bb.writeLog("deptcode:"+deptcode);
        List<String> list = new ArrayList<String>();

        String sql ="  select id,departmentcode from hrmdepartment d\n" +
                " connect by prior d.id = d.supdepid\n" +
                " start with d.departmentcode in ("+deptcode+") ";
        bb.writeLog("sql:"+sql);
        rs.execute(sql);
        while (rs.next()){
            String id = Util.null2String(rs.getString("id"));
            list.add(id);
        }
        bb.writeLog("list:"+list.size());
        return list;
    }


}
