@Override public int updateByPk(PK pk, E entity) { Assert.notNull(pk, "primary key can not be null"); Assert.hasText(String.valueOf(pk), "primary key can not be null"); Assert.notNull(entity, "entity can not be null"); entity.setId(pk); tryValidate(entity, UpdateGroup.class); return createUpdate(entity) //如果是RecordCreationEntity则不修改creator_id和creator_time .when(entity instanceof RecordCreationEntity, update -> update.and().excludes(((RecordCreationEntity) entity).getCreatorIdProperty(), RecordCreationEntity.createTime)) .where(GenericEntity.id, pk) .exec(); }
@Override public E deleteByPk(PK pk) { E old = selectByPk(pk); if (old == null) { return null; } if (old instanceof LogicalDeleteEntity) { LogicalDeleteEntity deleteEntity = (LogicalDeleteEntity) old; deleteEntity.setDeleted(true); deleteEntity.setDeleteTime(System.currentTimeMillis()); createUpdate() .set(deleteEntity::getDeleted) .set(deleteEntity::getDeleteTime) .where(GenericEntity.id, pk) .exec(); } else { getDao().deleteByPk(pk); } return old; }
@Override public int updateByPk(PK pk, E entity) { Assert.notNull(pk, "primary key can not be null"); Assert.hasText(String.valueOf(pk), "primary key can not be null"); Assert.notNull(entity, "entity can not be null"); entity.setId(pk); tryValidate(entity, UpdateGroup.class); return createUpdate(entity) //如果是RecordCreationEntity则不修改creator_id和creator_time .when(entity instanceof RecordCreationEntity, update -> update.and().excludes(((RecordCreationEntity) entity).getCreatorIdProperty(), RecordCreationEntity.createTime)) .where(GenericEntity.id, pk) .exec(); }
@Override public E deleteByPk(PK pk) { E old = selectByPk(pk); if (old == null) { return null; } if (old instanceof LogicalDeleteEntity) { LogicalDeleteEntity deleteEntity = (LogicalDeleteEntity) old; deleteEntity.setDeleted(true); deleteEntity.setDeleteTime(System.currentTimeMillis()); createUpdate() .set(deleteEntity::getDeleted) .set(deleteEntity::getDeleteTime) .where(GenericEntity.id, pk) .exec(); } else { getDao().deleteByPk(pk); } return old; }