PosFenleiController.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.ruoyi.app.mendian;
  2. import java.util.List;
  3. import jakarta.servlet.http.HttpServletResponse;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  6. import com.ruoyi.common.annotation.Anonymous;
  7. import com.ruoyi.common.utils.MessageUtils;
  8. import com.ruoyi.system.domain.PosFood;
  9. import com.ruoyi.system.domain.PosStore;
  10. import com.ruoyi.system.service.IPosFoodService;
  11. import com.ruoyi.system.service.MerchantStoreAccessService;
  12. import com.ruoyi.system.utils.Auth;
  13. import com.ruoyi.system.utils.AuthContext;
  14. import com.ruoyi.system.utils.JwtUtil;
  15. import org.springframework.security.access.prepost.PreAuthorize;
  16. import org.springframework.beans.factory.annotation.Autowired;
  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.PosFenlei;
  23. import com.ruoyi.system.service.IPosFenleiService;
  24. import com.ruoyi.common.utils.poi.ExcelUtil;
  25. import com.ruoyi.common.core.page.TableDataInfo;
  26. /**
  27. * spfenleiController
  28. *
  29. * @author ruoyi
  30. * @date 2023-05-21
  31. */
  32. @RestController
  33. @RequestMapping("/system/fenlei")
  34. public class PosFenleiController extends BaseController
  35. {
  36. @Autowired
  37. private IPosFenleiService posFenleiService;
  38. @Autowired //商品
  39. private IPosFoodService posFoodService;
  40. @Autowired
  41. private MerchantStoreAccessService merchantStoreAccessService;
  42. /**
  43. * 删除商品分类
  44. */
  45. @Anonymous
  46. @Auth
  47. @GetMapping("/delefenlei")
  48. public AjaxResult delefenlei(@RequestHeader String token, @RequestParam String id){
  49. PosFenlei existing = posFenleiService.getById(Long.valueOf(id));
  50. if (existing == null) {
  51. return error(MessageUtils.message("no.data.not.exist"));
  52. }
  53. merchantStoreAccessService.requireStoreAccess(
  54. AuthContext.requireUserId(), existing.getMendid());
  55. QueryWrapper<PosFood> query = new QueryWrapper<>();
  56. query.eq("fl_id",id);
  57. List<PosFood> fdlist = posFoodService.list(query);
  58. if(fdlist.size()>0){
  59. return error(MessageUtils.message("no.data.exist.not.del"));
  60. }else {
  61. return toAjax(posFenleiService.deletePosFenleiById(Long.valueOf(id)));
  62. }
  63. }
  64. /**
  65. * 添加或修改商品分类
  66. */
  67. @Anonymous
  68. @Auth
  69. @PostMapping("/addfenlei")
  70. public AjaxResult addfenlei(@RequestHeader String token, @RequestBody PosFenlei posFenlei){
  71. Long userId = AuthContext.requireUserId();
  72. if (posFenlei.getId() == null) {
  73. merchantStoreAccessService.requireStoreAccess(userId, posFenlei.getMendid());
  74. } else {
  75. PosFenlei existing = posFenleiService.getById(posFenlei.getId());
  76. if (existing == null) {
  77. return error(MessageUtils.message("no.data.not.exist"));
  78. }
  79. merchantStoreAccessService.requireStoreAccess(userId, existing.getMendid());
  80. posFenlei.setMendid(existing.getMendid());
  81. }
  82. Boolean org = posFenleiService.saveOrUpdate(posFenlei);
  83. if(org){
  84. return success();
  85. }else {
  86. return error();
  87. }
  88. }
  89. /**
  90. * 查询商品分类
  91. */
  92. @Anonymous
  93. @GetMapping("/getfenlei")
  94. public AjaxResult getfenlei(@RequestParam Integer id,@RequestParam(defaultValue = "") String language){
  95. QueryWrapper<PosFenlei> queryWrapper= new QueryWrapper<>();
  96. queryWrapper.select().orderByDesc("sort");
  97. queryWrapper.eq("mendid",id);
  98. String lang = "3";
  99. if(!"".equals(language)){
  100. lang = language;
  101. }
  102. queryWrapper.eq("language",lang);
  103. List<PosFenlei> list = posFenleiService.list(queryWrapper);
  104. return success(list);
  105. }
  106. /**
  107. * 查询spfenlei列表
  108. */
  109. @PreAuthorize("@ss.hasPermi('system:fenlei:list')")
  110. @GetMapping("/list")
  111. public TableDataInfo list(PosFenlei posFenlei)
  112. {
  113. startPage();
  114. List<PosFenlei> list = posFenleiService.selectPosFenleiList(posFenlei);
  115. return getDataTable(list);
  116. }
  117. /**
  118. * 导出spfenlei列表
  119. */
  120. @PreAuthorize("@ss.hasPermi('system:fenlei:export')")
  121. @Log(title = "spfenlei", businessType = BusinessType.EXPORT)
  122. @PostMapping("/export")
  123. public void export(HttpServletResponse response, PosFenlei posFenlei)
  124. {
  125. List<PosFenlei> list = posFenleiService.selectPosFenleiList(posFenlei);
  126. ExcelUtil<PosFenlei> util = new ExcelUtil<PosFenlei>(PosFenlei.class);
  127. util.exportExcel(response, list, MessageUtils.message("no.export.excel.goods.classify"));
  128. }
  129. /**
  130. * 获取spfenlei详细信息
  131. */
  132. @PreAuthorize("@ss.hasPermi('system:fenlei:query')")
  133. @GetMapping(value = "/{id}")
  134. public AjaxResult getInfo(@PathVariable("id") Long id)
  135. {
  136. return success(posFenleiService.selectPosFenleiById(id));
  137. }
  138. /**
  139. * 新增spfenlei
  140. */
  141. @PreAuthorize("@ss.hasPermi('system:fenlei:add')")
  142. @Log(title = "spfenlei", businessType = BusinessType.INSERT)
  143. @PostMapping
  144. public AjaxResult add(@RequestBody PosFenlei posFenlei)
  145. {
  146. return toAjax(posFenleiService.insertPosFenlei(posFenlei));
  147. }
  148. /**
  149. * 修改spfenlei
  150. */
  151. @PreAuthorize("@ss.hasPermi('system:fenlei:edit')")
  152. @Log(title = "spfenlei", businessType = BusinessType.UPDATE)
  153. @PutMapping
  154. public AjaxResult edit(@RequestBody PosFenlei posFenlei)
  155. {
  156. return toAjax(posFenleiService.updatePosFenlei(posFenlei));
  157. }
  158. /**
  159. * 删除spfenlei
  160. */
  161. @PreAuthorize("@ss.hasPermi('system:fenlei:remove')")
  162. @Log(title = "spfenlei", businessType = BusinessType.DELETE)
  163. @DeleteMapping("/{ids}")
  164. public AjaxResult remove(@PathVariable Long[] ids)
  165. {
  166. return toAjax(posFenleiService.deletePosFenleiByIds(ids));
  167. }
  168. }