package com.ruoyi.web.controller.system; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.system.domain.PoCollection; import com.ruoyi.system.domain.PoUser; import com.ruoyi.system.domain.vo.TetherVo; import com.ruoyi.system.service.IPoUserService; import io.swagger.annotations.ApiOperation; import org.springframework.data.repository.query.Param; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.system.domain.PoTether; import com.ruoyi.system.service.IPoTetherService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; /** * 套系Controller * * @author ruoyi * @date 2023-02-12 */ @RestController @RequestMapping("/system/tether") public class PoTetherController extends BaseController { @Autowired private IPoTetherService poTetherService; @Autowired private IPoUserService poUserService; /** * 标题和时间搜索消息列表 */ @ApiOperation("标题和时间搜索消息列表") @Log(title = "标题和时间搜索") @PreAuthorize("@ss.hasPermi('system:tether:queryTether')") @GetMapping("/queryTether") public TableDataInfo list(@RequestParam(value="tetherName",required = false)String tetherName, @RequestParam(value="tetherTimeStart",required = false) Date tetherTimeStart, @RequestParam(value="tetherTimeEnd",required = false) Date tetherTimeEnd) { startPage(); List list= poTetherService.selectListByTitleAndTime(tetherName,tetherTimeStart,tetherTimeEnd); return getDataTable(list); } /** * 查询套系列表 在售 */ @PreAuthorize("@ss.hasPermi('system:tether:sellingList')") @GetMapping("/sellingList") public TableDataInfo sellingList(PoTether poTether) { startPage(); List sellingList = poTetherService.selectPoTetherSellingList(poTether); return getDataTable(sellingList); } /** * 查询套系列表 预售 */ @PreAuthorize("@ss.hasPermi('system:tether:advanceList')") @GetMapping("/advanceList") public TableDataInfo advanceList(PoTether poTether) { startPage(); List advanceList = poTetherService.selectPoTetherAdvanceList(poTether); return getDataTable(advanceList); } /** * 查询套系列表 已过期 */ @PreAuthorize("@ss.hasPermi('system:tether:selledList')") @GetMapping("/selledList") public TableDataInfo selledList(PoTether poTether) { startPage(); List selledList = poTetherService.selectPoTetherSelledList(poTether); return getDataTable(selledList); } /** * 导出套系列表 */ @PreAuthorize("@ss.hasPermi('system:tether:export')") @Log(title = "套系", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, PoTether poTether) { List list = poTetherService.selectPoTetherList(poTether); ExcelUtil util = new ExcelUtil(PoTether.class); util.exportExcel(response, list, "套系数据"); } /** * 藏品列表 */ @PreAuthorize("@ss.hasPermi('system:tether:collectionList')") @GetMapping("/collectionList/{tetherId}") public TableDataInfo collectionList( @PathVariable("tetherId") Long tetherId){ startPage(); List collectionList = poTetherService.selectPoCollectionListById(tetherId); return getDataTable(collectionList); } /** * 新增套系 */ @PreAuthorize("@ss.hasPermi('system:tether:add')") @Log(title = "套系", businessType = BusinessType.INSERT) @PostMapping("/add") public AjaxResult add(@RequestBody TetherVo tetherVo, @RequestBody @Param("poUser") PoUser poUser) { //判断当前用户是否有操作的权限 poUserService.checkUserAllowed(poUser); if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){ return AjaxResult.error("新增失败"+tetherVo.getTetherName()+"已经存在"); } if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){ return AjaxResult.error("新增失败"+tetherVo.getImage()+"已经存在"); } tetherVo.setCreateBy(getUsername()); tetherVo.setCreateTime(new Date()); return toAjax(poTetherService.insertPoTetherWithCollection(tetherVo)); } /** * 通过id获取套系详细信息 */ @PreAuthorize("@ss.hasPermi('system:tether:query')") @GetMapping(value = "/{tetherId}") public AjaxResult getInfo(@PathVariable("tetherId") Long tetherId) { TetherVo byIdWithCollection = poTetherService.selectPoTetherByTetherIdWithCollection(tetherId); return success(byIdWithCollection); } /** * 修改套系 */ @PreAuthorize("@ss.hasPermi('system:tether:edit')") @Log(title = "套系", businessType = BusinessType.UPDATE) @PutMapping("edit") public AjaxResult edit(@RequestBody TetherVo tetherVo,@RequestBody PoUser poUser) { //校验是否有操作的权限 poUserService.checkUserAllowed(poUser); //校验是否可以访问到数据 poUserService.checkUserDataScope(poUser.getUserId()); if (UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherNameUnique(tetherVo))){ return AjaxResult.error("修改失败"+tetherVo.getTetherName()+"已经存在"); } if(UserConstants.NOT_UNIQUE.equals(poTetherService.checkPostTetherImageUnique(tetherVo))){ return AjaxResult.error("修改失败"+tetherVo.getImage()+"已经存在"); } //清理所有套系的缓存数 //因为对于修改操作,用户是可以修改菜品的分类的,如果用户修改了菜品的分类, // 那么原来分类下将少一个菜品,新的分类下将多一个菜品,这样的话,两个分类下的菜品列表数据都发生了变化。 tetherVo.setUpdateBy(getUsername()); tetherVo.setUpdateTime(new Date()); return toAjax(poTetherService.updatePoTetherWithCollection(tetherVo)); } /** * 删除套系 */ @PreAuthorize("@ss.hasPermi('system:tether:remove')") @Log(title = "套系", businessType = BusinessType.DELETE) @DeleteMapping("/remove/{tetherIds}") public AjaxResult remove(@PathVariable Long[] tetherIds) { if (!getUsername().equals("admin")){ return AjaxResult.error("删除消息失败当前用户不是管理员"); } return toAjax(poTetherService.deletePoTetherByTetherIdsWithCollection(tetherIds)); } }