|
@@ -0,0 +1,80 @@
|
|
|
+package com.xt.js.gkaq.common;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 服务层共通基类
|
|
|
+ *
|
|
|
+ * @author 袁晓冬
|
|
|
+ *
|
|
|
+ * @param <T>
|
|
|
+ */
|
|
|
+public abstract class BaseUUIDModelServiceImpl<T extends BaseUUIDModel> implements BaseUUIDModelService<T> {
|
|
|
+ /** ID主键生成器 */
|
|
|
+ protected IdGenerator idGenerator = new UUIDGenerator();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据库操作接口
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ protected abstract BaseMapper<T> getMapper();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取检查过的Mapper对象
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private BaseMapper<T> getCheckedMapper() {
|
|
|
+ BaseMapper<T> mapper = getMapper();
|
|
|
+ if (null == mapper) {
|
|
|
+ throw new RuntimeException("mapper 不能为空!");
|
|
|
+ }
|
|
|
+ return mapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteByID(String id) {
|
|
|
+ return getCheckedMapper().deleteByPrimaryKey(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public int deleteLogicByID(String id) {
|
|
|
+ T record = getCheckedMapper().selectByPrimaryKey(id);
|
|
|
+ record.setState(BaseUUIDModel.STATE_DELETE);
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ return getCheckedMapper().updateByPrimaryKey(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public int add(T record) {
|
|
|
+ record.setId(idGenerator.generateStringId());
|
|
|
+ Date now = new Date();
|
|
|
+ record.setCreateTime(now);
|
|
|
+ record.setUpdateTime(now);
|
|
|
+ record.setState(BaseUUIDModel.STATE_ADD);
|
|
|
+ return getCheckedMapper().insert(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public T findById(String id) {
|
|
|
+ return getCheckedMapper().selectByPrimaryKey(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<T> findAll() {
|
|
|
+ return getCheckedMapper().selectAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public int update(T record) {
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ return getCheckedMapper().updateByPrimaryKey(record);
|
|
|
+ }
|
|
|
+}
|