english_company_todo.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // 英文客户Todo状态枚举值
  9. const (
  10. EnglishCompanyTodoStatusDoing = "进行中"
  11. EnglishCompanyTodoStatusCompleted = "已完成"
  12. EnglishCompanyTodoStatusVoided = "已作废"
  13. EnglishCompanyTodoStatusNull = "无任务"
  14. )
  15. // EnglishCompanyTodo 英文客户TODO任务
  16. type EnglishCompanyTodo struct {
  17. Id int `gorm:"column:id;primary_key:true" description:"任务ID"`
  18. CompanyId int `gorm:"column:company_id" description:"客户ID"`
  19. Content string `gorm:"column:content" description:"任务描述"`
  20. SellerId int `gorm:"column:seller_id" description:"客户所属销售ID"`
  21. SellerName string `gorm:"column:seller_name" description:"客户所属销售名称"`
  22. CreateUserId int `gorm:"column:create_user_id" description:"创建人用户ID"`
  23. CreateUserName string `gorm:"column:create_user_name" description:"创建人用户姓名"`
  24. ApproveUserId int `gorm:"column:approve_user_id" description:"审批人用户ID"`
  25. ApproveUserName string `gorm:"column:approve_user_name" description:"审批人用户姓名"`
  26. ApprovedSellerId int `gorm:"column:approved_seller_id" description:"审批时,客户所属销售ID"`
  27. ApprovedSellerName string `gorm:"column:approved_seller_name" description:"审批时,客户所属销售名称"`
  28. Status string `gorm:"column:status" description:"任务状态: 枚举值:进行中,已完成,已作废"`
  29. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  30. ApproveTime time.Time `gorm:"column:approve_time" description:"审核时间"`
  31. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  32. EndTime time.Time `gorm:"column:end_time" description:"截止时间"`
  33. IsDelete int `gorm:"column:is_delete" json:"-" description:"是否已经删除,0:未删除,1:已删除;默认:0"`
  34. Remark string `gorm:"column:remark" description:"审批备注"`
  35. }
  36. // EnglishCompanyTodoResp 英文客户TODO响应体
  37. type EnglishCompanyTodoResp struct {
  38. Id int `orm:"column(id);pk"`
  39. CompanyId int `description:"客户id"`
  40. Content string `description:"任务描述"`
  41. SellerId int `description:"客户所属销售id"`
  42. SellerName string `description:"客户所属销售名称"`
  43. CreateUserId int `description:"创建人用户id"`
  44. CreateUserName string `description:"创建人用户姓名"`
  45. ApproveUserId int `description:"审批人用户id"`
  46. ApproveUserName string `description:"审批人用户姓名"`
  47. Status string `description:"任务状态: 枚举值:进行中,已完成,已作废"`
  48. CreateTime string `description:"创建时间"`
  49. EndTime string `description:"截止时间"`
  50. ApproveTime string `description:"审核时间"`
  51. EndTimeStr string `description:"格式化后的截止时间"`
  52. Remark string `description:"审批备注"`
  53. }
  54. func (item *EnglishCompanyTodo) Create() (err error) {
  55. //o := orm.NewOrmUsingDB("rddp")
  56. //id, err := o.Insert(item)
  57. //if err != nil {
  58. // return
  59. //}
  60. //item.CompanyId = int(id)
  61. err = global.DmSQL["rddp"].Create(item).Error
  62. return
  63. }
  64. func (item *EnglishCompanyTodo) Update(cols []string) (err error) {
  65. //o := orm.NewOrmUsingDB("rddp")
  66. //_, err = o.Update(item, cols...)
  67. err = global.DmSQL["rddp"].Select(cols).Updates(item).Error
  68. return
  69. }
  70. // EnglishCompanyTodoAddReq 新增任务请求
  71. type EnglishCompanyTodoAddReq struct {
  72. CompanyId int `description:"客户id"`
  73. Description string `description:"任务描述"`
  74. EndTime string `description:"截止时间"`
  75. }
  76. // EnglishCompanyTodoEditReq 编辑任务请求
  77. type EnglishCompanyTodoEditReq struct {
  78. Id int `description:"客户任务记录id"`
  79. CompanyId int `description:"客户id"`
  80. Description string `description:"任务描述"`
  81. EndTime string `description:"截止时间"`
  82. }
  83. // EnglishCompanyTodoApproveReq 审批任务请求
  84. type EnglishCompanyTodoApproveReq struct {
  85. Id int `description:"客户任务记录id"`
  86. Remark string `description:"审批备注"`
  87. }
  88. // GetEnglishCompanyTodoById 根据任务ID获取客户任务
  89. func GetEnglishCompanyTodoById(id int) (item *EnglishCompanyTodo, err error) {
  90. //o := orm.NewOrmUsingDB("rddp")
  91. sql := `SELECT * FROM english_company_todo WHERE id = ? LIMIT 1 `
  92. //err = o.Raw(sql, id).QueryRow(&item)
  93. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  94. return
  95. }
  96. // GetCountDoingEnglishCompanyTodo 获取正在进行中的任务数量
  97. func GetCountDoingEnglishCompanyTodo(companyId int) (total int, err error) {
  98. //o := orm.NewOrmUsingDB("rddp")
  99. sql := `SELECT count(1) AS total FROM english_company_todo WHERE status = "进行中" AND company_id = ? AND is_delete = 0 `
  100. //err = o.Raw(sql, companyId).QueryRow(&total)
  101. err = global.DmSQL["rddp"].Raw(sql, companyId).Scan(&total).Error
  102. return
  103. }
  104. // GetEnglishCompanyTodoPageListResp 英文客户TODO-分页列表
  105. type GetEnglishCompanyTodoPageListResp struct {
  106. List []*EnglishCompanyTodoResp
  107. Paging *paging.PagingItem `description:"分页数据"`
  108. }
  109. // GetEnglishCompanyTodoList 获取客户任务列表
  110. func GetEnglishCompanyTodoList(companyId, startSize, pageSize int, order string) (total int, items []*EnglishCompanyTodo, err error) {
  111. //o := orm.NewOrmUsingDB("rddp")
  112. sql := `SELECT
  113. a.*
  114. FROM
  115. english_company_todo a
  116. JOIN english_company b ON a.company_id = b.company_id
  117. WHERE
  118. a.company_id = ? AND a.status != "已作废" AND a.is_delete = 0 `
  119. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  120. //if err = o.Raw(totalSQl, companyId).QueryRow(&total); err != nil {
  121. if err = global.DmSQL["rddp"].Raw(totalSQl, companyId).Scan(&total).Error; err != nil {
  122. return
  123. }
  124. if order != `` {
  125. sql += order
  126. } else {
  127. sql += ` ORDER BY a.create_time DESC`
  128. }
  129. sql += ` LIMIT ?,?`
  130. //_, err = o.Raw(sql, companyId, startSize, pageSize).QueryRows(&items)
  131. err = global.DmSQL["rddp"].Raw(sql, companyId, startSize, pageSize).Find(&items).Error
  132. return
  133. }
  134. // GetDoingEnglishCompanyTodoList 获取客户的进行中任务列表
  135. func GetDoingEnglishCompanyTodoList(companyId int) (items []*EnglishCompanyTodo, err error) {
  136. //o := orm.NewOrmUsingDB("rddp")
  137. sql := `SELECT
  138. a.*
  139. FROM
  140. english_company_todo a
  141. JOIN english_company b ON a.company_id = b.company_id
  142. WHERE
  143. a.company_id = ? AND a.status = "进行中" AND a.is_delete = 0
  144. ORDER BY
  145. a.create_time ASC`
  146. //_, err = o.Raw(sql, companyId).QueryRows(&items)
  147. err = global.DmSQL["rddp"].Raw(sql, companyId).Find(&items).Error
  148. return
  149. }
  150. // GetEnglishCompanyLatestTodoByCompanyIds 获取英文客户最新的一条TODO任务
  151. func GetEnglishCompanyLatestTodoByCompanyIds(companyIds []int) (items []*EnglishCompanyTodo, err error) {
  152. itemsLen := len(companyIds)
  153. if itemsLen == 0 {
  154. return
  155. }
  156. //o := orm.NewOrmUsingDB("rddp")
  157. sql := `SELECT b.* FROM
  158. (
  159. SELECT
  160. company_id,
  161. MAX(create_time) AS ct
  162. FROM
  163. english_company_todo
  164. WHERE
  165. is_delete = 0 AND status != "已作废" AND company_id IN (` + utils.GetOrmInReplace(itemsLen) + `)
  166. GROUP BY
  167. company_id
  168. ) AS a
  169. LEFT JOIN english_company_todo AS b ON b.company_id = a.company_id AND b.create_time = a.ct `
  170. //_, err = o.Raw(sql, companyIds).QueryRows(&items)
  171. err = global.DmSQL["rddp"].Raw(sql, companyIds).Find(&items).Error
  172. return
  173. }
  174. type EnglishCompanyTodoDoing struct {
  175. Id int `description:"待办ID"`
  176. CompanyId int `description:"客户id"`
  177. CompanyName string `description:"客户名称"`
  178. Content string `description:"任务描述"`
  179. SellerId int `description:"客户所属销售id"`
  180. SellerName string `description:"客户所属销售名称"`
  181. CreateUserId int `description:"创建人用户id"`
  182. CreateUserName string `description:"创建人用户姓名"`
  183. ApproveUserId int `description:"审批人用户id"`
  184. ApproveUserName string `description:"审批人用户姓名"`
  185. ApprovedSellerId int `description:"审批时,客户所属销售id"`
  186. ApprovedSellerName string `description:"审批时,客户所属销售名称"`
  187. Status string `description:"任务状态: 枚举值:进行中,已完成,已作废"`
  188. ModifyTime time.Time `description:"修改时间"`
  189. ApproveTime time.Time `description:"审核时间"`
  190. CreateTime time.Time `description:"创建时间"`
  191. EndTime time.Time `description:"截止时间"`
  192. Remark string `description:"审批备注"`
  193. }
  194. type EnglishCompanyTodoDoingResp struct {
  195. Id int `description:"待办ID"`
  196. CompanyId int `description:"客户id"`
  197. CompanyName string `description:"客户名称"`
  198. Content string `description:"任务描述"`
  199. SellerId int `description:"客户所属销售id"`
  200. SellerName string `description:"客户所属销售名称"`
  201. CreateUserId int `description:"创建人用户id"`
  202. CreateUserName string `description:"创建人用户姓名"`
  203. ApproveUserId int `description:"审批人用户id"`
  204. ApproveUserName string `description:"审批人用户姓名"`
  205. Status string `description:"任务状态: 枚举值:进行中,已完成,已作废"`
  206. CreateTime string `description:"创建时间"`
  207. EndTime string `description:"截止时间"`
  208. ApproveTime string `description:"审核时间"`
  209. Remark string `description:"审批备注"`
  210. }
  211. // GetEnglishCompanyTodoDoingPageListResp 英文客户未完成TODO-分页列表
  212. type GetEnglishCompanyTodoDoingPageListResp struct {
  213. List []*EnglishCompanyTodoDoingResp
  214. Paging *paging.PagingItem `description:"分页数据"`
  215. }
  216. // GetEnglishCompanyTodoDoingList 获取客户任务未完成列表
  217. func GetEnglishCompanyTodoDoingList(startSize, pageSize int, order string) (total int, items []*EnglishCompanyTodoDoing, err error) {
  218. //o := orm.NewOrmUsingDB("rddp")
  219. sql := `SELECT
  220. a.*,
  221. b.company_name
  222. FROM
  223. english_company_todo a
  224. JOIN english_company b ON a.company_id = b.company_id
  225. WHERE
  226. a.status = "进行中" AND a.is_delete = 0 `
  227. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  228. //if err = o.Raw(totalSQl).QueryRow(&total); err != nil {
  229. if err = global.DmSQL["rddp"].Raw(totalSQl).Scan(&total).Error; err != nil {
  230. return
  231. }
  232. if order != `` {
  233. sql += order
  234. } else {
  235. sql += ` ORDER BY a.end_time ASC`
  236. }
  237. sql += ` LIMIT ?,?`
  238. //_, err = o.Raw(sql, startSize, pageSize).QueryRows(&items)
  239. err = global.DmSQL["rddp"].Raw(sql, startSize, pageSize).Find(&items).Error
  240. return
  241. }
  242. // DeleteEnglishCompanyTodoByCompanyId (软)删除英文客户TODO
  243. func DeleteEnglishCompanyTodoByCompanyId(companyId int) (err error) {
  244. //o := orm.NewOrmUsingDB("rddp")
  245. sql := `UPDATE english_company_todo SET is_delete = 1 WHERE company_id = ?`
  246. //_, err = o.Raw(sql, companyId).Exec()
  247. err = global.DmSQL["rddp"].Exec(sql, companyId).Error
  248. return
  249. }