PlanController.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. package com.ruoyi.demo.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.annotation.SaIgnore;
  4. import cn.dev33.satoken.stp.StpUtil;
  5. import com.ruoyi.common.core.domain.R;
  6. import com.ruoyi.common.core.domain.entity.SysUser;
  7. import com.ruoyi.common.core.validate.AddGroup;
  8. import com.ruoyi.demo.entity.bo.PlanAddBo;
  9. import com.ruoyi.demo.entity.bo.PlanBo;
  10. import com.ruoyi.demo.entity.bo.UpDownBo;
  11. import com.ruoyi.demo.service.PlanService;
  12. import com.ruoyi.system.service.ISysUserService;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.validation.annotation.Validated;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.validation.constraints.NotBlank;
  17. @RestController
  18. @RequestMapping("/plan")
  19. public class PlanController {
  20. @Autowired
  21. PlanService planService;
  22. @Autowired
  23. ISysUserService sysUserService;
  24. // 广告管理
  25. /**
  26. * 上下架广告计划
  27. * @param planId 计划id
  28. * @return
  29. */
  30. @SaCheckPermission("szzs:planManage:update")
  31. @PutMapping("/{planId}")
  32. public R planUpDown(@PathVariable String planId){
  33. int i = planService.planUpDown(planId);
  34. if (i == 1)
  35. return R.ok("成功");
  36. if (i == -1)
  37. return R.fail("计划不存在");
  38. return R.fail("失败");
  39. }
  40. /**
  41. * 查询广告计划列表
  42. * @param bo 请求体
  43. * @return
  44. */
  45. @SaCheckPermission("szzs:planManage:list")
  46. @PostMapping("/list")
  47. public R planList(@RequestBody PlanBo bo){
  48. if (bo.getStartTime() != null && bo.getEndTime() != null)
  49. if (bo.getStartTime().compareTo(bo.getEndTime()) > 0)
  50. return R.fail("起始时间不能大于结束时间");
  51. return R.ok(planService.getPlanList(bo));
  52. }
  53. /**
  54. * 查询广告计划明细
  55. * @param planId 计划id
  56. * @return
  57. */
  58. @SaCheckPermission("szzs:planManage:query")
  59. @GetMapping("/{planId}")
  60. public R planDetail(@PathVariable String planId){
  61. return R.ok(planService.getPlanDetail(planId));
  62. }
  63. /**
  64. * 投放广告计划
  65. * @param equipmentCode 设备编号
  66. * @return
  67. */
  68. @SaIgnore
  69. @GetMapping("/push/{equipmentCode}")
  70. public R planPush(@PathVariable String equipmentCode){
  71. return R.ok(planService.getPlanPushByCode(equipmentCode));
  72. }
  73. // 广告计划管理
  74. /**
  75. * 审核广告计划
  76. * @param bo 请求体
  77. * @return
  78. */
  79. @SaCheckPermission("szzs:planAudit:check")
  80. @PutMapping("/audit")
  81. public R checkPlan(@RequestBody PlanBo bo){
  82. // 获取用户id和用户名
  83. String loginId = String.valueOf(StpUtil.getLoginId());
  84. String numericPart = loginId.split(":")[1];
  85. Long userId = Long.valueOf(numericPart);
  86. SysUser sysUser = sysUserService.selectUserById(userId);
  87. int i = planService.checkPlan(bo,userId,sysUser.getNickName());
  88. if (i == 1)
  89. return R.ok("审核操作成功");
  90. if (i == -1)
  91. return R.fail("该计划不存在");
  92. if (i == -2)
  93. return R.fail("回调地址错误或失效");
  94. return R.fail("审核操作失败");
  95. }
  96. /**
  97. * 查询广告计划管理列表
  98. * @param bo 请求体
  99. * @return
  100. */
  101. @SaCheckPermission("szzs:planAudit:list")
  102. @PostMapping("/audit/list")
  103. public R auditList(@RequestBody PlanBo bo){
  104. if (bo.getStartTime() != null && bo.getEndTime() != null)
  105. if (bo.getStartTime().compareTo(bo.getEndTime()) > 0)
  106. return R.fail("起始时间不能大于结束时间");
  107. return R.ok(planService.getPlanManageList(bo));
  108. }
  109. /**
  110. * 查询广告计划管理明细
  111. * @param planId 广告计划id
  112. * @return
  113. */
  114. @SaCheckPermission("szzs:planAudit:query")
  115. @GetMapping("/audit/{planId}")
  116. public R auditDetail(@PathVariable String planId){
  117. return R.ok(planService.getPlanManageDetail(planId));
  118. }
  119. // 广告推送
  120. /**
  121. * 获取sign——用于测试
  122. * @param bo 请求体
  123. * @return
  124. */
  125. // @SaCheckPermission("szzs:plan:test")
  126. @SaIgnore
  127. @PostMapping("/getSign")
  128. public R getSign(@RequestBody PlanAddBo bo){
  129. if (bo.getPlanStartTime() != null && bo.getPlanEndTime() != null)
  130. if (bo.getPlanStartTime().compareTo(bo.getPlanEndTime()) > 0)
  131. return R.fail("起始时间不能大于结束时间");
  132. String sign = planService.getSign(bo);
  133. if (sign.equals("error"))
  134. return R.fail("无效的appkey");
  135. return R.ok(sign);
  136. }
  137. /**
  138. * 添加广告推送计划
  139. * @param bo 广告id
  140. * @return
  141. */
  142. @SaIgnore
  143. @PostMapping()
  144. public R addPlan(@RequestBody @Validated(value = {AddGroup.class}) PlanAddBo bo){
  145. if (bo.getPlanStartTime() != null && bo.getPlanEndTime() != null)
  146. if (bo.getPlanStartTime().compareTo(bo.getPlanEndTime()) > 0)
  147. return R.fail("起始时间不能大于结束时间");
  148. String i = planService.addPlan(bo);
  149. if ("0".equals(i))
  150. return R.fail("添加失败");
  151. if ("-1".equals(i))
  152. return R.fail("无效的appkey");
  153. if ("-3".equals(i))
  154. return R.fail("校验sign出错");
  155. return R.ok(i);
  156. }
  157. /**
  158. * 删除广告推送计划
  159. * @param planId 广告id
  160. * @return
  161. */
  162. // @SaCheckPermission("szzs:plan:delete")
  163. @SaIgnore
  164. @DeleteMapping("/{planId}")
  165. public R deletePlan(@PathVariable String planId){
  166. int i = planService.deletePlan(planId);
  167. if (i == -1)
  168. return R.fail("删除失败");
  169. return R.ok("删除成功");
  170. }
  171. /**
  172. * 查询广告计划推送计划列表
  173. * @param bo 请求体
  174. * @return
  175. */
  176. // @SaCheckPermission("szzs:plan:list")
  177. @SaIgnore
  178. @PostMapping("/push/list")
  179. public R pushList(@RequestBody PlanBo bo){
  180. if (bo.getStartTime() != null && bo.getEndTime() != null)
  181. if (bo.getStartTime().compareTo(bo.getEndTime()) > 0)
  182. return R.fail("起始时间不能大于结束时间");
  183. return R.ok(planService.getPlanPushList(bo));
  184. }
  185. /**
  186. * 上下架广告
  187. *
  188. * @param bo
  189. * @return
  190. */
  191. @SaIgnore
  192. @PostMapping("/push")
  193. public R planPushUpDown(@RequestBody UpDownBo bo){
  194. int i = planService.planPushUpDown(bo);
  195. if (i == 1)
  196. return R.ok("上架/下架成功");
  197. if (i == -1)
  198. return R.fail("无效的appkey");
  199. if (i == -3)
  200. return R.fail("校验sign出错");
  201. return R.fail("上架/下架失败");
  202. }
  203. /**
  204. * 上下架广告——获取sign——用于测试
  205. *
  206. * @param bo
  207. * @return
  208. */
  209. @SaIgnore
  210. @PostMapping("/push/getSign")
  211. public R UpDownGetSign(@RequestBody UpDownBo bo){
  212. String sign = planService.pushGetSign(bo);
  213. if ("error".equals(sign))
  214. return R.fail("无效的appkey");
  215. return R.ok(sign);
  216. }
  217. // 广告投放
  218. /**
  219. * 广告投放列表
  220. * @param bo 请求体
  221. * @return
  222. */
  223. @SaCheckPermission("szzs:planStatistics:list")
  224. @PostMapping("/statistics/list")
  225. public R statisticsList(@RequestBody PlanBo bo){
  226. if (bo.getStartTime() != null && bo.getEndTime() != null)
  227. if (bo.getStartTime().compareTo(bo.getEndTime()) > 0)
  228. return R.fail("起始时间不能大于结束时间");
  229. return R.ok(planService.getPlanPushStatisticsList(bo));
  230. }
  231. /**
  232. * 立刻进行一次统计——用于测试
  233. * @return
  234. */
  235. @GetMapping("/statistics/start")
  236. public R statisticsStart(){
  237. planService.planPushStatisticsStart();
  238. return R.ok("更新完成");
  239. }
  240. // 首页
  241. /**
  242. * 获取总广告数
  243. * @return
  244. */
  245. @GetMapping("/total")
  246. public R total(){
  247. return R.ok(planService.getPlanTotal());
  248. }
  249. // 其他
  250. /**
  251. * 获取设备信息
  252. * @param bo 请求体
  253. * @return
  254. */
  255. @SaIgnore
  256. @PostMapping("/getEquipments")
  257. public R getEquipments(@RequestBody PlanBo bo){
  258. return R.ok(planService.getEquipments(bo));
  259. }
  260. /**
  261. * 下拉框——获取省市区地区码
  262. * @param code 地区码
  263. * @param level 城市等级
  264. * @return
  265. */
  266. @SaIgnore
  267. @GetMapping("/getAddrCategory")
  268. public R getAddrCategory(String code,String level){
  269. return R.ok(planService.getAddrCategoryLevel(code,level));
  270. }
  271. }