@Authorize(action = Permission.ACTION_ADD) @PostMapping @ResponseStatus(HttpStatus.CREATED) @ApiOperation(value = "新增") default ResponseMessage<PK> add(@RequestBody M data) { E entity = modelToEntity(data, getService().createEntity()); //自动添加创建人和创建时间 if (entity instanceof RecordCreationEntity) { RecordCreationEntity creationEntity = (RecordCreationEntity) entity; creationEntity.setCreateTimeNow(); creationEntity.setCreatorId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } //修改人和修改时间 if (entity instanceof RecordModifierEntity) { RecordModifierEntity creationEntity = (RecordModifierEntity) entity; creationEntity.setModifyTimeNow(); creationEntity.setModifierId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } return ok(getService().insert(entity)); }
@Authorize(action = {Permission.ACTION_UPDATE, Permission.ACTION_ADD}, logical = Logical.AND) @PatchMapping @ApiOperation("新增或者修改") default ResponseMessage<PK> saveOrUpdate(@RequestBody M data) { E entity = modelToEntity(data, getService().createEntity()); //自动添加创建人和创建时间 if (entity instanceof RecordCreationEntity) { RecordCreationEntity creationEntity = (RecordCreationEntity) entity; creationEntity.setCreateTimeNow(); creationEntity.setCreatorId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } //修改人和修改时间 if (entity instanceof RecordModifierEntity) { RecordModifierEntity creationEntity = (RecordModifierEntity) entity; creationEntity.setModifyTimeNow(); creationEntity.setModifierId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } return ResponseMessage.ok(getService().saveOrUpdate(entity)); }
@Override public PK insert(E entity) { if (!StringUtils.isEmpty(entity.getId())) { if ((entity.getId() instanceof String) && !StringUtils.isEmpty(entity.getId())) { tryValidateProperty(entity.getId().toString().matches("[a-zA-Z0-9_\\-]+"), "id", "只能由数字,字母,下划线,和-组成"); } tryValidateProperty(selectByPk(entity.getId()) == null, "id", entity.getId() + "已存在"); } if (StringUtils.isEmpty(entity.getId()) && getIDGenerator() != null) { entity.setId(getIDGenerator().generate()); } if (entity instanceof RecordCreationEntity) { ((RecordCreationEntity) entity).setCreateTimeNow(); } tryValidate(entity, CreateGroup.class); getDao().insert(entity); return entity.getId(); }
@Authorize(action = Permission.ACTION_ADD) @PostMapping @ResponseStatus(HttpStatus.CREATED) @ApiOperation(value = "新增") default ResponseMessage<PK> add(@RequestBody M data) { E entity = modelToEntity(data, getService().createEntity()); //自动添加创建人和创建时间 if (entity instanceof RecordCreationEntity) { RecordCreationEntity creationEntity = (RecordCreationEntity) entity; creationEntity.setCreateTimeNow(); creationEntity.setCreatorId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } //修改人和修改时间 if (entity instanceof RecordModifierEntity) { RecordModifierEntity creationEntity = (RecordModifierEntity) entity; creationEntity.setModifyTimeNow(); creationEntity.setModifierId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } return ok(getService().insert(entity)); }
@Authorize(action = {Permission.ACTION_UPDATE, Permission.ACTION_ADD}, logical = Logical.AND) @PatchMapping @ApiOperation("新增或者修改") default ResponseMessage<PK> saveOrUpdate(@RequestBody M data) { E entity = modelToEntity(data, getService().createEntity()); //自动添加创建人和创建时间 if (entity instanceof RecordCreationEntity) { RecordCreationEntity creationEntity = (RecordCreationEntity) entity; creationEntity.setCreateTimeNow(); creationEntity.setCreatorId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } //修改人和修改时间 if (entity instanceof RecordModifierEntity) { RecordModifierEntity creationEntity = (RecordModifierEntity) entity; creationEntity.setModifyTimeNow(); creationEntity.setModifierId(Authentication.current() .map(Authentication::getUser) .map(User::getId) .orElse(null)); } return ResponseMessage.ok(getService().saveOrUpdate(entity)); }
@Override public PK insert(E entity) { if (!StringUtils.isEmpty(entity.getId())) { if ((entity.getId() instanceof String) && !StringUtils.isEmpty(entity.getId())) { tryValidateProperty(entity.getId().toString().matches("[a-zA-Z0-9_\\-]+"), "id", "只能由数字,字母,下划线,和-组成"); } tryValidateProperty(selectByPk(entity.getId()) == null, "id", entity.getId() + "已存在"); } if (StringUtils.isEmpty(entity.getId()) && getIDGenerator() != null) { entity.setId(getIDGenerator().generate()); } if (entity instanceof RecordCreationEntity) { ((RecordCreationEntity) entity).setCreateTimeNow(); } tryValidate(entity, CreateGroup.class); getDao().insert(entity); return entity.getId(); }