shanggjj преди 5 години
родител
ревизия
d28c24976b

+ 20 - 8
pom.xml

@@ -2,6 +2,11 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
 		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+		<groupId>net.mingsoft</groupId>
+        <artifactId>ms-pom</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+    </parent>
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>net.mingsoft</groupId>
 	<artifactId>ms-mcms</artifactId>
@@ -70,9 +75,17 @@
 		<dependency>
 			<groupId>net.mingsoft</groupId>
 			<artifactId>ms-mpeople</artifactId>
-			<version>1.0.22</version>
 		</dependency>
-
+		<dependency>
+			<groupId>net.mingsoft</groupId>
+			<artifactId>ms-basic</artifactId>
+			<version>1.0.27-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>net.mingsoft</groupId>
+			<artifactId>ms-upgrader</artifactId>
+			<version>1.0.17</version>
+		</dependency>
 
 
 	</dependencies>
@@ -158,11 +171,7 @@
 					<encoding>${project.build.sourceEncoding}</encoding>
 					<showDeprecation>true</showDeprecation>
 					<showWarnings>true</showWarnings>
-					<compilerArguments>
-						<verbose />
-						<bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>
-					</compilerArguments>
-					<compilerArgument>-Xlint:unchecked</compilerArgument>
+
 				</configuration>
 				<dependencies>
 					<dependency>
@@ -173,7 +182,10 @@
 				</dependencies>
 			</plugin>
 
-
+			<plugin>
+				<groupId>org.springframework.boot</groupId>
+				<artifactId>spring-boot-maven-plugin</artifactId>
+			</plugin>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-javadoc-plugin</artifactId>

+ 6 - 11
src/main/java/net/mingsoft/cms/action/GeneraterAction.java

@@ -205,18 +205,13 @@ public class GeneraterAction extends BaseAction {
 		String dateTime = request.getParameter("dateTime");
 		// 网站风格物理路径
 		List<ContentBean> articleIdList = null;
-		try {
-			// 查出所有文章(根据选择栏目)包括子栏目
-			articleIdList = contentBiz.queryIdsByCategoryIdForParser(columnId, dateTime, null);
-			// 有符合条件的新闻就更新
-			if (articleIdList.size() > 0) {
-				CmsParserUtil.generateBasic(articleIdList);
-			}
-			this.outJson(response, true);
-		} catch (IOException e) {
-			e.printStackTrace();
-			this.outJson(response, false);
+		// 查出所有文章(根据选择栏目)包括子栏目
+		articleIdList = contentBiz.queryIdsByCategoryIdForParser(columnId, dateTime, null);
+		// 有符合条件的新闻就更新
+		if (articleIdList.size() > 0) {
+			CmsParserUtil.generateBasic(articleIdList);
 		}
+		this.outJson(response, true);
 	}
 
 

+ 9 - 1
src/main/java/net/mingsoft/cms/biz/ICategoryBiz.java

@@ -23,7 +23,15 @@ public interface ICategoryBiz extends IBaseBiz {
 
     void saveEntity(CategoryEntity entity);
 
+    /**更新父级及子集
+     * @param entity
+     */
     void updateEntity(CategoryEntity entity);
 
+    /**只更新自身
+     * @param entity
+     */
+    void update(CategoryEntity entity);
+
     void delete(int categoryId);
-}
+}

+ 5 - 0
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java

@@ -139,6 +139,11 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz {
 	}
 
 	@Override
+	public void update(CategoryEntity entity) {
+		super.updateEntity(entity);
+	}
+
+	@Override
 	public void delete(int categoryId) {
 		// TODO Auto-generated method stub
 		CategoryEntity category = (CategoryEntity) categoryDao.getEntity(categoryId);

+ 47 - 0
src/main/java/net/mingsoft/cms/upgrade/Upgrade.java

@@ -0,0 +1,47 @@
+package net.mingsoft.cms.upgrade;
+
+import cn.hutool.core.util.StrUtil;
+import net.mingsoft.basic.util.BasicUtil;
+import net.mingsoft.basic.util.SpringUtil;
+import net.mingsoft.cms.biz.ICategoryBiz;
+import net.mingsoft.cms.entity.CategoryEntity;
+import net.mingsoft.cms.util.PinYinUtil;
+
+import java.util.List;
+
+/**
+ * @author by 铭飞开源团队
+ * @Description TODO
+ * @date 2020/6/19 15:58
+ */
+public class Upgrade {
+
+    /**
+     * 菜单拼音升级
+     */
+    public void upgrade(){
+        ICategoryBiz categoryBiz = SpringUtil.getBean(ICategoryBiz.class);
+        List<CategoryEntity> list = categoryBiz.queryAll();
+        //先更新所有栏目的拼音
+        list.forEach(x->{
+            String pingYin = PinYinUtil.getPingYin(x.getCategoryTitle());
+            CategoryEntity category=new CategoryEntity();
+            category.setCategoryPinyin(pingYin);
+            category.setAppId(BasicUtil.getAppId());
+            CategoryEntity categoryBizEntity = (CategoryEntity)categoryBiz.getEntity(category);
+            x.setCategoryPinyin(pingYin);
+            //拼音存在则拼接id
+            if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(x.getId())){
+                x.setCategoryPinyin(pingYin+x.getId());
+            }
+            categoryBiz.update(x);
+        });
+        //再更新路径
+        list.forEach(x->{
+            if(StrUtil.isBlank(x.getCategoryId())||x.getCategoryId().equals("0")){
+                categoryBiz.updateEntity(x);
+            }
+        });
+
+    }
+}

+ 44 - 13
src/main/java/net/mingsoft/cms/util/CmsParserUtil.java

@@ -1,5 +1,8 @@
 package net.mingsoft.cms.util;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.TimeInterval;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.PageUtil;
 import freemarker.cache.FileTemplateLoader;
@@ -20,7 +23,11 @@ import net.mingsoft.mdiy.entity.ModelEntity;
 import net.mingsoft.mdiy.parser.TagParser;
 import net.mingsoft.mdiy.util.ParserUtil;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.util.WebAppRootListener;
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
@@ -28,6 +35,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
 
 public class CmsParserUtil extends ParserUtil {
 
@@ -144,7 +152,7 @@ public class CmsParserUtil extends ParserUtil {
 						// 将tag.getContent()写入路径
 						FileUtil.writeString(tag.rendering(), mobilePath, Const.UTF8);
 					}
-					writer = new StringWriter();
+
 				} else {
 					// 遍历分页
 					for (int i = 0; i < totalPageSize; i++) {
@@ -176,7 +184,6 @@ public class CmsParserUtil extends ParserUtil {
 							// 将tag.getContent()写入路径
 							FileUtil.writeString(tag.rendering(), mobilePath, Const.UTF8);
 						}
-						writer = new StringWriter();
 						pageNo++;
 					}
 				}
@@ -199,16 +206,16 @@ public class CmsParserUtil extends ParserUtil {
 	 * @throws MalformedTemplateNameException
 	 * @throws TemplateNotFoundException
 	 */
-	public static void generateBasic(List<ContentBean>  articleIdList)
-			throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException {
+	public static void generateBasic(List<ContentBean>  articleIdList) {
 
 		Map<Object, Object> contentModelMap = new HashMap<Object, Object>();
 		ModelEntity contentModel = null;
-		String writePath = null;
 		// 记录已经生成了文章编号
 		List<Integer> generateIds = new ArrayList<>();
+		ExecutorService pool=SpringUtil.getBean(ExecutorService.class);
 		// 生成文档
 		for (int artId = 0; artId < articleIdList.size();) {
+			String writePath = null;
 			//设置分页类
 			PageBean page = new PageBean();
 			// 文章编号
@@ -235,12 +242,13 @@ public class CmsParserUtil extends ParserUtil {
 			}
 			// 将
 			generateIds.add(articleId);
-			// 组合文章路径如:html/站点id/栏目id/文章id.html
-			writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId);
 			//如果是封面就生成index.html
 			if(Integer.parseInt(articleIdList.get(artId).getCategoryType()) == COLUMN_TYPE_COVER) {
 				writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX);
-			}
+			}else {
+                // 组合文章路径如:html/站点id/栏目id/文章id.html
+                writePath = ParserUtil.buildHtmlPath(articleColumnPath + File.separator + articleId);
+            }
 			Map<String, Object> parserParams = new HashMap<String, Object>();
 			parserParams.put(ParserUtil.COLUMN, articleIdList.get(artId));
 			// 判断当前栏目是否有自定义模型
@@ -278,23 +286,46 @@ public class CmsParserUtil extends ParserUtil {
 
 			parserParams.put(IS_DO, false);
 			parserParams.put(ParserUtil.PAGE, page);
-			String content = CmsParserUtil.generate(articleIdList.get(artId).getCategoryUrl(), parserParams, false);
-			FileUtil.writeString(content, writePath, Const.UTF8);
+			String finalWritePath = writePath;
+			HashMap<Object, Object> cloneMap = CollUtil.newHashMap();
+			cloneMap.putAll(parserParams);
+            HttpServletRequest request = SpringUtil.getRequest();
+            pool.execute(() -> {
+				String content = null;
+				try {
+					SpringUtil.setRequest(request);
+					content = CmsParserUtil.generate(columnUrl, cloneMap, false);
+					FileUtil.writeString(content, finalWritePath, Const.UTF8);
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			});
 			// 手机端
+
 			if (ParserUtil.hasMobileFile(columnUrl)) {
-				writePath = ParserUtil.buildMobileHtmlPath(articleColumnPath + File.separator + articleId);
 				//如果是封面就生成index.html
 				if(Integer.parseInt(articleIdList.get(artId).getCategoryType())  == COLUMN_TYPE_COVER) {
 					writePath = ParserUtil.buildMobileHtmlPath(articleColumnPath + File.separator + ParserUtil.INDEX);
+				}else {
+					writePath = ParserUtil.buildMobileHtmlPath(articleColumnPath + File.separator + articleId);
 				}
 				// 判断文件是否存在,若不存在弹出返回信息
 				if (!FileUtil.exist(ParserUtil.buildTempletPath(MOBILE + File.separator + columnUrl))) {
 					artId++;
 					continue;
 				}
+				String finalWritePath1 = writePath;
+				pool.execute(() -> {
+                    SpringUtil.setRequest(request);
 				parserParams.put(MOBILE, BasicUtil.getApp().getAppMobileStyle());
-				content = CmsParserUtil.generate(articleIdList.get(artId).getCategoryUrl(), parserParams, true);
-				FileUtil.writeString(content, writePath, Const.UTF8);
+					String content = null;
+					try {
+						content = CmsParserUtil.generate(columnUrl, parserParams, true);
+						FileUtil.writeString(content, finalWritePath1, Const.UTF8);
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+				});
 			}
 			artId++;
 		}

+ 13 - 3
src/main/java/net/mingsoft/config/WebConfig.java

@@ -2,6 +2,7 @@ package net.mingsoft.config;
 
 import java.io.File;
 import java.util.List;
+import java.util.concurrent.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -132,17 +133,26 @@ public class WebConfig implements WebMvcConfigurer {
 		// TODO Auto-generated method stub
 		converters.add(mappingJackson2HttpMessageConverter());
 		WebMvcConfigurer.super.configureMessageConverters(converters);
-		
+
 	}
-	
+
 	@Bean
     public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(){
         MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
         ObjectMapper objectMapper = new ObjectMapper();
+
         //添加此配置
         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
         converter.setObjectMapper(objectMapper);
         return converter;
     }
-
+	@Bean
+	public ExecutorService crawlExecutorPool() {
+		// 创建线程池
+		ExecutorService pool =
+				new ThreadPoolExecutor(20, 20,
+						0L, TimeUnit.MILLISECONDS,
+						new LinkedBlockingQueue<Runnable>());
+		return pool;
+	}
 }

+ 1 - 1
src/main/resources/application-dev.yml

@@ -2,6 +2,6 @@ spring:
   datasource:
     url: jdbc:mysql://localhost:3306/db-mcms-open?autoReconnect=true&useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
     username: root
-    password: 123456
+    password:
     filters: wall,mergeStat
     type: com.alibaba.druid.pool.DruidDataSource