Skip to content

Commit

Permalink
完善邮件通知功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyulei committed Jul 25, 2020
1 parent c2c9576 commit ee97034
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 25 deletions.
4 changes: 2 additions & 2 deletions apis/process/workOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ProcessStructure(c *gin.Context) {
func CreateWorkOrder(c *gin.Context) {
var (
taskList []string
stateList []map[string]interface{}
stateList []interface{}
userInfo system.SysUser
variableValue []interface{}
processValue process.Info
Expand Down Expand Up @@ -181,7 +181,7 @@ func CreateWorkOrder(c *gin.Context) {
WorkOrder: workOrderInfo.Id,
State: workOrderValue.SourceState,
Source: workOrderValue.Source,
Target: stateList[0]["id"].(string),
Target: stateList[0].(map[string]interface{})["id"].(string),
Circulation: "新建",
Processor: nameValue,
ProcessorId: userInfo.UserId,
Expand Down
11 changes: 10 additions & 1 deletion database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"ferry/tools/config"
"strconv"

"github.com/spf13/viper"

_ "github.com/go-sql-driver/mysql" //加载mysql
"github.com/jinzhu/gorm"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -39,7 +41,14 @@ func (e *Mysql) Setup() {
log.Fatalf("database error %v", orm.Eloquent.Error)
}

orm.Eloquent.LogMode(true)
// 是否开启详细日志记录
orm.Eloquent.LogMode(viper.GetBool("settings.gorm.logMode"))

// 设置最大打开连接数
orm.Eloquent.DB().SetMaxOpenConns(viper.GetInt("settings.gorm.maxOpenConn"))

// 用于设置闲置的连接数.设置闲置的连接数则当开启的一个连接使用完成后可以放在池里等候下一次使用
orm.Eloquent.DB().SetMaxIdleConns(viper.GetInt("settings.gorm.maxIdleConn"))
}

type Mysql struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ require (
github.com/jinzhu/gorm v1.9.10
github.com/json-iterator/go v1.1.8 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mojocn/base64Captcha v1.3.1
github.com/mssola/user_agent v0.5.1
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.0
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.20.3+incompatible
github.com/sirupsen/logrus v1.4.2
github.com/smallnest/rpcx v0.0.0-20200724150913-530623a2800b
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.6.2
github.com/swaggo/gin-swagger v1.2.0
Expand Down
278 changes: 278 additions & 0 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pkg/service/getPrincipal.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetPrincipal(processor []int, processMethod string) (principals string, err
}

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

for _, stateItem := range stateList {
switch stateItem["process_method"] {
switch stateItem.(map[string]interface{})["process_method"] {
case "person":
err = orm.Eloquent.Model(&system.SysUser{}).
Where("user_id in (?)", stateItem["processor"].([]interface{})).
Where("user_id in (?)", stateItem.(map[string]interface{})["processor"].([]interface{})).
Find(&userInfoListTmp).Error
if err != nil {
return
}
userInfoList = append(userInfoList, userInfoListTmp...)
case "variable": // 变量
for _, processor := range stateItem["processor"].([]interface{}) {
for _, processor := range stateItem.(map[string]interface{})["processor"].([]interface{}) {
if int(processor.(float64)) == 1 {
// 创建者
userInfoList = append(userInfoList, userInfo)
Expand Down
49 changes: 37 additions & 12 deletions pkg/service/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"ferry/models/system"
"ferry/pkg/notify"
"ferry/tools"
"ferry/tools/app"
"fmt"
"reflect"
"time"
Expand Down Expand Up @@ -341,7 +340,6 @@ func (h *Handle) HandleWorkOrder(
currentUserInfo system.SysUser
sendToUserList []system.SysUser
noticeList []int
stateList []map[string]interface{}
sendSubject string = "您有一条待办工单,请及时处理"
sendDescription string = "您有一条待办工单请及时处理,工单描述如下"
)
Expand Down Expand Up @@ -635,7 +633,6 @@ func (h *Handle) HandleWorkOrder(
Where("user_id = ?", tools.GetUserId(c)).
Find(&currentUserInfo).Error
if err != nil {
app.Error(c, -1, err, fmt.Sprintf("当前用户查询失败,%v", err.Error()))
return
}

Expand All @@ -657,10 +654,17 @@ func (h *Handle) HandleWorkOrder(
h.tx.Rollback()
return
}

// 获取流程通知类型列表
err = json.Unmarshal(processInfo.Notice, &noticeList)
if err != nil {
return
}

// 判断目标是否是结束节点
if h.targetStateValue["clazz"] == "end" && h.endHistory == true {
sendSubject = "您的工单已完成"
sendDescription = "您的工单已完成,工单描述如下"
sendSubject = "您的工单已处理完成"
sendDescription = "您的工单已处理完成,工单描述如下"
err = h.tx.Create(&process.CirculationHistory{
Model: base.Model{},
Title: h.workOrderDetails.Title,
Expand All @@ -675,20 +679,41 @@ func (h *Handle) HandleWorkOrder(
h.tx.Rollback()
return
}

// 查询工单创建人信息
err = h.tx.Model(&system.SysUser{}).
Where("user_id = ?", h.workOrderDetails.Creator).
Find(&sendToUserList).Error
if err != nil {
return
}

// 发送通知
go func() {
bodyData := notify.BodyData{
SendTo: map[string]interface{}{
"userList": sendToUserList,
},
Subject: sendSubject,
Description: sendDescription,
Classify: noticeList,
ProcessId: h.workOrderDetails.Process,
Id: h.workOrderDetails.Id,
Title: h.workOrderDetails.Title,
Creator: currentUserInfo.NickName,
Priority: h.workOrderDetails.Priority,
CreatedAt: h.workOrderDetails.CreatedAt.Format("2006-01-02 15:04:05"),
}
bodyData.SendNotify()
}()
}

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

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

Expand Down
10 changes: 5 additions & 5 deletions tools/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func GetUserId(c *gin.Context) int {
if data["identity"] != nil {
return int((data["identity"]).(float64))
}
log.Println("****************************** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 说明:缺少identity")
log.Println("********** 路径:" + c.Request.URL.Path + " 请求方法:" + c.Request.Method + " 说明:缺少identity")
return 0
}

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

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

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

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

0 comments on commit ee97034

Please sign in to comment.