Skip to content

Commit

Permalink
meger
Browse files Browse the repository at this point in the history
  • Loading branch information
sanluan committed Jan 9, 2017
1 parent 72bf65f commit 818438d
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 39 deletions.
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 @@ -34,7 +34,7 @@ public class FreeMarkerUtils extends Base {
/** /**
* @param templateFilePath * @param templateFilePath
* @param destFilePath * @param destFilePath
* @param config * @param configuration
* @param model * @param model
* @throws IOException * @throws IOException
* @throws TemplateException * @throws TemplateException
Expand Down Expand Up @@ -86,6 +86,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 +104,7 @@ public static void makeFileByFile(String templateFilePath, String destFilePath,


/** /**
* @param template * @param template
* @param configurationuration * @param configuration
* @return * @return
* @throws TemplateException * @throws TemplateException
* @throws IOException * @throws IOException
Expand Down
2 changes: 1 addition & 1 deletion publiccms-by-maven/pom.xml
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>publiccms</groupId> <groupId>publiccms</groupId>
<artifactId>cms</artifactId> <artifactId>cms</artifactId>
<version>V2017.01.01</version> <version>V2016.0828</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>
Expand Down
Expand Up @@ -22,35 +22,25 @@ 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)) {
entity = service.getEntity(id); CmsContent entity = service.getEntity(id);

if (notEmpty(entity) && site.getId() == entity.getSiteId()) {
}else if(notEmpty(categoryId)){ handler.put("object", entity).render();
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,7 +5,6 @@
// 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 @@ -27,12 +26,7 @@ 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)) {
Map<String, String> extendMap = getExtendMap(entity.getData()); handler.put("object", getExtendMap(entity.getData())).render();
if(extendMap.size()>0){
handler.put("object", extendMap).render();
}else{
handler.put("data", entity.getData()).render();
}
} }
} }
} }
Expand Down
Expand Up @@ -9,15 +9,8 @@
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 @@ -41,6 +34,7 @@ public class FreeMarkerUtils extends Base {
/** /**
* @param templateFilePath * @param templateFilePath
* @param destFilePath * @param destFilePath
* @param configuration
* @param model * @param model
* @throws IOException * @throws IOException
* @throws TemplateException * @throws TemplateException
Expand Down Expand Up @@ -81,8 +75,6 @@ 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 Down Expand Up @@ -112,6 +104,7 @@ public static void makeFileByFile(String templateFilePath, String destFilePath,


/** /**
* @param template * @param template
* @param configuration
* @return * @return
* @throws TemplateException * @throws TemplateException
* @throws IOException * @throws IOException
Expand Down
@@ -1,4 +1,4 @@
site.filePath=/media/gaojie/Java/workspace-jee/PublicCMS/data/publiccms site.filePath=/data/publiccms/
site.masterSiteIds=1 site.masterSiteIds=1
site.defaultSiteId=1 site.defaultSiteId=1
ftp.enable=true ftp.enable=true
Expand Down

0 comments on commit 818438d

Please sign in to comment.