123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- package com.fdkankan.common.base;
- import java.io.Serializable;
- import java.util.LinkedHashMap;
- import java.util.List;
- public abstract class AbstractService<T extends Serializable> implements IServiceOperations<T> {
- protected abstract IOperations<T> getMapper();
-
- protected String tableName = "";
- public abstract void setTableName(String tableName);
-
- protected String getTableName() {
- return this.tableName;
- }
-
- @Override
- public void insert(T entity) {
- getMapper().insert(entity, this.getTableName());
- }
- @Override
- public int insertByBatch(List<T> list) {
- return getMapper().insertByBatch(list, this.getTableName());
- }
- @Override
- public int update(List<T> list) {
- return getMapper().update(list, this.getTableName());
- }
-
- @Override
- public int updateByBatch(LinkedHashMap<String, String> condition, String field) {
- return getMapper().updateByBatch(condition, field, this.getTableName());
- }
- @Override
- public T getById(int id) {
- return getMapper().getById(id, this.getTableName());
- }
- @Override
- public T getOne(LinkedHashMap<String, String> condition) {
- String field = null;
- return this.getOne(condition, field, this.getTableName());
- }
- @Override
- public T getOne(LinkedHashMap<String, String> condition, String field) {
- return getMapper().getOne(condition, field, this.getTableName());
- }
- @Override
- public int getCount(LinkedHashMap<String, String> condition, String field) {
- return getMapper().getCount(condition, field, this.getTableName());
- }
- @Override
- public List<T> getList(LinkedHashMap<String, String> condition, int pageNo, int pageSize, String order, String field) {
- int offset = (pageNo - 1) * pageSize;
- int limit = pageSize;
- return getMapper().getList(condition, offset, limit, order, field, this.getTableName());
- }
-
- @Override
- public List<T> getAllList(LinkedHashMap<String, String> condition) {
- return this.getAllList(condition, null);
- }
-
- @Override
- public List<T> getAllList(LinkedHashMap<String, String> condition, String order) {
- if(order == null || order.trim().length() == 0) {
- order = null;
- }
- return getMapper().getList(condition, 0, 0, order, null, this.getTableName());
- }
- @Override
- public List<T> getList(int pageNo, int pageSize) {
- String order = null;
- return this.getList(pageNo, pageSize, order);
- }
- @Override
- public List<T> getList(int pageNo, int pageSize, String order) {
- String field = null;
- return this.getList(pageNo, pageSize, order, field);
- }
- @Override
- public List<T> getList(int pageNo, int pageSize, String order, String field) {
- LinkedHashMap<String, String> condition = new LinkedHashMap<String, String>();
- return this.getList(condition, pageNo, pageSize, order, field);
- }
- @Override
- public List<T> getList(LinkedHashMap<String, String> condition, int pageNo, int pageSize) {
- String order = null;
- return this.getList(condition, pageNo, pageSize, order);
- }
- @Override
- public List<T> getList(LinkedHashMap<String, String> condition, int pageNo, int pageSize, String order) {
- String field = null;
- return this.getList(condition, pageNo, pageSize, order, field);
- }
- @Override
- public int existTable(String tableName) {
- return getMapper().existTable(tableName);
- }
- @Override
- public int createTable(String tableName) {
- return getMapper().createTable(tableName);
- }
- // 以下暂时没有场景用到,留在这里,需要时候根据实际情况进行修改即可。
- @Override
- public void insert(T entity, String tableName) {
- this.getMapper().insert(entity, tableName);
- }
- @Override
- public int insertByBatch(List<T> list, String tableName) {
- return this.getMapper().insertByBatch(list, tableName);
- }
- @Override
- public int update(List<T> list, String tableName) {
- return this.update(list, tableName);
- }
-
- @Override
- public int updateByBatch(LinkedHashMap<String, String> condition, String field, String tableName) {
- return this.getMapper().updateByBatch(condition, field, this.getTableName());
- }
- @Override
- public T getById(int id, String tableName) {
- return this.getMapper().getById(id, tableName);
- }
- @Override
- public T getOne(LinkedHashMap<String, String> condition, String field, String tableName) {
- return this.getMapper().getOne(condition, field, tableName);
- }
- @Override
- public int getCount(LinkedHashMap<String, String> condition, String field, String tableName) {
- return this.getMapper().getCount(condition, field, tableName);
- }
- @Override
- public List<T> getList(LinkedHashMap<String, String> condition, int offset, int limit, String order, String field, String tableName) {
- return this.getMapper().getList(condition, offset, limit, order, field, tableName);
- }
- }
|