feat:完善项目
This commit is contained in:
@ -73,7 +73,7 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string)
|
||||
|
||||
// Logout 退出请求
|
||||
func (c *Instance) Logout() error {
|
||||
if c.UID > 0 {
|
||||
if c.Session != nil && c.UID > 0 {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
service.HubMessage.UnregisterHandle(service.NewWebsocket(c.UIDToString(), nil))
|
||||
}
|
||||
|
118
app/controller/dashboard/instance.go
Normal file
118
app/controller/dashboard/instance.go
Normal file
@ -0,0 +1,118 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Instance struct{ *service.Session }
|
||||
|
||||
type InstanceHandle func(session *service.Session) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 列表信息
|
||||
InstanceInfo struct {
|
||||
Workbench []*instanceInfoForWorkbench `json:"workbench"`
|
||||
Notice []*instanceInfoForNotice `json:"notice"`
|
||||
}
|
||||
// instanceInfoForWorkbench 待办事项
|
||||
instanceInfoForWorkbench struct {
|
||||
basic.CommonIDString
|
||||
EquipmentCode string `json:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title"`
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
Username string `json:"username"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// instanceInfoForNotice 公告信息
|
||||
instanceInfoForNotice struct {
|
||||
basic.CommonIDString
|
||||
Title string `json:"title"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
)
|
||||
|
||||
var defaultDataLimit int = 10
|
||||
|
||||
// Workbench 待办信息
|
||||
func (c *Instance) Workbench(limit int) ([]*instanceInfoForWorkbench, error) {
|
||||
mSysUserRole := model.NewSysUserRole()
|
||||
roleIDs := make([]string, 0)
|
||||
|
||||
err := model2.Pluck(mSysUserRole.SysUserRole, "role_id", &roleIDs, model2.NewWhere("uid", c.UID))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
|
||||
out := make([]*model.WorkInstanceInfo, 0)
|
||||
|
||||
if out, err = mWorkInstance.Workbench(&model.WorkbenchCondition{
|
||||
UID: c.UIDToString(), RoleIDs: roleIDs,
|
||||
}, limit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*instanceInfoForWorkbench, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mWorkInstance.SetID(v.ID)
|
||||
|
||||
list = append(list, &instanceInfoForWorkbench{
|
||||
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()},
|
||||
EquipmentCode: v.EquipmentCode,
|
||||
EquipmentTitle: v.EquipmentTitle,
|
||||
BreakdownTitle: v.BreakdownTitle,
|
||||
Username: v.Username,
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// notice 通知信息
|
||||
func (c *Instance) notice(limit int) ([]*instanceInfoForNotice, error) {
|
||||
mManageNotice := model.NewManageNotice()
|
||||
|
||||
out := make([]*model2.ManageNotice, 0)
|
||||
|
||||
if err := model2.ScanLimitFields(mManageNotice.ManageNotice, &out, []string{"id", "title", "created_at"}, limit, &model2.ModelWhereOrder{
|
||||
Where: model2.NewWhere("tenant_id", c.TenantID),
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*instanceInfoForNotice, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &instanceInfoForNotice{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
Title: v.Title,
|
||||
CreatedAt: v.CreatedAt,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Index 首页信息
|
||||
func (c *Instance) Index() (*InstanceInfo, error) {
|
||||
out := new(InstanceInfo)
|
||||
var err error
|
||||
|
||||
if out.Workbench, err = c.Workbench(defaultDataLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Notice, err = c.notice(defaultDataLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{session}
|
||||
}
|
||||
}
|
66
app/controller/dashboard/repair.go
Normal file
66
app/controller/dashboard/repair.go
Normal file
@ -0,0 +1,66 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Repair struct{ *service.Session }
|
||||
|
||||
type RepairHandle func(session *service.Session) *Repair
|
||||
|
||||
// Static 统计
|
||||
func (c *Repair) Static(date string) (interface{}, error) {
|
||||
currentAt := time.Now()
|
||||
|
||||
if date != "" {
|
||||
currentAt = utils.DataTimeForLayout(date, "2006-01")
|
||||
}
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
monthBegin := utils.MonthBeginAt(int(currentAt.Year()), int(currentAt.Month()))
|
||||
monthEnd := utils.MonthFinishAt(int(currentAt.Year()), int(currentAt.Month()))
|
||||
|
||||
where = append(where, model2.NewWhereSectionTime("w.created_at", []string{
|
||||
utils.FormatDate(monthBegin),
|
||||
utils.FormatDate(monthEnd)})...)
|
||||
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
|
||||
out, err := mWorkInstance.Static(where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_map := make(map[string]*model.WorkInstanceStaticInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
_map[v.Date] = v
|
||||
}
|
||||
list := make([]*model.WorkInstanceStaticInfo, 0)
|
||||
|
||||
for i := 0; i < monthEnd.Day(); i++ {
|
||||
if i > 0 {
|
||||
monthBegin = monthBegin.AddDate(0, 0, 1)
|
||||
}
|
||||
_date := utils.FormatDate(monthBegin)
|
||||
|
||||
if data, has := _map[_date]; has {
|
||||
list = append(list, data)
|
||||
continue
|
||||
}
|
||||
list = append(list, &model.WorkInstanceStaticInfo{
|
||||
Date: _date,
|
||||
})
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func NewRepair() RepairHandle {
|
||||
return func(session *service.Session) *Repair {
|
||||
return &Repair{session}
|
||||
}
|
||||
}
|
20
app/controller/dashboard/supplier.go
Normal file
20
app/controller/dashboard/supplier.go
Normal file
@ -0,0 +1,20 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/service"
|
||||
)
|
||||
|
||||
type Supplier struct{ *service.Session }
|
||||
|
||||
type SupplierHandle func(session *service.Session) *Supplier
|
||||
|
||||
func (c *Supplier) StaticScore() (*basic.PageDataResponse, error) {
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
}
|
||||
|
||||
func NewSupplier() SupplierHandle {
|
||||
return func(session *service.Session) *Supplier {
|
||||
return &Supplier{session}
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@ type (
|
||||
}
|
||||
// EquipmentParams 装备参数信息
|
||||
EquipmentParams struct {
|
||||
ID uint64
|
||||
ID, ParentID uint64
|
||||
Code, Title, Image, Config, Remark string
|
||||
}
|
||||
)
|
||||
@ -186,6 +186,7 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
mManageEquipment.ParentID = params.ParentID
|
||||
mManageEquipment.Code = params.Code
|
||||
mManageEquipment.Title = params.Title
|
||||
mManageEquipment.Image.Image = params.Image
|
||||
@ -210,11 +211,7 @@ func (c *Equipment) Form(params *EquipmentParams) error {
|
||||
func (c *Equipment) Delete(id uint64) error {
|
||||
mManageEquipment := model.NewManageEquipment()
|
||||
mManageEquipment.ID = id
|
||||
|
||||
if err := model2.Delete(mManageEquipment.ManageEquipment); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return model2.Delete(mManageEquipment.ManageEquipment)
|
||||
}
|
||||
|
||||
func NewEquipment() EquipmentHandle {
|
||||
|
@ -6,7 +6,9 @@ import (
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/config"
|
||||
"ArmedPolice/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -23,13 +25,17 @@ type (
|
||||
// MaterialInfo 基本信息
|
||||
MaterialInfo struct {
|
||||
basic.CommonIDString
|
||||
ManufacturerID string `json:"manufacturer_id"`
|
||||
*model.ManageMaterialInfo
|
||||
}
|
||||
// MaterialParams 基本参数
|
||||
MaterialParams struct {
|
||||
ID, ManufacturerID uint64
|
||||
Code, Title, Image, Remark string
|
||||
Unit int
|
||||
ID, ManufacturerID, MaterialID uint64
|
||||
Code, Title, Image, Remark string
|
||||
Unit int
|
||||
Price float64
|
||||
SupplierID uint64
|
||||
Stock float64
|
||||
}
|
||||
)
|
||||
|
||||
@ -62,7 +68,7 @@ func (c *Material) List(manufacturerID, supplierID uint64, code, title string, p
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mManageMaterial.Materials(page, pageSize, &count)
|
||||
out, err := mManageMaterial.Materials(page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -70,9 +76,14 @@ func (c *Material) List(manufacturerID, supplierID uint64, code, title string, p
|
||||
list := make([]*MaterialInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mManageMaterial.SetID(v.ManageMaterial.ManufacturerID)
|
||||
|
||||
v.Stock -= v.FrozenStock
|
||||
v.Image.Image = v.Analysis(config.SettingInfo.Domain)
|
||||
|
||||
list = append(list, &MaterialInfo{
|
||||
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
|
||||
ManufacturerID: mManageMaterial.GetEncodeID(),
|
||||
ManageMaterialInfo: v,
|
||||
})
|
||||
}
|
||||
@ -122,9 +133,13 @@ func (c *Material) Form(params *MaterialParams) error {
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
}
|
||||
if mManageMaterial.TenantID != c.TenantID {
|
||||
return errors.New("操作错误,无权限操作")
|
||||
}
|
||||
}
|
||||
mManageMaterial.ManufacturerID = params.ManufacturerID
|
||||
mManageMaterial.Code = params.Code
|
||||
mManageMaterial.Price = params.Price
|
||||
mManageMaterial.Title = params.Title
|
||||
mManageMaterial.Unit = model2.ManageMaterialUnit(params.Unit)
|
||||
mManageMaterial.Remark = params.Remark
|
||||
@ -133,15 +148,44 @@ func (c *Material) Form(params *MaterialParams) error {
|
||||
mManageMaterial.UpdatedAt = time.Now()
|
||||
return model2.Updates(mManageMaterial.ManageMaterial, mManageMaterial.ManageMaterial)
|
||||
}
|
||||
isExist, err := params.isExistForCode(mManageMaterial, c.TenantID)
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if params.MaterialID <= 0 {
|
||||
isExist, err := params.isExistForCode(mManageMaterial, c.TenantID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
mManageMaterial.TenantID = c.TenantID
|
||||
|
||||
if err = model2.Create(mManageMaterial.ManageMaterial, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
params.MaterialID = mManageMaterial.ID
|
||||
} else {
|
||||
if params.SupplierID <= 0 {
|
||||
return errors.New("操作错误,未知的供应商信息")
|
||||
}
|
||||
}
|
||||
mManageMaterialSupplier := model.NewManageMaterialSupplier()
|
||||
|
||||
var count int64
|
||||
|
||||
err := model2.Count(mManageMaterialSupplier.ManageMaterialSupplier, &count, model2.NewWhere("material_id", params.MaterialID),
|
||||
model2.NewWhere("supplier_id", params.SupplierID))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if count > 0 {
|
||||
return errors.New("操作错误,该器材已含有供应商信息")
|
||||
}
|
||||
mManageMaterialSupplier.MaterialID = params.MaterialID
|
||||
mManageMaterialSupplier.SupplierID = params.SupplierID
|
||||
mManageMaterialSupplier.Stock = params.Stock
|
||||
return model2.Create(mManageMaterialSupplier.ManageMaterialSupplier, tx)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if isExist {
|
||||
return errors.New("操作错误,已存在此对应的器材编码")
|
||||
}
|
||||
mManageMaterial.TenantID = c.TenantID
|
||||
return model2.Create(mManageMaterial.ManageMaterial)
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
|
@ -15,8 +15,10 @@ type InstanceHandle func(session *service.Session) *Instance
|
||||
type (
|
||||
// InstanceInfo 租户信息
|
||||
InstanceInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
*model2.Area
|
||||
*model2.AreaInfo
|
||||
Remark string `json:"remark"`
|
||||
Children []*InstanceInfo `json:"children"`
|
||||
@ -29,17 +31,20 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) tree(src []*model2.SysTenant, parentID uint64) []*InstanceInfo {
|
||||
func (c *Instance) tree(iModel model2.IModel, src []*model2.SysTenant, parentID uint64) []*InstanceInfo {
|
||||
out := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
iModel.SetID(v.ParentID)
|
||||
out = append(out, &InstanceInfo{
|
||||
ID: v.GetEncodeID(),
|
||||
ParentID: iModel.GetEncodeID(),
|
||||
Name: v.Name,
|
||||
Area: &v.Area,
|
||||
AreaInfo: v.Area.Format(),
|
||||
Remark: v.Remark,
|
||||
Children: c.tree(src, v.ID),
|
||||
Children: c.tree(iModel, src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -55,7 +60,7 @@ func (c *Instance) List() ([]*InstanceInfo, error) {
|
||||
if err := model2.Find(mSysTenant.SysTenant, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.tree(out, 0), nil
|
||||
return c.tree(mSysTenant.SysTenant, out, 0), nil
|
||||
}
|
||||
|
||||
// Form 数据操作
|
||||
|
@ -113,7 +113,7 @@ func (c *Instance) Person(materialID uint64, kind, page, pageSize int) (*basic.P
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mWorkInstance.Persons(c.UID, model2.WorkScheduleKindForRepair, page, pageSize, &count, where...)
|
||||
out, err := mWorkInstance.Persons(c.UID, page, pageSize, &count, where...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -155,7 +155,7 @@ func (c *Instance) Workbench(materialID uint64, kind, page, pageSize int) (*basi
|
||||
|
||||
out := make([]*model.WorkInstanceInfo, 0)
|
||||
|
||||
if out, err = mWorkInstance.Workbench(&model.WorkbenchCondition{
|
||||
if out, err = mWorkInstance.Workbenchs(&model.WorkbenchCondition{
|
||||
UID: c.UIDToString(), RoleIDs: roleIDs,
|
||||
}, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
@ -202,6 +202,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
}
|
||||
// 工单信息
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.UID = c.UID
|
||||
mWorkInstance.Kind = model2.WorkInstanceKind(params.Kind)
|
||||
mWorkInstance.Title = params.Title
|
||||
mWorkInstance.EquipmentID = params.EquipmentID
|
||||
|
Reference in New Issue
Block a user