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.

127 lines
3.0 KiB

package db
import (
"errors"
"leit.com/leit_seat_aps/common"
"strings"
"xorm.io/core"
)
//属性表
type Me_attribute struct {
Finr int `xorm:"pk" json:"me_attribute.finr"`
Attrcode int `xorm:"pk" json:"me_attribute.attrcode"`
Attrname string `json:"me_attribute.attrname"`
Descr string `json:"me_attribute.descr"`
Shortcode string `json:"me_attribute.shortcode"`
Attrtype int `json:"me_attribute.attrtype"`
Valformat string `json:"me_attribute.valformat"`
Lastmodif string `json:"me_attribute.lastmodif"`
Lastuser string `json:"me_attribute.lastuser"`
Credatuz string `json:"me_attribute.credatuz"`
Valst []Me_attribute_valst `json:"valst" xorm:"-"`
}
func (t *Me_attribute) Clipped() {
common.TrimStruct(t, *t)
}
func (t *Me_attribute) TableName() string {
return "me_attribute"
}
//增
func (t *Me_attribute) Add() error {
e := G_DbEngine
attrtab := new(Me_attribute)
affw, err := e.Table("me_attribute").ID(core.PK{G_FINR, t.Attrcode}).Count(attrtab)
if err != nil {
return err
}
if affw > 0 {
return errors.New("数据已经存在!")
}
_, err = e.Table("me_attribute").Insert(t)
if err != nil {
return err
}
return nil
}
//删
func (t *Me_attribute) Del() bool {
e := G_DbEngine
_, err := e.ID(core.PK{G_FINR, t.Attrcode}).Delete(&Me_attribute{})
if err != nil {
return false
}
return true
}
//改
func (t *Me_attribute) Update() bool {
e := G_DbEngine
_, err := e.ID(core.PK{G_FINR, t.Attrcode}).Update(t)
if err != nil {
return false
}
return true
}
//查
func (t *Me_attribute) SelectOne() (data Me_attribute, err error) {
var valst []Me_attribute_valst
e := G_DbEngine
_, err = e.ID(core.PK{G_FINR, t.Attrcode}).Get(&data)
if err != nil {
return data, err
}
data.Clipped()
// 获取值列表
if err = e.Where("finr = ? and attrcode = ?", G_FINR, t.Attrcode).OrderBy("pos").Find(&valst); err != nil {
return
}
for i, _ := range valst {
valst[i].Clipped()
}
data.Valst = valst
return data, nil
}
// 获取指定类型的属性列表
func (t *Me_attribute) GetTypeAttributes(attrtype int) (datalst []Me_attribute, err error) {
var i, j int
e := G_DbEngine
if err = e.Where("finr = ? and attrtype = ?", G_FINR, attrtype).OrderBy("attrcode").Find(&datalst); err != nil {
return
}
// 遍历属性获取属性值列表
for i, _ = range datalst {
datalst[i].Clipped()
datalst[i].Valst = make([]Me_attribute_valst, 0)
// 获取值列表
if err = e.Where("finr = ? and attrcode = ?", G_FINR, datalst[i].Attrcode).OrderBy("pos").Find(&datalst[i].Valst); err != nil {
return
}
for j, _ = range datalst[i].Valst {
datalst[i].Valst[j].Clipped()
}
}
return
}
// 获取指定属性值的位置
func (t *Me_attribute) GetValuePos(cval string) int {
var i int
for i = 0; i < len(t.Valst); i++ {
if strings.TrimSpace(cval) == strings.TrimSpace(t.Valst[i].Shortcode) {
return i
}
}
return -1
}