|
|
@@ -0,0 +1,171 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package com.store.goods.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.store.goods.entity.GoodsItems;
|
|
|
+import com.store.goods.service.IGoodsItemsService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiParam;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import javax.validation.Valid;
|
|
|
+
|
|
|
+import org.springblade.core.mp.support.Condition;
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.store.goods.entity.GoodsDesc;
|
|
|
+import com.store.goods.vo.GoodsDescVO;
|
|
|
+import com.store.goods.service.IGoodsDescService;
|
|
|
+import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 控制器
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2021-11-19
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/goodsdesc")
|
|
|
+@Api(value = "商品主表", tags = "商品主表接口")
|
|
|
+public class GoodsDescController extends BladeController {
|
|
|
+
|
|
|
+ private final IGoodsDescService goodsDescService;
|
|
|
+
|
|
|
+ private final IGoodsItemsService goodsItemsService;
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ */
|
|
|
+ @GetMapping("/detail")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "详情", notes = "传入goodsDesc")
|
|
|
+ public R<GoodsDesc> detail(GoodsDesc goodsDesc) {
|
|
|
+ GoodsDesc detail = goodsDescService.getOne(Condition.getQueryWrapper(goodsDesc));
|
|
|
+ LambdaQueryWrapper<GoodsItems> itemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ itemsLambdaQueryWrapper
|
|
|
+ .eq(GoodsItems::getIsDeleted,0)
|
|
|
+ .eq(GoodsItems::getPid,detail.getId())
|
|
|
+ .eq(GoodsItems::getTenantId, AuthUtil.getTenantId());
|
|
|
+ List<GoodsItems> itemsList = goodsItemsService.list(itemsLambdaQueryWrapper);
|
|
|
+ detail.setItemsList(itemsList);
|
|
|
+ return R.data(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入goodsDesc")
|
|
|
+ public R<IPage<GoodsDesc>> list(GoodsDesc goodsDesc, Query query) {
|
|
|
+ IPage<GoodsDesc> pages = goodsDescService.page(Condition.getPage(query), Condition.getQueryWrapper(goodsDesc));
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义分页
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "分页", notes = "传入goodsDesc")
|
|
|
+ public R<IPage<GoodsDescVO>> page(GoodsDescVO goodsDesc, Query query) {
|
|
|
+ IPage<GoodsDescVO> pages = goodsDescService.selectGoodsDescPage(Condition.getPage(query), goodsDesc);
|
|
|
+ return R.data(pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ */
|
|
|
+ @PostMapping("/save")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "新增", notes = "传入goodsDesc")
|
|
|
+ public R save(@Valid @RequestBody GoodsDesc goodsDesc) {
|
|
|
+ return R.status(goodsDescService.save(goodsDesc));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ */
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperationSupport(order = 5)
|
|
|
+ @ApiOperation(value = "修改", notes = "传入goodsDesc")
|
|
|
+ public R update(@Valid @RequestBody GoodsDesc goodsDesc) {
|
|
|
+ return R.status(goodsDescService.updateById(goodsDesc));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或修改
|
|
|
+ */
|
|
|
+ @PostMapping("/submit")
|
|
|
+ @ApiOperationSupport(order = 6)
|
|
|
+ @ApiOperation(value = "新增或修改", notes = "传入goodsDesc")
|
|
|
+ public R submit(@Valid @RequestBody GoodsDesc goodsDesc) {
|
|
|
+ return R.status(goodsDescService.saveOrUpdate(goodsDesc));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ @PostMapping("/remove")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "删除", notes = "传入ids")
|
|
|
+ public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
|
|
+ return R.status(goodsDescService.removeByIds(Func.toLongList(ids)));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量上下架
|
|
|
+ */
|
|
|
+ @PostMapping("/batchOperationGoods")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "批量上下架", notes = "传入ids")
|
|
|
+ public R batchOperationGoods(@ApiParam(value = "主键集合", required = true) @RequestParam String ids,
|
|
|
+ @ApiParam(value = "0:下架 1:上架", required = true) @RequestParam int flag)
|
|
|
+ {
|
|
|
+ List<Long> longs = Func.toLongList(ids);
|
|
|
+ if(CollectionUtils.isEmpty(longs))
|
|
|
+ {
|
|
|
+ throw new SecurityException("传入ids不能为空");
|
|
|
+ }
|
|
|
+ goodsDescService.batchOperationGoods(longs,flag);
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认保存
|
|
|
+ */
|
|
|
+ @PostMapping("/modify")
|
|
|
+ @ApiOperationSupport(order = 8)
|
|
|
+ @ApiOperation(value = "确认保存", notes = "传入商品主表和规格")
|
|
|
+ public R modify(@RequestBody GoodsDesc goodsDesc)
|
|
|
+ {
|
|
|
+ goodsDescService.modify(goodsDesc);
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|