|
@@ -0,0 +1,57 @@
|
|
|
+package com.qunzhixinxi.hnqz.admin;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ArrayUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmWkArticle;
|
|
|
+import com.qunzhixinxi.hnqz.admin.enums.DelEnum;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmWkArticleService;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 文章数据处理
|
|
|
+ *
|
|
|
+ * @author lixuesong
|
|
|
+ * @date 2023/11/15
|
|
|
+ */
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
+@SpringBootTest(classes = {HnqzAdminApplication.class})
|
|
|
+public class WmArticleTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WmWkArticleService wmWkArticleService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增量更新文章来源的deptId
|
|
|
+ */
|
|
|
+// @Test
|
|
|
+ public void testArticle() {
|
|
|
+ String[] newSourceEnt = new String[]{"1611890564", "1611890570", "1611890587", "1611890597", "1611890619"};
|
|
|
+
|
|
|
+ List<WmWkArticle> articleList = wmWkArticleService.list(Wrappers.<WmWkArticle>lambdaQuery()
|
|
|
+ .eq(WmWkArticle::getDelFlag, DelEnum.NOT_DEL.val())
|
|
|
+ .select(WmWkArticle::getSourceEnt, WmWkArticle::getId));
|
|
|
+ List<WmWkArticle> updateArticles = new ArrayList<>();
|
|
|
+ articleList.forEach(article -> {
|
|
|
+ WmWkArticle updateArticle = new WmWkArticle();
|
|
|
+ updateArticle.setId(article.getId());
|
|
|
+
|
|
|
+ String[] sourceEnt = ArrayUtil.distinct(ArrayUtil.append(article.getSourceEnt(), newSourceEnt));
|
|
|
+ System.out.println("id=" + article.getId() + " sourceEnt=" + ArrayUtil.join(sourceEnt, ","));
|
|
|
+
|
|
|
+ updateArticle.setSourceEnt(sourceEnt);
|
|
|
+ updateArticle.setUpdateTime(LocalDateTime.now());
|
|
|
+ updateArticle.setUpdateUser(1);
|
|
|
+ updateArticles.add(updateArticle);
|
|
|
+ });
|
|
|
+
|
|
|
+ wmWkArticleService.updateBatchById(updateArticles);
|
|
|
+ }
|
|
|
+}
|