// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved. package models import ( "errors" "leit.com/aps_engine/db" "leit.com/aps_engine/grmi" "xorm.io/core" ) type WorkShift struct { PlantNr int `xorm:"pk int 'PlantNr'" json:"WorkShift-PlantNr"` WorkShiftNr int `xorm:"pk int 'WorkShiftNr' autoincr" json:"WorkShift-WorkShiftNr"` Descr string `xorm:"nvarchar(100) 'Descr'" json:"WorkShift-Descr"` Abrev string `xorm:"nvarchar(10) 'Abrev' not null" json:"WorkShift-Abrev"` HexColor string `xorm:"nvarchar(10) 'HexColor'" json:"WorkShift-HexColor"` PlanPersonQty int `xorm:"int 'PlanPersonQty'" json:"WorkShift-PlanPersonQty"` PlanEfficiency float64 `xorm:"float 'PlanEfficiency' not null" json:"WorkShift-PlanEfficiency"` SBeg int `xorm:"int 'S_Beg'" json:"WorkShift-S_Beg"` SEnd int `xorm:"int 'S_End'" json:"WorkShift-S_End"` SLen int `xorm:"int 'S_Len'" json:"WorkShift-S_Len"` SB1Beg int `xorm:"int 'S_B1_Beg'" json:"WorkShift-S_B1_Beg"` SB1End int `xorm:"int 'S_B1_End'" json:"WorkShift-S_B1_End"` SB2Beg int `xorm:"int 'S_B2_Beg'" json:"WorkShift-S_B2_Beg"` SB2End int `xorm:"int 'S_B2_End'" json:"WorkShift-S_B2_End"` SB3Beg int `xorm:"int 'S_B3_Beg'" json:"WorkShift-S_B3_Beg"` SB3End int `xorm:"int 'S_B3_End'" json:"WorkShift-S_B3_End"` SB4Beg int `xorm:"int 'S_B4_Beg'" json:"WorkShift-S_B4_Beg"` SB4End int `xorm:"int 'S_B4_End'" json:"WorkShift-S_B4_End"` SB5Beg int `xorm:"int 'S_B5_Beg'" json:"WorkShift-S_B5_Beg"` SB5End int `xorm:"int 'S_B5_End'" json:"WorkShift-S_B5_End"` LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"WorkShift-LastModify"` LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"WorkShift-LastUser"` CreateTime grmi.DateTime `xorm:"datetime 'CreateTime' not null created" json:"WorkShift-CreateTime"` WorkShiftEffLst []WorkShiftEffLst `xorm:"-" json:"WorkShift-WorkShiftEffLst"` } /******数据表名******/ func (t *WorkShift) TableName() string { return "Workshift" } /****************************************************************************** * * @Function Name : GetKey *----------------------------------------------------------------------------- * * @Description : 获取实体的主键 * * @Return Value : 实体的主键 * * @Author : 代码生成器创建 * * @Date : 2021-03-23 17:06:57 * ******************************************************************************/ func (self *WorkShift) GetKey() core.PK { return core.PK{self.PlantNr, self.WorkShiftNr} } /****************************************************************************** * * @Function Name : *----------------------------------------------------------------------------- * * @Description : 数据添加 * * @Function Parameters: * * @Return Value : * * @Author : Lou Wenzhi * * @Date : 2021/3/6 8:47 * ******************************************************************************/ func (t *WorkShift) Add() error { e := db.Eloquent.Master() count := new(WorkShift) affw, err := e.Table(t.TableName()).ID(t.GetKey()).Count(count) if err != nil { return err } if affw > 0 { return errors.New("数据已经存在!") } _, err = e.Table(t.TableName()).Insert(t) if err != nil { return err } return nil } /****************************************************************************** * * @Function Name : *----------------------------------------------------------------------------- * * @Description : 数据删除 * * @Function Parameters: * * @Return Value : * * @Author : Lou Wenzhi * * @Date : 2021/3/6 8:47 * ******************************************************************************/ func (t *WorkShift) Del() bool { e := db.Eloquent.Master() _, err := e.ID(t.GetKey()).Delete(&WorkShift{}) if err != nil { return false } return true } /****************************************************************************** * * @Function Name : *----------------------------------------------------------------------------- * * @Description : 数据修改 * * @Function Parameters: * * @Return Value : * * @Author : Lou Wenzhi * * @Date : 2021/3/6 8:47 * ******************************************************************************/ func (t *WorkShift) Update() error { e := db.Eloquent.Master() _, err := e.ID(t.GetKey()).Update(t) if err != nil { return err } return nil } /****************************************************************************** * * @Function Name : *----------------------------------------------------------------------------- * * @Description : 数据查找 * * @Function Parameters: * * @Return Value : * * @Author : Lou Wenzhi * * @Date : 2021/3/6 8:47 * ******************************************************************************/ func (t *WorkShift) SelectOne() (WorkShift, error) { e := db.Eloquent.Master() var data WorkShift _, err := e.ID(t.GetKey()).Get(&data) if err != nil { return data, err } return data, nil } /****************************************************************************** * * @Function Name : *----------------------------------------------------------------------------- * * @Description : 数据查找 * * @Function Parameters: * * @Return Value : * * @Author : Lou Wenzhi * * @Date : 2021/3/6 8:47 * ******************************************************************************/ func (t *WorkShift) SelectAll() (datalst []WorkShift, err error) { var i int e := db.Eloquent.Master() if err = e.Table(t.TableName()).Where("PlantNr = ?",t.PlantNr).OrderBy("WorkShiftNr").Find(&datalst);err != nil { return } for i = 0; i < len(datalst); i++ { if err = e.Table("Workshiftefflst").Where("PlantNr = ? and WorkShiftNr = ?", datalst[i].PlantNr, datalst[i].WorkShiftNr).OrderBy("LevelId").Find(&datalst[i].WorkShiftEffLst); err != nil { return } } return }