diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmUserGroupMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmUserGroupMapper.java index 192f2600a..f524fef69 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmUserGroupMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmUserGroupMapper.java @@ -4,7 +4,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.group.B import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmUserGroupDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -18,15 +18,15 @@ import java.util.List; public interface BpmUserGroupMapper extends BaseMapperX { default PageResult selectPage(BpmUserGroupPageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus()) - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc("id")); + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(BpmUserGroupDO::getName, reqVO.getName()) + .eqIfPresent(BpmUserGroupDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(BpmUserGroupDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(BpmUserGroupDO::getId)); } default List selectListByStatus(Integer status) { - return selectList("status", status); + return selectList(BpmUserGroupDO::getStatus, status); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmTaskExtMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmTaskExtMapper.java index a71f06151..cc9a88af5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmTaskExtMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmTaskExtMapper.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.task; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmTaskExtDO; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; @@ -12,11 +12,11 @@ import java.util.List; public interface BpmTaskExtMapper extends BaseMapperX { default void updateByTaskId(BpmTaskExtDO entity) { - update(entity, new QueryWrapper().eq("task_id", entity.getTaskId())); + update(entity, new LambdaQueryWrapper().eq(BpmTaskExtDO::getTaskId, entity.getTaskId())); } default List selectListByTaskIds(Collection taskIds) { - return selectList("task_id", taskIds); + return selectList(BpmTaskExtDO::getTaskId, taskIds); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/job/InfJobMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/job/InfJobMapper.java index a57ba0f39..1f4a83792 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/job/InfJobMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/infra/dal/mysql/job/InfJobMapper.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.infra.dal.mysql.job; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobExportReqVO; import cn.iocoder.yudao.adminserver.modules.infra.controller.job.vo.job.InfJobPageReqVO; import cn.iocoder.yudao.adminserver.modules.infra.dal.dataobject.job.InfJobDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -19,22 +19,22 @@ import java.util.List; public interface InfJobMapper extends BaseMapperX { default InfJobDO selectByHandlerName(String handlerName) { - return selectOne("handler_name", handlerName); + return selectOne(InfJobDO::getHandlerName, handlerName); } default PageResult selectPage(InfJobPageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus()) - .likeIfPresent("handler_name", reqVO.getHandlerName()) + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(InfJobDO::getName, reqVO.getName()) + .eqIfPresent(InfJobDO::getStatus, reqVO.getStatus()) + .likeIfPresent(InfJobDO::getHandlerName, reqVO.getHandlerName()) ); } default List selectList(InfJobExportReqVO reqVO) { - return selectList(new QueryWrapperX() - .likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus()) - .likeIfPresent("handler_name", reqVO.getHandlerName()) + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(InfJobDO::getName, reqVO.getName()) + .eqIfPresent(InfJobDO::getStatus, reqVO.getStatus()) + .likeIfPresent(InfJobDO::getHandlerName, reqVO.getHandlerName()) ); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dept/SysDeptMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dept/SysDeptMapper.java index d4e0098cd..acece8a21 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dept/SysDeptMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dept/SysDeptMapper.java @@ -1,9 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dept; +import cn.iocoder.yudao.adminserver.modules.tool.enums.SqlConstants; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptListReqVO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; @@ -14,22 +17,22 @@ import java.util.List; public interface SysDeptMapper extends BaseMapperX { default List selectList(SysDeptListReqVO reqVO) { - return selectList(new QueryWrapperX().likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus())); + return selectList(new LambdaQueryWrapperX().likeIfPresent(SysDeptDO::getName, reqVO.getName()) + .eqIfPresent(SysDeptDO::getStatus, reqVO.getStatus())); } default SysDeptDO selectByParentIdAndName(Long parentId, String name) { - return selectOne(new QueryWrapper().eq("parent_id", parentId) - .eq("name", name)); + return selectOne(new LambdaQueryWrapper().eq(SysDeptDO::getParentId, parentId) + .eq(SysDeptDO::getParentId, name)); } default Integer selectCountByParentId(Long parentId) { - return selectCount("parent_id", parentId); + return selectCount(SysDeptDO::getParentId, parentId); } default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return selectOne(new QueryWrapper().select("id") - .gt("update_time", maxUpdateTime).last("LIMIT 1")) != null; + return selectOne(new LambdaQueryWrapper().select(SysDeptDO::getId) + .gt(SysDeptDO::getUpdateTime, maxUpdateTime).last(SqlConstants.LIMIT1)) != null; } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java index cc1046344..5cf5a732f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/dict/SysDictDataMapper.java @@ -2,13 +2,15 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.dict; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; +import cn.iocoder.yudao.adminserver.modules.tool.enums.SqlConstants; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; @@ -17,36 +19,36 @@ import java.util.List; public interface SysDictDataMapper extends BaseMapperX { default SysDictDataDO selectByDictTypeAndValue(String dictType, String value) { - return selectOne(new QueryWrapper().eq("dict_type", dictType) - .eq("value", value)); + return selectOne(new LambdaQueryWrapper().eq(SysDictDataDO::getDictType, dictType) + .eq(SysDictDataDO::getValue, value)); } default List selectByDictTypeAndValues(String dictType, Collection values) { - return selectList(new QueryWrapper().eq("dict_type", dictType) - .in("value", values)); + return selectList(new LambdaQueryWrapper().eq(SysDictDataDO::getDictType, dictType) + .in(SysDictDataDO::getValue, values)); } default int selectCountByDictType(String dictType) { - return selectCount("dict_type", dictType); + return selectCount(SysDictDataDO::getDictType, dictType); } default PageResult selectPage(SysDictDataPageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("label", reqVO.getLabel()) - .likeIfPresent("dict_type", reqVO.getDictType()) - .eqIfPresent("status", reqVO.getStatus()) - .orderByAsc("dict_type", "sort")); + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(SysDictDataDO::getLabel, reqVO.getLabel()) + .likeIfPresent(SysDictDataDO::getDictType, reqVO.getDictType()) + .eqIfPresent(SysDictDataDO::getStatus, reqVO.getStatus()) + .orderByAsc(Arrays.asList(SysDictDataDO::getDictType, SysDictDataDO::getSort))); } default List selectList(SysDictDataExportReqVO reqVO) { - return selectList(new QueryWrapperX().likeIfPresent("label", reqVO.getLabel()) - .likeIfPresent("dict_type", reqVO.getDictType()) - .eqIfPresent("status", reqVO.getStatus())); + return selectList(new LambdaQueryWrapperX().likeIfPresent(SysDictDataDO::getLabel, reqVO.getLabel()) + .likeIfPresent(SysDictDataDO::getDictType, reqVO.getDictType()) + .eqIfPresent(SysDictDataDO::getStatus, reqVO.getStatus())); } default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return selectOne(new QueryWrapper().select("id") - .gt("update_time", maxUpdateTime).last("LIMIT 1")) != null; + return selectOne(new LambdaQueryWrapper().select(SysDictDataDO::getId) + .gt(SysDictDataDO::getUpdateTime, maxUpdateTime).last(SqlConstants.LIMIT1)) != null; } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysMenuMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysMenuMapper.java index 7502bc0e6..d1b9616f3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysMenuMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/permission/SysMenuMapper.java @@ -1,10 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.permission; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; import cn.iocoder.yudao.adminserver.modules.system.controller.permission.vo.menu.SysMenuListReqVO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysMenuDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import cn.iocoder.yudao.adminserver.modules.tool.enums.SqlConstants; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Date; @@ -14,22 +15,22 @@ import java.util.List; public interface SysMenuMapper extends BaseMapperX { default SysMenuDO selectByParentIdAndName(Long parentId, String name) { - return selectOne(new QueryWrapper().eq("parent_id", parentId) - .eq("name", name)); + return selectOne(new LambdaQueryWrapper().eq(SysMenuDO::getParentId, parentId) + .eq(SysMenuDO::getName, name)); } default Integer selectCountByParentId(Long parentId) { - return selectCount("parent_id", parentId); + return selectCount(SysMenuDO::getParentId, parentId); } default List selectList(SysMenuListReqVO reqVO) { - return selectList(new QueryWrapperX().likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus())); + return selectList(new LambdaQueryWrapperX().likeIfPresent(SysMenuDO::getParentId, reqVO.getName()) + .eqIfPresent(SysMenuDO::getStatus, reqVO.getStatus())); } default boolean selectExistsByUpdateTimeAfter(Date maxUpdateTime) { - return selectOne(new QueryWrapper().select("id") - .gt("update_time", maxUpdateTime).last("LIMIT 1")) != null; + return selectOne(new LambdaQueryWrapper().select(SysMenuDO::getId) + .gt(SysMenuDO::getUpdateTime, maxUpdateTime).last(SqlConstants.LIMIT1)) != null; } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java index f0a315076..60d99a0a3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.sms.vo.template.Sy import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -14,35 +14,36 @@ import java.util.List; public interface SysSmsTemplateMapper extends BaseMapperX { default SysSmsTemplateDO selectByCode(String code) { - return selectOne("code", code); + return selectOne(SysSmsTemplateDO::getCode, code); } + // TODO 这种参数都一样的得想办法封装一下 default PageResult selectPage(SysSmsTemplatePageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .eqIfPresent("type", reqVO.getType()) - .eqIfPresent("status", reqVO.getStatus()) - .likeIfPresent("code", reqVO.getCode()) - .likeIfPresent("content", reqVO.getContent()) - .likeIfPresent("api_template_id", reqVO.getApiTemplateId()) - .eqIfPresent("channel_id", reqVO.getChannelId()) - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc("id")); + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(SysSmsTemplateDO::getType, reqVO.getType()) + .eqIfPresent(SysSmsTemplateDO::getStatus, reqVO.getStatus()) + .likeIfPresent(SysSmsTemplateDO::getCode, reqVO.getCode()) + .likeIfPresent(SysSmsTemplateDO::getContent, reqVO.getContent()) + .likeIfPresent(SysSmsTemplateDO::getApiTemplateId, reqVO.getApiTemplateId()) + .eqIfPresent(SysSmsTemplateDO::getChannelId, reqVO.getChannelId()) + .betweenIfPresent(SysSmsTemplateDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(SysSmsTemplateDO::getId)); } default List selectList(SysSmsTemplateExportReqVO reqVO) { - return selectList(new QueryWrapperX() - .eqIfPresent("type", reqVO.getType()) - .eqIfPresent("status", reqVO.getStatus()) - .likeIfPresent("code", reqVO.getCode()) - .likeIfPresent("content", reqVO.getContent()) - .likeIfPresent("api_template_id", reqVO.getApiTemplateId()) - .eqIfPresent("channel_id", reqVO.getChannelId()) - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc("id")); + return selectList(new LambdaQueryWrapperX() + .eqIfPresent(SysSmsTemplateDO::getType, reqVO.getType()) + .eqIfPresent(SysSmsTemplateDO::getStatus, reqVO.getStatus()) + .likeIfPresent(SysSmsTemplateDO::getCode, reqVO.getCode()) + .likeIfPresent(SysSmsTemplateDO::getContent, reqVO.getContent()) + .likeIfPresent(SysSmsTemplateDO::getApiTemplateId, reqVO.getApiTemplateId()) + .eqIfPresent(SysSmsTemplateDO::getChannelId, reqVO.getChannelId()) + .betweenIfPresent(SysSmsTemplateDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(SysSmsTemplateDO::getId)); } default Integer selectCountByChannelId(Long channelId) { - return selectCount("channel_id", channelId); + return selectCount(SysSmsTemplateDO::getChannelId, channelId); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/tenant/SysTenantMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/tenant/SysTenantMapper.java index e0e87d158..999d5c59b 100755 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/tenant/SysTenantMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/tenant/SysTenantMapper.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenan import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -19,26 +19,26 @@ import java.util.List; public interface SysTenantMapper extends BaseMapperX { default PageResult selectPage(SysTenantPageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("name", reqVO.getName()) - .likeIfPresent("contact_name", reqVO.getContactName()) - .likeIfPresent("contact_mobile", reqVO.getContactMobile()) - .eqIfPresent("status", reqVO.getStatus()) - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc("id")); + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(SysTenantDO::getName, reqVO.getName()) + .likeIfPresent(SysTenantDO::getContactName, reqVO.getContactName()) + .likeIfPresent(SysTenantDO::getContactMobile, reqVO.getContactMobile()) + .eqIfPresent(SysTenantDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(SysTenantDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(SysTenantDO::getId)); } default List selectList(SysTenantExportReqVO reqVO) { - return selectList(new QueryWrapperX() - .likeIfPresent("name", reqVO.getName()) - .likeIfPresent("contact_name", reqVO.getContactName()) - .likeIfPresent("contact_mobile", reqVO.getContactMobile()) - .eqIfPresent("status", reqVO.getStatus()) - .betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) - .orderByDesc("id")); + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(SysTenantDO::getName, reqVO.getName()) + .likeIfPresent(SysTenantDO::getContactName, reqVO.getContactName()) + .likeIfPresent(SysTenantDO::getContactMobile, reqVO.getContactMobile()) + .eqIfPresent(SysTenantDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(SysTenantDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .orderByDesc(SysTenantDO::getId)); } default SysTenantDO selectByName(String name) { - return selectOne("name", name); + return selectOne(SysTenantDO::getName, name); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java index 46023bdd5..8739301af 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java @@ -1,14 +1,14 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserExportReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.SysUserPageReqVO; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import jodd.util.StringPool; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; @@ -19,57 +19,58 @@ import java.util.Optional; public interface SysUserMapper extends BaseMapperX { default SysUserDO selectByUsername(String username) { - return selectOne(new QueryWrapper().eq("username", username)); + return selectOne(new LambdaQueryWrapper().eq(SysUserDO::getUsername, username)); } default SysUserDO selectByEmail(String email) { - return selectOne(new QueryWrapper().eq("email", email)); + return selectOne(new LambdaQueryWrapper().eq(SysUserDO::getEmail, email)); } default SysUserDO selectByMobile(String mobile) { - return selectOne(new QueryWrapper().eq("mobile", mobile)); + return selectOne(new LambdaQueryWrapper().eq(SysUserDO::getMobile, mobile)); } default PageResult selectPage(SysUserPageReqVO reqVO, Collection deptIds) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("username", reqVO.getUsername()) - .likeIfPresent("mobile", reqVO.getMobile()) - .eqIfPresent("status", reqVO.getStatus()) - .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()) - .inIfPresent("dept_id", deptIds)); + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(SysUserDO::getUsername, reqVO.getUsername()) + .likeIfPresent(SysUserDO::getMobile, reqVO.getMobile()) + .eqIfPresent(SysUserDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(SysUserDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime()) + .inIfPresent(SysUserDO::getDeptId, deptIds)); } default List selectList(SysUserExportReqVO reqVO, Collection deptIds) { - return selectList(new QueryWrapperX().likeIfPresent("username", reqVO.getUsername()) - .likeIfPresent("mobile", reqVO.getMobile()) - .eqIfPresent("status", reqVO.getStatus()) - .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()) - .inIfPresent("dept_id", deptIds)); + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(SysUserDO::getUsername, reqVO.getUsername()) + .likeIfPresent(SysUserDO::getMobile, reqVO.getMobile()) + .eqIfPresent(SysUserDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(SysUserDO::getCreateTime, reqVO.getBeginTime(), reqVO.getEndTime()) + .inIfPresent(SysUserDO::getDeptId, deptIds)); } default List selectListByNickname(String nickname) { - return selectList(new QueryWrapperX().like("nickname", nickname)); + return selectList(new LambdaQueryWrapperX().like(SysUserDO::getNickname, nickname)); } default List selectListByUsername(String username) { - return selectList(new QueryWrapperX().like("username", username)); + return selectList(new LambdaQueryWrapperX().like(SysUserDO::getUsername, username)); } // TODO 芋艿:可废弃该方法 default List selectListByDepartIdAndPostId(Long departId, Long postId) { - return selectList(new QueryWrapperX() - .eq("status", CommonStatusEnum.ENABLE.getStatus()) - .eq("dept_id", departId) + return selectList(new LambdaQueryWrapperX() + .eq(SysUserDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) + .eq(SysUserDO::getDeptId, departId) // TODO @jason: 封装一个 StringUtils .toString 。如果空的时候,设置为 null。会更简洁 - .likeIfPresent("post_ids", Optional.ofNullable(postId).map(t -> String.valueOf(postId)).orElse(""))); + .likeIfPresent(SysUserDO::getPostIds, Optional.ofNullable(postId).map(t -> String.valueOf(postId)).orElse(StringPool.EMPTY))); } default List selectListByStatus(Integer status) { - return selectList("status", status); + return selectList(SysUserDO::getStatus, status); } default List selectListByDeptIds(Collection deptIds) { - return selectList("dept_id", deptIds); + return selectList(SysUserDO::getDeptId, deptIds); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/SqlConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/SqlConstants.java new file mode 100644 index 000000000..a33b1b854 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/tool/enums/SqlConstants.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.adminserver.modules.tool.enums; + +/** + * SQL相关常量类 + */ +public interface SqlConstants { + + + String LIMIT1 = "LIMIT 1"; + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java index 1ba856eb1..8075608af 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/infra/dal/mysql/file/InfFileCoreMapper.java @@ -9,7 +9,7 @@ import org.apache.ibatis.annotations.Mapper; public interface InfFileCoreMapper extends BaseMapperX { default Integer selectCountById(String id) { - return selectCount("id", id); + return selectCount(InfFileDO::getId, id); } /** diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/merchant/PayChannelCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/merchant/PayChannelCoreMapper.java index d8780a92f..767a16b24 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/merchant/PayChannelCoreMapper.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/merchant/PayChannelCoreMapper.java @@ -11,7 +11,7 @@ import java.util.Date; public interface PayChannelCoreMapper extends BaseMapperX { default PayChannelDO selectByAppIdAndCode(Long appId, String code) { - return selectOne("app_id", appId, "code", code); + return selectOne(PayChannelDO::getAppId, appId, PayChannelDO::getCode, code); } @Select("SELECT id FROM pay_channel WHERE update_time > #{maxUpdateTime} LIMIT 1") diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/order/PayOrderExtensionCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/order/PayOrderExtensionCoreMapper.java index 3518986f8..08c95cea6 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/order/PayOrderExtensionCoreMapper.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/mysql/order/PayOrderExtensionCoreMapper.java @@ -2,19 +2,19 @@ package cn.iocoder.yudao.coreservice.modules.pay.dal.mysql.order; import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order.PayOrderExtensionDO; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; @Mapper public interface PayOrderExtensionCoreMapper extends BaseMapperX { default PayOrderExtensionDO selectByNo(String no) { - return selectOne("no", no); + return selectOne(PayOrderExtensionDO::getNo, no); } default int updateByIdAndStatus(Long id, Integer status, PayOrderExtensionDO update) { - return update(update, new QueryWrapper() - .eq("id", id).eq("status", status)); + return update(update, new LambdaQueryWrapper() + .eq(PayOrderExtensionDO::getId, id).eq(PayOrderExtensionDO::getStatus, status)); } } diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index 96065dae2..ec3194cec 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -4,9 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; 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.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import org.apache.ibatis.annotations.Param; import java.util.Collection; @@ -29,14 +31,26 @@ public interface BaseMapperX extends BaseMapper { return selectOne(new QueryWrapper().eq(field, value)); } + default T selectOne(SFunction field, Object value) { + return selectOne(new LambdaQueryWrapper().eq(field, value)); + } + default T selectOne(String field1, Object value1, String field2, Object value2) { return selectOne(new QueryWrapper().eq(field1, value1).eq(field2, value2)); } + default T selectOne(SFunction field1, Object value1, SFunction field2, Object value2) { + return selectOne(new LambdaQueryWrapper().eq(field1, value1).eq(field2, value2)); + } + default Integer selectCount(String field, Object value) { return selectCount(new QueryWrapper().eq(field, value)).intValue(); } + default Integer selectCount(SFunction field, Object value) { + return selectCount(new LambdaQueryWrapper().eq(field, value)).intValue(); + } + default List selectList() { return selectList(new QueryWrapper<>()); } @@ -45,10 +59,18 @@ public interface BaseMapperX extends BaseMapper { return selectList(new QueryWrapper().eq(field, value)); } + default List selectList(SFunction field, Object value) { + return selectList(new LambdaQueryWrapper().eq(field, value)); + } + default List selectList(String field, Collection values) { return selectList(new QueryWrapper().in(field, values)); } + default List selectList(SFunction field, Collection values) { + return selectList(new LambdaQueryWrapper().in(field, values)); + } + default void insertBatch(Collection entities) { // TODO 芋艿:修改成支持批量的 entities.forEach(this::insert); diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java new file mode 100644 index 000000000..463db3038 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/query/LambdaQueryWrapperX.java @@ -0,0 +1,129 @@ +package cn.iocoder.yudao.framework.mybatis.core.query; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.ArrayUtils; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; +import org.springframework.util.StringUtils; + +import java.util.Collection; + +/** + * 拓展 MyBatis Plus QueryWrapper 类,主要增加如下功能: + * + * 1. 拼接条件的方法,增加 xxxIfPresent 方法,用于判断值不存在的时候,不要拼接到条件中。 + * + * @param 数据类型 + */ +public class LambdaQueryWrapperX extends LambdaQueryWrapper { + + public LambdaQueryWrapperX likeIfPresent(SFunction column, String val) { + if (StringUtils.hasText(val)) { + return (LambdaQueryWrapperX) super.like(column, val); + } + return this; + } + + public LambdaQueryWrapperX inIfPresent(SFunction column, Collection values) { + if (!CollectionUtils.isEmpty(values)) { + return (LambdaQueryWrapperX) super.in(column, values); + } + return this; + } + + public LambdaQueryWrapperX inIfPresent(SFunction column, Object... values) { + if (!ArrayUtils.isEmpty(values)) { + return (LambdaQueryWrapperX) super.in(column, values); + } + return this; + } + + public LambdaQueryWrapperX eqIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.eq(column, val); + } + return this; + } + + public LambdaQueryWrapperX neIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.ne(column, val); + } + return this; + } + + public LambdaQueryWrapperX gtIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.gt(column, val); + } + return this; + } + + public LambdaQueryWrapperX geIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.ge(column, val); + } + return this; + } + + public LambdaQueryWrapperX ltIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.lt(column, val); + } + return this; + } + + public LambdaQueryWrapperX leIfPresent(SFunction column, Object val) { + if (val != null) { + return (LambdaQueryWrapperX) super.le(column, val); + } + return this; + } + + public LambdaQueryWrapperX betweenIfPresent(SFunction column, Object val1, Object val2) { + if (val1 != null && val2 != null) { + return (LambdaQueryWrapperX) super.between(column, val1, val2); + } + if (val1 != null) { + return (LambdaQueryWrapperX) ge(column, val1); + } + if (val2 != null) { + return (LambdaQueryWrapperX) le(column, val2); + } + return this; + } + + // ========== 重写父类方法,方便链式调用 ========== + + @Override + public LambdaQueryWrapperX eq(boolean condition, SFunction column, Object val) { + super.eq(condition, column, val); + return this; + } + + @Override + public LambdaQueryWrapperX eq(SFunction column, Object val) { + super.eq(column, val); + return this; + } + + @Override + public LambdaQueryWrapperX orderByDesc(SFunction column) { + super.orderByDesc(true, column); + return this; + } + + @Override + public LambdaQueryWrapperX last(String lastSql) { + super.last(lastSql); + return this; + } + + @Override + public LambdaQueryWrapperX in(SFunction column, Collection coll) { + super.in(column, coll); + return this; + } + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java index 35546f1d8..6abb5ddf3 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java @@ -13,7 +13,7 @@ import org.apache.ibatis.annotations.Mapper; public interface MbrUserMapper extends BaseMapperX { default MbrUserDO selectByMobile(String mobile) { - return selectOne("mobile", mobile); + return selectOne(MbrUserDO::getMobile, mobile); } }