注意:使用@Builder注解时,要加上无参构造器,否则无法更新
@Override
@Transactional
public void saveManufacturerInfo(List<Manufacturer> manufacturerList) {
List<ManufacturerMap> codeNameMapping = manufacturerList.stream().map(item -> ManufacturerMap
.builder()
.deptcodeKyz(item.getDeptcodeKyz())
.name(item.getName())
.build()
).collect(Collectors.toList());
if (CollectionUtils.isEmpty(codeNameMapping)) {
return;
}
Map<String, Manufacturer> manufacturerMapping = this.baseMapper.listByCodeAndNameMap(codeNameMapping)
.stream().collect(Collectors.toMap(item -> item.getDeptcodeKyz() + item.getName(), Manufacturer -> Manufacturer));
List<Manufacturer> collect = codeNameMapping.stream().map(item -> {
String deptcodeKyz = item.getDeptcodeKyz();
String name = item.getName();
Manufacturer dbObj = manufacturerMapping.get(deptcodeKyz + name);
Date date = new Date();
if (Objects.isNull(dbObj)) {
return Manufacturer.builder()
.deptcodeKyz(deptcodeKyz)
.name(name)
.createTime(date)
.updateTime(date)
.build();
} else {
dbObj.setUpdateTime(date);
return dbObj;
}
}).collect(Collectors.toList());
this.saveOrUpdateBatch(collect, collect.size());
}
<select id="listByCodeAndNameMap" resultType="com.cars.ict.core.device.entity.Manufacturer">
SELECT
<include refid="Base_Column_List"/>
FROM manufacturer
WHERE( DEPTCODE_KYZ, name ) IN
<foreach collection="list" item="item" separator="," open="(" close=")">
( #{item.deptcodeKyz}, #{item.name} )
</foreach>
</select>
@TableName(value ="manufacturer")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Manufacturer implements Serializable {
/**
* 主键
*/
@TableId(type = IdType.UUID)
private String id;
/**
* 车站唯一编码
*/
private String deptcodeKyz;
/**
* 设备厂商
*/
private String name;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private Date createTime;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
标签:mybatisplus,name,collect,新增,更新,item,deptcodeKyz,private,String From: https://www.cnblogs.com/sensenh/p/17761284.html