feat:完善项目

This commit is contained in:
henry
2021-11-16 11:46:44 +08:00
parent 78128277ff
commit 978918e5aa
14 changed files with 193 additions and 19 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
doc/ doc/
log/ log/
dist/ dist/
data/
cmd/ctl/main cmd/ctl/main
cmd/ctl/ctl cmd/ctl/ctl
main main

View File

@ -32,6 +32,11 @@ type Dashboard struct{}
* @apiSuccess (200) {String} data.notice.id ID * @apiSuccess (200) {String} data.notice.id ID
* @apiSuccess (200) {String} data.notice.title 公告标题 * @apiSuccess (200) {String} data.notice.title 公告标题
* @apiSuccess (200) {Time} data.notice.created_at 公告创建时间 * @apiSuccess (200) {Time} data.notice.created_at 公告创建时间
* @apiSuccess (200) {Object} data.evaluate 评价信息
* @apiSuccess (200) {String} data.evaluate.name ID
* @apiSuccess (200) {Number} data.evaluate.praise 好评数
* @apiSuccess (200) {Number} data.evaluate.middle 中评数
* @apiSuccess (200) {Number} data.evaluate.negative 差评数
* @apiSuccess (200) {Number} code 成功响应状态码! * @apiSuccess (200) {Number} code 成功响应状态码!
* @apiSuccess (200) {String} msg 成功提示 * @apiSuccess (200) {String} msg 成功提示
* *
@ -48,11 +53,17 @@ type Dashboard struct{}
* "breakdown_title": "" * "breakdown_title": ""
* "username": "" * "username": ""
* "created_at": "" * "created_at": ""
* ] * ],
* "notice": [ * "notice": [
* "id": "", * "id": "",
* "title": "", * "title": "",
* "created_at": "2021-11-01" * "created_at": "2021-11-01"
* ],
* "evaluate": [
* "name": "",
* "praise": 1,
* "middle": 0,
* "negative": 0,
* ] * ]
* } * }
* } * }
@ -104,7 +115,3 @@ func (*Dashboard) Repair(c *gin.Context) {
data, err := dashboard.NewRepair()(getSession()(c).(*service.Session)).Static(form.Date) data, err := dashboard.NewRepair()(getSession()(c).(*service.Session)).Static(form.Date)
APIResponse(err, data)(c) APIResponse(err, data)(c)
} }
func (*Dashboard) Score(c *gin.Context) {
}

View File

@ -50,7 +50,7 @@ func initModel() {
// 公告管理 // 公告管理
&synchronized{iModel: model.NewManageNotice()}, &synchronized{iModel: model.NewManageNotice()},
// 功能信息 // 功能信息
&synchronized{iModel: model.NewManageSupplier()}, &synchronized{iModel: model.NewManageSupplier()}, &synchronized{iModel: model.NewManageSupplierEvaluate()},
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()}, &synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
&synchronized{iModel: model.NewManageMaterial()}, &synchronized{iModel: model.NewManageMaterialSupplier()}, &synchronized{iModel: model.NewManageMaterial()}, &synchronized{iModel: model.NewManageMaterialSupplier()},
&synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()}, &synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()},

View File

@ -0,0 +1,20 @@
package model
// ManageSupplierEvaluate 供应商评价数据模型
type ManageSupplierEvaluate struct {
Model
SupplierID uint64 `gorm:"column:supplier_id;type:int(11);default:0;comment:供应商ID" json:"-"`
Praise int `gorm:"column:praise;type:int(8);default:0;comment:好评" json:"praise"`
Middle int `gorm:"column:middle;type:int(8);default:0;comment:中评" json:"middle"`
Negative int `gorm:"column:negative;type:int(8);default:0;comment:差评" json:"negative"`
ModelDeleted
ModelAt
}
func (m *ManageSupplierEvaluate) TableName() string {
return "manage_supplier_evaluate"
}
func NewManageSupplierEvaluate() *ManageSupplierEvaluate {
return &ManageSupplierEvaluate{}
}

View File

@ -68,7 +68,8 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string)
service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, ip) service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, ip)
return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime, return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime,
WsUrl: config.SystemConfig[config.WsDomain].(string)}, nil //WsUrl: config.SystemConfig[config.WsDomain].(string)}, nil
WsUrl: ""}, nil
} }
// Logout 退出请求 // Logout 退出请求

View File

@ -15,8 +15,9 @@ type InstanceHandle func(session *service.Session) *Instance
type ( type (
// InstanceInfo 列表信息 // InstanceInfo 列表信息
InstanceInfo struct { InstanceInfo struct {
Workbench []*instanceInfoForWorkbench `json:"workbench"` Workbench []*instanceInfoForWorkbench `json:"workbench"`
Notice []*instanceInfoForNotice `json:"notice"` Notice []*instanceInfoForNotice `json:"notice"`
Evaluate []*model.ManageSupplierEvaluateInfo `json:"evaluate"`
} }
// instanceInfoForWorkbench 待办事项 // instanceInfoForWorkbench 待办事项
instanceInfoForWorkbench struct { instanceInfoForWorkbench struct {
@ -33,6 +34,9 @@ type (
Title string `json:"title"` Title string `json:"title"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
} }
// instanceInfoForEvaluate 好评信息
instanceInfoForEvaluate struct {
}
) )
var defaultDataLimit int = 10 var defaultDataLimit int = 10
@ -97,6 +101,11 @@ func (c *Instance) notice(limit int) ([]*instanceInfoForNotice, error) {
return list, nil return list, nil
} }
func (c *Instance) evaluate(limit int) ([]*model.ManageSupplierEvaluateInfo, error) {
mManageSupplier := model.NewManageSupplier()
return mManageSupplier.Evaluate(model2.ManageSupplierKindForMaterial, limit)
}
// Index 首页信息 // Index 首页信息
func (c *Instance) Index() (*InstanceInfo, error) { func (c *Instance) Index() (*InstanceInfo, error) {
out := new(InstanceInfo) out := new(InstanceInfo)
@ -108,6 +117,9 @@ func (c *Instance) Index() (*InstanceInfo, error) {
if out.Notice, err = c.notice(defaultDataLimit); err != nil { if out.Notice, err = c.notice(defaultDataLimit); err != nil {
return nil, err return nil, err
} }
if out.Evaluate, err = c.evaluate(defaultDataLimit); err != nil {
return nil, err
}
return out, nil return out, nil
} }

View File

@ -1,7 +1,8 @@
package dashboard package dashboard
import ( import (
"ArmedPolice/app/controller/basic" model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/model"
"ArmedPolice/app/service" "ArmedPolice/app/service"
) )
@ -9,8 +10,10 @@ type Supplier struct{ *service.Session }
type SupplierHandle func(session *service.Session) *Supplier type SupplierHandle func(session *service.Session) *Supplier
func (c *Supplier) StaticScore() (*basic.PageDataResponse, error) { func (c *Supplier) StaticEvaluate() (interface{}, error) {
return &basic.PageDataResponse{Data: nil, Count: 0}, nil mManageSupplier := model.NewManageSupplier()
out, err := mManageSupplier.Evaluate(model2.ManageSupplierKindForMaterial, 10)
return out, err
} }
func NewSupplier() SupplierHandle { func NewSupplier() SupplierHandle {

View File

@ -163,7 +163,7 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
mWorkRepair := model.NewWorkRepair() mWorkRepair := model.NewWorkRepair()
mWorkRepair.ID = id mWorkRepair.ID = id
isExist, err := model2.FirstField(mWorkRepair.WorkRepair, []string{"id", "status", "is_evaluate"}) isExist, err := model2.FirstField(mWorkRepair.WorkRepair, []string{"id", "work_id", "status", "is_evaluate"})
if err != nil { if err != nil {
return err return err
@ -176,12 +176,65 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
if mWorkRepair.IsEvaluate != model2.WorkRepairStatusEvaluateForNot { if mWorkRepair.IsEvaluate != model2.WorkRepairStatusEvaluateForNot {
return errors.New("操作错误,当前工单已评价,不可重复评价") return errors.New("操作错误,当前工单已评价,不可重复评价")
} }
if err = model2.Updates(mWorkRepair.WorkRepair, map[string]interface{}{ // 查询工单下使用的器材供应商信息
"is_evaluate": model2.WorkRepairStatusEvaluateForYes, "evaluate_score": score, "updated_at": time.Now(), mWorkMaterial := model.NewWorkMaterial()
}); err != nil { supplierIDs := make([]uint64, 0)
if err = model2.Pluck(mWorkMaterial.WorkMaterial, "material_supplier_id", &supplierIDs,
model2.NewWhere("work_id", mWorkRepair.WorkID)); err != nil {
return err return err
} }
return nil _supplierIDs := utils.ArrayUnique(supplierIDs)
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
if err = model2.Updates(mWorkRepair.WorkRepair, map[string]interface{}{
"is_evaluate": model2.WorkRepairStatusEvaluateForYes, "evaluate_score": score, "updated_at": time.Now(),
}, tx); err != nil {
return err
}
updates := map[string]interface{}{
"updated_at": time.Now(),
}
if score == 1 {
updates["praise"] = gorm.Expr("praise + ?", 1)
} else if score == 2 {
updates["middle"] = gorm.Expr("middle + ?", 1)
} else {
updates["negative"] = gorm.Expr("negative + ?", 1)
}
mManageSupplierEvaluate := model.NewManageSupplierEvaluate()
supplierEvaluates := make([]*model2.ManageSupplierEvaluate, 0)
for _, v := range _supplierIDs {
// 查询是否存在
if isExist, err = model2.FirstField(mManageSupplierEvaluate.ManageSupplierEvaluate, []string{"id"},
model2.NewWhere("id", v)); err != nil {
return err
} else if !isExist {
if err = model2.Updates(mManageSupplierEvaluate.ManageSupplierEvaluate, updates, tx); err != nil {
return err
}
continue
}
data := &model2.ManageSupplierEvaluate{SupplierID: v.(uint64)}
if score == 1 {
data.Praise = 1
} else if score == 2 {
data.Middle = 2
} else {
data.Negative = 1
}
supplierEvaluates = append(supplierEvaluates, data)
}
if len(supplierEvaluates) > 0 {
if err = model2.Creates(mManageSupplierEvaluate.ManageSupplierEvaluate, supplierEvaluates, tx); err != nil {
return err
}
}
return nil
})
} }
func NewRepair() RepairHandle { func NewRepair() RepairHandle {

View File

@ -1,11 +1,41 @@
package model package model
import "ArmedPolice/app/common/model" import (
"ArmedPolice/app/common/model"
"ArmedPolice/serve/orm"
"fmt"
)
type ManageSupplier struct { type ManageSupplier struct {
*model.ManageSupplier *model.ManageSupplier
} }
type ManageSupplierEvaluateInfo struct {
Name string `json:"name"`
Praise int `json:"praise"`
Middle int `json:"middle"`
Negative int `json:"negative"`
}
// Evaluate 评分统计
// Deprecated: Test
func (m *ManageSupplier) Evaluate(kind model.ManageSupplierKind, limit int) ([]*ManageSupplierEvaluateInfo, error) {
db := orm.GetDB().Table(m.TableName()+" AS s").
Select("s.name", "e.praise", "e.middle", "e.negative").
Joins(fmt.Sprintf("LEFT JOIN %s AS e ON s.id = e.supplier_id AND e.is_deleted = %d",
model.NewManageSupplierEvaluate().TableName(), model.DeleteStatusForNot)).
Where("s.is_deleted = ?", model.DeleteStatusForNot).
Where("s.kind = ?", kind).
Where("e.id > ?", 0)
out := make([]*ManageSupplierEvaluateInfo, 0)
err := db.Order("e.praise " + model.OrderModeToDesc).Order("e.negative " + model.OrderModeToAsc).
Limit(limit).Scan(&out).Error
return out, err
}
func NewManageSupplier() *ManageSupplier { func NewManageSupplier() *ManageSupplier {
return &ManageSupplier{model.NewManageSupplier()} return &ManageSupplier{model.NewManageSupplier()}
} }

View File

@ -0,0 +1,13 @@
package model
import (
"ArmedPolice/app/common/model"
)
type ManageSupplierEvaluate struct {
*model.ManageSupplierEvaluate
}
func NewManageSupplierEvaluate() *ManageSupplierEvaluate {
return &ManageSupplierEvaluate{model.NewManageSupplierEvaluate()}
}

View File

@ -20,6 +20,10 @@ type WorkRepairInfo struct {
BreakdownTitle string `json:"breakdown_title"` BreakdownTitle string `json:"breakdown_title"`
} }
type WorkRepairEvaluateInfo struct {
Name string `json:"name"`
}
// Repairs 维修工单信息 // Repairs 维修工单信息
func (m *WorkRepair) Repairs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkRepairInfo, error) { func (m *WorkRepair) Repairs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkRepairInfo, error) {
db := orm.GetDB().Table(m.TableName()+" r"). db := orm.GetDB().Table(m.TableName()+" r").

View File

@ -69,7 +69,6 @@ func (this *Router) registerAPI() {
_api := new(api.Dashboard) _api := new(api.Dashboard)
dashboardV1.GET("/", _api.Index) dashboardV1.GET("/", _api.Index)
dashboardV1.POST("/repair", _api.Repair) dashboardV1.POST("/repair", _api.Repair)
dashboardV1.GET("/score", _api.Score)
} }
// Account 接口管理 // Account 接口管理
accountV1 := v1.Group("/account") accountV1 := v1.Group("/account")

View File

@ -49,3 +49,24 @@ func ArrayStrings(src interface{}) []string {
} }
return out return out
} }
func ArrayUnique(src interface{}) []interface{} {
val := reflect.ValueOf(src)
kind := val.Kind()
out := make([]interface{}, 0)
if kind == reflect.Slice || kind == reflect.Array {
for i := 0; i < val.Len(); i++ {
for _, v := range out {
if v == val.Index(i).Interface() {
goto BREAK
}
}
out = append(out, val.Index(i).Interface())
BREAK:
}
}
return out
}

View File

@ -38,3 +38,13 @@ func TestArrayStrings(t *testing.T) {
t.Log(b) t.Log(b)
t.Log(reflect.TypeOf(b).String()) t.Log(reflect.TypeOf(b).String())
} }
func TestArrayUnique(t *testing.T) {
a := []uint64{1, 2, 3, 4, 5, 5, 5}
b := ArrayUnique(a)
t.Log(b)
for _, v := range b {
fmt.Printf(reflect.TypeOf(v).String())
}
}