|
|
@ -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 |
|
|
|
} |
|
|
|
} |