jdk1.8 lamba表达式使用


 // 1.8 赋空值的操作。
healthSystem.setOperatorName(Optional.ofNullable(adminManager.findOne(healthSystem.getOperatorId())).map(AdminBO::getUsername).orElse(""));

# 时间处理
healthSystem.setGmtDeleted(LocalDateTime.of(9999, 12, 31, 23, 59, 59));
healthSystem.setGmtCreated(LocalDateTime.now());

# 异常处理,空是ture 是false
Preconditions.checkArgument(healthSystemDO != null, "该健康制度不存在");
 错误提示 
 throw new ServiceException(ServiceErrorCode.ACCOUNT_DISABLES);
 
 
# list 循环 List<Long> orgIds  
  healthSystem.getOrgIds().forEach(orgId -> {
    HealthSystemOrgRelationBO healthSystemOrgRelationBO
     list对象取单个属性列表
    List<String> phoneList = list.stream().map(HrPersonDTO::getPhone).collect(Collectors.toList());


# 枚举类型
 healthSystem.setIsDraft(IsDraftedEnum.NO.code());                
 
#事务处理
  @Override
    @Transactional(rollbackFor = Exception.class)
    public void publish(HealthSystemBO healthSystem){


# 默认属性设置
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@AllArgsConstructor 加个全参的构造方法
@Slf4j  日志logger
@Validated 类上添加后在具体的参数上添加校验,
    @AssertFalse 校验false
    @AssertTrue 校验true
    @DecimalMax(value=,inclusive=) 小于等于value,
    inclusive=true,是小于等于
    @DecimalMin(value=,inclusive=) 与上类似
    @Max(value=) 小于等于value
    @Min(value=) 大于等于value
    @NotNull  检查Null
    @Past  检查日期
    @Pattern(regex=,flag=)  正则
    @Size(min=, max=)  字符串,集合,map限制大小
    @Validate 对po实体类进行校验
    
    
// 设置列表操作 获取所有权限
List<AdminRoleRelationDO> roleRelationList = adminRoleRelationMapper.listByUserId(userId);
List<Long> exitsIdList = roleRelationList.stream().map(AdminRoleRelationDO::getRoleId).collect(Collectors.toList());
List<Long> addIdList = roleIdList.stream().filter(roleId -> !exitsIdList.contains(roleId)).collect(Collectors.toList());
List<Long> delIdList = exitsIdList.stream().filter(roleId -> !roleIdList.contains(roleId)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(addIdList)) {
    addIdList.forEach(id -> {
        AdminRoleRelationDO addDO = new AdminRoleRelationDO();
        addDO.setId(idGenerator.deviationSnowflakeId());
        addDO.setAdminId(userId);
        addDO.setRoleId(id);
        addDO.setGmtCreated(LocalDateTime.now());
        addDO.setGmtModified(LocalDateTime.now());
        addDO.setIsDeleted(false);
        adminRoleRelationMapper.create(addDO);
    });
}
if (CollectionUtils.isNotEmpty(delIdList)) {
    List<Long> idList = roleRelationList.stream().filter(relation -> delIdList.contains(relation.getRoleId())).map(AdminRoleRelationDO::getId).collect(Collectors.toList());
    adminRoleRelationMapper.deleteByIds(idList);
}
        

// contains 和 containsAll区别
https://www.it610.com/article/1288345525191516160.htm
 contains:判断2集合是否全包含顺序也必须一样。
 contailsAll: 判断2集合第二个集合的所有元素是否在集合一中,有就true
        
        
        
        
        
        
        
        
        
        
        
        
        
        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值