From 9509af69aff71aeb1f3b62f766e124d291c3f374 Mon Sep 17 00:00:00 2001 From: liulin <lin.liu@aliyun.com> Date: 星期二, 30 七月 2024 00:07:04 +0800 Subject: [PATCH] 适配mybatis-plus --- src/main/java/com/lunhan/xxx/service/TestInfoService.java | 53 +++++++++++++++++++++++++++-------------------------- 1 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/lunhan/xxx/service/TestInfoService.java b/src/main/java/com/lunhan/xxx/service/TestInfoService.java index 40b8a7a..62b7a33 100644 --- a/src/main/java/com/lunhan/xxx/service/TestInfoService.java +++ b/src/main/java/com/lunhan/xxx/service/TestInfoService.java @@ -10,10 +10,10 @@ import com.lunhan.xxx.entity.request.ReqSetSort; import com.lunhan.xxx.entity.request.test.ReqCreateTestInfo; import com.lunhan.xxx.entity.request.test.ReqModifyTestInfo; -import com.lunhan.xxx.repository.dao.TestInfoDao; +import com.lunhan.xxx.repository.imapper.TestInfoMapper; import com.lunhan.xxx.repository.po.TestInfoPO; import com.lunhan.xxx.repository.vo.TestInfoVO; -import com.lunhan.xxx.service.convert.TestInfoMapper; +import com.lunhan.xxx.service.convert.TestInfoConvert; import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -27,19 +27,19 @@ @Service public class TestInfoService extends BaseService { @Autowired - private TestInfoDao dao; + private TestInfoMapper mapper; public ExecutedResult<Long> create(ReqCreateTestInfo request) { // 转换po - TestInfoPO item = TestInfoMapper.INSTANCE.toCreate(request); + TestInfoPO item = TestInfoConvert.INSTANCE.toCreate(request); item.setId(SnowFlakeUtil.getId()); // 设置状态 item.setStatus(EState.NORMAL.getValue()); // 设置记录创建时间 item.setCreateTime(LocalDateTimeUtil.nowTimeStamp()); - Boolean result = this.dao.addNotIncrement(item); - if (BooleanUtils.isFalse(result)) { + int rowCount = mapper.insert(item); + if (rowCount != 1) { return ExecutedResult.failed("创建[测试信息]失败。"); } return ExecutedResult.success(item.getId()); @@ -53,10 +53,10 @@ } // 转换po - TestInfoPO item = TestInfoMapper.INSTANCE.toModify(request); + TestInfoPO item = TestInfoConvert.INSTANCE.toModify(request); - Boolean result = this.dao.modify(item); - if (BooleanUtils.isFalse(result)) { + int rowCount = mapper.updateById(item); + if (rowCount != 1) { return ExecutedResult.failed("编辑[测试信息]失败。"); } return ExecutedResult.success(); @@ -65,9 +65,9 @@ public ExecutedResult<TestInfoVO> get(Long id) { TestInfoVO result = new TestInfoVO(); - TestInfoPO find = dao.getById(id); + TestInfoPO find = mapper.selectById(id); if (null != find) { - result = TestInfoMapper.INSTANCE.toVo(find); + result = TestInfoConvert.INSTANCE.toVo(find); } return ExecutedResult.success(result); } @@ -83,8 +83,8 @@ item.setId(id); item.setStatus(EState.DISABLED.getValue()); - Boolean result = this.dao.modify(item); - if (BooleanUtils.isFalse(result)) { + int rowCount = mapper.updateById(item); + if (rowCount != 1) { return ExecutedResult.failed("停用[测试信息]失败。"); } return ExecutedResult.success(); @@ -101,8 +101,8 @@ item.setId(id); item.setStatus(EState.NORMAL.getValue()); - Boolean result = this.dao.modify(item); - if (BooleanUtils.isFalse(result)) { + int rowCount = mapper.updateById(item); + if (rowCount != 1) { return ExecutedResult.failed("启用[测试信息]失败。"); } return ExecutedResult.success(); @@ -119,8 +119,8 @@ item.setId(request.getId()); item.setSort(request.getSort()); - Boolean result = this.dao.modify(item); - if (BooleanUtils.isFalse(result)) { + int rowCount = mapper.updateById(item); + if (rowCount != 1) { return ExecutedResult.failed("[测试信息]设置排序值失败。"); } return ExecutedResult.success(); @@ -143,7 +143,7 @@ return item; }) .collect(Collectors.toList()); - Boolean result = dao.modifyList(listUpdate); + Boolean result = mapper.modifyList(listUpdate); if (result) { return ExecutedResult.success(); } @@ -157,7 +157,7 @@ return ExecutedResult.failed(checkExists.getMsg()); } - Boolean result = this.dao.deleteLogic(id); + Boolean result = mapper.deleteLogic(id); if (BooleanUtils.isFalse(result)) { return ExecutedResult.failed("删除[测试信息]失败。"); } @@ -171,7 +171,7 @@ return ExecutedResult.failed(checkExists.getMsg()); } - Boolean result = this.dao.deleteLogic(listId); + Boolean result = mapper.deleteLogic(listId); if (BooleanUtils.isFalse(result)) { return ExecutedResult.failed("删除[测试信息]失败。"); } @@ -181,7 +181,7 @@ public ExecutedResult<List<TestInfoVO>> getList(List<Long> listId) { List<TestInfoVO> result = new ArrayList<>(); - List<TestInfoPO> list = this.dao.getListById(listId); + List<TestInfoPO> list = mapper.getList(listId); if (ListUtil.isNotNullOrEmpty(list)) { result = CopierUtil.mapTo(list, TestInfoVO.class); } @@ -198,13 +198,13 @@ search.setCreateTimeEnd(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem2()).getTime()); } - PagerResult<TestInfoPO> pageList = dao.search(search); + PagerResult<TestInfoPO> pageList = mapper.search(search); List<TestInfoVO> listVo = new ArrayList<>(); List<TestInfoPO> list = pageList.getList(); if (ListUtil.isNotNullOrEmpty(list)) { pageList.setLastId(list.get(list.size() - 1).getId()); // 转换vo - listVo = TestInfoMapper.INSTANCE.toVo(list); + listVo = TestInfoConvert.INSTANCE.toVo(list); } PagerResult<TestInfoVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo); result.setLastId(pageList.getLastId()); @@ -212,7 +212,7 @@ } protected ExecutedResult<TestInfoPO> check4Id(Long id) { - TestInfoPO exists = dao.getById(id); + TestInfoPO exists = mapper.get(id); if (Objects.isNull(exists)) { return ExecutedResult.failed("[测试信息]不存在:" + id); } @@ -220,7 +220,7 @@ } protected ExecutedResult<List<TestInfoPO>> check4Id(List<Long> listId) { // 从数据库查找类别 - List<TestInfoPO> list = dao.getListById(listId); + List<TestInfoPO> list = mapper.getList(listId); if (ListUtil.isNullOrEmpty(list)) { return ExecutedResult.failed("[测试信息]不存在." + listId); } @@ -236,8 +236,9 @@ } return ExecutedResult.success(list); } + protected Map<Long, TestInfoPO> getMap4Id(List<Long> listId) { - List<TestInfoPO> list = this.dao.getListById(listId); + List<TestInfoPO> list = mapper.getList(listId); if (ListUtil.isNullOrEmpty(list)) { return new HashMap<>(0); } -- Gitblit v1.9.3