allocation_company_contract.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // 研究员派点
  7. type CygxAllocationCompanyContract struct {
  8. AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
  9. CompanyContractId int `description:"合同id"`
  10. CreateTime time.Time `description:"创建时间"`
  11. ModifyTime time.Time `description:"更新时间"`
  12. AdminId int `description:"操作人ID"`
  13. AdminName string `description:"内容"`
  14. Proportion float64 `description:"占比"`
  15. Money float64 `description:"金额"`
  16. RealName string `description:"研究员姓名"`
  17. ChartPermissionName string `description:"行业名称"`
  18. }
  19. // 研究员派点日志
  20. type CygxAllocationCompanyContractLog struct {
  21. AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
  22. CompanyContractId int `description:"合同id"`
  23. CreateTime time.Time `description:"创建时间"`
  24. ModifyTime time.Time `description:"更新时间"`
  25. AdminId int `description:"操作人ID"`
  26. AdminName string `description:"内容"`
  27. Proportion float64 `description:"占比"`
  28. Money float64 `description:"金额"`
  29. RealName string `description:"研究员姓名"`
  30. ChartPermissionName string `description:"行业名称"`
  31. }
  32. // 行业派点
  33. type CygxAllocationCompanyContractPermission struct {
  34. AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
  35. CompanyContractId int `description:"合同id"`
  36. CreateTime time.Time `description:"创建时间"`
  37. ModifyTime time.Time `description:"更新时间"`
  38. AdminId int `description:"操作人ID"`
  39. AdminName string `description:"内容"`
  40. Proportion float64 `description:"占比"`
  41. Money float64 `description:"金额"`
  42. ChartPermissionName string `description:"行业名称"`
  43. }
  44. // 行业派点日志
  45. type CygxAllocationCompanyContractPermissionLog struct {
  46. AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
  47. CompanyContractId int `description:"合同id"`
  48. CreateTime time.Time `description:"创建时间"`
  49. ModifyTime time.Time `description:"更新时间"`
  50. AdminId int `description:"操作人ID"`
  51. AdminName string `description:"内容"`
  52. Proportion float64 `description:"占比"`
  53. Money float64 `description:"金额"`
  54. ChartPermissionName string `description:"行业名称"`
  55. }
  56. // 更新派点信息
  57. func AddAndUpdateCygxAllocationCompanyContract(items []*CygxAllocationCompanyContract, itemsPermission []*CygxAllocationCompanyContractPermission, companyContractId int) (err error) {
  58. o := orm.NewOrmUsingDB("hz_cygx")
  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. //组合研究员派点日志结构体
  71. var itemsLog []*CygxAllocationCompanyContractLog
  72. for _, v := range items {
  73. item := new(CygxAllocationCompanyContractLog)
  74. item.CompanyContractId = v.CompanyContractId
  75. item.AdminId = v.AdminId
  76. item.CompanyContractId = v.CompanyContractId
  77. item.AdminName = v.AdminName
  78. item.RealName = v.RealName
  79. item.ChartPermissionName = v.ChartPermissionName
  80. item.Proportion = v.Proportion
  81. item.Money = v.Money
  82. item.CreateTime = time.Now()
  83. item.ModifyTime = time.Now()
  84. itemsLog = append(itemsLog, item)
  85. }
  86. //组合行业派点日志结构体
  87. var itemsPermissionLog []*CygxAllocationCompanyContractPermissionLog
  88. for _, v := range itemsPermission {
  89. item := new(CygxAllocationCompanyContractPermissionLog)
  90. item.CompanyContractId = v.CompanyContractId
  91. item.AdminId = v.AdminId
  92. item.CompanyContractId = v.CompanyContractId
  93. item.AdminName = v.AdminName
  94. item.ChartPermissionName = v.ChartPermissionName
  95. item.Proportion = v.Proportion
  96. item.Money = v.Money
  97. item.CreateTime = time.Now()
  98. item.ModifyTime = time.Now()
  99. itemsPermissionLog = append(itemsPermissionLog, item)
  100. }
  101. //删除原有的研究员派点信息
  102. sql := `DELETE FROM cygx_allocation_company_contract WHERE company_contract_id = ?`
  103. _, err = to.Raw(sql, companyContractId).Exec()
  104. if err != nil {
  105. return
  106. }
  107. //删除原有的行业派点信息
  108. sql = ` DELETE FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ?`
  109. _, err = to.Raw(sql, companyContractId).Exec()
  110. if err != nil {
  111. return
  112. }
  113. //批量添加研究员派点信息
  114. _, err = to.InsertMulti(len(items), items)
  115. if err != nil {
  116. return
  117. }
  118. _, err = to.InsertMulti(len(itemsLog), itemsLog)
  119. if err != nil {
  120. return
  121. }
  122. //批量添加行业派点信息
  123. _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
  124. if err != nil {
  125. return
  126. }
  127. _, err = to.InsertMulti(len(itemsPermissionLog), itemsPermissionLog)
  128. if err != nil {
  129. return
  130. }
  131. ow := orm.NewOrm()
  132. sqlW := `UPDATE company_contract SET is_allocation=1 WHERE company_contract_id=? `
  133. _, err = ow.Raw(sqlW, companyContractId).Exec()
  134. return
  135. }
  136. type UpdateAllocationCompanyContractReq struct {
  137. CompanyContractId int `description:"合同ID"`
  138. List []*AllocationPermissionListResp
  139. }
  140. type CygxAllocationCompanyContractDetailResp struct {
  141. CompanyContractId int `description:"合同ID"`
  142. Money float64 `description:"金额(单位万)"`
  143. TotalPointsContent string `description:"总点数描述"`
  144. IsGray bool `description:"是否置灰"`
  145. List []*AllocationPermissionListResp
  146. }
  147. // 行业
  148. type AllocationPermissionListResp struct {
  149. ChartPermissionName string `description:"行业名称"`
  150. Proportion float64 `description:"占比"`
  151. Money float64 `description:"金额(单位万)"`
  152. List []*AllocationRealNameListResp
  153. }
  154. // 行业
  155. type AllocationRealNameListResp struct {
  156. RealName string `description:"研究员姓名"`
  157. Proportion float64 `description:"占比"`
  158. Money float64 `description:"金额(单位万)"`
  159. }
  160. // 获取数量
  161. func GetCygxAllocationCompanyContractCountByCompanyContractId(companyContractId int) (count int, err error) {
  162. o := orm.NewOrmUsingDB("hz_cygx")
  163. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_allocation_company_contract WHERE company_contract_id = ? `
  164. err = o.Raw(sqlCount, companyContractId).QueryRow(&count)
  165. return
  166. }
  167. // 研究员列表
  168. func GetCygxAllocationCompanyContractListById(companyContractId int) (items []*CygxAllocationCompanyContract, err error) {
  169. o := orm.NewOrmUsingDB("hz_cygx")
  170. sql := `SELECT * FROM cygx_allocation_company_contract WHERE company_contract_id = ? `
  171. _, err = o.Raw(sql, companyContractId).QueryRows(&items)
  172. return
  173. }
  174. // 研究员列表
  175. func GetCygxAllocationCompanyContractList(condition string, pars []interface{}) (items []*CygxAllocationCompanyContract, err error) {
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. sql := `SELECT * FROM cygx_allocation_company_contract as art WHERE 1= 1 `
  178. if condition != "" {
  179. sql += condition
  180. }
  181. _, err = o.Raw(sql, pars).QueryRows(&items)
  182. return
  183. }
  184. // 行业列表
  185. func GetCygxAllocationCompanyContractPermissionListById(companyContractId int) (items []*AllocationPermissionListResp, err error) {
  186. o := orm.NewOrmUsingDB("hz_cygx")
  187. sql := ` SELECT * FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ? `
  188. _, err = o.Raw(sql, companyContractId).QueryRows(&items)
  189. return
  190. }
  191. type CygxAllocationCompanyContractDetailStatisticsResp struct {
  192. List []*AllocationPermissionStatisticsListResp
  193. TotalContract int `description:"关联合同总计"`
  194. TotalMoney float64 `description:"总派点总计"`
  195. }
  196. // 行业
  197. type AllocationPermissionStatisticsListResp struct {
  198. ChartPermissionName string `description:"行业名称"`
  199. List []*AllocationRealNameStatisticsListResp
  200. }
  201. // 行业
  202. type AllocationRealNameStatisticsListResp struct {
  203. RealName string `description:"研究员姓名"`
  204. TotalRelatedContract float64 `description:"关联合同"`
  205. TotalDispatchPoint string `description:"总派点"`
  206. GroupProportion string `description:"组内占比"`
  207. DepartmentProportion string `description:"部门占比"`
  208. }