|
@@ -0,0 +1,156 @@
|
|
|
+package com.txz.mall.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.txz.mall.core.Result;
|
|
|
+import com.txz.mall.core.ResultCode;
|
|
|
+import com.txz.mall.model.StoreCombination;
|
|
|
+import com.txz.mall.service.StoreCombinationService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by CodeGenerator on 2025/07/14.
|
|
|
+ */
|
|
|
+@Api(tags = "[后台]拼团商品表管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/store/combination")
|
|
|
+public class StoreCombinationController {
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(StoreCombinationController.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StoreCombinationService storeCombinationService;
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ @ApiOperation(value = "拼团商品表新增", httpMethod = "POST")
|
|
|
+ public Result add(@RequestBody StoreCombination storeCombination, Long userId) {
|
|
|
+ if (storeCombination == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ storeCombination.setCreateTime(new Date());
|
|
|
+ storeCombination.setCreateUserId(userId);
|
|
|
+ storeCombinationService.save(storeCombination);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ @ApiOperation(value = "拼团商品表删除", httpMethod = "POST")
|
|
|
+ public Result delete(@RequestParam Long id, Long userId) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ StoreCombination storeCombination = new StoreCombination();
|
|
|
+ storeCombination.setId(id);
|
|
|
+ storeCombination.setIsDelete(1);
|
|
|
+ storeCombinationService.update(storeCombination);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperation(value = "拼团商品表更新", httpMethod = "POST")
|
|
|
+ public Result update(@RequestBody StoreCombination storeCombination, Long userId) {
|
|
|
+ if (storeCombination == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (storeCombination.getId() == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ storeCombination.setUpdateTime(new Date());
|
|
|
+ storeCombination.setUpdateUserId(userId);
|
|
|
+ storeCombinationService.update(storeCombination);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/detail")
|
|
|
+ @ApiOperation(value = "拼团商品表获取详情", httpMethod = "POST")
|
|
|
+ public Result<StoreCombination> detail(@RequestParam Long id, Long userId) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ StoreCombination storeCombination = null;
|
|
|
+ try {
|
|
|
+ storeCombination = storeCombinationService.findById(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(storeCombination);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ @ApiOperation(value = "拼团商品表获取列表", httpMethod = "POST")
|
|
|
+ public Result<List<StoreCombination>> list(@RequestBody StoreCombination storeCombination, @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, Long userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+
|
|
|
+ Condition condition = new Condition(storeCombination.getClass());
|
|
|
+// Criteria criteria = condition.createCriteria();
|
|
|
+// criteria.andEqualTo("name", city.getName());
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ List<StoreCombination> list = storeCombinationService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/addActivityProduct")
|
|
|
+ @ApiOperation(value = "添加活动商品")
|
|
|
+ public Result addActivityProduct(@RequestBody List<StoreCombination> list, Long activityId) {
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (activityId == null) {
|
|
|
+ return Result.fail(ResultCode.USERID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ storeCombinationService.addActivityProduct(list, activityId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+}
|