Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ee97034

Browse files
committed
完善邮件通知功能。
1 parent c2c9576 commit ee97034

File tree

7 files changed

+337
-25
lines changed

7 files changed

+337
-25
lines changed

‎apis/process/workOrder.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ProcessStructure(c *gin.Context) {
5858
func CreateWorkOrder(c *gin.Context) {
5959
var (
6060
taskList []string
61-
stateList []map[string]interface{}
61+
stateList []interface{}
6262
userInfo system.SysUser
6363
variableValue []interface{}
6464
processValue process.Info
@@ -181,7 +181,7 @@ func CreateWorkOrder(c *gin.Context) {
181181
WorkOrder: workOrderInfo.Id,
182182
State: workOrderValue.SourceState,
183183
Source: workOrderValue.Source,
184-
Target: stateList[0]["id"].(string),
184+
Target: stateList[0].(map[string]interface{})["id"].(string),
185185
Circulation: "新建",
186186
Processor: nameValue,
187187
ProcessorId: userInfo.UserId,

‎database/mysql.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"ferry/tools/config"
77
"strconv"
88

9+
"github.com/spf13/viper"
10+
911
_ "github.com/go-sql-driver/mysql" //加载mysql
1012
"github.com/jinzhu/gorm"
1113
log "github.com/sirupsen/logrus"
@@ -39,7 +41,14 @@ func (e *Mysql) Setup() {
3941
log.Fatalf("database error %v", orm.Eloquent.Error)
4042
}
4143

42-
orm.Eloquent.LogMode(true)
44+
// 是否开启详细日志记录
45+
orm.Eloquent.LogMode(viper.GetBool("settings.gorm.logMode"))
46+
47+
// 设置最大打开连接数
48+
orm.Eloquent.DB().SetMaxOpenConns(viper.GetInt("settings.gorm.maxOpenConn"))
49+
50+
// 用于设置闲置的连接数.设置闲置的连接数则当开启的一个连接使用完成后可以放在池里等候下一次使用
51+
orm.Eloquent.DB().SetMaxIdleConns(viper.GetInt("settings.gorm.maxIdleConn"))
4352
}
4453

4554
type Mysql struct {

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ require (
2020
github.com/jinzhu/gorm v1.9.10
2121
github.com/json-iterator/go v1.1.8 // indirect
2222
github.com/mailru/easyjson v0.7.1 // indirect
23-
github.com/mattn/go-isatty v0.0.10 // indirect
2423
github.com/mojocn/base64Captcha v1.3.1
2524
github.com/mssola/user_agent v0.5.1
2625
github.com/pkg/errors v0.9.1
2726
github.com/robfig/cron/v3 v3.0.0
2827
github.com/satori/go.uuid v1.2.0
2928
github.com/shirou/gopsutil v2.20.3+incompatible
3029
github.com/sirupsen/logrus v1.4.2
30+
github.com/smallnest/rpcx v0.0.0-20200724150913-530623a2800b
3131
github.com/spf13/cobra v1.0.0
3232
github.com/spf13/viper v1.6.2
3333
github.com/swaggo/gin-swagger v1.2.0

‎go.sum‎

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.

‎pkg/service/getPrincipal.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err
4646
}
4747

4848
// 获取用户对应
49-
func GetPrincipalUserInfo(stateList []map[string]interface{}, creator int) (userInfoList []system.SysUser, err error) {
49+
func GetPrincipalUserInfo(stateList []interface{}, creator int) (userInfoList []system.SysUser, err error) {
5050
var (
5151
userInfo system.SysUser
5252
deptInfo system.Dept
@@ -59,17 +59,17 @@ func GetPrincipalUserInfo(stateList []map[string]interface{}, creator int) (user
5959
}
6060

6161
for _, stateItem := range stateList {
62-
switch stateItem["process_method"] {
62+
switch stateItem.(map[string]interface{})["process_method"] {
6363
case "person":
6464
err = orm.Eloquent.Model(&system.SysUser{}).
65-
Where("user_id in (?)", stateItem["processor"].([]interface{})).
65+
Where("user_id in (?)", stateItem.(map[string]interface{})["processor"].([]interface{})).
6666
Find(&userInfoListTmp).Error
6767
if err != nil {
6868
return
6969
}
7070
userInfoList = append(userInfoList, userInfoListTmp...)
7171
case "variable": // 变量
72-
for _, processor := range stateItem["processor"].([]interface{}) {
72+
for _, processor := range stateItem.(map[string]interface{})["processor"].([]interface{}) {
7373
if int(processor.(float64)) == 1 {
7474
// 创建者
7575
userInfoList = append(userInfoList, userInfo)

‎pkg/service/handle.go‎

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"ferry/models/system"
1010
"ferry/pkg/notify"
1111
"ferry/tools"
12-
"ferry/tools/app"
1312
"fmt"
1413
"reflect"
1514
"time"
@@ -341,7 +340,6 @@ func (h *Handle) HandleWorkOrder(
341340
currentUserInfo system.SysUser
342341
sendToUserList []system.SysUser
343342
noticeList []int
344-
stateList []map[string]interface{}
345343
sendSubject string = "您有一条待办工单,请及时处理"
346344
sendDescription string = "您有一条待办工单请及时处理,工单描述如下"
347345
)
@@ -635,7 +633,6 @@ func (h *Handle) HandleWorkOrder(
635633
Where("user_id = ?", tools.GetUserId(c)).
636634
Find(&currentUserInfo).Error
637635
if err != nil {
638-
app.Error(c, -1, err, fmt.Sprintf("当前用户查询失败,%v", err.Error()))
639636
return
640637
}
641638

@@ -657,10 +654,17 @@ func (h *Handle) HandleWorkOrder(
657654
h.tx.Rollback()
658655
return
659656
}
657+
658+
// 获取流程通知类型列表
659+
err = json.Unmarshal(processInfo.Notice, &noticeList)
660+
if err != nil {
661+
return
662+
}
663+
660664
// 判断目标是否是结束节点
661665
if h.targetStateValue["clazz"] == "end" && h.endHistory == true {
662-
sendSubject = "您的工单已完成"
663-
sendDescription = "您的工单已完成,工单描述如下"
666+
sendSubject = "您的工单已处理完成"
667+
sendDescription = "您的工单已处理完成,工单描述如下"
664668
err = h.tx.Create(&process.CirculationHistory{
665669
Model: base.Model{},
666670
Title: h.workOrderDetails.Title,
@@ -675,20 +679,41 @@ func (h *Handle) HandleWorkOrder(
675679
h.tx.Rollback()
676680
return
677681
}
682+
683+
// 查询工单创建人信息
684+
err = h.tx.Model(&system.SysUser{}).
685+
Where("user_id = ?", h.workOrderDetails.Creator).
686+
Find(&sendToUserList).Error
687+
if err != nil {
688+
return
689+
}
690+
691+
// 发送通知
692+
go func() {
693+
bodyData := notify.BodyData{
694+
SendTo: map[string]interface{}{
695+
"userList": sendToUserList,
696+
},
697+
Subject: sendSubject,
698+
Description: sendDescription,
699+
Classify: noticeList,
700+
ProcessId: h.workOrderDetails.Process,
701+
Id: h.workOrderDetails.Id,
702+
Title: h.workOrderDetails.Title,
703+
Creator: currentUserInfo.NickName,
704+
Priority: h.workOrderDetails.Priority,
705+
CreatedAt: h.workOrderDetails.CreatedAt.Format("2006年01月02日 15:04:05"),
706+
}
707+
bodyData.SendNotify()
708+
}()
678709
}
679710

680711
h.tx.Commit() // 提交事务
681712

682713
// 发送通知
683-
err = json.Unmarshal(processInfo.Notice, &noticeList)
684-
if err != nil {
685-
app.Error(c, -1, err, "")
686-
return
687-
}
688714
if len(noticeList) > 0 {
689-
sendToUserList, err = GetPrincipalUserInfo(stateList, h.workOrderDetails.Creator)
715+
sendToUserList, err = GetPrincipalUserInfo(h.updateValue["state"].([]interface{}), h.workOrderDetails.Creator)
690716
if err != nil {
691-
app.Error(c, -1, err, fmt.Sprintf("获取所有处理人的用户信息失败,%v", err.Error()))
692717
return
693718
}
694719

‎tools/user.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func GetUserId(c *gin.Context) int {
2222
if data["identity"] != nil {
2323
return int((data["identity"]).(float64))
2424
}
25-
log.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 说明:缺少identity")
25+
log.Println("********** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 说明:缺少identity")
2626
return 0
2727
}
2828

@@ -31,7 +31,7 @@ func GetUserIdStr(c *gin.Context) string {
3131
if data["identity"] != nil {
3232
return Int64ToString(int64((data["identity"]).(float64)))
3333
}
34-
log.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少identity")
34+
log.Println("********** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少identity")
3535
return ""
3636
}
3737

@@ -40,7 +40,7 @@ func GetUserName(c *gin.Context) string {
4040
if data["nice"] != nil {
4141
return (data["nice"]).(string)
4242
}
43-
fmt.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少nice")
43+
fmt.Println("********** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少nice")
4444
return ""
4545
}
4646

@@ -49,7 +49,7 @@ func GetRoleName(c *gin.Context) string {
4949
if data["rolekey"] != nil {
5050
return (data["rolekey"]).(string)
5151
}
52-
fmt.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少rolekey")
52+
fmt.Println("********** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少rolekey")
5353
return ""
5454
}
5555

@@ -59,6 +59,6 @@ func GetRoleId(c *gin.Context) int {
5959
i := int((data["roleid"]).(float64))
6060
return i
6161
}
62-
fmt.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少roleid")
62+
fmt.Println("********** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 缺少roleid")
6363
return 0
6464
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /