business_apply.go 8.2 KB

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