123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package models
- import (
- "errors"
- "zhiyuan/pkg/db"
- "github.com/gin-gonic/gin"
- )
- type WorkProcess struct {
- ID int64 `json:"id" prop:"add:false"`
- NodeId int64 `json:"node_id" type:"int" prop:"add" search:"="`
- Name string `json:"name" label:"工序名称" type:"string" prop:"add edit" search:"like"`
- State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0"`
- OrderAt int64 `json:"order_at" prop:"add:false select:false"`
- DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
- CreatedAt int64 `json:"created_at" prop:"add:false select:false"`
- UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"`
- Requires []WorkProcessRequire `json:"requires" prop:"ignore"`
- db.BaseModel
- }
- func (WorkProcess) TableName() string {
- return "zy_work_process"
- }
- func (WorkProcess) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- return true
- }
- func (WorkProcess) OnePrivilege(c *gin.Context, id int64) bool {
- return true
- }
- func (WorkProcess) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
- return nil
- }
- func (WorkProcess) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
- return nil
- }
- func (WorkProcess) DelPrivilege(c *gin.Context, id int64) error {
- return nil
- }
- func (WorkProcess) OrderField() string {
- return "order_at"
- }
- func (WorkProcess) Page() bool {
- return false
- }
- func (WorkProcess) Count() bool {
- return true
- }
- func (a WorkProcess) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*WorkProcess, error) {
- if retVal == nil {
- var work_process *WorkProcess
- err := db.GetOne(a.TableName(), where, fields, &work_process)
- return work_process, err
- } else {
- err := db.GetOne(a.TableName(), where, fields, retVal)
- return nil, err
- }
- }
- func (a WorkProcess) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*WorkProcess, error) {
- if retVal == nil {
- var work_process []*WorkProcess
- err := db.GetMulti(a.TableName(), where, fields, &work_process)
- return work_process, err
- } else {
- err := db.GetMulti(a.TableName(), where, fields, retVal)
- return nil, err
- }
- }
- func (a WorkProcess) GetOneRaw(where map[string]string, param map[string]interface{}, retVal interface{}) (*WorkProcess, error) {
- work_process, err := a.GetMultiRaw(where, param, retVal)
- if err != nil {
- return nil, err
- }
- if len(work_process) == 0 {
- return nil, errors.New("empty record2")
- }
- return work_process[0], nil
- }
- func (a WorkProcess) GetMultiRaw(where map[string]string, param map[string]interface{}, retVal interface{}) ([]*WorkProcess, error) {
- field := "SELECT * FROM zy_work_process "
- if retVal == nil {
- var work_process []*WorkProcess
- err := db.GetMultiRaw(field, where, param, &work_process)
- return work_process, err
- } else {
- err := db.GetMultiRaw(field, where, param, retVal)
- return nil, err
- }
- }
- func CopyWorkProcesss(processs []WorkProcess, node_id int64, order int64) error {
- for i, process := range processs {
- _, err := process.Copy(node_id, order+int64(len(processs)-i))
- if err != nil {
- return err
- }
- }
- return nil
- }
- func (model WorkProcess) Copy(node_id int64, order int64) (int64, error) {
- id, err := db.InsertModel(db.Type(model), map[string]interface{}{
- "node_id": node_id,
- "name": model.Name,
- "state": model.State,
- "order_at": order,
- })
- if err != nil {
- return 0, err
- }
- err = CopyWorkProcessRequires(model.Requires, id, order)
- if err != nil {
- return id, err
- }
- return id, nil
- }
|