allocation_company_contract.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. ChartPermissionId int `description:"行业id"`
  155. Proportion float64 `description:"占比"`
  156. Money float64 `description:"金额(单位万)"`
  157. MoneyAvg float64 `description:"行业所占合同的平均金额"`
  158. List []*AllocationRealNameListResp
  159. }
  160. // 行业
  161. type AllocationRealNameListResp struct {
  162. RealName string `description:"研究员姓名"`
  163. Proportion float64 `description:"占比"`
  164. Money float64 `description:"金额(单位万)"`
  165. ChartPermissionId int `description:"行业id"`
  166. }
  167. // 获取数量
  168. func GetCygxAllocationCompanyContractCountByCompanyContractId(companyContractId int) (count int, err error) {
  169. o := orm.NewOrmUsingDB("hz_cygx")
  170. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_allocation_company_contract WHERE company_contract_id = ? `
  171. err = o.Raw(sqlCount, companyContractId).QueryRow(&count)
  172. return
  173. }
  174. // 研究员列表
  175. func GetCygxAllocationCompanyContractListById(companyContractId int) (items []*CygxAllocationCompanyContract, err error) {
  176. o := orm.NewOrmUsingDB("hz_cygx")
  177. sql := `SELECT * FROM cygx_allocation_company_contract WHERE company_contract_id = ? `
  178. _, err = o.Raw(sql, companyContractId).QueryRows(&items)
  179. return
  180. }
  181. // 研究员列表
  182. func GetCygxAllocationCompanyContractList(condition string, pars []interface{}) (items []*CygxAllocationCompanyContract, err error) {
  183. o := orm.NewOrmUsingDB("hz_cygx")
  184. sql := `SELECT * FROM cygx_allocation_company_contract as art WHERE 1= 1 `
  185. if condition != "" {
  186. sql += condition
  187. }
  188. _, err = o.Raw(sql, pars).QueryRows(&items)
  189. return
  190. }
  191. // 行业列表
  192. func GetCygxAllocationCompanyContractPermissionListById(companyContractId int) (items []*AllocationPermissionListResp, err error) {
  193. o := orm.NewOrmUsingDB("hz_cygx")
  194. sql := ` SELECT * FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ? `
  195. _, err = o.Raw(sql, companyContractId).QueryRows(&items)
  196. return
  197. }
  198. // 行业列表
  199. func GetCygxAllocationCompanyContractPermissionList(condition string, pars []interface{}) (items []*AllocationPermissionListResp, err error) {
  200. o := orm.NewOrmUsingDB("hz_cygx")
  201. sql := ` SELECT * FROM cygx_allocation_company_contract_permission as art WHERE 1= 1 `
  202. if condition != "" {
  203. sql += condition
  204. }
  205. _, err = o.Raw(sql, pars).QueryRows(&items)
  206. return
  207. }
  208. type CygxAllocationCompanyContractDetailStatisticsResp struct {
  209. List []*AllocationPermissionStatisticsListResp
  210. TotalContract int `description:"关联合同总计"`
  211. TotalMoney float64 `description:"总派点总计"`
  212. }
  213. // 行业
  214. type AllocationPermissionStatisticsListResp struct {
  215. ChartPermissionName string `description:"行业名称"`
  216. List []*AllocationRealNameStatisticsListResp
  217. }
  218. // 行业
  219. type AllocationRealNameStatisticsListResp struct {
  220. RealName string `description:"研究员姓名"`
  221. TotalRelatedContract float64 `description:"关联合同"`
  222. TotalDispatchPoint string `description:"总派点"`
  223. GroupProportion string `description:"组内占比"`
  224. DepartmentProportion string `description:"部门占比"`
  225. }