feat: 添加工单操作历史的状态记录。
This commit is contained in:
parent
d4dd4ffb65
commit
2a7d71a806
@ -3,6 +3,8 @@ package dashboard
|
|||||||
import (
|
import (
|
||||||
"ferry/pkg/service"
|
"ferry/pkg/service"
|
||||||
"ferry/tools/app"
|
"ferry/tools/app"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -13,14 +15,26 @@ import (
|
|||||||
|
|
||||||
func InitData(c *gin.Context) {
|
func InitData(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
count map[string]int // 工单数量统计
|
count map[string]int // 工单数量统计
|
||||||
ranks []service.Ranks
|
ranks []service.Ranks
|
||||||
|
submit map[string][]interface{}
|
||||||
|
startTime string
|
||||||
|
endTime string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
startTime = c.DefaultQuery("start_time", "")
|
||||||
|
endTime = c.DefaultQuery("end_time", "")
|
||||||
|
|
||||||
|
if startTime == "" || endTime == "" {
|
||||||
|
// 默认为最近7天的数据
|
||||||
|
startTime = fmt.Sprintf("%s 00:00:00", time.Now().AddDate(0, 0, -6).Format("2006-01-02"))
|
||||||
|
endTime = fmt.Sprintf("%s 23:59:59", time.Now().Format("2006-01-02"))
|
||||||
|
}
|
||||||
|
|
||||||
statistics := service.Statistics{
|
statistics := service.Statistics{
|
||||||
StartTime: "",
|
StartTime: startTime,
|
||||||
EndTime: "",
|
EndTime: endTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询工单类型数据统计
|
// 查询工单类型数据统计
|
||||||
@ -37,8 +51,18 @@ func InitData(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 工单提交数据统计
|
||||||
|
submit, err = statistics.DateRangeStatistics()
|
||||||
|
if err != nil {
|
||||||
|
app.Error(c, -1, err, "工单提交数据统计失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 工单处理人统计
|
||||||
|
|
||||||
app.OK(c, map[string]interface{}{
|
app.OK(c, map[string]interface{}{
|
||||||
"count": count,
|
"count": count,
|
||||||
"ranks": ranks,
|
"ranks": ranks,
|
||||||
|
"submit": submit,
|
||||||
}, "")
|
}, "")
|
||||||
}
|
}
|
||||||
|
@ -215,6 +215,7 @@ func UnityWorkOrder(c *gin.Context) {
|
|||||||
Processor: userInfo.NickName,
|
Processor: userInfo.NickName,
|
||||||
ProcessorId: tools.GetUserId(c),
|
ProcessorId: tools.GetUserId(c),
|
||||||
Remarks: "手动结束工单。",
|
Remarks: "手动结束工单。",
|
||||||
|
Status: 2,
|
||||||
})
|
})
|
||||||
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
@ -225,14 +226,16 @@ func UnityWorkOrder(c *gin.Context) {
|
|||||||
// 转交工单
|
// 转交工单
|
||||||
func InversionWorkOrder(c *gin.Context) {
|
func InversionWorkOrder(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
cirHistoryValue []process.CirculationHistory
|
||||||
workOrderInfo process.WorkOrderInfo
|
err error
|
||||||
stateList []map[string]interface{}
|
workOrderInfo process.WorkOrderInfo
|
||||||
stateValue []byte
|
stateList []map[string]interface{}
|
||||||
currentState map[string]interface{}
|
stateValue []byte
|
||||||
userInfo system.SysUser
|
currentState map[string]interface{}
|
||||||
currentUserInfo system.SysUser
|
userInfo system.SysUser
|
||||||
params struct {
|
currentUserInfo system.SysUser
|
||||||
|
costDurationValue int64
|
||||||
|
params struct {
|
||||||
WorkOrderId int `json:"work_order_id"`
|
WorkOrderId int `json:"work_order_id"`
|
||||||
NodeId string `json:"node_id"`
|
NodeId string `json:"node_id"`
|
||||||
UserId int `json:"user_id"`
|
UserId int `json:"user_id"`
|
||||||
@ -306,15 +309,33 @@ func InversionWorkOrder(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 流转历史写入
|
||||||
|
err = orm.Eloquent.Model(&cirHistoryValue).
|
||||||
|
Where("work_order = ?", params.WorkOrderId).
|
||||||
|
Find(&cirHistoryValue).
|
||||||
|
Order("create_time desc").Error
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, t := range cirHistoryValue {
|
||||||
|
if t.Source != currentState["id"].(string) {
|
||||||
|
costDuration := time.Since(t.CreatedAt.Time)
|
||||||
|
costDurationValue = int64(costDuration) / 1000 / 1000 / 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 添加转交历史
|
// 添加转交历史
|
||||||
tx.Create(&process.CirculationHistory{
|
tx.Create(&process.CirculationHistory{
|
||||||
Title: workOrderInfo.Title,
|
Title: workOrderInfo.Title,
|
||||||
WorkOrder: workOrderInfo.Id,
|
WorkOrder: workOrderInfo.Id,
|
||||||
State: currentState["label"].(string),
|
State: currentState["label"].(string),
|
||||||
Circulation: "转交",
|
Circulation: "转交",
|
||||||
Processor: currentUserInfo.NickName,
|
Processor: currentUserInfo.NickName,
|
||||||
ProcessorId: tools.GetUserId(c),
|
ProcessorId: tools.GetUserId(c),
|
||||||
Remarks: fmt.Sprintf("此阶段负责人已转交给《%v》", userInfo.NickName),
|
Remarks: fmt.Sprintf("此阶段负责人已转交给《%v》", userInfo.NickName),
|
||||||
|
Status: 2, // 其他
|
||||||
|
CostDuration: costDurationValue,
|
||||||
})
|
})
|
||||||
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
@ -11,16 +11,17 @@ import (
|
|||||||
// 工单流转历史
|
// 工单流转历史
|
||||||
type CirculationHistory struct {
|
type CirculationHistory struct {
|
||||||
base.Model
|
base.Model
|
||||||
Title string `gorm:"column:title; type: varchar(128)" json:"title" form:"title"` // 工单标题
|
Title string `gorm:"column:title; type: varchar(128)" json:"title" form:"title"` // 工单标题
|
||||||
WorkOrder int `gorm:"column:work_order; type: int(11)" json:"work_order" form:"work_order"` // 工单ID
|
WorkOrder int `gorm:"column:work_order; type: int(11)" json:"work_order" form:"work_order"` // 工单ID
|
||||||
State string `gorm:"column:state; type: varchar(128)" json:"state" form:"state"` // 工单状态
|
State string `gorm:"column:state; type: varchar(128)" json:"state" form:"state"` // 工单状态
|
||||||
Source string `gorm:"column:source; type: varchar(128)" json:"source" form:"source"` // 源节点ID
|
Source string `gorm:"column:source; type: varchar(128)" json:"source" form:"source"` // 源节点ID
|
||||||
Target string `gorm:"column:target; type: varchar(128)" json:"target" form:"target"` // 目标节点ID
|
Target string `gorm:"column:target; type: varchar(128)" json:"target" form:"target"` // 目标节点ID
|
||||||
Circulation string `gorm:"column:circulation; type: varchar(128)" json:"circulation" form:"circulation"` // 流转ID
|
Circulation string `gorm:"column:circulation; type: varchar(128)" json:"circulation" form:"circulation"` // 流转ID
|
||||||
Processor string `gorm:"column:processor; type: varchar(45)" json:"processor" form:"processor"` // 处理人
|
Status int `gorm:"column:status; type: int(11)" json:"status" form:"status"` // 流转状态 1 同意, 0 拒绝, 2 其他
|
||||||
ProcessorId int `gorm:"column:processor_id; type: int(11)" json:"processor_id" form:"processor_id"` // 处理人ID
|
Processor string `gorm:"column:processor; type: varchar(45)" json:"processor" form:"processor"` // 处理人
|
||||||
CostDuration string `gorm:"column:cost_duration; type: varchar(128)" json:"cost_duration" form:"cost_duration"` // 处理时长
|
ProcessorId int `gorm:"column:processor_id; type: int(11)" json:"processor_id" form:"processor_id"` // 处理人ID
|
||||||
Remarks string `gorm:"column:remarks; type: longtext" json:"remarks" form:"remarks"` // 备注
|
CostDuration int64 `gorm:"column:cost_duration; type: int(11)" json:"cost_duration" form:"cost_duration"` // 处理时长
|
||||||
|
Remarks string `gorm:"column:remarks; type: longtext" json:"remarks" form:"remarks"` // 备注
|
||||||
}
|
}
|
||||||
|
|
||||||
func (CirculationHistory) TableName() string {
|
func (CirculationHistory) TableName() string {
|
||||||
|
@ -272,6 +272,7 @@ func CreateWorkOrder(c *gin.Context) (err error) {
|
|||||||
Circulation: "新建",
|
Circulation: "新建",
|
||||||
Processor: nameValue,
|
Processor: nameValue,
|
||||||
ProcessorId: userInfo.UserId,
|
ProcessorId: userInfo.UserId,
|
||||||
|
Status: 2, // 其他
|
||||||
}).Error
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
@ -30,8 +30,8 @@ func NewStatistics(startTime string, endTime string) *Statistics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询周统计数据
|
// 查询范围统计数据
|
||||||
func WeeklyStatistics() (statisticsData map[string][]interface{}, err error) {
|
func (s *Statistics) DateRangeStatistics() (statisticsData map[string][]interface{}, err error) {
|
||||||
var (
|
var (
|
||||||
datetime string
|
datetime string
|
||||||
total int
|
total int
|
||||||
@ -120,7 +120,7 @@ func WeeklyStatistics() (statisticsData map[string][]interface{}, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 查询工单提交排名
|
// 查询工单提交排名
|
||||||
func SubmitRanking() (submitRankingData map[string][]interface{}, err error) {
|
func (s *Statistics) SubmitRanking() (submitRankingData map[string][]interface{}, err error) {
|
||||||
var (
|
var (
|
||||||
userId int
|
userId int
|
||||||
username string
|
username string
|
||||||
@ -198,8 +198,6 @@ func (s *Statistics) WorkOrderCount(c *gin.Context) (countList map[string]int, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询指定范围内的提交工单折线图统计
|
|
||||||
|
|
||||||
// 查询指定范围内的提交工单排名数据
|
// 查询指定范围内的提交工单排名数据
|
||||||
func (s *Statistics) WorkOrderRanks() (ranks []Ranks, err error) {
|
func (s *Statistics) WorkOrderRanks() (ranks []Ranks, err error) {
|
||||||
ranks = make([]Ranks, 0)
|
ranks = make([]Ranks, 0)
|
||||||
@ -207,6 +205,7 @@ func (s *Statistics) WorkOrderRanks() (ranks []Ranks, err error) {
|
|||||||
err = orm.Eloquent.Model(&process.WorkOrderInfo{}).
|
err = orm.Eloquent.Model(&process.WorkOrderInfo{}).
|
||||||
Joins("left join p_process_info on p_process_info.id = p_work_order_info.process").
|
Joins("left join p_process_info on p_process_info.id = p_work_order_info.process").
|
||||||
Select("p_process_info.name as name, count(p_work_order_info.id) as total").
|
Select("p_process_info.name as name, count(p_work_order_info.id) as total").
|
||||||
|
Where("p_work_order_info.create_time between ? and ?", s.StartTime, s.EndTime).
|
||||||
Group("p_work_order_info.process").
|
Group("p_work_order_info.process").
|
||||||
Order("total desc").
|
Order("total desc").
|
||||||
Limit(10).
|
Limit(10).
|
||||||
|
@ -53,15 +53,6 @@ type Handle struct {
|
|||||||
tx *gorm.DB
|
tx *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// 时间格式化
|
|
||||||
func fmtDuration(d time.Duration) string {
|
|
||||||
d = d.Round(time.Minute)
|
|
||||||
h := d / time.Hour
|
|
||||||
d -= h * time.Hour
|
|
||||||
m := d / time.Minute
|
|
||||||
return fmt.Sprintf("%02d小时 %02d分钟", h, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 会签
|
// 会签
|
||||||
func (h *Handle) Countersign(c *gin.Context) (err error) {
|
func (h *Handle) Countersign(c *gin.Context) (err error) {
|
||||||
var (
|
var (
|
||||||
@ -423,7 +414,7 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
relatedPersonList []int
|
relatedPersonList []int
|
||||||
cirHistoryValue []process.CirculationHistory
|
cirHistoryValue []process.CirculationHistory
|
||||||
cirHistoryData process.CirculationHistory
|
cirHistoryData process.CirculationHistory
|
||||||
costDurationValue string
|
costDurationValue int64
|
||||||
sourceEdges []map[string]interface{}
|
sourceEdges []map[string]interface{}
|
||||||
targetEdges []map[string]interface{}
|
targetEdges []map[string]interface{}
|
||||||
condExprStatus bool
|
condExprStatus bool
|
||||||
@ -534,13 +525,13 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
"id": h.targetStateValue["id"].(string),
|
"id": h.targetStateValue["id"].(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceEdges, err = h.processState.GetEdge(h.targetStateValue["id"].(string), "source")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch h.targetStateValue["clazz"] {
|
switch h.targetStateValue["clazz"] {
|
||||||
// 排他网关
|
case "exclusiveGateway": // 排他网关
|
||||||
case "exclusiveGateway":
|
|
||||||
sourceEdges, err = h.processState.GetEdge(h.targetStateValue["id"].(string), "source")
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
breakTag:
|
breakTag:
|
||||||
for _, edge := range sourceEdges {
|
for _, edge := range sourceEdges {
|
||||||
edgeCondExpr := make([]map[string]interface{}, 0)
|
edgeCondExpr := make([]map[string]interface{}, 0)
|
||||||
@ -588,15 +579,8 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
err = errors.New("所有流转均不符合条件,请确认。")
|
err = errors.New("所有流转均不符合条件,请确认。")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 并行/聚合网关
|
case "parallelGateway": // 并行/聚合网关
|
||||||
case "parallelGateway":
|
|
||||||
// 入口,判断
|
// 入口,判断
|
||||||
sourceEdges, err = h.processState.GetEdge(h.targetStateValue["id"].(string), "source")
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("查询流转信息失败,%v", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
targetEdges, err = h.processState.GetEdge(h.targetStateValue["id"].(string), "target")
|
targetEdges, err = h.processState.GetEdge(h.targetStateValue["id"].(string), "target")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("查询流转信息失败,%v", err.Error())
|
err = fmt.Errorf("查询流转信息失败,%v", err.Error())
|
||||||
@ -777,7 +761,7 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
for _, t := range cirHistoryValue {
|
for _, t := range cirHistoryValue {
|
||||||
if t.Source != h.stateValue["id"] {
|
if t.Source != h.stateValue["id"] {
|
||||||
costDuration := time.Since(t.CreatedAt.Time)
|
costDuration := time.Since(t.CreatedAt.Time)
|
||||||
costDurationValue = fmtDuration(costDuration)
|
costDurationValue = int64(costDuration) / 1000 / 1000 / 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,6 +783,7 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
Circulation: circulationValue,
|
Circulation: circulationValue,
|
||||||
Processor: currentUserInfo.NickName,
|
Processor: currentUserInfo.NickName,
|
||||||
ProcessorId: tools.GetUserId(c),
|
ProcessorId: tools.GetUserId(c),
|
||||||
|
Status: flowProperties,
|
||||||
CostDuration: costDurationValue,
|
CostDuration: costDurationValue,
|
||||||
Remarks: remarks,
|
Remarks: remarks,
|
||||||
}
|
}
|
||||||
@ -843,6 +828,7 @@ func (h *Handle) HandleWorkOrder(
|
|||||||
ProcessorId: tools.GetUserId(c),
|
ProcessorId: tools.GetUserId(c),
|
||||||
Circulation: "结束",
|
Circulation: "结束",
|
||||||
Remarks: "工单已结束",
|
Remarks: "工单已结束",
|
||||||
|
Status: 2, // 其他状态
|
||||||
}).Error
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.tx.Rollback()
|
h.tx.Rollback()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user