Browse Source

新增新建套餐接口,返回值为套餐信息

zhangchen 3 months ago
parent
commit
5504102add

+ 9 - 0
alien-store/src/main/java/shop/alien/store/controller/LifeGroupBuyController.java

@@ -9,6 +9,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.LifeGroupBuyThali;
 import shop.alien.entity.store.dto.LifeGroupBuyDto;
 import shop.alien.entity.store.vo.LifeGroupBuyThaliVo;
 import shop.alien.store.service.LifeGroupBuyService;
@@ -36,6 +37,14 @@ public class LifeGroupBuyController {
         return R.fail("失败");
     }
 
+    @ApiOperation("保存套餐团购(返回保存套餐)")
+    @PostMapping("/saveThaliNew")
+    public R<LifeGroupBuyThali> saveThaliNew(@RequestBody LifeGroupBuyDto lifeGroupBuyDto) {
+        log.info("LifeGroupBuyController.saveThaliNew?lifeGroupBuyDto={}", lifeGroupBuyDto.toString());
+        LifeGroupBuyThali lifeGroupBuyThali = lifeGroupBuyService.saveThaliNew(lifeGroupBuyDto);
+        return R.data(lifeGroupBuyThali);
+    }
+
     @ApiOperation("套餐团购列表")
     @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页数", dataType = "Integer", paramType = "query", required = true),
             @ApiImplicitParam(name = "size", value = "页容", dataType = "Integer", paramType = "query", required = true),

+ 3 - 0
alien-store/src/main/java/shop/alien/store/service/LifeGroupBuyService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.transaction.annotation.Transactional;
 import shop.alien.entity.store.LifeGroupBuyMain;
+import shop.alien.entity.store.LifeGroupBuyThali;
 import shop.alien.entity.store.dto.LifeGroupBuyDto;
 import shop.alien.entity.store.vo.LifeGroupBuyThaliVo;
 
@@ -15,6 +16,8 @@ public interface LifeGroupBuyService extends IService<LifeGroupBuyMain> {
     @Transactional(rollbackFor = Exception.class)
     boolean saveThali(LifeGroupBuyDto lifeGroupBuyDto);
 
+    LifeGroupBuyThali saveThaliNew(LifeGroupBuyDto lifeGroupBuyDto);
+
     IPage<LifeGroupBuyThaliVo> getThaliList(int page, int size, String storeId, String status, String groupName, String groupType);
 
     LifeGroupBuyThaliVo getThaliById(String id, String userId);

+ 42 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeGroupBuyServiceImpl.java

@@ -86,6 +86,48 @@ public class LifeGroupBuyServiceImpl extends ServiceImpl<LifeGroupBuyMainMapper,
     }
 
     @Override
+    public LifeGroupBuyThali saveThaliNew(LifeGroupBuyDto lifeGroupBuyDto) {
+        JSONObject currentUserInfo = JwtUtil.getCurrentUserInfo();
+        Integer userId = null;
+        if (!ObjectUtils.isEmpty(currentUserInfo)) {
+            userId = currentUserInfo.getInteger("userId");
+        }
+        LifeGroupBuyMain lifeGroupBuyMain = lifeGroupBuyDto.getLifeGroupBuyMain();
+        List<LifeGroupBuyThali> lifeGroupBuyThalis = lifeGroupBuyDto.getLifeGroupBuyThalis();
+        LifeGroupBuyThali lifeGroupBuyThali = null;
+        if (ObjectUtils.isEmpty(lifeGroupBuyMain.getId())) {
+            Integer count = lifeGroupBuyMainMapper.selectCount(new LambdaQueryWrapper<LifeGroupBuyMain>().like(LifeGroupBuyMain::getCreatedTime, DateUtils.formatDate(new Date(), "yyyy-MM-dd")).eq(LifeGroupBuyMain::getStoreId, lifeGroupBuyMain.getStoreId()));
+            lifeGroupBuyMain.setGroupNo("G" + DateUtils.formatDate(new Date(), "yyyyMMdd") + lifeGroupBuyMain.getStoreId() + org.apache.commons.lang3.StringUtils.leftPad(String.valueOf(count + 1), 5, "0"));
+            lifeGroupBuyMain.setCreatedUserId(userId);
+            lifeGroupBuyMainMapper.insert(lifeGroupBuyMain);
+            if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
+                for (int i = 0; i < lifeGroupBuyThalis.size(); i++) {
+                    lifeGroupBuyThali = lifeGroupBuyThalis.get(i);
+                    lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
+                    lifeGroupBuyThali.setDetailSort(i + 1);
+                    lifeGroupBuyThali.setCreatedUserId(userId);
+                    lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
+                }
+            }
+            return lifeGroupBuyThali;
+        } else {
+            lifeGroupBuyMain.setUpdatedUserId(userId);
+            lifeGroupBuyMainMapper.updateById(lifeGroupBuyMain);
+            lifeGroupBuyThaliMapper.update(null, new LambdaUpdateWrapper<LifeGroupBuyThali>().eq(LifeGroupBuyThali::getParentId, lifeGroupBuyMain.getId()).set(LifeGroupBuyThali::getDeleteFlag, 1));
+            if (ObjectUtils.isNotEmpty(lifeGroupBuyThalis)) {
+                for (int i = 0; i < lifeGroupBuyThalis.size(); i++) {
+                    lifeGroupBuyThali = lifeGroupBuyThalis.get(i);
+                    lifeGroupBuyThali.setParentId(lifeGroupBuyMain.getId().toString());
+                    lifeGroupBuyThali.setDetailSort(i + 1);
+                    lifeGroupBuyThali.setCreatedUserId(userId);
+                    lifeGroupBuyThaliMapper.insert(lifeGroupBuyThali);
+                }
+            }
+            return lifeGroupBuyThali;
+        }
+    }
+
+    @Override
     public IPage<LifeGroupBuyThaliVo> getThaliList(int page, int size, String storeId, String status, String groupName, String groupType) {
         QueryWrapper<LifeGroupBuyThaliVo> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq(StringUtils.isNotEmpty(storeId), "store_id", storeId)