package weaver.interfaces.htsc.payment;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;
import weaver.workflow.request.RequestManager;

/**
 * k1810012
 * <p>
 * 1、公共费用：否【0】，ngbmfgld赋空;
 * 2、公共费用：否【0】 并且 hjxxjeitxmf<100000时，ngbmfgld赋空；
 * 3、公共费用：是【1】时，ngbmfgld赋值当前拟稿人的分管领导（select t.deptLeaders from hrmdepartmentdefined t ）;
 */
public class PayCplFgld extends BaseBean implements Action {

	@Override
	public String execute(RequestInfo requestInfo) {
		RequestManager requestManager = requestInfo.getRequestManager();
		String tableName = requestManager.getBillTableName();
		int requestId = requestManager.getRequestid();
		writeLog("====处理分管领导开始PayCplFgld@tableName=" + tableName + "@requestId=" + requestId);
		try {
			String sql = "select ggfyqtfy,ngbmfgld,hjxxjeitxmf,szbm from " + tableName + " where REQUESTID=" + requestId;
			RecordSet rs = new RecordSet();
			rs.executeQuery(sql);
			String ggfyqtfy = ""; //公共费用,其他费用
			String ngbmfgld = ""; //拟稿部门分管领导
			String szbm = ""; //所在部门
			double hjxxjeitxmf = 0.0; //合计金额
			if (rs.next()) {
				ggfyqtfy = Util.null2String(rs.getString("ggfyqtfy"));
				ngbmfgld = Util.null2String(rs.getString("ngbmfgld"));
				szbm = Util.null2String(rs.getString("szbm"));
				hjxxjeitxmf = rs.getDouble("hjxxjeitxmf");
			}

			rs.executeQuery("select t.deptLeaders from hrmdepartmentdefined t where deptid =?", szbm);
			if (rs.next()) {
				ngbmfgld = Util.null2String(rs.getString("deptLeaders"));
			}
			if("0".equals(ggfyqtfy)){

				if ( hjxxjeitxmf >= 100000.0) {
					writeLog("====fgldlcsp赋值@requestId=" + requestId);
					rs.executeUpdate("update " + tableName + " set fgldlcsp= ?,sxcwglcsp='12016',dwfsj=null,dwsj=null,zclcsp=null  where REQUESTID=?", ngbmfgld, requestId);
				} else {
					writeLog("====fgldlcsp赋null @REQUESTID= " + requestId);
					rs.executeUpdate("update " + tableName + " set fgldlcsp=null,sxcwglcsp=null,dwfsj=null,dwsj=null,zclcsp=null  where REQUESTID=?", requestId);
				}
			}

			return SUCCESS;
		} catch (Exception e) {
			requestInfo.getRequestManager().setMessageid("500");
			requestInfo.getRequestManager().setMessagecontent("审批链赋值异常,请联系管理员");
			return FAILURE_AND_CONTINUE;
		}
	}

	public static void main(String[] args) {
		GCONST.setRootPath("WEB-INF/");
		GCONST.setServerName("ecology");
		PayCplFgld payCplFgld = new PayCplFgld();

		payCplFgld.execute(new RequestInfo());
	}
}
