| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- package com.ruoyi.app.mendian;
- import java.util.List;
- import jakarta.servlet.http.HttpServletResponse;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.ruoyi.common.annotation.Anonymous;
- import com.ruoyi.common.utils.MessageUtils;
- import com.ruoyi.system.domain.PosFood;
- import com.ruoyi.system.domain.PosStore;
- import com.ruoyi.system.service.IPosFoodService;
- import com.ruoyi.system.service.MerchantStoreAccessService;
- import com.ruoyi.system.utils.Auth;
- import com.ruoyi.system.utils.AuthContext;
- import com.ruoyi.system.utils.JwtUtil;
- 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.PosFenlei;
- import com.ruoyi.system.service.IPosFenleiService;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.common.core.page.TableDataInfo;
- /**
- * spfenleiController
- *
- * @author ruoyi
- * @date 2023-05-21
- */
- @RestController
- @RequestMapping("/system/fenlei")
- public class PosFenleiController extends BaseController
- {
- @Autowired
- private IPosFenleiService posFenleiService;
- @Autowired //商品
- private IPosFoodService posFoodService;
- @Autowired
- private MerchantStoreAccessService merchantStoreAccessService;
- /**
- * 删除商品分类
- */
- @Anonymous
- @Auth
- @GetMapping("/delefenlei")
- public AjaxResult delefenlei(@RequestHeader String token, @RequestParam String id){
- PosFenlei existing = posFenleiService.getById(Long.valueOf(id));
- if (existing == null) {
- return error(MessageUtils.message("no.data.not.exist"));
- }
- merchantStoreAccessService.requireStoreAccess(
- AuthContext.requireUserId(), existing.getMendid());
- QueryWrapper<PosFood> query = new QueryWrapper<>();
- query.eq("fl_id",id);
- List<PosFood> fdlist = posFoodService.list(query);
- if(fdlist.size()>0){
- return error(MessageUtils.message("no.data.exist.not.del"));
- }else {
- return toAjax(posFenleiService.deletePosFenleiById(Long.valueOf(id)));
- }
- }
- /**
- * 添加或修改商品分类
- */
- @Anonymous
- @Auth
- @PostMapping("/addfenlei")
- public AjaxResult addfenlei(@RequestHeader String token, @RequestBody PosFenlei posFenlei){
- Long userId = AuthContext.requireUserId();
- if (posFenlei.getId() == null) {
- merchantStoreAccessService.requireStoreAccess(userId, posFenlei.getMendid());
- } else {
- PosFenlei existing = posFenleiService.getById(posFenlei.getId());
- if (existing == null) {
- return error(MessageUtils.message("no.data.not.exist"));
- }
- merchantStoreAccessService.requireStoreAccess(userId, existing.getMendid());
- posFenlei.setMendid(existing.getMendid());
- }
- Boolean org = posFenleiService.saveOrUpdate(posFenlei);
- if(org){
- return success();
- }else {
- return error();
- }
- }
- /**
- * 查询商品分类
- */
- @Anonymous
- @GetMapping("/getfenlei")
- public AjaxResult getfenlei(@RequestParam Integer id,@RequestParam(defaultValue = "") String language){
- QueryWrapper<PosFenlei> queryWrapper= new QueryWrapper<>();
- queryWrapper.select().orderByDesc("sort");
- queryWrapper.eq("mendid",id);
- String lang = "3";
- if(!"".equals(language)){
- lang = language;
- }
- queryWrapper.eq("language",lang);
- List<PosFenlei> list = posFenleiService.list(queryWrapper);
- return success(list);
- }
- /**
- * 查询spfenlei列表
- */
- @PreAuthorize("@ss.hasPermi('system:fenlei:list')")
- @GetMapping("/list")
- public TableDataInfo list(PosFenlei posFenlei)
- {
- startPage();
- List<PosFenlei> list = posFenleiService.selectPosFenleiList(posFenlei);
- return getDataTable(list);
- }
- /**
- * 导出spfenlei列表
- */
- @PreAuthorize("@ss.hasPermi('system:fenlei:export')")
- @Log(title = "spfenlei", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, PosFenlei posFenlei)
- {
- List<PosFenlei> list = posFenleiService.selectPosFenleiList(posFenlei);
- ExcelUtil<PosFenlei> util = new ExcelUtil<PosFenlei>(PosFenlei.class);
- util.exportExcel(response, list, MessageUtils.message("no.export.excel.goods.classify"));
- }
- /**
- * 获取spfenlei详细信息
- */
- @PreAuthorize("@ss.hasPermi('system:fenlei:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id)
- {
- return success(posFenleiService.selectPosFenleiById(id));
- }
- /**
- * 新增spfenlei
- */
- @PreAuthorize("@ss.hasPermi('system:fenlei:add')")
- @Log(title = "spfenlei", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody PosFenlei posFenlei)
- {
- return toAjax(posFenleiService.insertPosFenlei(posFenlei));
- }
- /**
- * 修改spfenlei
- */
- @PreAuthorize("@ss.hasPermi('system:fenlei:edit')")
- @Log(title = "spfenlei", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody PosFenlei posFenlei)
- {
- return toAjax(posFenleiService.updatePosFenlei(posFenlei));
- }
- /**
- * 删除spfenlei
- */
- @PreAuthorize("@ss.hasPermi('system:fenlei:remove')")
- @Log(title = "spfenlei", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
- return toAjax(posFenleiService.deletePosFenleiByIds(ids));
- }
- }
|