PoTetherController.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package com.ruoyi.web.controller.system;
  2. import java.util.Date;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.ruoyi.common.constant.UserConstants;
  6. import com.ruoyi.system.domain.PoCollection;
  7. import com.ruoyi.system.domain.PoUser;
  8. import com.ruoyi.system.domain.vo.TetherVo;
  9. import com.ruoyi.system.service.IPoUserService;
  10. import io.swagger.annotations.ApiOperation;
  11. import org.springframework.data.repository.query.Param;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import com.ruoyi.common.annotation.Log;
  16. import com.ruoyi.common.core.controller.BaseController;
  17. import com.ruoyi.common.core.domain.AjaxResult;
  18. import com.ruoyi.common.enums.BusinessType;
  19. import com.ruoyi.system.domain.PoTether;
  20. import com.ruoyi.system.service.IPoTetherService;
  21. import com.ruoyi.common.utils.poi.ExcelUtil;
  22. import com.ruoyi.common.core.page.TableDataInfo;
  23. /**
  24. * 套系Controller
  25. *
  26. * @author ruoyi
  27. * @date 2023-02-12
  28. */
  29. @RestController
  30. @RequestMapping("/system/tether")
  31. public class PoTetherController extends BaseController
  32. {
  33. @Autowired
  34. private IPoTetherService poTetherService;
  35. @Autowired
  36. private IPoUserService poUserService;
  37. /**
  38. * 标题和时间搜索消息列表
  39. */
  40. @ApiOperation("标题和时间搜索消息列表")
  41. @Log(title = "标题和时间搜索")
  42. @PreAuthorize("@ss.hasPermi('system:tether:queryTether')")
  43. @GetMapping("/queryTether")
  44. public TableDataInfo list(@RequestParam(value="tetherName",required = false)String tetherName,
  45. @RequestParam(value="tetherTimeStart",required = false) Date tetherTimeStart,
  46. @RequestParam(value="tetherTimeEnd",required = false) Date tetherTimeEnd)
  47. {
  48. startPage();
  49. List<PoTether> list= poTetherService.selectListByTitleAndTime(tetherName,tetherTimeStart,tetherTimeEnd);
  50. return getDataTable(list);
  51. }
  52. /**
  53. * 查询套系列表 在售
  54. */
  55. @PreAuthorize("@ss.hasPermi('system:tether:sellingList')")
  56. @GetMapping("/sellingList")
  57. public TableDataInfo sellingList(PoTether poTether)
  58. {
  59. startPage();
  60. List<PoTether> sellingList = poTetherService.selectPoTetherSellingList(poTether);
  61. return getDataTable(sellingList);
  62. }
  63. /**
  64. * 查询套系列表 预售
  65. */
  66. @PreAuthorize("@ss.hasPermi('system:tether:advanceList')")
  67. @GetMapping("/advanceList")
  68. public TableDataInfo advanceList(PoTether poTether)
  69. {
  70. startPage();
  71. List<PoTether> advanceList = poTetherService.selectPoTetherAdvanceList(poTether);
  72. return getDataTable(advanceList);
  73. }
  74. /**
  75. * 查询套系列表 已过期
  76. */
  77. @PreAuthorize("@ss.hasPermi('system:tether:selledList')")
  78. @GetMapping("/selledList")
  79. public TableDataInfo selledList(PoTether poTether)
  80. {
  81. startPage();
  82. List<PoTether> selledList = poTetherService.selectPoTetherSelledList(poTether);
  83. return getDataTable(selledList);
  84. }
  85. /**
  86. * 导出套系列表
  87. */
  88. @PreAuthorize("@ss.hasPermi('system:tether:export')")
  89. @Log(title = "套系", businessType = BusinessType.EXPORT)
  90. @PostMapping("/export")
  91. public void export(HttpServletResponse response, PoTether poTether)
  92. {
  93. List<PoTether> list = poTetherService.selectPoTetherList(poTether);
  94. ExcelUtil<PoTether> util = new ExcelUtil<PoTether>(PoTether.class);
  95. util.exportExcel(response, list, "套系数据");
  96. }
  97. /**
  98. * 藏品列表
  99. */
  100. @PreAuthorize("@ss.hasPermi('system:tether:collectionList')")
  101. @GetMapping("/collectionList/{tetherId}")
  102. public TableDataInfo collectionList( @PathVariable("tetherId") Long tetherId){
  103. startPage();
  104. List<PoCollection> collectionList = poTetherService.selectPoCollectionListById(tetherId);
  105. return getDataTable(collectionList);
  106. }
  107. /**
  108. * 新增套系
  109. */
  110. @PreAuthorize("@ss.hasPermi('system:tether:add')")
  111. @Log(title = "套系", businessType = BusinessType.INSERT)
  112. @PostMapping("/add")
  113. public AjaxResult add(@RequestBody TetherVo tetherVo, @RequestBody @Param("poUser") PoUser poUser)
  114. {
  115. //判断当前用户是否有操作的权限
  116. poUserService.checkUserAllowed(poUser);
  117. if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){
  118. return AjaxResult.error("新增失败"+tetherVo.getTetherName()+"已经存在");
  119. }
  120. if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){
  121. return AjaxResult.error("新增失败"+tetherVo.getImage()+"已经存在");
  122. }
  123. tetherVo.setCreateBy(getUsername());
  124. tetherVo.setCreateTime(new Date());
  125. return toAjax(poTetherService.insertPoTetherWithCollection(tetherVo));
  126. }
  127. /**
  128. * 通过id获取套系详细信息
  129. */
  130. @PreAuthorize("@ss.hasPermi('system:tether:query')")
  131. @GetMapping(value = "/{tetherId}")
  132. public AjaxResult getInfo(@PathVariable("tetherId") Long tetherId)
  133. {
  134. TetherVo byIdWithCollection = poTetherService.selectPoTetherByTetherIdWithCollection(tetherId);
  135. return success(byIdWithCollection);
  136. }
  137. /**
  138. * 修改套系
  139. */
  140. @PreAuthorize("@ss.hasPermi('system:tether:edit')")
  141. @Log(title = "套系", businessType = BusinessType.UPDATE)
  142. @PutMapping("edit")
  143. public AjaxResult edit(@RequestBody TetherVo tetherVo,@RequestBody PoUser poUser)
  144. {
  145. //校验是否有操作的权限
  146. poUserService.checkUserAllowed(poUser);
  147. //校验是否可以访问到数据
  148. poUserService.checkUserDataScope(poUser.getUserId());
  149. if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){
  150. return AjaxResult.error("修改失败"+tetherVo.getTetherName()+"已经存在");
  151. }
  152. if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){
  153. return AjaxResult.error("修改失败"+tetherVo.getImage()+"已经存在");
  154. }
  155. //清理所有套系的缓存数
  156. //因为对于修改操作,用户是可以修改菜品的分类的,如果用户修改了菜品的分类,
  157. // 那么原来分类下将少一个菜品,新的分类下将多一个菜品,这样的话,两个分类下的菜品列表数据都发生了变化。
  158. tetherVo.setUpdateBy(getUsername());
  159. tetherVo.setUpdateTime(new Date());
  160. return toAjax(poTetherService.updatePoTetherWithCollection(tetherVo));
  161. }
  162. /**
  163. * 删除套系
  164. */
  165. @PreAuthorize("@ss.hasPermi('system:tether:remove')")
  166. @Log(title = "套系", businessType = BusinessType.DELETE)
  167. @DeleteMapping("/remove/{tetherIds}")
  168. public AjaxResult remove(@PathVariable Long[] tetherIds)
  169. {
  170. if (!getUsername().equals("admin")){
  171. return AjaxResult.error("删除消息失败当前用户不是管理员");
  172. }
  173. return toAjax(poTetherService.deletePoTetherByTetherIdsWithCollection(tetherIds));
  174. }
  175. }