ProjectDetail.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package Project
  2. import (
  3. "ERP_project/logs"
  4. orm2 "github.com/beego/beego/v2/client/orm"
  5. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  6. "time"
  7. _ "github.com/astaxie/beego/cache/redis"
  8. "github.com/beego/beego/v2/adapter/orm"
  9. _ "github.com/go-sql-driver/mysql"
  10. )
  11. // 项目明细
  12. type ProjectDetail struct {
  13. Id int `orm:"column(ID);size(11);auto;pk"`
  14. T_project_id int `orm:"index;size(256);null"` // 项目ID
  15. T_function string `orm:"size(256);null"` // 功能与指标
  16. T_planned_time float32 `orm:"digits(12);decimals(2)"` // 计划时间(工作日)
  17. T_finish string `orm:"size(1024);null"` // 是否完成 0 未完成 1 已完成
  18. CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now_add"` //auto_now_add 第一次保存时才设置时间
  19. UpdateTime time.Time `orm:"column(update_time);type(timestamp);null;auto_now"` //auto_now 每次 model 保存时都会对时间自动更新
  20. }
  21. func (t *ProjectDetail) TableName() string {
  22. return "project_detail" // 数据库名称 // ************** 替换 FormulaList **************
  23. }
  24. type ProjectDetailDaoImpl struct {
  25. orm orm.Ormer
  26. }
  27. func NewProjectDetail(orm orm.Ormer) *ProjectDetailDaoImpl {
  28. return &ProjectDetailDaoImpl{orm: orm}
  29. }
  30. //func init() {
  31. // //注册模型
  32. // orm.RegisterModel(new(ProjectDetail))
  33. //}
  34. //type ProjectDetail_R struct {
  35. // T_project_id int // 项目ID
  36. // T_function string // 功能与指标
  37. // T_planned_time float32 // 计划时间(工作日)
  38. // T_finish string // 是否完成 0 未完成 1 已完成
  39. //}
  40. //func ProjectDetailToProjectDetail_R(t ProjectDetail) (r ProjectDetail_R) {
  41. // r.T_project_id = t.T_project_id
  42. // r.T_function = t.T_function
  43. // r.T_planned_time = t.T_planned_time
  44. // r.T_finish = t.T_finish
  45. //
  46. // return r
  47. //}
  48. // 添加
  49. func (dao *ProjectDetailDaoImpl) Add_ProjectDetail(r ProjectDetail) (id int64, err error) {
  50. id, err = dao.orm.Insert(&r)
  51. if err != nil {
  52. logs.Error(lib.FuncName(), err)
  53. }
  54. return id, err
  55. }
  56. // 删除
  57. func (dao *ProjectDetailDaoImpl) Delete_ProjectDetail_ByT_project_id(T_project_id int) error {
  58. // 也可以直接使用 Model 结构体作为表名
  59. qs := dao.orm.QueryTable(new(ProjectDetail))
  60. var list []ProjectDetail
  61. _, err := qs.Filter("T_project_id", T_project_id).All(&list)
  62. if err != nil {
  63. logs.Error(lib.FuncName(), err)
  64. return err
  65. }
  66. if len(list) == 0 {
  67. return nil
  68. }
  69. for _, v := range list {
  70. _, err = dao.orm.Delete(&v)
  71. if err != nil {
  72. logs.Error(lib.FuncName(), err)
  73. return err
  74. }
  75. }
  76. return nil
  77. }
  78. // 获取列表
  79. func (dao *ProjectDetailDaoImpl) Read_ProjectDetail_List(T_project_id int) (r_ []ProjectDetail_R) {
  80. // 也可以直接使用 Model 结构体作为表名
  81. qs := dao.orm.QueryTable(new(ProjectDetail))
  82. // 过滤
  83. cond := orm.NewCondition()
  84. cond = cond.And("T_project_id", T_project_id)
  85. // 查询
  86. var r []ProjectDetail
  87. _, err := qs.SetCond((*orm2.Condition)(cond)).OrderBy("Id").All(&r)
  88. if err != nil {
  89. logs.Error(lib.FuncName(), err)
  90. return
  91. }
  92. //for _, v := range r {
  93. // r_ = append(r_, ProjectDetailToProjectDetail_R(v))
  94. //}
  95. return r_
  96. }
  97. func (dao *ProjectDetailDaoImpl) Read_ProjectDetail_T_State_List(T_number string) (lists orm2.ParamsList) {
  98. o := orm.NewOrm()
  99. var pl_lists orm2.ParamsList
  100. sql := "SELECT DISTINCT t__state FROM contract_product WHERE t_contract_number = " + T_number
  101. _, err := o.Raw(sql).ValuesFlat(&pl_lists)
  102. if err != nil {
  103. logs.Error(lib.FuncName(), err)
  104. return
  105. }
  106. return pl_lists
  107. }