business_apply.go 7.9 KB

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