|
@@ -2,6 +2,8 @@ package company
|
|
|
|
|
|
import (
|
|
|
"hongze/hongze_task/models"
|
|
|
+ "hongze/hongze_task/models/company_contract"
|
|
|
+ "hongze/hongze_task/utils"
|
|
|
"rdluck_tools/orm"
|
|
|
"time"
|
|
|
)
|
|
@@ -69,7 +71,7 @@ func TryOutToFormal(companyId, productId, sellerId, companyContractId int, start
|
|
|
}
|
|
|
|
|
|
//服务更新
|
|
|
-func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, startDate, endDate, sellerName, productName string) (err error) {
|
|
|
+func ApplyServiceUpdateOld(companyId, productId, sellerId, companyContractId int, startDate, endDate, sellerName, productName string) (err error) {
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
defer func() {
|
|
@@ -129,3 +131,112 @@ func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, s
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+func ApplyServiceUpdate(companyId, productId, sellerId, companyContractId int, startDate, endDate, sellerName, productName string) (err error) {
|
|
|
+ o := orm.NewOrm()
|
|
|
+ o.Begin()
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ o.Rollback()
|
|
|
+ } else {
|
|
|
+ o.Commit()
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ sql := `UPDATE company_product SET status='正式',start_date=?,end_date=?,modify_time=NOW() WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = o.Raw(sql, startDate, endDate, companyId, productId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //合同权限变更
|
|
|
+ items := make([]*models.CompanyReportPermission, 0)
|
|
|
+ sql = `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //已存在的权限map
|
|
|
+ nowCompanyReportPermissionMap := make(map[int]*models.CompanyReportPermission)
|
|
|
+
|
|
|
+ for _, pv := range items {
|
|
|
+ cpLog := new(models.CompanyPermissionLog)
|
|
|
+ cpLog.CompanyId = companyId
|
|
|
+ cpLog.ChartPermissionId = pv.ChartPermissionId
|
|
|
+ cpLog.CreateTime = time.Now()
|
|
|
+ cpLog.SysUserId = sellerId
|
|
|
+ cpLog.SysUserName = sellerName
|
|
|
+ cpLog.StartDate = pv.StartDate
|
|
|
+ cpLog.EndDate = pv.EndDate
|
|
|
+ cpLog.ProductId = productId
|
|
|
+ cpLog.ProductName = pv.ProductName
|
|
|
+ go models.AddCompanyPermissionLog(cpLog)
|
|
|
+
|
|
|
+ //将权限插入到已存在的权限map中
|
|
|
+ nowCompanyReportPermissionMap[pv.ChartPermissionId] = pv
|
|
|
+ }
|
|
|
+ sql = `DELETE FROM company_report_permission WHERE company_id=? AND product_id=? `
|
|
|
+ _, err = o.Raw(sql, companyId, productId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ contractPermission := make([]*company_contract.CompanyContractPermission, 0)
|
|
|
+ sql = `SELECT * FROM company_contract_permission WHERE company_contract_id=? AND company_id=? `
|
|
|
+ _, err = o.Raw(sql, companyContractId, companyId).QueryRows(&contractPermission)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, pv := range contractPermission {
|
|
|
+ nowPermission, ok := nowCompanyReportPermissionMap[pv.ChartPermissionId]
|
|
|
+ //判断是否已经存在该权限,如果存在的话,那么是修改,否则是新增
|
|
|
+ if ok {
|
|
|
+ needUpdate := false
|
|
|
+ if nowPermission.Status != "正式" && nowPermission.Status != "永续" {
|
|
|
+ needUpdate = true
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果 需要更新 字段 为false,那么再去校验时间
|
|
|
+ if needUpdate == false {
|
|
|
+ //如果当前存该权限,那么去校验是否需要修改
|
|
|
+ nowPermissionEndDateTime, tmpErr := time.Parse(utils.FormatDate, nowPermission.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ contractPermissionEndDateTime, tmpErr := time.Parse(utils.FormatDate, pv.EndDate)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if contractPermissionEndDateTime.After(nowPermissionEndDateTime) {
|
|
|
+ needUpdate = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果 需要更新 字段 为 true,那么就去更新
|
|
|
+ if needUpdate {
|
|
|
+ sql = `update company_report_permission set end_date=?,last_updated_time=now(),modify_time=now(),company_contract_id=?,status=? where company_report_permission_id=? `
|
|
|
+ _, tmpErr := o.Raw(sql, pv.EndDate, companyContractId, "正式", nowPermission.CompanyReportPermissionId).Exec()
|
|
|
+ err = tmpErr
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ sql = `INSERT INTO company_report_permission(company_id, report_permission_id,created_time, last_updated_time,
|
|
|
+ chart_permission_id, start_date,end_date,product_id,product_name, modify_time,company_contract_id,status)
|
|
|
+ VALUES(?,?,NOW(),NOW(),?,?,?,?,?,NOW(),?,?) `
|
|
|
+ _, tmpErr := o.Raw(sql, companyId, pv.ChartPermissionId, pv.ChartPermissionId, pv.StartDate, pv.EndDate, productId, productName, companyContractId, "正式").Exec()
|
|
|
+ err = tmpErr
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|