批量上下架

This commit is contained in:
seesaw
2024-10-30 13:59:21 +08:00
parent a4fa53440b
commit b17e85469f
6 changed files with 61 additions and 15 deletions

View File

@ -107,6 +107,7 @@ public interface ErrorCodeConstants {
ErrorCode STORE_GOODS_TYPE_NOT_EXISTS = new ErrorCode(1_007_904_002,"商品类别不存在");
ErrorCode STORE_SALE_GOODS_NOT_EXISTS = new ErrorCode(1_007_904_003, "售卖商品不存在");
ErrorCode STORE_SALE_GOODS_EXIST = new ErrorCode(1_007_904_007, "售卖商品已在门店上架");
ErrorCode STORE_SALE_GOODS_NOT_NULL = new ErrorCode(1_007_904_04, "售卖商品不能为空");

View File

@ -41,7 +41,7 @@ public class StoreSaleGoodsController {
@PostMapping("/create")
@Operation(summary = "创建售卖商品(上架)")
@PreAuthorize("@ss.hasPermission('member:store-sale-goods:create')")
public CommonResult<Long> createStoreSaleGoods(@Valid @RequestBody StoreSaleGoodsSaveReqVO createReqVO) {
public CommonResult<Integer> createStoreSaleGoods(@Valid @RequestBody StoreSaleGoodsSaveBatchVO createReqVO) {
return success(storeSaleGoodsService.createStoreSaleGoods(createReqVO));
}
@ -57,7 +57,7 @@ public class StoreSaleGoodsController {
@Operation(summary = "删除售卖商品(下架)")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('member:store-sale-goods:delete')")
public CommonResult<Boolean> deleteStoreSaleGoods(@RequestParam("id") Long id) {
public CommonResult<Boolean> deleteStoreSaleGoods(@RequestParam("id") String id) {
storeSaleGoodsService.deleteStoreSaleGoods(id);
return success(true);
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.member.controller.admin.storesalegoods.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 售卖商品新增/修改 Request VO")
@Data
public class StoreSaleGoodsSaveBatchVO {
@Schema(description = "商品id", example = "11772")
private List<Integer> goodsIds;
@Schema(description = "数量")
private Integer number;
@Schema(description = "设备ID")
private String equipmentCode;
@Schema(description = "门店ID")
private List<Long> carteenIds;
}

View File

@ -22,7 +22,7 @@ public interface StoreSaleGoodsService {
* @param createReqVO 创建信息
* @return 编号
*/
Long createStoreSaleGoods(@Valid StoreSaleGoodsSaveReqVO createReqVO);
Integer createStoreSaleGoods(@Valid StoreSaleGoodsSaveBatchVO createReqVO);
/**
* 更新售卖商品
@ -36,7 +36,7 @@ public interface StoreSaleGoodsService {
*
* @param id 编号
*/
void deleteStoreSaleGoods(Long id);
void deleteStoreSaleGoods(String id);
/**
* 获得售卖商品

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.member.controller.app.store.dto.StoreSaleGoodsDto
import cn.iocoder.yudao.module.system.api.cashregisterinfo.CashregisterinfoApi;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cn.iocoder.yudao.module.member.controller.admin.storesalegoods.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.storesalegoods.StoreSaleGoodsDO;
@ -41,12 +43,28 @@ public class StoreSaleGoodsServiceImpl implements StoreSaleGoodsService {
private CashregisterinfoApi cashregisterinfoApi;
@Override
public Long createStoreSaleGoods(StoreSaleGoodsSaveReqVO createReqVO) {
// 插入
StoreSaleGoodsDO storeSaleGoods = BeanUtils.toBean(createReqVO, StoreSaleGoodsDO.class);
storeSaleGoodsMapper.insert(storeSaleGoods);
// 返回
return storeSaleGoods.getId();
public Integer createStoreSaleGoods(StoreSaleGoodsSaveBatchVO createReqVO) {
List<StoreSaleGoodsDO> addList = new ArrayList<>();
List<Long> carteenIds = createReqVO.getCarteenIds();
List<Integer> goodsIds = createReqVO.getGoodsIds();
for (Long carteenId : carteenIds) {
List<StoreSaleGoodsDO> storeSaleGoodsDOS = storeSaleGoodsMapper.selectList(Wrappers.<StoreSaleGoodsDO>lambdaQuery()
.eq(StoreSaleGoodsDO::getCarteenId, carteenId));
List<Integer> saleGoods = storeSaleGoodsDOS.stream().map(StoreSaleGoodsDO::getGoodsId).collect(Collectors.toList());
for (Integer goodsId : goodsIds) {
if(saleGoods.contains(goodsId)){
continue;
}
// 插入
StoreSaleGoodsDO storeSaleGoods = new StoreSaleGoodsDO();
storeSaleGoods.setCarteenId(carteenId);
storeSaleGoods.setGoodsId(goodsId);
addList.add(storeSaleGoods);
}
}
storeSaleGoodsMapper.insertBatch(addList);
return addList.size();
}
@Override
@ -59,11 +77,12 @@ public class StoreSaleGoodsServiceImpl implements StoreSaleGoodsService {
}
@Override
public void deleteStoreSaleGoods(Long id) {
// 校验存在
validateStoreSaleGoodsExists(id);
public void deleteStoreSaleGoods(String id) {
String[] split = id.split(",");
LambdaQueryWrapper<StoreSaleGoodsDO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(StoreSaleGoodsDO::getId, Arrays.asList(split));
// 删除
storeSaleGoodsMapper.deleteById(id);
storeSaleGoodsMapper.delete(wrapper);
}
private void validateStoreSaleGoodsExists(Long id) {

View File

@ -25,7 +25,7 @@
and mu.nickname like concat('%',#{vo.nickName},'%')
</if>
<if test="vo.mobile != null and vo.mobile != ''">
and mu.mobile like concat('%',#{mobile},'%')
and mu.mobile like concat('%',#{vo.mobile},'%')
</if>
</where>
order by so.order_id DESC