apzl_leasing/src_tenwa/com/tenwa/orginfo/UserInfoLogService.java
2018-06-03 22:26:41 +08:00

137 lines
5.0 KiB
Java

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{
Map<String,String>searchCondtion=new HashMap<String,String>();
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{
Map<String,String>searchCondtion=new HashMap<String,String>();
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";
List<BizObject>orgs=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;
}
}