diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java index a7050a182..def79df69 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/DeptMapper.java @@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -19,9 +18,7 @@ public interface DeptMapper extends BaseMapperX { } default DeptDO selectByParentIdAndName(Long parentId, String name) { - return selectOne(new LambdaQueryWrapper() - .eq(DeptDO::getParentId, parentId) - .eq(DeptDO::getName, name)); + return selectOne(DeptDO::getParentId, parentId, DeptDO::getName, name); } default Long selectCountByParentId(Long parentId) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java index 6bcb8e2fd..ba062a2c0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/PostMapper.java @@ -2,11 +2,10 @@ package cn.iocoder.yudao.module.system.dal.mysql.dept; 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 cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; import java.util.Collection; @@ -16,31 +15,32 @@ import java.util.List; public interface PostMapper extends BaseMapperX { default List selectList(Collection ids, Collection statuses) { - return selectList(new QueryWrapperX().inIfPresent("id", ids) - .inIfPresent("status", statuses)); + return selectList(new LambdaQueryWrapperX() + .inIfPresent(PostDO::getId, ids) + .inIfPresent(PostDO::getStatus, statuses)); } default PageResult selectPage(PostPageReqVO reqVO) { - return selectPage(reqVO, new QueryWrapperX() - .likeIfPresent("code", reqVO.getCode()) - .likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus()) - .orderByDesc("id")); + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(PostDO::getCode, reqVO.getCode()) + .likeIfPresent(PostDO::getName, reqVO.getName()) + .eqIfPresent(PostDO::getStatus, reqVO.getStatus()) + .orderByDesc(PostDO::getId)); } default List selectList(PostExportReqVO reqVO) { - return selectList(new QueryWrapperX() - .likeIfPresent("code", reqVO.getCode()) - .likeIfPresent("name", reqVO.getName()) - .eqIfPresent("status", reqVO.getStatus())); + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(PostDO::getCode, reqVO.getCode()) + .likeIfPresent(PostDO::getName, reqVO.getName()) + .eqIfPresent(PostDO::getStatus, reqVO.getStatus())); } default PostDO selectByName(String name) { - return selectOne(new QueryWrapper().eq("name", name)); + return selectOne(PostDO::getName, name); } default PostDO selectByCode(String code) { - return selectOne(new QueryWrapper().eq("code", code)); + return selectOne(PostDO::getCode, code); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java index 9d2601e8f..9d74a7beb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dept/UserPostMapper.java @@ -28,7 +28,7 @@ public interface UserPostMapper extends BaseMapperX { .in(UserPostDO::getPostId, postIds)); } - default void deleteByUserId(Long userId){ + default void deleteByUserId(Long userId) { delete(Wrappers.lambdaUpdate(UserPostDO.class).eq(UserPostDO::getUserId, userId)); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java index 951ef87af..244825093 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/dict/DictDataMapper.java @@ -17,13 +17,11 @@ import java.util.List; public interface DictDataMapper extends BaseMapperX { default DictDataDO selectByDictTypeAndValue(String dictType, String value) { - return selectOne(new LambdaQueryWrapper().eq(DictDataDO::getDictType, dictType) - .eq(DictDataDO::getValue, value)); + return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getValue, value); } default DictDataDO selectByDictTypeAndLabel(String dictType, String label) { - return selectOne(new LambdaQueryWrapper().eq(DictDataDO::getDictType, dictType) - .eq(DictDataDO::getLabel, label)); + return selectOne(DictDataDO::getDictType, dictType, DictDataDO::getLabel, label); } default List selectByDictTypeAndValues(String dictType, Collection values) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java index 3cb6bc8af..93baced06 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/errorcode/ErrorCodeMapper.java @@ -36,11 +36,11 @@ public interface ErrorCodeMapper extends BaseMapperX { } default List selectListByCodes(Collection codes) { - return selectList(new LambdaQueryWrapperX().in(ErrorCodeDO::getCode, codes)); + return selectList(ErrorCodeDO::getCode, codes); } default ErrorCodeDO selectByCode(Integer code) { - return selectOne(new LambdaQueryWrapperX().eq(ErrorCodeDO::getCode, code)); + return selectOne(ErrorCodeDO::getCode, code); } default List selectListByApplicationNameAndUpdateTimeGt(String applicationName, LocalDateTime minUpdateTime) { diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java index d28f2baed..ed0712a90 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceImpl.java @@ -58,7 +58,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { @Override public void updateErrorCode(ErrorCodeUpdateReqVO updateReqVO) { // 校验存在 - this.validateErrorCodeExists(updateReqVO.getId()); + validateErrorCodeExists(updateReqVO.getId()); // 校验 code 重复 validateCodeDuplicate(updateReqVO.getCode(), updateReqVO.getId()); @@ -71,7 +71,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { @Override public void deleteErrorCode(Long id) { // 校验存在 - this.validateErrorCodeExists(id); + validateErrorCodeExists(id); // 删除 errorCodeMapper.deleteById(id); } @@ -100,7 +100,7 @@ public class ErrorCodeServiceImpl implements ErrorCodeService { } @VisibleForTesting - public void validateErrorCodeExists(Long id) { + void validateErrorCodeExists(Long id) { if (errorCodeMapper.selectById(id) == null) { throw exception(ERROR_CODE_NOT_EXISTS); } diff --git a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java index 163a2cda3..cd5e01307 100644 --- a/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java +++ b/yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/service/errorcode/ErrorCodeServiceTest.java @@ -2,9 +2,9 @@ package cn.iocoder.yudao.module.system.service.errorcode; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.ArrayUtils; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeAutoGenerateReqDTO; +import cn.iocoder.yudao.module.system.api.errorcode.dto.ErrorCodeRespDTO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodeExportReqVO; import cn.iocoder.yudao.module.system.controller.admin.errorcode.vo.ErrorCodePageReqVO; @@ -22,7 +22,9 @@ import java.util.List; import java.util.function.Consumer; import static cn.hutool.core.util.RandomUtil.randomEle; +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; @@ -57,7 +59,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testUpdateErrorCode_success() { // mock 数据 - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(); + ErrorCodeDO dbErrorCode = randomErrorCodeDO(); errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 // 准备参数 ErrorCodeUpdateReqVO reqVO = randomPojo(ErrorCodeUpdateReqVO.class, o -> { @@ -75,7 +77,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testDeleteErrorCode_success() { // mock 数据 - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(); + ErrorCodeDO dbErrorCode = randomErrorCodeDO(); errorCodeMapper.insert(dbErrorCode);// @Sql: 先插入出一条存在的数据 // 准备参数 Long id = dbErrorCode.getId(); @@ -96,7 +98,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { reqVO.setApplicationName("tu"); reqVO.setCode(1); reqVO.setMessage("ma"); - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 11, 1),buildTime(2020, 11, 30)})); + reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); // 调用 PageResult pageResult = errorCodeService.getErrorCodePage(reqVO); @@ -110,7 +112,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { * 初始化 getErrorCodePage 方法的测试数据 */ private ErrorCodeDO initGetErrorCodePage() { - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> { // 等会查询到 + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> { // 等会查询到 o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType()); o.setApplicationName("tudou"); o.setCode(1); @@ -119,20 +121,20 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { }); errorCodeMapper.insert(dbErrorCode); // 测试 type 不匹配 - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType()))); // 测试 applicationName 不匹配 - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setApplicationName("yuan"))); // 测试 code 不匹配 - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCode(2))); // 测试 message 不匹配 - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai"))); + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setMessage("nai"))); // 测试 createTime 不匹配 - errorCodeMapper.insert(ObjectUtils.cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12)))); + errorCodeMapper.insert(cloneIgnoreId(dbErrorCode, o -> o.setCreateTime(buildTime(2020, 12, 12)))); return dbErrorCode; } @Test - public void testGetErrorCodeList() { + public void testGetErrorCodeList_export() { // mock 数据 ErrorCodeDO dbErrorCode = initGetErrorCodePage(); // 准备参数 @@ -141,7 +143,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { reqVO.setApplicationName("tu"); reqVO.setCode(1); reqVO.setMessage("ma"); - reqVO.setCreateTime((new LocalDateTime[]{buildTime(2020, 11, 1),buildTime(2020, 11, 30)})); + reqVO.setCreateTime(buildBetweenTime(2020, 11, 1, 2020, 11, 30)); // 调用 List list = errorCodeService.getErrorCodeList(reqVO); @@ -155,7 +157,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { // 准备参数 Integer code = randomInteger(); // mock 数据 - errorCodeMapper.insert(randomInfErrorCodeDO(o -> o.setCode(code))); + errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code))); // 调用,校验异常 assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, null), @@ -168,7 +170,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { Long id = randomLongId(); Integer code = randomInteger(); // mock 数据 - errorCodeMapper.insert(randomInfErrorCodeDO(o -> o.setCode(code))); + errorCodeMapper.insert(randomErrorCodeDO(o -> o.setCode(code))); // 调用,校验异常 assertServiceException(() -> errorCodeService.validateCodeDuplicate(code, id), @@ -204,7 +206,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testAutoGenerateErrorCodes_021() { // mock 数据 - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())); + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.MANUAL_OPERATION.getType())); errorCodeMapper.insert(dbErrorCode); // 准备参数 ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, @@ -224,7 +226,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testAutoGenerateErrorCodes_022() { // mock 数据 - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); errorCodeMapper.insert(dbErrorCode); // 准备参数 ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, @@ -244,7 +246,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testAutoGenerateErrorCodes_023() { // mock 数据 - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); errorCodeMapper.insert(dbErrorCode); // 准备参数 ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, @@ -265,7 +267,7 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { @Test public void testAutoGenerateErrorCodes_024() { // mock 数据 - ErrorCodeDO dbErrorCode = randomInfErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); + ErrorCodeDO dbErrorCode = randomErrorCodeDO(o -> o.setType(ErrorCodeTypeEnum.AUTO_GENERATION.getType())); errorCodeMapper.insert(dbErrorCode); // 准备参数 ErrorCodeAutoGenerateReqDTO generateReqDTO = randomPojo(ErrorCodeAutoGenerateReqDTO.class, @@ -279,10 +281,44 @@ public class ErrorCodeServiceTest extends BaseDbUnitTest { assertPojoEquals(generateReqDTO, errorCode); } + @Test + public void testGetErrorCode() { + // 准备参数 + ErrorCodeDO errorCodeDO = randomErrorCodeDO(); + errorCodeMapper.insert(errorCodeDO); + // mock 方法 + Long id = errorCodeDO.getId(); + + // 调用 + ErrorCodeDO dbErrorCode = errorCodeService.getErrorCode(id); + // 断言 + assertPojoEquals(errorCodeDO, dbErrorCode); + } + + @Test + public void testGetErrorCodeList() { + // 准备参数 + ErrorCodeDO errorCodeDO01 = randomErrorCodeDO( + o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 10))); + errorCodeMapper.insert(errorCodeDO01); + ErrorCodeDO errorCodeDO02 = randomErrorCodeDO( + o -> o.setApplicationName("yunai_server").setUpdateTime(buildTime(2022, 1, 12))); + errorCodeMapper.insert(errorCodeDO02); + // mock 方法 + String applicationName = "yunai_server"; + LocalDateTime minUpdateTime = buildTime(2022, 1, 11); + + // 调用 + List errorCodeList = errorCodeService.getErrorCodeList(applicationName, minUpdateTime); + // 断言 + assertEquals(1, errorCodeList.size()); + assertPojoEquals(errorCodeDO02, errorCodeList.get(0)); + } + // ========== 随机对象 ========== @SafeVarargs - private static ErrorCodeDO randomInfErrorCodeDO(Consumer... consumers) { + private static ErrorCodeDO randomErrorCodeDO(Consumer... consumers) { Consumer consumer = (o) -> { o.setType(randomEle(ErrorCodeTypeEnum.values()).getType()); // 保证 key 的范围 };