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 jbo.sys.USER_INFO; import com.amarsoft.app.lc.util.DateAssistant; 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 UserInfoLogService { public ASUser curUser; public JBOTransaction tx; public BizObject user; public UserInfoLogService( ASUser curUser,JBOTransaction tx,BizObject user) { this.curUser=curUser; this.tx=tx; this.user=user; } public void logUser(String Otype)throws Exception{ String comment=""; if(Otype.equals("Insert")){ comment=logUserInsert(); }else if(Otype.equals("Update")){ comment=logUserUpdate(); }else if(Otype.equals("Delete")){ comment=logUserDelete(); } 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", DateAssistant.getTodayNow()); orgLogTable.saveObject(orgLog); } } public String logUserDelete()throws Exception{ MapsearchCondtion=new HashMap(); searchCondtion.put("USERID", this.user.getAttribute("USERID").getString()); this.user=DataOperatorUtil.getSingleJBO(USER_INFO.CLASS_NAME, searchCondtion, this.tx); String sComment=this.curUser.getUserName()+"删除"+this.getParentOrgName()+"下面的用户["+this.user.getAttribute("USERNAME").getString()+"]("+DateAssistant.getTodayNow()+")"; return sComment; } public String logUserUpdate()throws Exception{ MapsearchCondtion=new HashMap(); searchCondtion.put("USERID", this.user.getAttribute("USERID").getString()); BizObject oldUserr=DataOperatorUtil.getSingleJBO(USER_INFO.CLASS_NAME, searchCondtion, this.tx); String sourceName=oldUserr.getAttribute("USERNAME").getString(); String sourceLoginId=oldUserr.getAttribute("LOGINID").getString(); String newName=this.user.getAttribute("USERNAME").getString(); String newLoginId=this.user.getAttribute("LOGINID").getString(); String sComment=""; if(!sourceName.equals(newName)){ sComment="用户名["+sourceName+"]修改为["+newName+"]"; } if(!sourceLoginId.equals(newLoginId)){ if(sComment.length()>0){sComment=sComment+",";} sComment=sComment+"登录名["+sourceLoginId+"]修改为["+newLoginId+"]"; } String strReturn=""; if(sComment.length()>0){ strReturn=this.curUser.getUserName()+"更新"+this.getParentOrgName()+"下面的用户("+sComment+")("+DateAssistant.getTodayNow()+")"; } return strReturn; } public String logUserInsert()throws Exception{ String sComment=this.curUser.getUserName()+"在"+this.getParentOrgName()+"新增用户["+this.user.getAttribute("USERNAME").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=this.user.getAttribute("BELONGORG").getString(); 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; } }