package SQF.job.voucher;
import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import com.SQF.manage.front.frontPub;
import com.SQF.pub.pub_function;
import com.SQF.tool.workJob;
import swotech.lease.core.voucher.voucher_interface;
public class voucher_settleaccounts extends workJob {
public voucher_settleaccounts(Hashtable htinfo) {
this.htparam = htinfo;
}
public void start(HttpServletRequest request) throws Exception {
Hashtable<String, String> inputht = (Hashtable) htparam.get("inputvalues");
String acdtid = inputht.get("acdtid"); // 凭证批号
acdtid = request.getParameter("acdtid");
if (pub_function.IsEmptyStr(acdtid)) {
errmsg = "凭证批号不能为空!";
return;
}
String usercode = inputht.get("usercode"); // 操作人
if (pub_function.IsEmptyStr(usercode)) {
usercode = (String) request.getSession().getAttribute("usercode");
}
String sql = "select * from znfi_acdt where acdtid=" + pub_function.checkStr(acdtid);
Hashtable ht = frontPub.getRow(sql, 1);
if (ht == null)
return;
String acdt = (String) ht.get("acdt"); // 会计日期
String genfeq = (String) ht.get("genfeq"); // 结算类型
String billdate = (String) ht.get("billdate"); // 制单日期
sql = "select a.usercode,a.username from sysusertb a left join sysinsttb b on a.instcode=b.instcode left join sysroletb c on a.rolecode = c.rolecode where a.usercode="
+ pub_function.checkStr(usercode) + " and a.userstat='1' ";
Hashtable userHts[] = frontPub.getRowHtbs(sql);
String username = "";
if (userHts == null) {
username = (String) userHts[0].get("username");
}
String sqlbse = "select voucherclass,vouchername,genfeq,vouchertyp,voucherpro,querysql," +
"acctype,databasename,absmodel" +
" from znpub_voucher where useflg='1' and genfeq='"
+ genfeq + "' order by voucherClass asc";
Hashtable bseHts[] = frontPub.getRowHtbs(sqlbse);
String bgtime = pub_function.getCurrentTime();
CountDownLatch latch=new CountDownLatch(bseHts.length);
// System.out.println("====================len"+bseHts.length);
int bb=0;
int lincout=5;//线程数量
System.out.println("Total Number of threads =====1==" +ManagementFactory.getThreadMXBean().getThreadCount());
CountDownLatch latchson=new CountDownLatch(lincout);
for (int i = 0; bseHts != null && i < bseHts.length; i++) {
Hashtable hst=bseHts[i];
if(bb==lincout){
bb=0;
//latchson.countDown();
}
new MyThread2(hst,acdt,acdtid,usercode,username,billdate,latch,latchson).start();
bb=bb+1;
if(bb==lincout){
latchson.await();//latchson.countDown();
}
// System.out.println("子线程执行");
// System.out.println("====================bb===="+bb);
// System.out.println("====================latch===="+latch);
// System.out.println("====================latchson===="+latchson);
//System.out.println("Total Number of threads =====2==" +ManagementFactory.getThreadMXBean().getThreadCount());
}
//System.out.println("Total Number of threads =====3==" +ManagementFactory.getThreadMXBean().getThreadCount());
latch.await(15, TimeUnit.SECONDS);//线程等待等计数为0的时候执行
//
//System.out.println("主线程执行");
// 处理0生成的凭证
sql = "delete from znfi_fitem where DAMOUNT=0 and CAMOUNT=0";
errmsg = frontPub.excuteSql(sql);
// 更新成功数
String totalnum = getSucNum(acdtid) + "";
// String sucnum = getSucNum(acdtid)+"";
sql = "update znfi_acdt set totalnum=" + totalnum + ",sucnum=" + totalnum + " where acdtid="
+ pub_function.checkStr(acdtid);
errmsg = frontPub.excuteSql(sql);
}
public int getSucNum(String acdtid) throws Exception {
String sql="select count(*) from znfi_fitem where acdtid="+pub_function.checkStr(acdtid);
return frontPub.runCountSql(sql);
}
public void runClass(String calpro, Hashtable hts) throws Exception {
try {
Class obj = Class.forName(calpro);
voucher_interface vi = (voucher_interface) obj.newInstance();
vi.voucher(hts);
} catch (Exception e) {
pub_function.printToLog(e.getMessage());
e.printStackTrace();
}
}
static class MyThread2 extends Thread {
private Hashtable bseHts;
private String acdt;
private String acdtid;
private String usercode;
private String username;
private String billdate;
private CountDownLatch latch;
private CountDownLatch latchson;
public MyThread2(Hashtable bseHts, String acdt,String acdtid,String usercode,String username,String billdate, CountDownLatch latch, CountDownLatch latchson) {
//this.bseHts = bseHts;
this.bseHts=bseHts;
this.acdt=acdt;
this.acdtid=acdtid;
this.usercode=usercode;
this.username=username;
this.billdate=billdate;
this.latch=latch;
this.latchson=latchson;
}
public void runClass(String calpro, Hashtable hts) throws Exception {
try {
Class obj = Class.forName(calpro);
voucher_interface vi = (voucher_interface) obj.newInstance();
vi.voucher(hts);
} catch (Exception e) {
pub_function.printToLog(e.getMessage());
e.printStackTrace();
}
}
public void run() {
String voucherpro = "swotech.lease.core.voucher.baseVoucher";
if (bseHts.get("voucherpro") != null) {
if (!pub_function.IsEmptyStr((String) bseHts.get("voucherpro"))) {
voucherpro = (String) bseHts.get("voucherpro");
}
}
bseHts.put("acdt", acdt);
bseHts.put("rundt", acdt);
bseHts.put("acdtid", acdtid);
bseHts.put("usercode", usercode);
bseHts.put("username", username);
bseHts.put("billdate", billdate);
// 调用接口 执行接口程序 ..生成凭证
try {
runClass(voucherpro,bseHts);
latch.countDown();
latchson.countDown();
} catch (Exception e) {
e.printStackTrace();
}finally {
}
}
}
}
多线程传参
于 2022-06-15 11:54:30 首次发布