ShopBackController.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package com.cdf.controller.back;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.cdf.aop.SysLog;
  5. import com.cdf.common.PageInfo;
  6. import com.cdf.common.ResultData;
  7. import com.cdf.entity.Dept;
  8. import com.cdf.entity.Shop;
  9. import com.cdf.entity.ShopCategory;
  10. import com.cdf.request.ShopRequest;
  11. import com.cdf.response.ShopVo;
  12. import com.cdf.service.IDeptService;
  13. import com.cdf.service.IShopCategoryService;
  14. import com.cdf.service.IShopService;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. @RestController
  22. @RequestMapping("/back/shop")
  23. public class ShopBackController {
  24. @Autowired
  25. IShopService shopService;
  26. @Autowired
  27. IDeptService deptService;
  28. @Autowired
  29. IShopCategoryService categoryService;
  30. @PostMapping("/saveOrUpdate")
  31. @SysLog(logType = "店铺管理",value = "新增或修改")
  32. public ResultData saveOrUpdate(@RequestBody Shop shop){
  33. shop.setCreateTime(null);
  34. shop.setUpdateTime(null);
  35. shopService.saveOrUpdate(shop);
  36. return ResultData.ok();
  37. }
  38. @PostMapping("/list")
  39. public ResultData list(@RequestBody ShopRequest param){
  40. LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<>();
  41. if(StringUtils.isNotBlank(param.getShopName())){
  42. wrapper.eq(Shop::getShopName,param.getShopName());
  43. }
  44. if(param.getDeptId() !=null){
  45. wrapper.eq(Shop::getDeptId,param.getDeptId());
  46. }
  47. Page<Shop> page = shopService.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  48. List<ShopVo> pageVo = new ArrayList<>();
  49. for (Shop shop : page.getRecords()) {
  50. ShopVo shopVo = new ShopVo();
  51. BeanUtils.copyProperties(shop,shopVo);
  52. Dept dept = deptService.getById(shop.getDeptId());
  53. if(dept !=null){
  54. shopVo.setDeptName(dept.getDeptName());
  55. }
  56. ShopCategory category = categoryService.getById(shop.getCategoryId());
  57. if(category !=null){
  58. shopVo.setCategoryName(category.getCategoryName());
  59. }
  60. pageVo.add(shopVo);
  61. }
  62. return ResultData.ok(PageInfo.PageInfo(page.getCurrent(),page.getSize(),page.getTotal(),pageVo));
  63. }
  64. @PostMapping("/delete")
  65. @SysLog(logType = "店铺管理",value = "删除")
  66. public ResultData delete(@RequestBody ShopRequest param){
  67. shopService.removeById(param.getId());
  68. return ResultData.ok();
  69. }
  70. }