SJA APS后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
6.2 KiB

package db
import (
"errors"
"github.com/go-xorm/xorm"
"leit.com/leit_seat_aps/common"
"xorm.io/core"
)
// 项目对象
type Me_project struct {
Finr int `xorm:"pk"`
Projectid string `xorm:"pk"`
Descr string
Enabled int
Plantsitecode int
Parse_tod int
Parse_seq int
Parse_reorder int
Parse_calloff int
Fileserver_host string
Tod_folder string
Seq_folder string
Reorder_folder string
Calloff_folder string
Tod_filename_regexp string
Seq_filename_regexp string
Reorder_filename_regexp string
Calloff_filename_regexp string
Tod_verify_part int
Tod_verify_partfamily int
Tod_verify_supplygroup int
Tod_verify_partfamilyattribute int
Tod_verify_supplygroupattribute int
Seq_verify_sequence int
Seq_verfiy_partfamily string
Seq_verify_carmodelattribute int
Reorder_email_alert int
Calloff_verify_checksequence int
Calloff_verify_orderstatus int
Calloff_verify_orderspec int
Emailserver_host string
Emailserver_port int
From_email string
From_pwd string
Tod_error_to_recievers string
Tod_error_cc_recievers string
Seq_error_to_recievers string
Seq_error_cc_recievers string
Reorder_picktemplateid string
Reorder_pickorder_snr string
Reorder_error_to_recievers string
Reorder_error_cc_recievers string
Calloff_error_to_recievers string
Calloff_error_cc_recievers string
Log_url string
Log_table string
Custorder_snr string
Workorder_snr string
Manualwo_snr string
Ordermsg_snr string
Reorder_snr string
Shippack_snr string
Shippacksync_snr string
Shipcar_snr string
Asn_file_prefix string
Asn_snr string
Asn_pfmapper string
Asn_file_type string
Asn_folder string
Backflush_folder string
Shipfile_folder string
Tier2_folder string
Shipfile_snr string
Lastmodif string
Lastuser string
Credatuz string
}
func (t *Me_project) Clipped() {
common.TrimStruct(t, *t)
}
func (t *Me_project) TableName() string {
return "me_project"
}
//增
func (t *Me_project) Add() error {
e := G_DbEngine
projtab := new(Me_project)
affw, err := e.Table("me_project").ID(core.PK{G_FINR, t.Projectid}).Count(projtab)
if err != nil {
return err
}
if affw > 0 {
return errors.New("数据已经存在!")
}
_, err = e.Table("me_project").Insert(t)
if err != nil {
return err
}
return nil
}
//删
func (t *Me_project) Del() bool {
e := G_DbEngine
_, err := e.ID(core.PK{G_FINR, t.Projectid}).Delete(&Me_project{})
if err != nil {
return false
}
return true
}
//改
func (t *Me_project) Update() bool {
e := G_DbEngine
_, err := e.ID(core.PK{G_FINR, t.Projectid}).Update(t)
if err != nil {
return false
}
return true
}
//查
func (t *Me_project) SelectOne() (data Me_project, err error) {
e := G_DbEngine
_, err = e.ID(core.PK{G_FINR, t.Projectid}).Get(&data)
if err != nil {
return data, err
}
return data, nil
}
//查
func (t *Me_project) SelectOneBySession(session *xorm.Session, ) (data Me_project, err error) {
_, err = session.ID(core.PK{G_FINR, t.Projectid}).Get(&data)
if err != nil {
return data, err
}
return data, nil
}
//获取所有激活的项目数据
func (t *Me_project) GetAllActive() (datalst []Me_project, err error) {
e := G_DbEngine
if err = e.Where("finr = ? and enabled = ?", G_FINR, 1).OrderBy("projectid").Find(&datalst); err != nil {
return
}
for i, _ := range datalst {
datalst[i].Clipped()
}
return
}
// 获取项目未解析且客户订单解析状态为IT或RC的Landing数据
func (t *Me_project) GetProjectUnparsedCOV() (datalist []VCustorderVer, err error) {
e := G_DbEngine
datalist = make([]VCustorderVer, 0)
if err = e.Table("pln_custorder_ver").Alias("cov").Join("INNER", []string{"pln_custorder", "co"},
"cov.finr = co.finr and cov.custordernr = co.custordernr").Where("cov.finr = ? and cov.parsed = ? and co.handlestatus != ? and co.projnr = ?",
G_FINR, 0, common.CO_PARSE_STATUS_ERROR, t.Projectid).OrderBy("cov.custordernr, cov.version").Find(&datalist); err != nil {
return
}
return
}
// 确认项目是否需要重载TOD/SEQ/REORDER/CALLOFF 解析用主数据
//func (t *Me_project) NeedToReloadMasterData(ediMode string) (bReload bool, err error) {
// var projecttab Me_project
//
// if projecttab, err = t.SelectOne(); err != nil {
// return
// }
//
// bReload = false
//
// switch ediMode {
// case common.EDI_TOD:
// if projecttab.Reload_tod_masterdata > 0 {
// bReload = true
// }
// case common.EDI_SEQ:
// if projecttab.Reload_seq_masterdata > 0 {
// bReload = true
// }
// case common.EDI_REORDER:
// if projecttab.Reload_reorder_masterdata > 0 {
// bReload = true
// }
// case common.EDI_CALLOFF:
// if projecttab.Reload_calloff_masterdata > 0 {
// bReload = true
// }
// default:
// return
// }
//
// return
//}
// 重置项目重载TOD/SEQ/REORDER/CALLOFF 主数据标志
func (t *Me_project) ResetReloadFlagBySession(session *xorm.Session, ediMode string) (err error) {
var fields string
switch ediMode {
case common.EDI_TOD:
fields = "reload_tod_masterdata, lastmodif"
case common.EDI_SEQ:
fields = "reload_seq_masterdata, lastmodif"
case common.EDI_REORDER:
fields = "reload_reorder_masterdata, lastmodif"
case common.EDI_CALLOFF:
fields = "reload_calloff_masterdata, lastmodif"
default:
return
}
if _, err = session.Table("jit_shiporder").ID(core.PK{G_FINR, t.Projectid}).Cols(fields).Update(t); err != nil {
return
}
return
}