product_interior.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. type CygxProductInterior struct {
  10. ProductInteriorId int `orm:"column(product_interior_id);pk"`
  11. ColumnName string `description:"栏目名称"`
  12. Title string `description:"标题"`
  13. PublishTime time.Time `description:"发布日期"`
  14. CreateTime time.Time `description:"创建时间"`
  15. ModifyTime time.Time `description:"更新时间"`
  16. Status int `description:"0:未发布,1:已发布"`
  17. Body string `description:"内容"`
  18. IsCancel int `description:"是否取消,1是,0否"`
  19. VisibleRange int `description:"设置可见范围1全部,0内部"`
  20. Abstract string `description:"摘要"`
  21. Department string `description:"作者"`
  22. AdminId int `description:"管理员ID"`
  23. MatchTypeId int `description:"匹配类型ID"`
  24. ChartPermissionId int `description:"行业ID"`
  25. ChartPermissionName string `description:"行业ID"`
  26. IsSendWxMsg int `description:"是否推送过微信模板消息,1是,0:否"`
  27. }
  28. type AddProductInteriorReq struct {
  29. ProductInteriorId int `description:"ID"`
  30. DoType int `description:"操作类型 0,保存 、1,发布"`
  31. ColumnName string `description:"栏目名称"`
  32. Title string `description:"标题"`
  33. Abstract string `description:"摘要"`
  34. Department string `description:"作者"`
  35. Body string `description:"内容"`
  36. PublishTime string `description:"发布日期"`
  37. IndustrialManagementIds string `description:"产业id 多个用 , 隔开"`
  38. IndustrialSubjectIds string `description:"标的id 多个用 , 隔开"`
  39. MatchTypeId int `description:"匹配类型ID"`
  40. ChartPermissionId int `description:"行业ID"`
  41. }
  42. type ProductInteriorIdReq struct {
  43. ProductInteriorId int `description:"ID"`
  44. }
  45. // 添加
  46. func AddProductInterior(item *CygxProductInterior, industrialManagementIds, industrialSubjectIds string) (err error) {
  47. o := orm.NewOrmUsingDB("hz_cygx")
  48. to, err := o.Begin()
  49. if err != nil {
  50. return
  51. }
  52. defer func() {
  53. if err != nil {
  54. _ = to.Rollback()
  55. } else {
  56. _ = to.Commit()
  57. }
  58. }()
  59. newId, err := to.Insert(item)
  60. if err != nil {
  61. return
  62. }
  63. //添加产业与文章的关联
  64. //new(cygx.CygxProductInteriorIndustrialGroupManagement),
  65. // new(cygx.CygxProductInteriorIndustrialGroupSubject),
  66. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  67. for _, v := range industrialManagementIdList {
  68. itemIndustrialManagementGroup := new(CygxProductInteriorIndustrialGroupManagement)
  69. newIndustrialId, _ := strconv.Atoi(v)
  70. itemIndustrialManagementGroup.CreateTime = time.Now()
  71. itemIndustrialManagementGroup.ProductInteriorId = int(newId)
  72. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  73. _, err = to.Insert(itemIndustrialManagementGroup)
  74. if err != nil {
  75. return
  76. }
  77. }
  78. //添加标的与文章的关联
  79. if industrialSubjectIds != "" {
  80. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  81. for _, v := range industrialSubjectIdList {
  82. itemIndustrialSubjectGroup := new(CygxProductInteriorIndustrialGroupSubject)
  83. industrialSubjectId, _ := strconv.Atoi(v)
  84. itemIndustrialSubjectGroup.ProductInteriorId = int(newId)
  85. itemIndustrialSubjectGroup.IndustrialSubjectId = industrialSubjectId
  86. itemIndustrialSubjectGroup.CreateTime = time.Now()
  87. _, err = to.Insert(itemIndustrialSubjectGroup)
  88. if err != nil {
  89. return
  90. }
  91. }
  92. }
  93. return
  94. }
  95. // 修改
  96. func UpdateProductInterior(item *CygxProductInterior, industrialManagementIds, industrialSubjectIds string) (err error) {
  97. o := orm.NewOrmUsingDB("hz_cygx")
  98. to, err := o.Begin()
  99. if err != nil {
  100. return
  101. }
  102. defer func() {
  103. if err != nil {
  104. _ = to.Rollback()
  105. } else {
  106. _ = to.Commit()
  107. }
  108. }()
  109. updateParams := make(map[string]interface{})
  110. updateParams["PublishTime"] = item.PublishTime
  111. updateParams["ModifyTime"] = item.ModifyTime
  112. updateParams["ColumnName"] = item.ColumnName
  113. updateParams["Title"] = item.Title
  114. updateParams["Status"] = item.Status
  115. updateParams["Body"] = item.Body
  116. updateParams["IsCancel"] = item.IsCancel
  117. updateParams["VisibleRange"] = item.VisibleRange
  118. updateParams["Abstract"] = item.Abstract
  119. updateParams["Department"] = item.Department
  120. updateParams["MatchTypeId"] = item.MatchTypeId
  121. updateParams["ChartPermissionId"] = item.ChartPermissionId
  122. updateParams["ChartPermissionName"] = item.ChartPermissionName
  123. ptrStructOrTableName := "cygx_product_interior"
  124. whereParam := map[string]interface{}{"product_interior_id": item.ProductInteriorId}
  125. qs := to.QueryTable(ptrStructOrTableName)
  126. for expr, exprV := range whereParam {
  127. qs = qs.Filter(expr, exprV)
  128. }
  129. _, err = qs.Update(updateParams)
  130. if err != nil {
  131. return
  132. }
  133. //删除文章关联行业 (避免截断表时产生的脏数据,故不用update而是先删除再增加)
  134. sql := ` DELETE FROM cygx_product_interior_industrial_group_management WHERE product_interior_id = ?`
  135. _, err = to.Raw(sql, item.ProductInteriorId).Exec()
  136. if err != nil {
  137. return
  138. }
  139. //删除文章关联标的
  140. sql = ` DELETE FROM cygx_product_interior_industrial_group_subject WHERE product_interior_id = ?`
  141. _, err = to.Raw(sql, item.ProductInteriorId).Exec()
  142. if err != nil {
  143. return
  144. }
  145. industrialManagementIdList := strings.Split(industrialManagementIds, ",")
  146. for _, v := range industrialManagementIdList {
  147. itemIndustrialManagementGroup := new(CygxProductInteriorIndustrialGroupManagement)
  148. newIndustrialId, _ := strconv.Atoi(v)
  149. itemIndustrialManagementGroup.CreateTime = time.Now()
  150. itemIndustrialManagementGroup.ProductInteriorId = item.ProductInteriorId
  151. itemIndustrialManagementGroup.IndustrialManagementId = newIndustrialId
  152. _, err = to.Insert(itemIndustrialManagementGroup)
  153. if err != nil {
  154. return
  155. }
  156. }
  157. //添加标的与文章的关联
  158. if industrialSubjectIds != "" {
  159. industrialSubjectIdList := strings.Split(industrialSubjectIds, ",")
  160. for _, v := range industrialSubjectIdList {
  161. itemIndustrialSubjectGroup := new(CygxProductInteriorIndustrialGroupSubject)
  162. industrialSubjectId, _ := strconv.Atoi(v)
  163. itemIndustrialSubjectGroup.ProductInteriorId = item.ProductInteriorId
  164. itemIndustrialSubjectGroup.IndustrialSubjectId = industrialSubjectId
  165. itemIndustrialSubjectGroup.CreateTime = time.Now()
  166. _, err = to.Insert(itemIndustrialSubjectGroup)
  167. if err != nil {
  168. return
  169. }
  170. }
  171. }
  172. return
  173. }
  174. type GetCygxProductInteriorResp struct {
  175. Paging *paging.PagingItem `description:"分页数据"`
  176. List []*CygxProductInteriorResp
  177. }
  178. type CygxProductInteriorResp struct {
  179. ProductInteriorId int `description:"ID"`
  180. PublishTime string `description:"发布日期"`
  181. CreateTime string `description:"创建时间"`
  182. ModifyTime string `description:"更新时间"`
  183. Status int `description:"0:未发布,1:已发布,3:已下线"`
  184. Title string `description:"标题"`
  185. ColumnName string `description:"栏目名称"`
  186. Body string `description:"内容"`
  187. IsCancel int `description:"是否取消,1是,0否"`
  188. VisibleRange int `description:"设置可见范围1全部,0内部"`
  189. Abstract string `description:"摘要"`
  190. Department string `description:"作者"`
  191. Pv int `description:"PV"`
  192. Uv int `description:"Uv"`
  193. CommentNum int `description:"留言总数"`
  194. MatchTypeId int `description:"匹配类型ID"`
  195. MatchTypeName string `description:"匹配类型名称"`
  196. ChartPermissionId int `description:"行业ID"`
  197. ChartPermissionName string `description:"行业名称"`
  198. Label string `description:"标签"`
  199. IsSendWxMsg int `description:"是否推送过微信模板消息,1是,0:否"`
  200. ListIndustrial []*IndustrialActivityGroupManagementRep
  201. ListSubject []*SubjectActivityGroupManagementRep
  202. }
  203. // 获取数量
  204. func GetCygxProductInteriorCount(condition string, pars []interface{}) (count int, err error) {
  205. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_product_interior as art WHERE 1= 1 `
  206. if condition != "" {
  207. sqlCount += condition
  208. }
  209. o := orm.NewOrmUsingDB("hz_cygx")
  210. err = o.Raw(sqlCount, pars).QueryRow(&count)
  211. return
  212. }
  213. // 列表
  214. func GetCygxProductInteriorList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxProductInteriorResp, err error) {
  215. o := orm.NewOrmUsingDB("hz_cygx")
  216. sql := `SELECT * FROM cygx_product_interior as art WHERE 1= 1 `
  217. if condition != "" {
  218. sql += condition
  219. }
  220. sql += ` LIMIT ?,? `
  221. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  222. return
  223. }
  224. type GetCygxProductInteriorDetailResp struct {
  225. Detail *CygxProductInteriorResp
  226. }
  227. // 通过ID获取详情
  228. func GetCygxProductInteriorDetail(productInteriorId int) (item *CygxProductInteriorResp, err error) {
  229. o := orm.NewOrmUsingDB("hz_cygx")
  230. sql := `SELECT * FROM cygx_product_interior WHERE product_interior_id=? `
  231. err = o.Raw(sql, productInteriorId).QueryRow(&item)
  232. return
  233. }
  234. // 删除数据
  235. func DeleteProductInterior(productInteriorId int) (err error) {
  236. o := orm.NewOrmUsingDB("hz_cygx")
  237. sql := ` DELETE FROM cygx_product_interior WHERE product_interior_id = ?`
  238. _, err = o.Raw(sql, productInteriorId).Exec()
  239. return
  240. }
  241. // 修改是否展示
  242. func EditProductInteriorStatus(status, isCancel, productInteriorId int) (err error) {
  243. o := orm.NewOrmUsingDB("hz_cygx")
  244. sql := `UPDATE cygx_product_interior SET status=?,is_cancel = ? ,visible_range=0, modify_time=NOW() WHERE product_interior_id=? `
  245. _, err = o.Raw(sql, status, isCancel, productInteriorId).Exec()
  246. return
  247. }
  248. // 修改可见范围
  249. func ProductInteriorVisibleRange(visibleRange, productInteriorId int) (err error) {
  250. o := orm.NewOrmUsingDB("hz_cygx")
  251. sql := `UPDATE cygx_product_interior SET visible_range=?, modify_time=NOW() WHERE product_interior_id=? `
  252. _, err = o.Raw(sql, visibleRange, productInteriorId).Exec()
  253. return
  254. }
  255. // 修改是否推送过模板消息的状态
  256. func UpdateProductInteriorIsSendWxMsg(productInteriorId, isSendWxMsg int) (err error) {
  257. o := orm.NewOrmUsingDB("hz_cygx")
  258. sql := `UPDATE cygx_product_interior SET is_send_wx_msg=? WHERE product_interior_id =?`
  259. _, err = o.Raw(sql, isSendWxMsg, productInteriorId).Exec()
  260. return
  261. }