PoTetherController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.common.utils.DateUtils;
  7. import com.ruoyi.system.domain.PoCollection;
  8. import com.ruoyi.system.domain.PoTetherandcollection;
  9. import com.ruoyi.system.domain.PoUser;
  10. import com.ruoyi.system.domain.vo.TetherVo;
  11. import com.ruoyi.system.service.IPoUserService;
  12. import io.swagger.annotations.ApiOperation;
  13. import org.springframework.data.repository.query.Param;
  14. import org.springframework.security.access.prepost.PreAuthorize;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.validation.annotation.Validated;
  17. import org.springframework.web.bind.annotation.*;
  18. import com.ruoyi.common.annotation.Log;
  19. import com.ruoyi.common.core.controller.BaseController;
  20. import com.ruoyi.common.core.domain.AjaxResult;
  21. import com.ruoyi.common.enums.BusinessType;
  22. import com.ruoyi.system.domain.PoTether;
  23. import com.ruoyi.system.service.IPoTetherService;
  24. import com.ruoyi.common.utils.poi.ExcelUtil;
  25. import com.ruoyi.common.core.page.TableDataInfo;
  26. /**
  27. * 套系Controller
  28. *
  29. * @author ruoyi
  30. * @date 2023-02-12
  31. */
  32. @RestController
  33. @RequestMapping("/system/tether")
  34. public class PoTetherController extends BaseController
  35. {
  36. @Autowired
  37. private IPoTetherService poTetherService;
  38. @Autowired
  39. private IPoUserService poUserService;
  40. /**
  41. * 标题和时间搜索消息列表
  42. */
  43. @ApiOperation("标题和时间搜索消息列表")
  44. @Log(title = "标题和时间搜索")
  45. @PreAuthorize("@ss.hasPermi('system:tether:queryTether')")
  46. @GetMapping("/queryTether")
  47. public TableDataInfo list(@RequestParam(value="tetherName",required = false)String tetherName,
  48. @RequestParam(value="tetherTimeStart",required = false) Date tetherTimeStart,
  49. @RequestParam(value="tetherTimeEnd",required = false) Date tetherTimeEnd)
  50. {
  51. startPage();
  52. List<PoTether> list= poTetherService.selectListByTitleAndTime(tetherName,tetherTimeStart,tetherTimeEnd);
  53. return getDataTable(list);
  54. }
  55. /**
  56. * 查询套系列表 数量
  57. */
  58. @PreAuthorize("@ss.hasPermi('system:tether:list')")
  59. @GetMapping("/list")
  60. @ApiOperation("查询套系列表 在售")
  61. public TableDataInfo Total(PoTether poTether)
  62. {
  63. startPage();
  64. List<PoTether> sellingList = poTetherService.selectPoTetherCollectionList(poTether);
  65. return getDataTable(sellingList);
  66. }
  67. /**
  68. * 查询套系列表 在售
  69. */
  70. @PreAuthorize("@ss.hasPermi('system:tether:sellingList')")
  71. @GetMapping("/sellingList")
  72. @ApiOperation("查询套系列表 在售")
  73. public TableDataInfo sellingList(PoTether poTether)
  74. {
  75. startPage();
  76. List<PoTether> sellingList = poTetherService.selectPoTetherSellingList(poTether);
  77. return getDataTable(sellingList);
  78. }
  79. /**
  80. * 查询套系列表 预售
  81. */
  82. @ApiOperation("查询套系列表 预售")
  83. @PreAuthorize("@ss.hasPermi('system:tether:advanceList')")
  84. @GetMapping("/advanceList")
  85. public TableDataInfo advanceList(PoTether poTether)
  86. {
  87. startPage();
  88. List<PoTether> advanceList = poTetherService.selectPoTetherAdvanceList(poTether);
  89. return getDataTable(advanceList);
  90. }
  91. /**
  92. * 查询套系列表 已过期
  93. */
  94. @ApiOperation("查询套系列表 已过期")
  95. @PreAuthorize("@ss.hasPermi('system:tether:selledList')")
  96. @GetMapping("/selledList")
  97. public TableDataInfo selledList(PoTether poTether)
  98. {
  99. startPage();
  100. List<PoTether> selledList = poTetherService.selectPoTetherSelledList(poTether);
  101. return getDataTable(selledList);
  102. }
  103. /**
  104. * 导出套系列表
  105. */
  106. @ApiOperation("导出套系列表")
  107. @PreAuthorize("@ss.hasPermi('system:tether:export')")
  108. @Log(title = "套系", businessType = BusinessType.EXPORT)
  109. @PostMapping("/export")
  110. public void export(HttpServletResponse response, PoTether poTether)
  111. {
  112. List<PoTether> list = poTetherService.selectPoTetherList(poTether);
  113. ExcelUtil<PoTether> util = new ExcelUtil<PoTether>(PoTether.class);
  114. util.exportExcel(response, list, "套系数据");
  115. }
  116. /**
  117. * 藏品列表
  118. */
  119. @ApiOperation("藏品列表")
  120. @PreAuthorize("@ss.hasPermi('system:tether:collectionList')")
  121. @GetMapping("/collectionList/{tetherId}")
  122. public TableDataInfo collectionList( @PathVariable("tetherId") Long tetherId){
  123. startPage();
  124. List<PoTetherandcollection> collectionList = poTetherService.selectPoCollectionListById(tetherId);
  125. return getDataTable(collectionList);
  126. }
  127. /**
  128. * 新增套系
  129. */
  130. @ApiOperation("新增套系")
  131. @PreAuthorize("@ss.hasPermi('system:tether:add')")
  132. @Log(title = "套系", businessType = BusinessType.INSERT)
  133. @PostMapping("/add")
  134. public AjaxResult add(@RequestBody TetherVo tetherVo,
  135. @RequestBody @Param("poUser") PoUser poUser,
  136. @RequestBody PoTetherandcollection poTetherandcollection)
  137. {
  138. //判断当前用户是否有操作的权限
  139. poUserService.checkUserAllowed(poUser);
  140. if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){
  141. return AjaxResult.error("新增失败"+tetherVo.getTetherName()+"已经存在");
  142. }
  143. if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){
  144. return AjaxResult.error("新增失败"+tetherVo.getImage()+"已经存在");
  145. }
  146. tetherVo.setCreateBy(getUsername());
  147. tetherVo.setCreateTime(new Date());
  148. Date nowTime = new Date();
  149. nowTime = DateUtils.getNowDate();
  150. if (nowTime.after(tetherVo.getShowTimeEnd())){
  151. tetherVo.setSellStatus(2);
  152. }
  153. else if (nowTime.before(tetherVo.getShowTimeStart())){
  154. tetherVo.setSellStatus(1);
  155. }else{
  156. tetherVo.setSellStatus(0);
  157. }
  158. poTetherService.insertPoTetherWithCollection(tetherVo,poTetherandcollection);
  159. return success("新增成功");
  160. }
  161. /**
  162. * 通过id获取套系详细信息
  163. */
  164. @ApiOperation("通过id获取套系详细信息")
  165. @PreAuthorize("@ss.hasPermi('system:tether:query')")
  166. @GetMapping(value = "/{tetherId}")
  167. public AjaxResult getInfo(@PathVariable("tetherId") Long tetherId)
  168. {
  169. TetherVo byIdWithCollection = poTetherService.selectPoTetherByTetherIdWithCollection(tetherId);
  170. return success(byIdWithCollection);
  171. }
  172. /**
  173. * 修改套系
  174. */
  175. @ApiOperation("修改套系")
  176. @PreAuthorize("@ss.hasPermi('system:tether:edit')")
  177. @Log(title = "套系", businessType = BusinessType.UPDATE)
  178. @PutMapping("edit")
  179. public AjaxResult edit(@RequestBody TetherVo tetherVo,@RequestBody PoUser poUser)
  180. {
  181. //校验是否有操作的权限
  182. poUserService.checkUserAllowed(poUser);
  183. TetherVo tetherVo1 = poTetherService.selectPoTetherByTetherIdWithCollection(tetherVo.getTetherId());
  184. if (tetherVo1 == null){
  185. return error("没有对应的数据");
  186. }
  187. if (tetherVo1.getCochain() == 0){
  188. return error("已经上链");
  189. }
  190. if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){
  191. return AjaxResult.error("修改失败"+tetherVo.getTetherName()+"已经存在");
  192. }
  193. if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){
  194. return AjaxResult.error("修改失败"+tetherVo.getImage()+"已经存在");
  195. }
  196. tetherVo.setUpdateBy(getUsername());
  197. tetherVo.setUpdateTime(new Date());
  198. poTetherService.updatePoTetherWithCollection(tetherVo);
  199. return success("修改成功");
  200. }
  201. /**
  202. * 删除套系
  203. */
  204. @ApiOperation("删除套系")
  205. @PreAuthorize("@ss.hasPermi('system:tether:remove')")
  206. @Log(title = "套系", businessType = BusinessType.DELETE)
  207. @DeleteMapping("/remove/{tetherIds}")
  208. public AjaxResult remove(@PathVariable Long[] tetherIds) throws Exception {
  209. if (!getUsername().equals("admin")){
  210. return AjaxResult.error("删除消息失败当前用户不是管理员");
  211. }
  212. poTetherService.deletePoTetherByTetherIdsWithCollection(tetherIds);
  213. return success("删除成功");
  214. }
  215. /**
  216. * 修改状态 是否上链
  217. */
  218. @ApiOperation("修改状态 是否上链")
  219. @PreAuthorize("@ss.hasPermi('system:tether:isCochain')")
  220. @PostMapping("/isCochain/{cochain}/{tetherId}")
  221. public AjaxResult isCochain( @PathVariable("cochain") Integer cochain , @PathVariable("tetherId") Long tetherId){
  222. if (!getUsername().equals("admin")){
  223. return AjaxResult.error("不是管理员不可以修改上下链状态");
  224. }
  225. TetherVo tetherVo = poTetherService.selectPoTetherByTetherIdWithCollection(tetherId);
  226. if (tetherVo.getCochain() == 0){
  227. return error("禁止重复上链");
  228. }
  229. return toAjax(poTetherService.updatePoTetherIsCochain(cochain,tetherId));
  230. }
  231. /**
  232. * 修改状态 是否上架
  233. */
  234. @ApiOperation("修改状态 是否上架")
  235. @PreAuthorize("@ss.hasPermi('system:tether:isGrounding')")
  236. @PostMapping("/isGrounding/{grounding}/{tetherId}")
  237. public AjaxResult isGrounding( @PathVariable("grounding") Integer grounding , @PathVariable("tetherId") Long tetherId){
  238. if (!getUsername().equals("admin")){
  239. return AjaxResult.error("不是管理员不可以修改上下架状态");
  240. }
  241. TetherVo tetherVo = poTetherService.selectPoTetherByTetherIdWithCollection(tetherId);
  242. if (tetherVo.getCochain() == 0 ){
  243. return error("此套系为上链状态禁止上架");
  244. }
  245. if (tetherVo.getGrounding() == 0){
  246. return error("禁止重复上架");
  247. }
  248. return toAjax(poTetherService.updatePoTetherIsGrounding(grounding,tetherId));
  249. }
  250. }