|
|
@@ -1,16 +1,23 @@ |
|
|
|
package com.iformall.service.sm.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.CommonConstants; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.domain.dto.sm.SaveApiGuideDTO; |
|
|
|
import com.iformall.domain.dto.sm.UpdateApiGuideDTO; |
|
|
|
import com.iformall.domain.po.sm.ApiGuide; |
|
|
|
import com.iformall.exception.BizException; |
|
|
|
import com.iformall.service.sm.ApiGuideService; |
|
|
|
import com.iformall.mapper.ApiGuideMapper; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
*/ |
|
|
@@ -27,15 +34,52 @@ public class ApiGuideServiceImpl extends ServiceImpl<ApiGuideMapper, ApiGuide> i |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveApiGuide(SaveApiGuideDTO dto) { |
|
|
|
ApiGuide dbApiGuide = apiGuideMapper.selectOne(new LambdaQueryWrapper<ApiGuide>().eq(ApiGuide::getName, dto.getName())); |
|
|
|
if (dbApiGuide != null) { |
|
|
|
throw new BizException(ErrorCode.NAME_REPEAT); |
|
|
|
} |
|
|
|
|
|
|
|
// 暂时处理,存在正常的指南,则不可新增新的正常指南 |
|
|
|
List<ApiGuide> apiGuides = apiGuideMapper.selectList(new LambdaQueryWrapper<ApiGuide>() |
|
|
|
.eq(ApiGuide::getStatus, CommonConstants.STATUS_NORMAL) |
|
|
|
.eq(ApiGuide::getDeleteFlag, CommonConstants.FLAG_FALSE)); |
|
|
|
if (CommonConstants.STATUS_NORMAL.equals(dto.getStatus()) && !CollectionUtils.isEmpty(apiGuides)) { |
|
|
|
throw new BizException(ErrorCode.EXIST_AVAILABLE_GUIDE); |
|
|
|
} |
|
|
|
|
|
|
|
ApiGuide apiGuide = SaveApiGuideDTO.mapping(dto); |
|
|
|
apiGuideMapper.insert(apiGuide); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateApiGuide(UpdateApiGuideDTO dto) { |
|
|
|
ApiGuide dbApiGuide = apiGuideMapper.selectOne(new LambdaQueryWrapper<ApiGuide>() |
|
|
|
.eq(ApiGuide::getName, dto.getName()) |
|
|
|
.ne(ApiGuide::getId, dto.getId())); |
|
|
|
if (dbApiGuide != null) { |
|
|
|
throw new BizException(ErrorCode.NAME_REPEAT); |
|
|
|
} |
|
|
|
|
|
|
|
// 暂时处理,存在正常的指南,则不可修改新的正常指南 |
|
|
|
List<ApiGuide> apiGuides = apiGuideMapper.selectList(new LambdaQueryWrapper<ApiGuide>() |
|
|
|
.eq(ApiGuide::getStatus, CommonConstants.STATUS_NORMAL) |
|
|
|
.eq(ApiGuide::getDeleteFlag, CommonConstants.FLAG_FALSE) |
|
|
|
.ne(ApiGuide::getId, dto.getId())); |
|
|
|
if (CommonConstants.STATUS_NORMAL.equals(dto.getStatus()) && !CollectionUtils.isEmpty(apiGuides)) { |
|
|
|
throw new BizException(ErrorCode.EXIST_AVAILABLE_GUIDE); |
|
|
|
} |
|
|
|
|
|
|
|
ApiGuide apiGuide = UpdateApiGuideDTO.mapping(dto); |
|
|
|
apiGuideMapper.updateById(apiGuide); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ApiGuide getAvailableApiGuide() { |
|
|
|
ApiGuide apiGuide = new ApiGuide(); |
|
|
|
apiGuide.setStatus(CommonConstants.STATUS_NORMAL); |
|
|
|
List<ApiGuide> apiGuides = apiGuideMapper.listApiGuide(apiGuide); |
|
|
|
return !CollectionUtils.isEmpty(apiGuides) ? apiGuides.get(0) : null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|