company_contract_no_renewed_ascribe.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package company
  2. //合同未续约说明
  3. import (
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CompanyContractNoRenewedAscribe struct {
  8. NoRenewedAscribeId int `orm:"column(no_renewed_ascribe_id);pk" description:"主键ID"`
  9. CompanyAscribeId int `description:"归因ID"`
  10. AscribeContent string `description:"归因说明"`
  11. Content string `description:"内容说明"`
  12. AdminId int `description:"管理员ID"`
  13. CompanyId int `description:"公司ID"`
  14. CompanyContractId int `description:"合同id"`
  15. ProductId int `description:"产品id"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"更新时间"`
  18. }
  19. type CompanyContractNoRenewedAscribeLog struct {
  20. NoRenewedAscribeId int `orm:"column(no_renewed_ascribe_id);pk" description:"主键ID"`
  21. CompanyAscribeId int `description:"归因ID"`
  22. AscribeContent string `description:"归因说明"`
  23. Content string `description:"内容说明"`
  24. AdminId int `description:"管理员ID"`
  25. CompanyId int `description:"公司ID"`
  26. CompanyContractId int `description:"合同id"`
  27. ProductId int `description:"产品id"`
  28. CreateTime time.Time `description:"创建时间"`
  29. ModifyTime time.Time `description:"更新时间"`
  30. }
  31. type CompanyContractNoRenewedAscribeResp struct {
  32. NoRenewedAscribeId int `description:"主键ID"`
  33. CompanyAscribeId int `description:"归因ID"`
  34. AscribeContent string `description:"归因说明"`
  35. ProductId int `description:"产品id"`
  36. Content string `description:"内容说明"`
  37. AdminId int `description:"管理员ID"`
  38. CompanyId int `description:"公司ID"`
  39. CompanyContractId int `description:"合同id"`
  40. CreateTime string `description:"创建时间"`
  41. ModifyTime string `description:"更新时间"`
  42. }
  43. type CompanyContractNoRenewedAscribeListResp struct {
  44. List []*CompanyContractNoRenewedAscribeResp
  45. }
  46. type CompanyContractNoRenewedAscribeDetailResp struct {
  47. Detail *CompanyContractNoRenewedAscribeResp
  48. }
  49. type CompanyContractNoRenewedAscribeReq struct {
  50. CompanyAscribeId int `description:"归因ID"`
  51. ProductId int `description:"产品id"`
  52. Content string `description:"内容说明"`
  53. CompanyId int `description:"公司ID"`
  54. CompanyContractId int `description:"合同id"`
  55. }
  56. // 添加
  57. func AddCompanyContractNoRenewedAscribe(item *CompanyContractNoRenewedAscribe, itemLog *CompanyContractNoRenewedAscribeLog) (err error) {
  58. o := orm.NewOrm()
  59. to, err := o.Begin()
  60. if err != nil {
  61. return
  62. }
  63. defer func() {
  64. if err != nil {
  65. _ = to.Rollback()
  66. } else {
  67. _ = to.Commit()
  68. }
  69. }()
  70. _, err = to.Insert(item)
  71. if err != nil {
  72. return
  73. }
  74. _, err = to.Insert(itemLog)
  75. return
  76. }
  77. // 修改
  78. func UpdateCompanyContractNoRenewedAscribe(item *CompanyContractNoRenewedAscribe, itemLog *CompanyContractNoRenewedAscribeLog) (err error) {
  79. o := orm.NewOrm()
  80. to, err := o.Begin()
  81. if err != nil {
  82. return
  83. }
  84. defer func() {
  85. if err != nil {
  86. _ = to.Rollback()
  87. } else {
  88. _ = to.Commit()
  89. }
  90. }()
  91. updateParams := make(map[string]interface{})
  92. updateParams["CompanyAscribeId"] = item.CompanyAscribeId
  93. updateParams["ModifyTime"] = item.ModifyTime
  94. updateParams["Content"] = item.Content
  95. updateParams["AscribeContent"] = item.AscribeContent
  96. ptrStructOrTableName := "company_contract_no_renewed_ascribe"
  97. whereParam := map[string]interface{}{"company_id": item.CompanyId, "company_contract_id": item.CompanyContractId}
  98. qs := to.QueryTable(ptrStructOrTableName)
  99. for expr, exprV := range whereParam {
  100. qs = qs.Filter(expr, exprV)
  101. }
  102. _, err = qs.Update(updateParams)
  103. if err != nil {
  104. return
  105. }
  106. _, err = to.Insert(itemLog)
  107. return
  108. }
  109. // 获取数量
  110. func GetCompanyContractNoRenewedAscribeCount(condition string, pars []interface{}) (count int, err error) {
  111. sqlCount := ` SELECT COUNT(1) AS count FROM company_contract_no_renewed_ascribe as a WHERE 1= 1 `
  112. if condition != "" {
  113. sqlCount += condition
  114. }
  115. o := orm.NewOrm()
  116. err = o.Raw(sqlCount, pars).QueryRow(&count)
  117. return
  118. }
  119. // 通过ID获取详情
  120. func GetCompanyContractNoRenewedAscribeDetail(companyContractId int) (item *CompanyContractNoRenewedAscribeResp, err error) {
  121. o := orm.NewOrm()
  122. sql := `SELECT * FROM company_contract_no_renewed_ascribe WHERE company_contract_id=? `
  123. err = o.Raw(sql, companyContractId).QueryRow(&item)
  124. return
  125. }
  126. // 列表
  127. func GetCompanyContractNoRenewedAscribeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractNoRenewedAscribeResp, err error) {
  128. o := orm.NewOrm()
  129. sql := `SELECT * FROM company_contract_no_renewed_ascribe as a WHERE 1= 1 `
  130. if condition != "" {
  131. sql += condition
  132. }
  133. if startSize+pageSize > 0 {
  134. sql += ` LIMIT ?,? `
  135. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  136. }
  137. _, err = o.Raw(sql, pars).QueryRows(&items)
  138. return
  139. }