123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package data_approve
- import (
- "eta_gn/eta_api/global"
- "eta_gn/eta_api/utils"
- "fmt"
- "time"
- )
- type DataApprove struct {
- DataApproveId int `gorm:"column:data_approve_id;primary_key"`
- Title string `gorm:"column:title"`
- DataType int `gorm:"column:data_type"`
- State int `gorm:"column:state"` // '审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回'
- FlowId int `gorm:"column:flow_id"`
- FlowVersion int `gorm:"column:flow_version"`
- StartNodeId int `gorm:"column:start_node_id"`
- CurrNodeId int `gorm:"column:curr_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"`
- }
- var DataApproveCols = struct {
- DataApproveId string
- Title string
- DataType string // 资产类型:1:指标、2:图表
- State string // '审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回'
- FlowId string
- FlowVersion string
- StartNodeId string
- CurrNodeId string
- ApplyUserId string
- ApplyUserName string
- ApproveRemark string
- ApproveTime string
- CreateTime string
- ModifyTime string
- }{
- DataApproveId: "data_approve_id",
- Title: "title",
- DataType: "data_type",
- State: "state",
- FlowId: "flow_id",
- FlowVersion: "flow_version",
- StartNodeId: "start_node_id",
- CurrNodeId: "curr_node_id",
- ApplyUserId: "apply_user_id",
- ApplyUserName: "apply_user_name",
- ApproveRemark: "approve_remark",
- ApproveTime: "approve_time",
- CreateTime: "create_time",
- ModifyTime: "modify_time",
- }
- type DataApproveItemOrm struct {
- DataApproveId int `description:"审批ID"`
- DataApproveRecordId int `description:"审批记录ID"`
- Title string `description:"审批标题"`
- DataType int `description:"资产类型"`
- State int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
- RecordState int `description:"审批记录状态:1-待审批;2-已通过;3-已驳回"`
- FlowId int `description:"审批流ID"`
- FlowVersion int `description:"审批流版本"`
- StartNodeId int `description:"开始节点ID"`
- CurrNodeId int `description:"当前节点ID"`
- ApplyUserId int `description:"申请人ID"`
- ApplyUserName string `description:"申请人姓名"`
- ApproveRemark string `description:"审批备注"`
- ApproveTime time.Time `description:"审批时间"`
- HandleTime time.Time `description:"处理时间"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- NodeState int `description:"当前节点审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回" json:"-"`
- NodeApproveTime time.Time `description:"当前节点审批时间" json:"-"`
- }
- func (b *DataApprove) TableName() string {
- return "data_approve"
- }
- func (b *DataApprove) Update(cols []string) (err error) {
- db := global.DmSQL["data"]
- err = db.Model(b).Select(cols).Updates(b).Error
- return
- }
- func (b *DataApprove) Create() (err error) {
- db := global.DmSQL["data"]
- err = db.Create(b).Error
- return
- }
- // AddDataApprove
- // @Description: 添加审批单
- // @author: Roc
- // @datetime 2024-12-06 09:46:04
- // @param dataApprove *DataApprove
- // @param relationList []*DataApproveRelation
- // @return err error
- func AddDataApprove(dataApprove *DataApprove, relationList []*DataApproveRelation) (err error) {
- db := global.DmSQL["data"].Begin()
- defer func() {
- if err != nil {
- db.Rollback()
- } else {
- db.Commit()
- }
- }()
- err = db.Create(dataApprove).Error
- if err != nil {
- return
- }
- relationIdList := make([]int, 0)
- // 关联指标
- if len(relationList) > 0 {
- for _, v := range relationList {
- v.DataApproveId = dataApprove.DataApproveId
- relationIdList = append(relationIdList, v.DataId)
- }
- err = db.CreateInBatches(relationList, utils.MultiAddNum).Error
- if err != nil {
- return
- }
- }
- // 更新资产公开状态
- switch dataApprove.DataType {
- case utils.DataApproveTypeEdb:
- sql := `UPDATE edb_info set public_status = ?,modify_time=now() WHERE edb_info_id in (?) `
- err = global.DmSQL["data"].Exec(sql, utils.DataPublicCommit, relationIdList).Error
- case utils.DataApproveTypeChart:
- sql := `UPDATE chart_info set public_status = ?,modify_time=now() WHERE chart_info_id in (?) `
- err = global.DmSQL["data"].Exec(sql, utils.DataPublicCommit, relationIdList).Error
- }
- return
- }
- func GetDataApproveByFlowIdAndVersionId(dataFlowId int, flowVersion int) (item []*DataApprove, err error) {
- db := global.DmSQL["data"]
- err = db.Where("flow_id = ? AND flow_version = ?", dataFlowId, flowVersion).Find(&item).Error
- return
- }
- func GetDataApproveById(DataApproveId int) (item *DataApprove, err error) {
- db := global.DmSQL["data"]
- err = db.Where("data_approve_id = ?", DataApproveId).First(&item).Error
- return
- }
- // GetApprovingDataApproveCount 获取待处理的审批分页列表总数
- func GetApprovingDataApproveCount(cond string, pars []interface{}) (count int, err error) {
- base := fmt.Sprintf(`SELECT a.data_approve_record_id
- FROM data_approve_record AS a
- JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id AND a.node_id = b.curr_node_id
- WHERE 1 = 1 %s`, cond)
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
- err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // GetApprovingDataApprovePageList 获取待处理的审批列表-分页
- func GetApprovingDataApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*DataApproveItemOrm, err error) {
- order := `ORDER BY a.create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT a.data_approve_record_id, a.state AS record_state, b.*
- FROM data_approve_record AS a
- JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id AND a.node_id = b.curr_node_id
- WHERE 1 = 1 %s %s
- LIMIT ?,?`, cond, order)
- pars = append(pars, startSize, pageSize)
- err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetApprovedDataApproveCount 获取已处理的审批分页列表总数
- func GetApprovedDataApproveCount(cond string, pars []interface{}) (count int, err error) {
- base := fmt.Sprintf(`SELECT a.data_approve_record_id
- FROM data_approve_record AS a
- JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id
- WHERE 1 = 1 %s`, cond)
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
- err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // GetApprovedDataApprovePageList 获取已处理的审批列表-分页
- func GetApprovedDataApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*DataApproveItemOrm, err error) {
- order := `ORDER BY a.create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT a.data_approve_record_id, a.node_state AS record_state,a.node_state,a.node_approve_time, a.node_approve_time AS handle_time, b.*
- FROM data_approve_record AS a
- JOIN data_approve AS b ON a.data_approve_id = b.data_approve_id
- WHERE 1 = 1 %s %s
- LIMIT ?,?`, cond, order)
- pars = append(pars, startSize, pageSize)
- err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetApplyDataApproveCount 获取我发起的审批分页列表总数
- func GetApplyDataApproveCount(cond string, pars []interface{}) (count int, err error) {
- base := fmt.Sprintf(`SELECT a.* FROM data_approve AS a WHERE 1 = 1 %s`, cond)
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
- err = global.DmSQL["data"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // GetApplyDataApprovePageList 获取我发起的审批列表-分页
- func GetApplyDataApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*DataApproveItemOrm, err error) {
- order := `ORDER BY a.create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT a.*,a.approve_time as handle_time,a.state as record_state FROM data_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
- pars = append(pars, startSize, pageSize)
- err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetDataApproveCountByState(state int) (count int, err error) {
- db := global.DmSQL["data"]
- sql := `SELECT COUNT(*) FROM data_approve WHERE state = ?`
- err = db.Raw(sql, state).Scan(&count).Error
- return
- }
|