feat:完善项目
This commit is contained in:
@ -93,7 +93,8 @@ func (this *workLaunchMaterialForm) SupplierInfo() uint64 {
|
||||
* @apiHeader {string} x-token token
|
||||
* @apiHeader {string} Content-Type=application/json 传输方式
|
||||
*
|
||||
* @apiParam {String} [material_id=0] 装备ID
|
||||
* @apiParam {String} [equipment_code="''"] 装备编码
|
||||
* @apiParam {String} [equipment_title="''"] 装备名称
|
||||
* @apiParam {String} [kind=0] 工单类型
|
||||
* @apiParam {Number} current 当前页
|
||||
* @apiParam {Number} page_size 页展示数
|
||||
@ -135,15 +136,16 @@ func (this *workLaunchMaterialForm) SupplierInfo() uint64 {
|
||||
*/
|
||||
func (*Work) Instance(c *gin.Context) {
|
||||
form := &struct {
|
||||
MaterialID uint64 `json:"material_id" form:"material_id"`
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
EquipmentCode string `json:"equipment_code" form:"equipment_code"`
|
||||
EquipmentTitle string `json:"equipment_title" form:"equipment_title"`
|
||||
Kind int `json:"kind" form:"kind"`
|
||||
PageForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := work.NewInstance()(getSession()(c).(*service.Session)).List(form.MaterialID, form.Kind, form.Page, form.PageSize)
|
||||
data, err := work.NewInstance()(getSession()(c).(*service.Session)).List(form.EquipmentCode, form.EquipmentTitle, form.Kind, form.Page, form.PageSize)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ func initModel() {
|
||||
&synchronized{iModel: model.NewManageMaterial()}, &synchronized{iModel: model.NewManageMaterialSupplier()},
|
||||
&synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()},
|
||||
&synchronized{iModel: model.NewWorkInstance()}, &synchronized{iModel: model.NewWorkMaterial()}, &synchronized{iModel: model.NewWorkProgress()},
|
||||
&synchronized{iModel: model.NewWorkSchedule()},
|
||||
&synchronized{iModel: model.NewWorkSchedule()}, &synchronized{iModel: model.NewWorkPurchase()},
|
||||
&synchronized{iModel: model.NewWorkRepair()}, &synchronized{iModel: model.NewWorkRepairDetail()},
|
||||
)
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
package model
|
||||
|
||||
// ManageMaterialWork 维修器材工单明细
|
||||
type ManageMaterialWork struct {
|
||||
Model
|
||||
WorkID uint64 `gorm:"column:work_id;type:int(11);default:0;comment:工单ID" json:"work_id"`
|
||||
MaterialPurchaseID uint64 `gorm:"column:material_purchase_id;type:int(11);default:0;comment:器材采购ID" json:"material_purchase_id"`
|
||||
Number int `json:"number"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *ManageMaterialWork) TableName() string {
|
||||
return "manage_material_work"
|
||||
}
|
||||
|
||||
func NewManageMaterialWork() *ManageMaterialWork {
|
||||
return &ManageMaterialWork{}
|
||||
}
|
@ -16,7 +16,8 @@ type (
|
||||
MaterialSupplerBasic struct {
|
||||
basic.CommonIDString
|
||||
*model.ManageMaterialSupplierBasic
|
||||
Stock float64 `json:"stock"`
|
||||
SupplierID string `json:"supplier_id"`
|
||||
Stock float64 `json:"stock"`
|
||||
}
|
||||
)
|
||||
|
||||
@ -45,6 +46,7 @@ func (c *MaterialSuppler) Select(materialID uint64) ([]*MaterialSupplerBasic, er
|
||||
list = append(list, &MaterialSupplerBasic{
|
||||
CommonIDString: basic.CommonIDString{ID: mManageMaterSupplier.GetEncodeID()},
|
||||
ManageMaterialSupplierBasic: v,
|
||||
SupplierID: (&model2.Model{ID: v.SupplierID}).GetEncodeID(),
|
||||
Stock: stock,
|
||||
})
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ type (
|
||||
} `json:"outside" form:"outside"`
|
||||
Within struct {
|
||||
Material []*model.WorkMaterialInfo `json:"material"`
|
||||
Purchase []*model.WorkPurchaseInfo `json:"purchase"`
|
||||
} `json:"within"`
|
||||
Distribution *model2.WorkInstanceDistribution `json:"distribution"`
|
||||
History []*model.WorkProgressInfo `json:"history"`
|
||||
@ -136,38 +137,63 @@ func (c *Instance) material(tx *gorm.DB, material []*InstanceLaunchParamsForMate
|
||||
}
|
||||
|
||||
/// purchase 采购操作
|
||||
func (c *Instance) purchase(tx *gorm.DB, purchase []*InstanceLaunchParamsForPurchase) error {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
func (c *Instance) purchase(tx *gorm.DB, purchase []*InstanceLaunchParamsForPurchase, workID uint64) error {
|
||||
//mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
|
||||
_purchase := make([]*model2.ManageMaterialPurchase, 0)
|
||||
//_purchase := make([]*model2.ManageMaterialPurchase, 0)
|
||||
|
||||
for _, v := range purchase {
|
||||
_purchase = append(_purchase, &model2.ManageMaterialPurchase{
|
||||
UID: c.UID,
|
||||
OrderNo: lib.OrderNo(),
|
||||
MaterialID: v.ID,
|
||||
SupplierID: v.SupplierID,
|
||||
Price: v.Price,
|
||||
Number: v.Number,
|
||||
Remark: "工单采购",
|
||||
})
|
||||
}
|
||||
if len(_purchase) > 0 {
|
||||
if err := model2.Creates(mManageMaterialPurchase.ManageMaterialPurchase, _purchase, tx); err != nil {
|
||||
mManageMaterialPurchase := model.NewManageMaterialPurchase()
|
||||
|
||||
mManageMaterialPurchase.UID = c.UID
|
||||
mManageMaterialPurchase.OrderNo = lib.OrderNo()
|
||||
mManageMaterialPurchase.MaterialID = v.ID
|
||||
mManageMaterialPurchase.SupplierID = v.SupplierID
|
||||
mManageMaterialPurchase.Price = v.Price
|
||||
mManageMaterialPurchase.Number = v.Number
|
||||
mManageMaterialPurchase.Remark = "工单采购"
|
||||
|
||||
err := model2.Create(mManageMaterialPurchase.ManageMaterialPurchase, tx)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mWorkPurchase := model.NewWorkPurchase()
|
||||
mWorkPurchase.WorkID = workID
|
||||
mWorkPurchase.MaterialPurchaseID = mManageMaterialPurchase.ID
|
||||
|
||||
if err = model2.Create(mWorkPurchase.WorkPurchase, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
//_purchase = append(_purchase, &model2.ManageMaterialPurchase{
|
||||
// UID: c.UID,
|
||||
// OrderNo: lib.OrderNo(),
|
||||
// MaterialID: v.ID,
|
||||
// SupplierID: v.SupplierID,
|
||||
// Price: v.Price,
|
||||
// Number: v.Number,
|
||||
// Remark: "工单采购",
|
||||
//})
|
||||
}
|
||||
//if len(_purchase) > 0 {
|
||||
// if err := model2.Creates(mManageMaterialPurchase.ManageMaterialPurchase, _purchase, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
return nil
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List(materialID uint64, kind, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
func (c *Instance) List(equipmentCode, equipmentTitle string, 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 equipmentCode != "" {
|
||||
where = append(where, model2.NewWhereLike("e.code", equipmentCode))
|
||||
}
|
||||
if equipmentTitle != "" {
|
||||
where = append(where, model2.NewWhereLike("e.title", equipmentTitle))
|
||||
}
|
||||
if kind > 0 {
|
||||
where = append(where, model2.NewWhere("w.kind", kind))
|
||||
@ -285,14 +311,22 @@ func (c *Instance) Detail(id uint64) (*InstanceDetailInfo, error) {
|
||||
out.Distribution = mWorkInstance.GetDistributionAttribute()
|
||||
// 内修才有数据
|
||||
if out.WorkInstanceInfo.Kind == model2.WorkInstanceKindForWithin {
|
||||
// 器材信息
|
||||
materials := make([]*model.WorkMaterialInfo, 0)
|
||||
|
||||
if materials, err = model.NewWorkMaterial().Materials(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 采购信息
|
||||
purchases := make([]*model.WorkPurchaseInfo, 0)
|
||||
|
||||
if purchases, err = model.NewWorkPurchase().Purchases(id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.Within = struct {
|
||||
Material []*model.WorkMaterialInfo `json:"material"`
|
||||
}{Material: materials}
|
||||
Purchase []*model.WorkPurchaseInfo `json:"purchase"`
|
||||
}{Material: materials, Purchase: purchases}
|
||||
} else if out.WorkInstanceInfo.Kind == model2.WorkInstanceKindForOutside {
|
||||
out.Outside = struct {
|
||||
SupplierName string `json:"supplier_name"`
|
||||
@ -388,7 +422,7 @@ func (c *Instance) Launch(params *InstanceLaunchParams) error {
|
||||
return err
|
||||
}
|
||||
// 采购信息
|
||||
if err = c.purchase(tx, params.Purchase); err != nil {
|
||||
if err = c.purchase(tx, params.Purchase, mWorkInstance.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -496,7 +530,7 @@ func (c *Instance) Examine(id uint64, status int, remark string, isAssist int, p
|
||||
return err
|
||||
}
|
||||
// 采购信息
|
||||
if err = c.purchase(tx, params.Purchase); err != nil {
|
||||
if err = c.purchase(tx, params.Purchase, id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,14 @@ type ManageMaterialSupplierBasic struct {
|
||||
ID uint64 `json:"-"`
|
||||
Stock float64 `json:"-"`
|
||||
FrozenStock float64 `json:"-"`
|
||||
SupplierID uint64 `json:"-"`
|
||||
SupplierName string `json:"supplier_name"`
|
||||
}
|
||||
|
||||
// Basic 基本信息
|
||||
func (m *ManageMaterialSupplier) Basic(where ...*model.ModelWhere) ([]*ManageMaterialSupplierBasic, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" m_s").
|
||||
Select("m_s.id", "m_s.stock", "m_s.frozen_stock", "s.name AS supplier_name").
|
||||
Select("m_s.id", "m_s.stock", "m_s.frozen_stock", "s.id AS supplier_id", "s.name AS supplier_name").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_s.supplier_id = s.id", model.NewManageSupplier().TableName())).
|
||||
Where("m_s.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
|
46
app/model/work_purchase.go
Normal file
46
app/model/work_purchase.go
Normal file
@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type WorkPurchase struct {
|
||||
*model.WorkPurchase
|
||||
}
|
||||
|
||||
type WorkPurchaseInfo struct {
|
||||
*model.WorkPurchase
|
||||
Price float64 `json:"price"`
|
||||
Number float64 `json:"number"`
|
||||
MaterialCode string `json:"material_code"`
|
||||
MaterialTitle string `json:"material_title"`
|
||||
ManufacturerName string `json:"manufacturer_name"`
|
||||
SupplierName string `json:"supplier_name"`
|
||||
}
|
||||
|
||||
// Purchases 采购信息
|
||||
func (m *WorkPurchase) Purchases(workID uint64) ([]*WorkPurchaseInfo, error) {
|
||||
mManageSupplier := model.NewManageSupplier()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS p").
|
||||
Select("p.id", "m_p.price", "m_p.number", "m.code AS material_code", "m.title AS material_title",
|
||||
"m_s.name AS manufacturer_name", "s.name AS supplier_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m_p ON p.material_purchase_id = m_p.id", model.NewManageMaterialPurchase().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m ON m_p.material_id = m.id", model.NewManageMaterial().TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS s ON m_p.supplier_id = s.id", mManageSupplier.TableName())).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS m_s ON m.manufacturer_id = m_s.id", mManageSupplier.TableName())).
|
||||
Where("p.work_id = ?", workID).
|
||||
Where("p.is_deleted = ? AND m_p.is_deleted = ?", model.DeleteStatusForNot, model.DeleteStatusForNot)
|
||||
|
||||
out := make([]*WorkPurchaseInfo, 0)
|
||||
|
||||
err := db.Scan(&out).Error
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func NewWorkPurchase() *WorkPurchase {
|
||||
return &WorkPurchase{model.NewWorkPurchase()}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package task
|
||||
|
||||
func Init() {
|
||||
NewTaskListen().Listen()
|
||||
//NewTaskListen().Listen()
|
||||
|
||||
//NewTask()("order", 60, NewOrder()).Push()
|
||||
|
||||
NewTaskQueue().Queue()
|
||||
//NewTask()("order", 10, NewOrder()).Push()
|
||||
}
|
||||
|
@ -7,11 +7,13 @@ import (
|
||||
"ArmedPolice/utils"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TaskListen struct {
|
||||
Produce chan *Task
|
||||
Consume chan *Task
|
||||
ticker *time.Ticker
|
||||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
@ -35,12 +37,29 @@ func (this *TaskListen) Listen() {
|
||||
if err != nil {
|
||||
fmt.Printf("Task Produce Redis Sadd Error【%s】", err)
|
||||
} else {
|
||||
err = cache.Cache.HSet(config.RedisKeyForTaskQueueBody, p.ID, p)
|
||||
fmt.Printf("err:%v\n", err)
|
||||
_ = cache.Cache.HSet(config.RedisKeyForTaskQueueBody, p.ID, p)
|
||||
}
|
||||
case c := <-this.Consume:
|
||||
if err := c.Handle(); err != nil {
|
||||
fmt.Printf("err:%v\n", err)
|
||||
// 监听到数据,执行后续操作
|
||||
_ = c.Handle()
|
||||
case <-this.ticker.C:
|
||||
now := time.Now()
|
||||
|
||||
_cache, _ := cache.Cache.ZRangebyscore(config.RedisKeyForTaskQueue, &logic.ScoreRangeBy{Min: "0",
|
||||
Max: fmt.Sprintf("%d", now.Unix())})
|
||||
|
||||
if len(_cache) > 0 {
|
||||
for _, v := range _cache {
|
||||
body, _ := cache.Cache.HGet(config.RedisKeyForTaskQueueBody, v)
|
||||
// TODO:有Bug,读取接口数据为空
|
||||
task := new(Task)
|
||||
task.Body = new(Order)
|
||||
_ = task.UnmarshalBinary([]byte(body))
|
||||
task.Consume()
|
||||
}
|
||||
// 销毁信息
|
||||
_ = cache.Cache.ZRem(config.RedisKeyForTaskQueue, _cache)
|
||||
_ = cache.Cache.HDel(config.RedisKeyForTaskQueueBody, _cache...)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -48,12 +67,11 @@ func (this *TaskListen) Listen() {
|
||||
}
|
||||
|
||||
func NewTaskListen() *TaskListen {
|
||||
if TaskListenEvent == nil {
|
||||
TaskListenEvent = &TaskListen{
|
||||
Produce: make(chan *Task, 1),
|
||||
Consume: make(chan *Task, 1),
|
||||
lock: new(sync.Mutex),
|
||||
}
|
||||
TaskListenEvent = &TaskListen{
|
||||
Produce: make(chan *Task, 1),
|
||||
Consume: make(chan *Task, 1),
|
||||
ticker: time.NewTicker(time.Second * 1),
|
||||
lock: new(sync.Mutex),
|
||||
}
|
||||
return TaskListenEvent
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package task
|
||||
import (
|
||||
"ArmedPolice/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Order struct {
|
||||
@ -19,6 +20,8 @@ func (this *Order) UnmarshalBinary(data []byte) error {
|
||||
}
|
||||
|
||||
func (this *Order) Handle() error {
|
||||
fmt.Println(this.ID)
|
||||
fmt.Println(this.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,7 @@ func (this *Task) Consume() {
|
||||
|
||||
func (this *Task) Handle() error {
|
||||
// 处理各种方法
|
||||
this.Body.(*Order).Handle()
|
||||
return nil
|
||||
return this.Body.Handle()
|
||||
}
|
||||
|
||||
func NewTask() TaskHandle {
|
||||
|
@ -4,6 +4,6 @@ import "testing"
|
||||
|
||||
func TestSha256String(t *testing.T) {
|
||||
//t.Log(Md5String("9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05"))
|
||||
t.Log(HASHIDEncode(12))
|
||||
t.Log(HASHIDDecode("d3rJnGwE9o"))
|
||||
t.Log(HASHIDEncode(35))
|
||||
t.Log(HASHIDDecode("EgmJ4Ga7LQ"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user