Browse Source

完成对顺引功能的问题修复

pull/147/head
zhangxin 3 years ago
parent
commit
13cd3ff552
4 changed files with 84 additions and 32 deletions
  1. +1
    -0
      models/pln/const.go
  2. +43
    -22
      services/pln/implments/ToyotaCalloff.service.impl.go
  3. +36
    -6
      services/pln/implments/ToyotaDeliveryOrder.service.impl.go
  4. +4
    -4
      web/controllers/pln/ToyotaDeliveryOrder.rest.go

+ 1
- 0
models/pln/const.go View File

@ -26,6 +26,7 @@ const (
// toyota calloff 解析状态
CALLOFF_STATUS_UNPARSED = 0
CALLOFF_STATUS_PARSED = 1
CALLOFF_STATUS_SHIPED = 2
DELIVERY_STATUS_PLAN = 0
DELIVERY_STATUS_DONE = 1


+ 43
- 22
services/pln/implments/ToyotaCalloff.service.impl.go View File

@ -22,6 +22,7 @@ import (
"path"
"regexp"
"strconv"
"strings"
"time"
)
@ -354,10 +355,10 @@ func (impl *ToyotaCalloffServiceImplement) Update(user *global.User, entities *[
}
// ParseToyotaCallOffFile 解析南沙顺引
func (impl *ToyotaCalloffServiceImplement) ParseToyotaCallOffFile() {
func (impl *ToyotaCalloffServiceImplement) ParseToyotaCallOffFile() {
log, _ := logger.NewLogger("CallOff", "PLN")
user := &global.User{
UserId: "Scheduler",
UserId: "Scheduler",
PlantNr: baseModel.PlantNr,
}
engine := db.Eloquent.Master()
@ -390,12 +391,19 @@ func (impl *ToyotaCalloffServiceImplement) LoadFile(user *global.User, projectId
return
}
for _, file := range fileInfoList {
if file.IsDir() {
continue
}
filepath := path.Join(inBoxPath, file.Name())
repeat, err := impl.ParseCsvFile(user, filepath, file.Name(), projectId)
if err != nil {
log.Error("解析广丰CallOff, 解析失败, 文件:" + file.Name() + ", 错误:" + err.Error())
if !repeat {
errorPath := path.Join(errBoxPath, file.Name())
//c := exec.Command("move", filepath, errorPath)
//if err := c.Run(); err != nil {
// log.Error("解析广丰CallOff, 移动文件到错误文件夹失败,文件名:" + file.Name() + ", 错误:" + err.Error()+ ", errorPath:" + errorPath)
//}
err = os.Rename(filepath, errorPath)
if err != nil {
log.Error("解析广丰CallOff, 移动文件到错误文件夹失败,文件名:" + file.Name() + ", 错误:" + err.Error())
@ -405,6 +413,10 @@ func (impl *ToyotaCalloffServiceImplement) LoadFile(user *global.User, projectId
}
} else {
movePath := path.Join(outBoxPath, file.Name())
//c := exec.Command("move", filepath, movePath)
//if err := c.Run(); err != nil {
// log.Error("解析广丰CallOff, 移动文件到已解析文件夹失败,文件名:" + file.Name() + ", 错误:" + err.Error() + ", movePath:" + movePath)
//}
err = os.Rename(filepath, movePath)
if err != nil {
log.Error("解析广丰CallOff, 移动文件到已解析文件夹失败,文件名:" + file.Name() + ", 错误:" + err.Error())
@ -420,6 +432,15 @@ func (impl *ToyotaCalloffServiceImplement) ParseCsvFile(user *global.User, filep
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
demandId := strings.Split(filename, ".")[0]
calloffDao := dal.NewToyotaCalloffDAO(session, user.PlantNr, user.UserId)
existCallOff, err := calloffDao.SelectOne(demandId)
if err != nil {
return true, grmi.NewBusinessError("查询calloff数据失败, 错误:" + err.Error())
}
if existCallOff != nil {
return true, nil
}
f, err := os.Open(filepath)
if err != nil {
return true, grmi.NewBusinessError("打开文件失败, error:" + err.Error())
@ -445,7 +466,7 @@ func (impl *ToyotaCalloffServiceImplement) ParseCsvFile(user *global.User, filep
if len(matchLi[1]) < 9 {
return false, grmi.NewBusinessError("获取到的供应商数据不足")
}
demandId := matchLi[1]
fileId := matchLi[1]
supplyCode := matchLi[1][:9]
code := matchLi[2]
seqStr := matchLi[3]
@ -485,8 +506,8 @@ func (impl *ToyotaCalloffServiceImplement) ParseCsvFile(user *global.User, filep
EdiFile: filename,
EdiFileType: "csv",
CtrlStr1: code,
CtrlStr2: fileId,
}
calloffDao := dal.NewToyotaCalloffDAO(session, user.PlantNr, user.UserId)
err = calloffDao.InsertOne(&callOff)
if err != nil {
return true, grmi.NewBusinessError("写入callOff数据失败, error:" + err.Error())
@ -495,12 +516,12 @@ func (impl *ToyotaCalloffServiceImplement) ParseCsvFile(user *global.User, filep
}
// ParseToyotaCallOffCache 解析南沙顺引换成数据
func (impl *ToyotaCalloffServiceImplement) ParseToyotaCallOffCache() {
func (impl *ToyotaCalloffServiceImplement) ParseToyotaCallOffCache() {
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
user := &global.User{
UserId: "Scheduler",
UserId: "Scheduler",
PlantNr: baseModel.PlantNr,
}
log, _ := logger.NewLogger("CallOff", "PLN")
@ -533,7 +554,7 @@ func (impl *ToyotaCalloffServiceImplement) ParseCallOffData(user *global.User, p
return
}
if len(waitParseLi) == 0 {
log.Info("解析CallOff数据, 没有解析的CallOff数据")
log.Info("解析CallOff数据, 没有解析的CallOff数据")
}
maxSeqCallOff, err := callOffDao.SelectMaxSeqCallOff(project.ProjectId)
if err != nil {
@ -683,13 +704,13 @@ func (impl *ToyotaCalloffServiceImplement) ParseCallOffData(user *global.User, p
}
plcCode := `1` + strconv.Itoa(productFamily.CtrlPara1) + seatData
deliveryOrder := model.ToyotaDeliveryOrder{
DemandId: callOffData.DemandId,
SortNr: callOffData.CheckSequence,
DemandId: callOffData.DemandId,
SortNr: callOffData.CheckSequence,
ProductFamilyId: callOffData.ProductFamilyId,
ProjectId: project.ProjectId,
PlcIpAddress: conf.DbConfig.CallOffPlcAddress,
PlcCode: plcCode,
Status: model.DELIVERY_STATUS_PLAN,
ProjectId: project.ProjectId,
PlcIpAddress: conf.DbConfig.CallOffPlcAddress,
PlcCode: plcCode,
Status: model.DELIVERY_STATUS_PLAN,
}
err = deliveryOrderDao.InsertOne(&deliveryOrder)
if err != nil {
@ -718,7 +739,7 @@ func (impl *ToyotaCalloffServiceImplement) ParseCallOffData(user *global.User, p
}
}
_ = session.Commit()
log.Info("解析CallOff数据任务执行完成,当前项目:" + project.ProjectId + ", 最大MaxSeq:", strconv.Itoa(maxSeq-1))
log.Info("解析CallOff数据任务执行完成,当前项目:"+project.ProjectId+", 最大MaxSeq:", strconv.Itoa(maxSeq-1))
return
}
@ -787,7 +808,7 @@ func (impl *ToyotaCalloffServiceImplement) AnalysisAgain(user *global.User, dema
}
errorLi, err := callOffErrDao.Select([]grmi.Predicate{meta.ToyotaCallOffErrorLst_DemandId.NewPredicate(grmi.Equal, demandId),
meta.ToyotaCallOffErrorLst_ErrorStatus.NewPredicate(grmi.Equal, model.ERROR_STATUS_ON),
meta.ToyotaCallOffErrorLst_ErrorType.NewPredicate(grmi.Equal, model.ERROR_TYPE_DATA)}, nil)
meta.ToyotaCallOffErrorLst_ErrorType.NewPredicate(grmi.Equal, model.ERROR_TYPE_DATA)}, nil)
if len(errorLi) != 0 {
return grmi.NewBusinessError("存在未修复的数据项错误")
}
@ -980,13 +1001,13 @@ func (impl *ToyotaCalloffServiceImplement) AnalysisAgain(user *global.User, dema
seatData += product.ColorValue
plcCode := `1` + strconv.Itoa(productFamily.CtrlPara1) + seatData
deliveryOrder := model.ToyotaDeliveryOrder{
DemandId: callOff.DemandId,
SortNr: callOff.CheckSequence,
DemandId: callOff.DemandId,
SortNr: callOff.CheckSequence,
ProductFamilyId: callOff.ProductFamilyId,
ProjectId: callOff.ProjectId,
PlcIpAddress: conf.DbConfig.CallOffPlcAddress,
PlcCode: plcCode,
Status: model.DELIVERY_STATUS_PLAN,
ProjectId: callOff.ProjectId,
PlcIpAddress: conf.DbConfig.CallOffPlcAddress,
PlcCode: plcCode,
Status: model.DELIVERY_STATUS_PLAN,
}
err = deliveryOrderDao.InsertOne(&deliveryOrder)
if err != nil {
@ -1013,4 +1034,4 @@ func (impl *ToyotaCalloffServiceImplement) AnalysisAgain(user *global.User, dema
}
_ = session.Commit()
return nil
}
}

+ 36
- 6
services/pln/implments/ToyotaDeliveryOrder.service.impl.go View File

@ -375,6 +375,7 @@ func (impl *ToyotaDeliveryOrderServiceImplement) WriteDeliveryDataToPLC() {
}
dao := dal.NewToyotaDeliveryOrderDAO(session, user.PlantNr, user.UserId)
errDao := dal.NewToyotaDeliveryOrderErrorLstDAO(session, user.PlantNr, user.UserId)
callOffDao := dal.NewToyotaCalloffDAO(session, user.PlantNr, user.UserId)
deliveryOrder, err := dao.SelectTopOne([]grmi.Predicate{meta.ToyotaDeliveryOrder_Status.NewPredicate(grmi.Equal, model.DELIVERY_STATUS_PLAN)}, []grmi.Field{meta.ToyotaDeliveryOrder_SortNr})
if err != nil {
log.Error("广丰写入座椅出库数据, 查询发运数据失败, error:" + err.Error())
@ -389,6 +390,27 @@ func (impl *ToyotaDeliveryOrderServiceImplement) WriteDeliveryDataToPLC() {
log.Error("广丰写入座椅出库数据, 查询写入完成的发运单数据失败, error:" + err.Error())
return
}
callOff, err := callOffDao.SelectOne(deliveryOrder.DemandId)
if err != nil {
log.Error("查询callOff数据失败, 错误:" + err.Error())
return
}
if callOff == nil {
errorContent := "CallOff数据不存在"
log.Error("广丰写入座椅出库数据," + errorContent + ", demandId:" + deliveryOrder.DemandId)
errData := model.ToyotaDeliveryOrderErrorLst{
DemandId: deliveryOrder.DemandId,
Pos: 1,
ErrorType: model.ERROR_TYPE_HINT,
ErrorInfo: errorContent,
ErrorStatus: model.ERROR_STATUS_ON,
}
err = errDao.InsertOne(&errData)
if err != nil {
log.Error("广丰写入座椅出库数据, 写入错误数据失败, error:" + err.Error() + ", 错误数据:" + errorContent + ", demandId:" + deliveryOrder.DemandId)
}
return
}
//if doneOrder == nil {
// if deliveryOrder.SortNr != 1 {
// log.Error("广丰写入座椅出库数据, 起始SortNr不为1")
@ -439,7 +461,15 @@ func (impl *ToyotaDeliveryOrderServiceImplement) WriteDeliveryDataToPLC() {
err = dao.UpdateOne(deliveryOrder)
if err != nil {
_ = session.Rollback()
log.Error("广丰写入座椅出库数据, 写PLC数据失败, error:" + err.Error())
log.Error("广丰写入座椅出库数据, 更新发运数据失败, error:" + err.Error())
return
}
callOff.Parsed = model.CALLOFF_STATUS_SHIPED
err = callOffDao.UpdateOne(callOff)
if err != nil {
_ = session.Rollback()
log.Error("广丰写入座椅出库数据, 更新CallOff状态失败, 错误:" + err.Error())
return
}
err = impl.WriteToPLC(user, deliveryOrder)
if err != nil {
@ -568,7 +598,7 @@ func (impl *ToyotaDeliveryOrderServiceImplement) ReadSign() error {
log.Error("座椅出库plc写入, 读取标识位后台返回data格式不正确, 后台数据:" + string(boday))
return grmi.NewBusinessError("座椅出库plc写入, 读取标识位后台返回data格式不正确, 后台数据:" + string(boday))
}
if !sign {
if sign {
if retryNum >= 3 {
log.Error("座椅出库plc写入, 读取标识位不允许写入且达到最大次数, 后台数据:" + string(boday))
return grmi.NewBusinessError("座椅出库plc写入, 读取标识位不允许写入且达到最大次数, 后台数据:" + string(boday))
@ -599,8 +629,8 @@ func (impl *ToyotaDeliveryOrderServiceImplement) WriteSign() error {
log.Error("座椅出库plc写入, 序列化写入第一步标识位请求数据失败, error:" + err.Error())
return grmi.NewBusinessError("座椅出库plc写入, 序列化第一步标识位失败, error:" + err.Error())
}
log.Debug("座椅出库plc写入, 写入第一步标识位请求参数:" + string(postData) + ", url:" + conf.DbConfig.PLCWriteStringBackend)
boday, err := utils.Post(conf.DbConfig.PLCWriteStringBackend, postData)
log.Debug("座椅出库plc写入, 写入第一步标识位请求参数:" + string(postData) + ", url:" + conf.DbConfig.PLCWriteBackend)
boday, err := utils.Post(conf.DbConfig.PLCWriteBackend, postData)
if err != nil {
log.Error("座椅出库plc写入,写入第一步标识位调用失败, error:" + err.Error())
return grmi.NewBusinessError("座椅下线plc写入, 写入第一步标识位调用失败, error:" + err.Error())
@ -656,8 +686,8 @@ func (impl *ToyotaDeliveryOrderServiceImplement) WriteSeatData(seatData string)
log.Error("座椅出库plc写入, 序列化座椅数据请求数据失败, error:" + err.Error())
return grmi.NewBusinessError("座椅出库plc写入, 序列化座椅数据请求数据失败, error:" + err.Error())
}
log.Debug("座椅出库plc写入, 写入座椅数据请求参数:" + string(postData) + ", url:" + conf.DbConfig.PLCWriteStringBackend)
boday, err := utils.Post(conf.DbConfig.PLCWriteStringBackend, postData)
log.Debug("座椅出库plc写入, 写入座椅数据请求参数:" + string(postData) + ", url:" + conf.DbConfig.PLCWriteBackend)
boday, err := utils.Post(conf.DbConfig.PLCWriteBackend, postData)
if err != nil {
log.Error("座椅出库plc写入,写入座椅数据调用失败, error:" + err.Error())
return grmi.NewBusinessError("座椅出库plc写入, 写入座椅数据调用失败, error:" + err.Error())


+ 4
- 4
web/controllers/pln/ToyotaDeliveryOrder.rest.go View File

@ -183,10 +183,10 @@ func RegisterSelectOneToyotaDeliveryOrder(party router.Party, path string, metho
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
if result == nil {
supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
return
}
//if result == nil {
// supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
// return
//}
supports.Ok(ctx, supports.OptionSuccess, result)
})
}


Loading…
Cancel
Save