Authored by mali

库存管理

... ... @@ -20,7 +20,7 @@ public interface StorageMapper {
List<Storage> selectByGoodsIdList(@Param("list") List<Integer> goodsIdList);
int addStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum, @Param("oldStorageNum")Integer oldStorageNum);
int updateStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum, @Param("oldStorageNum")Integer oldStorageNum);
List<Storage> selectByIds(@Param("storageIdList")List<Integer> storageIdList);
}
\ No newline at end of file
... ...
... ... @@ -52,8 +52,8 @@
#{item}
</foreach>
</select>
<update id="addStorageNum">
update storage set storage_num = storage_num + #{storageNum,jdbcType=INTEGER},
<update id="updateStorageNum">
update storage set storage_num = #{storageNum,jdbcType=INTEGER},
update_time = unix_timestamp()
where id = #{storageId,jdbcType=INTEGER} and storage_num = #{oldStorageNum,jdbcType=INTEGER}
</update>
... ...
... ... @@ -37,6 +37,6 @@ public class StorageNumEventsListener implements ApplicationListener<StorageNumE
long count = storagePrices.stream().filter(item -> item.getStatus() == 1).count(); // 只看可售状态的库存
storageMapper.addStorageNum(storage.getId(), (int)count, storage.getStorageNum());
storageMapper.updateStorageNum(storage.getId(), (int)count, storage.getStorageNum());
}
}
... ...
... ... @@ -501,7 +501,7 @@ public static void main(String[] args) {
if (n == 1) {
Storage storage = storageMapper.selectByPrimaryKey(sp.getStorageId());
if (storageMapper.addStorageNum(sp.getStorageId(), -1, storage.getStorageNum()) != 1) { // 防止并发修改,如果失败则发送一个spring事件
if (storageMapper.updateStorageNum(sp.getStorageId(), storage.getStorageNum() - 1, storage.getStorageNum()) != 1) { // 防止并发修改,如果失败则发送一个spring事件
applicationContext.publishEvent(new StorageNumEvent(sp.getStorageId()));
}
... ...