package com.tenwa.orginfo; import java.util.HashMap; import java.util.List; import java.util.Map; import jbo.awe.ORG_INFO; import jbo.sys.LB_ORGUSER_LOG; import com.amarsoft.app.lc.util.DateAssistant; import com.amarsoft.app.util.ASOrgObject; import com.amarsoft.are.jbo.BizObject; import com.amarsoft.are.jbo.BizObjectManager; import com.amarsoft.are.jbo.JBOFactory; import com.amarsoft.are.jbo.JBOTransaction; import com.amarsoft.context.ASUser; import com.tenwa.comm.util.jboutil.DataOperatorUtil; import com.tenwa.officetempalte.util.FileOperatorUtil; /** * 机构管理日志表 * @author xu * */ public class OrgInfoLogService { public ASUser curUser; public JBOTransaction tx; public BizObject org; public OrgInfoLogService( ASUser curUser,JBOTransaction tx,BizObject org) { this.curUser=curUser; this.tx=tx; this.org=org; } public void logOrg(String Otype)throws Exception{ String comment=""; if(Otype.equals("Insert")){ comment=logOrgInsert(); }else if(Otype.equals("Update")){ comment=logOrgUpdate(); }else if(Otype.equals("Delete")){ comment=logOrgDelete(); } if(comment.length()>0){ BizObjectManager orgLogTable = JBOFactory.getBizObjectManager(LB_ORGUSER_LOG.CLASS_NAME); this.tx.join(orgLogTable); BizObject orgLog=orgLogTable.newObject(); orgLog.setAttributeValue("OCOMMENT",comment); orgLog.setAttributeValue("LOGTIME", DateAssistant.getTodayNow()); orgLog.setAttributeValue("OTYPE",Otype); orgLog.setAttributeValue("INPUTUSER",curUser.getUserID()); orgLog.setAttributeValue("INPUTORG", curUser.getOrgID()); orgLog.setAttributeValue("INPUTTIME", org.getAttribute("INPUTTIME").getString()); orgLogTable.saveObject(orgLog); } } public String logOrgDelete()throws Exception{ MapsearchCondtion=new HashMap(); searchCondtion.put("ORGID", this.org.getAttribute("ORGID").getString()); this.org=DataOperatorUtil.getSingleJBO(ORG_INFO.CLASS_NAME, searchCondtion, this.tx); String sComment=this.curUser.getUserName()+"删除"+this.getParentOrgName()+"下面的"+this.getLevel(this.org)+"["+this.org.getAttribute("ORGNAME").getString()+"]("+DateAssistant.getTodayNow()+")"; return sComment; } public String logOrgUpdate()throws Exception{ ASOrgObject orgObject= new ASOrgObject(this.org.getAttribute("ORGID").getString()); String sourceName=orgObject.getOrgName(); String newName=this.org.getAttribute("ORGNAME").getString(); String sComment=""; if(!sourceName.equals(newName)){ sComment=this.curUser.getUserName()+"更新"+this.getParentOrgName()+"下面的"+getLevel(org)+"["+sourceName+"]修改为["+newName+"]("+DateAssistant.getTodayNow()+")"; } return sComment; } public String logOrgInsert()throws Exception{ String sComment=this.curUser.getUserName()+"在"+this.getParentOrgName()+"新增"+this.getLevel(this.org)+"["+this.org.getAttribute("ORGNAME").getString()+"]("+DateAssistant.getTodayNow()+")"; return sComment; } public String getLevel(BizObject org)throws Exception{ String sLevel=""; sLevel=org.getAttribute("ORGLEVEL").getString(); String slevelName=""; if(sLevel.equals("0")){ slevelName="平台"; }else if(sLevel.equals("3")){ slevelName="公司"; }else if(sLevel.equals("6")){ slevelName="部门"; }else if(sLevel.equals("9")){ slevelName="渠道"; }else if(sLevel.equals("12")){ slevelName="机构"; } return slevelName; } public String getParentOrgName()throws Exception{ String orgId=org.getAttribute("orgid").getString(); orgId=orgId.substring(0, orgId.length()-3); String parentList=""; if(orgId.length()<2){ parentList=orgId; }else{ orgId=orgId.substring(0, orgId.length()-3); if(orgId.length()>1){ while(orgId.length()>1){ if(parentList.length()>0){parentList=parentList+",";} parentList=parentList+orgId; orgId=orgId.substring(0, orgId.length()-3); } }else{ parentList=orgId; } } String parentOrgName=""; String sql="select orgname from o where o.orgid in("+FileOperatorUtil.getStrArray(parentList, ",")+") order by sortno"; Listorgs=JBOFactory.createBizObjectQuery(ORG_INFO.CLASS_NAME, sql).getResultList(false); for(BizObject bo:orgs){ if(parentOrgName.length()>0){ parentOrgName=parentOrgName+"-->"; } parentOrgName=parentOrgName+bo.getAttribute("orgname").getString(); } return parentOrgName; } }