feat(mes): 添加定时同步可生产数量到WMS及BOM项相关标准字段
- 在main.go中添加定时任务每10分钟同步可生产数量到WMS系统 - 为BomItem实体添加relatedStandard字段及相关CRUD方法 - 为InspectionRecord实体添加reportNo、materialCode、materialName等字段 - 更新ent schema确保新字段的验证和默认值设置 - 添加必要的数据库迁移和字段映射逻辑
This commit is contained in:
@@ -30,16 +30,20 @@ func createZoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
exists, err := ctx.EntClient.Zone.Query().
|
||||
// 货位唯一性(U18):按四级组合(区域+货架+层+位置)判重,与 DB 组合唯一索引 ux_zones_location 一致。
|
||||
// zone_code 不再单列唯一——同一区域下可登记多个货位(NULL/空串归一为""比较,与 COALESCE 索引一致)。
|
||||
sameZone, err := ctx.EntClient.Zone.Query().
|
||||
Where(zone.ZoneCodeEQ(req.ZoneCode)).
|
||||
Exist(ctx0())
|
||||
All(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if exists {
|
||||
fail(w, http.StatusConflict, "区域编码已存在")
|
||||
return
|
||||
for _, sz := range sameZone {
|
||||
if sz.ShelfNo == req.ShelfNo && sz.LayerNo == req.LayerNo && sz.PositionNo == req.PositionNo {
|
||||
fail(w, http.StatusConflict, locDupMsg(req.ZoneCode, req.ShelfNo, req.LayerNo, req.PositionNo))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
z, err := ctx.EntClient.Zone.Create().
|
||||
@@ -81,6 +85,21 @@ func updateZoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "区域名称必填")
|
||||
return
|
||||
}
|
||||
// 货位唯一性(排除自身,U18):改后四级组合不得与其他货位重复(DB 组合唯一索引兜底)。
|
||||
if req.ZoneCode != "" {
|
||||
others, e := ctx.EntClient.Zone.Query().
|
||||
Where(zone.ZoneCodeEQ(req.ZoneCode), zone.IDNEQ(req.ID)).All(ctx0())
|
||||
if e != nil {
|
||||
fail(w, http.StatusInternalServerError, e.Error())
|
||||
return
|
||||
}
|
||||
for _, oz := range others {
|
||||
if oz.ShelfNo == req.ShelfNo && oz.LayerNo == req.LayerNo && oz.PositionNo == req.PositionNo {
|
||||
fail(w, http.StatusConflict, locDupMsg(req.ZoneCode, req.ShelfNo, req.LayerNo, req.PositionNo))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
upd := ctx.EntClient.Zone.UpdateOneID(req.ID).SetZoneName(req.ZoneName)
|
||||
if req.ZoneCode != "" {
|
||||
upd.SetZoneCode(req.ZoneCode)
|
||||
@@ -168,3 +187,8 @@ func listZonesForPicker(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
ok(w, list)
|
||||
}
|
||||
}
|
||||
|
||||
// locDupMsg 货位重复登记的统一提示(复用 locLabel 拼四级货位串,U18)。
|
||||
func locDupMsg(zoneCode, shelfNo, layerNo, positionNo string) string {
|
||||
return "该货位已存在:" + locLabel(zoneCode, shelfNo, layerNo, positionNo)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user