|
@@ -3,6 +3,7 @@ package com.xt.js.gkaq.common;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
@@ -13,68 +14,73 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
* @param <T>
|
|
|
*/
|
|
|
public abstract class BaseUUIDModelServiceImpl<T extends BaseUUIDModel> implements BaseUUIDModelService<T> {
|
|
|
- /** ID主键生成器 */
|
|
|
- protected IdGenerator idGenerator = new UUIDGenerator();
|
|
|
+ /** ID主键生成器 */
|
|
|
+ protected IdGenerator idGenerator = new UUIDGenerator();
|
|
|
|
|
|
- /**
|
|
|
- * 获取数据库操作接口
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected abstract BaseMapper<T> getMapper();
|
|
|
+ /**
|
|
|
+ * 获取数据库操作接口
|
|
|
+ *
|
|
|
+ * @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;
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 获取检查过的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);
|
|
|
- }
|
|
|
+ @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 deleteLogicByID(String id) {
|
|
|
+ T record = getCheckedMapper().selectByPrimaryKey(id);
|
|
|
+ record.setState(BaseUUIDModel.STATE_DELETE);
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ User u = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ record.setUpdateUser(u.getLoginName());
|
|
|
+ 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);
|
|
|
- }
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public int add(T record) {
|
|
|
+ record.setId(idGenerator.generateStringId());
|
|
|
+ Date now = new Date();
|
|
|
+ record.setCreateTime(now);
|
|
|
+ record.setUpdateTime(now);
|
|
|
+ User u = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ record.setCreateUser(u.getLoginName());
|
|
|
+ record.setUpdateUser(u.getLoginName());
|
|
|
+ record.setState(BaseUUIDModel.STATE_ADD);
|
|
|
+ return getCheckedMapper().insert(record);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public T findById(String id) {
|
|
|
- return getCheckedMapper().selectByPrimaryKey(id);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public T findById(String id) {
|
|
|
+ return getCheckedMapper().selectByPrimaryKey(id);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public List<T> findAll() {
|
|
|
- return getCheckedMapper().selectAll();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<T> findAll() {
|
|
|
+ return getCheckedMapper().selectAll();
|
|
|
+ }
|
|
|
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public int update(T record) {
|
|
|
- record.setUpdateTime(new Date());
|
|
|
- return getCheckedMapper().updateByPrimaryKey(record);
|
|
|
- }
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public int update(T record) {
|
|
|
+ record.setUpdateTime(new Date());
|
|
|
+ User u = (User) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ record.setUpdateUser(u.getLoginName());
|
|
|
+ return getCheckedMapper().updateByPrimaryKey(record);
|
|
|
+ }
|
|
|
}
|