business_apply.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. IsClose bool `description:"true,可关闭,false,不可关闭"`
  72. CloseReason string `description:"关闭理由"`
  73. Itinerary string `description:"行程说明"`
  74. }
  75. func GetBusinessApplyListCount(condition string, pars []interface{}) (count int, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT COUNT(1) AS count FROM business_apply AS a WHERE 1=1 `
  78. if condition != "" {
  79. sql += condition
  80. }
  81. err = o.Raw(sql, pars).QueryRow(&count)
  82. return
  83. }
  84. func GetBusinessApplyList(condition string, pars []interface{}, startSize, pageSize int) (list []*BusinessApplyView, err error) {
  85. o := orm.NewOrm()
  86. sql := `SELECT * FROM business_apply AS a WHERE 1=1 `
  87. if condition != "" {
  88. sql += condition
  89. }
  90. sql += ` ORDER BY a.create_time DESC LIMIT ?,? `
  91. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  92. return
  93. }
  94. type BusinessApplyListResp struct {
  95. Paging *paging.PagingItem
  96. List []*BusinessApplyView
  97. }
  98. type BusinessApplyDeleteReq struct {
  99. BusinessApplyId int `description:"出差申请id"`
  100. }
  101. func GetBusinessApplyById(businessApplyId int) (item *BusinessApplyView, err error) {
  102. o := orm.NewOrm()
  103. sql := `SELECT * FROM business_apply WHERE business_apply_id=? `
  104. err = o.Raw(sql, businessApplyId).QueryRow(&item)
  105. return
  106. }
  107. // 删除
  108. func DeleteBusinessApply(businessApplyId int) (err error) {
  109. o := orm.NewOrm()
  110. sql := ` DELETE FROM business_apply WHERE business_apply_id=? `
  111. _, err = o.Raw(sql, businessApplyId).Exec()
  112. if err != nil {
  113. return err
  114. }
  115. return err
  116. }
  117. type BusinessApplyBackReq struct {
  118. BusinessApplyId int `description:"出差申请id"`
  119. }
  120. // 更新
  121. func UpdateBusinessApply(where, updateParams map[string]interface{}) error {
  122. o := orm.NewOrm()
  123. ptrStructOrTableName := "business_apply"
  124. qs := o.QueryTable(ptrStructOrTableName)
  125. for expr, exprV := range where {
  126. qs = qs.Filter(expr, exprV)
  127. }
  128. _, err := qs.Update(updateParams)
  129. return err
  130. }
  131. // 更新
  132. func UpdateBusinessApplyPeer(where, updateParams map[string]interface{}) error {
  133. o := orm.NewOrm()
  134. ptrStructOrTableName := "business_apply_peer"
  135. qs := o.QueryTable(ptrStructOrTableName)
  136. for expr, exprV := range where {
  137. qs = qs.Filter(expr, exprV)
  138. }
  139. _, err := qs.Update(updateParams)
  140. return err
  141. }
  142. type BusinessApplyEditReq struct {
  143. BusinessApplyId int `description:"出差申请id"`
  144. ArriveDate string `description:"到达日期"`
  145. ReturnDate string `description:"返程日期"`
  146. Province string `description:"目的地省"`
  147. City string `description:"目的地市"`
  148. Reason string `description:"出差事由"`
  149. Transportation string `description:"交通工具"`
  150. PeerPeopleId string `description:"同行人id"`
  151. PeerPeopleName string `description:"同行人"`
  152. Itinerary string `description:"行程说明"`
  153. }
  154. func CheckBusinessApplyDateCount(condition string, pars []interface{}) (count int, err error) {
  155. o := orm.NewOrm()
  156. sql := `SELECT COUNT(1) AS count FROM business_apply AS a
  157. WHERE 1=1 `
  158. if condition != "" {
  159. sql += condition
  160. }
  161. err = o.Raw(sql, pars).QueryRow(&count)
  162. return
  163. }
  164. func CheckBusinessApplyDate(startDateTime, endDateTime, status string, applyId, businessApplyId int) (calendarCount int, err error) {
  165. var condition string
  166. var pars []interface{}
  167. if businessApplyId > 0 {
  168. condition += " AND business_apply_id <> ? "
  169. pars = append(pars, businessApplyId)
  170. }
  171. condition += " AND apply_admin_id = ? "
  172. pars = append(pars, applyId)
  173. condition += " AND status IN (" + status + ") "
  174. condition += ` AND ((? >= arrive_date AND ? <= return_date) OR (? >= arrive_date AND ? <= return_date))`
  175. pars = append(pars, startDateTime)
  176. pars = append(pars, startDateTime)
  177. pars = append(pars, endDateTime)
  178. pars = append(pars, endDateTime)
  179. calendarCount, err = CheckBusinessApplyDateCount(condition, pars)
  180. return
  181. }
  182. func CheckBusinessApplyPeerDateCount(condition string, pars []interface{}) (count int, err error) {
  183. o := orm.NewOrm()
  184. sql := `SELECT COUNT(1) AS count FROM business_apply_peer AS a
  185. WHERE 1=1 `
  186. if condition != "" {
  187. sql += condition
  188. }
  189. err = o.Raw(sql, pars).QueryRow(&count)
  190. return
  191. }
  192. func CheckBusinessApplyPeerDate(startDateTime, endDateTime, status string, applyId, businessApplyId int) (calendarCount int, err error) {
  193. var condition string
  194. var pars []interface{}
  195. if businessApplyId > 0 {
  196. condition += " AND business_apply_id <> ? "
  197. pars = append(pars, businessApplyId)
  198. }
  199. condition += " AND peer_people_id = ? "
  200. pars = append(pars, applyId)
  201. condition += " AND status IN (" + status + ") "
  202. condition += ` AND ((? >= arrive_date AND ? <= return_date) OR (? >= arrive_date AND ? <= return_date))`
  203. pars = append(pars, startDateTime)
  204. pars = append(pars, startDateTime)
  205. pars = append(pars, endDateTime)
  206. pars = append(pars, endDateTime)
  207. calendarCount, err = CheckBusinessApplyPeerDateCount(condition, pars)
  208. return
  209. }
  210. type BusinessApplyCloseReq struct {
  211. BusinessApplyId int `description:"出差申请id"`
  212. CloseReason string `description:"关闭原因"`
  213. }