|
@@ -2,14 +2,24 @@ package seal
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
"hongze/hz_crm_api/controllers"
|
|
|
"hongze/hz_crm_api/models"
|
|
|
+ "hongze/hz_crm_api/models/company"
|
|
|
+ "hongze/hz_crm_api/models/contract"
|
|
|
+ sealModels "hongze/hz_crm_api/models/seal"
|
|
|
"hongze/hz_crm_api/models/seal/request"
|
|
|
"hongze/hz_crm_api/models/seal/response"
|
|
|
"hongze/hz_crm_api/services/seal"
|
|
|
"hongze/hz_crm_api/utils"
|
|
|
+ "os"
|
|
|
+ "path/filepath"
|
|
|
+ "strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// 用印审批管理
|
|
@@ -28,6 +38,8 @@ type SealApprovalController struct {
|
|
|
// @Param StartTime query string false "提交开始时间"
|
|
|
// @Param EndTime query string false "提交结束时间"
|
|
|
// @Param Keyword query string false "搜索关键词(客户名称/社会信用码)"
|
|
|
+// @Param IsExport query bool false "是否导出excel,默认是false"
|
|
|
+// @Param AffiliatedCompany query string false "归属公司"
|
|
|
// @Success 200 {object} response.SealApprovalListResp
|
|
|
// @router /getApprovalPageList [get]
|
|
|
func (this *SealApprovalController) List() {
|
|
@@ -55,7 +67,7 @@ func (this *SealApprovalController) List() {
|
|
|
currentIndex = 1
|
|
|
}
|
|
|
startSize = paging.StartIndex(currentIndex, pageSize)
|
|
|
-
|
|
|
+ isExport, _ := this.GetBool("IsExport", false)
|
|
|
// 筛选条件
|
|
|
condition := ""
|
|
|
joinCondition := " AND a.curr_node_id = d.node_id" // contract_approval和contract_approval_record的join条件
|
|
@@ -158,6 +170,19 @@ func (this *SealApprovalController) List() {
|
|
|
pars = append(pars, keywords, keywords, keywords)
|
|
|
}
|
|
|
|
|
|
+ // 归属公司
|
|
|
+ affiliatedCompany := this.GetString("AffiliatedCompany")
|
|
|
+ if affiliatedCompany != "" {
|
|
|
+ condition += ` AND c.affiliated_company = ?`
|
|
|
+ pars = append(pars, affiliatedCompany)
|
|
|
+ }
|
|
|
+
|
|
|
+ //导出excel
|
|
|
+ if isExport {
|
|
|
+ ApprovalListExport(this, condition, joinCondition, pars, br)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// 列表
|
|
|
listData, listTotal, err := seal.GetSealApprovalPageList(condition, joinCondition, pars, startSize, pageSize, sysUser)
|
|
|
if err != nil {
|
|
@@ -176,6 +201,242 @@ func (this *SealApprovalController) List() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ApprovalListExport 审批列表导出
|
|
|
+func ApprovalListExport(this *SealApprovalController, condition, joinCondition string, pars []interface{}, br *models.BaseResponse) {
|
|
|
+ list, err := sealModels.GetSealApprovalList(condition, joinCondition, pars)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "审批列表获取失败!"
|
|
|
+ br.ErrMsg = "审批列表获取失败!" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ////超级管理员和权益管理员、权益研究员可以下载所有客户,销售组长能下载本组客户,销售只能下载本人名下客户
|
|
|
+ //resp := new(cygx.CanDownload)
|
|
|
+ //adminInfo, errAdmin := system.GetSysUserById(sysUser.AdminId)
|
|
|
+ //if errAdmin != nil {
|
|
|
+ // br.Msg = "获取失败"
|
|
|
+ // br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if adminInfo.Role == "admin" || adminInfo.Role == "researcher" {
|
|
|
+ // resp.IsCanDownload = true
|
|
|
+ //}
|
|
|
+
|
|
|
+ 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))
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取所有关联的合同列表
|
|
|
+ selfContractMap := make(map[int]*contract.ContractList)
|
|
|
+ {
|
|
|
+ if len(contractIdSlice) > 0 {
|
|
|
+ contractIdStr := strings.Join(contractIdSlice, ",")
|
|
|
+ contractList, tempErr := contract.GetContractListByContractIds(contractIdStr)
|
|
|
+ if tempErr != nil {
|
|
|
+ err = errors.New(fmt.Sprint("获取合同失败,Err:"+tempErr.Error(), err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for i := 0; i < len(contractList); i++ {
|
|
|
+ selfContractMap[contractList[i].ContractId] = contractList[i]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ approversList := make([][]string, 0)
|
|
|
+ ccList := make([][]string, 0)
|
|
|
+ for _, key := range keySort {
|
|
|
+ approver := make([]string, 0)
|
|
|
+ cc := make([]string, 0)
|
|
|
+ if node, ok := flowNodeMap[key]; ok {
|
|
|
+ for _, vv := range node {
|
|
|
+ if vv.NodeType == "check" {
|
|
|
+ approver = append(approver, vv.ApproveUserName)
|
|
|
+ } else if vv.NodeType == "cc" {
|
|
|
+ cc = append(cc, vv.ApproveUserName)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(approver) > 0 {
|
|
|
+ approversList = append(approversList, approver)
|
|
|
+ }
|
|
|
+ if len(cc) > 0 {
|
|
|
+ ccList = append(ccList, cc)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(approversList) > 0 {
|
|
|
+ list[i].FirstLevelApprovers = strings.Join(approversList[0], ",")
|
|
|
+ }
|
|
|
+ if len(ccList) > 0 {
|
|
|
+ list[i].FirstLevelCC = strings.Join(ccList[0], ",")
|
|
|
+ }
|
|
|
+ if len(approversList) > 1 {
|
|
|
+ list[i].SecondLevelApprovers = strings.Join(approversList[1], ",")
|
|
|
+ }
|
|
|
+ if len(ccList) > 1 {
|
|
|
+ list[i].SecondLevelCC = strings.Join(ccList[1], ",")
|
|
|
+ }
|
|
|
+ if len(approversList) > 2 {
|
|
|
+ list[i].ThirdLevelApprovers = strings.Join(approversList[2], ",")
|
|
|
+ }
|
|
|
+ if len(ccList) > 2 {
|
|
|
+ list[i].ThirdLevelCC = strings.Join(ccList[2], ",")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建excel
|
|
|
+ dir, err := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "生成文件失败"
|
|
|
+ br.ErrMsg = "生成文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+
|
|
|
+ sheetName := "审批列表"
|
|
|
+ sheet, err := xlsxFile.AddSheet(sheetName)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //标头
|
|
|
+ rowTitle := sheet.AddRow()
|
|
|
+ cellA := rowTitle.AddCell()
|
|
|
+ cellA.Value = "归属公司"
|
|
|
+ cellB := rowTitle.AddCell()
|
|
|
+ cellB.Value = "客户名称"
|
|
|
+ cellC := rowTitle.AddCell()
|
|
|
+ cellC.Value = "社会信用码"
|
|
|
+ cellD := rowTitle.AddCell()
|
|
|
+ cellD.Value = "用印用途"
|
|
|
+ cellE := rowTitle.AddCell()
|
|
|
+ cellE.Value = "合同编号"
|
|
|
+ cellF := rowTitle.AddCell()
|
|
|
+ cellF.Value = "合同类型"
|
|
|
+ cellG := rowTitle.AddCell()
|
|
|
+ cellG.Value = "加盖印章"
|
|
|
+ cellH := rowTitle.AddCell()
|
|
|
+ cellH.Value = "所属销售"
|
|
|
+ cellI := rowTitle.AddCell()
|
|
|
+ cellI.Value = "提交时间"
|
|
|
+ cellJ := rowTitle.AddCell()
|
|
|
+ cellJ.Value = "用印状态"
|
|
|
+ cellK := rowTitle.AddCell()
|
|
|
+ cellK.Value = "一级审批人"
|
|
|
+ cellL := rowTitle.AddCell()
|
|
|
+ cellL.Value = "一级抄送人"
|
|
|
+ cellM := rowTitle.AddCell()
|
|
|
+ cellM.Value = "二级审批人"
|
|
|
+ cellN := rowTitle.AddCell()
|
|
|
+ cellN.Value = "二级抄送人"
|
|
|
+ cellO := rowTitle.AddCell()
|
|
|
+ cellO.Value = "三级审批人"
|
|
|
+ cellP := rowTitle.AddCell()
|
|
|
+ cellP.Value = "三级抄送人"
|
|
|
+
|
|
|
+ for _, v := range list {
|
|
|
+ row := sheet.AddRow()
|
|
|
+ cellA := row.AddCell()
|
|
|
+ cellA.Value = v.AffiliatedCompany
|
|
|
+ cellB := row.AddCell()
|
|
|
+ cellB.Value = v.CompanyName
|
|
|
+ cellC := row.AddCell()
|
|
|
+ cellC.Value = v.CreditCode
|
|
|
+ cellD := row.AddCell()
|
|
|
+ cellD.Value = v.Use
|
|
|
+ cellE := row.AddCell()
|
|
|
+ cellE.Value = v.ContractCode
|
|
|
+ cellF := row.AddCell()
|
|
|
+ cellF.Value = v.ContractType
|
|
|
+ cellG := row.AddCell()
|
|
|
+ cellG.Value = v.SealType
|
|
|
+ cellH := row.AddCell()
|
|
|
+ cellH.Value = v.ApplyUserName
|
|
|
+ cellI := row.AddCell()
|
|
|
+ cellI.Value = v.CreateTime.Format(utils.FormatDateTime)
|
|
|
+ cellJ := row.AddCell()
|
|
|
+ cellJ.Value = v.Status
|
|
|
+ cellK := row.AddCell()
|
|
|
+ cellK.Value = v.FirstLevelApprovers
|
|
|
+ cellL := row.AddCell()
|
|
|
+ cellL.Value = v.FirstLevelCC
|
|
|
+ cellM := row.AddCell()
|
|
|
+ cellM.Value = v.SecondLevelApprovers
|
|
|
+ cellN := row.AddCell()
|
|
|
+ cellN.Value = v.SecondLevelCC
|
|
|
+ cellO := row.AddCell()
|
|
|
+ cellO.Value = v.ThirdLevelApprovers
|
|
|
+ cellP := row.AddCell()
|
|
|
+ cellP.Value = v.ThirdLevelCC
|
|
|
+ }
|
|
|
+
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存文件失败"
|
|
|
+ br.ErrMsg = "保存文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ downloadFileName := "审批列表" + ".xlsx"
|
|
|
+ this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
|
|
|
+ defer func() {
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ }()
|
|
|
+ br.Success = true
|
|
|
+ br.Ret = 200
|
|
|
+ br.IsAddLog = true
|
|
|
+}
|
|
|
+
|
|
|
// 用印申请
|
|
|
// @Title 用印申请
|
|
|
// @Description 用印申请
|
|
@@ -204,12 +465,13 @@ func (this *SealApprovalController) Apply() {
|
|
|
return
|
|
|
}
|
|
|
reqVerify := utils.Rules{
|
|
|
- "Use": {utils.NotEmpty()},
|
|
|
- "CompanyName": {utils.NotEmpty()},
|
|
|
- "CreditCode": {utils.NotEmpty()},
|
|
|
- "ServiceType": {utils.NotEmpty()},
|
|
|
- "SealType": {utils.NotEmpty()},
|
|
|
- "FileUrls": {utils.NotEmpty()},
|
|
|
+ "Use": {utils.NotEmpty()},
|
|
|
+ "CompanyName": {utils.NotEmpty()},
|
|
|
+ "CreditCode": {utils.NotEmpty()},
|
|
|
+ "ServiceType": {utils.NotEmpty()},
|
|
|
+ "SealType": {utils.NotEmpty()},
|
|
|
+ "FileUrls": {utils.NotEmpty()},
|
|
|
+ "AffiliatedCompany": {utils.NotEmpty()},
|
|
|
}
|
|
|
|
|
|
err = utils.Verify(req, reqVerify, utils.LANG_CN)
|
|
@@ -294,6 +556,11 @@ func (this *SealApprovalController) Edit() {
|
|
|
br.ErrMsg = "合同附件不能为空"
|
|
|
return
|
|
|
}
|
|
|
+ if req.AffiliatedCompany == "" {
|
|
|
+ br.Msg = "归属公司不能为空"
|
|
|
+ br.ErrMsg = "归属公司不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
// 编辑用印
|
|
|
err = seal.EditApply(this.SysUser, req)
|
|
@@ -693,3 +960,36 @@ func (this *SealApprovalController) OperationList() {
|
|
|
List: list,
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 关联公司列表
|
|
|
+// @Title 关联公司列表
|
|
|
+// @Description 关联公司列表
|
|
|
+// @Success 200 {object} response.SealApprovalListResp
|
|
|
+// @router /getAffiliatedCompany [get]
|
|
|
+func (this *SealApprovalController) AffiliatedCompanyList() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := this.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ crmConfig, err := company.GetConfigDetailByCode("affiliated_company")
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取配置失败"
|
|
|
+ br.ErrMsg = "获取配置失败"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list := strings.Split(crmConfig.ConfigValue, ",")
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = list
|
|
|
+}
|