批量插入

This commit is contained in:
2025-11-28 18:08:12 +08:00
parent e80bf9a39e
commit 403c872ee3
12 changed files with 22 additions and 27 deletions

View File

@@ -1,24 +1,19 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.PageDTO;
import com.czg.account.dto.register.MerchantRegisterDTO;
import com.czg.account.entity.MerchantRegister;
import com.czg.account.service.MerchantRegisterService;
import com.czg.account.vo.MerchantRegisterVO;
import com.czg.service.account.mapper.MerchantRegisterMapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* 激活码 服务层实现。
@@ -46,6 +41,7 @@ public class MerchantRegisterServiceImpl extends ServiceImpl<MerchantRegisterMap
tbMerchantRegister.setPeriodMonth(merchantRegisterDTO.periodMonth());
registers.add(tbMerchantRegister);
}
return saveBatch(registers);
int i = mapper.insertBatchSelective(registers, 50);
return i > 0;
}
}

View File

@@ -61,7 +61,7 @@ public class ShopExtendServiceImpl extends ServiceImpl<ShopExtendMapper, ShopExt
newRecord.initAutoKey(key, shopId);
newRecords.add(newRecord);
}
saveBatch(newRecords);
mapper.insertBatchSelective(newRecords,50);
return newRecords;
} else {
for (ShopExtend shopExtend : shopExtendList) {
@@ -97,7 +97,7 @@ public class ShopExtendServiceImpl extends ServiceImpl<ShopExtendMapper, ShopExt
newRecords.add(newRecord);
}
saveBatch(newRecords);
mapper.insertBatchSelective(newRecords,50);
shopExtendList.addAll(newRecords);
return shopExtendList;

View File

@@ -103,7 +103,7 @@ public class ShopTableServiceImpl extends ServiceImpl<ShopTableMapper, ShopTable
tableArrayList.add(shopTable);
}
saveBatch(tableArrayList);
mapper.insertBatchSelective(tableArrayList, 50);
if (StrUtil.isNotBlank(msg.toString())) {
msg.append("台桌名已存在,未添加");
throw new CzgException(msg.toString());

View File

@@ -180,11 +180,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
// Step 4: 批量保存(如有数据)
return rolesMenus.isEmpty() || sysRolesMenusService.saveBatch(rolesMenus);
return rolesMenus.isEmpty() || sysRolesMenusService.getMapper().insertBatchSelective(rolesMenus, 50) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean editPermission(long userId, RolePermissionDTO rolePermissionDTO) {

View File

@@ -49,7 +49,7 @@ public class MkCouponGiftServiceImpl extends ServiceImpl<MkCouponGiftMapper, MkC
public void addCouponGift(Long sourceId, String sourceName, Integer type, List<MkCouponGiftDTO> couponGiftList) {
remove(new QueryWrapper().eq(MkCouponGift::getSourceId, sourceId).eq(MkCouponGift::getType, type));
if (CollUtil.isNotEmpty(couponGiftList)) {
List newCoupons = new ArrayList<>();
List<MkCouponGift> newCoupons = new ArrayList<>();
for (MkCouponGiftDTO giftDTO : couponGiftList) {
ShopCoupon coupon = couponMapper.selectOneByQuery(new QueryWrapper().eq(ShopCoupon::getId, giftDTO.getCouponId()));
if (coupon == null) {
@@ -64,7 +64,7 @@ public class MkCouponGiftServiceImpl extends ServiceImpl<MkCouponGiftMapper, MkC
couponGift.setNum(giftDTO.getNum());
newCoupons.add(couponGift);
}
saveBatch(newCoupons);
mapper.insertBatchSelective(newCoupons, 50);
}
}

View File

@@ -476,7 +476,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
recordList.add(record);
}
}
saveBatch(recordList);
mapper.insertBatchSelective(recordList, 50);
QueryWrapper queryWrapper = new QueryWrapper();
ShopCoupon newCoupon = new ShopCoupon();
newCoupon.setGiftNum(coupon.getGiftNum());

View File

@@ -112,7 +112,7 @@ public class ShopProdStatisticServiceImpl extends ServiceImpl<ShopProdStatisticM
if (exists) {
remove(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId).eq(ShopProdStatistic::getCreateDay, day));
}
saveBatch(realTimeData);
mapper.insertBatchSelective(realTimeData, 50);
}
}

View File

@@ -57,7 +57,7 @@ public class ShopTableOrderStatisticServiceImpl extends ServiceImpl<ShopTableOrd
.toList();
if (CollUtil.isNotEmpty(realTimeData)) {
remove(QueryWrapper.create().eq(ShopTableOrderStatistic::getShopId, shopId).eq(ShopTableOrderStatistic::getCreateDay, day));
saveBatch(realTimeData);
mapper.insertBatchSelective(realTimeData, 50);
}
}
}

View File

@@ -121,7 +121,7 @@
consInfo.setStockNumber(consStockFlow.getAfterNumber());
updateStockList.add(consInfo);
}
super.saveBatch(insertList);
mapper.insertBatchSelective(insertList, 50);
for (ConsInfo consInfo : updateStockList) {
consInfoMapper.update(consInfo);
}
@@ -158,7 +158,7 @@
consInfo.setStockNumber(entity.getAfterNumber());
updateStockList.add(consInfo);
}
super.saveBatch(insertList);
mapper.insertBatchSelective(insertList, 50);
for (ConsInfo consInfo : updateStockList) {
consInfoMapper.update(consInfo);
}

View File

@@ -36,7 +36,7 @@ public class ProdConsRelationServiceImpl extends ServiceImpl<ProdConsRelationMap
private QueryWrapper buildQueryWrapper(ProdConsRelationDTO param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
Long shopId = StpKit.USER.getShopId(0L);
Long shopId = StpKit.USER.getShopId();
queryWrapper.eq(ProdConsRelation::getShopId, shopId);
return queryWrapper;
}
@@ -50,7 +50,7 @@ public class ProdConsRelationServiceImpl extends ServiceImpl<ProdConsRelationMap
@Override
@Transactional(rollbackFor = Exception.class)
public void saveProdConsRelation(ProdConsBindDTO dto) {
Long shopId = StpKit.USER.getShopId(0L);
Long shopId = StpKit.USER.getShopId();
long count = productMapper.selectCountByQuery(query().eq(Product::getShopId, shopId).eq(Product::getId, dto.getId()));
if (count == 0) {
throw new CzgException("商品不存在");
@@ -72,7 +72,7 @@ public class ProdConsRelationServiceImpl extends ServiceImpl<ProdConsRelationMap
throw new CzgException("非法操作,绑定关系商品不一致");
}
List<ProdConsRelation> entityList = BeanUtil.copyToList(consList, ProdConsRelation.class);
super.saveBatch(entityList);
mapper.insertBatchSelective(entityList, 50);
}
}

View File

@@ -733,7 +733,7 @@ public class ShopSyncServiceImpl implements ShopSyncService {
}
}
if (CollUtil.isNotEmpty(addList)) {
prodGroupRelationService.saveBatch(addList, 100);
prodGroupRelationService.getMapper().insertBatchSelective(addList, 100);
}
if (CollUtil.isNotEmpty(upList)) {
prodGroupRelationService.updateBatch(addList, 100);

View File

@@ -157,7 +157,7 @@ public class ShopVendorServiceImpl extends ServiceImpl<ShopVendorMapper, ShopVen
throw new CzgException("批量付款应全部付款");
}
consPayRecordService.saveBatch(records);
consPayRecordService.getMapper().insertBatchSelective(records, 50);
return consStockFlowService.updateBatch(stockFlows);
}else {
ConsStockFlow stockFlow = consStockFlowMapper.selectOneByQuery(new QueryWrapper().eq(ConsStockFlow::getShopId, shopId).eq(ConsStockFlow::getId, payDTO.getFlowIdList().getFirst()));