fix: 更新无updateTime和updateBy,MP报错

This commit is contained in:
DataCall 2024-07-24 18:27:12 +08:00
parent 7338ac886e
commit 18d7fc918d
3 changed files with 12 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import com.ruoyi.wms.domain.vo.InventoryVo;
import com.ruoyi.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -15,5 +16,5 @@ import java.util.List;
*/
public interface InventoryMapper extends BaseMapperPlus<Inventory, InventoryVo> {
void updateQuantity(@Param("list") List<Inventory> updateList);
void updateQuantity(@Param("list") List<Inventory> updateList, @Param("updateTime") LocalDateTime updateTime, @Param("updateBy") String updateBy);
}

View file

@ -9,6 +9,7 @@ import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.satoken.utils.LoginHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.domain.bo.InventoryBo;
@ -18,6 +19,7 @@ import com.ruoyi.wms.mapper.InventoryMapper;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -116,10 +118,14 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
Map<String, Long> existMap = inventoryMapper.selectList().stream().collect(Collectors.toMap(keyFunction, Inventory::getId));
List<Inventory> addList = new LinkedList<>();
List<Inventory> updateList = new LinkedList<>();
LocalDateTime optDate = LocalDateTime.now();
String optUser = LoginHelper.getUsername();
validList.forEach(it -> {
Long inventoryId = existMap.get(keyFunction.apply(it));
if (inventoryId != null) {
it.setId(inventoryId);
it.setUpdateBy(optUser);
it.setUpdateTime(optDate);
updateList.add(it);
} else {
addList.add(it);
@ -129,7 +135,7 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
saveBatch(addList);
}
if (updateList.size() > 0) {
inventoryMapper.updateQuantity(updateList);
inventoryMapper.updateQuantity(updateList, optDate, optUser);
}
}

View file

@ -14,9 +14,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
end
)
-- ,
-- update_time = #{updateTime},
-- update_by = #{userId}
,
update_time = #{updateTime},
update_by = #{updateBy}
where id in
<foreach collection="list" open="(" separator="," close=")" item="it">
#{it.id}