Browse Source

Merge branch 'small_291' into debug

xiziwen 6 days ago
parent
commit
ca6bc89b98
2 changed files with 110 additions and 6 deletions
  1. 66 5
      controllers/seal/seal_approval.go
  2. 44 1
      models/seal/seal.go

+ 66 - 5
controllers/seal/seal_approval.go

@@ -224,8 +224,10 @@ func ApprovalListExport(this *SealApprovalController, condition, joinCondition s
 	if len(list) > 0 {
 		// 取出所有列表的关联合同id
 		contractIdSlice := make([]string, 0)
+		contractApprovalIdSlice := make([]string, 0)
 		for i := 0; i < len(list); i++ {
 			contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
+			contractApprovalIdSlice = append(contractApprovalIdSlice, strconv.Itoa(list[i].ContractApprovalId))
 		}
 
 		// 获取所有关联的合同列表
@@ -244,11 +246,70 @@ func ApprovalListExport(this *SealApprovalController, condition, joinCondition s
 			}
 		}
 
+		selfContractApprovalRecordMap := make(map[int][]*contract.ContractApprovalRecord)
+		{
+			if len(contractApprovalIdSlice) > 0 {
+				contractApprovalIdStr := strings.Join(contractApprovalIdSlice, ",")
+				contractApprovalList, tempErr := contract.GetContractApprovalRecordListByContractApprovalIds(contractApprovalIdStr)
+				if tempErr != nil {
+					err = errors.New(fmt.Sprint("获取合同审批记录失败,Err:"+tempErr.Error(), err))
+					return
+				}
+				for i := 0; i < len(contractApprovalList); i++ {
+					selfContractApprovalRecordMap[contractApprovalList[i].ContractApprovalId] = append(selfContractApprovalRecordMap[contractApprovalList[i].ContractApprovalId], contractApprovalList[i])
+				}
+			}
+		}
+
 		for i, v := range list {
 			// 合同编码
 			if selfContract, has := selfContractMap[v.ContractId]; has {
 				list[i].ContractCode = selfContract.ContractCode
 			}
+
+			// 审批人和抄送人
+			if recordList, ok := selfContractApprovalRecordMap[v.ContractApprovalId]; ok {
+				keySort := make([]int, 0)
+				flowNodeMap := make(map[int][]contract.ContractApprovalRecord, 0)
+				for _, approvalRecord := range recordList {
+					if tmpFlowNodeList, ok := flowNodeMap[approvalRecord.NodeId]; ok {
+						flowNodeMap[approvalRecord.NodeId] = append(tmpFlowNodeList, *approvalRecord)
+					} else {
+						tmpFlowNodeList := make([]contract.ContractApprovalRecord, 1)
+						tmpFlowNodeList[0] = *approvalRecord
+						flowNodeMap[approvalRecord.NodeId] = tmpFlowNodeList
+
+						keySort = append(keySort, approvalRecord.NodeId)
+					}
+				}
+				for ii, key := range keySort {
+					if ii == 0 {
+						if node, ok := flowNodeMap[key]; ok {
+							for _, vv := range node {
+								if vv.NodeType == "check" {
+									list[i].FirstLevelApprovers += vv.ApproveUserName + ","
+								}
+							}
+						}
+					} else {
+						if node, ok := flowNodeMap[key]; ok {
+							for _, vv := range node {
+								if vv.NodeType == "check" {
+									list[i].SecondLevelApprovers += vv.ApproveUserName + ","
+								} else if vv.NodeType == "cc"  && list[i].FirstLevelCC == "" {
+									list[i].FirstLevelCC += vv.ApproveUserName + ","
+								} else {
+									list[i].SecondLevelCC += vv.ApproveUserName + ","
+								}
+							}
+						}
+					}
+				}
+				list[i].FirstLevelApprovers = strings.TrimRight(list[i].FirstLevelApprovers, ",")
+				list[i].FirstLevelCC = strings.TrimRight(list[i].FirstLevelCC, ",")
+				list[i].SecondLevelApprovers = strings.TrimRight(list[i].SecondLevelApprovers, ",")
+				list[i].SecondLevelCC = strings.TrimRight(list[i].SecondLevelCC, ",")
+			}
 		}
 	}
 	//创建excel
@@ -327,17 +388,17 @@ func ApprovalListExport(this *SealApprovalController, condition, joinCondition s
 		cellH := row.AddCell()
 		cellH.Value = v.ApplyUserName
 		cellI := row.AddCell()
-		cellI.Value = v.CreateTimeStr
+		cellI.Value = v.CreateTime.Format(utils.FormatDateTime)
 		cellJ := row.AddCell()
 		cellJ.Value = v.Status
 		cellK := row.AddCell()
-		cellK.Value = "一级审批人"
+		cellK.Value = v.FirstLevelApprovers
 		cellL := row.AddCell()
-		cellL.Value = "一级抄送人"
+		cellL.Value = v.FirstLevelCC
 		cellM := row.AddCell()
-		cellM.Value = "二级审批人"
+		cellM.Value = v.SecondLevelApprovers
 		cellN := row.AddCell()
-		cellN.Value = "二级抄送人"
+		cellN.Value = v.SecondLevelCC
 	}
 
 	err = xlsxFile.Save(downLoadnFilePath)

+ 44 - 1
models/seal/seal.go

@@ -220,8 +220,51 @@ WHERE c.is_delete = 0 AND a.approval_type="seal" `
 	return
 }
 
+type SealApprovaExportlItem struct {
+	ContractApprovalId       int `description:"审批单ID"`
+	ContractId               int `description:"合同ID"`
+	ContractApprovalRecordId int `description:"审批流ID"`
+	//ContractCode             string                  `description:"合同编号"`
+	Use            string                  `description:"用印用途,枚举值:'销售合同','渠道合同','付款通知函','招投标','战略合作协议'"`
+	ContractType   string                  `description:"合同类型,枚举值:'新签合同','续约合同','补充协议','代付合同'"`
+	Status         string                  `description:"合同状态,枚举值:待审批','已审批','已驳回','已撤回','已签回',默认待审批"`
+	ApproveStatus  string                  `json:"-" description:"审批单状态,枚举值:待审批','已审批','已驳回','已撤回',默认待审批"`
+	ApplyContent   string                  `description:"申请内容"`
+	ApplyUserId    int                     `description:"申请人ID"`
+	ApplyUserName  string                  `description:"申请人名称"`
+	ContractDetail string                  `json:"-" description:"提交审批时的合同信息;用印快照"`
+	ContractInfo   contract.ContractDetail `json:"-" description:"提交审批时的合同信息;用印快照"`
+	ApproveRemark  string                  `description:"审核备注"`
+	SealType       string                  `description:"用印类型"`
+	CompanyName    string                  `description:"客户名称"`
+	FileUrl        string                  `description:"合同下载地址"`
+	CurrNodeId     int                     `description:"当前审批节点id"`
+	StartNodeId    int                     `description:"开始审批节点id"`
+	//UserId                   int                     `description:"申请人id"`
+	//UserName                 string                  `description:"申请人名称"`
+	SealId               int       `description:"用印审批ID"`
+	CreateTime           time.Time `description:"发起审批的时间"`
+	ModifyTime           time.Time `description:"最后一次修改的时间"`
+	ApproveTime          time.Time `description:"审批时间"`
+	InvalidTime          time.Time `description:"作废时间"`
+	CheckBackFileUrl     string    `description:"签回附件地址"`
+	CheckBackFileTime    time.Time `description:"签回用印附件时间"`
+	CreditCode           string    `description:"社会信用码"`
+	CreateTimeStr        string    `description:"发起审批的时间(字符串)"`
+	ModifyTimeStr        string    `description:"最后一次修改的时间(字符串)"`
+	ApproveTimeStr       string    `description:"审批时间(字符串)"`
+	InvalidTimeStr       string    `description:"作废时间(字符串)"`
+	CheckBackFileTimeStr string    `description:"签回用印附件时间(字符串)"`
+	ContractCode         string    `description:"合同编码"`
+	AffiliatedCompany    string    `description:"归属公司"`
+	FirstLevelApprovers  string    `description:"一级审批人"`
+	SecondLevelApprovers string    `description:"二级审批人"`
+	FirstLevelCC         string    `description:"一级抄送人"`
+	SecondLevelCC        string    `description:"二级抄送人"`
+}
+
 // GetSealApprovalList 获取用印审批列表
-func GetSealApprovalList(condition, joinCondition string, pars []interface{}) (list []*SealApprovalItem, err error) {
+func GetSealApprovalList(condition, joinCondition string, pars []interface{}) (list []*SealApprovaExportlItem, err error) {
 	o := orm.NewOrm()
 	fields := `a.contract_approval_id,c.contract_id,a.apply_content,a.approve_remark,a.apply_user_id,a.apply_user_name,a.curr_node_id,a.start_node_id,c.create_time,a.modify_time,a.status approval_status,
 			   c.status,c.seal_id,c.seal_type,c.service_type contract_type,c.use,c.company_name,c.file_url,c.approve_time,c.invalid_time,c.code,c.credit_code,c.check_back_file_time,c.check_back_file_url,c.affiliated_company `