Borrow.java
上传用户:hbzhoufeng
上传日期:2009-12-23
资源大小:75k
文件大小:17k
- package com.jat.test;
- import java.net.*;
- import java.sql.*;
- import java.text.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import javax.mail.*;
- import javax.mail.internet.*;
- import org.ofbiz.core.entity.*;
- import org.ofbiz.core.service.*;
- import org.ofbiz.core.service.job.*;
- import org.ofbiz.core.stats.*;
- import org.ofbiz.core.util.*;
- import org.ofbiz.core.workflow.*;
- import org.ofbiz.core.security.*;
- import org.ofbiz.commonapp.order.order.*;
- import org.ofbiz.commonapp.party.contact.*;
- import org.ofbiz.commonapp.product.catalog.*;
- import org.ofbiz.commonapp.marketing.tracking.*;
- import org.ofbiz.core.workflow.definition.*;
- import org.ofbiz.core.workflow.client.*;
- public class Borrow
- {
- public static final String module = Borrow.class.getName();
-
- public static String dman(HttpServletRequest request, HttpServletResponse response)
- {
- try
- {
- GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
-
- String workEffortId=request.getParameter("workEffortId");
- String borrowId=request.getParameter("borrowId");
- String dman=request.getParameter("dman");
- if(dman==null)
- {
- dman="";
- }
- String roleTypeId=request.getParameter("roleTypeId");
- String fromDateS=request.getParameter("fromDate");
- int year=Integer.parseInt(fromDateS.substring(0,4))-1900;
- int month=Integer.parseInt(fromDateS.substring(5,7))-1;
- int day=Integer.parseInt(fromDateS.substring(8,10));
- int hour=Integer.parseInt(fromDateS.substring(11,13));
- int minute=Integer.parseInt(fromDateS.substring(14,16));
- int second=Integer.parseInt(fromDateS.substring(17,19));
- Timestamp fromDate=new Timestamp(year,month,day,hour,minute,second,0);
-
- //保存意见
- GenericValue borrow=delegator.findByPrimaryKey("Borrow",UtilMisc.toMap("borrowId",borrowId));
- borrow.set("dman",dman);
- borrow.store();
-
- //完成activity
- Security security = dispatcher.getSecurity();
- GenericValue userLogin=(GenericValue)request.getSession().getAttribute(SiteDefs.USER_LOGIN);
- String partyId = (String)userLogin.getString("partyId");
-
- if (!hasPermission(security, workEffortId, userLogin))
- {
- Debug.log("没有权限完成当前任务!");
- return "error";
- }
-
- try
- {
- Map actResults = new HashMap();
- WorkflowClient client=new WorkflowClient(delegator,dispatcher);
- client.complete(workEffortId,partyId,roleTypeId,fromDate,actResults);
- }
- catch(WfException we)
- {
- Debug.log(we);
- return "error";
- }
-
- return "success";
- }
- catch(Exception e)
- {
- Debug.log(e);
- return "error";
- }
- }
-
- public static String gman(HttpServletRequest request, HttpServletResponse response)
- {
- try
- {
- GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
-
- String workEffortId=request.getParameter("workEffortId");
- String borrowId=request.getParameter("borrowId");
- String gman=request.getParameter("gman");
- if(gman==null)
- {
- gman="";
- }
- String roleTypeId=request.getParameter("roleTypeId");
- String fromDateS=request.getParameter("fromDate");
- int year=Integer.parseInt(fromDateS.substring(0,4))-1900;
- int month=Integer.parseInt(fromDateS.substring(5,7))-1;
- int day=Integer.parseInt(fromDateS.substring(8,10));
- int hour=Integer.parseInt(fromDateS.substring(11,13));
- int minute=Integer.parseInt(fromDateS.substring(14,16));
- int second=Integer.parseInt(fromDateS.substring(17,19));
- Timestamp fromDate=new Timestamp(year,month,day,hour,minute,second,0);
-
- //保存意见
- GenericValue borrow=delegator.findByPrimaryKey("Borrow",UtilMisc.toMap("borrowId",borrowId));
- borrow.set("gman",gman);
- borrow.store();
-
- //完成activity
- Security security = dispatcher.getSecurity();
- GenericValue userLogin=(GenericValue)request.getSession().getAttribute(SiteDefs.USER_LOGIN);
- String partyId = (String)userLogin.getString("partyId");
- if (!hasPermission(security, workEffortId, userLogin))
- {
- Debug.log("没有权限完成当前任务!");
- return "error";
- }
- try
- {
- Map actResults = new HashMap();
- WorkflowClient client=new WorkflowClient(delegator,dispatcher);
- client.complete(workEffortId,partyId,roleTypeId,fromDate,actResults);
- }
- catch(WfException we)
- {
- Debug.log(we);
- return "error";
- }
-
- return "success";
- }
- catch(Exception e)
- {
- Debug.log(e);
- return "error";
- }
- }
-
- public static String financial(HttpServletRequest request, HttpServletResponse response)
- {
- try
- {
- GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
-
- String workEffortId=request.getParameter("workEffortId");
- String borrowId=request.getParameter("borrowId");
- String financial=request.getParameter("financial");
- if(financial==null)
- {
- financial="";
- }
- String roleTypeId=request.getParameter("roleTypeId");
- String fromDateS=request.getParameter("fromDate");
- int year=Integer.parseInt(fromDateS.substring(0,4))-1900;
- int month=Integer.parseInt(fromDateS.substring(5,7))-1;
- int day=Integer.parseInt(fromDateS.substring(8,10));
- int hour=Integer.parseInt(fromDateS.substring(11,13));
- int minute=Integer.parseInt(fromDateS.substring(14,16));
- int second=Integer.parseInt(fromDateS.substring(17,19));
- Timestamp fromDate=new Timestamp(year,month,day,hour,minute,second,0);
-
- //保存意见
- GenericValue borrow=delegator.findByPrimaryKey("Borrow",UtilMisc.toMap("borrowId",borrowId));
- borrow.set("financial",financial);
- borrow.store();
-
- //完成activity
- Security security = dispatcher.getSecurity();
- GenericValue userLogin=(GenericValue)request.getSession().getAttribute(SiteDefs.USER_LOGIN);
- String partyId = (String)userLogin.getString("partyId");
-
- if (!hasPermission(security, workEffortId, userLogin))
- {
- Debug.log("没有权限完成当前任务!");
- return "error";
- }
-
- try
- {
- Map actResults = new HashMap();
- WorkflowClient client=new WorkflowClient(delegator,dispatcher);
- client.complete(workEffortId,partyId,roleTypeId,fromDate,actResults);
- }
- catch(WfException we)
- {
- Debug.log(we);
- return "error";
- }
-
- return "success";
- }
- catch(Exception e)
- {
- Debug.log(e);
- return "error";
- }
- }
-
- public static String newborrow(HttpServletRequest request, HttpServletResponse response)
- {
- try
- {
- GenericDelegator delegator = (GenericDelegator)request.getAttribute("delegator");
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
- GenericValue userLogin=(GenericValue)request.getSession().getAttribute(SiteDefs.USER_LOGIN);
-
- //新建记录
- String borrowId=delegator.getNextSeqId("Borrow").toString();
- Double reqsum=new Double(request.getParameter("reqsum"));
- String bmemo=request.getParameter("bmemo");
- Timestamp bdate = UtilDateTime.nowTimestamp();
- Double actsum=new Double(0);
- String userLoginId=userLogin.getString("userLoginId");
-
- Map map=new HashMap();
- map.put("borrowId",borrowId);
- map.put("reqsum",reqsum);
- map.put("bmemo",bmemo);
- map.put("bdate",bdate);
- map.put("dman","");
- map.put("gman","");
- map.put("financial","");
- map.put("actsum",actsum);
- map.put("workEffortId","");
- map.put("userLoginId",userLoginId);
- GenericValue borrow = delegator.create("Borrow",map);
- borrow.store();
-
-
- //启动process
- dispatcher.runAsync("processBorrow", UtilMisc.toMap("borrowId",borrowId,"sum",reqsum));
- }
- catch(Exception e)
- {
- Debug.log(e);
- return "error";
- }
-
- return "success";
- }
-
- public static String worklist(HttpServletRequest request, HttpServletResponse response)
- {
- GenericDelegator delegator=(GenericDelegator)request.getAttribute("delegator");
- GenericValue userLogin=(GenericValue)request.getSession().getAttribute(SiteDefs.USER_LOGIN);
-
- //取得partyAssignment
- List partyWorkEfforts = null;
-
- if (userLogin != null && userLogin.get("partyId") != null)
- {
- try
- {
- List constraints = new LinkedList();
-
- constraints.add(new EntityExpr("partyId", EntityOperator.EQUALS, userLogin.get("partyId")));
- constraints.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "ACTIVITY"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
- constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_COMPLETED"));
- constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_TERMINATED"));
- constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_ABORTED"));
- partyWorkEfforts = delegator.findByAnd("WorkEffortAndPartyAssign", constraints, UtilMisc.toList("priority","workEffortId"));
- }
- catch (GenericEntityException e)
- {
- Debug.logWarning(e);
- return "error";
- }
- }
-
- if (partyWorkEfforts == null) partyWorkEfforts = new LinkedList();
- request.setAttribute("partyAssignment",partyWorkEfforts);
-
-
- //取得roleAssignment
- List roleWorkEfforts = null;
-
- if (userLogin != null && userLogin.get("partyId") != null)
- {
- try {
- List constraints = new LinkedList();
-
- constraints.add(new EntityExpr("partyId", EntityOperator.EQUALS, userLogin.get("partyId")));
- constraints.add(new EntityExpr("roleTypeId", EntityOperator.NOT_EQUAL, "_NA_"));
- constraints.add(new EntityExpr("workEffortTypeId", EntityOperator.EQUALS, "ACTIVITY"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_ACCEPTED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
- constraints.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
- constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_COMPLETED"));
- constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_TERMINATED"));
- constraints.add(new EntityExpr("currentStatusId", EntityOperator.NOT_EQUAL, "WF_ABORTED"));
- roleWorkEfforts = delegator.findByAnd("WorkEffortPartyAssignByRole", constraints, UtilMisc.toList("priority"));
- }
- catch (GenericEntityException e)
- {
- Debug.logWarning(e);
- return "error";
- }
- }
-
- if (roleWorkEfforts == null) roleWorkEfforts = new LinkedList();
- request.setAttribute("roleAssignment",roleWorkEfforts);
-
-
- return "success";
- }
-
- public static String accept(HttpServletRequest request, HttpServletResponse response)
- {
- GenericDelegator delegator=(GenericDelegator)request.getAttribute("delegator");
- LocalDispatcher dispatcher=(LocalDispatcher)request.getAttribute("dispatcher");
-
- String workEffortId = request.getParameter("workEffortId");
- String partyId = request.getParameter("partyId");
- String roleTypeId=request.getParameter("roleTypeId");
- String fromDateS=request.getParameter("fromDate");
- int year=Integer.parseInt(fromDateS.substring(0,4))-1900;
- int month=Integer.parseInt(fromDateS.substring(5,7))-1;
- int day=Integer.parseInt(fromDateS.substring(8,10));
- int hour=Integer.parseInt(fromDateS.substring(11,13));
- int minute=Integer.parseInt(fromDateS.substring(14,16));
- int second=Integer.parseInt(fromDateS.substring(17,19));
- Timestamp fromDate=new Timestamp(year,month,day,hour,minute,second,0);
-
- try
- {
- WorkflowClient client=new WorkflowClient(delegator,dispatcher);
- client.delegateAndAccept(workEffortId,"_NA_",roleTypeId,fromDate,partyId,roleTypeId,fromDate,true);
- }
- catch (WfException we)
- {
- Debug.log(we);
- request.setAttribute("borrow.error","该任务已经被其他人接受,不能再接受!");
- return "error";
- }
-
- return "success";
- }
-
- public static String dispatch(HttpServletRequest request, HttpServletResponse response)
- {
- GenericDelegator delegator=(GenericDelegator)request.getAttribute("delegator");
- LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
-
- String workEffortId=request.getParameter("workEffortId");
-
- try
- {
- GenericValue workEffortDetail=delegator.findByPrimaryKey("WorkEffort",UtilMisc.toMap("workEffortId",workEffortId));
-
- String packageId=workEffortDetail.getString("workflowPackageId");
- String processId=workEffortDetail.getString("workflowProcessId");
- String activityId=workEffortDetail.getString("workflowActivityId");
-
- //取得活动对应的borrowId
- WorkflowClient wfc=new WorkflowClient(delegator,dispatcher);
- Map ctx=wfc.getContext(workEffortId);
- String borrowId=(String)ctx.get("borrowId");
-
- //取得borrowId对应的借款单数据
- GenericValue borrow=delegator.findByPrimaryKey("Borrow",UtilMisc.toMap("borrowId",borrowId));
-
- //判断是哪个活动,并根据活动转发。
- //此处为硬编码,将来在项目中应根据配置文件进行动态转发。
- if(packageId.equals("com.jat.test"))
- {
- if(processId.equals("Borrow"))
- {
- if(activityId.equals("deptManAudit"))//部门负责人审核
- {
- request.setAttribute("borrow",borrow);
- return "dman";
- }
- else if(activityId.equals("generalManAudit"))//总经理审核
- {
- request.setAttribute("borrow",borrow);
- return "gman";
- }
- else if(activityId.equals("finDeptAudit"))//财务审核
- {
- request.setAttribute("borrow",borrow);
- return "financial";
- }
- else
- {
- Debug.log("未知的任务!");
- return "error";
- }
- }
- else
- {
- Debug.log("未知的过程!");
- return "error";
- }
- }
- else
- {
- Debug.log("未知的包名!");
- return "error";
- }
- }
- catch(Exception e)
- {
- Debug.log(e);
- return "error";
- }
- }
-
- public static Map dealWithPay(DispatchContext ctx, Map context)
- {
- GenericDelegator delegator = ctx.getDelegator();
- Map result = new HashMap();
- String borrowId=(String)context.get("borrowId");
-
- try
- {
- GenericValue borrow=delegator.findByPrimaryKey("Borrow",UtilMisc.toMap("borrowId",borrowId));
- borrow.set("actsum",borrow.getDouble("reqsum"));
- borrow.store();
- result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
- }
- catch(Exception we)
- {
- Debug.log(we);
- result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
- }
-
- return result;
- }
-
- public static boolean hasPermission(Security sec, String workEffortId, GenericValue userLogin)
- {
- if(userLogin == null || workEffortId == null)
- {
- Debug.logWarning("No UserLogin object or no Workeffort ID was passed.");
- return false;
- }
- if(sec.hasPermission("WORKFLOW_MAINT", userLogin))
- {
- return true;
- }
- else
- {
- String partyId = userLogin.getString("partyId");
-
- List expr = new ArrayList();
- expr.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
- expr.add(new EntityExpr("workEffortId", EntityOperator.EQUALS, workEffortId));
- expr.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()));
- Collection c = null;
- try
- {
- c = userLogin.getDelegator().findByAnd("WorkEffortAndPartyAssign", expr);
- }
- catch(GenericEntityException e)
- {
- Debug.logWarning(e);
- return false;
- }
- if (c.size() == 0)
- {
- expr = new ArrayList();
- expr.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DECLINED"));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_DELEGATED"));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_COMPLETED"));
- expr.add(new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "CAL_CANCELLED"));
- expr.add(new EntityExpr("workEffortParentId", EntityOperator.EQUALS, workEffortId));
- expr.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, UtilDateTime.nowTimestamp()));
- try
- {
- c = userLogin.getDelegator().findByAnd("WorkEffortAndPartyAssign", expr);
- if (Debug.infoOn()) Debug.logInfo("Found " + c.size() + " records.");
- }
- catch(GenericEntityException e)
- {
- Debug.logWarning(e);
- return false;
- }
- }
-
- if(c.size() > 0)
- {
- return true;
- }
- }
- return false;
- }
-
- public static String borrowlist(HttpServletRequest request, HttpServletResponse response)
- {
- GenericDelegator delegator=(GenericDelegator)request.getAttribute("delegator");
-
- List borrows=null;
- try
- {
- borrows=delegator.findAll("Borrow",UtilMisc.toList("borrowId"));
- }
- catch (GenericEntityException e)
- {
- Debug.logWarning(e);
- return "error";
- }
-
- if (borrows == null) borrows = new LinkedList();
- request.setAttribute("borrowList",borrows);
-
- return "success";
- }
- }