company_contract_merge.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package company
  2. import (
  3. //"fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CompanyContractMerge struct {
  8. CompanyContractMergeId int `orm:"column(company_contract_merge_id);pk" description:"主键ID"`
  9. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  10. ProductId int `description:"产品id"`
  11. ProductName string `description:"产品名称"`
  12. CompanyId int `description:"客户id"`
  13. CompanyProductId int `description:"客户产品id"`
  14. StartDate string `description:"合同开始时间"`
  15. EndDate string `description:"合同结束时间"`
  16. Money float64 `description:"合同金额"`
  17. CreateTime time.Time `description:"合同创建时间"`
  18. ModifyTime time.Time `description:"合同修改时间"`
  19. CompanyContractIdGroup string `description:"表company_contract合并的 company_contract_id"`
  20. ChartPermissionName string `description:"权限类目名称"`
  21. PackageDifference string `description:"和上一份合同的区别"`
  22. IsBestNew int `description:"是否是最新的一条数据"`
  23. }
  24. type CompanyContractMergeResp struct {
  25. CompanyContractMergeId int `orm:"column(company_contract_merge_id);pk" description:"主键ID"`
  26. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  27. ProductId int `description:"产品id"`
  28. ProductName string `description:"产品名称"`
  29. CompanyId int `description:"客户id"`
  30. CompanyProductId int `description:"客户产品id"`
  31. StartDate time.Time `description:"合同开始时间"`
  32. EndDate time.Time `description:"合同结束时间"`
  33. Money float64 `description:"合同金额"`
  34. CreateTime time.Time `description:"合同创建时间"`
  35. ModifyTime time.Time `description:"合同修改时间"`
  36. CompanyContractIdGroup string `description:"表company_contract合并的 company_contract_id"`
  37. ChartPermissionName string `description:"权限类目名称"`
  38. PackageDifference string `description:"和上一份合同的区别"`
  39. }
  40. type CompanyContractMergeDetailResp struct {
  41. CompanyContractMergeId int `orm:"column(company_contract_merge_id);pk" description:"主键ID"`
  42. ContractType string `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
  43. ProductId int `description:"产品id"`
  44. ProductName string `description:"产品名称"`
  45. CompanyId int `description:"客户id"`
  46. CompanyProductId int `description:"客户产品id"`
  47. StartDate string `description:"合同开始时间"`
  48. EndDate string `description:"合同结束时间"`
  49. Money float64 `description:"合同金额"`
  50. CreateTime time.Time `description:"合同创建时间"`
  51. ModifyTime time.Time `description:"合同修改时间"`
  52. CompanyContractIdGroup string `description:"表company_contract合并的 company_contract_id"`
  53. ChartPermissionName string `description:"权限类目名称"`
  54. PackageDifference string `description:"和上一份合同的区别"`
  55. PermissionName string `description:"权限名"`
  56. }
  57. func AddCompanyContractMerge(item *CompanyContractMerge) (err error) {
  58. o := orm.NewOrm()
  59. _, err = o.Insert(item)
  60. return
  61. }
  62. // MultiAddCompanyContractMerge 批量添加合同合并之后的数据
  63. func MultiAddCompanyContractMerge(items []*CompanyContractMerge) (err error) {
  64. if len(items) == 0 {
  65. return
  66. }
  67. o := orm.NewOrm()
  68. _, err = o.InsertMulti(len(items), items)
  69. return
  70. }
  71. // 修改
  72. func UpdateCompanyContractMerge(item *CompanyContractMerge) (err error) {
  73. o := orm.NewOrm()
  74. to, err := o.Begin()
  75. if err != nil {
  76. return
  77. }
  78. defer func() {
  79. if err != nil {
  80. _ = to.Rollback()
  81. } else {
  82. _ = to.Commit()
  83. }
  84. }()
  85. updateParams := make(map[string]interface{})
  86. updateParams["EndDate"] = item.EndDate
  87. updateParams["Money"] = item.Money
  88. updateParams["CompanyContractIdGroup"] = item.CompanyContractIdGroup
  89. updateParams["PackageDifference"] = item.PackageDifference
  90. updateParams["IsBestNew"] = item.IsBestNew
  91. updateParams["ModifyTime"] = item.ModifyTime
  92. ptrStructOrTableName := "company_contract_merge"
  93. whereParam := map[string]interface{}{"company_contract_merge_id": item.CompanyContractMergeId}
  94. qs := to.QueryTable(ptrStructOrTableName)
  95. for expr, exprV := range whereParam {
  96. qs = qs.Filter(expr, exprV)
  97. }
  98. _, err = qs.Update(updateParams)
  99. if err != nil {
  100. return
  101. }
  102. return
  103. }
  104. // GetIncrementalNewCompanyProductMergeCount 获取增量客户产品报表列表统计数据(根据合同来展示)
  105. func GetIncrementalNewCompanyProductMergeCount(condition string, pars []interface{}) (total int, err error) {
  106. o := orm.NewOrm()
  107. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  108. JOIN company b ON a.company_id = b.company_id
  109. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
  110. if condition != "" {
  111. sql += condition
  112. }
  113. sql = `select count(1) count from (` + sql + ` ) f`
  114. err = o.Raw(sql, pars).QueryRow(&total)
  115. return
  116. }
  117. // GetIncrementalRenewalCompanyProductMergeCount 续约合同数量
  118. func GetIncrementalRenewalCompanyProductMergeCount(condition string, pars []interface{}) (total int, err error) {
  119. o := orm.NewOrm()
  120. sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
  121. JOIN company b ON a.company_id = b.company_id
  122. JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
  123. if condition != "" {
  124. sql += condition
  125. }
  126. sql = `select count(1) count from (` + sql + ` ) f`
  127. err = o.Raw(sql, pars).QueryRow(&total)
  128. return
  129. }
  130. type GetCompanyContractMergeDetailResp struct {
  131. Detail *CompanyContractMergeDetailResp
  132. }
  133. // 通过ID获取详情
  134. //func GetCompanyContractMergeDetail(condition string, pars []interface{}) (item *CompanyContractMergeDetailResp, err error) {
  135. // o := orm.NewOrm()
  136. // sql := `SELECT * FROM company_contract_merge WHERE 1= 1 ` + condition
  137. // err = o.Raw(sql, pars).QueryRow(&item)
  138. // return
  139. //}
  140. //
  141. //// UpdateCompanyContractMergeIsBestNew 更改 is_best_new 状态
  142. //func UpdateCompanyContractMergeIsBestNew(isBestNew, companyId int) (err error) {
  143. // o := orm.NewOrm()
  144. // sql := `UPDATE company_contract_merge SET is_best_new = ? WHERE company_id=? `
  145. // _, err = o.Raw(sql, isBestNew, companyId).Exec()
  146. // return
  147. //}
  148. //
  149. //// UpdateCompanyContractMergeIsBestNew 更改 is_best_new 状态
  150. //func UpdateCompanyContractMergeIsBestNewto1(companyContractMergeId int) (err error) {
  151. // o := orm.NewOrm()
  152. // sql := `UPDATE company_contract_merge SET is_best_new = 1 WHERE company_contract_merge_id=? `
  153. // _, err = o.Raw(sql, companyContractMergeId).Exec()
  154. // return
  155. //}