|
@@ -0,0 +1,208 @@
|
|
|
+package org.dromara.system.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.ObjectUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.system.domain.bo.EventMenuBo;
|
|
|
+import org.dromara.system.domain.vo.EventMenuVo;
|
|
|
+import org.dromara.system.domain.EventMenu;
|
|
|
+import org.dromara.system.mapper.EventMenuMapper;
|
|
|
+import org.dromara.system.service.IEventMenuService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 赛事菜单关联Service业务层处理
|
|
|
+ *
|
|
|
+ * @author wenkai
|
|
|
+ * @date 2025-08-18
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class EventMenuServiceImpl implements IEventMenuService {
|
|
|
+
|
|
|
+ private final EventMenuMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询赛事菜单关联
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 赛事菜单关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public EventMenuVo queryById(Long id) {
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询赛事菜单关联
|
|
|
+ *
|
|
|
+ * @param eventId 赛事id
|
|
|
+ * @return 赛事菜单关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public EventMenuVo queryByEventId(Long eventId) {
|
|
|
+ return baseMapper.selectVoOne(
|
|
|
+ Wrappers.lambdaQuery(EventMenu.class)
|
|
|
+ .eq(EventMenu::getEventId, eventId)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询赛事菜单关联列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 赛事菜单关联分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<EventMenuVo> queryPageList(EventMenuBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<EventMenu> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<EventMenuVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ result.getRecords().stream()
|
|
|
+ .map(item -> {
|
|
|
+ Optional.ofNullable(item.getMenuList())
|
|
|
+ .ifPresent(menuList -> item.setMenus(JSONUtil.toList(menuList, Long.class)));
|
|
|
+ return item;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的赛事菜单关联列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 赛事菜单关联列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<EventMenuVo> queryList(EventMenuBo bo) {
|
|
|
+ LambdaQueryWrapper<EventMenu> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<EventMenu> buildQueryWrapper(EventMenuBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<EventMenu> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(EventMenu::getEventId, bo.getEventId());
|
|
|
+ lqw.orderByAsc(EventMenu::getId);
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增赛事菜单关联
|
|
|
+ *
|
|
|
+ * @param bo 赛事菜单关联
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(EventMenuBo bo) {
|
|
|
+ EventMenu add = MapstructUtils.convert(bo, EventMenu.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ Optional.ofNullable(bo.getMenuList())
|
|
|
+ .ifPresent(menuList -> add.setMenuList(JSONUtil.toJsonStr(menuList)));
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改赛事菜单关联
|
|
|
+ *
|
|
|
+ * @param bo 赛事菜单关联
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(EventMenuBo bo) {
|
|
|
+ EventMenu update = MapstructUtils.convert(bo, EventMenu.class);
|
|
|
+ Optional.ofNullable(bo.getMenuList())
|
|
|
+ .ifPresent(menuList -> update.setMenuList(JSONUtil.toJsonStr(menuList)));
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(EventMenu entity) {
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除赛事菜单关联信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if (isValid) {
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新赛事关联菜单
|
|
|
+ *
|
|
|
+ * @param bo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean editByVo(EventMenuBo bo) {
|
|
|
+ if (ObjectUtils.isNull(bo)) {
|
|
|
+ throw new ServiceException("参数不能为空");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(bo.getEventId())) {
|
|
|
+ throw new ServiceException("赛事id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long eventId = bo.getEventId();
|
|
|
+
|
|
|
+ // 如果 menus 为空或 null,则视为删除该赛事的菜单关联
|
|
|
+ if (ObjectUtils.isEmpty(bo.getMenus())) {
|
|
|
+ // 删除该 eventId 对应的记录
|
|
|
+ LambdaQueryWrapper<EventMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(EventMenu::getEventId, eventId);
|
|
|
+ baseMapper.delete(queryWrapper);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换并设置菜单 JSON 字符串
|
|
|
+ EventMenu entity = MapstructUtils.convert(bo, EventMenu.class);
|
|
|
+ entity.setMenuList(JSONUtil.toJsonStr(bo.getMenus()));
|
|
|
+
|
|
|
+ // 根据 eventId 查询是否存在记录
|
|
|
+ LambdaQueryWrapper<EventMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(EventMenu::getEventId, eventId);
|
|
|
+ EventMenu old = baseMapper.selectOne(queryWrapper);
|
|
|
+
|
|
|
+ if (old != null) {
|
|
|
+ // 存在则更新
|
|
|
+ entity.setId(old.getId()); // 保持主键一致
|
|
|
+ baseMapper.updateById(entity);
|
|
|
+ } else {
|
|
|
+ // 不存在则插入
|
|
|
+ baseMapper.insert(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+}
|