|
@@ -21,6 +21,7 @@ import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.baomidou.framework.service.IService;
|
|
import com.baomidou.framework.service.IService;
|
|
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
|
@@ -39,20 +40,22 @@ import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
|
|
*/
|
|
*/
|
|
public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable> implements IService<T, PK> {
|
|
public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable> implements IService<T, PK> {
|
|
|
|
|
|
- @Autowired
|
|
|
|
- protected M baseMapper;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 判断数据库操作是否成功
|
|
|
|
- *
|
|
|
|
- * @param result 数据库操作返回影响条数
|
|
|
|
- * @return boolean
|
|
|
|
- */
|
|
|
|
- protected boolean retBool(int result) {
|
|
|
|
- return result >= 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean insertOrUpdate(T entity) {
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ protected M baseMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断数据库操作是否成功
|
|
|
|
+ *
|
|
|
|
+ * @param result
|
|
|
|
+ * 数据库操作返回影响条数
|
|
|
|
+ * @return boolean
|
|
|
|
+ */
|
|
|
|
+ protected boolean retBool(int result) {
|
|
|
|
+ return result >= 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean insertOrUpdate(T entity) {
|
|
if (null != entity) {
|
|
if (null != entity) {
|
|
Class<?> cls = entity.getClass();
|
|
Class<?> cls = entity.getClass();
|
|
TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
|
|
TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
|
|
@@ -69,88 +72,100 @@ public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean insert(T entity) {
|
|
|
|
- return retBool(baseMapper.insert(entity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean insertSelective(T entity) {
|
|
|
|
- return retBool(baseMapper.insertSelective(entity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean insertBatch(List<T> entityList) {
|
|
|
|
- return retBool(baseMapper.insertBatch(entityList));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean deleteById(PK id) {
|
|
|
|
- return retBool(baseMapper.deleteById(id));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean deleteByMap(Map<String, Object> columnMap) {
|
|
|
|
- return retBool(baseMapper.deleteByMap(columnMap));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean deleteSelective(T entity) {
|
|
|
|
- return retBool(baseMapper.deleteSelective(entity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean deleteBatchIds(List<PK> idList) {
|
|
|
|
- return retBool(baseMapper.deleteBatchIds(idList));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean updateById(T entity) {
|
|
|
|
- return retBool(baseMapper.updateById(entity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean updateSelectiveById(T entity) {
|
|
|
|
- return retBool(baseMapper.updateSelectiveById(entity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean update(T entity, T whereEntity) {
|
|
|
|
- return retBool(baseMapper.update(entity, whereEntity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean updateSelective(T entity, T whereEntity) {
|
|
|
|
- return retBool(baseMapper.updateSelective(entity, whereEntity));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public boolean updateBatchById(List<T> entityList) {
|
|
|
|
- return retBool(baseMapper.updateBatchById(entityList));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public T selectById(PK id) {
|
|
|
|
- return baseMapper.selectById(id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<T> selectBatchIds(List<PK> idList) {
|
|
|
|
- return baseMapper.selectBatchIds(idList);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<T> selectByMap(Map<String, Object> columnMap) {
|
|
|
|
- return baseMapper.selectByMap(columnMap);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public T selectOne(T entity) {
|
|
|
|
- return baseMapper.selectOne(entity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public int selectCount(T entity) {
|
|
|
|
- return baseMapper.selectCount(entity);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List<T> selectList(EntityWrapper<T> entityWrapper) {
|
|
|
|
- return baseMapper.selectList(entityWrapper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Page<T> selectPage(Page<T> page, EntityWrapper<T> entityWrapper) {
|
|
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean insert(T entity) {
|
|
|
|
+ return retBool(baseMapper.insert(entity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean insertSelective(T entity) {
|
|
|
|
+ return retBool(baseMapper.insertSelective(entity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean insertBatch(List<T> entityList) {
|
|
|
|
+ return retBool(baseMapper.insertBatch(entityList));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean deleteById(PK id) {
|
|
|
|
+ return retBool(baseMapper.deleteById(id));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean deleteByMap(Map<String, Object> columnMap) {
|
|
|
|
+ return retBool(baseMapper.deleteByMap(columnMap));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean deleteSelective(T entity) {
|
|
|
|
+ return retBool(baseMapper.deleteSelective(entity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean deleteBatchIds(List<PK> idList) {
|
|
|
|
+ return retBool(baseMapper.deleteBatchIds(idList));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean updateById(T entity) {
|
|
|
|
+ return retBool(baseMapper.updateById(entity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean updateSelectiveById(T entity) {
|
|
|
|
+ return retBool(baseMapper.updateSelectiveById(entity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean update(T entity, T whereEntity) {
|
|
|
|
+ return retBool(baseMapper.update(entity, whereEntity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean updateSelective(T entity, T whereEntity) {
|
|
|
|
+ return retBool(baseMapper.updateSelective(entity, whereEntity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public boolean updateBatchById(List<T> entityList) {
|
|
|
|
+ return retBool(baseMapper.updateBatchById(entityList));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public T selectById(PK id) {
|
|
|
|
+ return baseMapper.selectById(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<T> selectBatchIds(List<PK> idList) {
|
|
|
|
+ return baseMapper.selectBatchIds(idList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<T> selectByMap(Map<String, Object> columnMap) {
|
|
|
|
+ return baseMapper.selectByMap(columnMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public T selectOne(T entity) {
|
|
|
|
+ return baseMapper.selectOne(entity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public int selectCount(T entity) {
|
|
|
|
+ return baseMapper.selectCount(entity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<T> selectList(EntityWrapper<T> entityWrapper) {
|
|
|
|
+ return baseMapper.selectList(entityWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Page<T> selectPage(Page<T> page, EntityWrapper<T> entityWrapper) {
|
|
if (null != entityWrapper) {
|
|
if (null != entityWrapper) {
|
|
entityWrapper.orderBy(page.getOrderByField(), page.isAsc());
|
|
entityWrapper.orderBy(page.getOrderByField(), page.isAsc());
|
|
}
|
|
}
|
|
page.setRecords(baseMapper.selectPage(page, entityWrapper));
|
|
page.setRecords(baseMapper.selectPage(page, entityWrapper));
|
|
return page;
|
|
return page;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|