|
@@ -0,0 +1,139 @@
|
|
|
+package com.fjhx.xmhjc.service.home.impl;
|
|
|
+
|
|
|
+import com.fjhx.xmhjc.entity.column.dto.ColumnArticleSelectDto;
|
|
|
+import com.fjhx.xmhjc.entity.column.dto.ColumnMenuSelectDto;
|
|
|
+import com.fjhx.xmhjc.entity.column.dto.ColumnMenuSubSelectDto;
|
|
|
+import com.fjhx.xmhjc.entity.column.vo.ColumnArticleVo;
|
|
|
+import com.fjhx.xmhjc.entity.column.vo.ColumnMenuSubVo;
|
|
|
+import com.fjhx.xmhjc.entity.column.vo.ColumnMenuVo;
|
|
|
+import com.fjhx.xmhjc.entity.home.po.HomeSetting;
|
|
|
+import com.fjhx.xmhjc.entity.home.vo.HomeSettingByOpenVo;
|
|
|
+import com.fjhx.xmhjc.mapper.home.HomeSettingMapper;
|
|
|
+import com.fjhx.xmhjc.service.column.ColumnArticleService;
|
|
|
+import com.fjhx.xmhjc.service.column.ColumnMenuService;
|
|
|
+import com.fjhx.xmhjc.service.home.HomeSettingService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fjhx.xmhjc.entity.home.vo.HomeSettingVo;
|
|
|
+import com.fjhx.xmhjc.entity.home.dto.HomeSettingSelectDto;
|
|
|
+import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
+import com.fjhx.xmhjc.entity.home.dto.HomeSettingDto;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 首页配置 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author lqh
|
|
|
+ * @since 2023-11-22
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class HomeSettingServiceImpl extends ServiceImpl<HomeSettingMapper, HomeSetting> implements HomeSettingService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ColumnMenuService columnMenuService;
|
|
|
+ @Resource
|
|
|
+ private ColumnArticleService columnArticleService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<HomeSettingVo> getList(HomeSettingSelectDto dto) {
|
|
|
+ IWrapper<HomeSetting> wrapper = getWrapper();
|
|
|
+ wrapper.orderByAsc("hs", HomeSetting::getId);
|
|
|
+ List<HomeSettingVo> list = this.baseMapper.getList(wrapper);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<HomeSettingVo> getPage(HomeSettingSelectDto dto) {
|
|
|
+ IWrapper<HomeSetting> wrapper = getWrapper();
|
|
|
+ wrapper.orderByDesc("hs", HomeSetting::getId);
|
|
|
+ Page<HomeSettingVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HomeSettingVo detail(Long id) {
|
|
|
+ HomeSetting HomeSetting = this.getById(id);
|
|
|
+ HomeSettingVo result = BeanUtil.toBean(HomeSetting, HomeSettingVo.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(HomeSettingDto homeSettingDto) {
|
|
|
+ this.save(homeSettingDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(HomeSettingDto homeSettingDto) {
|
|
|
+ this.updateById(homeSettingDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initHomeSetting(List<HomeSettingVo> list) {
|
|
|
+ //固定生成4个栏目模块
|
|
|
+ Set<Long> longSet = new HashSet<Long>(){{
|
|
|
+ add(1L);add(2L); add(3L); add(4L);
|
|
|
+ }};
|
|
|
+
|
|
|
+ Set<Long> idSet = list.stream().map(HomeSettingVo::getId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ longSet.forEach(id ->{
|
|
|
+ if (!idSet.contains(id)){
|
|
|
+ HomeSettingVo homeSettingVo = new HomeSettingVo();
|
|
|
+ homeSettingVo.setId(id);
|
|
|
+ list.add(homeSettingVo);
|
|
|
+
|
|
|
+ HomeSettingDto homeSettingDto = BeanUtil.toBean(homeSettingVo, HomeSettingDto.class);
|
|
|
+ this.save(homeSettingDto);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handHomeSetting(List<HomeSettingVo> list) {
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, String> menuMap = columnMenuService.getList(new ColumnMenuSelectDto()).stream().collect(Collectors.toMap(ColumnMenuVo::getId, ColumnMenuVo::getName));
|
|
|
+ Map<Long, String> articleMap = columnArticleService.getList(new ColumnArticleSelectDto()).stream().collect(Collectors.toMap(ColumnArticleVo::getId, ColumnArticleVo::getTitle));
|
|
|
+
|
|
|
+ list.forEach(home ->{
|
|
|
+ home.setMenuIdName(Objects.nonNull(home.getMenuId()) ?menuMap.getOrDefault(home.getMenuId(),""):"");
|
|
|
+ home.setArticleTitle1(Objects.nonNull(home.getArticle1())?articleMap.getOrDefault(home.getArticle1(),""):"");
|
|
|
+ home.setArticleTitle2(Objects.nonNull(home.getArticle2())?articleMap.getOrDefault(home.getArticle2(),""):"");
|
|
|
+ home.setArticleTitle3(Objects.nonNull(home.getArticle3())?articleMap.getOrDefault(home.getArticle3(),""):"");
|
|
|
+ home.setArticleTitle4(Objects.nonNull(home.getArticle4())?articleMap.getOrDefault(home.getArticle4(),""):"");
|
|
|
+ } );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handHomeSettingByOpen(List<HomeSettingByOpenVo> list) {
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, String> menuMap = columnMenuService.getList(new ColumnMenuSelectDto()).stream().collect(Collectors.toMap(ColumnMenuVo::getId, ColumnMenuVo::getName));
|
|
|
+ Map<Long, ColumnArticleVo> articleMap = columnArticleService.getList(new ColumnArticleSelectDto()).stream().collect(Collectors.toMap(ColumnArticleVo::getId, Function.identity()));
|
|
|
+
|
|
|
+ list.forEach(home ->{
|
|
|
+ home.setMenuIdName(Objects.nonNull(home.getMenuId()) ?menuMap.getOrDefault(home.getMenuId(),""):"");
|
|
|
+ home.setArticleObj1(Objects.nonNull(home.getArticle1())?articleMap.getOrDefault(home.getArticle1(),new ColumnArticleVo()):new ColumnArticleVo());
|
|
|
+ home.setArticleObj2(Objects.nonNull(home.getArticle2())?articleMap.getOrDefault(home.getArticle2(),new ColumnArticleVo()):new ColumnArticleVo());
|
|
|
+ home.setArticleObj3(Objects.nonNull(home.getArticle3())?articleMap.getOrDefault(home.getArticle3(),new ColumnArticleVo()):new ColumnArticleVo());
|
|
|
+ home.setArticleObj4(Objects.nonNull(home.getArticle4())?articleMap.getOrDefault(home.getArticle4(),new ColumnArticleVo()):new ColumnArticleVo());
|
|
|
+ } );
|
|
|
+
|
|
|
+ }
|
|
|
+}
|