|
|
@@ -0,0 +1,167 @@
|
|
|
+package org.dromara.system.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+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.PlatformConfigBo;
|
|
|
+import org.dromara.system.domain.vo.PlatformConfigVo;
|
|
|
+import org.dromara.system.domain.PlatformConfig;
|
|
|
+import org.dromara.system.mapper.PlatformConfigMapper;
|
|
|
+import org.dromara.system.service.IPlatformConfigService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 平台配置Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LionLi
|
|
|
+ * @date 2025-12-11
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class PlatformConfigServiceImpl extends ServiceImpl<PlatformConfigMapper, PlatformConfig> implements IPlatformConfigService {
|
|
|
+
|
|
|
+ private final PlatformConfigMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询平台配置
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 平台配置
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PlatformConfigVo queryById(Long id){
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询平台配置列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 平台配置分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<PlatformConfigVo> queryPageList(PlatformConfigBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<PlatformConfig> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<PlatformConfigVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的平台配置列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 平台配置列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PlatformConfigVo> queryList(PlatformConfigBo bo) {
|
|
|
+ LambdaQueryWrapper<PlatformConfig> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<PlatformConfig> buildQueryWrapper(PlatformConfigBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<PlatformConfig> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(PlatformConfig::getId);
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPlatformCode()), PlatformConfig::getPlatformCode, bo.getPlatformCode());
|
|
|
+ lqw.eq(bo.getRelationId() != null, PlatformConfig::getRelationId, bo.getRelationId());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getConfigType()), PlatformConfig::getConfigType, bo.getConfigType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getConfigKey()), PlatformConfig::getConfigKey, bo.getConfigKey());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getName()), PlatformConfig::getName, bo.getName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getValue()), PlatformConfig::getValue, bo.getValue());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增平台配置
|
|
|
+ *
|
|
|
+ * @param bo 平台配置
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(PlatformConfigBo bo) {
|
|
|
+ PlatformConfig add = MapstructUtils.convert(bo, PlatformConfig.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改平台配置
|
|
|
+ *
|
|
|
+ * @param bo 平台配置
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(PlatformConfigBo bo) {
|
|
|
+ PlatformConfig update = MapstructUtils.convert(bo, PlatformConfig.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(PlatformConfig 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 boList 平台配置列表
|
|
|
+ * @return 是否保存成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean saveBatch(List<PlatformConfigBo> boList) {
|
|
|
+ for (PlatformConfigBo bo : boList) {
|
|
|
+ // 根据 configType 和 configKey 查询是否存在
|
|
|
+ LambdaQueryWrapper<PlatformConfig> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(PlatformConfig::getConfigType, bo.getConfigType());
|
|
|
+ lqw.eq(PlatformConfig::getConfigKey, bo.getConfigKey());
|
|
|
+ PlatformConfig exist = baseMapper.selectOne(lqw);
|
|
|
+
|
|
|
+ if (exist != null) {
|
|
|
+ // 存在则更新
|
|
|
+ exist.setValue(bo.getValue());
|
|
|
+ exist.setName(bo.getName());
|
|
|
+ baseMapper.updateById(exist);
|
|
|
+ } else {
|
|
|
+ // 不存在则新增
|
|
|
+ PlatformConfig add = MapstructUtils.convert(bo, PlatformConfig.class);
|
|
|
+ baseMapper.insert(add);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|