final_mat_item.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package final
  2. import (
  3. "fmt"
  4. "strings"
  5. "zhiyuan/pkg/db"
  6. "github.com/gin-gonic/gin"
  7. )
  8. type FinalMatItem struct {
  9. ID int64 `json:"id" prop:"add:false"`
  10. Name string `json:"name" label:"项目名称" type:"string" prop:"add edit" search:"like"`
  11. Type int64 `json:"type" label:"类型" type:"int" prop:"add edit" search:"="`
  12. TypeId int64 `json:"type_id" label:"辅材类型" type:"int" prop:"edit" search:"="`
  13. PType int64 `json:"ptype" label:"类型" type:"int" prop:"edit" search:"="`
  14. MatTypeIds string `json:"mattype_ids" label:"选材类型" type:"string" prop:"add edit"`
  15. OrderAt int64 `json:"order_at" prop:"add:false select:false"`
  16. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  17. CreatedAt int64 `json:"created_at" prop:"add:false"`
  18. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  19. db.BaseModel
  20. }
  21. func (FinalMatItem) TableName() string {
  22. return "zy_final_mat_item"
  23. }
  24. func (model FinalMatItem) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  25. if mattype_id, ok := data["mattype_id"]; ok {
  26. mattype_id, _ = db.ToInt64(mattype_id)
  27. var mattype FinalMatType
  28. db.GetModel(map[string]interface{}{
  29. "id": mattype_id,
  30. }, &mattype)
  31. where := "1=2"
  32. where += fmt.Sprintf(" OR find_in_set(%s, `%s`.`mattype_ids`)", s.Param(mattype.ID), model.TableName())
  33. for _, v := range strings.Split(mattype.Path, ",") {
  34. if v != "" {
  35. i, _ := db.ToInt64(v)
  36. where += fmt.Sprintf(" OR find_in_set(%s, `%s`.`mattype_ids`)", s.Param(i), model.TableName())
  37. }
  38. }
  39. s.Where = append(s.Where, where)
  40. }
  41. return true
  42. }
  43. func (FinalMatItem) OnePrivilege(c *gin.Context, id int64) bool {
  44. return true
  45. }
  46. func (FinalMatItem) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  47. return nil
  48. }
  49. func (FinalMatItem) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  50. return nil
  51. }
  52. func (FinalMatItem) DelPrivilege(c *gin.Context, id int64) error {
  53. return nil
  54. }
  55. func (FinalMatItem) OrderField() string {
  56. return "order_at"
  57. }
  58. func (FinalMatItem) Page() bool {
  59. return false
  60. }
  61. func (FinalMatItem) Count() bool {
  62. return true
  63. }
  64. func (model FinalMatItem) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  65. return []db.JoinModel{}
  66. }