1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009 |
- package report_approve
- import (
- "encoding/json"
- "eta/eta_api/controllers"
- "eta/eta_api/models"
- "eta/eta_api/models/report_approve"
- "eta/eta_api/services"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- // ReportApproveController 报告审批
- type ReportApproveController struct {
- controllers.BaseAuthController
- }
- // List
- // @Title 审批列表
- // @Description 审批列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码"
- // @Param ListType query int true "列表类型:1-待处理;2-已处理;3-我发起的"
- // @Param ReportType query int false "报告类型:1-中文研报;2-英文研报;3-智能研报"
- // @Param ClassifyIdFirst query int false "一级分类ID"
- // @Param ClassifyIdSecond query int false "二级分类ID"
- // @Param Keyword query string false "搜索关键词"
- // @Param ApproveState query int false "审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"
- // @Param TimeType query int false "时间类型:1-提交时间;2-处理时间;3-审批时间"
- // @Param StartTime query string false "开始时间"
- // @Param EndTime query string false "结束时间"
- // @Param SortField query int false "排序字段:1-提交时间;2-处理时间;3-审批时间"
- // @Param SortRule query int false "排序方式: 1-正序; 2-倒序(默认)"
- // @Success 200 {object} report_approve.ReportApproveListResp
- // @router /list [get]
- func (this *ReportApproveController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- params := new(report_approve.ReportApproveListReq)
- if e := this.ParseForm(params); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "入参解析失败, Err: " + e.Error()
- return
- }
- if params.ListType != 1 && params.ListType != 2 && params.ListType != 3 {
- br.Msg = "列表类型有误"
- return
- }
- // 报告分类
- cnClassifyIdName, enClassifyIdName := make(map[int]string), make(map[int]string)
- cnClassify, e := models.GetAllClassify()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中文分类失败, Err: " + e.Error()
- return
- }
- for _, v := range cnClassify {
- cnClassifyIdName[v.Id] = v.ClassifyName
- }
- enClassify, e := models.GetEnglishClassifies()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取英文分类失败, Err: " + e.Error()
- return
- }
- enRootIdMap := make(map[int]int) // 英文分类的一级分类ID
- for _, v := range enClassify {
- enClassifyIdName[v.Id] = v.ClassifyName
- enRootIdMap[v.Id] = v.RootId
- }
- // 分页
- var startSize int
- if params.PageSize <= 0 {
- params.PageSize = utils.PageSize20
- }
- if params.CurrentIndex <= 0 {
- params.CurrentIndex = 1
- }
- startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
- resp := new(report_approve.ReportApproveListResp)
- respTotal := 0
- respList := make([]*report_approve.ReportApproveItem, 0)
- timeField := map[int]string{1: fmt.Sprintf("a.%s", report_approve.ReportApproveCols.CreateTime), 2: fmt.Sprintf("a.%s", report_approve.ReportApproveRecordCols.ApproveTime), 3: fmt.Sprintf("b.%s", report_approve.ReportApproveCols.ApproveTime)}
- mineTimeField := map[int]string{1: fmt.Sprintf("%s", report_approve.ReportApproveCols.CreateTime), 3: fmt.Sprintf("%s", report_approve.ReportApproveCols.ApproveTime)}
- orderRules := map[int]string{1: "ASC", 2: "DESC"}
- ormList := make([]*report_approve.ReportApproveItemOrm, 0)
- // 待处理
- if params.ListType == 1 {
- cond := fmt.Sprintf(` AND a.%s = ? AND b.%s = ? AND a.%s = ?`, report_approve.ReportApproveRecordCols.State, report_approve.ReportApproveCols.State, report_approve.ReportApproveRecordCols.ApproveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, report_approve.ReportApproveStateApproving, report_approve.ReportApproveStateApproving, sysUser.AdminId)
- order := ""
- // 筛选条件
- if params.ReportType > 0 && params.ClassifySecondId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ? AND b.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
- pars = append(pars, params.ReportType, params.ClassifySecondId)
- }
- if params.TimeType <= 0 {
- params.TimeType = 1
- }
- if params.TimeType == 1 && params.StartTime != "" && params.EndTime != "" {
- _, e := time.Parse(utils.FormatDate, params.StartTime)
- if e != nil {
- br.Msg = "开始时间格式有误"
- return
- }
- _, e = time.Parse(utils.FormatDate, params.EndTime)
- if e != nil {
- br.Msg = "结束时间格式有误"
- return
- }
- st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
- ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
- cond += fmt.Sprintf(` AND (b.%s BETWEEN ? AND ?)`, report_approve.ReportApproveCols.CreateTime)
- pars = append(pars, st, ed)
- }
- params.Keyword = strings.TrimSpace(params.Keyword)
- if params.Keyword != "" {
- kw := fmt.Sprint("%", params.Keyword, "%")
- cond += fmt.Sprintf(` AND b.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
- pars = append(pars, kw)
- }
- if params.SortField > 0 && params.SortRule > 0 {
- orderField := timeField[params.SortField]
- if orderField == "" {
- br.Msg = "时间排序字段有误"
- return
- }
- orderRule := orderRules[params.SortRule]
- if orderRule == "" {
- br.Msg = "时间排序方式有误"
- return
- }
- order = fmt.Sprintf("%s %s", orderField, orderRule)
- }
- total, e := report_approve.GetApprovingReportApproveCount(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "GetApprovingReportApproveCount err: " + e.Error()
- return
- }
- respTotal = total
- list, e := report_approve.GetApprovingReportApprovePageList(cond, pars, order, startSize, params.PageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "GetApprovingReportApprovePageList err: " + e.Error()
- return
- }
- ormList = list
- }
- // 已处理
- if params.ListType == 2 {
- cond := fmt.Sprintf(` AND a.%s = ? AND a.%s IN (%s)`, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.NodeState, utils.GetOrmInReplace(2))
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId, []int{report_approve.ReportApproveStatePass, report_approve.ReportApproveStateRefuse})
- order := ""
- // 筛选条件
- if params.ReportType > 0 && params.ClassifySecondId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ? AND b.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
- pars = append(pars, params.ReportType, params.ClassifySecondId)
- }
- if params.TimeType > 0 && params.StartTime != "" && params.EndTime != "" {
- _, e := time.Parse(utils.FormatDate, params.StartTime)
- if e != nil {
- br.Msg = "开始时间格式有误"
- return
- }
- _, e = time.Parse(utils.FormatDate, params.EndTime)
- if e != nil {
- br.Msg = "结束时间格式有误"
- return
- }
- st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
- ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
- cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, timeField[params.TimeType])
- pars = append(pars, st, ed)
- }
- params.Keyword = strings.TrimSpace(params.Keyword)
- if params.Keyword != "" {
- kw := fmt.Sprint("%", params.Keyword, "%")
- cond += fmt.Sprintf(` AND b.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
- pars = append(pars, kw)
- }
- if params.SortField > 0 && params.SortRule > 0 {
- orderField := timeField[params.SortField]
- if orderField == "" {
- br.Msg = "时间排序字段有误"
- return
- }
- orderRule := orderRules[params.SortRule]
- if orderRule == "" {
- br.Msg = "时间排序方式有误"
- return
- }
- order = fmt.Sprintf("%s %s", orderField, orderRule)
- }
- if params.ApproveState > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveRecordCols.State)
- pars = append(pars, params.ApproveState)
- }
- total, e := report_approve.GetApprovedReportApproveCount(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "GetApprovedReportApproveCount err: " + e.Error()
- return
- }
- respTotal = total
- list, e := report_approve.GetApprovedReportApprovePageList(cond, pars, order, startSize, params.PageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "GetApprovedReportApprovePageList err: " + e.Error()
- return
- }
- for _, v := range list {
- // 这个时候的状态,用审批状态
- v.RecordState = v.NodeState
- v.ApproveTime = v.NodeApproveTime
- }
- ormList = list
- }
- // 我发起的
- if params.ListType == 3 {
- cond := fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ApplyUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId)
- order := ""
- // 筛选条件
- if params.ReportType > 0 && params.ClassifySecondId > 0 {
- cond += fmt.Sprintf(` AND a.%s = ? AND a.%s = ?`, report_approve.ReportApproveCols.ReportType, report_approve.ReportApproveCols.ClassifySecondId)
- pars = append(pars, params.ReportType, params.ClassifySecondId)
- }
- if params.TimeType > 0 && params.StartTime != "" && params.EndTime != "" {
- _, e := time.Parse(utils.FormatDate, params.StartTime)
- if e != nil {
- br.Msg = "开始时间格式有误"
- return
- }
- _, e = time.Parse(utils.FormatDate, params.EndTime)
- if e != nil {
- br.Msg = "结束时间格式有误"
- return
- }
- st := fmt.Sprintf("%s %s", params.StartTime, "00:00:00")
- ed := fmt.Sprintf("%s %s", params.EndTime, "23:59:59")
- field := mineTimeField[params.TimeType]
- if field == "" {
- br.Msg = "筛选时间有误"
- return
- }
- cond += fmt.Sprintf(` AND (%s BETWEEN ? AND ?)`, field)
- pars = append(pars, st, ed)
- }
- params.Keyword = strings.TrimSpace(params.Keyword)
- if params.Keyword != "" {
- kw := fmt.Sprint("%", params.Keyword, "%")
- cond += fmt.Sprintf(` AND a.%s LIKE ?`, report_approve.ReportApproveCols.ReportTitle)
- pars = append(pars, kw)
- }
- if params.SortField > 0 && params.SortRule > 0 {
- orderField := mineTimeField[params.SortField]
- if orderField == "" {
- br.Msg = "时间排序字段有误"
- return
- }
- orderRule := orderRules[params.SortRule]
- if orderRule == "" {
- br.Msg = "时间排序方式有误"
- return
- }
- order = fmt.Sprintf("%s %s", orderField, orderRule)
- }
- if params.ApproveState > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveRecordCols.State)
- pars = append(pars, params.ApproveState)
- }
- total, e := report_approve.GetApplyReportApproveCount(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "GetApplyReportApproveCount err: " + e.Error()
- return
- }
- respTotal = total
- list, e := report_approve.GetApplyReportApprovePageList(cond, pars, order, startSize, params.PageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "GetApplyReportApprovePageList err: " + e.Error()
- return
- }
- ormList = list
- }
- // 审批通过的报告显示下载按钮
- reportImg := make(map[string]string)
- reportPdf := make(map[string]string)
- {
- var reportIds, enReportIds []int
- for _, v := range ormList {
- if v.State != report_approve.ReportApproveStatePass {
- continue
- }
- if v.ReportType == report_approve.FlowReportTypeChinese {
- reportIds = append(reportIds, v.ReportId)
- }
- if v.ReportType == report_approve.FlowReportTypeEnglish {
- enReportIds = append(enReportIds, v.ReportId)
- }
- }
- if len(reportIds) > 0 {
- reports, e := models.GetReportFieldsByIds(reportIds, []string{"id", "detail_img_url", "detail_pdf_url"})
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("GetReportFieldsByIds, %v", e)
- return
- }
- for _, r := range reports {
- k := fmt.Sprintf("%d-%d", report_approve.FlowReportTypeChinese, r.Id)
- reportImg[k] = r.DetailImgUrl
- reportPdf[k] = r.DetailPdfUrl
- }
- }
- if len(enReportIds) > 0 {
- enReports, e := models.GetEnglishReportFieldsByIds(enReportIds, []string{"id", "detail_img_url", "detail_pdf_url"})
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("GetEnglishReportFieldsByIds, %v", e)
- return
- }
- for _, r := range enReports {
- k := fmt.Sprintf("%d-%d", report_approve.FlowReportTypeEnglish, r.Id)
- reportImg[k] = r.DetailImgUrl
- reportPdf[k] = r.DetailPdfUrl
- }
- }
- }
- // 格式化列表
- for _, v := range ormList {
- t := report_approve.FormatReportApproveOrm2Item(v)
- if v.ReportType == report_approve.FlowReportTypeEnglish {
- t.ReportClassify = fmt.Sprintf("%s/%s/%s/%s", report_approve.FlowReportTypeMap[v.ReportType], enClassifyIdName[enRootIdMap[v.ClassifySecondId]], enClassifyIdName[v.ClassifyFirstId], enClassifyIdName[v.ClassifySecondId])
- } else {
- //t.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[v.ReportType], cnClassifyIdName[v.ClassifyFirstId], cnClassifyIdName[v.ClassifySecondId])
- reportClassify := fmt.Sprintf("%s/%s", report_approve.FlowReportTypeMap[v.ReportType], cnClassifyIdName[v.ClassifyFirstId])
- if v.ClassifySecondId > 0 {
- reportClassify = fmt.Sprintf("%s/%s", reportClassify, cnClassifyIdName[v.ClassifySecondId])
- }
- if v.ClassifyThirdId > 0 {
- reportClassify = fmt.Sprintf("%s/%s", reportClassify, cnClassifyIdName[v.ClassifyThirdId])
- }
- t.ReportClassify = reportClassify
- }
- k := fmt.Sprintf("%d-%d", t.ReportType, t.ReportId)
- t.DetailImgUrl = reportImg[k]
- t.DetailPdfUrl = reportPdf[k]
- respList = append(respList, t)
- }
- page := paging.GetPaging(params.CurrentIndex, params.PageSize, respTotal)
- resp.Paging = page
- resp.List = respList
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Detail
- // @Title 审批详情
- // @Description 审批详情
- // @Param ReportApproveId query int true "审批ID"
- // @Success 200 {object} report_approve.ReportApproveDetail
- // @router /detail [get]
- func (this *ReportApproveController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- approveId, _ := this.GetInt("ReportApproveId")
- if approveId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", approveId)
- return
- }
- approveOb := new(report_approve.ReportApprove)
- approveItem, e := approveOb.GetItemById(approveId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "审批已被删除, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批失败, Err: " + e.Error()
- return
- }
- // 审批信息
- detail := new(report_approve.ReportApproveDetail)
- detail.Approve = new(report_approve.ReportApproveDetailItem)
- detail.Approve.ReportApproveId = approveItem.ReportApproveId
- detail.Approve.State = approveItem.State
- detail.Approve.FlowId = approveItem.FlowId
- detail.Approve.FlowVersion = approveItem.FlowVersion
- detail.Approve.StartNodeId = approveItem.StartNodeId
- detail.Approve.CurrNodeId = approveItem.CurrNodeId
- detail.Approve.ApplyUserId = approveItem.ApplyUserId
- detail.Approve.ApplyUserName = approveItem.ApplyUserName
- detail.Approve.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.ApproveTime)
- detail.Approve.CreateTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.CreateTime)
- detail.Approve.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, approveItem.ModifyTime)
- // 审批流
- //flowOb := new(report_approve.ReportApproveFlow)
- //flowItem, e := flowOb.GetItemById(approveItem.FlowId)
- //if e != nil {
- // if e.Error() == utils.ErrNoRow() {
- // br.Msg = "审批流已被删除, 请刷新页面"
- // return
- // }
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取审批流失败, Err: " + e.Error()
- // return
- //}
- //detail.ApproveFlow = report_approve.FormatReportApproveFlow2Item(flowItem)
- // 审批节点
- nodeOb := new(report_approve.ReportApproveNode)
- nodeCond := fmt.Sprintf(` AND %s = ? AND %s = ?`, report_approve.ReportApproveNodeCols.ReportApproveFlowId, report_approve.ReportApproveNodeCols.CurrVersion)
- nodePars := make([]interface{}, 0)
- nodePars = append(nodePars, approveItem.FlowId, approveItem.FlowVersion)
- nodeItems, e := nodeOb.GetItemsByCondition(nodeCond, nodePars, []string{}, "")
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批节点失败, Err: " + e.Error()
- return
- }
- // 审批记录
- recordOb := new(report_approve.ReportApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, approveItem.ReportApproveId)
- recordItems, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, fmt.Sprintf("%s DESC", report_approve.ReportApproveRecordCols.ApproveTime))
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批记录失败, Err: " + e.Error()
- return
- }
- recordMap := make(map[string]*report_approve.ReportApproveRecord)
- for _, v := range recordItems {
- k := fmt.Sprintf("%d-%d", v.NodeId, v.ApproveUserId)
- recordMap[k] = v
- }
- // 审批流节点详情
- detail.ApproveFlowNodes = make([]*report_approve.ReportApproveDetailNodes, 0)
- for _, v := range nodeItems {
- t := new(report_approve.ReportApproveDetailNodes)
- t.ReportApproveNodeId = v.ReportApproveNodeId
- t.ReportApproveFlowId = v.ReportApproveFlowId
- t.PrevNodeId = v.PrevNodeId
- t.NextNodeId = v.NextNodeId
- t.NodeType = v.NodeType
- t.ApproveType = v.ApproveType
- t.Users = make([]*report_approve.ReportApproveDetailNodeUser, 0)
- us := make([]*report_approve.ReportApproveNodeUserReq, 0)
- if v.Users != "" {
- e = json.Unmarshal([]byte(v.Users), &us)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "节点用户解析失败, Err: " + e.Error()
- return
- }
- }
- for _, vu := range us {
- u := new(report_approve.ReportApproveDetailNodeUser)
- u.UserType = vu.UserType
- u.UserId = vu.UserId
- u.UserName = vu.UserName
- u.Sort = vu.Sort
- // 审批记录
- k := fmt.Sprintf("%d-%d", v.ReportApproveNodeId, vu.UserId)
- r := recordMap[k]
- if r != nil {
- u.ApproveRecord = new(report_approve.ReportApproveDetailNodeUserRecord)
- u.ApproveRecord.ReportApproveRecordId = r.ReportApproveRecordId
- u.ApproveRecord.State = r.State
- u.ApproveRecord.ApproveUserId = r.ApproveUserId
- u.ApproveRecord.ApproveUserName = r.ApproveUserName
- u.ApproveRecord.ApproveRemark = r.ApproveRemark
- u.ApproveRecord.ApproveTime = utils.TimeTransferString(utils.FormatDateTime, r.ApproveTime)
- }
- t.Users = append(t.Users, u)
- }
- sort.Slice(t.Users, func(k, j int) bool {
- return t.Users[k].Sort < t.Users[j].Sort
- })
- detail.ApproveFlowNodes = append(detail.ApproveFlowNodes, t)
- }
- // 报告信息
- cnClassifyIdName, enClassifyIdName := make(map[int]string), make(map[int]string)
- cnClassify, e := models.GetAllClassify()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中文分类失败, Err: " + e.Error()
- return
- }
- for _, v := range cnClassify {
- cnClassifyIdName[v.Id] = v.ClassifyName
- }
- enClassify, e := models.GetEnglishClassifies()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取英文分类失败, Err: " + e.Error()
- return
- }
- enRootIdMap := make(map[int]int) // 英文分类的一级分类ID
- for _, v := range enClassify {
- enClassifyIdName[v.Id] = v.ClassifyName
- enRootIdMap[v.Id] = v.RootId
- }
- detail.Report = new(report_approve.ReportApproveDetailReport)
- detail.Report.ReportType = approveItem.ReportType
- detail.Report.ReportId = approveItem.ReportId
- detail.Report.ReportTitle = approveItem.ReportTitle
- detail.Report.ReportLayout = 1
- // 报告分类路由
- if approveItem.ReportType == report_approve.FlowReportTypeChinese {
- reportInfo, e := models.GetReportLayoutByReportId(approveItem.ReportId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- detail.Report.ReportLayout = reportInfo.ReportLayout
- detail.Report.ReportCode = utils.MD5(strconv.Itoa(approveItem.ReportId))
- detail.Report.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[approveItem.ReportType], cnClassifyIdName[approveItem.ClassifyFirstId], cnClassifyIdName[approveItem.ClassifySecondId])
- }
- if approveItem.ReportType == report_approve.FlowReportTypeEnglish {
- detail.Report.ReportCode = utils.MD5(strconv.Itoa(approveItem.ReportId))
- detail.Report.ReportClassify = fmt.Sprintf("%s/%s/%s/%s", report_approve.FlowReportTypeMap[approveItem.ReportType], enClassifyIdName[enRootIdMap[approveItem.ClassifySecondId]], enClassifyIdName[approveItem.ClassifyFirstId], enClassifyIdName[approveItem.ClassifySecondId])
- }
- if approveItem.ReportType == report_approve.FlowReportTypeSmart {
- detail.Report.ReportLayout = 2
- detail.Report.ReportCode = utils.MD5(fmt.Sprint("smart_", approveItem.ReportId))
- detail.Report.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[approveItem.ReportType], cnClassifyIdName[approveItem.ClassifyFirstId], cnClassifyIdName[approveItem.ClassifySecondId])
- }
- br.Data = detail
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // Approve
- // @Title 通过审批
- // @Description 通过审批
- // @Param request body report_approve.ReportApprovePassReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /approve [post]
- func (this *ReportApproveController) Approve() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req report_approve.ReportApprovePassReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- if req.ReportApproveId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
- return
- }
- approveOb := new(report_approve.ReportApprove)
- approveItem, e := approveOb.GetItemById(req.ReportApproveId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "审批不存在, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取审批信息失败, Err: " + e.Error()
- return
- }
- if approveItem.State != report_approve.ReportApproveStateApproving {
- br.Msg = "审批状态有误, 请刷新页面"
- br.ErrMsg = fmt.Sprintf("审批状态有误, State: %d", approveItem.State)
- return
- }
- // 校验审批记录和审批
- recordOb := new(report_approve.ReportApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, approveItem.ReportApproveId, sysUser.AdminId, report_approve.ReportApproveStateApproving)
- recordItem, e := recordOb.GetItemByCondition(recordCond, recordPars, "")
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "无权审批"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取审批记录失败, Err: " + e.Error()
- return
- }
- // 通过审批
- tips, e := services.PassReportApprove(approveItem, recordItem, sysUser.AdminId, req.ReportUrl)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "通过审批失败, Err: " + e.Error()
- return
- }
- if tips != "" {
- br.Msg = tips
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Refuse
- // @Title 驳回审批
- // @Description 驳回审批
- // @Param request body report_approve.ReportApproveRefuseReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /refuse [post]
- func (this *ReportApproveController) Refuse() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req report_approve.ReportApproveRefuseReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- if req.ReportApproveId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
- return
- }
- approveOb := new(report_approve.ReportApprove)
- approveItem, e := approveOb.GetItemById(req.ReportApproveId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "审批不存在, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取审批信息失败, Err: " + e.Error()
- return
- }
- if approveItem.State != report_approve.ReportApproveStateApproving {
- br.Msg = "审批状态有误, 请刷新页面"
- br.ErrMsg = fmt.Sprintf("审批状态有误, State: %d", approveItem.State)
- return
- }
- // 校验审批记录和审批
- recordOb := new(report_approve.ReportApproveRecord)
- recordCond := fmt.Sprintf(` AND %s = ? AND %s = ? AND %s = ?`, report_approve.ReportApproveRecordCols.ReportApproveId, report_approve.ReportApproveRecordCols.ApproveUserId, report_approve.ReportApproveRecordCols.State)
- recordPars := make([]interface{}, 0)
- recordPars = append(recordPars, approveItem.ReportApproveId, sysUser.AdminId, report_approve.ReportApproveStateApproving)
- recordItem, e := recordOb.GetItemByCondition(recordCond, recordPars, "")
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "无权审批"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取审批记录失败, Err: " + e.Error()
- return
- }
- // 驳回审批
- if e = services.RefuseReportApprove(approveItem, recordItem, req.ApproveRemark, sysUser.AdminId); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "驳回审批失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // Cancel
- // @Title 撤销审批
- // @Description 撤销审批
- // @Param request body report_approve.ReportApproveCancelReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /cancel [post]
- func (this *ReportApproveController) Cancel() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req report_approve.ReportApproveCancelReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- if req.ReportApproveId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportApproveId: %d", req.ReportApproveId)
- return
- }
- approveOb := new(report_approve.ReportApprove)
- approveItem, e := approveOb.GetItemById(req.ReportApproveId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "审批已被删除, 请刷新页面"
- return
- }
- br.Msg = "操作失败"
- br.ErrMsg = "获取审批失败, Err: " + e.Error()
- return
- }
- if approveItem.ApplyUserId != sysUser.AdminId {
- br.Msg = "非申请人不可撤销"
- return
- }
- // 撤销审批
- e = services.CancelReportApprove(approveItem.ReportType, approveItem.ReportId, approveItem.ReportApproveId, sysUser.AdminId, sysUser.RealName)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "撤销审批失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // MessageList
- // @Title 审批消息列表
- // @Description 审批消息列表
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码"
- // @Success 200 {object} report_approve.ReportApproveMessageListResp
- // @router /message/list [get]
- func (this *ReportApproveController) MessageList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- params := new(report_approve.ReportApproveListReq)
- if e := this.ParseForm(params); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "入参解析失败, Err: " + e.Error()
- return
- }
- // 分页
- var startSize int
- if params.PageSize <= 0 {
- params.PageSize = utils.PageSize20
- }
- if params.CurrentIndex <= 0 {
- params.CurrentIndex = 1
- }
- startSize = utils.StartIndex(params.CurrentIndex, params.PageSize)
- resp := new(report_approve.ReportApproveMessageListResp)
- resp.List = make([]*report_approve.ReportApproveMessageItem, 0)
- cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId)
- order := fmt.Sprintf(`%s ASC, %s DESC`, report_approve.ReportApproveMessageCols.IsRead, report_approve.ReportApproveMessageCols.CreateTime)
- messageOb := new(report_approve.ReportApproveMessage)
- total, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
- return
- }
- list, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, params.PageSize)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批消息列表失败, Err: " + e.Error()
- return
- }
- for _, v := range list {
- t := report_approve.FormatReportApproveMessage2Item(v)
- resp.List = append(resp.List, t)
- }
- // 未读消息数
- cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
- pars = append(pars, 0)
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
- return
- }
- resp.UnreadTotal = unreadTotal
- page := paging.GetPaging(params.CurrentIndex, params.PageSize, total)
- resp.Paging = page
- br.Data = resp
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
- // MessageRead
- // @Title 消息已读
- // @Description 消息已读
- // @Param request body report_approve.ReportApproveMessageReadReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /message/read [post]
- func (this *ReportApproveController) MessageRead() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req report_approve.ReportApproveMessageReadReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- if req.MessageId <= 0 {
- br.Msg = "参数有误"
- br.ErrMsg = fmt.Sprintf("参数有误, MessageId: %d", req.MessageId)
- return
- }
- messageOb := new(report_approve.ReportApproveMessage)
- messageItem, e := messageOb.GetItemById(req.MessageId)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "消息不存在, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批消息失败, Err: " + e.Error()
- return
- }
- messageItem.IsRead = 1
- messageItem.ModifyTime = time.Now().Local()
- cols := []string{"IsRead", "ModifyTime"}
- if e = messageItem.Update(cols); e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "更新审批消息已读失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // CheckApproveOpen
- // @Title 校验分类是否开启审批
- // @Description 校验分类是否开启审批
- // @Param request body report_approve.ReportApproveCheckApproveOpenReq true "type json string"
- // @Success 200 string "操作成功"
- // @router /classify/check_open [post]
- func (this *ReportApproveController) CheckApproveOpen() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req report_approve.ReportApproveCheckApproveOpenReq
- if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
- br.Msg = "参数有误"
- br.ErrMsg = "参数解析失败, Err: " + e.Error()
- return
- }
- // 校验是否开启了审批流
- opening, e := services.CheckReportOpenApprove(req.ReportType, req.ClassifyFirstId, req.ClassifySecondId, req.ClassifyThirdId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
- return
- }
- br.Data = opening
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|