|
@@ -1,22 +1,26 @@
|
|
|
package contract
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"hongze/hongze_mobile_admin/models/custom"
|
|
|
contractCustom "hongze/hongze_mobile_admin/models/custom/contract"
|
|
|
+ contractReq "hongze/hongze_mobile_admin/models/request/contract"
|
|
|
contractResp "hongze/hongze_mobile_admin/models/response/contract"
|
|
|
+ "hongze/hongze_mobile_admin/models/tables/company_report_permission"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_approval"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_approval_record"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_operation_record"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_service_detail"
|
|
|
"hongze/hongze_mobile_admin/utils"
|
|
|
+ "reflect"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-//作废合同
|
|
|
+// InvalidContract 作废合同
|
|
|
func InvalidContract(contractId int, opUser *custom.AdminWx) (err error) {
|
|
|
//查询当前合同信息
|
|
|
nowContract, err := contract.GetContractById(contractId)
|
|
@@ -52,7 +56,7 @@ func InvalidContract(contractId int, opUser *custom.AdminWx) (err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//根据id获取合同详情(包含服务)
|
|
|
+// GetContractDetail 根据id获取合同详情(包含服务)
|
|
|
func GetContractDetail(contractId int) (contractDetail *contract.ContractDetail, err error) {
|
|
|
contractDetail, err = contract.GetContractDetailById(contractId)
|
|
|
if err != nil {
|
|
@@ -80,7 +84,7 @@ func GetContractDetail(contractId int) (contractDetail *contract.ContractDetail,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//上传签回合同附件
|
|
|
+// UploadCheckBackFile 上传签回合同附件
|
|
|
func UploadCheckBackFile(contractId int, fileUrl string, opUser *custom.AdminWx) (err error) {
|
|
|
//获取合同信息
|
|
|
contractInfo, err := contract.GetContractById(contractId)
|
|
@@ -107,7 +111,7 @@ func UploadCheckBackFile(contractId int, fileUrl string, opUser *custom.AdminWx)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//获取审批流和权限
|
|
|
+// GetOpButton 获取审批流和权限
|
|
|
func GetOpButton(contractInfo *contract.ContractDetail, contractApprovalInfo *contract_approval.ContractApproval, opUser *custom.AdminWx) (contractOpButton contractResp.OpButton, flowNodeListResp [][]contract_approval_record.ContractApprovalRecord, err error) {
|
|
|
//审批流
|
|
|
approvalRecordList, err := contract_approval_record.GetContractApprovalRecordListByContractApprovalId(contractApprovalInfo.ContractApprovalId)
|
|
@@ -151,7 +155,7 @@ func GetOpButton(contractInfo *contract.ContractDetail, contractApprovalInfo *co
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//根据合同获取合同详情
|
|
|
+// GetContractDetailByContractId 根据合同获取合同详情
|
|
|
func GetContractDetailByContractId(contractId int, opUser *custom.AdminWx) (contractInfo *contract.ContractDetail, flowNodeListResp [][]contract_approval_record.ContractApprovalRecord, opButton contractResp.OpButton, err error) {
|
|
|
contractInfo, err = GetContractDetail(contractId)
|
|
|
if err != nil {
|
|
@@ -164,6 +168,10 @@ func GetContractDetailByContractId(contractId int, opUser *custom.AdminWx) (cont
|
|
|
contractInfo.ModifyTimeStr = contractInfo.ModifyTime.Format(utils.FormatDateTime)
|
|
|
contractInfo.CreateTimeStr = contractInfo.CreateTime.Format(utils.FormatDateTime)
|
|
|
|
|
|
+ //合同中包含的产品权限
|
|
|
+ permissionLookList, _ := GetPermissionByContractService(contractInfo.ProductId, contractInfo.Service)
|
|
|
+ contractInfo.PermissionLookList = permissionLookList
|
|
|
+
|
|
|
//查询最近一次审批单信息
|
|
|
lastApprovalInfo, err := contract_approval.GetLastContractApprovalByContractId(contractInfo.ContractId, "contract")
|
|
|
if err != nil {
|
|
@@ -185,3 +193,151 @@ func GetContractDetailByContractId(contractId int, opUser *custom.AdminWx) (cont
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetProductCelData 获取品种列数据(因为前端可以随意插入列数据,所以需要根据列名来搜索对应的品种列)
|
|
|
+func GetProductCelData(detail contract_service_detail.ContractServiceDetail, tableCel *contractReq.AddContractServiceDetailReq) (err error) {
|
|
|
+ t := reflect.TypeOf(detail)
|
|
|
+ v := reflect.ValueOf(detail)
|
|
|
+ for k := 0; k < t.NumField(); k++ {
|
|
|
+ //获取结构体的参数名
|
|
|
+ tmpName := t.Field(k).Name
|
|
|
+ if strings.Contains(tmpName, "Col") {
|
|
|
+ //获取结构体该参数名的值
|
|
|
+ tmpValue := v.Field(k).String()
|
|
|
+ //如果值不为空的话,那么做下json转换
|
|
|
+ if tmpValue != "" {
|
|
|
+ tmpErr := json.Unmarshal([]byte(tmpValue), tableCel)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if tableCel.HeadName == "品种" {
|
|
|
+ err = nil
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetPermissionByContractService 通过合同服务,获取权限集合列表
|
|
|
+func GetPermissionByContractService(productId int, serviceList []*contractCustom.ContractServiceAndDetail) (permissionList []*company_report_permission.PermissionLookList, err error) {
|
|
|
+ //子权限切片集合
|
|
|
+ var permissionClassifyArr []string
|
|
|
+ if productId == 1 {
|
|
|
+ for _, v := range utils.PermissionFiccClassifyArr {
|
|
|
+ permissionClassifyArr = append(permissionClassifyArr, v)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ permissionClassifyArr = append(permissionClassifyArr, "权益")
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取已经勾选的的权限
|
|
|
+ checkPermissionIdMap, err := GetServicePermissionMap(serviceList)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //遍历获取
|
|
|
+ for _, v := range permissionClassifyArr {
|
|
|
+ checkList := make([]int, 0)
|
|
|
+ plist := new(company_report_permission.PermissionLookList)
|
|
|
+ items, tmpErr := company_report_permission.GetPermissionLookItems(productId, v)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, n := range items {
|
|
|
+ if _, ok := checkPermissionIdMap[n.ChartPermissionId]; ok {
|
|
|
+ checkList = append(checkList, n.ChartPermissionId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ plist.Items = items
|
|
|
+ plist.ClassifyName = v
|
|
|
+ plist.CheckList = checkList
|
|
|
+
|
|
|
+ permissionList = append(permissionList, plist)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetServicePermissionMap 获取合同服务中的权限id map
|
|
|
+func GetServicePermissionMap(serviceList []*contractCustom.ContractServiceAndDetail) (checkPermissionIdMap map[int]int, err error) {
|
|
|
+ checkPermissionIdMap = make(map[int]int)
|
|
|
+
|
|
|
+ //获取已经勾选的的权限
|
|
|
+ for _, contractService := range serviceList {
|
|
|
+ //如果是权益,那么研选必要
|
|
|
+ if contractService.ProductId == 2 {
|
|
|
+ chartPermissionId := 31 //研 选服务
|
|
|
+ checkPermissionIdMap[chartPermissionId] = chartPermissionId
|
|
|
+ }
|
|
|
+
|
|
|
+ //看看系统中有没有映射对应的权限,如果有的话,那么直接返回,没有那么可能是特殊服务,需要去遍历
|
|
|
+ if contractService.ChartPermissionId > 0 {
|
|
|
+ checkPermissionIdMap[contractService.ChartPermissionId] = contractService.ChartPermissionId
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ switch contractService.ServiceTemplateId {
|
|
|
+ case 1: //ficc 大套餐
|
|
|
+ for _, v := range utils.PermissionFiccClassifyArr {
|
|
|
+ //大套餐中 市场策略暂时不作为勾选项
|
|
|
+ if v == "市场策略" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ items, tmpErr := company_report_permission.GetPermissionLookItems(1, v)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, n := range items {
|
|
|
+ checkPermissionIdMap[n.ChartPermissionId] = n.ChartPermissionId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case 2: //ficc小套餐
|
|
|
+ permissionValues := []string{
|
|
|
+ "FICC周报", "商品双周报+线上电话会讨论会<br/>(由弘则的研究员主持线上讨论)", "数据点评",
|
|
|
+ }
|
|
|
+ for _, detail := range contractService.DetailList {
|
|
|
+ var tableCel contractReq.AddContractServiceDetailReq
|
|
|
+ tmpErr := json.Unmarshal([]byte(detail.Col1), &tableCel)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if strings.Contains(strings.Join(permissionValues, ","), tableCel.Value) {
|
|
|
+ //获取品种列数据
|
|
|
+ var tableCel2 contractReq.AddContractServiceDetailReq
|
|
|
+ tmpErr := GetProductCelData(*detail, &tableCel2)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, serviceId := range tableCel2.ValueId {
|
|
|
+ checkPermissionIdMap[serviceId] = serviceId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ case 4, 5, 6: //权益大套餐
|
|
|
+ permissionFiccClassifyArr := []string{"权益"}
|
|
|
+ for _, v := range permissionFiccClassifyArr {
|
|
|
+ items, tmpErr := company_report_permission.GetPermissionLookItems(2, v)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, n := range items {
|
|
|
+ //如果是专家行业,那么 结束当前循环,进入下一循环(产品需求:专家行业不在里面)
|
|
|
+ if n.ChartPermissionId == 29 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ checkPermissionIdMap[n.ChartPermissionId] = n.ChartPermissionId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|