@ -1,17 +1,32 @@
package com.engine.demo.cmd ;
import com.alibaba.excel.EasyExcel ;
import com.engine.common.biz.AbstractCommonCommand ;
import com.engine.common.entity.BizLogContext ;
import com.engine.core.interceptor.CommandContext ;
import org.apache.tika.utils.StringUtils ;
import com.engine.demo.entity.FillData ;
import com.engine.workflow.biz.RobotNode.RobotNodeBiz ;
import com.engine.workflow.biz.RobotNode.RobotNodeServiceBiz ;
import com.engine.workflow.biz.requestList.RequestListBiz ;
import org.apache.commons.lang3.StringUtils ;
import weaver.conn.RecordSet ;
import weaver.crm.Maint.CustomerInfoComInfo ;
import weaver.general.BaseBean ;
import weaver.general.GCONST ;
import weaver.general.Util ;
import weaver.hrm.User ;
import weaver.hrm.resource.ResourceComInfo ;
import java.io.File ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
public class WorklowBatchExportCmd extends AbstractCommonCommand < Map < String , Object > > {
BaseBean bb = new BaseBean ( ) ;
public WorklowBatchExportCmd ( Map < String , Object > params , User user ) {
this . user = user ;
this . params = params ;
@ -26,18 +41,200 @@ public class WorklowBatchExportCmd extends AbstractCommonCommand<Map<String, Obj
public Map < String , Object > execute ( CommandContext commandContext ) {
Map < String , Object > result = new HashMap < String , Object > ( ) ;
String requestids = Util . null2String ( params . get ( "requestids" ) ) ;
bb . writeLog ( "requestids: " + requestids ) ;
if ( StringUtils . is Blank( requestids ) ) {
if ( ! StringUtils . is Not Blank( requestids ) ) {
result . put ( "code" , "500" ) ;
result . put ( "msg" , "请先选择需要导出的流程" ) ;
return result ;
}
String [ ] requestidArr = requestids . split ( "," ) ;
/*导出的字段有 流程标题、所属路径、创建人、创建时间、当前节点、当前未操作人、当前状况、流程编号*/
//流程标题 workflow_requestbase.requestname
//所属路径 workflow_requestbase.workflowid
//创建人 workflow_requestbase.creater
//创建时间 workflow_requestbase.createdate
//当前节点 workflow_requestbase.currentnodeid
//当前未操作人 getUnoperators(requestid, user)
//当前状况 workflow_requestbase.status
//流程编号 workflow_requestbase.requestmark
List < FillData > fillDatas = new ArrayList < > ( ) ;
RecordSet rs = new RecordSet ( ) ;
for ( String requestid : requestidArr ) {
FillData fillData = new FillData ( ) ;
String acqDataSql = "select requestname, workflowid, creater, createdate, currentnodeid, status, requestmark from workflow_requestbase" +
" where requestid in (" + requestid + ") " ;
rs . executeQuery ( acqDataSql ) ;
while ( rs . next ( ) ) {
String requestname = Util . null2String ( rs . getString ( "requestname" ) ) ;
String workflowid = Util . null2String ( rs . getString ( "workflowid" ) ) ;
String creater = Util . null2String ( rs . getString ( "creater" ) ) ;
String createdate = Util . null2String ( rs . getString ( "createdate" ) ) ;
String currentnodeid = Util . null2String ( rs . getString ( "currentnodeid" ) ) ;
String status = Util . null2String ( rs . getString ( "status" ) ) ;
String requestmark = Util . null2String ( rs . getString ( "requestmark" ) ) ;
fillData . setRequestName ( requestname ) ;
fillData . setWorkflowId ( workflowid ) ;
fillData . setCreater ( creater ) ;
fillData . setCreateDate ( createdate ) ;
fillData . setCurrentNodeId ( currentnodeid ) ;
fillData . setStatus ( status ) ;
fillData . setRequestMark ( requestmark ) ;
}
String unoperators = getUnoperators ( requestid , user ) ;
fillData . setCurrentNoOperators ( unoperators ) ;
fillDatas . add ( fillData ) ;
}
String fillUrl = "" ;
if ( fillDatas ! = null & & fillDatas . size ( ) > 0 ) {
String templateFileName = Util . null2String ( bb . getPropValue ( "workflow_export" , "templateFileName" ) ) ;
String outFile = Util . null2String ( bb . getPropValue ( "workflow_export" , "outFile" ) ) ;
if ( StringUtils . isNotBlank ( templateFileName ) & & StringUtils . isNotBlank ( outFile ) ) {
fillUrl = this . simpleFill ( fillDatas , templateFileName , outFile ) ;
} else {
bb . writeLog ( "流程批量导出:请先配置模版名或文件导出路径" ) ;
result . put ( "code" , "500" ) ;
result . put ( "msg" , "请先配置模版名或文件导出路径" ) ;
return result ;
}
} else {
result . put ( "code" , "500" ) ;
result . put ( "msg" , "无需要导出流程" ) ;
return result ;
}
result . put ( "code" , "200" ) ;
result . put ( "data" , fillUrl ) ;
return result ;
}
private String getUnoperators ( String requestid , User user ) {
List < String > unOperators = new ArrayList < > ( ) ;
String language = user . getLanguage ( ) + "" ;
String userid = user . getUID ( ) + "" ;
RecordSet rs = new RecordSet ( ) ;
String returnStr = "" ;
RobotNodeServiceBiz robotNodeServiceBiz = new RobotNodeServiceBiz ( ) ;
ResourceComInfo rc = null ;
CustomerInfoComInfo cci = null ;
try {
rc = new ResourceComInfo ( ) ;
cci = new CustomerInfoComInfo ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
List < String > unoperatorTypes = Util . TokenizerString ( new RequestListBiz ( ) . getUnOperatorSet ( userid ) , "," ) ;
if ( Util . getIntValue ( requestid ) > - 1 ) { //oa系统流程
String isremarkStr = " (1 = 2 or " ;
//--------------------处理isremark条件----------------------
if ( unoperatorTypes . contains ( "1" ) ) { //节点操作者
isremarkStr + = " (isremark = 0 or (isremark = 4 and viewtype = 0) or (isremark = 1 and takisremark = '2')) or " ;
} else if ( unoperatorTypes . contains ( "2" ) ) { //转办操作者
isremarkStr + = " (isremark = 0 and (takisremark is null or takisremark=0) and handleforwardid > 0) or " ;
}
if ( unoperatorTypes . contains ( "4" ) & & unoperatorTypes . contains ( "5" ) ) {
isremarkStr + = " (isremark in(8,9,11)) or " ;
} else if ( unoperatorTypes . contains ( "4" ) ) { //抄送操作者
isremarkStr + = " (isremark in(8,9)) or " ;
} else if ( unoperatorTypes . contains ( "5" ) ) { //传阅操作者
isremarkStr + = " (isremark in(11)) or " ;
}
if ( unoperatorTypes . contains ( "3" ) ) { //转发操作者
isremarkStr + = " (isremark = 1 and (takisremark <>'2' or takisremark is null)) or " ;
}
if ( unoperatorTypes . contains ( "6" ) ) { //其他操作者--协办、超时干预到指定对象
isremarkStr + = " (isremark in(5,7)) or " ;
}
isremarkStr + = " 1=2)" ;
//--------------------处理isremark条件----------------------
//--------------------分页----------------------
rs . executeSql ( "select userid,usertype,agenttype,agentorbyagentid,isremark,showorder,id,groupid,nodeid from workflow_currentoperator where requestid = " + requestid + " and " + isremarkStr + " order by isremark,groupid,showorder asc ,id asc limit 20" ) ;
//--------------------分页----------------------
while ( rs . next ( ) ) {
//去除重复
String key = rs . getString ( "userid" ) + ":" + rs . getString ( "usertype" ) + ":" + rs . getString ( "agenttype" ) + ":" + rs . getString ( "agentorbyagentid" ) ;
if ( unOperators . contains ( key ) ) {
continue ;
} else {
unOperators . add ( key ) ;
}
if ( rs . getInt ( "usertype" ) = = 0 ) {
if ( rs . getInt ( "agenttype" ) = = 2 ) {
returnStr + = Util . formatMultiLang ( rc . getResourcename ( rs . getString ( "agentorbyagentid" ) ) , language ) + "->" + Util . formatMultiLang ( rc . getResourcename ( rs . getString ( "userid" ) ) , language ) + " " ;
//判断是否被代理者,如果是,则不显示该记录
} else if ( rs . getInt ( "agenttype" ) = = 1 & & rs . getInt ( "isremark" ) = = 4 ) {
continue ;
} else {
returnStr + = Util . formatMultiLang ( rc . getResourcename ( rs . getString ( "userid" ) ) , language ) + " " ;
}
} else if ( RobotNodeBiz . operatortype . equals ( rs . getString ( "usertype" ) ) ) {
returnStr + = Util . formatMultiLang ( robotNodeServiceBiz . getRobotNodeSet ( Util . getIntValue ( rs . getString ( "nodeid" ) ) ) . getOperatorName ( ) , language ) + " " ;
} else {
//TD11591(人力资源与客户同时存在时、加','处理)
returnStr + = Util . formatMultiLang ( cci . getCustomerInfoname ( rs . getString ( "userid" ) ) , language ) + " " ;
}
}
}
returnStr = returnStr . replaceAll ( "\"" , "" ) . replaceAll ( "'" , "" ) ;
if ( returnStr . length ( ) > 0 ) {
returnStr = ( returnStr . substring ( 0 , returnStr . length ( ) - 1 ) ) ;
}
return returnStr ;
}
/ * *
* 最 简 单 的 填 充
*
* @since 2.1 .1
* /
public String simpleFill ( List < FillData > fillDatas , String templateFileName , String outFile ) {
try {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
templateFileName = GCONST . getRootPath ( ) + templateFileName ;
// 方案1 根据对象填充
File file = new File ( outFile ) ;
//如果文件夹不存在则创建
if ( ! file . exists ( ) & & ! file . isDirectory ( ) ) {
bb . writeLog ( "//不存在" ) ;
file . mkdir ( ) ;
} else {
bb . writeLog ( "//目录存在" ) ;
}
String name = String . valueOf ( System . currentTimeMillis ( ) ) ;
String fileName = outFile + File . separator + name + ".xlsx" ;
EasyExcel . write ( fileName ) . withTemplate ( templateFileName ) . sheet ( ) . doFill ( fillDatas ) ;
String outUrl = outFile . split ( "ecology" ) [ 1 ] + File . separator + name + ".xlsx" ;
bb . writeLog ( "outUrl: " + outUrl ) ;
return outUrl ;
} catch ( Exception e ) {
bb . writeLog ( "simpleFill Exception: " + e ) ;
}
return null ;
}
}