Quellcode durchsuchen

fix: 新增门店bug

pangqijun vor 3 Monaten
Ursprung
Commit
8211d4e408

+ 1 - 1
src/main/java/org/springblade/modules/api/controller/ApiFacilityController.java

@@ -118,7 +118,7 @@ public class ApiFacilityController extends BaseController {
         List<Facility> list = iFacilityService.lambdaQuery()
                 .eq(Facility::getMerchantId, AuthUtil.getUserId())
                 .and((item) -> item.eq(shopId != null, Facility::getShopId, shopId)
-                        .or(item1 -> item1.eq(Facility::getShopId, shopId)))
+                        .or(item1 -> item1.isNull(Facility::getShopId)))
                 .eq(Facility::getIsDelete, 0)
                 .list();
         return R.data(FacilityWrapper.build().listVO(list));

+ 11 - 3
src/main/java/org/springblade/modules/api/controller/ApiShopController.java

@@ -25,11 +25,13 @@ import org.springblade.modules.business.service.IShopService;
 import org.springblade.modules.business.vo.ShopVO;
 import org.springblade.modules.business.wrapper.ShopWrapper;
 import org.springblade.modules.system.service.IUserMerchantService;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @AllArgsConstructor
@@ -41,22 +43,23 @@ public class ApiShopController extends BaseController {
     private final IFacilityService iFacilityService;
     private final IUserMerchantService iUserMerchantService;
 
+    @Transactional
     @PostMapping("/add")
     @ApiOperationSupport(order = 1)
     @ApiOperation(value = "添加门店", notes = "传入shop")
     public R<Void> save(@Valid @RequestBody Shop shop) {
         shop.setMerchantId(AuthUtil.getUserId());
-
+        iShopService.save(shop);
         //添加设备门店关联
         List<Facility> facilityList = iFacilityService.lambdaQuery()
                 .in(Facility::getId, Func.toLongList(shop.getFacilityIds()))
                 .list();
         facilityList.forEach((item)->item.setShopId(shop.getId()));
-        iFacilityService.updateBatchById(facilityList);
 
-        return R.status(iShopService.save(shop));
+        return R.status(iFacilityService.updateBatchById(facilityList));
     }
 
+    @Transactional
     @PostMapping("/update")
     @ApiOperationSupport(order = 2)
     @ApiOperation(value = "修改门店", notes = "传入shop")
@@ -100,6 +103,11 @@ public class ApiShopController extends BaseController {
     @ApiOperation(value = "门店详情", notes = "传入shop")
     public R<ShopVO> detail(@ApiParam(value = "门店id", required = true) @RequestParam Long id) {
         Shop detail = iShopService.getById(id);
+        List<Facility> list = iFacilityService.lambdaQuery().eq(Facility::getShopId, id).list();
+        if (CollUtil.isNotEmpty(list)) {
+            List<Long> collect = list.stream().map(BaseEntity::getId).collect(Collectors.toList());
+            detail.setFacilityIds(CollUtil.join(collect, ","));
+        }
         return R.data(ShopWrapper.build().entityVO(detail));
     }