liulin
2024-07-31 5351c356a7f7872a06c6b27a3be81b3d6d9164c8
src/main/java/com/lunhan/xxx/service/TestInfoService.java
@@ -2,6 +2,7 @@
import com.lunhan.xxx.common.ExecutedResult;
import com.lunhan.xxx.common.PagerResult;
import com.lunhan.xxx.common.enums.EYesOrNo;
import com.lunhan.xxx.common.model.Tuple;
import com.lunhan.xxx.common.util.*;
import com.lunhan.xxx.entity.dto.search.SearchTestInfo;
@@ -10,10 +11,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.impl.TestInfoMapperImpl;
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 +28,21 @@
@Service
public class TestInfoService extends BaseService {
    @Autowired
    private TestInfoDao dao;
    private TestInfoMapperImpl 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());
        // 非逻辑删除
        item.setIsDelete(EYesOrNo.NO.getValue());
        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 +56,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 +68,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 +86,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 +104,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 +122,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 +146,7 @@
                    return item;
                })
                .collect(Collectors.toList());
        Boolean result = dao.modifyList(listUpdate);
        Boolean result = mapper.modifyList(listUpdate);
        if (result) {
            return ExecutedResult.success();
        }
@@ -157,7 +160,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 +174,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 +184,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 +201,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 +215,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 +223,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 +239,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);
        }