123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- package biapprove
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "time"
- )
- type BiApprove struct {
- BiApproveId int `gorm:"column:bi_approve_id;primary_key"`
- BiId int `gorm:"column:bi_id"`
- BiTitle string `gorm:"column:bi_title"`
- ClassifyId int `gorm:"column:classify_id"`
- 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 BiApproveCols = struct {
- BiApproveId string
- BiId string
- BiTitle string
- ClassifyId string
- 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
- }{
- BiApproveId: "bi_approve_id",
- BiId: "bi_id",
- BiTitle: "bi_title",
- ClassifyId: "classify_id",
- 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 BiApproveItemOrm struct {
- BiApproveId int `description:"审批ID"`
- BiApproveRecordId int `description:"审批记录ID"`
- BiId int `description:"报告ID"`
- BiTitle string `description:"报告标题"`
- ClassifyId int `description:"分类ID"`
- 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 *BiApprove) TableName() string {
- return "bi_approve"
- }
- func (b *BiApprove) Update(cols []string) (err error) {
- db := global.DmSQL["rddp"]
- err = db.Model(b).Select(cols).Updates(b).Error
- return
- }
- func (b *BiApprove) Create() (err error) {
- db := global.DmSQL["rddp"]
- err = db.Create(b).Error
- return
- }
- func GetBiApproveByFlowIdAndVersionId(biFlowId int, flowVersion int) (item []*BiApprove, err error) {
- db := global.DmSQL["rddp"]
- err = db.Where("flow_id = ? AND flow_version = ?", biFlowId, flowVersion).Find(&item).Error
- return
- }
- func GetBiApproveById(biApproveId int) (item *BiApprove, err error) {
- db := global.DmSQL["rddp"]
- err = db.Where("bi_approve_id = ?", biApproveId).First(&item).Error
- return
- }
- // GetApprovingBiApproveCount 获取待处理的审批分页列表总数
- func GetApprovingBiApproveCount(cond string, pars []interface{}) (count int, err error) {
- base := fmt.Sprintf(`SELECT a.bi_approve_record_id
- FROM bi_approve_record AS a
- JOIN bi_approve AS b ON a.bi_approve_id = b.bi_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["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // GetApprovingBiApprovePageList 获取待处理的审批列表-分页
- func GetApprovingBiApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BiApproveItemOrm, err error) {
- order := `ORDER BY a.create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT a.bi_approve_record_id, a.state AS record_state, b.*
- FROM bi_approve_record AS a
- JOIN bi_approve AS b ON a.bi_approve_id = b.bi_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["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetApprovedBiApproveCount 获取已处理的审批分页列表总数
- func GetApprovedBiApproveCount(cond string, pars []interface{}) (count int, err error) {
- base := fmt.Sprintf(`SELECT a.bi_approve_record_id
- FROM bi_approve_record AS a
- JOIN bi_approve AS b ON a.bi_approve_id = b.bi_approve_id
- WHERE 1 = 1 %s`, cond)
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // GetApprovedBiApprovePageList 获取已处理的审批列表-分页
- func GetApprovedBiApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BiApproveItemOrm, err error) {
- order := `ORDER BY a.create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT a.bi_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 bi_approve_record AS a
- JOIN bi_approve AS b ON a.bi_approve_id = b.bi_approve_id
- WHERE 1 = 1 %s %s
- LIMIT ?,?`, cond, order)
- pars = append(pars, startSize, pageSize)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetApplyBiApproveCount 获取我发起的审批分页列表总数
- func GetApplyBiApproveCount(cond string, pars []interface{}) (count int, err error) {
- base := fmt.Sprintf(`SELECT a.* FROM bi_approve AS a WHERE 1 = 1 %s`, cond)
- sql := fmt.Sprintf(`SELECT COUNT(1) FROM (%s) t`, base)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
- return
- }
- // GetApplyBiApprovePageList 获取我发起的审批列表-分页
- func GetApplyBiApprovePageList(cond string, pars []interface{}, orderRule string, startSize, pageSize int) (items []*BiApproveItemOrm, err error) {
- order := `ORDER BY a.create_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT a.* FROM bi_approve AS a WHERE 1 = 1 %s %s LIMIT ?,?`, cond, order)
- pars = append(pars, startSize, pageSize)
- err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetBiApproveByBoardId(biApproveId int) (item *BiApprove, err error) {
- db := global.DmSQL["rddp"]
- err = db.Where("bi_id = ?", biApproveId).Order("create_time DESC").First(&item).Error
- return
- }
- func GetBiApproveCountByState(state int) (count int, err error) {
- db := global.DmSQL["rddp"]
- sql := `SELECT COUNT(*) FROM bi_approve WHERE state = ?`
- err = db.Raw(sql, state).Scan(&count).Error
- return
- }
|