From 6a008202edfbb92ee30a1eaa3eec0eb92aca79f1 Mon Sep 17 00:00:00 2001 From: louwenzhi Date: Mon, 22 Nov 2021 15:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E4=BF=AE=E9=80=BB=E8=BE=91=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=8A=E5=85=B6=E8=87=AA=E5=8A=A8=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/qm/ReclinerReclst.dao.go | 63 ++++ dao/qm/implments/ReclinerReclst.dao.impl.go | 52 ++++ main.go | 2 + meta/qm/ReclinerReclst.meta.go | 4 +- models/base/Const.go | 3 + models/qm/ReclinerReclst.model.go | 1 + models/qm/qm.go | 6 + .../log/implments/PackOrder.service.impl.go | 74 +++-- services/qm/ReclinerReclst.service.go | 102 +++++++ .../implments/ReclinerReclst.service.impl.go | 271 +++++++++++++++++- task/printer.go | 61 ++++ web/controllers/qm/ReclinerReclst.rest.go | 115 ++++++++ web/controllers/qm/qm.go | 3 + 13 files changed, 728 insertions(+), 29 deletions(-) create mode 100644 models/qm/qm.go diff --git a/dao/qm/ReclinerReclst.dao.go b/dao/qm/ReclinerReclst.dao.go index 400c35c..e9009eb 100644 --- a/dao/qm/ReclinerReclst.dao.go +++ b/dao/qm/ReclinerReclst.dao.go @@ -79,6 +79,27 @@ type ReclinerReclstDAO interface { * ******************************************************************************/ SelectOne(int) (*model.ReclinerReclst, error) + /****************************************************************************** + * + * @Function Name : SelectSeriOne + *----------------------------------------------------------------------------- + * + * @Description : 查找指定键的ReclinerReclst + * + * @Function Parameters : 主键 + * + * @Function Parameters : 主键 + * + * @Return Value : 查找到的ReclinerReclst + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-07-12 14:05:20 + * + ******************************************************************************/ + SelectSeriOne(string) (*model.ReclinerReclst, error) /****************************************************************************** * * @Function Name : UpdateOne @@ -221,6 +242,48 @@ type ReclinerReclstDAO interface { * ******************************************************************************/ UpdateWhere([]grmi.Predicate, *model.ReclinerReclst, ...string) error + /****************************************************************************** + * + * @Function Name : SelectUnPrint + *----------------------------------------------------------------------------- + * + * @Description : 按条件查询PackOrder + * + * @Function Parameters : 查询条件 + * + * @Function Parameters : 排序字段 + * + * @Return Value : 查询结果 + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-03-24 09:53:49 + * + ******************************************************************************/ + SelectUnPrint(num int) ([]model.ReclinerReclst, error) + /****************************************************************************** + * + * @Function Name : UpdateUnPrint + *----------------------------------------------------------------------------- + * + * @Description : 批量更新PackOrder + * + * @Function Parameters : 查询条件 + * + * @Function Parameters : 排序字段 + * + * @Return Value : 查询结果 + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-03-24 09:53:49 + * + ******************************************************************************/ + UpdateUnPrint(recIds []int) error } /****************************************************************************** diff --git a/dao/qm/implments/ReclinerReclst.dao.impl.go b/dao/qm/implments/ReclinerReclst.dao.impl.go index bcb70b7..202c23c 100644 --- a/dao/qm/implments/ReclinerReclst.dao.impl.go +++ b/dao/qm/implments/ReclinerReclst.dao.impl.go @@ -5,6 +5,7 @@ package implments import ( "LAPP_GAAS_GFrame_BACKEND/grmi" meta "LAPP_GAAS_GFrame_BACKEND/meta/qm" + common "LAPP_GAAS_GFrame_BACKEND/models/base" model "LAPP_GAAS_GFrame_BACKEND/models/qm" "fmt" "github.com/go-xorm/xorm" @@ -98,6 +99,23 @@ func (impl *ReclinerReclstDAOImplement) SelectOne(recNr int) (*model.ReclinerRec return &data, nil } +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/dao/qm/ReclinerReclstDAO.SelectOne + * + ******************************************************************************/ +func (impl *ReclinerReclstDAOImplement) SelectSeriOne(orderId string) (*model.ReclinerReclst, error) { + var data model.ReclinerReclst + ok, err := impl.session.Table(impl.meta.TableName).Where("PlantNr = ? and SerialOrderId = ? and RecType = ?",impl.plantNr, orderId,model.QM_SERI_TYPE).Get(&data) + if err != nil { + return nil, grmi.NewDataBaseError(err) + } + if !ok { + return nil, nil + } + return &data, nil +} + /****************************************************************************** * * @Reference LAPP_GAAS_GFrame_BACKEND/dao/qm/ReclinerReclstDAO.UpdateOne @@ -300,3 +318,37 @@ func (impl *ReclinerReclstDAOImplement) UpdateWhere(predicates []grmi.Predicate, } return nil } + + +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/dao/log/PackOrderDAO.SelectUnPrint + * + ******************************************************************************/ +func (impl *ReclinerReclstDAOImplement) SelectUnPrint(num int) ([]model.ReclinerReclst, error) { + + session := impl.session.Table(impl.meta.TableName).Where("PlantNr = ? and Status = ?", impl.plantNr, 0, common.UN_PRINT).Asc("RecNr") + + data := make([]model.ReclinerReclst, 0) + err := session.Limit(num).Find(&data) + if err != nil { + return nil, grmi.NewDataBaseError(err) + } + return data, nil +} + +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/dao/log/PackOrderDAO.UpdateUnPrint + * + ******************************************************************************/ +func (impl *ReclinerReclstDAOImplement) UpdateUnPrint(recIds []int) error { + entity := new(model.ReclinerReclst) + entity.Status = common.PRINT + session := impl.session.Table(impl.meta.TableName).Select("Status").In("RecNr", recIds).Where("PlantNr = ? and Status = ?", impl.plantNr, common.UN_PRINT) + _, err := session.Update(entity) + if err != nil { + return grmi.NewDataBaseError(err) + } + return nil +} \ No newline at end of file diff --git a/main.go b/main.go index 278f564..a4cd1fe 100644 --- a/main.go +++ b/main.go @@ -134,6 +134,8 @@ func imain() { //开启生成打印包装消息 go task.CreatePackPrintTask() + //返修打印 + go task.CreateRecPrintTask() //启动监听端口 app.Run(iris.Addr(":8093"), iris.WithConfiguration(conf.C)) diff --git a/meta/qm/ReclinerReclst.meta.go b/meta/qm/ReclinerReclst.meta.go index 8365ac4..2ff1bb6 100644 --- a/meta/qm/ReclinerReclst.meta.go +++ b/meta/qm/ReclinerReclst.meta.go @@ -18,6 +18,7 @@ import ( ******************************************************************************/ var ReclinerReclst_PlantNr = grmi.NewField("PlantNr", "QM_ReclinerReclst.PlantNr", "plantnr", grmi.TypeInt) var ReclinerReclst_RecNr = grmi.NewField("RecNr", "QM_ReclinerReclst.RecNr", "recnr", grmi.TypeInt) +var ReclinerReclst_RecType = grmi.NewField("RecType", "QM_ReclinerReclst.RecType", "RecType", grmi.TypeString) var ReclinerReclst_Line = grmi.NewField("Line", "QM_ReclinerReclst.Line", "line", grmi.TypeString) var ReclinerReclst_ArtId = grmi.NewField("ArtId", "QM_ReclinerReclst.ArtId", "artid", grmi.TypeString) var ReclinerReclst_SerialOrderId = grmi.NewField("SerialOrderId", "QM_ReclinerReclst.SerialOrderId", "serialorderid", grmi.TypeString) @@ -43,6 +44,7 @@ var ReclinerReclst = grmi.NewEntity( map[string]grmi.Field{ ReclinerReclst_PlantNr.Name: ReclinerReclst_PlantNr, ReclinerReclst_RecNr.Name: ReclinerReclst_RecNr, + ReclinerReclst_RecType.Name: ReclinerReclst_RecType, ReclinerReclst_Line.Name: ReclinerReclst_Line, ReclinerReclst_ArtId.Name: ReclinerReclst_ArtId, ReclinerReclst_SerialOrderId.Name: ReclinerReclst_SerialOrderId, @@ -54,4 +56,4 @@ var ReclinerReclst = grmi.NewEntity( ReclinerReclst_CreateTime.Name: ReclinerReclst_CreateTime, }, []string{"PlantNr"}, - []string{"ArtId", "SerialOrderId", "ReclinerNr", "ItemPartNr", "Status", "LastUser"}) + []string{"ArtId", "RecType", "SerialOrderId", "ReclinerNr", "ItemPartNr", "Status", "LastUser"}) diff --git a/models/base/Const.go b/models/base/Const.go index 0ba9de5..848f46a 100644 --- a/models/base/Const.go +++ b/models/base/Const.go @@ -118,4 +118,7 @@ const ( ART_SPEC_FG = "FG" PRINT_BUSINESS_OBJ_TYPE_PACK = "PACK" + + UN_PRINT = "N" + PRINT = "C" ) diff --git a/models/qm/ReclinerReclst.model.go b/models/qm/ReclinerReclst.model.go index e54c85c..4c89ae1 100644 --- a/models/qm/ReclinerReclst.model.go +++ b/models/qm/ReclinerReclst.model.go @@ -22,6 +22,7 @@ import ( type ReclinerReclst struct { PlantNr int `xorm:"pk int 'PlantNr'" json:"QM_ReclinerReclst-PlantNr"` RecNr int `xorm:"pk int 'RecNr' autoincr" json:"QM_ReclinerReclst-RecNr"` + RecType string `xorm:"nvarchar(16) 'RecType'" json:"QM_ReclinerReclst-RecType"` Line string `xorm:"nvarchar(16) 'Line'" json:"QM_ReclinerReclst-Line"` ArtId string `xorm:"nvarchar(64) 'ArtId'" json:"QM_ReclinerReclst-ArtId"` SerialOrderId string `xorm:"nvarchar(100) 'SerialOrderId'" json:"QM_ReclinerReclst-SerialOrderId"` diff --git a/models/qm/qm.go b/models/qm/qm.go new file mode 100644 index 0000000..7535467 --- /dev/null +++ b/models/qm/qm.go @@ -0,0 +1,6 @@ +package qm + +const ( + QM_REC_TYPE = "REC" + QM_SERI_TYPE = "SERI" +) diff --git a/services/log/implments/PackOrder.service.impl.go b/services/log/implments/PackOrder.service.impl.go index 30824cf..e0c7eae 100644 --- a/services/log/implments/PackOrder.service.impl.go +++ b/services/log/implments/PackOrder.service.impl.go @@ -7,6 +7,7 @@ import ( "LAPP_GAAS_GFrame_BACKEND/dao/api" "LAPP_GAAS_GFrame_BACKEND/dao/base" basedal "LAPP_GAAS_GFrame_BACKEND/dao/base" + qmdal "LAPP_GAAS_GFrame_BACKEND/dao/qm" omdal "LAPP_GAAS_GFrame_BACKEND/dao/om" jitdal "LAPP_GAAS_GFrame_BACKEND/dao/jit" bmeta "LAPP_GAAS_GFrame_BACKEND/meta/base" @@ -713,21 +714,29 @@ func (self *PackOrderServiceImplement) IsCreatePackOrder(user *models.Usertab, o defer slavesession.Close() apiDao := api.NewACCUNITSTATUSDAO(slavesession, user.Userid) - //根据唯一码查询信息 - mesData, err := apiDao.SelectInfo(orderId) + //查询条码是否返工 + recDao := qmdal.NewReclinerReclstDAO(session, user.Pid, user.Userid) + recInfo, err := recDao.SelectSeriOne(orderId) if err != nil { return nil, err } - if mesData == nil { - return nil, grmi.NewBusinessError("该唯一码不存在!") - } - if mesData.LINE == "G-Frame Assy" { - //校验 - if mesData.OP != "017" { - return nil, grmi.NewBusinessError("上一工序未完成!") + if recInfo == nil{ + //根据唯一码查询信息 + mesData, err := apiDao.SelectInfo(orderId) + if err != nil { + return nil, err } - if mesData.STATUS != "2" { - return nil, grmi.NewBusinessError("上一工序未完成!") + if mesData == nil { + return nil, grmi.NewBusinessError("该唯一码不存在!") + } + if mesData.LINE == "G-Frame Assy" { + //校验 + if mesData.OP != "017" { + return nil, grmi.NewBusinessError("上一工序未完成!") + } + if mesData.STATUS != "2" { + return nil, grmi.NewBusinessError("上一工序未完成!") + } } } @@ -854,8 +863,10 @@ func (self *PackOrderServiceImplement) IsCreatePackOrder(user *models.Usertab, o PackOrderItemlst.SerialOrderId = orderId PackOrderItemlst.ActQty = 1 PackOrderItemlst.Status = bmodel.PACK_STATUS_RUNNING - - columns := []string{"SerialOrderId", "Status", "ActQty"} + if recInfo !=nil{ + PackOrderItemlst.PKOICustC1 = recInfo.ReclinerNr + } + columns := []string{"SerialOrderId", "Status", "ActQty","PKOICustC1"} err = dao.UpdateWhere([]grmi.Predicate{ meta.PackOrderItemlst_PlantNr.NewPredicate(grmi.Equal, user.Pid), meta.PackOrderItemlst_PackOrderId.NewPredicate(grmi.Equal, packOrderId), @@ -905,7 +916,6 @@ func (self *PackOrderServiceImplement) IsCreatePackOrder(user *models.Usertab, o Itemlst.PlantNr = user.Pid Itemlst.PackOrderId = packOrderId Itemlst.Status = bmodel.PACK_STATUS_CLOSED - columns := []string{"Status"} err = dao.UpdateWhere([]grmi.Predicate{ meta.PackOrderItemlst_PlantNr.NewPredicate(grmi.Equal, user.Pid), @@ -1185,21 +1195,29 @@ func (self *PackOrderServiceImplement) CheckPackOrderItem(user *models.Usertab, defer slavesession.Close() apiDao := api.NewACCUNITSTATUSDAO(slavesession, user.Userid) - //根据唯一码查询信息 - mesData, err := apiDao.SelectInfo(orderId) + //查询条码是否返工 + recDao := qmdal.NewReclinerReclstDAO(session, user.Pid, user.Userid) + recInfo, err := recDao.SelectSeriOne(orderId) if err != nil { return "", err } - if mesData == nil { - return "", grmi.NewBusinessError("该唯一码不存在!") - } - if mesData.LINE == "G-Frame Assy" { - //校验 - if mesData.OP != "017" { - return "", grmi.NewBusinessError("上一工序未完成!") + if recInfo == nil{ + //根据唯一码查询信息 + mesData, err := apiDao.SelectInfo(orderId) + if err != nil { + return "", err + } + if mesData == nil { + return "", grmi.NewBusinessError("该唯一码不存在!") } - if mesData.STATUS != "2" { - return "", grmi.NewBusinessError("上一工序未完成!") + if mesData.LINE == "G-Frame Assy" { + //校验 + if mesData.OP != "017" { + return "", grmi.NewBusinessError("上一工序未完成!") + } + if mesData.STATUS != "2" { + return "", grmi.NewBusinessError("上一工序未完成!") + } } } articleDAO := base.NewArticleDAO(session, user.Pid, user.Userid) @@ -1264,8 +1282,10 @@ func (self *PackOrderServiceImplement) CheckPackOrderItem(user *models.Usertab, PackOrderItemlst.SerialOrderId = orderId PackOrderItemlst.ActQty = 1 PackOrderItemlst.Status = bmodel.PACK_STATUS_RUNNING - - columns := []string{"SerialOrderId", "Status", "ActQty"} + if recInfo !=nil{ + PackOrderItemlst.PKOICustC1 = recInfo.ReclinerNr + } + columns := []string{"SerialOrderId", "Status", "ActQty","PKOICustC1"} err = dao.UpdateWhere([]grmi.Predicate{ meta.PackOrderItemlst_PlantNr.NewPredicate(grmi.Equal, user.Pid), meta.PackOrderItemlst_PackOrderId.NewPredicate(grmi.Equal, packOrderId), diff --git a/services/qm/ReclinerReclst.service.go b/services/qm/ReclinerReclst.service.go index 8ecf411..ae5eebf 100644 --- a/services/qm/ReclinerReclst.service.go +++ b/services/qm/ReclinerReclst.service.go @@ -40,6 +40,25 @@ type ReclinerReclstService interface { * ******************************************************************************/ InsertOne(*models.Usertab, *model.ReclinerReclst) error + /****************************************************************************** + * + * @Function Name : InsertSeriOne + *----------------------------------------------------------------------------- + * + * @Description : 插入一条ReclinerReclst + * + * @Function Parameters : 当前访问人员信息 + * + * @Function Parameters : 需要插入的ReclinerReclst + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-07-12 14:05:20 + * + ******************************************************************************/ + InsertSeriOne(*models.Usertab, *model.ReclinerReclst) error /****************************************************************************** * * @Function Name : AddPrinterInfo @@ -99,6 +118,27 @@ type ReclinerReclstService interface { * ******************************************************************************/ SelectOne(*models.Usertab, int) (*model.ReclinerReclst, error) + /****************************************************************************** + * + * @Function Name : SelectSeriOne + *----------------------------------------------------------------------------- + * + * @Description : 查找指定键的ReclinerReclst + * + * @Function Parameters : 主键 + * + * @Function Parameters : 主键 + * + * @Return Value : 查找到的ReclinerReclst + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-07-12 14:05:20 + * + ******************************************************************************/ + SelectSeriOne(*models.Usertab, string) (*model.ReclinerReclst, error) /****************************************************************************** * * @Function Name : UpdateOne @@ -196,6 +236,68 @@ type ReclinerReclstService interface { * ******************************************************************************/ Update(*models.Usertab, *[]model.ReclinerReclst) error + + /****************************************************************************** + * + * @Function Name : SelectUnPrint + *----------------------------------------------------------------------------- + * + * @Description : 查询未打印的包装 + * + * @Function Parameters : 当前访问人员信息 + * + * @Function Parameters : Article标识 + * + * @Return Value : 包装单模板,当只有一项返回时,根据返回的模板创建包装单,不会为空,如果未找到模板直接报错. + * + * @Return Value : 执行时发生的错误 + * + * @Author : 娄文智 + * + * @Date : 2021-06-02 + * + ******************************************************************************/ + SelectUnPrint(num int) ([]model.ReclinerReclst, error) + /****************************************************************************** + * + * @Function Name : UpdateUnPrint + *----------------------------------------------------------------------------- + * + * @Description : 修改多条PackOrder + * + * @Function Parameters : 当前访问人员信息 + * + * @Function Parameters : 需要修改的PackOrder列表 + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-03-18 23:20:31 + * + ******************************************************************************/ + UpdateUnPrint(recIds []int) error + /****************************************************************************** + * + * @Function Name : CreatePackOrderPrintInfo + *----------------------------------------------------------------------------- + * + * @Description : 插入打印消息列表 + * + * @Function Parameters : 查询条件 + * + * @Function Parameters : 排序字段 + * + * @Return Value : 查询结果 + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-03-24 09:53:49 + * + ******************************************************************************/ + CreateRecPrintInfo(rec model.ReclinerReclst) error } /****************************************************************************** diff --git a/services/qm/implments/ReclinerReclst.service.impl.go b/services/qm/implments/ReclinerReclst.service.impl.go index bc41768..099a13b 100644 --- a/services/qm/implments/ReclinerReclst.service.impl.go +++ b/services/qm/implments/ReclinerReclst.service.impl.go @@ -30,6 +30,7 @@ import ( var DefaultConditionOfReclinerReclst = grmi.NewCondition( map[string]grmi.ConditionItem{ meta.ReclinerReclst_RecNr.UrlParameterName: grmi.NewConditionItem(meta.ReclinerReclst_RecNr, grmi.Equal, true), + meta.ReclinerReclst_RecType.UrlParameterName: grmi.NewConditionItem(meta.ReclinerReclst_RecType, grmi.Equal, true), meta.ReclinerReclst_Line.UrlParameterName: grmi.NewConditionItem(meta.ReclinerReclst_Line, grmi.Equal, true), meta.ReclinerReclst_ArtId.UrlParameterName: grmi.NewConditionItem(meta.ReclinerReclst_ArtId, grmi.Equal, false), meta.ReclinerReclst_SerialOrderId.UrlParameterName: grmi.NewConditionItem(meta.ReclinerReclst_SerialOrderId, grmi.Equal, false), @@ -136,6 +137,8 @@ func (impl *ReclinerReclstServiceImplement) InsertOne(user *models.Usertab, enti artId = artIds[0] } entity.ArtId = artId + entity.RecType = model.QM_REC_TYPE + entity.Status = "N" err = dao.InsertOne(entity) if err != nil { return err @@ -143,6 +146,130 @@ func (impl *ReclinerReclstServiceImplement) InsertOne(user *models.Usertab, enti return nil } +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/services/qm/ReclinerReclstService.InsertSeriOne + * + ******************************************************************************/ +func (impl *ReclinerReclstServiceImplement) InsertSeriOne(user *models.Usertab, entity *model.ReclinerReclst) error { + + grmi.Log(user, "/services/qm/implments/ReclinerReclst.service.impl.go", "InsertOneReclinerReclst", "插入一个ReclinerReclst") + + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + dao := dal.NewReclinerReclstDAO(session, user.Pid, user.Userid) + seriDao := omDal.NewSerialOrderDAO(session, user.Pid, user.Userid) + seriInfo, err := seriDao.SelectBySerialOrder(entity.SerialOrderId) + if err != nil { + return err + } + if seriInfo == nil { + return grmi.NewBusinessError("不存在指定记录!") + } + if seriInfo.PlanResourceId != "G-Frame Assy" { + return grmi.NewBusinessError("该产线不是装配线!") + } + bDao := baseDal.NewLabelParserHeadDAO(session, user.Pid, user.Userid) + result, err := bDao.SelectOne("Barcode") + if err != nil { + return err + } + orderId := entity.SerialOrderId + var artId string + if utils.ValueIsEmpty(result.Split) { + lstdao := baseDal.NewLabelParserDetailLstDAO(session, user.Pid, user.Userid) + list, err := lstdao.Select([]grmi.Predicate{ + bmeta.LabelParserDetailLst_ParserId.NewPredicate(grmi.Equal, "Barcode"), + }, nil) + if err != nil { + return err + } + result.Valst = list + if len(orderId) < result.Length { + return grmi.NewBusinessError("序列订单错误!") + } + codeInfos := bmodel.ParseBarcode(orderId, result.Valst) + artId = codeInfos["artId"] + } else { + artIds := strings.Split(orderId, result.Split) + artId = artIds[0] + } + entity.ArtId = artId + entity.Line = seriInfo.PlanResourceId + entity.RecType = model.QM_SERI_TYPE + entity.Status = "N" + if len(orderId) < 27{ + return grmi.NewBusinessError("序列订单长度错误!") + } + entity.ReclinerNr = orderId[0:19] + "R" + orderId[20:27] + err = dao.InsertOne(entity) + if err != nil { + return err + } + return nil +} + +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/services/qm/ReclinerReclstService.SelectSeriOne + * + ******************************************************************************/ +func (impl *ReclinerReclstServiceImplement) SelectSeriOne(user *models.Usertab, orderId string) (*model.ReclinerReclst, error) { + + grmi.Log(user, "/services/qm/implments/ReclinerReclst.service.impl.go", "InsertOneReclinerReclst", "插入一个ReclinerReclst") + + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + seriDao := omDal.NewSerialOrderDAO(session, user.Pid, user.Userid) + seriInfo, err := seriDao.SelectBySerialOrder(orderId) + if err != nil { + return nil, err + } + if seriInfo == nil { + return nil, grmi.NewBusinessError("不存在指定记录!") + } + if seriInfo.PlanResourceId != "G-Frame Assy" { + return nil, grmi.NewBusinessError("该产线不是装配线!") + } + bDao := baseDal.NewLabelParserHeadDAO(session, user.Pid, user.Userid) + result, err := bDao.SelectOne("Barcode") + if err != nil { + return nil, err + } + entity := new(model.ReclinerReclst) + var artId string + if utils.ValueIsEmpty(result.Split) { + lstdao := baseDal.NewLabelParserDetailLstDAO(session, user.Pid, user.Userid) + list, err := lstdao.Select([]grmi.Predicate{ + bmeta.LabelParserDetailLst_ParserId.NewPredicate(grmi.Equal, "Barcode"), + }, nil) + if err != nil { + return nil, err + } + result.Valst = list + if len(orderId) < result.Length { + return nil, grmi.NewBusinessError("序列订单错误!") + } + codeInfos := bmodel.ParseBarcode(orderId, result.Valst) + artId = codeInfos["artId"] + } else { + artIds := strings.Split(orderId, result.Split) + artId = artIds[0] + } + entity.PlantNr = user.Pid + entity.ArtId = artId + entity.SerialOrderId = orderId + entity.Line = seriInfo.PlanResourceId + entity.RecType = model.QM_SERI_TYPE + if len(orderId) < 27{ + return nil, grmi.NewBusinessError("序列订单长度错误!") + } + entity.ReclinerNr = orderId[0:19] + "R" + orderId[20:27] + return entity, nil +} + /****************************************************************************** * * @Reference LAPP_GAAS_GFrame_BACKEND/services/qm/ReclinerReclstService.AddPrinterInfo @@ -192,7 +319,7 @@ func (impl *ReclinerReclstServiceImplement) AddPrinterInfo(user *models.Usertab, snr := new(models.Snrtab) snr.Finr = bmodel.PlantNr snr.Snrid = "PrintId" - headId,err := snr.GetNextSnr("PrintId") + headId, err := snr.GetNextSnr("PrintId") if err != nil { fmt.Println(err) return grmi.NewBusinessError("打印头部生成错误!") @@ -246,6 +373,108 @@ func (impl *ReclinerReclstServiceImplement) AddPrinterInfo(user *models.Usertab, return nil } + +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/services/qm/ReclinerReclstService.CreatePackOrderPrintInfo + * + ******************************************************************************/ +func (impl *ReclinerReclstServiceImplement) CreateRecPrintInfo(entity model.ReclinerReclst) error { + + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + + templateId := "TSC-BARCODE" + dao := baseDal.NewLabelTemplateHeadDAO(session, bmodel.PlantNr, "Rec") + result, err := dao.SelectOne(templateId) + if err != nil { + return err + } + lstdao := baseDal.NewLabelTemplateDetailDAO(session, bmodel.PlantNr, "Rec") + list, err := lstdao.Select([]grmi.Predicate{ + bmeta.LabelTemplateDetail_LabelTemplateId.NewPredicate(grmi.Equal, templateId), + }, nil) + if err != nil { + return err + } + result.LabelTemplateDetail = list + + //查询物料主数据表 + artDao := baseDal.NewArticleDAO(session, bmodel.PlantNr, "Rec") + artInfo, err := artDao.SelectOne(entity.ArtId) + if err != nil { + return err + } + if artInfo == nil { + return grmi.NewBusinessError("客户订单号没有维护!") + } + //查询序列订单表 + orderDao := omDal.NewSerialOrderDAO(session, bmodel.PlantNr, "Rec") + orderInfo, err := orderDao.SelectBySerialOrder(entity.SerialOrderId) + if err != nil { + return err + } + if orderInfo == nil { + return grmi.NewBusinessError("序列订单订单不存在!") + } + snr := new(models.Snrtab) + snr.Finr = bmodel.PlantNr + snr.Snrid = "PrintId" + headId, err := snr.GetNextSnr("PrintId") + if err != nil { + fmt.Println(err) + return grmi.NewBusinessError("打印头部生成错误!") + } + + // add Begin() before any action + if err := session.Begin(); err != nil { + return err + } + headDao := baseDal.NewLabelHeadDAO(session, bmodel.PlantNr, "Rec") + head := new(bmodel.LabelHead) + head.PlantNr = result.PlantNr + head.LabelId = headId + head.Status = 0 + head.LabelTemplateId = result.LabelTemplateId + head.PrinterId = result.PrinterId + head.PrintQty = 1 + head.BusinessObjType = "BACK" + head.BusinessObjId = entity.SerialOrderId + err = headDao.InsertOne(head) + if err != nil { + session.Rollback() + return err + } + + detailDao := baseDal.NewLabelDetailDAO(session, bmodel.PlantNr, "Rec") + for k, v := range list { + detail := new(bmodel.LabelDetail) + head.PlantNr = result.PlantNr + detail.LabelId = headId + detail.Pos = (k + 1) + detail.VariableName = v.LabelItemValue + //映射值 + if detail.VariableName == "$SN$" { + detail.VariableValue = entity.SerialOrderId + } else if detail.VariableName == "$DATE$" { + dateStr := utils.TimeFormat(orderInfo.PlanStartTime.Restore(), "yyyy/MM/dd") + detail.VariableValue = dateStr + } else if detail.VariableName == "$CUSTID$" { + detail.VariableValue = artInfo.AlternativeArtId + } else if detail.VariableName == "$ORDERID$" { + detail.VariableValue = entity.SerialOrderId + } + err = detailDao.InsertOne(detail) + if err != nil { + session.Rollback() + return err + } + } + session.Commit() + return nil +} + /****************************************************************************** * * @Reference LAPP_GAAS_GFrame_BACKEND/services/qm/ReclinerReclstService.DeleteOne @@ -445,3 +674,43 @@ func (impl *ReclinerReclstServiceImplement) Update(user *models.Usertab, entitie } return nil } + + + +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/services/log/PackOrderService.SelectUnPrint + * + ******************************************************************************/ +func (impl *ReclinerReclstServiceImplement) SelectUnPrint(num int) ([]model.ReclinerReclst, error) { + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + dao := dal.NewReclinerReclstDAO(session, bmodel.PlantNr, "Rec") + if num < 1 { + num = 50 + } + result, err := dao.SelectUnPrint(num) + if err != nil { + return nil, err + } + return result, nil + +} + +/****************************************************************************** + * + * @Reference LAPP_GAAS_GFrame_BACKEND/services/log/PackOrderService.UpdateUnPrint + * + ******************************************************************************/ +func (impl *ReclinerReclstServiceImplement) UpdateUnPrint(recIds []int) error { + engine := db.Eloquent.Master() + session := engine.NewSession() + defer session.Close() + dao := dal.NewReclinerReclstDAO(session, bmodel.PlantNr, "Rec") + err := dao.UpdateUnPrint(recIds) + if err != nil { + return err + } + return nil +} \ No newline at end of file diff --git a/task/printer.go b/task/printer.go index ea9cb8b..30002c3 100644 --- a/task/printer.go +++ b/task/printer.go @@ -2,7 +2,9 @@ package task import ( svr "LAPP_GAAS_GFrame_BACKEND/services/log" + qmsvr "LAPP_GAAS_GFrame_BACKEND/services/qm" model "LAPP_GAAS_GFrame_BACKEND/models/log" + qmmodel "LAPP_GAAS_GFrame_BACKEND/models/qm" "context" "time" ) @@ -69,4 +71,63 @@ func doTaskPrintPack(ctx context.Context) { } } } +} + + +//仓库 +var recChan = make(chan qmmodel.ReclinerReclst, 100) //定义一个调度任务通道 + +/****查询要打印的任务**********/ +func CreateRecPrintTask() { + for { + //创建继承Baxkground的子节点Context + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go doTaskPrintRec(ctx) + + data := make([]qmmodel.ReclinerReclst, 0) + recList := make([]int, 0) + //第一步,查询要打印的数据 + var serviceOfRec = qmsvr.NewReclinerReclstService() + + data, err := serviceOfRec.SelectUnPrint(printNum) + if err != nil { + return + } + //锁定 + for _, v := range data { + recList = append(recList, v.RecNr) + } + err = serviceOfRec.UpdateUnPrint(recList) + if err != nil { + time.Sleep(1 * time.Second) + continue + } + //第二步,把所有的服务调度放到channel + for _, v := range data { + recChan <- v + } + time.Sleep(1 * time.Second) + } +} + +/********打印逻辑************/ +func doTaskPrintRec(ctx context.Context) { + //第三步,启动协程,从channel里读取数据 + for { + select { + case <-ctx.Done(): + return + case task, ok := <-recChan: + + if !ok { + return //停机退出 + } + var serviceOfRec = qmsvr.NewReclinerReclstService() + err := serviceOfRec.CreateRecPrintInfo(task) + if err !=nil{ + return + } + } + } } \ No newline at end of file diff --git a/web/controllers/qm/ReclinerReclst.rest.go b/web/controllers/qm/ReclinerReclst.rest.go index 79634d1..7fed996 100644 --- a/web/controllers/qm/ReclinerReclst.rest.go +++ b/web/controllers/qm/ReclinerReclst.rest.go @@ -62,6 +62,80 @@ func RegisterOneReclinerReclst(party router.Party, httpMethod string, path strin }) } +/****************************************************************************** + * + * @Function Name : RegisterInsertOneReclinerReclst + *----------------------------------------------------------------------------- + * + * @Description : 为一个插入单条ReclinerReclst的方法注册路由 + * + * @Function Parameters : 路由分组 + * + * @Function Parameters : 路径 + * + * @Function Parameters : 实际处理请求的方法 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-07-12 14:05:20 + * + ******************************************************************************/ +func RegisterInsertSeriOneReclinerReclst(party router.Party, path string, method func(*models.Usertab, *model.ReclinerReclst) error) { + + RegisterOneSeriReclinerReclst(party, "POST", path, method) +} + +/****************************************************************************** + * + * @Function Name : RegisterOneSeriReclinerReclst + *----------------------------------------------------------------------------- + * + * @Description : 为一个处理单条ReclinerReclst的方法注册路由 + * + * @Function Parameters : 路由分组 + * + * @Function Parameters : HTTP方法 + * + * @Function Parameters : 路径 + * + * @Function Parameters : 实际处理请求的方法 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-07-12 14:05:20 + * + ******************************************************************************/ +func RegisterOneSeriReclinerReclst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *model.ReclinerReclst) error) { + + party.Handle(httpMethod, path, func(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + + var err error = nil + + entity := new(model.ReclinerReclst) + if ctx.GetContentLength() > 0 { + err := ctx.ReadJSON(entity) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + } else { + entity = nil + } + + err = method(user, entity) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, nil) + }) +} + /****************************************************************************** * * @Function Name : RegisterIDOfReclinerReclst @@ -222,6 +296,47 @@ func RegisterSelectOneReclinerReclst(party router.Party, path string, method fun }) } + +/****************************************************************************** + * + * @Function Name : RegisterSelectSeriOneReclinerReclst + *----------------------------------------------------------------------------- + * + * @Description : 为一个查找单条ReclinerReclst的方法注册路由 + * + * @Function Parameters : 路由分组 + * + * @Function Parameters : 路径 + * + * @Function Parameters : 实际处理请求的方法 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-07-12 14:05:20 + * + ******************************************************************************/ +func RegisterSelectSeriOneReclinerReclst(party router.Party, path string, method func(*models.Usertab, string) (*model.ReclinerReclst, error)) { + + party.Get(path+"/{orderId:string}", func(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + + orderId := ctx.Params().GetString("orderId") + result, err := method(user, orderId) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + if result == nil { + supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, result) + }) +} /****************************************************************************** * * @Function Name : RegisterUpdateOneReclinerReclst diff --git a/web/controllers/qm/qm.go b/web/controllers/qm/qm.go index 4934845..ef6cc4b 100644 --- a/web/controllers/qm/qm.go +++ b/web/controllers/qm/qm.go @@ -242,6 +242,8 @@ func RegisterRoutes() { var serviceOfReclinerReclst = svr.NewReclinerReclstService() // ReclinerReclst插入一条 RegisterInsertOneReclinerReclst(reclinerreclst, "/insertone", serviceOfReclinerReclst.InsertOne) + // 插入条码 + RegisterInsertSeriOneReclinerReclst(reclinerreclst, "/insertserione", serviceOfReclinerReclst.InsertSeriOne) //添加打印消息 RegisterAddPrinterInfo(reclinerreclst, "/addprinterinfo", serviceOfReclinerReclst.AddPrinterInfo) // ReclinerReclst插入多条 @@ -254,6 +256,7 @@ func RegisterRoutes() { RegisterSelectReclinerReclst(reclinerreclst, "/query", serviceOfReclinerReclst.Select) // ReclinerReclst查询一条 RegisterSelectOneReclinerReclst(reclinerreclst, "/get", serviceOfReclinerReclst.SelectOne) + RegisterSelectSeriOneReclinerReclst(reclinerreclst, "/serione", serviceOfReclinerReclst.SelectSeriOne) // ReclinerReclst修改一条 // RegisterUpdateOneReclinerReclst(reclinerreclst, "/updateone", serviceOfReclinerReclst.UpdateOne) // ReclinerReclst修改多条