Skip to content

Commit 64d53a8

Browse files
add getPageNum
1 parent 24362f2 commit 64d53a8

File tree

5 files changed

+220
-1
lines changed

5 files changed

+220
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
/example/server
1616
/doc/~$*
1717
tmp/
18+
.idea/

bll/b_flow.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,21 @@ func (a *Flow) QueryTodoFlowInstanceResult(userID, typeCode, flowCode string, la
376376
return a.FlowModel.QueryTodoFlowInstanceResult(userID, typeCode, flowCode, lastID, count)
377377
}
378378

379+
// QueryWebTodoFlowInstanceResult web查询待办的流程实例数据
380+
func (a *Flow) QueryWebTodoFlowInstanceResult(userID, typeCode, flowCode string, count int,ParamSearchList map[string]string) ([]*schema.FlowWebInstanceResult, error) {
381+
return a.FlowModel.QueryTodoWebFlowInstanceResult(userID, typeCode, flowCode, count,ParamSearchList)
382+
}
383+
379384
// QueryHandleFlowInstanceResult 查询处理的流程实例结果
380385
func (a *Flow) QueryHandleFlowInstanceResult(processor, typeCode, flowCode string, lastID int64, count int) ([]*schema.FlowInstanceResult, error) {
381386
return a.FlowModel.QueryHandleFlowInstanceResult(processor, typeCode, flowCode, lastID, count)
382387
}
383388

389+
// QueryWebHandleFlowInstanceResult web查询处理的流程实例结果
390+
func (a *Flow) QueryWebHandleFlowInstanceResult(processor, typeCode, flowCode string, lastID int64, count int , ParamSearchList map[string]string ) ([]*schema.FlowInstanceResult, error) {
391+
return a.FlowModel.QueryWebHandleFlowInstanceResult(processor, typeCode, flowCode, lastID, count,ParamSearchList)
392+
}
393+
384394
// QueryLastNodeInstances 查询流程实例的最后一个节点实例
385395
func (a *Flow) QueryLastNodeInstances(flowInstanceIDs []string) (map[string]*schema.NodeInstance, error) {
386396
items, err := a.FlowModel.QueryLastNodeInstances(flowInstanceIDs)
@@ -395,6 +405,21 @@ func (a *Flow) QueryLastNodeInstances(flowInstanceIDs []string) (map[string]*sch
395405
return data, nil
396406
}
397407

408+
// QueryWebLastNodeInstances web查询流程实例的最后一个节点实例
409+
func (a *Flow) QueryWebLastNodeInstances(flowInstanceIDs []string,ParamSearchList map[string]string) (map[string]*schema.NodeInstance, error) {
410+
411+
items, err := a.FlowModel.QueryWebLastNodeInstances(flowInstanceIDs,ParamSearchList)
412+
if err != nil {
413+
return nil, err
414+
}
415+
416+
data := make(map[string]*schema.NodeInstance)
417+
for _, item := range items {
418+
data[item.FlowInstanceID] = item
419+
}
420+
return data, nil
421+
}
422+
398423
// QueryLastNodeInstance 查询节点实例
399424
func (a *Flow) QueryLastNodeInstance(flowInstanceID string) (*schema.NodeInstance, error) {
400425
return a.FlowModel.QueryLastNodeInstance(flowInstanceID)

model/m_flow.go

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package model
33
import (
44
"database/sql"
55
"fmt"
6+
"strconv"
67
"strings"
78
"time"
89

@@ -797,6 +798,8 @@ func (a *Flow) QueryLaunchFlowInstanceResult(launcher, typeCode, flowCode string
797798
return items, nil
798799
}
799800

801+
802+
800803
// QueryTodoFlowInstanceResult 查询待办的流程实例数据
801804
func (a *Flow) QueryTodoFlowInstanceResult(userID, typeCode, flowCode string, lastID int64, count int) ([]*schema.FlowInstanceResult, error) {
802805
var args []interface{}
@@ -831,6 +834,7 @@ func (a *Flow) QueryTodoFlowInstanceResult(userID, typeCode, flowCode string, la
831834
return items, nil
832835
}
833836

837+
834838
// QueryHandleFlowInstanceResult 查询处理的流程实例结果
835839
func (a *Flow) QueryHandleFlowInstanceResult(processor, typeCode, flowCode string, lastID int64, count int) ([]*schema.FlowInstanceResult, error) {
836840
var args []interface{}
@@ -865,6 +869,7 @@ func (a *Flow) QueryHandleFlowInstanceResult(processor, typeCode, flowCode strin
865869
return items, nil
866870
}
867871

872+
868873
// QueryLastNodeInstances 查询流程实例的最后一个节点实例
869874
func (a *Flow) QueryLastNodeInstances(flowInstanceIDs []string) ([]*schema.NodeInstance, error) {
870875
errMsg := "查询流程实例的最后一个节点实例发生错误"
@@ -1078,4 +1083,186 @@ func (a *Flow) QueryFlowVersion(code string) ([]*schema.FlowQueryResult, error)
10781083
return items, nil
10791084
}
10801085

1086+
1087+
// QueryTodoWebFlowInstanceResult web查询待办的流程实例数据
1088+
func (a *Flow) QueryTodoWebFlowInstanceResult(userID, typeCode, flowCode string, count int,ParamSearchList map[string]string) ([]*schema.FlowWebInstanceResult, error) {
1089+
var args []interface{}
1090+
query := fmt.Sprintf("SELECT fi.id,fi.record_id,fi.flow_id,fi.status,fi.launcher,fi.launch_time,f.code 'flow_code',f.name 'flow_name' FROM %s fi LEFT JOIN %s f ON fi.flow_id=f.record_id AND f.deleted=0 WHERE fi.deleted=0 AND fi.status = 1", schema.FlowInstanceTableName, schema.FlowTableName)
1091+
//最后的更改
1092+
if ParamSearchList != nil && len(ParamSearchList) > 0 {
1093+
tmpSql := ``
1094+
for i, v := range ParamSearchList {
1095+
if i == "page"{
1096+
continue
1097+
}
1098+
tmpSql +=` AND input_data->'$.`+i+`' = '`+v+`'`
1099+
}
1100+
query = fmt.Sprintf("%s AND fi.record_id IN(SELECT flow_instance_id FROM %s WHERE deleted=0 AND status=1 %s AND record_id IN(SELECT node_instance_id FROM %s WHERE deleted=0 AND candidate_id=?))", query, schema.NodeInstanceTableName, tmpSql,schema.NodeCandidateTableName)
1101+
}else{
1102+
query = fmt.Sprintf("%s AND fi.record_id IN(SELECT flow_instance_id FROM %s WHERE deleted=0 AND status=1 AND record_id IN(SELECT node_instance_id FROM %s WHERE deleted=0 AND candidate_id=?))", query, schema.NodeInstanceTableName, schema.NodeCandidateTableName)
1103+
}
1104+
args = append(args, userID)
1105+
1106+
if typeCode != "" {
1107+
query = fmt.Sprintf("%s AND f.type_code IN(?)", query)
1108+
args = append(args, strings.Split(typeCode, ","))
1109+
} else if flowCode != "" {
1110+
query = fmt.Sprintf("%s AND f.code=?", query)
1111+
args = append(args, flowCode)
1112+
}
1113+
1114+
1115+
if v,ok := ParamSearchList["page"];ok {
1116+
if v != "" {
1117+
page ,_ := strconv.Atoi(v)
1118+
query = fmt.Sprintf("%s ORDER BY fi.id DESC LIMIT %d offset %d", query, count,(page - 1 )*count)
1119+
}
1120+
}
1121+
1122+
query, args, _ = a.DB.In(query, args...)
1123+
var items []*schema.FlowWebInstanceResult
1124+
_, err := a.DB.Select(&items, query, args...)
1125+
if err != nil {
1126+
return nil, errors.Wrapf(err, "查询发起的流程实例数据发生错误")
1127+
}
1128+
1129+
return items, nil
1130+
}
1131+
1132+
1133+
1134+
// QueryWebHandleFlowInstanceResult web查询处理的流程实例结果
1135+
func (a *Flow) QueryWebHandleFlowInstanceResult(processor, typeCode, flowCode string, lastID int64, count int , ParamSearchList map[string]string) ([]*schema.FlowInstanceResult, error) {
1136+
var (
1137+
args []interface{}
1138+
1139+
)
1140+
query := fmt.Sprintf("SELECT fi.id,fi.record_id,fi.flow_id,fi.status,fi.launcher,fi.launch_time,f.code 'flow_code',f.name 'flow_name' FROM %s fi LEFT JOIN %s f ON fi.flow_id=f.record_id AND f.deleted=0 WHERE fi.deleted=0", schema.FlowInstanceTableName, schema.FlowTableName)
1141+
query = fmt.Sprintf("%s AND fi.launcher!=?", query)
1142+
args = append(args, processor)
1143+
if ParamSearchList != nil && len(ParamSearchList) > 0 {
1144+
tmpSql := ``
1145+
for i, v := range ParamSearchList {
1146+
if i == "page"{
1147+
continue
1148+
}
1149+
tmpSql += ` AND input_data->'$.` + i + `' = '` + v + `'`
1150+
}
1151+
query = fmt.Sprintf("%s AND fi.record_id IN(SELECT flow_instance_id FROM %s WHERE deleted=0 AND status=2 %s AND processor=?)", query, schema.NodeInstanceTableName,tmpSql)
1152+
}else {
1153+
query = fmt.Sprintf("%s AND fi.record_id IN(SELECT flow_instance_id FROM %s WHERE deleted=0 AND status=2 AND processor=?)", query, schema.NodeInstanceTableName)
1154+
1155+
}
1156+
args = append(args, processor)
1157+
1158+
if typeCode != "" {
1159+
query = fmt.Sprintf("%s AND f.type_code IN(?)", query)
1160+
args = append(args, strings.Split(typeCode, ","))
1161+
} else if flowCode != "" {
1162+
query = fmt.Sprintf("%s AND f.code=?", query)
1163+
args = append(args, flowCode)
1164+
}
1165+
tmpSql:=`SELECT fi.id,fi.record_id,fi.flow_id,fi.status,fi.launcher,fi.launch_time,f.code 'flow_code',f.name 'flow_name'`
1166+
num := a.GetWebFlowNumber(tmpSql,query,args )
1167+
1168+
fmt.Println("开始打印 --------------------------------条数")
1169+
fmt.Println()
1170+
fmt.Println(num)
1171+
fmt.Println()
1172+
fmt.Println("开始打印 --------------------------------条数")
1173+
1174+
if v,ok := ParamSearchList["page"];ok {
1175+
if v != "" {
1176+
//tmpSql := query
1177+
//tmpSql = fmt.Sprintf("select count(%s) as num ", tmpSql)
1178+
//tmpSql, args, _ = a.DB.In(tmpSql, args...)
1179+
//_, err := a.DB.Select(&items, tmpSql, args...)
1180+
page ,_ := strconv.Atoi(v)
1181+
query = fmt.Sprintf("%s ORDER BY fi.id DESC LIMIT %d offset %d", query, count,(page - 1 )*count)
1182+
}
1183+
} else {
1184+
if lastID > 0 {
1185+
query = fmt.Sprintf("%s AND fi.id<?", query)
1186+
args = append(args, lastID)
1187+
}
1188+
query = fmt.Sprintf("%s ORDER BY fi.id DESC LIMIT %d", query, count)
1189+
}
1190+
1191+
query, args, _ = a.DB.In(query, args...)
1192+
var items []*schema.FlowInstanceResult
1193+
_, err := a.DB.Select(&items, query, args...)
1194+
if err != nil {
1195+
return nil, errors.Wrapf(err, "查询发起的流程实例数据发生错误")
1196+
}
1197+
1198+
return items, nil
1199+
}
1200+
1201+
// QueryWebLastNodeInstances web查询流程实例的最后一个节点实例
1202+
func (a *Flow) QueryWebLastNodeInstances(flowInstanceIDs []string,ParamSearchList map[string]string) ([]*schema.NodeInstance, error) {
1203+
var (
1204+
query ,errMsg string
1205+
)
1206+
//说明有搜索条件
1207+
if len(ParamSearchList) > 0 {
1208+
query = `SELECT MAX(id)'id' FROM f_node_instance WHERE deleted=0 `
1209+
for i, v := range ParamSearchList {
1210+
if i == "page"{
1211+
continue
1212+
}
1213+
query +=` AND input_data->'$.`+i+`' = '`+v+`'`
1214+
}
1215+
query += ` AND flow_instance_id IN(?) GROUP BY flow_instance_id`
1216+
} else {
1217+
query = fmt.Sprintf("SELECT MAX(id)'id' FROM %s WHERE deleted=0 AND flow_instance_id IN(?) GROUP BY flow_instance_id", schema.NodeInstanceTableName)
1218+
}
1219+
1220+
errMsg = "查询流程实例的最后一个节点实例发生错误"
1221+
query, args, err := a.DB.In(query, flowInstanceIDs)
1222+
if err != nil {
1223+
return nil, errors.Wrapf(err, errMsg)
1224+
}
1225+
1226+
type IDItem struct {
1227+
ID int64 `db:"id"`
1228+
}
1229+
var idItems []IDItem
1230+
_, err = a.DB.Select(&idItems, query, args...)
1231+
if err != nil {
1232+
return nil, errors.Wrapf(err, errMsg)
1233+
} else if len(idItems) == 0 {
1234+
return nil, nil
1235+
}
1236+
1237+
ids := make([]int64, len(idItems))
1238+
for i, item := range idItems {
1239+
ids[i] = item.ID
1240+
}
1241+
query = fmt.Sprintf("SELECT * FROM %s WHERE id IN(?)", schema.NodeInstanceTableName)
1242+
query, args, err = a.DB.In(query, ids)
1243+
if err != nil {
1244+
return nil, errors.Wrapf(err, errMsg)
1245+
}
1246+
1247+
var items []*schema.NodeInstance
1248+
_, err = a.DB.Select(&items, query, args...)
1249+
if err != nil {
1250+
return nil, errors.Wrapf(err, errMsg)
1251+
}
1252+
return items, nil
1253+
}
1254+
1255+
// GetWebFlowNumber 获取条数
1256+
func (a *Flow)GetWebFlowNumber(tmpsql,sql string ,args []interface{})(num int64){
1257+
sql = strings.Replace(sql, tmpsql, " select count(fi.id) as num ", 1)
1258+
1259+
fmt.Println("开始打印 --------------------------------SQL")
1260+
fmt.Println()
1261+
fmt.Println(sql)
1262+
fmt.Println()
1263+
fmt.Println("开始打印 --------------------------------SQL")
1264+
sql, args, _ = a.DB.In(sql, args...)
1265+
num ,_ = a.DB.SelectInt(sql, args...)
1266+
return
1267+
}
10811268
// -----------------------------web查询操作(end)---------------------------------

schema/s_flow.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,13 @@ type FlowInstanceResult struct {
283283
FlowName string `db:"flow_name,size:36" structs:"flow_name" json:"flow_name"` // 流程名称
284284
}
285285

286+
//FlowWebInstanceResult web流程实例结果
287+
type FlowWebInstanceResult struct{
288+
FlowInstanceResult
289+
Num int64 `db:"num" structs:"num" json:"num"` //页码
290+
}
291+
292+
286293
// NodeOperating 节点操作
287294
type NodeOperating struct {
288295
NodeGroup []*Node

service/db/db.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"reflect"
1010
"strings"
1111
"time"
12-
1312
"github.com/LyricTian/retry"
1413
"github.com/pkg/errors"
1514
"gopkg.in/gorp.v2"

0 commit comments

Comments
 (0)