瀏覽代碼

Merge branch 'feature/bi_approve' of eta_gn_server/eta_api into BI_Dashboard

鲍自强 6 月之前
父節點
當前提交
961ca0066c

+ 40 - 0
controllers/bi_approve/bi_approve.go

@@ -0,0 +1,40 @@
+package biapprove
+
+import (
+	"eta_gn/eta_api/controllers"
+	"eta_gn/eta_api/models"
+)
+
+type BIApproveController 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 *BIApproveController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+
+}

+ 302 - 0
controllers/bi_approve/bi_approve_flow.go

@@ -0,0 +1,302 @@
+package biapprove
+
+import (
+	"encoding/json"
+	"eta_gn/eta_api/controllers"
+	"eta_gn/eta_api/models"
+	"eta_gn/eta_api/models/bi_approve/request"
+	"eta_gn/eta_api/models/bi_approve/response"
+	biapprove "eta_gn/eta_api/services/bi_approve"
+	"eta_gn/eta_api/utils"
+	"strings"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+type BiApproveFlowController struct {
+	controllers.BaseAuthController
+}
+
+// List
+// @Title 审批流列表
+// @Description 审批流列表
+// @Param   PageSize			query	int		true	"每页数据条数"
+// @Param   CurrentIndex		query	int		true	"当前页页码"
+// @Param   ClassifyId		query	int		false	"分类ID"
+// @Param   Keyword				query	string	false	"搜索关键词"
+// @Param   SortRule			query	int		false	"排序方式: 1-正序; 2-倒序(默认)"
+// @Success 200 {object} report_approve.ReportApproveListResp
+// @router /flow/list [get]
+func (c *BiApproveFlowController) List() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	pageSize, _ := c.GetInt("PageSize")
+	currentIndex, _ := c.GetInt("CurrentIndex")
+	keyword := c.GetString("Keyword")
+	classifyId, _ := c.GetInt("ClassifyId", 0)
+	sortRule, _ := c.GetInt("SortRule", 2)
+	if pageSize <= 0 {
+		pageSize = utils.PageSize10
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	var condition string
+	var pars []interface{}
+	if keyword != "" {
+		condition = ` AND flow_name LIKE ?`
+		pars = utils.GetLikeKeywordPars(pars, keyword, 1)
+	}
+	if classifyId > 0 {
+		condition += ` AND classify_id = ?`
+		pars = append(pars, classifyId)
+	}
+	startSize := paging.StartIndex(currentIndex, pageSize)
+	orderMap := map[int]string{1: "ASC", 2: "DESC"}
+	condition += " ORDER BY create_time " + orderMap[sortRule]
+
+	res, total, msg, err := biapprove.GetBiApproveFlowList(condition, pars, startSize, pageSize)
+	if err != nil {
+		if msg != "" {
+			br.Msg = msg
+		} else {
+			br.Msg = "获取审批流列表失败"
+		}
+		br.ErrMsg = "获取审批流列表失败, err:" + err.Error()
+		return
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(response.BiApproveFlowListResp)
+	resp.List = res
+	resp.Paging = page
+
+	br.Data = resp
+	br.Msg = "获取审批流列表成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// Add
+// @Title 新增审批流
+// @Description 新增审批流
+// @Param	request	body request.BiApproveFlowSaveReq true "type json string"
+// @Success 200
+// @router /flow/add [post]
+func (c *BiApproveFlowController) Add() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	var req *request.BiApproveFlowSaveReq
+	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数解析失败"
+		br.ErrMsg = "参数解析失败, err:" + err.Error()
+		return
+	}
+	req.FlowName = strings.TrimSpace(req.FlowName)
+	if req.FlowName == "" {
+		br.Msg = "审批流名称不能为空"
+		return
+	}
+
+	if len([]rune(req.FlowName)) > 20 {
+		br.Msg = "审批流名称最多输入20个字符"
+		return
+	}
+	if req.ClassifyId <= 0 {
+		br.Msg = "请选择审批分类"
+		return
+	}
+	if len(req.Nodes) == 0 {
+		br.Msg = "请添加审批流程"
+		return
+	}
+
+	if req.BiApproveFlowId > 0 {
+		br.Msg = "审批流已存在"
+		return
+	}
+
+	_, msg, err := biapprove.SaveBiApproveFlow(req)
+	if err != nil {
+		if msg != "" {
+			br.Msg = msg
+		} else {
+			br.Msg = "新增审批流失败"
+		}
+		br.ErrMsg = "新增审批流失败, err:" + err.Error()
+		return
+	}
+
+	br.Msg = "新增审批流成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// edit
+// @Title 新增审批流
+// @Description 新增审批流
+// @Param	request	body request.BiApproveFlowSaveReq true "type json string"
+// @Success 200 {object} report_approve.ReportApproveFlowDetailItem
+// @router /flow/edit [post]
+func (c *BiApproveFlowController) Edit() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	var req *request.BiApproveFlowSaveReq
+	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数解析失败"
+		br.ErrMsg = "参数解析失败, err:" + err.Error()
+		return
+	}
+	req.FlowName = strings.TrimSpace(req.FlowName)
+	if req.FlowName == "" {
+		br.Msg = "审批流名称不能为空"
+		return
+	}
+
+	if len([]rune(req.FlowName)) > 20 {
+		br.Msg = "审批流名称最多输入20个字符"
+		return
+	}
+	if req.ClassifyId <= 0 {
+		br.Msg = "请选择审批分类"
+		return
+	}
+	if len(req.Nodes) == 0 {
+		br.Msg = "请添加审批流程"
+		return
+	}
+
+	if req.BiApproveFlowId == 0 {
+		br.Msg = "审批流不存在, 请刷新重试"
+		return
+	}
+
+	ok, msg, err := biapprove.SaveBiApproveFlow(req)
+	if err != nil {
+		if msg != "" {
+			br.Msg = msg
+		} else {
+			br.Msg = "编辑审批流失败"
+		}
+		br.ErrMsg = "编辑审批流失败, err:" + err.Error()
+		return
+	}
+	if !ok {
+		br.Msg = msg
+		return
+	}
+
+	br.Msg = "编辑审批流成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// delete
+// @Title 新增审批流
+// @Description 新增审批流
+// @Param	request	body request.BiApproveFlowRemoveResp true "type json string"
+// @Success 200 {object} report_approve.ReportApproveFlowDetailItem
+// @router /flow/remove [post]
+func (c *BiApproveFlowController) Remove() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	var req *request.BiApproveFlowRemoveResp
+	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数解析失败"
+		br.ErrMsg = "参数解析失败, err:" + err.Error()
+		return
+	}
+	if req.BiApproveFlowId <= 0 {
+		br.Msg = "审批流不存在, 请刷新重试"
+		return
+	}
+	ok, msg, err := biapprove.DeleteBiApproveFlow(req.BiApproveFlowId)
+	if err != nil {
+		if msg != "" {
+			br.Msg = msg
+		} else {
+			br.Msg = "删除审批流失败"
+		}
+		br.ErrMsg = "删除审批流失败, err:" + err.Error()
+		return
+	}
+	if !ok {
+		br.Msg = msg
+		return
+	}
+
+	br.Msg = "删除审批流成功"
+	br.Success = true
+	br.Ret = 200
+}
+
+// Detail
+// @Title 审批流详情
+// @Description 审批流详情
+// @Param	request	body request.BiApproveFlowRemoveResp true "type json string"
+// @Success 200 {object} report_approve.ReportApproveFlowDetailItem
+// @router /flow/detail [get]
+func (c *BiApproveFlowController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	sysUser := c.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	flowId, _ := c.GetInt("BiApproveFlowId")
+	if flowId <= 0 {
+		br.Msg = "审批流不存在"
+		return
+	}
+	detail, msg, err := biapprove.GetBiApproveFlowDetail(flowId)
+	if err != nil {
+		if msg != "" {
+			br.Msg = msg
+		} else {
+			br.Msg = "获取审批流详情失败"
+		}
+		br.ErrMsg = "获取审批流详情失败, err:" + err.Error()
+		return
+	}
+	if detail == nil {
+		br.Msg = "审批流不存在"
+		return
+	}
+
+	br.Data = detail
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取审批流详情成功"
+}

+ 25 - 0
models/bi_approve/bi_approve.go

@@ -0,0 +1,25 @@
+package biapprove
+
+import "time"
+
+type BiApprove struct {
+	BiApproveId   int       `gorm:"column:bi_approve_id;primary_key"`
+	BiId          int       `gorm:"column:bi_id"`
+	BiTitle       string    `gorm:"column:bi_tittle"`
+	ClassifyId    int       `gorm:"column:classify_id"`
+	State         int       `gorm:"column:state"`
+	FlowId        int       `gorm:"column:flow_id"`
+	FlowVersion   int       `gorm:"column:flow_version"`
+	StartNodeId   int       `gorm:"column:start_node_id"`
+	CurrentNodeId int       `gorm:"column:current_node_id"`
+	ApplyUserId   int       `gorm:"column:apply_user_id"`
+	ApplyUserName string    `gorm:"column:apply_user_name"`
+	ApproveRemark string    `gorm:"column:approve_remark"`
+	ApproveTime   time.Time `gorm:"column:approve_time"`
+	CreateTime    time.Time `gorm:"column:create_time"`
+	ModifyTime    time.Time `gorm:"column:update_time"`
+}
+
+func (b *BiApprove) TableName() string {
+	return "bi_approve"
+}

+ 148 - 0
models/bi_approve/bi_approve_flow.go

@@ -0,0 +1,148 @@
+package biapprove
+
+import (
+	"eta_gn/eta_api/global"
+	"fmt"
+	"time"
+)
+
+type BiApproveFlow struct {
+	BiApproveFlowId int       `gorm:"column:bi_approve_flow_id;primaryKey"`
+	FlowName        string    `gorm:"column:flow_name"`
+	ClassifyId      int       `gorm:"column:classify_id"`
+	ClassifyName    string    `gorm:"column:classify_name"`
+	CurrVersion     int       `gorm:"column:curr_version"`
+	CreateTime      time.Time `gorm:"column:create_time"`
+	ModifyTime      time.Time `gorm:"column:modify_time"`
+}
+
+func (b *BiApproveFlow) TableName() string {
+	return "bi_approve_flow"
+}
+
+func (b *BiApproveFlow) Add(node []*BiApproveNode) (err error) {
+	prevNodes := make([]*BiApproveNode, 0)
+	o := global.DmSQL["rddp"].Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+
+		// 更新每个节点的下一个节点信息, 放在事务中会更新失败
+		if e := UpdateNextNodes(prevNodes); e != nil {
+			err = fmt.Errorf("UpdatePrevNodes err: %s", e.Error())
+			return
+		}
+	}()
+
+	err = o.Create(b).Error
+	if err != nil {
+		err = fmt.Errorf("insert approve err: %v", err)
+		return
+	}
+
+	nodesLen := len(node)
+	if nodesLen == 0 {
+		return
+	}
+	prevId := 0
+	prevNode := new(BiApproveNode)
+	for k, v := range node {
+		v.BiApproveFlowId = b.BiApproveFlowId
+		v.PrevNodeId = prevId
+		err = o.Create(v).Error
+		if err != nil {
+			err = fmt.Errorf("insert node err: %v", err)
+			return
+		}
+		prevId = v.BiApproveNodeId
+
+		// 下一个节点
+		if prevNode != nil && k > 0 && k < nodesLen {
+			prevNode.NextNodeId = v.BiApproveNodeId
+			prevNodes = append(prevNodes, prevNode)
+		}
+		prevNode = v
+	}
+	return
+}
+
+func (b *BiApproveFlow) Update(cols []string, node []*BiApproveNode) (err error) {
+	prevNodes := make([]*BiApproveNode, 0)
+	o := global.DmSQL["rddp"].Begin()
+	defer func() {
+		if err != nil {
+			o.Rollback()
+		} else {
+			o.Commit()
+		}
+
+		// 更新每个节点的下一个节点信息, 放在事务中会更新失败
+		if e := UpdateNextNodes(prevNodes); e != nil {
+			err = fmt.Errorf("UpdatePrevNodes err: %s", e.Error())
+			return
+		}
+	}()
+	err = o.Model(b).Select(cols).Updates(b).Error
+	if err != nil {
+		return
+	}
+
+	nodesLen := len(node)
+	if nodesLen == 0 {
+		return
+	}
+	prevId := 0
+	prevNode := new(BiApproveNode)
+	for k, v := range node {
+		v.BiApproveFlowId = b.BiApproveFlowId
+		v.PrevNodeId = prevId
+		err = o.Create(v).Error
+		if err != nil {
+			err = fmt.Errorf("insert node err: %v", err)
+			return
+		}
+		prevId = v.BiApproveNodeId
+
+		// 下一个节点
+		if prevNode != nil && k > 0 && k < nodesLen {
+			prevNode.NextNodeId = v.BiApproveNodeId
+			prevNodes = append(prevNodes, prevNode)
+		}
+		prevNode = v
+	}
+	return
+}
+
+func (b *BiApproveFlow) Delete() error {
+	return global.DmSQL["rddp"].Delete(b).Error
+}
+
+func GetBiApproveFlowById(biApproveFlowId int) (item *BiApproveFlow, err error) {
+	err = global.DmSQL["rddp"].Where("bi_approve_flow_id = ?", biApproveFlowId).First(&item).Error
+	return
+}
+
+func GetBiApproveFlowByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*BiApproveFlow, err error) {
+	o := global.DmSQL["rddp"]
+	sql := "SELECT * FROM bi_approve_flow WHERE 1=1 "
+	if condition != "" {
+		sql += condition
+	}
+	sql += " LIMIT ?,?"
+	pars = append(pars, startSize, pageSize)
+	err = o.Raw(sql, pars...).Scan(&items).Error
+	return
+}
+
+func GetBiApproveFlowCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := global.DmSQL["rddp"]
+	sql := "SELECT COUNT(*) AS count FROM bi_approve_flow WHERE 1=1 "
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars...).Scan(&count).Error
+	return
+}

+ 20 - 0
models/bi_approve/bi_approve_message.go

@@ -0,0 +1,20 @@
+package biapprove
+
+import "time"
+
+type ReportApproveMessage struct {
+	Id            int       `gorm:"primaryKey;column:id"`
+	SendUserId    int       `gorm:"column:send_user_id"`      // 发送人Id
+	ReceiveUserId int       `gorm:"column:receive_user_id"`   // 接收者Id
+	Content       string    `gorm:"column:content"`           // 消息内容
+	Remark        string    `gorm:"column:remark"`            // 备注信息
+	BiApproveId   int       `gorm:"column:report_approve_id"` // 审批Id
+	ApproveState  int       `gorm:"column:approve_state"`     // 审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回
+	IsRead        int       `gorm:"column:is_read"`           // 是否已读:0-未读;1-已读
+	CreateTime    time.Time `gorm:"column:create_time"`       // 创建时间
+	ModifyTime    time.Time `gorm:"column:modify_time"`       // 修改时间
+}
+
+func (r *ReportApproveMessage) TableName() string {
+	return "bi_approve_message"
+}

+ 43 - 0
models/bi_approve/bi_approve_node.go

@@ -0,0 +1,43 @@
+package biapprove
+
+import (
+	"eta_gn/eta_api/global"
+	"fmt"
+	"time"
+)
+
+type BiApproveNode struct {
+	BiApproveNodeId int       `gorm:"column:bi_approve_node_id;primaryKey"`
+	BiApproveFlowId int       `gorm:"column:bi_approve_flow_id"`
+	PrevNodeId      int       `gorm:"column:prev_node_id"`
+	NextNodeId      int       `gorm:"column:next_node_id"`
+	NodeType        int       `gorm:"column:node_type"`
+	ApproveType     int       `gorm:"column:approve_type"`
+	Users           string    `gorm:"column:users"`
+	CurrVersion     int       `gorm:"column:curr_version"`
+	CreatedTime     time.Time `gorm:"column:created_time"`
+}
+
+func (b *BiApproveNode) TableName() string {
+	return "bi_approve_node"
+}
+
+func UpdateNextNodes(nodes []*BiApproveNode) (err error) {
+	if len(nodes) == 0 {
+		return
+	}
+	updateCols := []string{"NextNodeId"}
+	for _, v := range nodes {
+		e := global.DmSQL["rddp"].Select(updateCols).Updates(v).Error
+		if e != nil {
+			err = fmt.Errorf("prev node update err: %v", e)
+			return
+		}
+	}
+	return
+}
+
+func GetBiApproveNodeByFlowIdAndVersionId(flowId int, versionId int) (node []*BiApproveNode, err error) {
+	err = global.DmSQL["rddp"].Model(&BiApproveNode{}).Where("bi_approve_flow_id =? AND curr_version =?", flowId, versionId).Scan(&node).Error
+	return
+}

+ 29 - 0
models/bi_approve/bi_approve_record.go

@@ -0,0 +1,29 @@
+package biapprove
+
+import "time"
+
+type BiApproveRecord struct {
+	BiApproveRecordId   int       `gorm:"column:bi_approve_record_id;primary_key"`
+	BiApproveId         int       `gorm:"column:bi_approve_id"`
+	State               int       `gorm:"column:state"`
+	NodeId              int       `gorm:"column:node_id"`
+	NodeType            int       `gorm:"column:node_type"`
+	PrevNodeId          int       `gorm:"column:prev_node_id"`
+	NextNodeId          int       `gorm:"column:next_node_id"`
+	ApproveType         int       `gorm:"column:approve_type"`
+	ApproveUserId       int       `gorm:"column:approve_user_id"`
+	ApproveUserName     string    `gorm:"column:approve_user_name"`
+	ApproveUserSort     int       `gorm:"column:approve_user_sort"`
+	ApproveRemark       string    `gorm:"column:approve_remark"`
+	ApproveTime         time.Time `gorm:"column:approve_time"`
+	CreateTime          time.Time `gorm:"column:create_time"`
+	ModifyTime          time.Time `gorm:"column:modify_time"`
+	NodeState           int       `gorm:"column:node_state"`
+	NodeApproveUserId   int       `gorm:"column:node_approve_user_id"`
+	NodeApproveUserName string    `gorm:"column:node_approve_user_name"`
+	NodeApproveTime     time.Time `gorm:"column:node_approve_time"`
+}
+
+func (b *BiApproveRecord) TableName() string {
+	return "bi_approve_record"
+}

+ 23 - 0
models/bi_approve/request/bi_approve_flow.go

@@ -0,0 +1,23 @@
+package request
+
+type BiApproveFlowSaveReq struct {
+	BiApproveFlowId int
+	ClassifyId      int
+	FlowName        string
+	Nodes           []Node
+}
+
+type Node struct {
+	ApproveType int `description:"审批类型: 1-依次审批, 2-会签, 3-或签"`
+	Users       []User
+}
+
+type User struct {
+	UserId   int    `description:"用户ID"`
+	UserName string `description:"用户名"`
+	UserType string `description:"用户类型: user-用户 role-角色"`
+}
+
+type BiApproveFlowRemoveResp struct {
+	BiApproveFlowId int
+}

+ 39 - 0
models/bi_approve/response/bi_approve_flow.go

@@ -0,0 +1,39 @@
+package response
+
+import "github.com/rdlucklib/rdluck_tools/paging"
+
+type BiApproveFlowItem struct {
+	BiApproveFlowId int    `description:"主键"`
+	FlowName        string `description:"bi审批流程名称"`
+	ClassifyId      int    `description:"分类ID"`
+	ClassifyName    string `description:"分类名称"`
+	CurrVersion     int    `description:"当前版本"`
+	CreateTime      string `description:"创建时间"`
+	ModifyTime      string `description:"修改时间"`
+}
+
+type BiApproveFlowListResp struct {
+	List   []*BiApproveFlowItem
+	Paging *paging.PagingItem
+}
+
+type BiApproveFlowDetailResp struct {
+	BiApproveFlowItem `description:"审批流信息"`
+	Nodes             []*BiApproveNodeItem `description:"节点信息"`
+}
+
+type BiApproveNodeUser struct {
+	UserType string `description:"审批人类型: user-用户; role-角色"`
+	UserId   int    `description:"用户/角色ID"`
+	UserName string `description:"用户/角色姓名"`
+	Sort     int    `description:"排序"`
+}
+type BiApproveNodeItem struct {
+	BiApproveNodeId int                  `description:"BI审批节点ID"`
+	BiApproveFlowId int                  `description:"BI审批流ID"`
+	PrevNodeId      int                  `description:"上一个节点ID(0为开始节点)"`
+	NextNodeId      int                  `description:"下一个节点ID(0为结束节点)"`
+	NodeType        int                  `description:"节点类型:0-审批;1-抄送"`
+	ApproveType     int                  `description:"审批类型:1-依次审批;2-会签;3-或签"`
+	Users           []*BiApproveNodeUser `description:"审批人信息"`
+}

+ 54 - 0
routers/commentsRouter.go

@@ -241,6 +241,60 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BIApproveController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BIApproveController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"],
+        beego.ControllerComments{
+            Method: "Add",
+            Router: `/flow/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/flow/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"],
+        beego.ControllerComments{
+            Method: "Edit",
+            Router: `/flow/edit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/flow/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/bi_approve:BiApproveFlowController"],
+        beego.ControllerComments{
+            Method: "Remove",
+            Router: `/flow/remove`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta_gn/eta_api/controllers/data_manage/correlation:CorrelationChartClassifyController"] = append(beego.GlobalControllerRouter["eta_gn/eta_api/controllers/data_manage/correlation:CorrelationChartClassifyController"],
         beego.ControllerComments{
             Method: "AddChartClassify",

+ 6 - 0
routers/router.go

@@ -10,6 +10,7 @@ package routers
 import (
 	"eta_gn/eta_api/controllers"
 	"eta_gn/eta_api/controllers/ai"
+	biapprove "eta_gn/eta_api/controllers/bi_approve"
 	"eta_gn/eta_api/controllers/data_manage"
 	"eta_gn/eta_api/controllers/data_manage/correlation"
 	"eta_gn/eta_api/controllers/data_manage/cross_variety"
@@ -352,6 +353,11 @@ func init() {
 				&report_approve.ReportApproveFlowController{},
 			),
 		),
+		web.NSNamespace("/bi_approve",
+			web.NSInclude(
+				&biapprove.BiApproveFlowController{},
+			),
+		),
 		web.NSNamespace("/data_source",
 			web.NSInclude(
 				&data_source.DataSourceController{},

+ 203 - 0
services/bi_approve/bi_approve_flow.go

@@ -0,0 +1,203 @@
+package biapprove
+
+import (
+	"encoding/json"
+	biapprove "eta_gn/eta_api/models/bi_approve"
+	"eta_gn/eta_api/models/bi_approve/request"
+	"eta_gn/eta_api/models/bi_approve/response"
+	"eta_gn/eta_api/utils"
+	"fmt"
+	"time"
+)
+
+// GetBiApproveFlowList 获取BI审批流列表
+func GetBiApproveFlowList(condition string, pars []interface{}, startSize, pageSize int) (items []*response.BiApproveFlowItem, total int, msg string, err error) {
+	total, err = biapprove.GetBiApproveFlowCountByCondition(condition, pars)
+	if err != nil {
+		msg = "获取审批流程列表失败"
+		return
+	}
+	if total == 0 {
+		items = make([]*response.BiApproveFlowItem, 0)
+		return
+	}
+	flowList, err := biapprove.GetBiApproveFlowByCondition(condition, pars, startSize, pageSize)
+	if err != nil {
+		msg = "获取审批流程列表失败"
+		return
+	}
+	items = toBiApproveFlowItem(flowList)
+	return
+}
+
+// SaveBiApproveFlow 保存审批流
+func SaveBiApproveFlow(flow *request.BiApproveFlowSaveReq) (ok bool, msg string, err error) {
+	if flow.BiApproveFlowId == 0 {
+		t := &biapprove.BiApproveFlow{
+			FlowName:    flow.FlowName,
+			ClassifyId:  flow.ClassifyId,
+			CurrVersion: 1,
+			CreateTime:  time.Now(),
+			ModifyTime:  time.Now(),
+		}
+		biFlowNodeItems := make([]*biapprove.BiApproveNode, 0)
+		for _, node := range flow.Nodes {
+			biFlowNode := new(biapprove.BiApproveNode)
+			biFlowNode.ApproveType = node.ApproveType
+			biFlowNode.CurrVersion = t.CurrVersion
+			userBytes, er := json.Marshal(node.Users)
+			if er != nil {
+				err = er
+				msg = "保存审批流失败"
+				return
+			}
+			biFlowNode.Users = string(userBytes)
+			biFlowNode.CreatedTime = time.Now()
+			biFlowNodeItems = append(biFlowNodeItems, biFlowNode)
+		}
+		err = t.Add(biFlowNodeItems)
+		if err != nil {
+			msg = "保存审批流失败"
+			return
+		}
+		ok = true
+	} else {
+		resFlow, er := biapprove.GetBiApproveFlowById(flow.BiApproveFlowId)
+		if er != nil {
+			msg = "保存审批流失败"
+			err = er
+			return
+		}
+		ok, err = CheckDeleteBiApproveFlow(resFlow.BiApproveFlowId)
+		if err != nil {
+			msg = "保存审批流失败"
+			return
+		}
+		if !ok {
+			msg = "保存审批流失败, 存在还未审批的报告"
+			return
+		}
+		var updateCols []string
+		if resFlow.FlowName != flow.FlowName {
+			resFlow.FlowName = flow.FlowName
+			updateCols = append(updateCols, "flow_name")
+		}
+		resFlow.CurrVersion += 1
+		resFlow.ModifyTime = time.Now()
+		updateCols = append(updateCols, "modify_time", "curr_version")
+
+		biFlowNodeItems := make([]*biapprove.BiApproveNode, 0)
+		for _, node := range flow.Nodes {
+			biFlowNode := new(biapprove.BiApproveNode)
+			biFlowNode.ApproveType = node.ApproveType
+			biFlowNode.CurrVersion = resFlow.CurrVersion
+			userBytes, er := json.Marshal(node.Users)
+			if er != nil {
+				err = er
+				msg = "保存审批流失败"
+				return
+			}
+			biFlowNode.Users = string(userBytes)
+			biFlowNode.CreatedTime = time.Now()
+			biFlowNodeItems = append(biFlowNodeItems, biFlowNode)
+		}
+
+		err = resFlow.Update(updateCols, biFlowNodeItems)
+		if err != nil {
+			msg = "保存审批流失败"
+			return
+		}
+		ok = true
+	}
+	return
+}
+
+func GetBiApproveFlowDetail(flowId int) (detail *response.BiApproveFlowDetailResp, msg string, err error) {
+	flowInfo, err := biapprove.GetBiApproveFlowById(flowId)
+	if err != nil {
+		msg = "获取审批流详情失败"
+		return
+	}
+	flowNodes, err := biapprove.GetBiApproveNodeByFlowIdAndVersionId(flowId, flowInfo.CurrVersion)
+	if err != nil {
+		msg = "获取审批流详情失败"
+		return
+	}
+	detail, err = FormatFlowAndNodesItem2Detail(flowInfo, flowNodes)
+	if err != nil {
+		msg = "获取审批流详情失败"
+		return
+	}
+	return
+}
+
+func DeleteBiApproveFlow(flowId int) (ok bool, msg string, err error) {
+	ok, err = CheckDeleteBiApproveFlow(flowId)
+	if err != nil {
+		msg = "删除审批流失败"
+		return
+	}
+	if !ok {
+		msg = "删除审批流失败, 存在还未审批的报告"
+		return
+	}
+
+	t := &biapprove.BiApproveFlow{
+		BiApproveFlowId: flowId,
+	}
+	err = t.Delete()
+	if err != nil {
+		msg = "删除审批流失败"
+		return
+	}
+	ok = true
+	return
+}
+
+func CheckDeleteBiApproveFlow(flowId int) (ok bool, err error) {
+	_, err = biapprove.GetBiApproveFlowById(flowId)
+	if err != nil {
+		return
+	}
+	// TODO: 检查是否存在还未审批的报告
+	ok = true
+	return
+}
+
+func toBiApproveFlowItem(src []*biapprove.BiApproveFlow) (res []*response.BiApproveFlowItem) {
+	res = make([]*response.BiApproveFlowItem, 0, len(src))
+	for _, item := range src {
+		res = append(res, &response.BiApproveFlowItem{
+			BiApproveFlowId: item.BiApproveFlowId,
+			FlowName:        item.FlowName,
+			ClassifyId:      item.ClassifyId,
+			ClassifyName:    item.ClassifyName,
+			CurrVersion:     item.CurrVersion,
+			CreateTime:      item.CreateTime.Format(utils.FormatDateTime),
+			ModifyTime:      item.ModifyTime.Format(utils.FormatDateTime),
+		})
+	}
+	return
+}
+
+func FormatFlowAndNodesItem2Detail(flowItem *biapprove.BiApproveFlow, nodeItems []*biapprove.BiApproveNode) (detail *response.BiApproveFlowDetailResp, err error) {
+	if flowItem == nil {
+		return
+	}
+	detail = new(response.BiApproveFlowDetailResp)
+	detail.BiApproveFlowId = flowItem.BiApproveFlowId
+	detail.FlowName = flowItem.FlowName
+	detail.ClassifyId = flowItem.ClassifyId
+	detail.CreateTime = utils.TimeTransferString(utils.FormatDateTime, flowItem.CreateTime)
+	detail.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, flowItem.ModifyTime)
+	detail.Nodes = make([]*response.BiApproveNodeItem, 0)
+	for _, v := range nodeItems {
+		t, e := FormatReportApproveNode2Item(v)
+		if e != nil {
+			err = fmt.Errorf("format node err: %s", e.Error())
+			return
+		}
+		detail.Nodes = append(detail.Nodes, t)
+	}
+	return
+}

+ 31 - 0
services/bi_approve/bi_approve_node.go

@@ -0,0 +1,31 @@
+package biapprove
+
+import (
+	"encoding/json"
+	biapprove "eta_gn/eta_api/models/bi_approve"
+	"eta_gn/eta_api/models/bi_approve/response"
+	"fmt"
+)
+
+// FormatReportApproveNode2Item 格式化报告审批节点信息
+func FormatReportApproveNode2Item(origin *biapprove.BiApproveNode) (item *response.BiApproveNodeItem, err error) {
+	if origin == nil {
+		return
+	}
+	item = new(response.BiApproveNodeItem)
+	item.BiApproveNodeId = origin.BiApproveNodeId
+	item.BiApproveFlowId = origin.BiApproveFlowId
+	item.PrevNodeId = origin.PrevNodeId
+	item.NextNodeId = origin.NextNodeId
+	item.NodeType = origin.NodeType
+	item.ApproveType = origin.ApproveType
+	item.Users = make([]*response.BiApproveNodeUser, 0)
+	if origin.Users != "" {
+		e := json.Unmarshal([]byte(origin.Users), &item.Users)
+		if e != nil {
+			err = fmt.Errorf("node users unmarshal err: %s", e.Error())
+			return
+		}
+	}
+	return
+}