Browse Source

修复冲突

chenlei1231 4 months ago
parent
commit
59c50395ba

+ 8 - 7
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/util/AdwebRedisUtil.java

@@ -23,9 +23,9 @@ import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 /**
- * redis 工具类
+ * Redis 工具类
  *
- * @author Scott
+ * @author wfansh
  */
 @Component
 @Slf4j
@@ -40,6 +40,8 @@ public class AdwebRedisUtil {
 
     @PostConstruct
     public void initRedisTemplate() {
+        this.redisTemplate = new RedisTemplate();
+        this.redisTemplate.setConnectionFactory(connectionFactory);
         JsonMapper jsonMapper =
                 JsonMapper.builder()
                         .visibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY)
@@ -52,18 +54,19 @@ public class AdwebRedisUtil {
                 new Jackson2JsonRedisSerializer<>(jsonMapper, Object.class);
         RedisSerializer<String> stringSerializer = new StringRedisSerializer();
 
-        this.redisTemplate = new RedisTemplate();
-        this.redisTemplate.setConnectionFactory(connectionFactory);
+        // Key序列化
         this.redisTemplate.setKeySerializer(stringSerializer);
+        // Value序列化
         this.redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
+        // Hash key序列化
         this.redisTemplate.setHashKeySerializer(stringSerializer);
+        // Hash value序列化
         this.redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
         this.redisTemplate.afterPropertiesSet();
     }
 
     public void sendMessage(String handlerName, BaseMap params) {
         params.put("handlerName", handlerName);
-        //        this.setRedisTemplate(this.redisTemplate);
         this.redisTemplate.convertAndSend("jeecg_redis_topic", params);
     }
 
@@ -146,7 +149,6 @@ public class AdwebRedisUtil {
      * @return 值
      */
     public Object get(String key) {
-        //        this.setRedisTemplate(this.redisTemplate);
         return key == null ? null : redisTemplate.opsForValue().get(key);
     }
 
@@ -157,7 +159,6 @@ public class AdwebRedisUtil {
      * @return 值
      */
     public String getString(String key) {
-        //        this.setRedisTemplate(this.redisTemplate);
         Object valueObj = get(key);
         return valueObj == null ? "" : valueObj.toString();
     }

+ 60 - 13
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/controller/SeoKeywordsController.java

@@ -27,9 +27,12 @@ import org.jeecg.common.system.api.ISysBaseAPI;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.modules.adweb.common.constant.AdwebConstant;
 import org.jeecg.modules.adweb.seo.dto.AvesApiSearchKeywordsDTO;
+import org.jeecg.modules.adweb.seo.dto.ChangeTypeDTO;
 import org.jeecg.modules.adweb.seo.entity.SeoKeywords;
+import org.jeecg.modules.adweb.seo.entity.SeoPlanSubscription;
 import org.jeecg.modules.adweb.seo.service.ISeoKeywordsRankService;
 import org.jeecg.modules.adweb.seo.service.ISeoKeywordsService;
+import org.jeecg.modules.adweb.seo.service.ISeoPlanSubscriptionService;
 import org.jeecg.modules.adweb.site.entity.AdwebSite;
 import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -67,6 +70,8 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
 
     @Autowired private IAdwebSiteService adwebSiteService;
 
+    @Autowired private ISeoPlanSubscriptionService seoPlanSubscriptionService;
+
     @Value("${jeecg.path.upload}")
     private String uploadUrl;
 
@@ -370,25 +375,27 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
      * @param request
      * @return
      */
+    @PreAuthorize("@jps.requiresPermissions('keywords:seo_keywords:importExcel')")
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public Result<?> importExcel(HttpServletRequest request) {
-        String siteId = request.getParameter("siteId");
-        log.info("siteId:" + siteId);
-        String subscriptionId = request.getParameter("subscriptionId");
-        log.info("subscriptionId:" + subscriptionId);
-        if (StringUtil.isEmpty(siteId)) {
-            return Result.error("站点id为空!");
+        String siteCode = request.getParameter("siteCode");
+        log.info("siteCode:" + siteCode);
+        if (StringUtil.isEmpty(siteCode)) {
+            return Result.error("站点code为空!");
         }
 
-        AdwebSite site = adwebSiteService.getById(siteId);
+        AdwebSite site = adwebSiteService.getSiteByCode(siteCode);
         if (site == null) {
             return Result.error("站点不存在!");
         }
-
         if (StringUtil.isEmpty(site.getDomain())) {
             return Result.error("站点域名未设置!");
         }
+        SeoPlanSubscription currentSeoAndSiteSubscription = seoPlanSubscriptionService.getCurrentSeoAndSiteSubscription(site.getId());
 
+        if (currentSeoAndSiteSubscription == null) {
+            return Result.error("当前站点没有有效的订阅套餐!");
+        }
         Date now = new Date();
 
         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
@@ -399,7 +406,7 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
             try {
                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
                 String formattedDate = dateFormat.format(now);
-                File realFile = new File(uploadUrl + "excel/", formattedDate + RandomStringUtils.random(4,true,true) + ".xlsx");
+                File realFile = new File(uploadUrl, formattedDate + RandomStringUtils.random(4,true,true) + ".xlsx");
                 file.transferTo(realFile);
                 stream = new FileInputStream(realFile);
                 XSSFWorkbook workbook = new XSSFWorkbook(stream);
@@ -448,7 +455,7 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
                     }
                     seoKeywords.setLastRank(0);
                     seoKeywords.setSearchStatus(0);
-                    seoKeywords.setSubscriptionId(subscriptionId);
+                    seoKeywords.setSubscriptionId(currentSeoAndSiteSubscription.getId());
                     list.add(seoKeywords);
                 }
 
@@ -457,9 +464,9 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
                 List<SeoKeywords> listNew = distinct(list);
                 // 去重
                 QueryWrapper<SeoKeywords> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("user_flag", site.getCode());
+                queryWrapper.eq("site_code", site.getCode());
                 queryWrapper.ne("status", 0);
-                queryWrapper.eq("history_id", subscriptionId);
+                queryWrapper.eq("subscription_id", currentSeoAndSiteSubscription.getId());
                 List<SeoKeywords> existingKeywordList = seoKeywordsService.list(queryWrapper);
                 if (CollectionUtil.isNotEmpty(existingKeywordList)) {
                     List<String> existingKeywords = new ArrayList<>();
@@ -474,7 +481,7 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
                     }
                 }
 
-                if (CollectionUtil.isNotEmpty(listNew)) {
+                if (CollectionUtil.isEmpty(listNew)) {
                     return Result.OK("关键词导入个数为0!");
                 }
 
@@ -518,4 +525,44 @@ public class SeoKeywordsController extends JeecgController<SeoKeywords, ISeoKeyw
         }
         return Result.OK(true);
     }
+
+    /**
+     * 关键词类型更改
+     *
+     * @return
+     */
+    @PostMapping(value = "/changeType")
+    public Result<?> changeType(@RequestBody ChangeTypeDTO changeTypeDTO) {
+        Integer id = changeTypeDTO.getId();
+        Integer type = changeTypeDTO.getType();
+        if (id == null || type == null) {
+            return Result.error("参数错误!");
+        }
+        SeoKeywords temp = seoKeywordsService.getById(id);
+        // 改为指定关键词时,判断是否是别的关键词的相关关键词,改为长尾关键词时,判断是否具有相关关键词
+        if (type == 2) {
+            QueryWrapper<SeoKeywords> queryWrapper2 = new QueryWrapper<>();
+            queryWrapper2.ne("status", 0);
+            queryWrapper2.eq("subscription_id", temp.getSubscriptionId());
+            queryWrapper2.eq("related_keyword_id", id);
+            if (seoKeywordsService.count(queryWrapper2) > 0) {
+                return Result.error("此关键词已经关联长尾词!");
+            }
+        }
+        if (type == 1) {
+            SeoKeywords word = seoKeywordsService.getById(id);
+            if (word != null && word.getRelatedKeywordId() != null) {
+                return Result.error("此关键词已关联指定关键词!");
+            }
+        }
+
+        SeoKeywords seoKeywords = new SeoKeywords();
+        seoKeywords.setId(id);
+        seoKeywords.setKeywordType(type);
+        boolean flag = seoKeywordsService.updateById(seoKeywords);
+        if (flag) {
+            return Result.OK("关键词类型更改成功!");
+        }
+        return Result.error("更改失败!");
+    }
 }

+ 14 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/seo/dto/ChangeTypeDTO.java

@@ -0,0 +1,14 @@
+package org.jeecg.modules.adweb.seo.dto;
+
+import lombok.Data;
+
+/**
+ * @author Zenas
+ */
+@Data
+public class ChangeTypeDTO {
+
+    Integer id;
+
+    Integer type;
+}