English
Groovy Code Example
About 207 wordsLess than 1 minute
2026-01-09
/**
* @author admin01
* @codeName Print Template
* @description Parameter passing example
* @createTime 2024-07-08
*/
Map map = [:]
// instanceId 66867287a1267e7b18549747
// dataId 664dd64ff7239000076e0adf
// instanceId = "66867287a1267e7b18549747"
def (Boolean err, List instanceList, String errMsg) = Fx.approval.findTasks(instanceId)
List printList = []
instanceList.each { inst ->
List opinions = ((Map) inst).opinions as List
opinions.eachWithIndex { opin, i ->
Map newOpin = [:]
// Approval node name
newOpin.task_name = ((Map) inst).task_name
// Approver
String replyUser = ((List) ((Map) opin).reply_user)[0]
def (Boolean err1, Map userInfo, String errMsg1) = Fx.org.findUserById(replyUser)
if(!err1){
newOpin.reply_user = userInfo.full_name
} else {
log.info(errMsg1)
}
// Approval result
String type = ((Map) opin).action_type
if(type == 'agree'){
newOpin.action_type = 'Approved'
} else if(type == 'reject'){
newOpin.action_type = 'Rejected'
} else if(type == 'cancel'){
newOpin.action_type = 'Cancelled'
}
// Approval comment
newOpin.opinion = ((Map) opin).opinion
// Merge approval node names, initialize colspan and rowspan
Map spanTaskName = [task_name: [colspan: 1, rowspan: 1]]
newOpin.span = spanTaskName
printList.add(newOpin)
}
}
// Generate relational data above, then group and calculate row merging for task_name
Map groupedByTaskName = printList.groupBy { ((Map) it).task_name }.collectEntries { [(it.key): (it.value)] }
groupedByTaskName.each { entry ->
def taskList = entry.value as List<Map>
if (taskList.size() <= 1) return
taskList.eachWithIndex { task, i ->
Map span = ((Map) task).span as Map
Map taskNameSpan = span.task_name as Map
if (i == 0) {
taskNameSpan.rowspan = taskList.size()
} else {
taskNameSpan.rowspan = 0
}
}
}
map.put('instanceList', printList)
return map