PoTetherController.java 11 KB

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