feat:完善项目

This commit is contained in:
henry
2021-11-09 14:08:02 +08:00
parent 08083d26d3
commit d544b7f80c
14 changed files with 338 additions and 61 deletions

View File

@ -52,18 +52,24 @@ func (c *EquipmentParams) isExist(iModel model2.IModel, tenantID uint64) (bool,
return count > 0, nil
}
func (c *Equipment) tree(src []*model2.ManageEquipment, parentID uint64) []*EquipmentInfo {
func (c *Equipment) tree(iModel model2.IModel, src []*model2.ManageEquipment, parentID uint64) []*EquipmentInfo {
out := make([]*EquipmentInfo, 0)
for _, v := range src {
if v.ParentID == parentID {
//parentID := "0"
//
//if v.ParentID > 0 {
// iModel.SetID(v.ParentID)
// parentID = iModel.GetEncodeID()
//}
out = append(out, &EquipmentInfo{
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
Code: v.Code,
Title: v.Title,
Image: v.Analysis(config.SettingInfo.Domain),
CreatedAt: v.CreatedAt,
Children: c.tree(src, v.ID),
Children: c.tree(iModel, src, v.ID),
})
}
}
@ -71,21 +77,17 @@ func (c *Equipment) tree(src []*model2.ManageEquipment, parentID uint64) []*Equi
}
// List 列表信息
func (c *Equipment) List(parentID uint64, title string, page, pageSize int) ([]*EquipmentInfo, error) {
func (c *Equipment) List(parentID uint64, title string) ([]*EquipmentInfo, error) {
mManageEquipment := model.NewManageEquipment()
out := make([]*model2.ManageEquipment, 0)
where := []*model2.ModelWhereOrder{
&model2.ModelWhereOrder{
Where: model2.NewWhere("parentID", parentID),
Order: model2.NewOrder("id", model2.OrderModeToDesc),
},
}
if parentID > 0 {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhere("parentID", parentID),
})
}
if title != "" {
where = append(where, &model2.ModelWhereOrder{
Where: model2.NewWhereLike("title", title),
@ -95,8 +97,7 @@ func (c *Equipment) List(parentID uint64, title string, page, pageSize int) ([]*
where...); err != nil {
return nil, err
}
return c.tree(out, 0), nil
return c.tree(mManageEquipment.ManageEquipment, out, 0), nil
}
// Detail 详细信息

View File

@ -17,6 +17,7 @@ type (
InstanceInfo struct {
ID string `json:"id"`
*model2.SysMenu
ParentID string `json:"parent_id"`
Children []*InstanceInfo `json:"children"`
}
// InstanceIdentityInfo 多个身份菜单信息
@ -37,15 +38,22 @@ type (
)
// tree 树状筛选
func (c *Instance) tree(src []*model2.SysMenu, parentID uint64) []*InstanceInfo {
func (c *Instance) tree(iModel model2.IModel, src []*model2.SysMenu, parentID uint64) []*InstanceInfo {
out := make([]*InstanceInfo, 0)
for _, v := range src {
if v.ParentID == parentID {
parentID := "0"
if v.ParentID > 0 {
iModel.SetID(v.ParentID)
parentID = iModel.GetEncodeID()
}
out = append(out, &InstanceInfo{
ID: v.GetEncodeID(),
ParentID: parentID,
SysMenu: v,
Children: c.tree(src, v.ID),
Children: c.tree(iModel, src, v.ID),
})
}
}
@ -79,7 +87,7 @@ func (c *Instance) List() ([]*InstanceInfo, error) {
if err != nil {
return nil, err
}
return c.tree(out, 0), nil
return c.tree(mSysMenu.SysMenu, out, 0), nil
}
// Form 数据操作
@ -96,7 +104,7 @@ func (c *Instance) Form(params *InstanceParams) error {
},
Auth: model2.SysMenuAuth(params.Auth),
Sort: params.Sort,
Status: model2.SysMenuStatusForNormal,
Status: model2.SysMenuStatus(params.Status),
Remark: params.Remark,
})
}
@ -121,7 +129,7 @@ func (c *Instance) Form(params *InstanceParams) error {
out.Status = model2.SysMenuStatus(params.Status)
out.Remark = params.Remark
if err = model2.Save(out); err != nil {
if err = model2.Save(out.SysMenu); err != nil {
return err
}
return nil

View File

@ -23,6 +23,11 @@ type (
basic.CommonIDString
*model.WorkInstanceInfo
}
// InstanceDetailInfo 详细信息
InstanceDetailInfo struct {
basic.CommonIDString
*model.WorkInstanceInfo
}
// InstanceLaunchParams 发起参数信息
InstanceLaunchParams struct {
ID uint64
@ -88,8 +93,46 @@ func (c *Instance) List(materialID uint64, kind, page, pageSize int) (*basic.Pag
return &basic.PageDataResponse{Data: list, Count: count}, nil
}
func (c *Instance) ToDo() {
// Person 个人提交的审核信息
func (c *Instance) Person(materialID uint64, kind, page, pageSize int) (*basic.PageDataResponse, error) {
mWorkInstance := model.NewWorkInstance()
where := make([]*model2.ModelWhere, 0)
if materialID > 0 {
where = append(where, model2.NewWhere("w.material_id", materialID))
}
if kind > 0 {
where = append(where, model2.NewWhere("w.kind", kind))
}
var count int64
out, err := mWorkInstance.Persons(c.UID, model2.WorkScheduleKindForRepair, page, pageSize, &count, where...)
if err != nil {
return nil, err
}
list := make([]*InstanceInfo, 0)
for _, v := range out {
mWorkInstance.ID = v.ID
list = append(list, &InstanceInfo{
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()}, WorkInstanceInfo: v,
})
}
return &basic.PageDataResponse{Data: list, Count: count}, nil
}
// Workbench 工作台
func (c *Instance) Workbench() {
}
func (c *Instance) Detail(id uint64) (interface{}, error) {
mWorkInstance := model.NewWorkInstance()
mWorkInstance.ID = id
return nil, nil
}
// Launch 发起工单申请
@ -129,7 +172,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
isExist := false
if isExist, err = mWorkSchedule.FirstSchedule(); err != nil {
if isExist, err = mWorkSchedule.FirstSchedule(model2.WorkScheduleKindForRepair); err != nil {
return err
} else if !isExist {
return errors.New("操作错误,无工单流程信息,请先核实数据")
@ -157,12 +200,9 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil {
return err
}
// 创建维修工单
mWorkRepair := model.NewWorkRepair()
mWorkRepair.WorkID = mWorkInstance.ID
if err = model2.Create(mWorkRepair.WorkRepair, tx); err != nil {
return err
if nextWorkSchedule != nil {
// 推送通知
go c.publish(nextWorkSchedule.Reviewer)
}
return nil
})
@ -204,6 +244,7 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e
} else if !isAuth {
return errors.New("操作错误,无权限审批")
}
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
// 工单流程记录
mWorkProgress := model.NewWorkProgress()
@ -220,33 +261,42 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e
"status": model2.WorkInstanceStatusForComplete, "updated_at": time.Now(),
}
// 下一流程
newNextScheduleInfo := new(model.WorkScheduleInfo)
nextScheduleInfo := new(model.WorkScheduleInfo)
// 拒绝审批,工单直接结束
if _status == model2.WorkProgressStatusForRefuse {
goto FINISH
}
// 下一流程信息
if newNextScheduleInfo, err = mWorkSchedule.NextSchedule(model2.WorkInstanceAssist(isAssist) == model2.WorkInstanceAssistForYes); err != nil {
if nextScheduleInfo, err = mWorkSchedule.NextSchedule(model2.WorkInstanceAssist(isAssist) == model2.WorkInstanceAssistForYes); err != nil {
return err
}
// 无下一流程,工单直接完成
if newNextScheduleInfo == nil || newNextScheduleInfo.ID <= 0 {
if nextScheduleInfo == nil || nextScheduleInfo.ID <= 0 {
goto FINISH
}
workUpdates["status"] = model2.WorkInstanceStatusForOngoing
workUpdates["schedule"] = newNextScheduleInfo.ID
workUpdates["schedule"] = nextScheduleInfo.ID
if newNextScheduleInfo.IsNext {
if nextScheduleInfo.IsNextStage {
workUpdates["is_assist"] = isAssist
}
// 推送通知
go c.publish(newNextScheduleInfo.Reviewer)
FINISH:
if err = model2.Updates(mWorkInstance.WorkInstance, workUpdates, tx); err != nil {
return err
}
// 完成,创建维修工单
if workUpdates["status"] == model2.WorkInstanceStatusForComplete {
// 创建维修工单
mWorkRepair := model.NewWorkRepair()
mWorkRepair.WorkID = mWorkInstance.ID
if err = model2.Create(mWorkRepair.WorkRepair, tx); err != nil {
return err
}
}
// 推送通知
go c.publish(nextScheduleInfo.Reviewer)
return nil
}); err != nil {
return err
@ -254,8 +304,11 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int) e
return nil
}
func (c *Instance) Delete() error {
return nil
// Delete 删除操作
func (c *Instance) Delete(id uint64) error {
mWorkInstance := model.NewWorkInstance()
mWorkInstance.ID = id
return model2.Delete(mWorkInstance.WorkInstance)
}
func NewInstance() InstanceHandle {