Skip to content

Commit

Permalink
Merge pull request !1 from gaojie/master
Browse files Browse the repository at this point in the history
  • Loading branch information
sanluan committed Jan 9, 2017
2 parents 2c9bce2 + f2fe773 commit 72bf65f
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 20 deletions.
57 changes: 55 additions & 2 deletions publiccms-by-maven/pom.xml
Expand Up @@ -3,11 +3,13 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>publiccms</groupId> <groupId>publiccms</groupId>
<artifactId>cms</artifactId> <artifactId>cms</artifactId>
<version>V2016.0828</version> <version>V2017.01.01</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>PublicCMS</name> <name>PublicCMS</name>
<url>http://www.publiccms.com/</url> <url>http://www.publiccms.com/</url>
<description>PublicCMS</description> <description>PublicCMS</description>


<properties> <properties>
<springVersion>4.3.2.RELEASE</springVersion> <springVersion>4.3.2.RELEASE</springVersion>
<hibernateVersion>5.1.1.Final</hibernateVersion> <hibernateVersion>5.1.1.Final</hibernateVersion>
Expand All @@ -16,7 +18,41 @@
<httpclientVersion>4.5.2</httpclientVersion> <httpclientVersion>4.5.2</httpclientVersion>
<jacksonVersion>2.8.1</jacksonVersion> <jacksonVersion>2.8.1</jacksonVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<db_host>172.17.0.2</db_host>
<db_username>root</db_username>
<db_password>mysql1234</db_password>
<ftl_update_delay>5</ftl_update_delay>
<log_level>info</log_level>

</properties> </properties>

<profiles>
<profile>
<id>release</id>
<properties>
<db_host>172.18.0.2</db_host>
<db_username>root</db_username>
<db_password>mysqlqidianxinchuang</db_password>
<ftl_update_delay>60</ftl_update_delay>
<log_level>info</log_level>
</properties>
</profile>

<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>local</id>
<properties>
<db_host>172.17.0.2</db_host>
<db_username>root</db_username>
<db_password>mysql123</db_password>
<ftl_update_delay>5</ftl_update_delay>
</properties>
</profile>
</profiles>

<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.freemarker</groupId> <groupId>org.freemarker</groupId>
Expand Down Expand Up @@ -183,7 +219,24 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>

<defaultGoal>compile</defaultGoal> <defaultGoal>compile</defaultGoal>
<resources>

<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
</resource>

<resource>
<directory>lib</directory>
<targetPath>lib</targetPath>
</resource>
</resources>

<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
Expand All @@ -195,7 +248,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version> <version>3.5.1</version>
<configuration> <configuration>
<source>1.7</source> <source>1.7</source>
<target>1.7</target> <target>1.7</target>
Expand Down
Expand Up @@ -9,6 +9,8 @@
import com.sanluan.common.handler.PageHandler; import com.sanluan.common.handler.PageHandler;
import com.sanluan.common.handler.QueryHandler; import com.sanluan.common.handler.QueryHandler;


import java.util.List;

@Repository @Repository
public class CmsCategoryDao extends BaseDao<CmsCategory> { public class CmsCategoryDao extends BaseDao<CmsCategory> {
public PageHandler getPage(Integer siteId, Integer parentId, Integer typeId, Boolean allowContribute, Boolean hidden, public PageHandler getPage(Integer siteId, Integer parentId, Integer typeId, Boolean allowContribute, Boolean hidden,
Expand Down Expand Up @@ -38,6 +40,24 @@ public PageHandler getPage(Integer siteId, Integer parentId, Integer typeId, Boo
return getPage(queryHandler, pageIndex, pageSize); return getPage(queryHandler, pageIndex, pageSize);
} }


public CmsCategory getCategory(Integer siteId, String code) {
QueryHandler queryHandler = getQueryHandler("from CmsCategory bean");
if (notEmpty(siteId)) {
queryHandler.condition("bean.siteId = :siteId").setParameter("siteId", siteId);
}
if (notEmpty(code)) {
queryHandler.condition("bean.code = :code").setParameter("code", code);
}
queryHandler.order("bean.sort asc,bean.id asc");
PageHandler page = getPage(queryHandler, 1, 1);
List<CmsCategory> list = (List<CmsCategory>) page.getList();
if(list.size()>0){
return list.get(0);
}
return null;

}

@Override @Override
protected CmsCategory init(CmsCategory entity) { protected CmsCategory init(CmsCategory entity) {
if (empty(entity.getChildIds())) { if (empty(entity.getChildIds())) {
Expand Down
Expand Up @@ -130,4 +130,8 @@ public void updateContents(Serializable id, int num) {


@Autowired @Autowired
private CmsCategoryDao dao; private CmsCategoryDao dao;

public CmsCategory getCategoryByCode(int siteId, String code) {
return dao.getCategory(siteId, code);
}
} }
Expand Up @@ -165,6 +165,18 @@ private Integer[] getCategoryIds(Boolean containChild, Integer categoryId) {
return categoryIds; return categoryIds;
} }


public CmsContent getLastEntity(Integer categoryId) {
CmsCategory category = categoryDao.getEntity(categoryId);
if(category != null){
PageHandler pageHandler = dao.getPage(category.getSiteId(), null, category.getId(), null, false, null, null, null, null, null, null, null, null, null, null, null, null, null, 1, 1);
List<CmsContent> list = (List<CmsContent>) pageHandler.getList();
if(list.size()>0){
return list.get(0);
}
}
return null;
}

@Autowired @Autowired
private CmsContentDao dao; private CmsContentDao dao;
@Autowired @Autowired
Expand Down
Expand Up @@ -38,7 +38,7 @@ public String save(SysUser entity, String repassword, Integer[] roleIds, HttpSer
entity.setName(trim(entity.getName())); entity.setName(trim(entity.getName()));
entity.setNickName(trim(entity.getNickName())); entity.setNickName(trim(entity.getNickName()));
entity.setPassword(trim(repassword)); entity.setPassword(trim(repassword));
repassword = trim(entity.getNickName()); repassword = trim(entity.getPassword());
if (verifyNotEmpty("username", entity.getName(), model) || verifyNotEmpty("nickname", entity.getNickName(), model) if (verifyNotEmpty("username", entity.getName(), model) || verifyNotEmpty("nickname", entity.getNickName(), model)
|| verifyNotUserName("username", entity.getName(), model) || verifyNotUserName("username", entity.getName(), model)
|| verifyNotNickName("nickname", entity.getNickName(), model)) { || verifyNotNickName("nickname", entity.getNickName(), model)) {
Expand Down
Expand Up @@ -22,13 +22,21 @@ public class CmsCategoryDirective extends AbstractTemplateDirective {
@Override @Override
public void execute(RenderHandler handler) throws IOException, Exception { public void execute(RenderHandler handler) throws IOException, Exception {
Integer id = handler.getInteger("id"); Integer id = handler.getInteger("id");
String code = handler.getString("code");

SysSite site = getSite(handler); SysSite site = getSite(handler);
if (notEmpty(id)) { if (notEmpty(id)) {
CmsCategory entity = service.getEntity(id); CmsCategory entity = service.getEntity(id);
if (notEmpty(entity) && site.getId() == entity.getSiteId()) { if (notEmpty(entity) && site.getId() == entity.getSiteId()) {
handler.put("object", entity).render(); handler.put("object", entity).render();
} }
} else { }else if(notEmpty(code)){
CmsCategory entity = service.getCategoryByCode(site.getId(), code);
if (notEmpty(entity) && site.getId() == entity.getSiteId()) {
handler.put("object", entity).render();
}

}else{
Integer[] ids = handler.getIntegerArray("ids"); Integer[] ids = handler.getIntegerArray("ids");
if (notEmpty(ids)) { if (notEmpty(ids)) {
List<CmsCategory> entityList = service.getEntitys(ids); List<CmsCategory> entityList = service.getEntitys(ids);
Expand Down
Expand Up @@ -22,25 +22,35 @@ public class CmsContentDirective extends AbstractTemplateDirective {
@Override @Override
public void execute(RenderHandler handler) throws IOException, Exception { public void execute(RenderHandler handler) throws IOException, Exception {
Long id = handler.getLong("id"); Long id = handler.getLong("id");
Integer categoryId = handler.getInteger("categoryId");

CmsContent entity = null;

SysSite site = getSite(handler); SysSite site = getSite(handler);
if (notEmpty(id)) { if (notEmpty(id)) {
CmsContent entity = service.getEntity(id); entity = service.getEntity(id);
if (notEmpty(entity) && site.getId() == entity.getSiteId()) {
handler.put("object", entity).render(); }else if(notEmpty(categoryId)){
} entity = service.getLastEntity(categoryId);

} else { } else {
Long[] ids = handler.getLongArray("ids"); Long[] ids = handler.getLongArray("ids");
if (notEmpty(ids)) { if (notEmpty(ids)) {
List<CmsContent> entityList = service.getEntitys(ids); List<CmsContent> entityList = service.getEntitys(ids);
Map<String, CmsContent> map = new LinkedHashMap<String, CmsContent>(); Map<String, CmsContent> map = new LinkedHashMap<String, CmsContent>();
for (CmsContent entity : entityList) { for (CmsContent _entity : entityList) {
if (site.getId() == entity.getSiteId()) { if (site.getId() == _entity.getSiteId()) {
map.put(String.valueOf(entity.getId()), entity); map.put(String.valueOf(_entity.getId()), _entity);
} }
} }
handler.put("map", map).render(); handler.put("map", map).render();
} }
} }


if (notEmpty(entity) && site.getId() == entity.getSiteId()) {
handler.put("object", entity).render();
}
} }


@Autowired @Autowired
Expand Down
Expand Up @@ -5,6 +5,7 @@
// Generated 2016-7-16 11:54:15 by com.sanluan.common.source.SourceMaker // Generated 2016-7-16 11:54:15 by com.sanluan.common.source.SourceMaker


import java.io.IOException; import java.io.IOException;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
Expand All @@ -26,7 +27,12 @@ public void execute(RenderHandler handler) throws IOException, Exception {
if (notEmpty(code) && notEmpty(subcode)) { if (notEmpty(code) && notEmpty(subcode)) {
SysConfig entity = service.getEntity(site.getId(), code, subcode); SysConfig entity = service.getEntity(site.getId(), code, subcode);
if (notEmpty(entity)) { if (notEmpty(entity)) {
handler.put("object", getExtendMap(entity.getData())).render(); Map<String, String> extendMap = getExtendMap(entity.getData());
if(extendMap.size()>0){
handler.put("object", extendMap).render();
}else{
handler.put("data", entity.getData()).render();
}
} }
} }
} }
Expand Down
Expand Up @@ -9,8 +9,15 @@
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;


import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;


Expand All @@ -34,7 +41,6 @@ public class FreeMarkerUtils extends Base {
/** /**
* @param templateFilePath * @param templateFilePath
* @param destFilePath * @param destFilePath
* @param config
* @param model * @param model
* @throws IOException * @throws IOException
* @throws TemplateException * @throws TemplateException
Expand Down Expand Up @@ -75,6 +81,8 @@ public static void makeFileByFile(String templateFilePath, String destFilePath,
throws MalformedTemplateNameException, ParseException, IOException, TemplateException { throws MalformedTemplateNameException, ParseException, IOException, TemplateException {
Template t = configuration.getTemplate(templateFilePath); Template t = configuration.getTemplate(templateFilePath);
File destFile = new File(destFilePath); File destFile = new File(destFilePath);


if (override || append || !destFile.exists()) { if (override || append || !destFile.exists()) {
File parent = destFile.getParentFile(); File parent = destFile.getParentFile();
if (null != parent) { if (null != parent) {
Expand All @@ -86,6 +94,7 @@ public static void makeFileByFile(String templateFilePath, String destFilePath,
Writer out = new BufferedWriter(new OutputStreamWriter(outputStream, DEFAULT_CHARSET)); Writer out = new BufferedWriter(new OutputStreamWriter(outputStream, DEFAULT_CHARSET));
t.process(model, out); t.process(model, out);
out.close(); out.close();
destFile.setReadable(true, false);
} finally { } finally {
try { try {
if (notEmpty(outputStream)) { if (notEmpty(outputStream)) {
Expand All @@ -103,7 +112,6 @@ public static void makeFileByFile(String templateFilePath, String destFilePath,


/** /**
* @param template * @param template
* @param configurationuration
* @return * @return
* @throws TemplateException * @throws TemplateException
* @throws IOException * @throws IOException
Expand Down
@@ -1,7 +1,7 @@
jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://127.0.0.1/public_cms?useUnicode\=true&characterEncoding\=UTF-8&zeroDateTimeBehavior\=round jdbc.url=jdbc\:mysql\://${db_host}/pcms?useUnicode\=true&characterEncoding\=UTF-8&zeroDateTimeBehavior\=round
jdbc.username=publiccms jdbc.username=${db_username}
jdbc.password=publiccms_password jdbc.password=${db_password}
cpool.checkoutTimeout=20000 cpool.checkoutTimeout=20000
cpool.autoCommitOnClose=true cpool.autoCommitOnClose=true
cpool.minPoolSize=5 cpool.minPoolSize=5
Expand Down
@@ -1,5 +1,5 @@
freemarkerSettings.new_builtin_class_resolver=allows_nothing freemarkerSettings.new_builtin_class_resolver=allows_nothing
freemarkerSettings.template_update_delay=1800 freemarkerSettings.template_update_delay=5
freemarkerSettings.defaultEncoding=UTF-8 freemarkerSettings.defaultEncoding=UTF-8
freemarkerSettings.url_escaping_charset=UTF-8 freemarkerSettings.url_escaping_charset=UTF-8
freemarkerSettings.locale=zh_CN freemarkerSettings.locale=zh_CN
Expand Down
@@ -1,4 +1,4 @@
site.filePath=/data/publiccms/ site.filePath=/media/gaojie/Java/workspace-jee/PublicCMS/data/publiccms
site.masterSiteIds=1 site.masterSiteIds=1
site.defaultSiteId=1 site.defaultSiteId=1
ftp.enable=true ftp.enable=true
Expand Down
2 changes: 1 addition & 1 deletion publiccms-by-maven/src/main/resources/simplelog.properties
Expand Up @@ -13,6 +13,6 @@ org.apache.commons.logging.simplelog.dateTimeFormat=MM-dd HH:mm:ss:SSS zzz


#Default logging detail level for all instances of SimpleLog. Must be one of: trace debug info warn error fatal If not specified, defaults to info. #Default logging detail level for all instances of SimpleLog. Must be one of: trace debug info warn error fatal If not specified, defaults to info.
#org.apache.commons.logging.simplelog.defaultlog=info #org.apache.commons.logging.simplelog.defaultlog=info
org.apache.commons.logging.simplelog.defaultlog=info org.apache.commons.logging.simplelog.defaultlog=${log_level}
## Configure logging levels ## Configure logging levels
#org.apache.commons.logging.simplelog.log.org.springframework.jdbc=trace #org.apache.commons.logging.simplelog.log.org.springframework.jdbc=trace

0 comments on commit 72bf65f

Please sign in to comment.