|
@@ -6,9 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.redxun.common.base.db.BaseDao;
|
|
|
import com.redxun.common.base.db.BaseService;
|
|
|
import com.redxun.common.base.db.PageHelper;
|
|
|
-import com.redxun.common.base.entity.BaseEntity;
|
|
|
import com.redxun.common.base.search.QueryFilter;
|
|
|
import com.redxun.common.service.impl.SuperServiceImpl;
|
|
|
+import com.redxun.common.tool.BeanUtil;
|
|
|
+import com.redxun.common.tool.IdGenerator;
|
|
|
import com.redxun.knowledge.entity.dao.Banner;
|
|
|
import com.redxun.knowledge.entity.dao.Knowledge;
|
|
|
import com.redxun.knowledge.entity.dao.KnowledgeCategory;
|
|
@@ -19,11 +20,11 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.Serializable;
|
|
|
-import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -72,22 +73,6 @@ public class BannerServiceImpl extends SuperServiceImpl<BannerMapper, Banner> im
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- if (filter.getParams().containsKey("bannerId") && filter.getParams().containsKey("flag")){
|
|
|
- String bannerId = (String) filter.getParams().get("bannerId");
|
|
|
- Boolean flag = (Boolean) filter.getParams().get("flag");
|
|
|
- if (flag){
|
|
|
- Banner banner = this.get(bannerId);
|
|
|
- BannerAdminVo bannerAdminVo = new BannerAdminVo();
|
|
|
- BeanUtils.copyProperties(banner,bannerAdminVo);
|
|
|
- int i = bannerAdminVos.indexOf(bannerAdminVo);
|
|
|
- log.info("上升记录位置 -> {}",i);
|
|
|
- BannerAdminVo bannerAdminVoPre = bannerAdminVos.get(i - 1);
|
|
|
- // 交换排序
|
|
|
- int temp = bannerAdminVo.getSort();
|
|
|
- bannerAdminVo.setSort(bannerAdminVoPre.getSort());
|
|
|
- bannerAdminVoPre.setSort(temp);
|
|
|
- }
|
|
|
- }
|
|
|
return page;
|
|
|
}
|
|
|
|
|
@@ -113,6 +98,89 @@ public class BannerServiceImpl extends SuperServiceImpl<BannerMapper, Banner> im
|
|
|
return banner;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增banner
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insert(Banner entity) {
|
|
|
+ if (BeanUtil.isEmpty(entity.getPkId())) {
|
|
|
+ entity.setPkId(IdGenerator.getIdStr());
|
|
|
+ }
|
|
|
+ if (entity.getSort() == null){
|
|
|
+ entity.setSort(0);
|
|
|
+ }
|
|
|
+ QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("SORT",entity.getSort());
|
|
|
+ Integer integer = bannerMapper.selectCount(queryWrapper);
|
|
|
+ if (integer > 0){
|
|
|
+ bannerMapper.insertOrUpdateBySort(entity.getSort());
|
|
|
+ }
|
|
|
+ return this.getRepository().insert(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改banner
|
|
|
+ * @param entity
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int update(Banner entity) {
|
|
|
+ if (entity.getSort() != null){
|
|
|
+ QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("SORT",entity.getSort());
|
|
|
+ Integer integer = bannerMapper.selectCount(queryWrapper);
|
|
|
+ if (integer > 0){
|
|
|
+ bannerMapper.insertOrUpdateBySort(entity.getSort());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.getRepository().updateById(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 状态为true,上升;为false,下降
|
|
|
+ * @param bannerId
|
|
|
+ * @param status
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void goUpOrDownUp(String bannerId,Boolean status) {
|
|
|
+ Banner banner = this.get(bannerId);
|
|
|
+ Integer sort = banner.getSort();
|
|
|
+ if (status){
|
|
|
+ // 上升
|
|
|
+ QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.orderByAsc("SORT").orderByDesc("ENABLED");
|
|
|
+ List<Banner> banners = bannerMapper.selectList(queryWrapper);
|
|
|
+ List<Banner> collect = banners.stream().filter(e -> e.getSort() < sort).collect(Collectors.toList());
|
|
|
+ Banner bannerPre = collect.get(collect.size() - 1);
|
|
|
+ // 交换位置
|
|
|
+ int temp = sort;
|
|
|
+ bannerMapper.swapSort(bannerId,bannerPre.getSort());
|
|
|
+ bannerMapper.swapSort(bannerPre.getPkId(),temp);
|
|
|
+ } else {
|
|
|
+ // 下降
|
|
|
+ QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.orderByAsc("SORT").orderByDesc("ENABLED");
|
|
|
+ List<Banner> banners = bannerMapper.selectList(queryWrapper);
|
|
|
+ List<Banner> collect = banners.stream().filter(e -> e.getSort() > sort).collect(Collectors.toList());
|
|
|
+ Banner bannerNext = collect.get(0);
|
|
|
+ // 交换位置
|
|
|
+ int temp = sort;
|
|
|
+ bannerMapper.swapSort(bannerId,bannerNext.getSort());
|
|
|
+ bannerMapper.swapSort(bannerNext.getPkId(),temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除banner
|
|
|
+ * @param pkId
|
|
|
+ */
|
|
|
+ public void deleteBanner(String pkId) {
|
|
|
+ bannerMapper.deleteBanner(pkId);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 前台查询全部banner展示(默认展示10张)
|
|
|
* @return
|
|
@@ -131,22 +199,6 @@ public class BannerServiceImpl extends SuperServiceImpl<BannerMapper, Banner> im
|
|
|
return collectBannerPcVo;
|
|
|
}
|
|
|
|
|
|
- public void deleteBanner(String pkId) {
|
|
|
- bannerMapper.deleteBanner(pkId);
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 状态为true,上升;为false,下降
|
|
|
- * @param bannerId
|
|
|
- * @param status
|
|
|
- */
|
|
|
- public void goUpOrDownUp(String bannerId,Boolean status) {
|
|
|
- Banner banner = this.get(bannerId);
|
|
|
- Integer sort = banner.getSort();
|
|
|
- QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.gt("SORT",sort);
|
|
|
- List<Banner> banners = bannerMapper.selectList(queryWrapper);
|
|
|
- log.info("bannerList -> {}",banners);
|
|
|
|
|
|
- }
|
|
|
}
|