business_apply.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package business_trip
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. type BusinessApply struct {
  8. BusinessApplyId int `orm:"column(business_apply_id);pk;auto" description:"ID"`
  9. ApplyAdminId int `description:"申请人id"`
  10. ApplyRealName string `description:"申请人姓名"`
  11. ArriveDate string `description:"到达日期"`
  12. ReturnDate string `description:"返程日期"`
  13. Province string `description:"目的地省"`
  14. City string `description:"目的地市"`
  15. Reason string `description:"出差事由"`
  16. Transportation string `description:"交通工具"`
  17. PeerPeopleId string `description:"同行人id"`
  18. PeerPeopleName string `description:"同行人"`
  19. Status string `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
  20. ApproveId int `description:"审批人id"`
  21. ApproveName string `description:"审批人姓名"`
  22. RefuseReason string `description:"拒绝理由"`
  23. RefuseTime time.Time `description:"拒绝时间"`
  24. ApproveTime time.Time `description:"审批时间"`
  25. CloseReason string `description:"关闭理由"`
  26. CloseTime time.Time `description:"关闭时间"`
  27. CreateTime time.Time `description:"创建时间"`
  28. ModifyTime time.Time `description:"修改时间"`
  29. }
  30. // 添加出差申请
  31. func AddBusinessApply(item *BusinessApply) (applyId int64, err error) {
  32. o := orm.NewOrm()
  33. applyId, err = o.Insert(item)
  34. if err != nil {
  35. return
  36. }
  37. return
  38. }
  39. type BusinessApplyReq struct {
  40. ArriveDate string `description:"到达日期"`
  41. ReturnDate string `description:"返程日期"`
  42. Province string `description:"目的地省"`
  43. City string `description:"目的地市"`
  44. Reason string `description:"出差事由"`
  45. Transportation string `description:"交通工具"`
  46. PeerPeopleId string `description:"同行人id"`
  47. PeerPeopleName string `description:"同行人"`
  48. }
  49. type BusinessApplyView struct {
  50. BusinessApplyId int `description:"出差申请id"`
  51. ApplyAdminId int `description:"申请人id"`
  52. ApplyRealName string `description:"申请人姓名"`
  53. ArriveDate string `description:"到达日期"`
  54. ReturnDate string `description:"返程日期"`
  55. Province string `description:"目的地省"`
  56. City string `description:"目的地市"`
  57. Reason string `description:"出差事由"`
  58. Transportation string `description:"交通工具"`
  59. PeerPeopleId string `description:"同行人id"`
  60. PeerPeopleName string `description:"同行人"`
  61. Status string `description:"状态:'待审批','已审批','已驳回','已撤回','已过期'"`
  62. ApproveId int `description:"审批人id"`
  63. ApproveName string `description:"审批人姓名"`
  64. RefuseReason string `description:"拒绝理由"`
  65. RefuseTime string `description:"拒绝时间"`
  66. ApproveTime string `description:"审批时间"`
  67. CreateTime string `description:"创建时间"`
  68. ModifyTime string `description:"修改时间"`
  69. IsApprove bool `description:"是否审批人,true:是,false:否"`
  70. CloseReason string `description:"关闭理由"`
  71. CloseTime string `description:"关闭时间"`
  72. IsClose bool `description:"true,可关闭,false,不可关闭"`
  73. }
  74. func GetBusinessApplyListCount(condition string, pars []interface{}) (count int, err error) {
  75. o := orm.NewOrm()
  76. sql := `SELECT COUNT(1) AS count FROM business_apply AS a WHERE 1=1 `
  77. if condition != "" {
  78. sql += condition
  79. }
  80. err = o.Raw(sql, pars).QueryRow(&count)
  81. return
  82. }
  83. func GetBusinessApplyList(condition string, pars []interface{}, startSize, pageSize int) (list []*BusinessApplyView, err error) {
  84. o := orm.NewOrm()
  85. sql := `SELECT * FROM business_apply AS a WHERE 1=1 `
  86. if condition != "" {
  87. sql += condition
  88. }
  89. sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
  90. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  91. return
  92. }
  93. type BusinessApplyListResp struct {
  94. Paging *paging.PagingItem
  95. List []*BusinessApplyView
  96. }
  97. type BusinessApplyDeleteReq struct {
  98. BusinessApplyId int `description:"出差申请id"`
  99. }
  100. func GetBusinessApplyById(businessApplyId int) (item *BusinessApplyView, err error) {
  101. o := orm.NewOrm()
  102. sql := `SELECT * FROM business_apply WHERE business_apply_id=? `
  103. err = o.Raw(sql, businessApplyId).QueryRow(&item)
  104. return
  105. }
  106. // 删除
  107. func DeleteBusinessApply(businessApplyId int) (err error) {
  108. o := orm.NewOrm()
  109. sql := ` DELETE FROM business_apply WHERE business_apply_id=? `
  110. _, err = o.Raw(sql, businessApplyId).Exec()
  111. if err != nil {
  112. return err
  113. }
  114. return err
  115. }
  116. type BusinessApplyBackReq struct {
  117. BusinessApplyId int `description:"出差申请id"`
  118. }
  119. // 更新
  120. func UpdateBusinessApply(where, updateParams map[string]interface{}) error {
  121. o := orm.NewOrm()
  122. ptrStructOrTableName := "business_apply"
  123. qs := o.QueryTable(ptrStructOrTableName)
  124. for expr, exprV := range where {
  125. qs = qs.Filter(expr, exprV)
  126. }
  127. _, err := qs.Update(updateParams)
  128. return err
  129. }
  130. type BusinessApplyEditReq struct {
  131. BusinessApplyId int `description:"出差申请id"`
  132. ArriveDate string `description:"到达日期"`
  133. ReturnDate string `description:"返程日期"`
  134. Province string `description:"目的地省"`
  135. City string `description:"目的地市"`
  136. Reason string `description:"出差事由"`
  137. Transportation string `description:"交通工具"`
  138. PeerPeopleId string `description:"同行人id"`
  139. PeerPeopleName string `description:"同行人"`
  140. }
  141. func CheckBusinessApplyDateCount(condition string, pars []interface{}) (count int, err error) {
  142. o := orm.NewOrm()
  143. sql := `SELECT COUNT(1) AS count FROM business_apply AS a
  144. WHERE 1=1 `
  145. if condition != "" {
  146. sql += condition
  147. }
  148. err = o.Raw(sql, pars).QueryRow(&count)
  149. return
  150. }
  151. func CheckBusinessApplyDate(startDateTime, endDateTime, status string, applyId, businessApplyId int) (calendarCount int, err error) {
  152. var condition string
  153. var pars []interface{}
  154. if businessApplyId > 0 {
  155. condition += " AND business_apply_id <> ? "
  156. pars = append(pars, businessApplyId)
  157. }
  158. condition += " AND apply_admin_id = ? "
  159. pars = append(pars, applyId)
  160. condition += " AND status IN (" + status + ") "
  161. condition += ` AND ((? >= arrive_date AND ? <= return_date) OR (? >= arrive_date AND ? <= return_date))`
  162. pars = append(pars, startDateTime)
  163. pars = append(pars, startDateTime)
  164. pars = append(pars, endDateTime)
  165. pars = append(pars, endDateTime)
  166. calendarCount, err = CheckBusinessApplyDateCount(condition, pars)
  167. return
  168. }
  169. func CheckBusinessApplyPeerDateCount(condition string, pars []interface{}) (count int, err error) {
  170. o := orm.NewOrm()
  171. sql := `SELECT COUNT(1) AS count FROM business_apply_peer AS a
  172. WHERE 1=1 `
  173. if condition != "" {
  174. sql += condition
  175. }
  176. err = o.Raw(sql, pars).QueryRow(&count)
  177. return
  178. }
  179. func CheckBusinessApplyPeerDate(startDateTime, endDateTime, status string, applyId, businessApplyId int) (calendarCount int, err error) {
  180. var condition string
  181. var pars []interface{}
  182. if businessApplyId > 0 {
  183. condition += " AND business_apply_id <> ? "
  184. pars = append(pars, businessApplyId)
  185. }
  186. condition += " AND peer_people_id = ? "
  187. pars = append(pars, applyId)
  188. condition += " AND status IN (" + status + ") "
  189. condition += ` AND ((? >= arrive_date AND ? <= return_date) OR (? >= arrive_date AND ? <= return_date))`
  190. pars = append(pars, startDateTime)
  191. pars = append(pars, startDateTime)
  192. pars = append(pars, endDateTime)
  193. pars = append(pars, endDateTime)
  194. calendarCount, err = CheckBusinessApplyPeerDateCount(condition, pars)
  195. return
  196. }
  197. type BusinessApplyCloseReq struct {
  198. BusinessApplyId int `description:"出差申请id"`
  199. CloseReason string `description:"关闭原因"`
  200. }
  201. // 更新
  202. func UpdateBusinessApplyPeer(where, updateParams map[string]interface{}) error {
  203. o := orm.NewOrm()
  204. ptrStructOrTableName := "business_apply_peer"
  205. qs := o.QueryTable(ptrStructOrTableName)
  206. for expr, exprV := range where {
  207. qs = qs.Filter(expr, exprV)
  208. }
  209. _, err := qs.Update(updateParams)
  210. return err
  211. }