package main
|
|
|
|
import (
|
|
dal "LAPP_ACURA_MOM_BACKEND/dao/om"
|
|
"LAPP_ACURA_MOM_BACKEND/global"
|
|
meta "LAPP_ACURA_MOM_BACKEND/meta/om"
|
|
model "LAPP_ACURA_MOM_BACKEND/models/om"
|
|
"fmt"
|
|
_ "github.com/denisenkom/go-mssqldb"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
"github.com/go-xorm/xorm"
|
|
"github.com/spf13/viper"
|
|
"strings"
|
|
)
|
|
|
|
var config = new(Config)
|
|
|
|
type Config struct {
|
|
*DB `mapstructure:"db"`
|
|
*App `mapstructure:"app"`
|
|
}
|
|
|
|
type DB struct {
|
|
Host string `yaml:"host"`
|
|
Port int `yaml:"port"`
|
|
User string `yaml:"user"`
|
|
Password string `yaml:"password"`
|
|
Database string `yaml:"database"`
|
|
Mod string `yaml:"mod"`
|
|
}
|
|
|
|
type App struct {
|
|
Mod string `yaml:"mod"`
|
|
CustOrderId string `yaml:"custOrderId"`
|
|
StartSchedKey int `yaml:"startSchedKey"`
|
|
Step int `yaml:"step"`
|
|
PlantNr int `yaml:"plantNr"`
|
|
}
|
|
|
|
func InitConfig() (err error) {
|
|
viper.SetConfigName("repairSchedKey")
|
|
viper.SetConfigType("yaml")
|
|
viper.AddConfigPath(".")
|
|
if err = viper.ReadInConfig(); err != nil {
|
|
return
|
|
}
|
|
if err = viper.Unmarshal(config); err != nil {
|
|
return
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
var err error
|
|
err = InitConfig()
|
|
if err != nil {
|
|
fmt.Println("初始化配置失败, 错误:", err)
|
|
return
|
|
}
|
|
driveSource := fmt.Sprintf("server=%s;database=%s;user id=%s;password=%s;port=%d;encrypt=disable",
|
|
config.DB.Host, config.DB.Database, config.DB.User, config.DB.Password, config.DB.Port)
|
|
Engine, err := xorm.NewEngine("mssql", driveSource)
|
|
if err != nil {
|
|
fmt.Println("连接数据库失败, 错误:", err)
|
|
return
|
|
}
|
|
if strings.ToLower(config.DB.Mod) == "debug" {
|
|
Engine.ShowSQL(true)
|
|
}
|
|
session := Engine.NewSession()
|
|
user := &global.User{
|
|
PlantNr: config.App.PlantNr,
|
|
UserId: "RepairSchedKey",
|
|
}
|
|
serialOrderDao := dal.NewSerialOrderDAO(session, user.PlantNr, user.UserId)
|
|
where := fmt.Sprintf("PlantNr = ? and CustOrderId = ? ")
|
|
args := []interface{}{config.App.PlantNr, config.App.CustOrderId}
|
|
serialOrderLi := make([]model.SerialOrder, 0)
|
|
err = session.Table("OM_SerialOrder").Where(where, args...).OrderBy(meta.SerialOrder_SchedKey.SortColumnName).Find(&serialOrderLi)
|
|
if err != nil {
|
|
fmt.Println("查询序列工单失败, 错误:", err)
|
|
return
|
|
}
|
|
if err = session.Begin(); err != nil {
|
|
fmt.Println("开启事务失败, 错误:" + err.Error())
|
|
return
|
|
}
|
|
for index, serialOrder := range serialOrderLi {
|
|
roginSchedKey := serialOrder.SchedKey
|
|
serialOrder.SchedKey = int64(config.App.StartSchedKey + 10*index)
|
|
if index != 0 {
|
|
serialOrder.PreSchedKey = int64(config.App.StartSchedKey + 10*(index-1))
|
|
}
|
|
err = serialOrderDao.UpdateOne(&serialOrder)
|
|
if err != nil {
|
|
fmt.Println("更新失败, 错误:"+err.Error(), "serialOrderId:", serialOrder.SerialOrderId)
|
|
_ = session.Rollback()
|
|
return
|
|
}
|
|
fmt.Println("处理完成工单ID:", serialOrder.SerialOrderId, "原schedKey:", roginSchedKey, "改为schedKey:", serialOrder.SchedKey)
|
|
}
|
|
if strings.ToLower(config.App.Mod) != "debug" {
|
|
_ = session.Commit()
|
|
} else {
|
|
_ = session.Rollback()
|
|
}
|
|
fmt.Println("执行完成")
|
|
}
|