feat:完善项目
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@
|
||||
doc/
|
||||
log/
|
||||
dist/
|
||||
data/
|
||||
cmd/ctl/main
|
||||
cmd/ctl/ctl
|
||||
main
|
||||
|
@ -32,6 +32,11 @@ type Dashboard struct{}
|
||||
* @apiSuccess (200) {String} data.notice.id ID
|
||||
* @apiSuccess (200) {String} data.notice.title 公告标题
|
||||
* @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) {String} msg 成功提示
|
||||
*
|
||||
@ -48,11 +53,17 @@ type Dashboard struct{}
|
||||
* "breakdown_title": ""
|
||||
* "username": ""
|
||||
* "created_at": ""
|
||||
* ]
|
||||
* ],
|
||||
* "notice": [
|
||||
* "id": "",
|
||||
* "title": "",
|
||||
* "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)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*Dashboard) Score(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func initModel() {
|
||||
// 公告管理
|
||||
&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.NewManageMaterial()}, &synchronized{iModel: model.NewManageMaterialSupplier()},
|
||||
&synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()},
|
||||
|
20
app/common/model/manage_supplier_evaluate.go
Normal file
20
app/common/model/manage_supplier_evaluate.go
Normal 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{}
|
||||
}
|
@ -68,7 +68,8 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string)
|
||||
service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, ip)
|
||||
|
||||
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 退出请求
|
||||
|
@ -15,8 +15,9 @@ type InstanceHandle func(session *service.Session) *Instance
|
||||
type (
|
||||
// InstanceInfo 列表信息
|
||||
InstanceInfo struct {
|
||||
Workbench []*instanceInfoForWorkbench `json:"workbench"`
|
||||
Notice []*instanceInfoForNotice `json:"notice"`
|
||||
Workbench []*instanceInfoForWorkbench `json:"workbench"`
|
||||
Notice []*instanceInfoForNotice `json:"notice"`
|
||||
Evaluate []*model.ManageSupplierEvaluateInfo `json:"evaluate"`
|
||||
}
|
||||
// instanceInfoForWorkbench 待办事项
|
||||
instanceInfoForWorkbench struct {
|
||||
@ -33,6 +34,9 @@ type (
|
||||
Title string `json:"title"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
// instanceInfoForEvaluate 好评信息
|
||||
instanceInfoForEvaluate struct {
|
||||
}
|
||||
)
|
||||
|
||||
var defaultDataLimit int = 10
|
||||
@ -97,6 +101,11 @@ func (c *Instance) notice(limit int) ([]*instanceInfoForNotice, error) {
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (c *Instance) evaluate(limit int) ([]*model.ManageSupplierEvaluateInfo, error) {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
return mManageSupplier.Evaluate(model2.ManageSupplierKindForMaterial, limit)
|
||||
}
|
||||
|
||||
// Index 首页信息
|
||||
func (c *Instance) Index() (*InstanceInfo, error) {
|
||||
out := new(InstanceInfo)
|
||||
@ -108,6 +117,9 @@ func (c *Instance) Index() (*InstanceInfo, error) {
|
||||
if out.Notice, err = c.notice(defaultDataLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out.Evaluate, err = c.evaluate(defaultDataLimit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/basic"
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
)
|
||||
|
||||
@ -9,8 +10,10 @@ 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 (c *Supplier) StaticEvaluate() (interface{}, error) {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
out, err := mManageSupplier.Evaluate(model2.ManageSupplierKindForMaterial, 10)
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewSupplier() SupplierHandle {
|
||||
|
@ -163,7 +163,7 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
|
||||
mWorkRepair := model.NewWorkRepair()
|
||||
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 {
|
||||
return err
|
||||
@ -176,12 +176,65 @@ func (c *Repair) Evaluate(id uint64, score float64) error {
|
||||
if mWorkRepair.IsEvaluate != model2.WorkRepairStatusEvaluateForNot {
|
||||
return errors.New("操作错误,当前工单已评价,不可重复评价")
|
||||
}
|
||||
if err = model2.Updates(mWorkRepair.WorkRepair, map[string]interface{}{
|
||||
"is_evaluate": model2.WorkRepairStatusEvaluateForYes, "evaluate_score": score, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
// 查询工单下使用的器材供应商信息
|
||||
mWorkMaterial := model.NewWorkMaterial()
|
||||
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 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 {
|
||||
|
@ -1,11 +1,41 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ManageSupplier struct {
|
||||
*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 {
|
||||
return &ManageSupplier{model.NewManageSupplier()}
|
||||
}
|
||||
|
13
app/model/manage_supplier_evaluate.go
Normal file
13
app/model/manage_supplier_evaluate.go
Normal file
@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
)
|
||||
|
||||
type ManageSupplierEvaluate struct {
|
||||
*model.ManageSupplierEvaluate
|
||||
}
|
||||
|
||||
func NewManageSupplierEvaluate() *ManageSupplierEvaluate {
|
||||
return &ManageSupplierEvaluate{model.NewManageSupplierEvaluate()}
|
||||
}
|
@ -20,6 +20,10 @@ type WorkRepairInfo struct {
|
||||
BreakdownTitle string `json:"breakdown_title"`
|
||||
}
|
||||
|
||||
type WorkRepairEvaluateInfo struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// Repairs 维修工单信息
|
||||
func (m *WorkRepair) Repairs(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*WorkRepairInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" r").
|
||||
|
@ -69,7 +69,6 @@ func (this *Router) registerAPI() {
|
||||
_api := new(api.Dashboard)
|
||||
dashboardV1.GET("/", _api.Index)
|
||||
dashboardV1.POST("/repair", _api.Repair)
|
||||
dashboardV1.GET("/score", _api.Score)
|
||||
}
|
||||
// Account 接口管理
|
||||
accountV1 := v1.Group("/account")
|
||||
|
@ -49,3 +49,24 @@ func ArrayStrings(src interface{}) []string {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
@ -38,3 +38,13 @@ func TestArrayStrings(t *testing.T) {
|
||||
t.Log(b)
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user