package com.fdkankan.common.base; import java.io.Serializable; import java.util.LinkedHashMap; import java.util.List; public abstract class AbstractService implements IServiceOperations { protected abstract IOperations 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 list) { return getMapper().insertByBatch(list, this.getTableName()); } @Override public int update(List list) { return getMapper().update(list, this.getTableName()); } @Override public int updateByBatch(LinkedHashMap 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 condition) { String field = null; return this.getOne(condition, field, this.getTableName()); } @Override public T getOne(LinkedHashMap condition, String field) { return getMapper().getOne(condition, field, this.getTableName()); } @Override public int getCount(LinkedHashMap condition, String field) { return getMapper().getCount(condition, field, this.getTableName()); } @Override public List getList(LinkedHashMap 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 getAllList(LinkedHashMap condition) { return this.getAllList(condition, null); } @Override public List getAllList(LinkedHashMap 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 getList(int pageNo, int pageSize) { String order = null; return this.getList(pageNo, pageSize, order); } @Override public List getList(int pageNo, int pageSize, String order) { String field = null; return this.getList(pageNo, pageSize, order, field); } @Override public List getList(int pageNo, int pageSize, String order, String field) { LinkedHashMap condition = new LinkedHashMap(); return this.getList(condition, pageNo, pageSize, order, field); } @Override public List getList(LinkedHashMap condition, int pageNo, int pageSize) { String order = null; return this.getList(condition, pageNo, pageSize, order); } @Override public List getList(LinkedHashMap 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 list, String tableName) { return this.getMapper().insertByBatch(list, tableName); } @Override public int update(List list, String tableName) { return this.update(list, tableName); } @Override public int updateByBatch(LinkedHashMap 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 condition, String field, String tableName) { return this.getMapper().getOne(condition, field, tableName); } @Override public int getCount(LinkedHashMap condition, String field, String tableName) { return this.getMapper().getCount(condition, field, tableName); } @Override public List getList(LinkedHashMap condition, int offset, int limit, String order, String field, String tableName) { return this.getMapper().getList(condition, offset, limit, order, field, tableName); } }