business_apply.go 8.0 KB

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