List<MainDataMd0006PO> listpo = BeanUtils.transferList(mainDataMd0006Params, MainDataMd0006PO.class); //查询 存在的--根据批次编码 List<MainDataMd0006PO> listup = mainDataMd0006Service.selectBatchIds(listpo); // 交集 (list1 & list2) 取list1 表的数据 List<MainDataMd0006PO> listupdate = listpo.stream().filter(item -> listup.stream().map(up -> up.getPOSID()).collect( Collectors.toList()).contains(item.getPOSID())).collect(Collectors.toList()); listupdate.stream().forEach(update -> listup.stream().filter(up -> Objects.equals(update.getPOSID(), up.getPOSID())). findAny().ifPresent(up -> update.setId(up.getId()))); // 差集 (list1 - list2) List<MainDataMd0006PO> listadd = listpo.stream().filter(item -> !listup.stream().map(up -> up.getPOSID()).collect( Collectors.toList()).contains(item.getPOSID())).collect(Collectors.toList());
更新多个字段示例
List<IrrigationPlanListDTO> irrigationPlanListDTOList=new ArrayList<>();
//赋值 irrigationTaskUniqueId irrigationPlanListDTOList.stream().forEach(update->irrigationTaskDOList.stream().filter( task->Objects.equals(update.getProcessId(),task.getProcessId()) ).findAny().ifPresent(task -> update.setIrrigationTaskUniqueId(task.getIrrigationTaskUniqueId()).setPlanUniqueId(task.getPlanUniqueId()) ));
更新多个字段时对应的实体类上面需要加注解 @Accessors
@Data @Accessors(chain = true) public class IrrigationPlanListDTO implements Serializable { /** * uniqueid */ private String planUniqueId; /** * 水肥灌溉计划名称 */ private String planName; /** * 计划状态,0=禁用,1=启用 */ private Integer status; /** * 任务uniqueid * */ private String irrigationTaskUniqueId; /** * 进程id * */ private String processId; /** * 计划下的总耗时 * */ private Long timeCost; /** * 计划下总次数 * */ private Integer totalCount; }