allocation_company_contract.go 9.1 KB

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