12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- 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"
- "sort"
- "strconv"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- // 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 ClassifyIdThird 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 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ReportType)
- pars = append(pars, params.ReportType)
- }
- if params.ClassifyFirstId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyFirstId)
- pars = append(pars, params.ClassifyFirstId)
- }
- if params.ClassifySecondId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifySecondId)
- pars = append(pars, params.ClassifySecondId)
- }
- if params.ClassifyThirdId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyThirdId)
- pars = append(pars, params.ClassifyThirdId)
- }
- 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 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ReportType)
- pars = append(pars, params.ReportType)
- }
- if params.ClassifyFirstId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyFirstId)
- pars = append(pars, params.ClassifyFirstId)
- }
- if params.ClassifySecondId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifySecondId)
- pars = append(pars, params.ClassifySecondId)
- }
- if params.ClassifyThirdId > 0 {
- cond += fmt.Sprintf(` AND b.%s = ?`, report_approve.ReportApproveCols.ClassifyThirdId)
- pars = append(pars, params.ClassifyThirdId)
- }
- 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 {
- cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ReportType)
- pars = append(pars, params.ReportType)
- }
- if params.ClassifyFirstId > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ClassifyFirstId)
- pars = append(pars, params.ClassifyFirstId)
- }
- if params.ClassifySecondId > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ClassifySecondId)
- pars = append(pars, params.ClassifySecondId)
- }
- if params.ClassifyThirdId > 0 {
- cond += fmt.Sprintf(` AND a.%s = ?`, report_approve.ReportApproveCols.ClassifyThirdId)
- pars = append(pars, params.ClassifyThirdId)
- }
- 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 {
- var classifyPath []string
- if v.ReportType > 0 {
- classifyPath = append(classifyPath, report_approve.FlowReportTypeMap[v.ReportType])
- }
- if v.ClassifyFirstId > 0 {
- classifyPath = append(classifyPath, enClassifyIdName[v.ClassifyFirstId])
- }
- if v.ClassifySecondId > 0 {
- classifyPath = append(classifyPath, enClassifyIdName[v.ClassifySecondId])
- }
- if v.ClassifyThirdId > 0 {
- classifyPath = append(classifyPath, enClassifyIdName[v.ClassifyThirdId])
- }
- t.ReportClassify = strings.Join(classifyPath, "/")
- } else {
- //t.ReportClassify = fmt.Sprintf("%s/%s/%s", report_approve.FlowReportTypeMap[v.ReportType], cnClassifyIdName[v.ClassifyFirstId], cnClassifyIdName[v.ClassifySecondId])
- var classifyPath []string
- if v.ReportType > 0 {
- classifyPath = append(classifyPath, report_approve.FlowReportTypeMap[v.ReportType])
- }
- if v.ClassifyFirstId > 0 {
- classifyPath = append(classifyPath, cnClassifyIdName[v.ClassifyFirstId])
- }
- if v.ClassifySecondId > 0 {
- classifyPath = append(classifyPath, cnClassifyIdName[v.ClassifySecondId])
- }
- if v.ClassifyThirdId > 0 {
- classifyPath = append(classifyPath, cnClassifyIdName[v.ClassifyThirdId])
- }
- t.ReportClassify = strings.Join(classifyPath, "/")
- }
- 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))
- }
- if approveItem.ReportType == report_approve.FlowReportTypeEnglish {
- detail.Report.ReportCode = utils.MD5(strconv.Itoa(approveItem.ReportId))
- }
- if approveItem.ReportType == report_approve.FlowReportTypeSmart {
- detail.Report.ReportLayout = 2
- detail.Report.ReportCode = utils.MD5(fmt.Sprint("smart_", approveItem.ReportId))
- }
- var classifyPath []string
- if approveItem.ReportType > 0 {
- classifyPath = append(classifyPath, report_approve.FlowReportTypeMap[approveItem.ReportType])
- }
- if approveItem.ReportType == report_approve.FlowReportTypeEnglish {
- if approveItem.ClassifyFirstId > 0 {
- classifyPath = append(classifyPath, enClassifyIdName[approveItem.ClassifyFirstId])
- }
- if approveItem.ClassifySecondId > 0 {
- classifyPath = append(classifyPath, enClassifyIdName[approveItem.ClassifySecondId])
- }
- if approveItem.ClassifyThirdId > 0 {
- classifyPath = append(classifyPath, enClassifyIdName[approveItem.ClassifyThirdId])
- }
- detail.Report.ReportClassify = strings.Join(classifyPath, "/")
- } else {
- if approveItem.ClassifyFirstId > 0 {
- classifyPath = append(classifyPath, cnClassifyIdName[approveItem.ClassifyFirstId])
- }
- if approveItem.ClassifySecondId > 0 {
- classifyPath = append(classifyPath, cnClassifyIdName[approveItem.ClassifySecondId])
- }
- if approveItem.ClassifyThirdId > 0 {
- classifyPath = append(classifyPath, cnClassifyIdName[approveItem.ClassifyThirdId])
- }
- detail.Report.ReportClassify = strings.Join(classifyPath, "/")
- }
- }
- 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 = "操作成功"
- }
|