|
|
@@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.uuid.IdUtils;
|
|
|
import com.ylx.massage.domain.TLbt;
|
|
|
+import com.ylx.massage.domain.dto.TLbtStatusDTO;
|
|
|
import com.ylx.massage.mapper.TLbtMapper;
|
|
|
import com.ylx.massage.service.TLbtService;
|
|
|
+import com.ylx.common.utils.DateUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -17,6 +19,10 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TLbtService {
|
|
|
+ private static final int STATUS_HIDE = 0;
|
|
|
+ private static final int STATUS_SHOW = 1;
|
|
|
+ private static final long MAX_SHOW_COUNT = 5L;
|
|
|
+ private static final long MIN_SHOW_COUNT = 1L;
|
|
|
|
|
|
@Override
|
|
|
public Boolean addOrUpdate(TLbt lbt) {
|
|
|
@@ -63,4 +69,43 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
|
|
|
}
|
|
|
return this.removeById(tLbt.getId());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateStatus(TLbtStatusDTO dto) {
|
|
|
+ if (dto == null) {
|
|
|
+ throw new ServiceException("参数不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getId())) {
|
|
|
+ throw new ServiceException("ID不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getStatus() == null || (dto.getStatus() != STATUS_HIDE && dto.getStatus() != STATUS_SHOW)) {
|
|
|
+ throw new ServiceException("显示状态值不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ TLbt exists = baseMapper.selectLbtById(dto.getId());
|
|
|
+ if (exists == null) {
|
|
|
+ throw new ServiceException("轮播图不存在");
|
|
|
+ }
|
|
|
+ if (dto.getStatus().equals(exists.getStatus())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long showCount = baseMapper.countByStatus(STATUS_SHOW);
|
|
|
+ if (STATUS_SHOW == dto.getStatus() && showCount >= MAX_SHOW_COUNT) {
|
|
|
+ throw new ServiceException("当前显示数量已达5条上限!");
|
|
|
+ }
|
|
|
+ if (STATUS_HIDE == dto.getStatus() && showCount <= MIN_SHOW_COUNT) {
|
|
|
+ throw new ServiceException("当前banner已是最后一条显示,不可关闭!");
|
|
|
+ }
|
|
|
+
|
|
|
+ TLbt update = new TLbt();
|
|
|
+ update.setId(dto.getId());
|
|
|
+ update.setStatus(dto.getStatus());
|
|
|
+ update.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ int rows = baseMapper.updateLbtById(update);
|
|
|
+ if (rows <= 0) {
|
|
|
+ throw new ServiceException("轮播图显示状态修改失败");
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|