1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- package com.cdf.controller.back;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.cdf.aop.SysLog;
- import com.cdf.common.PageInfo;
- import com.cdf.common.ResultData;
- import com.cdf.entity.Dept;
- import com.cdf.entity.Shop;
- import com.cdf.entity.ShopCategory;
- import com.cdf.request.ShopRequest;
- import com.cdf.response.ShopVo;
- import com.cdf.service.IDeptService;
- import com.cdf.service.IShopCategoryService;
- import com.cdf.service.IShopService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.List;
- @RestController
- @RequestMapping("/back/shop")
- public class ShopBackController {
- @Autowired
- IShopService shopService;
- @Autowired
- IDeptService deptService;
- @Autowired
- IShopCategoryService categoryService;
- @PostMapping("/saveOrUpdate")
- @SysLog(logType = "店铺管理",value = "新增或修改")
- public ResultData saveOrUpdate(@RequestBody Shop shop){
- shop.setCreateTime(null);
- shop.setUpdateTime(null);
- shopService.saveOrUpdate(shop);
- return ResultData.ok();
- }
- @PostMapping("/list")
- public ResultData list(@RequestBody ShopRequest param){
- LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getShopName())){
- wrapper.eq(Shop::getShopName,param.getShopName());
- }
- if(param.getDeptId() !=null){
- wrapper.eq(Shop::getDeptId,param.getDeptId());
- }
- Page<Shop> page = shopService.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- List<ShopVo> pageVo = new ArrayList<>();
- for (Shop shop : page.getRecords()) {
- ShopVo shopVo = new ShopVo();
- BeanUtils.copyProperties(shop,shopVo);
- Dept dept = deptService.getById(shop.getDeptId());
- if(dept !=null){
- shopVo.setDeptName(dept.getDeptName());
- }
- ShopCategory category = categoryService.getById(shop.getCategoryId());
- if(category !=null){
- shopVo.setCategoryName(category.getCategoryName());
- }
- pageVo.add(shopVo);
- }
- return ResultData.ok(PageInfo.PageInfo(page.getCurrent(),page.getSize(),page.getTotal(),pageVo));
- }
- @PostMapping("/delete")
- @SysLog(logType = "店铺管理",value = "删除")
- public ResultData delete(@RequestBody ShopRequest param){
- shopService.removeById(param.getId());
- return ResultData.ok();
- }
- }
|