|
@@ -0,0 +1,155 @@
|
|
|
+package cygx_allocation_company_contract
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/beego/beego/v2/client/orm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// 研究员派点
|
|
|
+type CygxAllocationCompanyContract struct {
|
|
|
+ AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
|
|
|
+ CompanyContractId int `description:"合同id"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"更新时间"`
|
|
|
+ AdminId int `description:"操作人ID"`
|
|
|
+ AdminName string `description:"内容"`
|
|
|
+ Proportion float64 `description:"占比"`
|
|
|
+ Money float64 `description:"金额"`
|
|
|
+ RealName string `description:"研究员姓名"`
|
|
|
+ ChartPermissionName string `description:"行业名称"`
|
|
|
+}
|
|
|
+
|
|
|
+// 研究员派点日志
|
|
|
+type CygxAllocationCompanyContractLog struct {
|
|
|
+ AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
|
|
|
+ CompanyContractId int `description:"合同id"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"更新时间"`
|
|
|
+ AdminId int `description:"操作人ID"`
|
|
|
+ AdminName string `description:"内容"`
|
|
|
+ Proportion float64 `description:"占比"`
|
|
|
+ Money float64 `description:"金额"`
|
|
|
+ RealName string `description:"研究员姓名"`
|
|
|
+ ChartPermissionName string `description:"行业名称"`
|
|
|
+}
|
|
|
+
|
|
|
+// 行业派点
|
|
|
+type CygxAllocationCompanyContractPermission struct {
|
|
|
+ AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
|
|
|
+ CompanyContractId int `description:"合同id"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"更新时间"`
|
|
|
+ AdminId int `description:"操作人ID"`
|
|
|
+ AdminName string `description:"内容"`
|
|
|
+ Proportion float64 `description:"占比"`
|
|
|
+ Money float64 `description:"金额"`
|
|
|
+ MoneyAvg float64 `description:"行业所占合同的平均金额"`
|
|
|
+ ChartPermissionName string `description:"行业名称"`
|
|
|
+}
|
|
|
+
|
|
|
+// 行业派点日志
|
|
|
+type CygxAllocationCompanyContractPermissionLog struct {
|
|
|
+ AllocationCompanyContractId int `orm:"column(allocation_company_contract_id);pk"`
|
|
|
+ CompanyContractId int `description:"合同id"`
|
|
|
+ CreateTime time.Time `description:"创建时间"`
|
|
|
+ ModifyTime time.Time `description:"更新时间"`
|
|
|
+ AdminId int `description:"操作人ID"`
|
|
|
+ AdminName string `description:"内容"`
|
|
|
+ Proportion float64 `description:"占比"`
|
|
|
+ Money float64 `description:"金额"`
|
|
|
+ MoneyAvg float64 `description:"行业所占合同的平均金额"`
|
|
|
+ ChartPermissionName string `description:"行业名称"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 更新派点信息
|
|
|
+func AddAndUpdateCygxAllocationCompanyContract(items []*CygxAllocationCompanyContract, itemsPermission []*CygxAllocationCompanyContractPermission, companyContractId int) (err error) {
|
|
|
+ o := orm.NewOrmUsingDB("hz_cygx")
|
|
|
+ to, err := o.Begin()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ _ = to.Rollback()
|
|
|
+ } else {
|
|
|
+ _ = to.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ //组合研究员派点日志结构体
|
|
|
+ var itemsLog []*CygxAllocationCompanyContractLog
|
|
|
+ for _, v := range items {
|
|
|
+ item := new(CygxAllocationCompanyContractLog)
|
|
|
+ item.CompanyContractId = v.CompanyContractId
|
|
|
+ item.AdminId = v.AdminId
|
|
|
+ item.CompanyContractId = v.CompanyContractId
|
|
|
+ item.AdminName = v.AdminName
|
|
|
+ item.RealName = v.RealName
|
|
|
+ item.ChartPermissionName = v.ChartPermissionName
|
|
|
+ item.Proportion = v.Proportion
|
|
|
+ item.Money = v.Money
|
|
|
+ item.Money = v.Money
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ itemsLog = append(itemsLog, item)
|
|
|
+ }
|
|
|
+
|
|
|
+ //组合行业派点日志结构体
|
|
|
+ var itemsPermissionLog []*CygxAllocationCompanyContractPermissionLog
|
|
|
+ for _, v := range itemsPermission {
|
|
|
+ item := new(CygxAllocationCompanyContractPermissionLog)
|
|
|
+ item.CompanyContractId = v.CompanyContractId
|
|
|
+ item.AdminId = v.AdminId
|
|
|
+ item.CompanyContractId = v.CompanyContractId
|
|
|
+ item.AdminName = v.AdminName
|
|
|
+ item.ChartPermissionName = v.ChartPermissionName
|
|
|
+ item.Proportion = v.Proportion
|
|
|
+ item.Money = v.Money
|
|
|
+ item.MoneyAvg = v.MoneyAvg
|
|
|
+ item.CreateTime = time.Now()
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ itemsPermissionLog = append(itemsPermissionLog, item)
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除原有的研究员派点信息
|
|
|
+ sql := `DELETE FROM cygx_allocation_company_contract WHERE company_contract_id = ?`
|
|
|
+ _, err = to.Raw(sql, companyContractId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //删除原有的行业派点信息
|
|
|
+ sql = ` DELETE FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ?`
|
|
|
+ _, err = to.Raw(sql, companyContractId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量添加研究员派点信息
|
|
|
+ _, err = to.InsertMulti(len(items), items)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = to.InsertMulti(len(itemsLog), itemsLog)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //批量添加行业派点信息
|
|
|
+ _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = to.InsertMulti(len(itemsPermissionLog), itemsPermissionLog)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ ow := orm.NewOrm()
|
|
|
+ sqlW := `UPDATE company_contract SET is_allocation=1 WHERE company_contract_id=? `
|
|
|
+ _, err = ow.Raw(sqlW, companyContractId).Exec()
|
|
|
+
|
|
|
+ return
|
|
|
+}
|