123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package business_trip
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "time"
- )
- type BusinessApply struct {
- BusinessApplyId int `orm:"column(business_apply_id);pk;auto" description:"ID"`
- ApplyAdminId int `description:"申请人id"`
- ApplyRealName string `description:"申请人姓名"`
- ArriveDate string `description:"到达日期"`
- ReturnDate string `description:"返程日期"`
- Province string `description:"目的地省"`
- City string `description:"目的地市"`
- Reason string `description:"出差事由"`
- Transportation string `description:"交通工具"`
- PeerPeopleId string `description:"同行人id"`
- PeerPeopleName string `description:"同行人"`
- Status string `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
- ApproveId int `description:"审批人id"`
- ApproveName string `description:"审批人姓名"`
- RefuseReason string `description:"拒绝理由"`
- RefuseTime time.Time `description:"拒绝时间"`
- ApproveTime time.Time `description:"审批时间"`
- CloseReason string `description:"关闭理由"`
- CloseTime time.Time `description:"关闭时间"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- }
- // 添加出差申请
- func AddBusinessApply(item *BusinessApply) (applyId int64, err error) {
- o := orm.NewOrm()
- applyId, err = o.Insert(item)
- if err != nil {
- return
- }
- return
- }
- type BusinessApplyReq struct {
- ArriveDate string `description:"到达日期"`
- ReturnDate string `description:"返程日期"`
- Province string `description:"目的地省"`
- City string `description:"目的地市"`
- Reason string `description:"出差事由"`
- Transportation string `description:"交通工具"`
- PeerPeopleId string `description:"同行人id"`
- PeerPeopleName string `description:"同行人"`
- }
- type BusinessApplyView struct {
- BusinessApplyId int `description:"出差申请id"`
- ApplyAdminId int `description:"申请人id"`
- ApplyRealName string `description:"申请人姓名"`
- ArriveDate string `description:"到达日期"`
- ReturnDate string `description:"返程日期"`
- Province string `description:"目的地省"`
- City string `description:"目的地市"`
- Reason string `description:"出差事由"`
- Transportation string `description:"交通工具"`
- PeerPeopleId string `description:"同行人id"`
- PeerPeopleName string `description:"同行人"`
- Status string `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
- ApproveId int `description:"审批人id"`
- ApproveName string `description:"审批人姓名"`
- RefuseReason string `description:"拒绝理由"`
- RefuseTime string `description:"拒绝时间"`
- ApproveTime string `description:"审批时间"`
- CreateTime string `description:"创建时间"`
- ModifyTime string `description:"修改时间"`
- IsApprove bool `description:"是否审批人,true:是,false:否"`
- CloseReason string `description:"关闭理由"`
- CloseTime string `description:"关闭时间"`
- IsClose bool `description:"true,可关闭,false,不可关闭"`
- }
- func GetBusinessApplyListCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM business_apply AS a WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetBusinessApplyList(condition string, pars []interface{}, startSize, pageSize int) (list []*BusinessApplyView, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM business_apply AS a WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
- return
- }
- type BusinessApplyListResp struct {
- Paging *paging.PagingItem
- List []*BusinessApplyView
- }
- type BusinessApplyDeleteReq struct {
- BusinessApplyId int `description:"出差申请id"`
- }
- func GetBusinessApplyById(businessApplyId int) (item *BusinessApplyView, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM business_apply WHERE business_apply_id=? `
- err = o.Raw(sql, businessApplyId).QueryRow(&item)
- return
- }
- // 删除
- func DeleteBusinessApply(businessApplyId int) (err error) {
- o := orm.NewOrm()
- sql := ` DELETE FROM business_apply WHERE business_apply_id=? `
- _, err = o.Raw(sql, businessApplyId).Exec()
- if err != nil {
- return err
- }
- return err
- }
- type BusinessApplyBackReq struct {
- BusinessApplyId int `description:"出差申请id"`
- }
- // 更新
- func UpdateBusinessApply(where, updateParams map[string]interface{}) error {
- o := orm.NewOrm()
- ptrStructOrTableName := "business_apply"
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range where {
- qs = qs.Filter(expr, exprV)
- }
- _, err := qs.Update(updateParams)
- return err
- }
- type BusinessApplyEditReq struct {
- BusinessApplyId int `description:"出差申请id"`
- ArriveDate string `description:"到达日期"`
- ReturnDate string `description:"返程日期"`
- Province string `description:"目的地省"`
- City string `description:"目的地市"`
- Reason string `description:"出差事由"`
- Transportation string `description:"交通工具"`
- PeerPeopleId string `description:"同行人id"`
- PeerPeopleName string `description:"同行人"`
- }
- func CheckBusinessApplyDateCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM business_apply AS a
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func CheckBusinessApplyDate(startDateTime, endDateTime, status string, applyId, businessApplyId int) (calendarCount int, err error) {
- var condition string
- var pars []interface{}
- if businessApplyId > 0 {
- condition += " AND business_apply_id <> ? "
- pars = append(pars, businessApplyId)
- }
- condition += " AND apply_admin_id = ? "
- pars = append(pars, applyId)
- condition += " AND status IN (" + status + ") "
- condition += ` AND ((? >= arrive_date AND ? <= return_date) OR (? >= arrive_date AND ? <= return_date))`
- pars = append(pars, startDateTime)
- pars = append(pars, startDateTime)
- pars = append(pars, endDateTime)
- pars = append(pars, endDateTime)
- calendarCount, err = CheckBusinessApplyDateCount(condition, pars)
- return
- }
- func CheckBusinessApplyPeerDateCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count FROM business_apply_peer AS a
- WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func CheckBusinessApplyPeerDate(startDateTime, endDateTime, status string, applyId, businessApplyId int) (calendarCount int, err error) {
- var condition string
- var pars []interface{}
- if businessApplyId > 0 {
- condition += " AND business_apply_id <> ? "
- pars = append(pars, businessApplyId)
- }
- condition += " AND peer_people_id = ? "
- pars = append(pars, applyId)
- condition += " AND status IN (" + status + ") "
- condition += ` AND ((? >= arrive_date AND ? <= return_date) OR (? >= arrive_date AND ? <= return_date))`
- pars = append(pars, startDateTime)
- pars = append(pars, startDateTime)
- pars = append(pars, endDateTime)
- pars = append(pars, endDateTime)
- calendarCount, err = CheckBusinessApplyPeerDateCount(condition, pars)
- return
- }
- type BusinessApplyCloseReq struct {
- BusinessApplyId int `description:"出差申请id"`
- CloseReason string `description:"关闭原因"`
- }
- // 更新
- func UpdateBusinessApplyPeer(where, updateParams map[string]interface{}) error {
- o := orm.NewOrm()
- ptrStructOrTableName := "business_apply_peer"
- qs := o.QueryTable(ptrStructOrTableName)
- for expr, exprV := range where {
- qs = qs.Filter(expr, exprV)
- }
- _, err := qs.Update(updateParams)
- return err
- }
|