Skip to content

NicheToolkit/rice-toolkit

Repository files navigation

GitHub License Maven Central Nexus Release Nexus Snapshot Tests

Toolkit Usages

Maven Central Repository

Dependent & Environment

Spring Boot 2.7.18.RELEASE
Maven 3.6.3+
JDK 1.8

Wiki Reference

Wiki Reference: https://github.com/NicheToolkit/rice-toolkit/wiki

Instructions

Maven Usages

rice-toolkit-mybatis

  • Maven (pom.xml)
<dependency>
    <groupId>io.github.nichetoolkit</groupId>
    <artifactId>rice-toolkit-mybatis</artifactId>
    <version>1.1.1</version>
</dependency>

rice-toolkit-core

  • Maven (pom.xml)
<dependency>
    <groupId>io.github.nichetoolkit</groupId>
    <artifactId>rice-toolkit-core</artifactId>
    <version>1.1.1</version>
</dependency>

rice-toolkit-context

  • Maven (pom.xml)
<dependency>
    <groupId>io.github.nichetoolkit</groupId>
    <artifactId>rice-toolkit-context</artifactId>
    <version>1.1.1</version>
</dependency>

rice-toolkit-starter

  • Maven (pom.xml)
<dependency>
    <groupId>io.github.nichetoolkit</groupId>
    <artifactId>rice-toolkit-starter</artifactId>
    <version>1.1.1</version>
</dependency>

Configure Properties

bean configuration

  • prefix

nichetoolkit.rice.service

  • values
value type defaultValue description
unique-model Boolean false the switch of unique model check on rest service saving handle.
dynamic-table Boolean false the switch of dynamic table on rest service handle.
unique-name Boolean true the switch of unique name check on rest service saving handle.(model name must be unique)
nonnull-name Boolean true the switch of nonnull name check on rest service saving handle.(model name can not be null)
identity-invade Boolean false the switch of invade model identity on rest service saving handle.(the model id can be external input)
identity-check Boolean true the switch of model identity exist check on rest service updating handle.(the model of key not exist maybe to save when updating handle)
delete-mode DeleteMode remove the delete mode of data on rest service delete handle.(the logical delete implementation mode)
before-skip Boolean true the switch of skip before handle on rest service delete handle.
after-skip Boolean true the switch of skip after handle on rest service delete handle.
partition.query-size Integer 2000 the partition size of in sql usage on rest service query handle.(the size of sql param: in (p1,p2,p3...p2000))
partition.save-size Integer 500 the partition size of model on rest service save handle.
partition.delete-size Integer 1000 the partition size of in sql usage on rest service delete handle.(the size of sql param: in (p1,p2,p3...p1000))
delete.accurate-judge Boolean false the switch of remove data with accurate judge sign on rest service query handle.
delete.logic-mode LogicMode config the logic mode of data on rest service remove handle.(the logical remove implementation mode)
delete.config-mark ConfigMark number the config mode of data on rest service logic handle.
delete.auto-mark AutoMark identity the auto mode of data on rest service logic handle.
delete.unmark-value Object 1 the unmark of normal data when logical remove model.
delete.mark-value Object 2 the mark of delete data when logical remove model.
  • properties
nichetoolkit.rice.service.unique-model=false
nichetoolkit.rice.service.dynamic-table=false
nichetoolkit.rice.service.identity-invade=false
nichetoolkit.rice.service.identity-check=true
nichetoolkit.rice.service.unique-name=true
nichetoolkit.rice.service.nonnull-name=true
nichetoolkit.rice.service.partition.query-size=2000
nichetoolkit.rice.service.partition.save-size=500
nichetoolkit.rice.service.partition.delete-size=1000
nichetoolkit.rice.service.before-skip=true
nichetoolkit.rice.service.after-skip=true
nichetoolkit.rice.service.delete-mode=remove
nichetoolkit.rice.service.delete.logic-mode=config
nichetoolkit.rice.service.delete.auto-mark=identity
nichetoolkit.rice.service.delete.config-mark=number
nichetoolkit.rice.service.delete.accurate-judge=true
nichetoolkit.rice.service.delete.unmark-value=
nichetoolkit.rice.service.delete.mark-value=

login configuration

  • prefix

nichetoolkit.rice.login

  • values
value type defaultValue description
enabled Boolean false the switch of login configuration.
token-prefixes String[] Bearer the token prefixes of login configuration.
skip-urls String[] the skip urls of login configuration.
token-headers String[] Authorization the token headers of login configuration.
token-expiration Integer 1800 the token expiration of login configuration.
token-time-unit TimeUnit seconds the token time unit of login configuration.
access-token-header String Access-Token the access token header of login configuration.
access-auth-header String Access-Auth the access auth header of login configuration.
  • properties
nichetoolkit.rice.login.enabled=false
nichetoolkit.rice.login.token-prefixes=Bearer
nichetoolkit.rice.login.skip-urls=
nichetoolkit.rice.login.token-headers=Authorization
nichetoolkit.rice.login.token-expiration=1800
nichetoolkit.rice.login.token-time-unit=seconds
nichetoolkit.rice.login.access-token-header=Access-Token
nichetoolkit.rice.login.access-auth-header=Access-Auth

serialize configuration

  • prefix

nichetoolkit.rice.serialize

  • values
value type defaultValue description
big-decimal-format String 0.00 the big decimal format of serialize configuration.
  • properties
nichetoolkit.rice.serialize.big-decimal-format=0.00

Model & Entity & Filter

model

the model is used on service or controller handle.

name typeParams description
SaveModel the model is used to keep SaveType field.
LogicModel the model is used to keep logic field.
OperateModel the model is used to keep OperateType field.
TimeModel the model is used to keep createTime and updateTime field.
IdModel <I> the model is used to keep id field,and the id type can be any object.
InfoModel <I> the model is used to keep name and description fields.
DefaultIdModel <M extends DefaultIdModel<M,E,I>,E extends DefaultIdEntity<E,M,I>,I> the children models of DefaultIdModel must be implement the toEntity() method,and the id type can be any object.
DefaultInfoModel <M extends DefaultInfoModel<M, E, I>, E extends DefaultInfoEntity<E, M, I>, I> the children models of DefaultInfoModel must be implement the toEntity() method,and the id type can be any object.
RestIdModel <M extends RestIdModel<M, E>, E extends RestIdEntity<E, M>> the children models of RestIdModel must be implement the toEntity() method,and the id type is default String.
RestInfoModel <M extends RestInfoModel<M, E>, E extends RestInfoEntity<E, M>> the children models of RestInfoModel must be implement the toEntity() method,and the id type is default String.
  • examples
@Data
public class SimpleModel extends RestInfoModel<SimpleModel, SimpleEntity> {
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date time;

    public SimpleModel() {
    }

    public SimpleModel(String id) {
        super(id);
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Override
    public SimpleEntity toEntity() {
        SimpleEntity entity = new SimpleEntity();
        entity.setId(this.getId());
        entity.setName(this.getName());
        entity.setDescription(this.getDescription());
        entity.setTime(this.getTime());
        return entity;
    }
}

entity

the entity is used to keep fields on mapper handle.

name typeParams description
LogicEntity the entity is used to keep logic field.
OperateEntity the entity is used to keep operate field.
TimeEntity the entity is used to keep createTime and updateTime fields.
IdEntity <I> the entity is used to keep id field,and the id type can be any object.
InfoEntity <I> the entity is used to keep name and description fields.
DefaultIdEntity <E extends DefaultIdEntity<E,M,I>, M extends DefaultIdModel<M,E,I>,I> the children entities of DefaultIdEntity must be implement the toModel() method,and the id type can be any object.
DefaultInfoEntity <E extends DefaultInfoEntity<E,M,I>,M extends DefaultInfoModel<M,E,I>,I> the children entities of DefaultInfoEntity must be implement the toModel() method,and the id type can be any object.
RestIdEntity <E extends RestIdEntity<E,M>,M extends RestIdModel<M,E>> the children entities of RestIdEntity must be implement the toModel() method,and the id type is default String.
RestInfoEntity <E extends RestInfoEntity<E, M>, M extends RestInfoModel<M, E>> the children entities of RestInfoEntity must be implement the toModel() method,and the id type is default String.
  • examples
@Data
public class SimpleEntity extends RestInfoEntity<SimpleEntity, SimpleModel> {

    private Date time;

    public SimpleEntity() {
    }

    public SimpleEntity(String id) {
        super(id);
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Override
    public SimpleModel toModel() {
        SimpleModel model = new SimpleModel();
        model.setId(this.getId());
        model.setName(this.getName());
        model.setDescription(this.getDescription());
        model.setTime(this.getTime());
        return entity;
    }

}

filter

the filter is used to receive query fields on service or controller handle.

name typeParams description
PageFilter the filter is used to receive pageNum and pageSize fields.(the loadLastPage is used to load the last page data of query handle)
SortFilter the filter is used to receive sorts field.(the RestSort is used to sort the data of query handle)
OperateFilter the filter is used to receive operate and operates fields.(the remove is used to load the logical delete data of query handle)
TableFilter <K> the filter is used to receive tablekey field,and the tablekey type can be any object.(the tablekey is used to load the data of query handle on dynamic table )
IdFilter <I, K> the filter is used to receive id and ids fields.and the id type can be any object.
TimeFilter <I, K> the filter is used to receive startTime and endTime fields.
JsonbFilter <I, K> the filter is used to receive contrastsrangesequals and contains fields.(the ContrastRuleRangeRuleEqualRule and ContainRule is used to filter the jsonb data of query handle)
NameFilter <I, K> the filter is used to receive name and names fields.
DefaultFilter <I, K> the children filters of DefaultFilter can build SQL with toRemoveSql() and toQuerySql() methods.
RestFilter the id and tablekeytype is default String.
  • examples
public class SimpleFilter extends RestFilter {
}

Advice & Mapper & Service

Advice

the advice is used to handle the models or entities on service.

name typeParams methods description
AlertAdvice <I> beforeAlert(I id) the advice is used to handle alert and alertAll methods.
beforeAlertAll(Collection<I> idList)
afterAlert(I id)
afterAlertAll(Collection<I> idList)
DeleteAdvice <E extends RestId<I>,I> beforeDelete(E entity) the advice is used to handle delete and deleteAll methods.
beforeDeleteAll(Collection<E> entityList)
afterDelete(E entity)
afterDeleteAll(Collection<E> entityList)
OperateAdvice <E extends RestId<I>,I> beforeOperate(E entity) the advice is used to handle operate and operateAll methods.
beforeOperateAll(Collection<E> entityList)
afterOperate(E entity)
afterOperateAll(Collection<E> entityList)
RemoveAdvice <E extends RestId<I>,I> beforeRemove(E entity) the advice is used to handle remove and removeAll methods.
beforeRemoveAll(Collection<E> entityList)
afterRemove(E entity)
afterRemoveAll(Collection<E> entityList)
SaveAdvice <M extends RestId<I>,I> beforeCreate(M model) the advice is used to handle createupdatesave and saveAll methods.
beforeUpdate(M model)
beforeSave(M model)
beforeSaveAll(Collection<M> modelList)
afterCreate(M model)
afterUpdate(M model)
afterSave(M model)
afterSaveAll(Collection<M> modelList)
BuilderAdvice <M extends RestId<I>, E extends RestId<I>,I> buildEntity(M model, E entity, Object... idArray) the advice is used to handle buildEntitybuildEntityListbuildModel and buildModelList methods.
buildEntityList(Collection<M> modelList, List<E> entityList, Object... idArray)
buildModel(E entity, M model, Boolean... isLoadArray)
buildModelList(Collection<E> entityList, List<M> modelList, Boolean... isLoadArray)
MutateAdvice <M extends RestId<I>, E extends RestId<I>,I> mutateEntity(E entity, Boolean... isLoadArray) the advice is used to handle mutateEntitymutateEntityListmutateModel and mutateModelList methods.
mutateEntityList(List<E> entityList, ConsumerActuator<E> actuator, Boolean... isLoadArray)
mutateModel(M model, Object... idArray)
mutateModelList(List<M> modelList, ConsumerActuator<M> actuator, Object... idArray)
TablenameAdvice <M extends RestId<I>, I, K> resolveTablename(K tablekey) the advice is used to handle resolveTablename method.
resolveTablename(K tablekey, M model)
resolveTablename(K tablekey, Collection<M> modelList)
FilterAdvice <F extends IdFilter<I, K>, I, K> queryWhereSql(F filter) the advice is used to handle filter build SQLmethods.
deleteWhereSql(F filter)
removeWhereSql(F filter)
operateWhereSql(F filter)
findLoadArray(F filter)
queryLoadArray(F filter)
fieldArray(F filter)
tablekey(F filter)
* examples
@Service
public class SimpleServiceImpl extends RestInfoService<SimpleModel, SimpleEntity, SimpleFilter> implements SimpleService {

    @Override
    protected void optionalInit(@NonNull SimpleModel model) throws RestException {
        model.setTime(Optional.ofNullable(model.getTime()).orElse(new Date()));
    }

    @Override
    public String queryWhereSql(SimpleFilter filter) throws RestException {
        return filter.toTimeSql("create_time").toNameSql("name").toQuerySql(this, "logic").addSorts("id").toIdSql().toSql();
    }
}

Mapper

  • default mapper
name typeParams methods description
AlertMapper <S,I> alertById(@Param("id") I id, @Param("status") S status) the mapper is used to handle alert and alertAll methods.
alertDynamicById(@Param("tablename") String tablename, @Param("id") I id, @Param("status") S status)
alertAll(@Param("idList") Collection<I> idList, @Param("status") S status)
alertDynamicAll(@Param("tablename") String tablename, @Param("idList") Collection<I> idList, @Param("status") S status)
DeleteMapper <I> deleteById(@Param("id") I id) the mapper is used to handle delete and deleteAll methods.
deleteDynamicById(@Param("tablename") String tablename, @Param("id") I id)
deleteAll(@Param("idList") Collection<I> idList)
deleteDynamicAll(@Param("tablename") String tablename, @Param("idList") Collection<I> idList)
deleteAllByWhere(@Param("whereSql") String whereSql)
deleteDynamicAllByWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql)
OperateMapper <I> operateById(@Param("id") I id, @Param("operate") Integer operate) the mapper is used to handle operate and operateAll methods.
operateDynamicById(@Param("tablename") String tablename, @Param("id") I id, @Param("operate") Integer operate)
operateAll(@Param("idList") Collection<I> idList, @Param("operate") Integer operate)
operateDynamicAll(@Param("tablename") String tablename, @Param("idList") Collection<I> idList, @Param("operate") Integer operate)
operateAllByWhere(@Param("whereSql") String whereSql, @Param("operate") Integer operate)
operateDynamicAllByWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("operate") Integer operate)
RemoveMapper <I> removeById(@Param("id") I id, @Param("logic") String logic) the mapper is used to handle remove and removeAll methods.
removeDynamicById(@Param("tablename") String tablename, @Param("id") I id, @Param("logic") String logic)
removeAll(@Param("idList") Collection<I> idList, @Param("logic") String logic)
removeDynamicAll(@Param("tablename") String tablename, @Param("idList") Collection<I> idList, @Param("logic") String logic)
removeAllByWhere(@Param("whereSql") String whereSql, @Param("logic") String logic)
removeDynamicAllByWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql,@Param("logic") String logic)
SaveMapper <E extends RestId<I>,I> save(@Param("entity") E entity) the mapper is used to handle save and saveAll methods.
saveDynamic(@Param("tablename") String tablename, @Param("entity") E entity)
saveAll(@Param("entityList") Collection<E> entityList)
saveDynamicAll(@Param("tablename") String tablename, @Param("entityList") Collection<E> entityList)
FindMapper <E extends RestId<I>,I> findById(@Param("id") I id) the mapper is used to handle find and findAll methods.
findDynamicById(@Param("tablename") String tablename, @Param("id") I id)
findAll(@Param("idList") Collection<I> idList)
findDynamicAll(@Param("tablename") String tablename, @Param("idList") Collection<I> idList)
findAllByWhere(@Param("whereSql") String whereSql)
findDynamicAllByWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql)
SuperMapper <E extends RestId<I>,I> the mapper is default super mapper.
InfoMapper <E extends RestId<I>,I> findByName(@Param("name") String name, @Param("logic") String logic) the mapper is used to handle find and findAll methods.
findDynamicByName(@Param("tablename") String tablename, @Param("name") String name, @Param("logic") String logic)
findByNameAndNotId(@Param("name") String name, @Param("id") I id, @Param("logic") String logic)
findDynamicByNameAndNotId(@Param("tablename") String tablename, @Param("name") String name, @Param("id") I id, @Param("logic") String logic)
findByEntity(@Param("entity") E entity, @Param("logic") String logic)
findDynamicByEntity(@Param("tablename") String tablename, @Param("entity") E entity, @Param("logic") String logic)
findByEntityAndNotId(@Param("entity") E entity, @Param("id") I id, @Param("logic") String logic)
findDynamicByEntityAndNotId(@Param("tablename") String tablename, @Param("entity") E entity, @Param("id") I id, @Param("logic") String logic)
  • link mapper
name typeParams methods description
DeleteLinkMapper <L, I> deleteByLinkId(@Param("linkId") L linkId) the mapper is used to handle deleteByLinkId and deleteAllByLinkIds methods.
deleteDynamicByLinkId(@Param("tablename") String tablename, @Param("linkId") L linkId)
deleteAllByLinkIds(@Param("linkIdList") Collection<L> linkIdList)
deleteDynamicAllByLinkIds(@Param("tablename") String tablename, @Param("linkIdList") Collection<L> linkIdList)
OperateLinkMapper <L, I> operateByLinkId(@Param("linkId") L linkId, @Param("operate") Integer operate) the mapper is used to handle operateByLinkId and operateAllByLinkIds methods.
operateDynamicByLinkId(@Param("tablename") String tablename, @Param("linkId") L linkId, @Param("operate") Integer operate)
operateAllByLinkIds(@Param("linkIdList") Collection<L> linkIdList, @Param("operate") Integer operate)
operateDynamicAllByLinkIds(@Param("tablename") String tablename, @Param("linkIdList") Collection<L> linkIdList, @Param("operate") Integer operate)
RemoveLinkMapper <L, I> removeByLinkId(@Param("linkId") L linkId, @Param("logic") String logic) the mapper is used to handle removeByLinkId and removeAllByLinkIds methods.
removeDynamicByLinkId(@Param("tablename") String tablename, @Param("linkId") L linkId, @Param("logic") String logic)
removeAllByLinkIds(@Param("linkIdList") Collection<L> linkIdList, @Param("logic") String logic)
removeDynamicAllByLinkIds(@Param("tablename") String tablename, @Param("linkIdList") Collection<L> linkIdList, @Param("logic") String logic)
AlertLinkMapper <L, S, I> alertByLinkId(@Param("linkId") L linkId, @Param("status") S status) the mapper is used to handle alertByLinkId and alertByLinkIds methods.
alertDynamicByLinkId(@Param("tablename") String tablename, @Param("linkId") L linkId, @Param("status") S status)
alertAllByLinkIds(@Param("linkIdList") Collection<L> linkIdList, @Param("status") S status)
alertDynamicAllByLinkIds(@Param("tablename") String tablename, @Param("linkIdList") Collection<L> linkIdList, @Param("status") S status)
  • native mapper
name typeParams methods description
FindLoadMapper <E extends RestId<I>, I> findByIdLoad(@Param("id") I id, @Param("loadParams") Boolean... loadParams) the mapper is used to handle findByIdLoad and findAllLoad methods.
findDynamicByIdLoad(@Param("tablename") String tablename, @Param("id") I id, @Param("loadParams") Boolean... loadParams)
findAllLoad(@Param("idList") Collection<I> idList, @Param("loadParams") Boolean... loadParams)
findDynamicAllLoad(@Param("tablename") String tablename, @Param("idList") Collection<I> idList, @Param("loadParams") Boolean... loadParams)
FilterLoadMapper <E extends RestId<I>, I> findAllByLoadWhere(@Param("whereSql") String whereSql, @Param("loadParams") Boolean... loadParams) the mapper is used to handle findAllByLoadWhere methods.
findDynamicAllByLoadWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("loadParams") Boolean... loadParams)
LinkLoadMapper <E extends RestId<I>, L, I> findByLinkIdLoad(@Param("linkId") L linkId, @Param("loadParams") Boolean... loadParams) the mapper is used to handle findByLinkIdLoad and findByLinkIdsLoad methods.
findDynamicByLinkIdLoad(@Param("tablename") String tablename, @Param("linkId") L linkId, @Param("loadParams") Boolean... loadParams)
findAllByLinkIdsLoad(@Param("linkIdList") Collection<L> linkIdList, @Param("loadParams") Boolean... loadParams)
findDynamicAllByLinkIdsLoad(@Param("tablename") String tablename, @Param("linkIdList") Collection<L> linkIdList, @Param("loadParams") Boolean... loadParams)
NameLoadMapper <E extends RestId<I>, I> findByNameLoad(@Param("name") String name,@Param("logic") String logic, @Param("loadParams") Boolean... loadParams) the mapper is used to handle findByNameLoad methods.
findDynamicByNameLoad(@Param("tablename") String tablename, @Param("name") String name, @Param("logic") String logic, @Param("loadParams") Boolean... loadParams)
FindFilterMapper <E extends RestId<I<, F extends IdFilter<I, K<, I, K< findAllByFilterWhere(@Param("whereSql") String whereSql, @Param("filter") F filter) the mapper is used to handle findAllByFilterWhere methods.
findDynamicAllByFilterWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("filter") F filter)
DeleteFilterMapper <E extends RestId<I<, F extends IdFilter<I, K<, I, K< deleteAllByFilterWhere(@Param("whereSql") String whereSql, @Param("filter") F filter) the mapper is used to handle deleteAllByFilterWhere methods.
deleteDynamicAllByFilterWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("filter") F filter)
RemoveFilterMapper <E extends RestId<I<, F extends IdFilter<I, K<, I, K< removeAllByFilterWhere(@Param("whereSql") String whereSql, @Param("filter") F filter, @Param("logic") String logic) the mapper is used to handle removeAllByFilterWhere methods.
removeDynamicAllByFilterWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("filter") F filter, @Param("logic") String logic)
OperateFilterMapper <E extends RestId<I<, F extends IdFilter<I, K<, I, K< operateAllByFilterWhere(@Param("whereSql") String whereSql, @Param("filter") F filter, @Param("operate") Integer operate) the mapper is used to handle operateAllByFilterWhere methods.
operateDynamicAllByFilterWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("filter") F filter, @Param("operate") Integer operate)
AlertFilterMapper <E extends RestId<I<, F extends IdFilter<I, K<, S, I, K< alertAllByFilterWhere(@Param("whereSql") String whereSql, @Param("filter") F filter, @Param("status") S status) the mapper is used to handle alertAllByFilterWhere methods.
alertDynamicAllByFilterWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("filter") F filter, @Param("status") S status)
FindFieldMapper <E extends RestId<I>, I> findAllByFieldWhere(@Param("whereSql") String whereSql, @Param("fieldParams") String... fieldParams) the mapper is used to handle findAllByFieldWhere methods.
findDynamicAllByFieldWhere(@Param("tablename") String tablename, @Param("whereSql") String whereSql, @Param("fieldParams") String... fieldParams)
  • examples
@Component
public interface SimpleMapper extends RestInfoMapper<SimpleEntity>, Mapper<SimpleEntity, String> {
}

Service

  • default service
name typeParams methods description
AlertService <I> alertAll(Collection<I> idList, RestKey<Integer> keyType) the service is used to handle alert and alertAll methods.
alertAll(String tablekey, Collection<I> idList, RestKey<Integer> keyType)
alertById(I id, RestKey<Integer> keyType)
alertById(String tablekey, I id, RestKey<Integer> keyType)
DeleteService <I,K> deleteAll(Collection<I> idList) the service is used to handle delete and deleteAll methods.
deleteAll(K tablekey, Collection<I> idList)
deleteById(I id)
deleteById(K tablekey, I id)
OperateService <I,K> operateAll(Collection<I> idList, OperateType operateType) the service is used to handle operate and operateAll methods.
operateAll(K tablekey, Collection<I> idList, OperateType operateType)
operateById(I id, OperateType operateType)
operateById(K tablekey, I id, OperateType operateType)
RemoveService <I,K> removeAll(Collection<I> idList) the service is used to handle remove and removeAll methods.
removeAll(K tablekey, Collection<I> idList)
removeById(I id)
removeById(K tablekey, I id)
NameService <M extends RestId<I>, I, K> queryByName(String name, Boolean... isLoadArray) the service is used to handle query methods.
queryByName(K tablekey, String name, Boolean... isLoadArray)
SingleService <M extends RestId<I>, I, K> create(M model, Object... idArray) the service is used to handle create and update methods.
create(K tablekey, M model, Object... idArray)
update(M model, Object... idArray)
update(K tablekey, M model, Object... idArray)
SaveService <M extends RestId<I>, I, K> save(M model, Object... idArray) the service is used to handle save and saveAll methods.
save(K tablekey, M model, Object... idArray)
saveAll(Collection<M> modelList, Object... idArray)
saveAll(K tablekey, Collection<M> modelList, Object... idArray)
QueryService <M extends RestId<I>, I, K> queryAll(Collection<I> idList, Boolean... isLoadArray) the service is used to handle query and queryAll methods.
queryAll(K tablekey, Collection<I> idList, Boolean... isLoadArray)
queryById(I id, Boolean... isLoadArray)
queryById(K tablekey, I id, Boolean... isLoadArray)
FilterService <M extends RestId<I>, F extends IdFilter<I,K>,I,K> queryAllWithFilter(F filter) the service is used to handle queryAlldeleteAllremoveAll and operateAll methods.
deleteAllWithFilter(F filter)
removeAllWithFilter(F filter)
operateAllWithFilter(F filter)
SuperService <M extends RestId<I>, E extends RestId<I>, F extends IdFilter<I, K>, I, K> the service is default super service.
InfoService <M extends InfoModel<I>, E extends InfoEntity<I>, F extends IdFilter<I, K>, I, K> the service is default info service.
  • extend service
name typeParams methods description
OptionalService <M extends RestId<I>, F extends IdFilter<I, K>, I, K> optional(@NonNull M model) the service is used to handle optional and exist methods.
existById(I id)
existById(K tablekey, I id)
optionalQueryFilter(F filter)
optionalDeleteFilter(F filter)
optionalRemoveFilter(F filter)
optionalOperateFilter(F filter)
OperateLinkService <I> operateAllByLinkIds(Collection<I> linkIdList, OperateType operateType) the service is used to handle operate and operateAll methods.
operateAllByLinkIds(String tablekey, Collection<I> linkIdList, OperateType operateType)
operateByLinkId(I linkId, OperateType operateType)
operateByLinkId(String tablekey, I linkId, OperateType operateType)
DeleteLinkService <I> deleteAllByLinkIds(Collection<I> linkIdList) the service is used to handle delete and deleteAll methods.
deleteAllByLinkIds(String tablekey, Collection<I> linkIdList)
deleteByLinkId(I linkId)
deleteByLinkId(String tablekey, I linkId)
RemoveLinkService <I, K> removeAllByLinkIds(Collection<I> linkIdList) the service is used to handle remove and removeAll methods.
removeAllByLinkIds(K tablekey, Collection<I> linkIdList)
removeByLinkId(I linkId)
removeByLinkId(K tablekey, I linkId)
AlertFieldService <I> alertFieldAll(Collection<I> idList, String field, RestKey<Integer> keyType) the service is used to handle alert and alertAll methods.
alertFieldAll(String tablekey, Collection<I> idList, String field, RestKey<Integer> keyType)
alertFieldById(I id, String field, RestKey<Integer> keyType)
alertFieldById(String tablekey, I id, String field, RestKey<Integer> keyType)
  • id & info service
name typeParams description
DefaultIdService <M extends DefaultIdModel<M, E, I>, E extends DefaultIdEntity<E, M, I>, F extends DefaultFilter<I, K>, I, K> the service is abstract id service, the id and tablekey type can be any object.
DefaultInfoService <M extends DefaultInfoModel<M, E, I>, E extends DefaultInfoEntity<E, M, I>, F extends DefaultFilter<I, K>, I, K> the service is abstract info service, the id and tablekey type can be any object.
RestIdService <M extends RestIdModel<M, E>, E extends RestIdEntity<E, M>, F extends RestFilter> the service is abstract id service, the id and tablekey type is default String.
RestInfoService <M extends RestInfoModel<M, E>, E extends RestInfoEntity<E, M>, F extends RestFilter> the service is abstract info service, the id and tablekey type is default String.
  • examples
public interface SimpleService extends FilterService<SimpleModel, SimpleFilter, String, String>, SingleService<SimpleModel, String, String> {
}

Custom Identity Resolver Usages

  • identity for String type Resolver examples
@Component
public class DefaultStringIdResolver implements RestIdResolver<String> {

    @Override
    public <M extends RestId<String>> String resolveId(M model) throws RestException {
        return IdentityUtils.generateString();
    }
}

Stereotype & Annotation

  • default annotation
annotation target description
RestService ElementType.TYPE the annotation is used to annotate subclass of super service.
RestSkip ElementType.METHODElementType.TYPE the annotation is used to annotate controller or method that need to skip login related handle.
RestLogin ElementType.METHOD the annotation is used to annotate method that need to generate authentication information for login.
RestCheck ElementType.METHOD the annotation is used to annotate method that need to check token prefixes for login.
RestAuth ElementType.METHOD the annotation is used to annotate method that need to check auth code for login.
RestPended ElementType.METHOD the annotation is used to annotate method that need to precheck authentication information for login.
RestLogout ElementType.METHOD the annotation is used to annotate method that need to discard for login.
RestUser ElementType.PARAMETER the annotation is used to annotate parameter that need to inject user information of login.
  • examples
@Slf4j
@CrossOrigin
@RestController
@RestNotelog(loggingKey = "login", notelog = "login controller log")
@RequestMapping("/rest")
public class LoginController {

    private final LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @RestLogin
    @PostMapping("/login/password")
    @RestUserlog(loggingType = LoggingType.USER_LOGIN, userlog = "password login")
    public RestResult<UserModel> loginWithPassword(RestMap restMap, @RequestBody LoginRequest loginRequest) throws RestException {
        UserModel user = loginService.loginWithPassword(loginRequest);
        return buildLoginResult(restMap, user);
    }

    @GetMapping("/logout")
    @RestUserlog(loggingType = LoggingType.USER_LOGOUT, userlog = "user logout")
    public RestResult<?> logout() throws Exception {
        return RestResult.success();
    }

    private RestResult<UserModel> buildLoginResult(RestMap restMap, UserModel user) {
        restMap.put(UserModel.LOGIN_USER_INFO, JsonUtils.parseJson(user));
        restMap.put(UserModel.LOGIN_USER_ID, user.getId());
        return RestResult.success(user);
    }

}
  • http request
POST http://localhost:8080/rest/login/password
Content-Type: application/json

{
  "account": "testUser",
  "password": "123456"
}

> {%
client.global.set("auth_token", response.body.data.token);
%}

###

GET http://localhost:8080/rest/info
Authorization: Bearer {{auth_token}}

###

GET http://localhost:8080/rest/logout
Authorization: Bearer {{auth_token}}

###

Custom Purview

  • custom RestPurview annotation
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface RestPurview {

    String key() default "";

    String[] keys() default {};

    long value() default 0L;

    long[] values() default {};

    PurviewType purview() default PurviewType.PURVIEW_ALL;

    PurviewType[] purviews() default {};

    final class Purview {

        public static List<String> keys(@NonNull RestPurview purview) throws RestException {
            Set<String> keySet = new HashSet<>();
            OptionalUtils.ofEmptyable(purview.key()).ifEmptyPresent(keySet::add);
            OptionalUtils.ofEmptyable(purview.keys()).ifEmptyPresent(keys -> keySet.addAll(Arrays.asList(keys)));
            OptionalUtils.ofNullable(purview.purview()).nullFlatMap(value -> OptionalUtils.ofEmptyable(value.getKey())).emptyMap(keySet::add);
            OptionalUtils.ofNullable(purview.purviews()).ifNullPresent(values -> RestStream.stream(values).forEach(value -> OptionalUtils.ofNullable(value).nullFlatMap(module -> OptionalUtils.ofEmptyable(module.getKey())).emptyMap(keySet::add)));
            return new ArrayList<>(keySet);
        }

        public static List<Long> values(@NonNull RestPurview purview) throws RestException {
            Set<Long> valueSet = new HashSet<>();
            OptionalUtils.ofEmptyable(purview.value()).ifEmptyPresent(valueSet::add);
            OptionalUtils.ofEmptyable(purview.values()).ifEmptyPresent(values -> Arrays.stream(values).forEach(valueSet::add));
            OptionalUtils.ofNullable(purview.purview()).nullFlatMap(value -> OptionalUtils.ofEmptyable(value.getValue())).emptyMap(valueSet::add);
            OptionalUtils.ofNullable(purview.purviews()).ifNullPresent(values -> RestStream.stream(values).forEach(value -> OptionalUtils.ofNullable(value).nullFlatMap(module -> OptionalUtils.ofEmptyable(module.getValue())).emptyMap(valueSet::add)));
            return new ArrayList<>(valueSet);
        }

    }
}
  • custom PurviewAdvice advice
@Slf4j
@Component
public class PurviewAdvice implements DefaultAdvice<RestPurview> {

    private final TokenService tokenService;

    @Autowired
    public PurviewAdvice(TokenService tokenService) {
        this.tokenService = tokenService;
    }

    @Override
    public int order() {
        return 98;
    }

    @Override
    public void doAnnotationHandle(RestHttpRequest request, HttpServletResponse response, HandlerMethod handlerMethod, RestPurview purview) throws RestException {
        UserModel userModel = tokenService.resolveUserInfo(request);
        /* custom user purview */
        userModel.setPurviewType(PurviewType.PURVIEW_1);
        /* custom key mode check*/
        purviewKeysCheck(userModel, RestPurview.Purview.keys(purview));
        /* custom value mode check*/
        purviewValuesCheck(userModel, RestPurview.Purview.values(purview));
    }

    private void purviewKeysCheck(UserModel userModel, List<String> purviewKeys) throws RestException {
        PurviewType purviewType = userModel.getPurviewType();
        if (GeneralUtils.isNotEmpty(purviewKeys)) {
            OptionalUtils.ofEmptyable(purviewType).emptyElseThrow(TokenPermissionException::new);
            String purviewTypeKey = purviewType.getKey();
            OptionalUtils.falseable(purviewKeys.contains(purviewTypeKey), TokenPermissionException::new);
        }
    }

    private void purviewValuesCheck(UserModel userModel, List<Long> purviewValues) throws RestException {
        PurviewType purviewType = userModel.getPurviewType();
        if (GeneralUtils.isNotEmpty(purviewValues)) {
            OptionalUtils.ofEmptyable(purviewType).emptyElseThrow(TokenPermissionException::new);
            Long annexValue = RestReckon.annexValue(purviewValues);
            Long value = purviewType.getValue();
            OptionalUtils.falseable(RestReckon.reachValue(annexValue, value), TokenPermissionException::new);
        }
    }
}
  • controller RestPurview usages
@Slf4j
@CrossOrigin
@RestController
@RestNotelog(loggingKey = "login", notelog = "login controller log")
@RequestMapping("/rest/purview")
public class PurviewController {

    @GetMapping("/test")
    @RestPurview(purview = PurviewType.PURVIEW_1)
    @RestUserlog(loggingType = LoggingType.TEST, userlog = "purview test")
    public RestResult<?> test() throws RestException {
        return RestResult.success("the purview test successfully");
    }

}

Test Example

rice-toolkit-example

License

Apache License

Dependencies

Rest-toolkit

Spring Boot

Lombok

PageHelper

About

the java toolkit of rice widget

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages