company_contract_no_renewed_ascribe.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. //修改未续约归因
  76. sql := `UPDATE company_contract SET company_ascribe_id = ? WHERE company_contract_id=? `
  77. _, err = to.Raw(sql, item.CompanyAscribeId, item.CompanyContractId).Exec()
  78. return
  79. }
  80. // 修改
  81. func UpdateCompanyContractNoRenewedAscribe(item *CompanyContractNoRenewedAscribe, itemLog *CompanyContractNoRenewedAscribeLog) (err error) {
  82. o := orm.NewOrm()
  83. to, err := o.Begin()
  84. if err != nil {
  85. return
  86. }
  87. defer func() {
  88. if err != nil {
  89. _ = to.Rollback()
  90. } else {
  91. _ = to.Commit()
  92. }
  93. }()
  94. updateParams := make(map[string]interface{})
  95. updateParams["CompanyAscribeId"] = item.CompanyAscribeId
  96. updateParams["ModifyTime"] = item.ModifyTime
  97. updateParams["Content"] = item.Content
  98. updateParams["AscribeContent"] = item.AscribeContent
  99. ptrStructOrTableName := "company_contract_no_renewed_ascribe"
  100. whereParam := map[string]interface{}{"company_id": item.CompanyId, "company_contract_id": item.CompanyContractId}
  101. qs := to.QueryTable(ptrStructOrTableName)
  102. for expr, exprV := range whereParam {
  103. qs = qs.Filter(expr, exprV)
  104. }
  105. _, err = qs.Update(updateParams)
  106. if err != nil {
  107. return
  108. }
  109. _, err = to.Insert(itemLog)
  110. //修改未续约归因
  111. sql := `UPDATE company_contract SET company_ascribe_id = ? WHERE company_contract_id=? `
  112. _, err = to.Raw(sql, item.CompanyAscribeId, item.CompanyContractId).Exec()
  113. return
  114. }
  115. // 获取数量
  116. func GetCompanyContractNoRenewedAscribeCount(condition string, pars []interface{}) (count int, err error) {
  117. sqlCount := ` SELECT COUNT(1) AS count FROM company_contract_no_renewed_ascribe as a WHERE 1= 1 `
  118. if condition != "" {
  119. sqlCount += condition
  120. }
  121. o := orm.NewOrm()
  122. err = o.Raw(sqlCount, pars).QueryRow(&count)
  123. return
  124. }
  125. // 通过ID获取详情
  126. func GetCompanyContractNoRenewedAscribeDetail(companyContractId int) (item *CompanyContractNoRenewedAscribeResp, err error) {
  127. o := orm.NewOrm()
  128. sql := `SELECT * FROM company_contract_no_renewed_ascribe WHERE company_contract_id=? `
  129. err = o.Raw(sql, companyContractId).QueryRow(&item)
  130. return
  131. }
  132. // 列表
  133. func GetCompanyContractNoRenewedAscribeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractNoRenewedAscribeResp, err error) {
  134. o := orm.NewOrm()
  135. sql := `SELECT * FROM company_contract_no_renewed_ascribe as a WHERE 1= 1 `
  136. if condition != "" {
  137. sql += condition
  138. }
  139. if startSize+pageSize > 0 {
  140. sql += ` LIMIT ?,? `
  141. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  142. }
  143. _, err = o.Raw(sql, pars).QueryRows(&items)
  144. return
  145. }