// 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