|
@@ -1,5 +1,6 @@
|
|
|
package com.ylx.massage.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.constant.MassageConstants;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
@@ -10,6 +11,8 @@ import com.ylx.massage.service.TLbtService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 轮播图 服务实现类
|
|
|
*/
|
|
@@ -18,17 +21,37 @@ public class TLbtServiceImpl extends ServiceImpl<TLbtMapper, TLbt> implements TL
|
|
|
|
|
|
@Override
|
|
|
public Boolean addOrUpdate(TLbt lbt) {
|
|
|
+ if (StringUtils.isBlank(lbt.getcImgUrl())) {
|
|
|
+ throw new ServiceException("图片不能为空");
|
|
|
+ }
|
|
|
+ if (lbt.getcSort() == null) {
|
|
|
+ throw new ServiceException("序号不能为空");
|
|
|
+ }
|
|
|
+ Integer i = lbt.getcSort();
|
|
|
+ LambdaQueryWrapper<TLbt> query = new LambdaQueryWrapper<TLbt>().eq(TLbt::getcSort, i);
|
|
|
+ TLbt one = getOne(query);
|
|
|
if (StringUtils.isBlank(lbt.getcId())) {
|
|
|
- if (StringUtils.isBlank(lbt.getcImgUrl())) {
|
|
|
- throw new ServiceException("图片不能为空");
|
|
|
+ //新增
|
|
|
+ if (one != null) {
|
|
|
+ batchLbt(i);
|
|
|
}
|
|
|
- if (lbt.getcSort() == null) {
|
|
|
- throw new ServiceException("序号不能为空");
|
|
|
+ } else {
|
|
|
+ //修改
|
|
|
+ query.ne(TLbt::getcId, lbt.getcId());
|
|
|
+ if (getOne(query) != null) {
|
|
|
+ batchLbt(i);
|
|
|
}
|
|
|
}
|
|
|
return this.saveOrUpdate(lbt);
|
|
|
}
|
|
|
|
|
|
+ private void batchLbt(Integer i) {
|
|
|
+ LambdaQueryWrapper<TLbt> query1 = new LambdaQueryWrapper<TLbt>().ge(TLbt::getcSort, i);
|
|
|
+ List<TLbt> lbts = list(query1);
|
|
|
+ lbts.forEach(tLbt1 -> tLbt1.setcSort(tLbt1.getcSort() + 1));
|
|
|
+ updateBatchById(lbts);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean del(TLbt tLbt) {
|
|
|
if (StringUtils.isBlank(tLbt.getcId())) {
|