将单据中明细的写入数据库,优化成批量写入

This commit is contained in:
jishenghua
2026-01-14 22:46:56 +08:00
parent 4ba5338514
commit ea660f0836
3 changed files with 30 additions and 6 deletions

View File

@@ -18,6 +18,9 @@ import java.util.List;
* @Date: 2019/1/24 16:59 * @Date: 2019/1/24 16:59
*/ */
public interface DepotItemMapperEx { public interface DepotItemMapperEx {
int batchInsert(List<DepotItem> depotItemList);
List<DepotItem> selectByConditionDepotItem( List<DepotItem> selectByConditionDepotItem(
@Param("name") String name, @Param("name") String name,
@Param("type") Integer type, @Param("type") Integer type,

View File

@@ -394,6 +394,7 @@ public class DepotItemService {
checkAssembleWithMaterialType(rowArr, depotHead.getSubType()); checkAssembleWithMaterialType(rowArr, depotHead.getSubType());
//校验多行明细当中是否存在重复的序列号 //校验多行明细当中是否存在重复的序列号
checkSerialNumberRepeat(rowArr); checkSerialNumberRepeat(rowArr);
List<DepotItem> depotItemList = new ArrayList<>();
for (int i = 0; i < rowArr.size(); i++) { for (int i = 0; i < rowArr.size(); i++) {
DepotItem depotItem = new DepotItem(); DepotItem depotItem = new DepotItem();
JSONObject rowObj = JSONObject.parseObject(rowArr.getString(i)); JSONObject rowObj = JSONObject.parseObject(rowArr.getString(i));
@@ -677,13 +678,17 @@ public class DepotItemService {
} }
} }
} }
this.insertDepotItemWithObj(depotItem); depotItemList.add(depotItem);
}
//批量写入单据明细数据
depotItemMapperEx.batchInsert(depotItemList);
for (DepotItem depotItem : depotItemList) {
//更新当前库存 //更新当前库存
updateCurrentStock(depotItem); updateCurrentStock(depotItem);
//更新当前成本价 //更新当前成本价
updateCurrentUnitPrice(depotItem); updateCurrentUnitPrice(depotItem);
//更新商品的价格 //更新商品的价格
updateMaterialExtendPrice(materialExtend.getId(), depotHead.getSubType(), depotHead.getBillType(), rowObj); updateMaterialExtendPrice(depotItem.getMaterialExtendId(), depotHead.getSubType(), depotHead.getBillType(), depotItem.getUnitPrice());
} }
//如果关联单据号非空则更新订单的状态,单据类型:采购入库单、销售出库单、盘点复盘单、其它入库单、其它出库单 //如果关联单据号非空则更新订单的状态,单据类型:采购入库单、销售出库单、盘点复盘单、其它入库单、其它出库单
if(BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType()) if(BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
@@ -915,13 +920,12 @@ public class DepotItemService {
* 更新商品的价格 * 更新商品的价格
* @param meId * @param meId
* @param subType * @param subType
* @param rowObj * @param unitPrice
*/ */
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateMaterialExtendPrice(Long meId, String subType, String billType, JSONObject rowObj) throws Exception { public void updateMaterialExtendPrice(Long meId, String subType, String billType, BigDecimal unitPrice) throws Exception {
if(systemConfigService.getUpdateUnitPriceFlag()) { if(systemConfigService.getUpdateUnitPriceFlag()) {
if (StringUtil.isExist(rowObj.get("unitPrice"))) { if (unitPrice!=null) {
BigDecimal unitPrice = rowObj.getBigDecimal("unitPrice");
MaterialExtend materialExtend = new MaterialExtend(); MaterialExtend materialExtend = new MaterialExtend();
materialExtend.setId(meId); materialExtend.setId(meId);
if(BusinessConstants.SUB_TYPE_PURCHASE.equals(subType)) { if(BusinessConstants.SUB_TYPE_PURCHASE.equals(subType)) {

View File

@@ -110,6 +110,23 @@
<result column="oper_number" jdbcType="VARCHAR" property="operNumber" /> <result column="oper_number" jdbcType="VARCHAR" property="operNumber" />
</resultMap> </resultMap>
<insert id="batchInsert" parameterType="java.util.List">
insert into jsh_depot_item (header_id, material_id, material_extend_id, material_unit, sku, oper_number,
basic_number, unit_price, purchase_unit_price, tax_unit_price, all_price, remark, depot_id, another_depot_id,
tax_rate, tax_money, tax_last_money, material_type, sn_list, batch_number, expiration_date, link_id)
values
<foreach collection="list" item="item" separator=",">
(#{item.headerId,jdbcType=BIGINT}, #{item.materialId,jdbcType=BIGINT},
#{item.materialExtendId,jdbcType=BIGINT}, #{item.materialUnit,jdbcType=VARCHAR}, #{item.sku,jdbcType=VARCHAR},
#{item.operNumber,jdbcType=DECIMAL}, #{item.basicNumber,jdbcType=DECIMAL}, #{item.unitPrice,jdbcType=DECIMAL},
#{item.purchaseUnitPrice,jdbcType=DECIMAL}, #{item.taxUnitPrice,jdbcType=DECIMAL}, #{item.allPrice,jdbcType=DECIMAL},
#{item.remark,jdbcType=VARCHAR}, #{item.depotId,jdbcType=BIGINT}, #{item.anotherDepotId,jdbcType=BIGINT},
#{item.taxRate,jdbcType=DECIMAL}, #{item.taxMoney,jdbcType=DECIMAL}, #{item.taxLastMoney,jdbcType=DECIMAL},
#{item.materialType,jdbcType=VARCHAR}, #{item.snList,jdbcType=VARCHAR}, #{item.batchNumber,jdbcType=VARCHAR},
#{item.expirationDate,jdbcType=TIMESTAMP}, #{item.linkId,jdbcType=BIGINT})
</foreach >
</insert>
<select id="selectByConditionDepotItem" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap"> <select id="selectByConditionDepotItem" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="com.jsh.erp.datasource.mappers.DepotItemMapper.BaseResultMap">
select * select *
FROM jsh_depot_item FROM jsh_depot_item