diff --git a/common-collect/src/main/java/com/docus/server/collect/web/common/entity/TaskConfig.java b/common-collect/src/main/java/com/docus/server/collect/web/common/entity/TaskConfig.java index 93a5c4d..f00c393 100644 --- a/common-collect/src/main/java/com/docus/server/collect/web/common/entity/TaskConfig.java +++ b/common-collect/src/main/java/com/docus/server/collect/web/common/entity/TaskConfig.java @@ -105,4 +105,10 @@ public class TaskConfig { return this.startTime; } + public String getLastErrorMsg() { + if (null != lastErrorMsg && lastErrorMsg.length() > 1000) { + return lastErrorMsg.substring(0, 1000); + } + return lastErrorMsg; + } } diff --git a/common-collect/src/main/java/com/docus/server/collect/web/dao/ITaskConfigDao.java b/common-collect/src/main/java/com/docus/server/collect/web/dao/ITaskConfigDao.java new file mode 100644 index 0000000..6025754 --- /dev/null +++ b/common-collect/src/main/java/com/docus/server/collect/web/dao/ITaskConfigDao.java @@ -0,0 +1,7 @@ +package com.docus.server.collect.web.dao; + +import com.docus.infrastructure.core.db.dao.IBaseDao; +import com.docus.server.collect.web.common.entity.TaskConfig; + +public interface ITaskConfigDao extends IBaseDao { +} diff --git a/common-collect/src/main/java/com/docus/server/collect/web/dao/impl/TaskConfigDaoImpl.java b/common-collect/src/main/java/com/docus/server/collect/web/dao/impl/TaskConfigDaoImpl.java new file mode 100644 index 0000000..9381532 --- /dev/null +++ b/common-collect/src/main/java/com/docus/server/collect/web/dao/impl/TaskConfigDaoImpl.java @@ -0,0 +1,14 @@ +package com.docus.server.collect.web.dao.impl; + +import com.docus.infrastructure.core.db.dao.impl.BaseDaoImpl; +import com.docus.server.collect.web.common.entity.TaskConfig; +import com.docus.server.collect.web.dao.ITaskConfigDao; +import com.docus.server.collect.web.mapper.TaskConfigMapper; +import org.springframework.stereotype.Repository; + +@Repository +public class TaskConfigDaoImpl extends BaseDaoImpl implements ITaskConfigDao { + + + +} diff --git a/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java b/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java index cf757c4..e9de0b5 100644 --- a/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java +++ b/common-collect/src/main/java/com/docus/server/collect/web/job/AbstractCollectJob.java @@ -15,7 +15,6 @@ import com.docus.server.sys.service.IPowerThirdLoginService; import com.docus.server.sys.service.IPowerUserService; import com.xxl.job.core.context.XxlJobHelper; import lombok.extern.slf4j.Slf4j; -import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -117,21 +116,19 @@ public abstract class AbstractCollectJob implements IJob { } } - @Transactional public void updateTaskState(TaskConfig taskConfig) { taskConfig.setState(StateEnum.OK); - taskConfigService.updateById(taskConfig); + taskConfigService.updateTaskConfig(taskConfig); } - @Transactional public void updateTaskState(String message, TaskConfig taskConfig) { taskConfig.setState(StateEnum.FAIL); - taskConfig.setLastErrorMsg(message.length() > 1000 ? message.substring(0, 1000) : message); - taskConfigService.updateById(taskConfig); + taskConfig.setLastErrorMsg(message); + taskConfigService.updateTaskConfig(taskConfig); } private TaskConfig getTaskConfig(String taskConfigId) { - return taskConfigService.getById(taskConfigId); + return taskConfigService.getTaskConfigById(taskConfigId); } protected String getJobParam() { diff --git a/common-collect/src/main/java/com/docus/server/collect/web/service/ITaskConfigService.java b/common-collect/src/main/java/com/docus/server/collect/web/service/ITaskConfigService.java index 1fd9a88..68850b8 100644 --- a/common-collect/src/main/java/com/docus/server/collect/web/service/ITaskConfigService.java +++ b/common-collect/src/main/java/com/docus/server/collect/web/service/ITaskConfigService.java @@ -1,14 +1,17 @@ package com.docus.server.collect.web.service; -import com.docus.infrastructure.core.db.service.IBaseService; import com.docus.server.collect.web.common.entity.TaskConfig; import java.util.Date; -public interface ITaskConfigService extends IBaseService { +public interface ITaskConfigService { void updateAllPointerDate(String id, Date date); void updateIncPointerDate(String id, Date date); + TaskConfig getTaskConfigById(String taskConfigId); + + void updateTaskConfig(TaskConfig taskConfig); + } diff --git a/common-collect/src/main/java/com/docus/server/collect/web/service/impl/TaskConfigServiceImpl.java b/common-collect/src/main/java/com/docus/server/collect/web/service/impl/TaskConfigServiceImpl.java index 3ba26a3..ae84989 100644 --- a/common-collect/src/main/java/com/docus/server/collect/web/service/impl/TaskConfigServiceImpl.java +++ b/common-collect/src/main/java/com/docus/server/collect/web/service/impl/TaskConfigServiceImpl.java @@ -1,30 +1,46 @@ package com.docus.server.collect.web.service.impl; -import com.docus.infrastructure.core.db.service.impl.BaseServiceImpl; import com.docus.server.collect.web.common.entity.TaskConfig; -import com.docus.server.collect.web.mapper.TaskConfigMapper; +import com.docus.server.collect.web.dao.ITaskConfigDao; import com.docus.server.collect.web.service.ITaskConfigService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.util.Date; @Service -public class TaskConfigServiceImpl extends BaseServiceImpl implements ITaskConfigService { - @Transactional +public class TaskConfigServiceImpl implements ITaskConfigService { + + @Resource + private ITaskConfigDao taskConfigDao; + + @Transactional(rollbackFor = Exception.class) @Override public void updateAllPointerDate(String id, Date date) { - TaskConfig taskConfig = super.getById(id); + TaskConfig taskConfig = getTaskConfigById(id); taskConfig.setAllPointerTime(date); - super.updateById(taskConfig); + updateTaskConfig(taskConfig); + updateTaskConfig(taskConfig); } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void updateIncPointerDate(String id, Date date) { - TaskConfig taskConfig = super.getById(id); + TaskConfig taskConfig = getTaskConfigById(id); taskConfig.setIncPointerTime(date); - super.updateById(taskConfig); + updateTaskConfig(taskConfig); + } + + @Override + public TaskConfig getTaskConfigById(String taskConfigId) { + return taskConfigDao.findById(taskConfigId); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void updateTaskConfig(TaskConfig taskConfig) { + taskConfigDao.saveOrUpdate(taskConfig); } } diff --git a/common-docus/docus-sys/src/main/java/com/docus/server/sys/infrastructure/dao/impl/PowerUserDaoImpl.java b/common-docus/docus-sys/src/main/java/com/docus/server/sys/infrastructure/dao/impl/PowerUserDaoImpl.java index 12d850d..bd9c620 100644 --- a/common-docus/docus-sys/src/main/java/com/docus/server/sys/infrastructure/dao/impl/PowerUserDaoImpl.java +++ b/common-docus/docus-sys/src/main/java/com/docus/server/sys/infrastructure/dao/impl/PowerUserDaoImpl.java @@ -1,6 +1,6 @@ package com.docus.server.sys.infrastructure.dao.impl; -import com.docus.server.common.BaseDaoImpl; +import com.docus.infrastructure.core.db.dao.impl.BaseDaoImpl; import com.docus.server.sys.common.pojo.dto.UserModifyParam; import com.docus.server.sys.common.pojo.entity.PowerUser; import com.docus.server.sys.infrastructure.dao.IPowerUserDao; diff --git a/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java b/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java index 54b8930..14d2bc3 100644 --- a/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java +++ b/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/IPowerThirdLoginService.java @@ -1,8 +1,5 @@ package com.docus.server.sys.service; -import com.docus.infrastructure.core.db.service.IBaseService; -import com.docus.server.sys.common.pojo.entity.PowerThirdLogin; - /** *

* 第三方登陆 服务类 @@ -11,6 +8,6 @@ import com.docus.server.sys.common.pojo.entity.PowerThirdLogin; * @author jiashi * @since 2021-04-26 */ -public interface IPowerThirdLoginService extends IBaseService { +public interface IPowerThirdLoginService { } diff --git a/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java b/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java index 962d7a1..f541cdf 100644 --- a/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java +++ b/common-docus/docus-sys/src/main/java/com/docus/server/sys/service/impl/PowerThirdLoginServiceImpl.java @@ -1,8 +1,5 @@ package com.docus.server.sys.service.impl; -import com.docus.infrastructure.core.db.service.impl.BaseServiceImpl; -import com.docus.server.sys.common.pojo.entity.PowerThirdLogin; -import com.docus.server.sys.infrastructure.mapper.PowerThirdLoginMapper; import com.docus.server.sys.service.IPowerThirdLoginService; import org.springframework.stereotype.Service; @@ -15,7 +12,7 @@ import org.springframework.stereotype.Service; * @since 2021-04-26 */ @Service -public class PowerThirdLoginServiceImpl extends BaseServiceImpl implements IPowerThirdLoginService { +public class PowerThirdLoginServiceImpl implements IPowerThirdLoginService { } diff --git a/docus-api-common/src/main/java/com/docus/server/common/AbstractBaseService.java b/docus-api-common/src/main/java/com/docus/server/common/AbstractBaseService.java deleted file mode 100644 index 87355bb..0000000 --- a/docus-api-common/src/main/java/com/docus/server/common/AbstractBaseService.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.docus.server.common; - -import com.docus.infrastructure.core.db.Sort; -import org.springframework.transaction.annotation.Transactional; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -public abstract class AbstractBaseService implements IService { - - protected abstract IDao getDao(); - - @Override - public T findById(Serializable id) { - return getDao().findById(id); - } - - @Override - public List findByIds(Collection ids) { - return getDao().findByIds(ids); - } - - @Override - public List findBy(String propertyName, Object propertyValue) { - return getDao().findBy(propertyName, propertyValue); - } - - @Override - public List findByList(String propertyName, Collection propertyValue) { - return getDao().findByList(propertyName, propertyValue); - } - - @Override - public List findActiveBy(String propertyName, Object propertyValue) { - return getDao().findActiveBy(propertyName, propertyValue); - } - - @Override - public List findBy(String propertyName, Object propertyValue, Sort sort) { - return getDao().findBy(propertyName, propertyValue, sort); - } - - @Override - public List findActiveBy(String propertyName, Object propertyValue, Sort sort) { - return getDao().findActiveBy(propertyName, propertyValue, sort); - } - - @Override - public T findOneBy(String propertyName, Object propertyValue) { - return getDao().findOneBy(propertyName, propertyValue); - } - - @Override - public T findOneByList(String propertyName, Collection propertyValue) { - return getDao().findOneByList(propertyName, propertyValue); - } - - @Override - public T findActiveOneBy(String propertyName, Object propertyValue) { - return getDao().findActiveOneBy(propertyName, propertyValue); - } - - @Override - public List findAll() { - return getDao().findAll(); - } - - @Override - public List findAllActive() { - return getDao().findAllActive(); - } - - @Override - public List findAll(Sort sort) { - return getDao().findAll(sort); - } - - @Override - public List findAllActive(Sort sort) { - return getDao().findAllActive(sort); - } - - @Override - public int deleteByIdList(List idList) { - return getDao().deleteByIdList(idList); - } - - @Transactional(rollbackFor = Exception.class) - @Override - public boolean saveBatch(Collection entityList, int batchSize) { - return getDao().saveBatch(entityList, batchSize); - } - - @Transactional(rollbackFor = Exception.class) - @Override - public boolean saveOrUpdate(T entity) { - return getDao().saveOrUpdate(entity); - } - - @Transactional(rollbackFor = Exception.class) - @Override - public boolean updateBatchById(Collection entityList, int batchSize) { - return getDao().updateBatchById(entityList, batchSize); - } - - @Transactional(rollbackFor = Exception.class) - @Override - public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { - return getDao().saveOrUpdateBatch(entityList, batchSize); - } -} diff --git a/docus-api-common/src/main/java/com/docus/server/common/BaseDaoImpl.java b/docus-api-common/src/main/java/com/docus/server/common/BaseDaoImpl.java deleted file mode 100644 index e252e58..0000000 --- a/docus-api-common/src/main/java/com/docus/server/common/BaseDaoImpl.java +++ /dev/null @@ -1,445 +0,0 @@ -package com.docus.server.common; - -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.core.conditions.Wrapper; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.enums.SqlMethod; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; -import com.baomidou.mybatisplus.core.toolkit.Assert; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.Constants; -import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils; -import com.baomidou.mybatisplus.core.toolkit.ReflectionKit; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.baomidou.mybatisplus.extension.service.IService; -import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; -import com.docus.infrastructure.core.db.Sort; -import com.github.pagehelper.PageHelper; -import org.apache.ibatis.binding.MapperMethod; -import org.apache.ibatis.logging.Log; -import org.apache.ibatis.logging.LogFactory; -import org.apache.ibatis.session.SqlSession; -import org.mybatis.spring.SqlSessionUtils; -import org.springframework.beans.factory.annotation.Autowired; - -import java.io.Serializable; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class BaseDaoImpl, T> implements IDao { - protected Log log = LogFactory.getLog(getClass()); - - @Autowired - protected M baseMapper; - - public M getBaseMapper() { - return baseMapper; - } - - protected Class entityClass = currentModelClass(); - - public Class getEntityClass() { - return entityClass; - } - - protected Class mapperClass = currentMapperClass(); - - @Override - public T findById(Serializable id) { - if (id == null) { - throw new RuntimeException("param id is required"); - } - return baseMapper.selectById(id); - } - - @Override - public List findByIds(Collection ids) { - if (ids == null || ids.size() == 0) { - return new ArrayList<>(); - } - return baseMapper.selectBatchIds(ids); - } - - /** - * 按字段查询,返回所有匹配的记录, eq - */ - @Override - public List findBy(String propertyName, Object propertyValue) { - String columnName = getColumnName(propertyName); - return baseMapper.selectList(new QueryWrapper().eq(columnName, propertyValue)); - } - - /** - * 按字段查询,返回所有匹配的记录, in - */ - @Override - public List findByList(String propertyName, Collection propertyValue) { - String columnName = getColumnName(propertyName); - return baseMapper.selectList(new QueryWrapper().in(!Objects.isNull(propertyValue), columnName, propertyValue)); - } - - @Override - public List findActiveBy(String propertyName, Object propertyValue) { - String columnName = getColumnName(propertyName); - QueryWrapper queryWrapper = new QueryWrapper().eq(columnName, propertyValue); - queryWrapper.ne("state", 1); - return baseMapper.selectList(queryWrapper); - } - - //返回所有匹配的记录并排序 - @Override - public List findBy(String propertyName, Object propertyValue, Sort sort) { - String columnName = getColumnName(propertyName); - QueryWrapper query = new QueryWrapper().eq(columnName, propertyValue); - buildSort(sort, query); - return baseMapper.selectList(query); - } - - /** - * 返回所有匹配的Active记录并排序 - */ - @Override - public List findActiveBy(String propertyName, Object propertyValue, Sort sort) { - String columnName = getColumnName(propertyName); - QueryWrapper query = new QueryWrapper().eq(columnName, propertyValue); - query.ne("state", 1); - buildSort(sort, query); - return baseMapper.selectList(query); - } - - @Override - public T findOneBy(String propertyName, Object propertyValue) { - String columnName = getColumnName(propertyName); - PageHelper.startPage(1, 1); - List list = baseMapper.selectList(new QueryWrapper().eq(columnName, propertyValue)); - return (list == null || list.size() == 0) ? null : list.get(0); - } - - @Override - public T findOneByList(String propertyName, Collection propertyValue) { - String columnName = getColumnName(propertyName); - List list = baseMapper.selectList(new QueryWrapper().eq(!Objects.isNull(propertyValue), columnName, propertyValue)); - return (list == null || list.size() == 0) ? null : list.get(0); - } - - //按字段查询,返回第一条Active 记录 - @Override - public T findActiveOneBy(String propertyName, Object propertyValue) { - String columnName = getColumnName(propertyName); - PageHelper.startPage(1, 1); - QueryWrapper queryWrapper = new QueryWrapper().eq(columnName, propertyValue); - queryWrapper.ne("state", 1); - List list = baseMapper.selectList(queryWrapper); - return (list == null || list.size() == 0) ? null : list.get(0); - } - - /*Lambda方式自由组合查询条件*/ - public List find(LambdaQueryWrapper queryWrapper) { - return baseMapper.selectList(queryWrapper); - } - - /*Lambda方式自由组合查询条件,返回第一条记录*/ - public T findOne(LambdaQueryWrapper queryWrapper) { - PageHelper.startPage(1, 1); - List list = baseMapper.selectList(queryWrapper); - return (list == null || list.size() == 0) ? null : list.get(0); - } - - //返回表所有记录 - @Override - public List findAll() { - return baseMapper.selectList(null); - } - - //返回表所有Active的记录 - @Override - public List findAllActive() { - return baseMapper.selectList(Wrappers.query().ne("state", 1)); - } - - //返回表所有记录并排序 - @Override - public List findAll(Sort sort) { - QueryWrapper query = new QueryWrapper(); - buildSort(sort, query); - return baseMapper.selectList(query); - } - - //返回表所有Active记录并排序 - @Override - public List findAllActive(Sort sort) { - QueryWrapper query = new QueryWrapper(); - query.ne("state", 1); - buildSort(sort, query); - return baseMapper.selectList(query); - } - - //组装排序语句 - private void buildSort(Sort sort, QueryWrapper query) { - if (sort != null) { - List sortList = sort.getSortList(); - - for (Sort.SortItem sortItem : sortList) { - if (sortItem.getDirection() == Sort.Direction.ASC) { - query.orderByAsc(getColumnName(sortItem.getProperty())); - } else { - query.orderByDesc(getColumnName(sortItem.getProperty())); - } - } - } - } - - @Override - public int deleteByIdList(List idList) { - if (idList == null || idList.size() == 0) { - return 0; - } - return baseMapper.deleteBatchIds(idList); - } - - /** - * 判断数据库操作是否成功 - * - * @param result 数据库操作返回影响条数 - * @return boolean - * @deprecated 3.3.1 - */ - @Deprecated - protected boolean retBool(Integer result) { - return SqlHelper.retBool(result); - } - - @SuppressWarnings("unchecked") - protected Class currentMapperClass() { - return (Class) ReflectionKit.getSuperClassGenericType(getClass(), 0); - } - - @SuppressWarnings("unchecked") - protected Class currentModelClass() { - return (Class) ReflectionKit.getSuperClassGenericType(getClass(), 1); - } - - /** - * 批量操作 SqlSession - * - * @deprecated 3.3.0 - */ - @Deprecated - protected SqlSession sqlSessionBatch() { - return SqlHelper.sqlSessionBatch(entityClass); - } - - /** - * 释放sqlSession - * - * @param sqlSession session - * @deprecated 3.3.0 - */ - @Deprecated - protected void closeSqlSession(SqlSession sqlSession) { - SqlSessionUtils.closeSqlSession(sqlSession, GlobalConfigUtils.currentSessionFactory(entityClass)); - } - - /** - * 获取 SqlStatement - * - * @param sqlMethod ignore - * @return ignore - * @see #getSqlStatement(SqlMethod) - * @deprecated 3.4.0 - */ - @Deprecated - protected String sqlStatement(SqlMethod sqlMethod) { - return SqlHelper.table(entityClass).getSqlStatement(sqlMethod.getMethod()); - } - - /** - * 批量插入 - * - * @param entityList ignore - * @param batchSize ignore - * @return ignore - */ - @Override - public boolean saveBatch(Collection entityList, int batchSize) { - String sqlStatement = getSqlStatement(SqlMethod.INSERT_ONE); - return executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity)); - } - - /** - * 获取mapperStatementId - * - * @param sqlMethod 方法名 - * @return 命名id - * @since 3.4.0 - */ - protected String getSqlStatement(SqlMethod sqlMethod) { - return SqlHelper.getSqlStatement(mapperClass, sqlMethod); - } - - /** - * TableId 注解存在更新记录,否插入一条记录 - * - * @param entity 实体对象 - * @return boolean - */ - @Override - public boolean saveOrUpdate(T entity) { - if (null != entity) { - TableInfo tableInfo = TableInfoHelper.getTableInfo(this.entityClass); - Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); - String keyProperty = tableInfo.getKeyProperty(); - Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); - Object idVal = ReflectionKit.getFieldValue(entity, tableInfo.getKeyProperty()); - return StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal)) ? save(entity) : updateById(entity); - } - return false; - } - - /** - * 根据 ID 查询 - * - * @param id 主键ID - */ - public T getById(Serializable id) { - return getBaseMapper().selectById(id); - } - - /** - * 根据 ID 选择修改 - * - * @param entity 实体对象 - */ - public boolean updateById(T entity) { - return SqlHelper.retBool(getBaseMapper().updateById(entity)); - } - - /** - * 插入一条记录(选择字段,策略插入) - * - * @param entity 实体对象 - */ - public boolean save(T entity) { - return SqlHelper.retBool(getBaseMapper().insert(entity)); - } - - @Override - public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { - TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass); - Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); - String keyProperty = tableInfo.getKeyProperty(); - Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); - return SqlHelper.saveOrUpdateBatch(this.entityClass, this.mapperClass, this.log, entityList, batchSize, (sqlSession, entity) -> { - Object idVal = ReflectionKit.getFieldValue(entity, keyProperty); - return StringUtils.checkValNull(idVal) - || CollectionUtils.isEmpty(sqlSession.selectList(getSqlStatement(SqlMethod.SELECT_BY_ID), entity)); - }, (sqlSession, entity) -> { - MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); - param.put(Constants.ENTITY, entity); - sqlSession.update(getSqlStatement(SqlMethod.UPDATE_BY_ID), param); - }); - } - - @Override - public boolean updateBatchById(Collection entityList, int batchSize) { - String sqlStatement = getSqlStatement(SqlMethod.UPDATE_BY_ID); - return executeBatch(entityList, batchSize, (sqlSession, entity) -> { - MapperMethod.ParamMap param = new MapperMethod.ParamMap<>(); - param.put(Constants.ENTITY, entity); - sqlSession.update(sqlStatement, param); - }); - } - - public T getOne(Wrapper queryWrapper, boolean throwEx) { - if (throwEx) { - return baseMapper.selectOne(queryWrapper); - } - return SqlHelper.getObject(log, baseMapper.selectList(queryWrapper)); - } - - public Map getMap(Wrapper queryWrapper) { - return SqlHelper.getObject(log, baseMapper.selectMaps(queryWrapper)); - } - - public V getObj(Wrapper queryWrapper, Function mapper) { - return SqlHelper.getObject(log, listObjs(queryWrapper, mapper)); - } - - private List listObjs(Wrapper queryWrapper, Function mapper) { - return getBaseMapper().selectObjs(queryWrapper).stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList()); - } - - /** - * 执行批量操作 - * - * @param consumer consumer - * @since 3.3.0 - * @deprecated 3.3.1 后面我打算移除掉 {@link #executeBatch(Collection, int, BiConsumer)} }. - */ - @Deprecated - protected boolean executeBatch(Consumer consumer) { - return SqlHelper.executeBatch(this.entityClass, this.log, consumer); - } - - /** - * 执行批量操作 - * - * @param list 数据集合 - * @param batchSize 批量大小 - * @param consumer 执行方法 - * @param 泛型 - * @return 操作结果 - * @since 3.3.1 - */ - protected boolean executeBatch(Collection list, int batchSize, BiConsumer consumer) { - return SqlHelper.executeBatch(this.entityClass, this.log, list, batchSize, consumer); - } - - /** - * 执行批量操作(默认批次提交数量{@link IService#DEFAULT_BATCH_SIZE}) - * - * @param list 数据集合 - * @param consumer 执行方法 - * @param 泛型 - * @return 操作结果 - * @since 3.3.1 - */ - protected boolean executeBatch(Collection list, BiConsumer consumer) { - return executeBatch(list, DEFAULT_BATCH_SIZE, consumer); - } - - - //通过实体属性获取对应的数据库字段名 - public String getColumnName(String propertyName) { - Map fieldMap = ReflectionKit.getFieldMap(getEntityClass()); - if (fieldMap != null) { - Field field = fieldMap.get(propertyName); - - if (field != null) { - TableField annotation = field.getAnnotation(TableField.class); - if (annotation != null) { - return annotation.value(); - } - TableId idAnnotation = field.getAnnotation(TableId.class); - if (idAnnotation != null) { - return idAnnotation.value(); - } - } - } - throw new RuntimeException("获取不到属性" + propertyName + "的列名"); - } - -} diff --git a/docus-api-common/src/main/java/com/docus/server/common/BaseService.java b/docus-api-common/src/main/java/com/docus/server/common/BaseService.java deleted file mode 100644 index fb62615..0000000 --- a/docus-api-common/src/main/java/com/docus/server/common/BaseService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.docus.server.common; - -public class BaseService extends AbstractBaseService { - - protected IDao baseDao; - - @Override - protected IDao getDao() { - return this.getBaseDao(); - } - - public IDao getBaseDao() { - return baseDao; - } - - public void setBaseDao(IDao baseDao) { - this.baseDao = baseDao; - } -} diff --git a/docus-api-common/src/main/java/com/docus/server/common/IDao.java b/docus-api-common/src/main/java/com/docus/server/common/IDao.java deleted file mode 100644 index 5e63ee8..0000000 --- a/docus-api-common/src/main/java/com/docus/server/common/IDao.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.docus.server.common; - -import com.docus.infrastructure.core.db.Sort; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -public interface IDao { - - /*默认批次提交数量*/ - int DEFAULT_BATCH_SIZE = 1000; - - T findById(Serializable id); - - List findByIds(Collection ids); - - List findBy(String propertyName, Object propertyValue); - - List findByList(String propertyName, Collection propertyValue); - - List findActiveBy(String propertyName, Object propertyValue); - - List findBy(String propertyName, Object propertyValue, Sort sort); - - List findActiveBy(String propertyName, Object propertyValue, Sort sort); - - T findOneBy(String propertyName, Object propertyValue); - - T findOneByList(String propertyName, Collection propertyValue); - - T findActiveOneBy(String propertyName, Object propertyValue); - - List findAll(); - - List findAllActive(); - - List findAll(Sort sort); - - List findAllActive(Sort sort); - - int deleteByIdList(List idList); - - boolean saveBatch(Collection entityList, int batchSize); - - boolean saveOrUpdate(T entity); - - boolean updateBatchById(Collection entityList, int batchSize); - - boolean saveOrUpdateBatch(Collection entityList, int batchSize); -} diff --git a/docus-api-common/src/main/java/com/docus/server/common/IService.java b/docus-api-common/src/main/java/com/docus/server/common/IService.java deleted file mode 100644 index 87a3121..0000000 --- a/docus-api-common/src/main/java/com/docus/server/common/IService.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.docus.server.common; - -import com.docus.infrastructure.core.db.Sort; - -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - -public interface IService { - - T findById(Serializable id); - - List findByIds(Collection ids); - - List findBy(String propertyName, Object propertyValue); - - List findByList(String propertyName, Collection propertyValue); - - List findActiveBy(String propertyName, Object propertyValue); - - List findBy(String propertyName, Object propertyValue, Sort sort); - - List findActiveBy(String propertyName, Object propertyValue, Sort sort); - - T findOneBy(String propertyName, Object propertyValue); - - T findOneByList(String propertyName, Collection propertyValue); - - T findActiveOneBy(String propertyName, Object propertyValue); - - List findAll(); - - List findAllActive(); - - List findAll(Sort sort); - - List findAllActive(Sort sort); - - int deleteByIdList(List idList); - - boolean saveBatch(Collection entityList, int batchSize); - - boolean saveOrUpdate(T entity); - - boolean updateBatchById(Collection entityList, int batchSize); - - boolean saveOrUpdateBatch(Collection entityList, int batchSize); -}