16 changed files with 758 additions and 24 deletions
@ -0,0 +1,171 @@ |
|||||
|
package maptostruct |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
"key_performance_indicators/models/modelsstorage" |
||||
|
"key_performance_indicators/overall" |
||||
|
"key_performance_indicators/overall/publicmethod" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2022-11-14 16:43:22 |
||||
|
@ 功能: 实验仓储类型树 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) CangChuThree(c *gin.Context) { |
||||
|
var mType []modelsstorage.MaterialType |
||||
|
overall.CONSTANT_DB_Storage.Where("`state` = 1").Find(&mType) |
||||
|
var toalVal int64 |
||||
|
// overall.CONSTANT_DB_Storage.Model(&modelsstorage.Material{}).Where("`state` = 1").Count(&toalVal)
|
||||
|
// var materList []modelsstorage.Material
|
||||
|
// err = overall.CONSTANT_DB_Storage.Find(&materList).Error
|
||||
|
// var jibuq []int
|
||||
|
// toalVal := 0
|
||||
|
var mTypeGroup []modelsstorage.MaterialType |
||||
|
var mttt readDataLock |
||||
|
for i, v := range mType { |
||||
|
|
||||
|
if (i+1)%100 == 0 { |
||||
|
syncSeting.Add(1) |
||||
|
mTypeGroup = append(mTypeGroup, v) |
||||
|
go mttt.chuLiType(mTypeGroup, toalVal) |
||||
|
mTypeGroup = []modelsstorage.MaterialType{} |
||||
|
} else { |
||||
|
mTypeGroup = append(mTypeGroup, v) |
||||
|
} |
||||
|
// if i == 0 {
|
||||
|
// // syncSeting.Add(1)
|
||||
|
// mTypeGroup = append(mTypeGroup, v)
|
||||
|
// // go mttt.chuLiType(mTypeGroup, toalVal)
|
||||
|
// }
|
||||
|
} |
||||
|
if len(mTypeGroup) > 0 { |
||||
|
syncSeting.Add(1) |
||||
|
go mttt.chuLiType(mTypeGroup, toalVal) |
||||
|
} |
||||
|
syncSeting.Wait() |
||||
|
|
||||
|
// fmt.Printf("%v", mttt)
|
||||
|
|
||||
|
var chanzongshu int |
||||
|
chanzongshu = 0 |
||||
|
for _, vvv := range mttt.MaterialAry { |
||||
|
chanzongshu = chanzongshu + len(vvv.MaterialList) |
||||
|
fmt.Printf("%v------>%v------>%v\n", vvv.Id, vvv.Name, len(vvv.MaterialList)) |
||||
|
} |
||||
|
|
||||
|
threeList := GetMenuThreePeiQuan(0, mttt.MaterialAry) |
||||
|
|
||||
|
outData := publicmethod.MapOut[string]() |
||||
|
outData["mttt_count"] = len(mttt.MaterialAry) |
||||
|
outData["chanzongshu"] = chanzongshu |
||||
|
// outData["mtttList"] = mttt.MaterialAry
|
||||
|
outData["threeList"] = threeList |
||||
|
fmt.Printf("%v------>%v------>%v------>%v\n", len(mType), toalVal, toalVal/1000, toalVal%1000) |
||||
|
publicmethod.Result(0, outData, c) |
||||
|
} |
||||
|
|
||||
|
// 多类别数据处理
|
||||
|
func (m *readDataLock) chuLiType(mType []modelsstorage.MaterialType, toalVal int64) { |
||||
|
defer syncSeting.Done() |
||||
|
var idList []int64 |
||||
|
for _, v := range mType { |
||||
|
idList = append(idList, v.OrderId) |
||||
|
} |
||||
|
|
||||
|
pageSum := toalVal / 1000 |
||||
|
if toalVal%1000 > 0 { |
||||
|
pageSum = pageSum + 1 |
||||
|
} |
||||
|
var i int64 |
||||
|
for i = 1; i <= pageSum; i++ { |
||||
|
// pageSize := publicmethod.LimitPage64(i, 1000)
|
||||
|
// fmt.Printf("第%v页,结束点%v\n", i, pageSize)
|
||||
|
// syncSetings.Add(1)
|
||||
|
// go m.Xiecheng(idList, pageSize, mType)
|
||||
|
} |
||||
|
pageSize := publicmethod.LimitPage64(i, 1000) |
||||
|
syncSetings.Add(1) |
||||
|
go m.Xiecheng(idList, pageSize, mType) |
||||
|
syncSetings.Wait() |
||||
|
// fmt.Println("--------------------------------")
|
||||
|
} |
||||
|
|
||||
|
func (m *readDataLock) Xiecheng(id []int64, pageSize int64, mType []modelsstorage.MaterialType) { |
||||
|
defer syncSetings.Done() |
||||
|
// pageSizeStr := strconv.FormatInt(pageSize, 10)
|
||||
|
// pageSizeInt, _ := strconv.Atoi(pageSizeStr)
|
||||
|
var materList []modelsstorage.Material |
||||
|
// overall.CONSTANT_DB_Storage.Where("`type_id` IN ? AND `state` = 1", id).Limit(1000).Offset(pageSizeInt).Find(&materList)
|
||||
|
overall.CONSTANT_DB_Storage.Where("`type_id` IN ? AND `state` = 1", id).Find(&materList) |
||||
|
for _, v := range mType { |
||||
|
var materialCont MaterialCont |
||||
|
materialCont.Id = v.Id //
|
||||
|
materialCont.Name = v.Name // 类型名称"`
|
||||
|
materialCont.Introduce = v.Introduce // 类型介绍"`
|
||||
|
materialCont.State = v.State //状态(启用2禁用3删除4不对其做任何操作)"`
|
||||
|
materialCont.ParentId = v.ParentId //父级"`
|
||||
|
materialCont.OrderId = v.OrderId //导入时id"`
|
||||
|
for _, mv := range materList { |
||||
|
if v.OrderId == mv.TypeId { |
||||
|
var materialcont modelsstorage.Material |
||||
|
|
||||
|
materialcont.Id = mv.Id // `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;index"`
|
||||
|
materialcont.DepositoryId = mv.DepositoryId // `json:"depositoryid" gorm:"column:depository_id;type:bigint(20) unsigned;default:0;not null;comment:仓库编号"`
|
||||
|
materialcont.Name = mv.Name // `json:"name" gorm:"column:mname;type:varchar(100);comment:材料名称"`
|
||||
|
materialcont.Quantity = mv.Quantity // `json:"quantity" gorm:"column:type;quantity:int(11) unsigned;default:1;not null;comment:数量"`
|
||||
|
materialcont.Amounts = mv.Amounts // `json:"amounts" gorm:"column:amounts;type:int(11) unsigned;default:1;not null;comment:总金额"`
|
||||
|
materialcont.TypeId = mv.TypeId // `json:"typeid" gorm:"column:type_id;type:bigint(20) unsigned;default:0;not null;comment:材料种类id"`
|
||||
|
materialcont.State = mv.State // `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"`
|
||||
|
materialcont.Code = mv.Code // `json:"code" gorm:"column:code;type:varchar(255);comment:存货编码"`
|
||||
|
materialcont.Version = mv.Version // `json:"version" gorm:"column:version;type:varchar(255);comment:规格型号"`
|
||||
|
materialcont.Price = mv.Price // `json:"price" gorm:"column:price;type:int(11) unsigned;default:1;not null;comment:单价"`
|
||||
|
materialcont.Unit = mv.Unit // `json:"unit" gorm:"column:unit;type:varchar(255);comment:计量单位"`
|
||||
|
materialcont.Texture = mv.Texture // `json:"texture" gorm:"column:texture;type:varchar(255);comment:材质"`
|
||||
|
materialcont.DepositoryCode = mv.DepositoryCode // `json:"depositoryCode" gorm:"column:depositoryCode;type:varchar(255);comment:货位码(存放位置)"`
|
||||
|
materialcont.Kingdeecode = mv.Kingdeecode // `json:"kingdeecode" gorm:"column:kingdeecode;type:varchar(255);comment:计量单位"`
|
||||
|
materialcont.NumberOfTemporary = mv.NumberOfTemporary // `json:"numberoftemporary" gorm:"column:number_of_temporary;type:int(11) unsigned;default:1;not null;comment:临时数目(临时出库数目)"`
|
||||
|
|
||||
|
materialCont.MaterialList = append(materialCont.MaterialList, materialcont) |
||||
|
} |
||||
|
} |
||||
|
m.MaterialAry = append(m.MaterialAry, materialCont) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 递归无限极菜单树
|
||||
|
/* |
||||
|
|
||||
|
@parentId 上级ID |
||||
|
@threeData 结果值 |
||||
|
|
||||
|
*/ |
||||
|
func GetMenuThreePeiQuan(parentId int64, threeData []MaterialCont) []CaiDanShu { |
||||
|
treeList := []CaiDanShu{} |
||||
|
for _, v := range threeData { |
||||
|
if v.ParentId == parentId { |
||||
|
child := GetMenuThreePeiQuan(v.OrderId, threeData) |
||||
|
var node CaiDanShu |
||||
|
node.Id = v.Id //
|
||||
|
node.Name = v.Name // 类型名称"`
|
||||
|
node.Introduce = v.Introduce // 类型介绍"`
|
||||
|
node.State = v.State //状态(启用2禁用3删除4不对其做任何操作)"`
|
||||
|
node.ParentId = v.ParentId //父级"`
|
||||
|
node.OrderId = v.OrderId //导入时id"`
|
||||
|
node.MaterialList = v.MaterialList |
||||
|
node.Child = child |
||||
|
treeList = append(treeList, node) |
||||
|
} |
||||
|
} |
||||
|
return treeList |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
package modelsstorage |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
// 仓储系统菜单管理
|
||||
|
type Material struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;index"` |
||||
|
DepositoryId int64 `json:"depositoryid" gorm:"column:depository_id;type:bigint(20) unsigned;default:0;not null;comment:仓库编号"` |
||||
|
Name string `json:"name" gorm:"column:mname;type:varchar(100);comment:材料名称"` |
||||
|
Quantity int `json:"quantity" gorm:"column:type;quantity:int(11) unsigned;default:1;not null;comment:数量"` |
||||
|
Amounts int `json:"amounts" gorm:"column:amounts;type:int(11) unsigned;default:1;not null;comment:总金额"` |
||||
|
TypeId int64 `json:"typeid" gorm:"column:type_id;type:bigint(20) unsigned;default:0;not null;comment:材料种类id"` |
||||
|
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
||||
|
Code string `json:"code" gorm:"column:code;type:varchar(255);comment:存货编码"` |
||||
|
Version string `json:"version" gorm:"column:version;type:varchar(255);comment:规格型号"` |
||||
|
Price int `json:"price" gorm:"column:price;type:int(11) unsigned;default:1;not null;comment:单价"` |
||||
|
Unit string `json:"unit" gorm:"column:unit;type:varchar(255);comment:计量单位"` |
||||
|
Texture string `json:"texture" gorm:"column:texture;type:varchar(255);comment:材质"` |
||||
|
DepositoryCode string `json:"depositoryCode" gorm:"column:depositoryCode;type:varchar(255);comment:货位码(存放位置)"` |
||||
|
Kingdeecode string `json:"kingdeecode" gorm:"column:kingdeecode;type:varchar(255);comment:计量单位"` |
||||
|
NumberOfTemporary int `json:"numberoftemporary" gorm:"column:number_of_temporary;type:int(11) unsigned;default:1;not null;comment:临时数目(临时出库数目)"` |
||||
|
} |
||||
|
|
||||
|
func (Material *Material) TableName() string { |
||||
|
return "material" |
||||
|
} |
||||
|
|
||||
|
// 编辑内容
|
||||
|
func (cont *Material) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_Storage.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 获取内容
|
||||
|
func (cont *Material) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_Storage.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
gormDb = gormDb.Where(whereMap) |
||||
|
err = gormDb.First(&cont).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 根据条件获取总数
|
||||
|
func (cont *Material) CountCont(whereMap interface{}) (countId int64) { |
||||
|
overall.CONSTANT_DB_Storage.Model(&cont).Where(whereMap).Count(&countId) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 读取全部信息
|
||||
|
func (cont *Material) ContMap(whereMap interface{}, field ...string) (countAry []Material, err error) { |
||||
|
gormDb := overall.CONSTANT_DB_Storage.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
err = gormDb.Where(whereMap).Find(&countAry).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 删除内容
|
||||
|
func (cont *Material) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_Storage.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
@ -0,0 +1,61 @@ |
|||||
|
package modelsstorage |
||||
|
|
||||
|
import ( |
||||
|
"key_performance_indicators/overall" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
// 仓储系统菜单管理
|
||||
|
type MaterialType struct { |
||||
|
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;index"` |
||||
|
Name string `json:"name" gorm:"column:tname;type:varchar(255);comment:类型名称"` |
||||
|
Introduce string `json:"introduce" gorm:"column:introduce;type:varchar(255);comment:类型介绍"` |
||||
|
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(启用2禁用3删除4不对其做任何操作)"` |
||||
|
ParentId int64 `json:"parentId" gorm:"column:parentId;type:bigint(20) unsigned;default:0;not null;comment:父级"` |
||||
|
OrderId int64 `json:"orderid" gorm:"column:oldId;type:bigint(20) unsigned;default:0;not null;comment:导入时id"` |
||||
|
} |
||||
|
|
||||
|
func (MaterialType *MaterialType) TableName() string { |
||||
|
return "material_type" |
||||
|
} |
||||
|
|
||||
|
// 编辑内容
|
||||
|
func (cont *MaterialType) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_Storage.Model(&cont).Where(whereMap).Updates(saveData).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 获取内容
|
||||
|
func (cont *MaterialType) GetCont(whereMap interface{}, field ...string) (err error) { |
||||
|
gormDb := overall.CONSTANT_DB_Storage.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
gormDb = gormDb.Where(whereMap) |
||||
|
err = gormDb.First(&cont).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 根据条件获取总数
|
||||
|
func (cont *MaterialType) CountCont(whereMap interface{}) (countId int64) { |
||||
|
overall.CONSTANT_DB_Storage.Model(&cont).Where(whereMap).Count(&countId) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 读取全部信息
|
||||
|
func (cont *MaterialType) ContMap(whereMap interface{}, field ...string) (countAry []MaterialType, err error) { |
||||
|
gormDb := overall.CONSTANT_DB_Storage.Model(&cont) |
||||
|
if len(field) > 0 { |
||||
|
fieldStr := strings.Join(field, ",") |
||||
|
gormDb = gormDb.Select(fieldStr) |
||||
|
} |
||||
|
err = gormDb.Where(whereMap).Find(&countAry).Error |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// 删除内容
|
||||
|
func (cont *MaterialType) DelCont(whereMap interface{}) (err error) { |
||||
|
err = overall.CONSTANT_DB_Storage.Where(whereMap).Delete(&cont).Error |
||||
|
return |
||||
|
} |
||||
Loading…
Reference in new issue