| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @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()); |
| | |
| | | } |
| | | |
| | | // 转换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(); |
| | |
| | | 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); |
| | | } |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | |
| | | return item; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | Boolean result = dao.modifyList(listUpdate); |
| | | Boolean result = mapper.modifyList(listUpdate); |
| | | if (result) { |
| | | return ExecutedResult.success(); |
| | | } |
| | |
| | | return ExecutedResult.failed(checkExists.getMsg()); |
| | | } |
| | | |
| | | Boolean result = this.dao.deleteLogic(id); |
| | | Boolean result = mapper.deleteLogic(id); |
| | | if (BooleanUtils.isFalse(result)) { |
| | | return ExecutedResult.failed("删除[测试信息]失败。"); |
| | | } |
| | |
| | | return ExecutedResult.failed(checkExists.getMsg()); |
| | | } |
| | | |
| | | Boolean result = this.dao.deleteLogic(listId); |
| | | Boolean result = mapper.deleteLogic(listId); |
| | | if (BooleanUtils.isFalse(result)) { |
| | | return ExecutedResult.failed("删除[测试信息]失败。"); |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | protected ExecutedResult<TestInfoPO> check4Id(Long id) { |
| | | TestInfoPO exists = dao.getById(id); |
| | | TestInfoPO exists = mapper.get(id); |
| | | if (Objects.isNull(exists)) { |
| | | return ExecutedResult.failed("[测试信息]不存在:" + id); |
| | | } |
| | |
| | | } |
| | | 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); |
| | | } |
| | |
| | | } |
| | | 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); |
| | | } |