123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- package crm
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/fms_api/models/crm"
- "hongze/fms_api/models/fms"
- "hongze/fms_api/utils"
- "reflect"
- "strings"
- )
- // GetContractDetail 根据id获取合同详情(包含服务)
- func GetContractDetail(contractId int) (contractDetail *crm.ContractDetail, err error) {
- contractDetail, err = getContractDetail(contractId)
- if err != nil {
- if err == utils.ErrNoRow {
- err = errors.New("找不到该合同")
- }
- return
- }
- relationContractDetailList := make([]*crm.ContractDetail, 0)
- switch contractDetail.ContractBusinessType {
- case "业务合同":
- tmpList, tmpErr := crm.GetContractRelationListByRelationContractId(contractDetail.ContractId)
- if tmpErr != nil {
- err = errors.New("查询业务关联合同异常:" + tmpErr.Error())
- return
- }
- // 获取所有关联合同详情
- for _, relationContract := range tmpList {
- tmpContractDetail, tmpErr := getContractDetail(relationContract.PaymentOnBehalfContractId)
- if tmpErr != nil {
- err = errors.New("查询业务关联合同详情异常:" + tmpErr.Error())
- return
- }
- relationContractDetailList = append(relationContractDetailList, tmpContractDetail)
- }
- case "代付合同":
- tmpList, tmpErr := crm.GetContractRelationListByPaymentOnBehalfContractId(contractDetail.ContractId)
- if tmpErr != nil {
- err = errors.New("查询代付关联合同异常:" + tmpErr.Error())
- return
- }
- // 获取所有关联合同详情
- for _, relationContract := range tmpList {
- tmpContractDetail, tmpErr := getContractDetail(relationContract.ContractId)
- if tmpErr != nil {
- err = errors.New("查询业务关联合同详情异常:" + tmpErr.Error())
- return
- }
- relationContractDetailList = append(relationContractDetailList, tmpContractDetail)
- }
- }
- contractDetail.RelationContractDetailList = relationContractDetailList
- return
- }
- // getContractDetail 根据id获取合同详情(包含服务)
- func getContractDetail(contractId int) (contractDetail *crm.ContractDetail, err error) {
- // 获取合同基础信息详情
- contractDetail, err = crm.GetContractDetailById(contractId)
- if err != nil {
- if err == utils.ErrNoRow {
- err = errors.New("找不到该合同")
- }
- return
- }
- // 获取合同服务内容详情
- serviceList, err := getContractServiceAndDetailList(contractId)
- if err != nil {
- err = errors.New(fmt.Sprint("查找合同服务异常", err))
- return
- }
- contractDetail.Service = serviceList
- return
- }
- // getContractServiceAndDetailList 根据合同Id获取服务详情列表
- func getContractServiceAndDetailList(contractId int) (serviceList []*crm.ContractServiceAndDetailRespItem, err error) {
- serviceList, err = crm.GetContractServiceAndDetailList(contractId)
- if err != nil {
- err = errors.New(fmt.Sprint("查找合同服务异常", err))
- return
- }
- serviceTempCond := ``
- serviceTempPars := make([]interface{}, 0)
- serviceTempOB := new(fms.ContractServiceTemplate)
- serviceTempList, e := serviceTempOB.List(serviceTempCond, serviceTempPars)
- if e != nil {
- return
- }
- templateMap := make(map[string]*fms.ContractServiceTemplate, 0)
- templateIdMap := make(map[int]string, 0)
- for _, v := range serviceTempList {
- templateIdMap[v.ServiceTemplateId] = v.Title
- }
- for _, v := range serviceTempList {
- if v.Title == "主观" || v.Title == "客观" {
- pTitle := templateIdMap[v.Pid]
- templateMap[pTitle+"("+v.Title+")"] = v
- } else {
- templateMap[v.Title] = v
- }
- }
- fmsTemplateIdMap := make(map[int]string, 0)
- newLen := len(serviceList)
- for i := 0; newLen > i; i++ {
- if serviceList[i].HasDetail == "是" {
- list, detailErr := crm.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
- if detailErr != nil {
- err = errors.New(fmt.Sprint("查找合同服务详情异常", detailErr))
- return
- }
- for aaa := range list {
- fmt.Println("list[aaa].Col1", list[aaa].Col1)
- }
- serviceList[i].DetailList = list
- }
- fmsTemplateIdMap[serviceList[i].ServiceTemplateId] = serviceList[i].Title
- }
- for _, v := range serviceList {
- if v.Title == "主观" || v.Title == "客观" {
- v.FMSServiceTemplateId = templateMap[v.Title].ServiceTemplateId
- v.FMSTitle = templateIdMap[v.FMSServiceTemplateId]
- v.FMSServiceTemplatePId = templateMap[v.Title].Pid
- v.FMSPTitle = templateIdMap[v.Pid]
- } else {
- if templateMap[v.Title] != nil {
- v.FMSServiceTemplateId = templateMap[v.Title].ServiceTemplateId
- v.FMSServiceTemplatePId = templateMap[v.Title].Pid
- }
- v.FMSTitle = templateIdMap[v.FMSServiceTemplateId]
- v.FMSPTitle = templateIdMap[v.Pid]
- }
- }
- return
- }
- // GetServicePermissionMap 获取合同服务中的权限id map
- func GetServicePermissionMap(serviceList []*crm.ContractServiceAndDetailRespItem) (checkPermissionIdMap map[int]int, err error) {
- checkPermissionIdMap = make(map[int]int)
- // 获取已经勾选的的权限
- for _, contractService := range serviceList {
- // 看看系统中有没有映射对应的权限,如果有的话,那么直接返回,没有那么可能是特殊服务,需要去遍历
- if contractService.ChartPermissionId > 0 {
- checkPermissionIdMap[contractService.ChartPermissionId] = contractService.ChartPermissionId
- continue
- }
- switch contractService.ServiceTemplateId {
- case 1: //ficc 大套餐
- permissionList, tmpErr := crm.GetSecondPermissionLookItemsByProductId(1)
- if tmpErr != nil {
- err = errors.New("查询FICC品种出错" + tmpErr.Error())
- return
- }
- for _, v := range permissionList {
- //大套餐中 市场策略暂时不作为勾选项
- if v.ClassifyName == "市场策略" {
- continue
- }
- checkPermissionIdMap[v.ChartPermissionId] = v.ChartPermissionId
- }
- case 2: //ficc小套餐
- permissionValues := []string{
- "FICC周报", "商品双周报+线上电话会讨论会<br/>(由弘则的研究员主持线上讨论)", "数据点评",
- }
- chartPermissionIds := make([]int, 0)
- for _, detail := range contractService.DetailList {
- var tableCel AddContractServiceDetailReq
- fmt.Println("detail.Col1", detail.Col1)
- tmpErr := json.Unmarshal([]byte(detail.Col1), &tableCel)
- if tmpErr != nil {
- fmt.Println(111)
- err = tmpErr
- return
- }
- if strings.Contains(strings.Join(permissionValues, ","), tableCel.Value) {
- //获取品种列数据
- var tableCel2 AddContractServiceDetailReq
- tmpErr := GetProductCelData(*detail, &tableCel2)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, serviceId := range tableCel2.ValueId {
- checkPermissionIdMap[serviceId] = serviceId
- }
- }
- }
- for k := range checkPermissionIdMap {
- chartPermissionIds = append(chartPermissionIds, checkPermissionIdMap[k])
- }
- contractService.ChartPermissionIds = chartPermissionIds
- case 4, 5, 6: //权益大套餐
- permissionFiccClassifyArr := []string{"权益"}
- for _, v := range permissionFiccClassifyArr {
- items, tmpErr := crm.GetPermissionLookItems(2, v)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, n := range items {
- //如果是专家行业,那么 结束当前循环,进入下一循环(产品需求:专家行业不在里面)
- if n.ChartPermissionId == 29 || n.ChartPermissionId == 31 {
- continue
- }
- checkPermissionIdMap[n.ChartPermissionId] = n.ChartPermissionId
- }
- }
- }
- }
- return
- }
- type AddContractServiceDetailReq struct {
- CanEdit bool `json:"CanEdit" description:"是否可编辑"`
- Type string `json:"Type" description:"类型"`
- Value string `json:"Value" description:"值"`
- ValueId []int `json:"ValueId" description:"类型"`
- HeadName string `json:"HeadName" description:"表头名称"`
- Tag string `json:"Tag" description:"表头名称"`
- RowDisable bool `json:"RowDisable" description:"该行是否禁用操作"`
- RowName string `json:"RowName" description:"该行关联名称"`
- Name string `json:"Name" description:"行名称"`
- }
- // GetProductCelData 获取品种列数据(因为前端可以随意插入列数据,所以需要根据列名来搜索对应的品种列)
- func GetProductCelData(detail crm.ContractServiceDetail, tableCel *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 {
- fmt.Println(222)
- err = tmpErr
- continue
- }
- if tableCel.HeadName == "品种" {
- err = nil
- return
- }
- }
- }
- }
- return
- }
|