|
@@ -0,0 +1,122 @@
|
|
|
|
+package com.chuanxia.mcp.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.chuanxia.mcp.bean.dto.DomainBindDto;
|
|
|
|
+import com.chuanxia.mcp.bean.dto.DomainQueryDto;
|
|
|
|
+import com.chuanxia.mcp.bean.enums.DefaultDomainEnums;
|
|
|
|
+import com.chuanxia.mcp.bean.model.CdnDomain;
|
|
|
|
+import com.chuanxia.mcp.bean.model.CdnDomainCity;
|
|
|
|
+import com.chuanxia.mcp.bean.model.SystemUser;
|
|
|
|
+import com.chuanxia.mcp.bean.vo.Result;
|
|
|
|
+import com.chuanxia.mcp.exception.ResultException;
|
|
|
|
+import com.chuanxia.mcp.mapper.CdnDomainMapper;
|
|
|
|
+import com.chuanxia.mcp.service.CdnDoaminService;
|
|
|
|
+import com.chuanxia.mcp.service.CdnDomainCityService;
|
|
|
|
+import com.chuanxia.mcp.service.UserService;
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author Administrator
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
+@Slf4j
|
|
|
|
+public class CdnDoaminServiceImpl extends ServiceImpl<CdnDomainMapper, CdnDomain> implements CdnDoaminService {
|
|
|
|
+ private final UserService userService;
|
|
|
|
+ private final CdnDomainMapper domainMapper;
|
|
|
|
+ private final CdnDomainCityService domainCityService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result listPage(DomainQueryDto queryDto) {
|
|
|
|
+ IPage<CdnDomain> page = new Page<>(queryDto.getPageNum(), queryDto.getPageSize());
|
|
|
|
+ LambdaQueryWrapper<CdnDomain> query = Wrappers.lambdaQuery();
|
|
|
|
+ if (StringUtils.isNotBlank(queryDto.getDomain())) {
|
|
|
|
+ query.like(CdnDomain::getDomain, queryDto.getDomain());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(queryDto.getManufacturer())) {
|
|
|
|
+ query.like(CdnDomain::getManufacturer, queryDto.getManufacturer());
|
|
|
|
+ }
|
|
|
|
+ page = domainMapper.selectPage(page, query);
|
|
|
|
+ return Result.success(page);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Result saveDomain(CdnDomain domain) {
|
|
|
|
+
|
|
|
|
+ SystemUser loginUser = userService.getLoginUser();
|
|
|
|
+ if (StringUtils.isBlank(domain.getDomain())) {
|
|
|
|
+ throw new ResultException(500, "域名不能为空");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isBlank(domain.getManufacturer())) {
|
|
|
|
+ throw new ResultException(500, "厂商不能为空");
|
|
|
|
+ }
|
|
|
|
+ Integer defaultDomain = domain.getDefaultDomain();
|
|
|
|
+ if (DefaultDomainEnums.DEFAULTDOMAIN.getStatus().equals(defaultDomain)) {
|
|
|
|
+ //判断是否已存在默认域名,存在则不允许添加了
|
|
|
|
+ LambdaQueryWrapper<CdnDomain> query = Wrappers.lambdaQuery();
|
|
|
|
+ query.eq(CdnDomain::getDefaultDomain, defaultDomain);
|
|
|
|
+ int count = this.count(query);
|
|
|
|
+ if (count >= 1) {
|
|
|
|
+ throw new ResultException(500, "已存在默认域名,不能再次添加默认域名");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ domain.setCreateBy(loginUser.getId());
|
|
|
|
+ this.save(domain);
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Result bindCdn(DomainBindDto bindDto) {
|
|
|
|
+ Integer domainId = bindDto.getDomainId();
|
|
|
|
+ CdnDomain domain = this.getById(domainId);
|
|
|
|
+ if (domain == null) {
|
|
|
|
+ throw new ResultException(500, "当前域名id不存在");
|
|
|
|
+ }
|
|
|
|
+ if (CollectionUtil.isEmpty(bindDto.getCityIds())) {
|
|
|
|
+ throw new ResultException(500, "城市列表不能为空");
|
|
|
|
+ }
|
|
|
|
+ List<Integer> cityIds = bindDto.getCityIds();
|
|
|
|
+ List<CdnDomainCity> domainCityList = new ArrayList<>(cityIds.size());
|
|
|
|
+ for (Integer cityId : cityIds) {
|
|
|
|
+ CdnDomainCity domainCity = new CdnDomainCity();
|
|
|
|
+ domainCity.setCityId(cityId);
|
|
|
|
+ domainCity.setDomainId(domainId);
|
|
|
|
+ domainCityList.add(domainCity);
|
|
|
|
+ }
|
|
|
|
+ LambdaQueryWrapper<CdnDomainCity> del = Wrappers.lambdaQuery();
|
|
|
|
+ del.eq(CdnDomainCity::getDomainId, domainId);
|
|
|
|
+ domainCityService.remove(del);
|
|
|
|
+ domainCityService.saveBatch(domainCityList);
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result updateDomain(CdnDomain domain) {
|
|
|
|
+ Integer defaultDomain = domain.getDefaultDomain();
|
|
|
|
+ if (DefaultDomainEnums.DEFAULTDOMAIN.getStatus().equals(defaultDomain)) {
|
|
|
|
+ //判断是否已存在默认域名,存在则不允许添加了
|
|
|
|
+ LambdaQueryWrapper<CdnDomain> query = Wrappers.lambdaQuery();
|
|
|
|
+ query.eq(CdnDomain::getDefaultDomain, defaultDomain).ne(CdnDomain::getId, domain.getId());
|
|
|
|
+ int count = this.count(query);
|
|
|
|
+ if (count >= 1) {
|
|
|
|
+ throw new ResultException(500, "已存在默认域名,不能再次添加默认域名");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.updateById(domain);
|
|
|
|
+ return Result.success();
|
|
|
|
+ }
|
|
|
|
+}
|