|
|
- package models
-
- import (
- "LAPP_SJA_ME/db"
- "LAPP_SJA_ME/utils"
- "xorm.io/core"
- "errors"
- )
-
- //生产线
- type Workline struct {
- Finr int `xorm:"pk comment('工厂号') Int" json:"workline-finr"`
- Worklineid string `xorm:"pk comment('生产线ID') VARCHAR(20)" json:"workline-worklineid"`
- Descr string `xorm:"comment('描述1') VARCHAR(40)" json:"workline-descr"`
- Linetype string `xorm:"comment('产线类型') VARCHAR(1)" json:"workline-linetype"`
- Lineplanmode string `xorm:"comment('产线计划模块') VARCHAR(3)" json:"workline-lineplanmode"`
- Weekmodelid int `xorm:"comment('周模块ID') Int" json:"workline-weekmodelid"`
- Workcalendarid int `xorm:"comment('工作日历') Int" json:"workline-workcalendarid"`
- Location string `xorm:"comment('位置') VARCHAR(40)" json:"workline-location"`
- Costcenterid string `xorm:"comment('成本中心') VARCHAR(40)" json:"workline-costcenterid"`
- Costrate float64 `xorm:"comment('成本费率') Double" json:"workline-costrate"`
- Prodeff float64 `xorm:"comment('生产效率') Double" json:"workline-prodeff"`
- Reqworkers int `xorm:"comment('定额人数') Int" json:"workline-reqworkers"`
- Pos int `xorm:"comment('位置') Int" json:"workline-pos"`
- Releaseparameter int `xorm:"comment('下达参数') Int" json:"workline-releaseparameter"`
- Multiqueuemixsort int `xorm:"comment('混线排序逻辑') Int" json:"workline-multiqueuemixsort"`
- Taskqueuesortway string `xorm:"comment('任务队列排序方式') VARCHAR(14)" json:"workline-taskqueuesortway"`
- Taskqueuemixsortway string `xorm:"comment('混线排序方式') VARCHAR(14)" json:"workline-taskqueuemixsortway"`
- Mixsortlogic string `xorm:"comment('混线排序逻辑') VARCHAR(14)" json:"workline-mixsortlogic"`
- Taskreleaseway string `xorm:"comment('任务下达方式') VARCHAR(14)" json:"workline-taskreleaseway"`
- Lastmodif string `xorm:"comment('最近一次更改时间') VARCHAR(14)" json:"workline-lastmodif"`
- Lastuser string `xorm:"comment('最近一次更改人') VARCHAR(20)" json:"workline-lastuser"`
- Credatuz string `xorm:"comment('创建时间') VARCHAR(14)" json:"workline-credatuz"`
- }
-
- func (t *Workline) TableName() string {
- return "workline"
- }
-
- // 清除string字段的右侧空格
- func (t *Workline) Clipped() {
- utils.TrimStruct(t, *t)
- }
-
- //增
- func (t *Workline) Add() error {
- e := db.Eloquent.Master()
- countrole := new(Workline)
- affw, err := e.Table("workline").ID(core.PK{t.Finr, t.Worklineid}).Count(countrole)
- if err != nil {
- return err
- }
- if affw > 0 {
- return errors.New("数据已经存在!")
- }
- _, err = e.Table("workline").Insert(t)
-
- if err != nil {
- return err
- }
- return nil
- }
-
- //删
- func (t *Workline) Del() bool {
- e := db.Eloquent.Master()
- _, err := e.ID(core.PK{t.Finr, t.Worklineid}).Delete(&Workline{})
- if err != nil {
- return false
- }
- return true
- }
-
- //改
- func (t *Workline) Update() bool {
- e := db.Eloquent.Master()
- _, err := e.ID(core.PK{t.Finr, t.Worklineid}).Update(t)
- if err != nil {
- return false
- }
- return true
- }
-
- //查
- func (t *Workline) SelectOne() (Workline, error) {
- e := db.Eloquent.Master()
- var data Workline
- _, err := e.ID(core.PK{t.Finr, t.Worklineid}).Get(&data)
- if err != nil {
- return data, err
- }
- return data, nil
- }
-
- //分页
- func (t *Workline) GetPage(pageSize int, pageIndex int) ([]Workline, int, error) {
- data := make([]Workline, 0)
- e := db.Eloquent.Master()
- table := e.Table("workline").Where("finr = ? ", t.Finr)
- where := "where finr = " + "'" + utils.ValueToString(t.Finr, "") + "'"
- if !utils.ValueIsEmpty(t.Worklineid) {
- table = table.And("worklineid = ?", t.Worklineid)
- where += " and worklineid = " + "'" + t.Worklineid + "'"
- }
- if !utils.ValueIsEmpty(t.Linetype) {
- table = table.And("linetype = ?", t.Linetype)
- where += " and linetype = " + "'" + t.Linetype + "'"
- }
- Offset := (pageIndex - 1) * pageSize
- err := e.SQL("SELECT TOP " + utils.ValueToString(pageSize, "") + " workline.* FROM workline " + where + " AND (convert(varchar(10),finr)+convert(varchar(40),worklineid) NOT IN (SELECT TOP " + utils.ValueToString(Offset, "") + " convert(varchar(10),finr)+convert(varchar(40),worklineid) FROM workline " + where + " ORDER BY credatuz DESC)) ORDER BY credatuz DESC").Find(&data)
- pcount := new(Workline)
- count, err := table.Count(pcount)
- if err != nil {
- return data, 0, err
- }
- for k, _ := range data {
- data[k].Clipped()
- }
- return data, int(count), nil
- }
-
- //查询当前worklineids集合
- func (t *Workline) SelectArr() (arr []string, err error) {
- e := db.Eloquent.Master()
- var data []Workline
- err = e.Where("finr = ? ", t.Finr).Cols("worklineid").Find(&data)
- for _, v := range data {
- v.Clipped()
- arr = append(arr, v.Worklineid)
- }
- if err != nil {
- return arr, err
- }
- return arr, nil
- }
|