Commit 6201a48d authored by 信 赵's avatar 信 赵
Browse files

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/net/mingsoft/cms/action/web/MCmsAction.java
#	src/main/java/net/mingsoft/cms/biz/IArticleBiz.java
#	src/main/java/net/mingsoft/cms/biz/impl/ArticleBizImpl.java
#	src/main/java/net/mingsoft/cms/dao/IArticleDao.java
#	src/main/java/net/mingsoft/cms/dao/IArticleDao.xml
#	src/main/java/net/mingsoft/cms/resources/resources_zh_CN.properties
parents dfad56af 2d19a084
package net.mingsoft.cms.action;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.annotation.LogAnn;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.constant.e.BusinessTypeEnum;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.entity.CategoryEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 分类管理控制层
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Api(value = "分类接口")
@Controller("cmsCategoryAction")
@RequestMapping("/${ms.manager.path}/cms/category")
public class CategoryAction extends BaseAction{
/**
* 注入分类业务层
*/
@Autowired
private ICategoryBiz categoryBiz;
/**
* 返回主界面index
*/
@GetMapping("/index")
public String index(HttpServletResponse response,HttpServletRequest request){
return "/cms/category/index";
}
/**
* 查询分类列表
* @param category 分类实体
*/
@ApiOperation(value = "查询分类列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categorySort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryUrl", value = "内容模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryImg", value = "缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required =false,paramType="query"),
@ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryManagerId", value = "发布用户id", required =false,paramType="query"),
@ApiImplicitParam(name = "appId", value = "应用编号", required =false,paramType="query"),
@ApiImplicitParam(name = "dictId", value = "字典对应编号", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryPath", value = "栏目路径", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
@RequestMapping("/list")
@ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
category.setAppId(BasicUtil.getAppId());
BasicUtil.startPage();
List categoryList = categoryBiz.query(category);
return ResultData.build().success(new EUListBean(categoryList,(int)BasicUtil.endPage(categoryList).getTotal()));
}
/**
* 返回编辑界面category_form
*/
@GetMapping("/form")
public String form(@ModelAttribute CategoryEntity category,HttpServletResponse response,HttpServletRequest request,ModelMap model){
if(category.getId()!=null){
BaseEntity categoryEntity = categoryBiz.getEntity(Integer.parseInt(category.getId()));
model.addAttribute("categoryEntity",categoryEntity);
}
return "/cms/category/form";
}
/**
* 获取分类
* @param category 分类实体
*/
@ApiOperation(value = "获取分类列表接口")
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
@GetMapping("/get")
@ResponseBody
public ResultData get(@ModelAttribute @ApiIgnore CategoryEntity category,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
if(category.getId()==null) {
return ResultData.build().error();
}
category.setAppId(BasicUtil.getAppId());
CategoryEntity _category = (CategoryEntity)categoryBiz.getEntity(Integer.parseInt(category.getId()));
return ResultData.build().success(_category);
}
@ApiOperation(value = "保存分类列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =true,paramType="query"),
@ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categorySort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryUrl", value = "内容模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryImg", value = "缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required =false,paramType="query"),
@ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryManagerId", value = "发布用户id", required =false,paramType="query"),
@ApiImplicitParam(name = "appId", value = "应用编号", required =false,paramType="query"),
@ApiImplicitParam(name = "dictId", value = "字典对应编号", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryPath", value = "栏目路径", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
/**
* 保存分类
* @param category 分类实体
*/
@PostMapping("/save")
@ResponseBody
@LogAnn(title = "保存分类", businessType = BusinessTypeEnum.INSERT)
@RequiresPermissions("cms:category:save")
public ResultData save(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response, HttpServletRequest request) {
//验证栏目管理名称的值是否合法
if(StringUtil.isBlank(category.getCategoryTitle())){
return ResultData.build().error(getResString("err.empty", this.getResString("category.title")));
}
if(!StringUtil.checkLength(category.getCategoryTitle()+"", 1, 100)){
return ResultData.build().error(getResString("err.length", this.getResString("category.title"), "1", "100"));
}
if(!StringUtil.checkLength(category.getCategoryPath()+"", 1, 100)){
return ResultData.build().error(getResString("err.length", this.getResString("category.path"), "1", "100"));
}
if(!StringUtil.checkLength(category.getCategoryParentId()+"", 1, 100)){
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
}
category.setAppId(BasicUtil.getAppId());
categoryBiz.saveEntity(category);
return ResultData.build().success(category);
}
/**
* @param category 分类实体
*/
@ApiOperation(value = "批量删除分类列表接口")
@PostMapping("/delete")
@ResponseBody
@LogAnn(title = "删除分类", businessType = BusinessTypeEnum.DELETE)
@RequiresPermissions("cms:category:del")
public ResultData delete(@RequestBody List<CategoryEntity> categorys,HttpServletResponse response, HttpServletRequest request) {
for(int i = 0;i<categorys.size();i++){
categoryBiz.delete(Integer.parseInt(categorys.get(i).getId()));
}
return ResultData.build().success();
}
/**
* 更新分类列表
* @param category 分类实体
*/
@ApiOperation(value = "更新分类列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"),
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =true,paramType="query"),
@ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categorySort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryUrl", value = "内容模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryImg", value = "缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required =false,paramType="query"),
@ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryManagerId", value = "发布用户id", required =false,paramType="query"),
@ApiImplicitParam(name = "appId", value = "应用编号", required =false,paramType="query"),
@ApiImplicitParam(name = "dictId", value = "字典对应编号", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryPath", value = "栏目路径", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
@PostMapping("/update")
@ResponseBody
@LogAnn(title = "更新分类", businessType = BusinessTypeEnum.UPDATE)
@RequiresPermissions("cms:category:update")
public ResultData update(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response,
HttpServletRequest request) {
//验证栏目管理名称的值是否合法
if(StringUtil.isBlank(category.getCategoryTitle())){
return ResultData.build().error(getResString("err.empty", this.getResString("category.title")));
}
if(!StringUtil.checkLength(category.getCategoryTitle()+"", 1, 100)){
return ResultData.build().error(getResString("err.length", this.getResString("category.title"), "1", "100"));
}
if(!StringUtil.checkLength(category.getCategoryPath()+"", 0, 100)){
return ResultData.build().error(getResString("err.length", this.getResString("category.path"), "1", "100"));
}
if(!StringUtil.checkLength(category.getCategoryParentId()+"", 0, 100)){
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
}
//判断是否选择子级为所属栏目
CategoryEntity _category = new CategoryEntity();
_category.setCategoryParentId(category.getId());
_category.setAppId(BasicUtil.getAppId());
List<CategoryEntity> categoryList = categoryBiz.queryChilds(_category);
for(CategoryEntity item:categoryList){
if(item.getId().equals(category.getCategoryId())){
return ResultData.build().error(getResString("cannot.select.child"));
}
}
category.setAppId(BasicUtil.getAppId());
categoryBiz.updateEntity(category);
return ResultData.build().success(category);
}
}
\ No newline at end of file
package net.mingsoft.cms.action;
import java.io.File;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import net.mingsoft.basic.action.BaseAction;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.biz.ICategoryBiz;
import net.mingsoft.basic.biz.IColumnBiz;
import net.mingsoft.basic.biz.IModelBiz;
import net.mingsoft.basic.constant.Const;
import net.mingsoft.basic.constant.ModelCode;
import net.mingsoft.basic.constant.e.SessionConstEnum;
import net.mingsoft.basic.entity.ColumnEntity;
import net.mingsoft.basic.entity.ManagerEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.FileUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.mdiy.util.ParserUtil;
/**
* 铭飞MS平台,通用栏目分类,为了区分文章栏目与其他栏目的权限,该类是从basic模块复制过来
* @author 铭飞开发团队
* @version
* 版本号:100-000-000<br/>
* 创建日期:2017年8月9日<br/>
* 历史修订:<br/>
*/
@Controller("articleColumnAction")
@RequestMapping("/${ms.manager.path}/cms/column")
public class ColumnAction extends BaseAction{
/**
* 栏目业务层
*/
@Autowired
private IColumnBiz columnBiz;
@Autowired
private ICategoryBiz categoryBiz;
/**
* 模块业务层注入
*/
@Autowired
private IModelBiz modelBiz;
/**
* 返回主界面index
*/
@RequestMapping("/index")
@RequiresPermissions("cms:column:view")
public String index(HttpServletResponse response,HttpServletRequest request,ModelMap model){
model.addAttribute("model", "cms");
return "/basic/column/index";
}
/**
* 栏目添加跳转页面
*
* @return
*/
@RequestMapping("/add")
public String add(HttpServletRequest request,ModelMap model) {
// 站点ID
int appId =BasicUtil.getAppId();
List<ColumnEntity> list = columnBiz.queryAll(appId, BasicUtil.getModelCodeId(net.mingsoft.cms.constant.ModelCode.CMS_COLUMN.toString()));
ColumnEntity columnSuper = new ColumnEntity();
model.addAttribute("appId",appId);
model.addAttribute("columnSuper", columnSuper);
model.addAttribute("column",new ColumnEntity());
model.addAttribute("listColumn", JSONArray.toJSONString(list));
model.addAttribute("model", "cms");
return "/basic/column/form";
}
/**
* 后台验证填写的栏目信息是否合法
* @param column 栏目信息
* @param response
* @return false:不合法 true:合法
*/
private boolean checkForm(ColumnEntity column, HttpServletResponse response){
//栏目标题空值验证
if(StringUtils.isBlank(column.getCategoryTitle())){
this.outJson( response, ModelCode.COLUMN, false, getResString("err.empty", this.getResString("categoryTitle")));
return false;
}
//栏目标题长度验证
if(!StringUtil.checkLength(column.getCategoryTitle(), 1, 31)){
this.outJson( response, ModelCode.COLUMN, false, getResString("err.length", this.getResString("categoryTitle"), "1", "30"));
return false;
}
//栏目属性空值验证
if(StringUtils.isBlank(column.getColumnType()+"")){
this.outJson( response, ModelCode.COLUMN, false, getResString("err.empty", this.getResString("columnType")));
return false;
}
return true;
}
/**
* 组织栏目链接地址
* @param request
* @param column 栏目实体
*/
private void columnPath(HttpServletRequest request,ColumnEntity column){
StringBuffer columnPath = new StringBuffer();
String file = BasicUtil.getRealPath("")+ParserUtil.HTML+File.separator+ column.getAppId();
String delFile = "";
//修改栏目路径时,删除已存在的文件夹
column = (ColumnEntity) columnBiz.getEntity(column.getCategoryId());
delFile = file + column.getColumnPath();
if(!StringUtils.isBlank(delFile)){
File delFileName = new File(delFile);
delFileName.delete();
}
//若为顶级栏目,则路径为:/+栏目ID
if(column.getCategoryCategoryId() == 0){
column.setColumnPath(File.separator+column.getCategoryId());
file = file + File.separator + column.getCategoryId();
} else {
List<ColumnEntity> list = columnBiz.queryParentColumnByColumnId(column.getCategoryId());
if(list != null){
StringBuffer temp = new StringBuffer();
for(int i = list.size()-1; i>=0; i--){
ColumnEntity entity = list.get(i);
columnPath.append(File.separator).append(entity.getCategoryId());
temp.append(File.separator).append(entity.getCategoryId());
}
column.setColumnPath(columnPath.append(File.separator).append(column.getCategoryId()).toString());
file = file + temp.toString() + File.separator + column.getCategoryId();
}
}
columnBiz.updateEntity(column);
//生成文件夹
File fileName = new File(file);
fileName.mkdir();
}
/**
* @param column 栏目表实体
* <i>column参数包含字段信息参考:</i><br/>
* columnCategoryid:多个columnCategoryid直接用逗号隔开,例如columnCategoryid=1,2,3,4
* 批量删除栏目表
* <dt><span class="strong">返回</span></dt><br/>
* <dd>{code:"错误编码",<br/>
* result:"true|false",<br/>
* resultMsg:"错误信息"<br/>
* }</dd>
*/
@RequestMapping("/delete")
@ResponseBody
public void delete(HttpServletResponse response, HttpServletRequest request) {
int[] ids = BasicUtil.getInts("ids", ",");
ColumnEntity column =new ColumnEntity();
for(int i=0;i<ids.length;i++){
column = (ColumnEntity) columnBiz.getEntity(ids[i]);
columnBiz.deleteCategory(ids[i]);
FileUtil.del(column);
};
this.outJson(response, true);
}
/**
* 栏目更新页面跳转
* @param columnId 栏目ID
* @param request
* @param model
* @return 编辑栏目页
*/
@RequestMapping("/{columnId}/edit")
public String edit(@PathVariable int columnId, HttpServletRequest request,ModelMap model) {
// 获取管理实体
ManagerEntity managerSession = (ManagerEntity) BasicUtil.getSession( SessionConstEnum.MANAGER_SESSION);
// 站点ID
int appId = BasicUtil.getAppId();
List<ColumnEntity> list = new ArrayList<ColumnEntity>();
// 判断管理员权限,查询其管理的栏目集合
list = columnBiz.queryAll(appId, BasicUtil.getModelCodeId(net.mingsoft.cms.constant.ModelCode.CMS_COLUMN.toString()));
//查询当前栏目实体
ColumnEntity column = (ColumnEntity) columnBiz.getEntity(columnId);
model.addAttribute("appId",appId);
model.addAttribute("column", column);
model.addAttribute("columnc", column.getCategoryId());
ColumnEntity columnSuper = new ColumnEntity();
// 获取父栏目对象
if (column.getCategoryCategoryId() != Const.COLUMN_TOP_CATEGORY_ID) {
columnSuper = (ColumnEntity) columnBiz.getEntity(column.getCategoryCategoryId());
}
model.addAttribute("columnSuper", columnSuper);
model.addAttribute("listColumn", JSONArray.toJSONString(list));
model.addAttribute("model", "cms");
return "/basic/column/form";
}
/**
* 栏目首页面列表显示
*/
@SuppressWarnings("deprecation")
@RequestMapping("/list")
public void list(@ModelAttribute ColumnEntity column,HttpServletResponse response, HttpServletRequest request,ModelMap model) {
// 站点ID有session获取
int websiteId = BasicUtil.getAppId();
// 需要打开的栏目节点树的栏目ID
List list = columnBiz.queryAll(websiteId, BasicUtil.getModelCodeId(net.mingsoft.cms.constant.ModelCode.CMS_COLUMN.toString()));
EUListBean _list = new EUListBean(list, list.size());
this.outJson(response, net.mingsoft.base.util.JSONArray.toJSONString(_list));
}
/**
* 栏目添加
*
* @param column
* 栏目对象
* @return 返回页面跳转
*/
@RequestMapping("/save")
public void save(@ModelAttribute ColumnEntity column,HttpServletRequest request,HttpServletResponse response) {
if(!checkForm(column,response)){
return;
}
column.setCategoryAppId( BasicUtil.getAppId());
column.setAppId(BasicUtil.getAppId());
column.setCategoryManagerId(getManagerBySession(request).getManagerId());
column.setCategoryDateTime(new Timestamp(System.currentTimeMillis()));
column.setCategoryModelId(BasicUtil.getModelCodeId(net.mingsoft.cms.constant.ModelCode.CMS_COLUMN.toString()));
if(column.getColumnType()==ColumnEntity.ColumnTypeEnum.COLUMN_TYPE_COVER.toInt()){
column.setColumnListUrl(null);
}
columnBiz.saveCategory(column);
this.columnPath(request,column);
this.outJson(response, ModelCode.COLUMN, true,null,JSONArray.toJSONString(column.getCategoryId()));
}
/**
* 更新栏目
* @param column 栏目实体
* @param request
* @param response
*/
@RequestMapping("/update")
@ResponseBody
public void update(@ModelAttribute ColumnEntity column,HttpServletRequest request,HttpServletResponse response) {
//获取站点ID
int websiteId = BasicUtil.getAppId();
//检测栏目信息是否合法
if(!checkForm(column,response)){
return;
}
//若栏目管理属性为单页,则栏目的列表模板地址设为Null
if(column.getColumnType()==ColumnEntity.ColumnTypeEnum.COLUMN_TYPE_COVER.toInt()){
column.setColumnListUrl(null);
}
column.setCategoryManagerId(getManagerBySession(request).getManagerId());
column.setAppId(websiteId);
columnBiz.updateCategory(column);
this.columnPath(request,column);
//查询当前栏目是否有子栏目,
List<ColumnEntity> childList = columnBiz.queryChild(column.getCategoryId(), websiteId,BasicUtil.getModelCodeId(net.mingsoft.cms.constant.ModelCode.CMS_COLUMN.toString()),null);
if(childList != null && childList.size()>0){
//改变子栏目的顶级栏目ID为当前栏目的父级栏目ID
for(int i=0;i<childList.size();i++){
childList.get(i).setCategoryCategoryId(column.getCategoryId());
childList.get(i).setCategoryManagerId(getManagerBySession(request).getManagerId());
childList.get(i).setAppId(websiteId);
columnBiz.updateCategory(childList.get(i));
//组织子栏目链接地址
this.columnPath(request, childList.get(i));
}
}
this.outJson(response, ModelCode.COLUMN, true,null,JSONArray.toJSONString(column.getCategoryId()));
}
}
package net.mingsoft.cms.action;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.annotation.LogAnn;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.constant.e.BusinessTypeEnum;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.entity.ContentEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 文章管理控制层
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Api(value = "文章接口")
@Controller("cmsContentAction")
@RequestMapping("/${ms.manager.path}/cms/content")
public class ContentAction extends BaseAction{
/**
* 注入文章业务层
*/
@Autowired
private IContentBiz contentBiz;
/**
* 返回主界面index
*/
@GetMapping("/index")
public String index(HttpServletResponse response,HttpServletRequest request){
return "/cms/content/index";
}
/**
* 返回主界面main
*/
@GetMapping("/main")
public String main(HttpServletResponse response,HttpServletRequest request){
return "/cms/content/main";
}
/**
* 查询文章列表
* @param content 文章实体
*/
@ApiOperation(value = "查询文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
@ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
@ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
@ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =false,paramType="query"),
@ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
@ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
@ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
@ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
@RequestMapping("/list")
@ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
content.setAppId(BasicUtil.getAppId());
BasicUtil.startPage();
List contentList = contentBiz.query(content);
return ResultData.build().success(new EUListBean(contentList,(int)BasicUtil.endPage(contentList).getTotal()));
}
/**
* 返回编辑界面content_form
*/
@GetMapping("/form")
public String form(@ModelAttribute ContentEntity content,HttpServletResponse response,HttpServletRequest request,ModelMap model){
if(content.getId()!=null){
BaseEntity contentEntity = contentBiz.getEntity(Integer.parseInt(content.getId()));
model.addAttribute("contentEntity",contentEntity);
}
return "/cms/content/form";
}
/**
* 获取文章
* @param content 文章实体
*/
@ApiOperation(value = "获取文章列表接口")
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
@GetMapping("/get")
@ResponseBody
public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
if(content.getId()==null) {
return ResultData.build().error();
}
content.setAppId(BasicUtil.getAppId());
ContentEntity _content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
return ResultData.build().success(_content);
}
@ApiOperation(value = "保存文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
@ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
@ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
@ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =true,paramType="query"),
@ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
@ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
@ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
@ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
/**
* 保存文章
* @param content 文章实体
*/
@PostMapping("/save")
@ResponseBody
@LogAnn(title = "保存文章", businessType = BusinessTypeEnum.INSERT)
@RequiresPermissions("cms:content:save")
public ResultData save(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response, HttpServletRequest request) {
//验证文章标题的值是否合法
if(StringUtil.isBlank(content.getContentTitle())){
return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));
}
if(!StringUtil.checkLength(content.getContentTitle()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.title"), "0", "200"));
}
if(!StringUtil.checkLength(content.getContentAuthor()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.author"), "0", "200"));
}
if(!StringUtil.checkLength(content.getContentSource()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.source"), "0", "200"));
}
//验证发布时间的值是否合法
if(StringUtil.isBlank(content.getContentDatetime())){
return ResultData.build().error(getResString("err.empty", this.getResString("content.datetime")));
}
if(!StringUtil.checkLength(content.getContentUrl()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
}
content.setAppId(BasicUtil.getAppId());
contentBiz.saveEntity(content);
return ResultData.build().success(content);
}
/**
* @param content 文章实体
*/
@ApiOperation(value = "批量删除文章列表接口")
@PostMapping("/delete")
@ResponseBody
@LogAnn(title = "删除文章", businessType = BusinessTypeEnum.DELETE)
@RequiresPermissions("cms:content:del")
public ResultData delete(@RequestBody List<ContentEntity> contents,HttpServletResponse response, HttpServletRequest request) {
int[] ids = new int[contents.size()];
for(int i = 0;i<contents.size();i++){
ids[i] =Integer.parseInt(contents.get(i).getId()) ;
}
contentBiz.delete(ids);
return ResultData.build().success();
}
/**
* 更新文章列表
* @param content 文章实体
*/
@ApiOperation(value = "更新文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"),
@ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
@ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
@ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
@ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =true,paramType="query"),
@ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
@ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
@ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
@ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
@PostMapping("/update")
@ResponseBody
@LogAnn(title = "更新文章", businessType = BusinessTypeEnum.UPDATE)
@RequiresPermissions("cms:content:update")
public ResultData update(@ModelAttribute @ApiIgnore ContentEntity content, HttpServletResponse response,
HttpServletRequest request) {
//验证文章标题的值是否合法
if(StringUtil.isBlank(content.getContentTitle())){
return ResultData.build().error(getResString("err.empty", this.getResString("content.title")));
}
if(!StringUtil.checkLength(content.getContentTitle()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.title"), "0", "200"));
}
if(!StringUtil.checkLength(content.getContentAuthor()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.author"), "0", "200"));
}
if(!StringUtil.checkLength(content.getContentSource()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.source"), "0", "200"));
}
//验证发布时间的值是否合法
if(StringUtil.isBlank(content.getContentDatetime())){
return ResultData.build().error(getResString("err.empty", this.getResString("content.datetime")));
}
if(!StringUtil.checkLength(content.getContentUrl()+"", 0, 200)){
return ResultData.build().error(getResString("err.length", this.getResString("content.url"), "0", "200"));
}
content.setAppId(BasicUtil.getAppId());
contentBiz.updateEntity(content);
return ResultData.build().success(content);
}
}
\ No newline at end of file
......@@ -21,15 +21,18 @@ The MIT License (MIT) * Copyright (c) 2016 铭飞科技(mingsoft.net)
package net.mingsoft.cms.action;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.io.FileUtil;
import net.mingsoft.basic.biz.IModelBiz;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.bean.ContentBean;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.entity.CategoryEntity;
import net.mingsoft.cms.util.CmsParserUtil;
import net.mingsoft.mdiy.util.ParserUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -40,31 +43,20 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import net.mingsoft.basic.action.BaseAction;
import net.mingsoft.basic.biz.IColumnBiz;
import net.mingsoft.basic.biz.IModelBiz;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.entity.CategoryEntity;
import net.mingsoft.basic.entity.ColumnEntity;
import net.mingsoft.cms.bean.ColumnArticleIdBean;
import net.mingsoft.cms.biz.IArticleBiz;
import net.mingsoft.cms.constant.ModelCode;
import net.mingsoft.cms.util.CmsParserUtil;
import net.mingsoft.mdiy.biz.IContentModelBiz;
import net.mingsoft.mdiy.biz.IContentModelFieldBiz;
import cn.hutool.core.io.FileUtil;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.mdiy.util.ParserUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @ClassName: GeneraterAction
* @Description:TODO 生成器
* @author: 铭飞开发团队
* @date: 2018年1月31日 下午2:52:07
*
*
* @Copyright: 2018 www.mingsoft.net Inc. All rights reserved.
*/
@Controller("cmsGenerater")
......@@ -76,13 +68,13 @@ public class GeneraterAction extends BaseAction {
* 文章管理业务层
*/
@Autowired
private IArticleBiz articleBiz;
private IContentBiz contentBiz;
/**
* 栏目管理业务层
*/
@Autowired
private IColumnBiz columnBiz;
private ICategoryBiz categoryBiz;
/**
* 模块管理业务层
......@@ -94,37 +86,22 @@ public class GeneraterAction extends BaseAction {
private String managerPath;
/**
* 新增字段业务层
*/
@Autowired
protected IContentModelFieldBiz fieldBiz;
/**
* 自定义模型业务层
*/
@Autowired
protected IContentModelBiz contentBiz;
/**
* 更新主页
*
*
* @return
*/
@RequestMapping("/index")
public String index(HttpServletRequest request, ModelMap model) {
// 该站点ID有session提供
int websiteId = BasicUtil.getAppId();
Integer modelId = modelBiz.getEntityByModelCode(ModelCode.CMS_COLUMN).getModelId(); // 查询当前模块编号
// 获取所有的内容管理栏目
List<ColumnEntity> list = columnBiz.queryAll(websiteId, modelId);
model.addAttribute("list", JSONArray.toJSONString(list));
model.addAttribute("now", new Date());
return "/cms/generate/index";
}
/**
* 生成主页
*
*
* @param request
* @param response
*/
......@@ -136,7 +113,7 @@ public class GeneraterAction extends BaseAction {
String tmpFileName = request.getParameter("url");
// 生成后的文件名称
String generateFileName = request.getParameter("position");
// 获取文件所在路径 首先判断用户输入的模版文件是否存在
if (!FileUtil.exist(ParserUtil.buildTempletPath())) {
this.outJson(response, false, getResString("templet.file"));
......@@ -150,50 +127,59 @@ public class GeneraterAction extends BaseAction {
}
}
}
/**
* 生成列表的静态页面
*
*
* @param request
* @param response
* @param columnId
* @param CategoryId
*/
@RequestMapping("/{columnId}/genernateColumn")
@RequestMapping("/{CategoryId}/genernateColumn")
@RequiresPermissions("cms:generate:column")
@ResponseBody
public void genernateColumn(HttpServletRequest request, HttpServletResponse response, @PathVariable int columnId) {
public void genernateColumn(HttpServletRequest request, HttpServletResponse response, @PathVariable int CategoryId) {
// 获取站点id
AppEntity app = BasicUtil.getApp();
List<ColumnEntity> columns = new ArrayList<ColumnEntity>();
List<CategoryEntity> columns = new ArrayList<CategoryEntity>();
// 如果栏目id小于0则更新所有的栏目,否则只更新选中的栏目
int modelId = BasicUtil.getModelCodeId(ModelCode.CMS_COLUMN); // 查询当前模块编号
if (columnId > 0) {
List<CategoryEntity> categorys = columnBiz.queryChildrenCategory(columnId, app.getAppId(), modelId);
for (CategoryEntity c : categorys) {
columns.add((ColumnEntity) columnBiz.getEntity(c.getCategoryId()));
}
if (CategoryId>0) {
CategoryEntity categoryEntity = new CategoryEntity();
categoryEntity.setId(CategoryId+"");
categoryEntity.setAppId(app.getAppId());
columns = categoryBiz.queryChilds(categoryEntity);
} else {
// 获取所有的内容管理栏目
columns = columnBiz.queryAll(app.getAppId(), modelId);
CategoryEntity categoryEntity=new CategoryEntity();
categoryEntity.setAppId(app.getAppId());
columns = categoryBiz.query(categoryEntity);
}
List<ColumnArticleIdBean> articleIdList = null;
List<ContentBean> articleIdList = null;
try {
// 1、设置模板文件夹路径
// 获取栏目列表模版
for (ColumnEntity column : columns) {
for (CategoryEntity column : columns) {
// 判断模板文件是否存在
if (!FileUtil.exist(ParserUtil.buildTempletPath(column.getColumnUrl()))) {
if (!FileUtil.exist(ParserUtil.buildTempletPath(column.getCategoryUrl()))) {
continue;
}
articleIdList = articleBiz.queryIdsByCategoryIdForParser(column.getCategoryId(), null, null);
articleIdList = contentBiz.queryIdsByCategoryIdForParser(column.getId(), null, null);
// 判断列表类型
switch (column.getColumnType()) {
case ColumnEntity.COLUMN_TYPE_LIST: // 列表
switch (column.getCategoryType()) {
//TODO 暂时先用字符串代替
case "1": // 列表
CmsParserUtil.generateList(column, articleIdList.size());
break;
case ColumnEntity.COLUMN_TYPE_COVER:// 单页
case "2":// 单页
if(articleIdList.size()==0){
ContentBean columnArticleIdBean=new ContentBean();
CopyOptions copyOptions=CopyOptions.create();
copyOptions.setIgnoreError(true);
BeanUtil.copyProperties(column,columnArticleIdBean,copyOptions);
articleIdList.add(columnArticleIdBean);
}
CmsParserUtil.generateBasic(articleIdList);
break;
}
......@@ -207,7 +193,7 @@ public class GeneraterAction extends BaseAction {
/**
* 根据栏目id更新所有的文章
*
*
* @param request
* @param response
* @param columnId
......@@ -215,13 +201,13 @@ public class GeneraterAction extends BaseAction {
@RequestMapping("/{columnId}/generateArticle")
@RequiresPermissions("cms:generate:article")
@ResponseBody
public void generateArticle(HttpServletRequest request, HttpServletResponse response, @PathVariable int columnId) {
public void generateArticle(HttpServletRequest request, HttpServletResponse response, @PathVariable String columnId) {
String dateTime = request.getParameter("dateTime");
// 网站风格物理路径
List<ColumnArticleIdBean> articleIdList = null;
List<ContentBean> articleIdList = null;
try {
// 查出所有文章(根据选择栏目)包括子栏目
articleIdList = articleBiz.queryIdsByCategoryIdForParser(columnId, dateTime, null);
articleIdList = contentBiz.queryIdsByCategoryIdForParser(columnId, dateTime, null);
// 有符合条件的新闻就更新
if (articleIdList.size() > 0) {
CmsParserUtil.generateBasic(articleIdList);
......@@ -232,12 +218,12 @@ public class GeneraterAction extends BaseAction {
this.outJson(response, false);
}
}
/**
* 用户预览主页
*
*
* @param request
* @return
*/
......@@ -249,4 +235,4 @@ public class GeneraterAction extends BaseAction {
+ File.separator + position + ParserUtil.HTML_SUFFIX;
return "redirect:" + indexPosition;
}
}
\ No newline at end of file
}
/**
The MIT License (MIT) * Copyright (c) 2016 铭飞科技(mingsoft.net)
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.mingsoft.cms.action.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.filter.DateValueFilter;
import net.mingsoft.basic.action.BaseAction;
import net.mingsoft.basic.bean.ListBean;
import net.mingsoft.basic.biz.IColumnBiz;
import net.mingsoft.basic.entity.ColumnEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.biz.IArticleBiz;
import net.mingsoft.cms.entity.ArticleEntity;
import net.mingsoft.mdiy.biz.IContentModelBiz;
import net.mingsoft.mdiy.biz.IContentModelFieldBiz;
import net.mingsoft.mdiy.entity.ContentModelEntity;
import springfox.documentation.annotations.ApiIgnore;
/**
*
* @ClassName: ArticleAction
* @Description:TODO 前段文章控制,如果标签不能满足可以使用这个控制来满足用户的查询文章需求,主要是通过ajax返回json数据格式
* @author: 铭飞开发团队
* @date: 2018年1月31日 下午2:52:44
*
* @Copyright: 2018 www.mingsoft.net Inc. All rights reserved.
*/
@Controller("jsonApiArticle")
@RequestMapping("/mcms/article")
public class ArticleAction extends BaseAction {
/**
* 文章管理业务处理层
*/
@Autowired
private IArticleBiz articleBiz;
/**
* 栏目管理业务处理层
*/
@Autowired
private IColumnBiz columnBiz;
/**
* 内容模型管理业务处理层
*/
@Autowired
private IContentModelBiz contentModelBiz;
/**
* 自定义字段管理业务处理层
*/
@Autowired
private IContentModelFieldBiz fieldBiz;
/**
* 文章信息
*
* @param basicId
* 文章编号
* <dt><span class="strong">返回</span></dt><br/>
* {"basicCategoryId":分类编号,basicTitle
* :"标题",basicDescription:"描述",basicThumbnails:"缩略图",
* basicDateTime:"发布时间",basicUpdateTime:"更新时间","basicHit":点击数,
* "basicId":编号 articleContent:"文章内容","basicSort":排序,[自定义模型字段]}
*/
@GetMapping("/{basicId}/detail")
@ResponseBody
public void detail(@PathVariable int basicId, HttpServletRequest request, HttpServletResponse response) {
ArticleEntity article = articleBiz.getById(basicId);
if (article == null) {
this.outJson(response, "");
return;
}
// 获取文章栏目id获取栏目实体
ColumnEntity column = (ColumnEntity) columnBiz.getEntity(article.getBasicCategoryId());
ContentModelEntity contentModel = (ContentModelEntity) contentModelBiz
.getEntity(column.getColumnContentModelId());
// 判断内容模型的值
if (contentModel != null) {
Map where = new HashMap();
// 压入basicId字段的值
where.put("basicId", basicId);
// 遍历所有的字段实体,得到字段名列表信息
List<String> listFieldName = new ArrayList<String>();
listFieldName.add("basicId");
// 查询新增字段的信息
List fieldLists = fieldBiz.queryBySQL(contentModel.getCmTableName(), listFieldName, where);
if (fieldLists.size() > 0) {
Map map = (Map) fieldLists.get(0);
article.setExtendsFields(map);
}
}
this.outJson(response, JSONObject.toJSONStringWithDateFormat(article, "yyyy-MM-dd hh:mm:ss"));
}
/**
* 文章列表信息
*
* @param pageSize
* 一页显示数量
* @param pageNum
* 当前页码
* @param basicCategoryId
* 分类编号
* <dt><span class="strong">返回</span></dt><br/>
* {"list":"[{
* "basicTitle":"标题",
* "basicDescription":"描述",
* "basicThumbnails":"缩略图",
* "basicDateTime":"发布时间",
* "basicUpdateTime":"更新时间",
* "basicHit":点击数,
* "basicId":编号,
* "articleContent":文章内容,
* "articleAuthor":文章作者
* "articleType":文章属性,
* "articleSource":文章的来源,
* "articleUrl":文章跳转链接地址,
* "articleKeyword":文章关键字,
* "articleCategoryId":文章所属的分类Id,
* "articleTypeLinkURL":文章分类url地址,主要是用户生成html使用,
* "order":"排序方式",
* "orderBy":"排序字段
* }],
* "page":{"endRow": 2, 当前页面最后一个元素在数据库中的行号
* "firstPage": 1, 第一页页码
* "hasNextPage": true存在下一页false不存在,
* "hasPreviousPage": true存在上一页false不存在,
* "isFirstPage": true是第一页false不是第一页,
* "isLastPage": true是最后一页false不是最后一页,
* "lastPage": 最后一页的页码,
* "navigatePages": 导航数量,实现 1...5.6.7....10效果,
* "navigatepageNums": []导航页码集合,
* "nextPage": 下一页,
* "pageNum": 当前页码,
* "pageSize": 一页显示数量,
* "pages": 总页数,
* "prePage": 上一页,
* "size": 总记录,
* "startRow":当前页面第一个元素在数据库中的行号,
* "total":总记录数量
* }
*/
@RequestMapping(value = "/list",method= RequestMethod.GET)
@ApiOperation(value="文章列表信息")
@ResponseBody
public void list(@ModelAttribute @ApiIgnore ArticleEntity article, HttpServletRequest request, HttpServletResponse response) {
int appId = BasicUtil.getAppId();
int[] ids = null;
if (article.getBasicCategoryId()>0) {
ids = new int[]{article.getBasicCategoryId()};
}
//默认为desc排序
boolean isOrder = true;
if(!StringUtils.isBlank(article.getOrder())){
String basicOrder = article.getOrder();
if(basicOrder.equalsIgnoreCase("asc")){
isOrder = false;
}
}
BasicUtil.startPage();
List<ArticleEntity> list = articleBiz.query(appId, ids, null, null, article.getOrderBy(), isOrder, null, null, article);
for(ArticleEntity _article : list){
// 获取文章栏目id获取栏目实体
ColumnEntity column = (ColumnEntity) columnBiz.getEntity(_article.getBasicCategoryId());
ContentModelEntity contentModel = (ContentModelEntity) contentModelBiz
.getEntity(column.getColumnContentModelId());
// 判断内容模型的值
if (contentModel != null) {
Map where = new HashMap();
// 压入basicId字段的值
where.put("basicId", _article.getBasicId());
// 遍历所有的字段实体,得到字段名列表信息
List<String> listFieldName = new ArrayList<String>();
listFieldName.add("basicId");
// 查询新增字段的信息
List fieldLists = fieldBiz.queryBySQL(contentModel.getCmTableName(), listFieldName, where);
if (fieldLists.size() > 0) {
Map map = (Map) fieldLists.get(0);
_article.setExtendsFields(map);
}
}
}
this.outJson(response, JSONArray.toJSONString(new ListBean(list, BasicUtil.endPage(list)),new DateValueFilter("yyyy-MM-dd HH:mm:ss")));
}
}
\ No newline at end of file
package net.mingsoft.cms.action.web;
import java.util.List;
import java.io.File;
import java.util.ArrayList;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import net.mingsoft.base.entity.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.BindingResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.ui.ModelMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.entity.CategoryEntity;
import net.mingsoft.base.util.JSONObject;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.base.filter.DateValueFilter;
import net.mingsoft.base.filter.DoubleValueFilter;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.annotation.LogAnn;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
/**
* 分类管理控制层
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Api(value = "分类接口")
@Controller("WebcmsCategoryAction")
@RequestMapping("/cms/category")
public class CategoryAction extends net.mingsoft.cms.action.BaseAction{
/**
* 注入分类业务层
*/
@Autowired
private ICategoryBiz categoryBiz;
/**
* 查询分类列表
* @param category 分类实体
*/
@ApiOperation(value = "查询分类列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categorySort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryUrl", value = "内容模板", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryImg", value = "缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required =false,paramType="query"),
@ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryManagerId", value = "发布用户id", required =false,paramType="query"),
@ApiImplicitParam(name = "appId", value = "应用编号", required =false,paramType="query"),
@ApiImplicitParam(name = "dictId", value = "字典对应编号", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryPath", value = "栏目路径", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
@RequestMapping("/list")
@ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
BasicUtil.startPage();
List categoryList = categoryBiz.query(category);
return ResultData.build().success(new EUListBean(categoryList,(int)BasicUtil.endPage(categoryList).getTotal()));
}
/**
* 获取分类
* @param category 分类实体
*/
@ApiOperation(value = "获取分类列表接口")
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
@GetMapping("/get")
@ResponseBody
public ResultData get(@ModelAttribute @ApiIgnore CategoryEntity category,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
if(category.getId()==null) {
return ResultData.build().error();
}
CategoryEntity _category = (CategoryEntity)categoryBiz.getEntity(Integer.parseInt(category.getId()));
return ResultData.build().success(_category);
}
}
\ No newline at end of file
package net.mingsoft.cms.action.web;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.entity.ContentEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 文章管理控制层
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Api(value = "文章接口")
@Controller("WebcmsContentAction")
@RequestMapping("/cms/content")
public class ContentAction extends net.mingsoft.cms.action.BaseAction{
/**
* 注入文章业务层
*/
@Autowired
private IContentBiz contentBiz;
/**
* 查询文章列表
* @param content 文章实体
*/
@ApiOperation(value = "查询文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
@ApiImplicitParam(name = "contentCategoryId", value = "所属栏目", required =false,paramType="query"),
@ApiImplicitParam(name = "contentType", value = "文章类型", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDisplay", value = "是否显示", required =false,paramType="query"),
@ApiImplicitParam(name = "contentAuthor", value = "文章作者", required =false,paramType="query"),
@ApiImplicitParam(name = "contentSource", value = "文章来源", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDatetime", value = "发布时间", required =false,paramType="query"),
@ApiImplicitParam(name = "contentSort", value = "自定义顺序", required =false,paramType="query"),
@ApiImplicitParam(name = "contentImg", value = "文章缩略图", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDescription", value = "描述", required =false,paramType="query"),
@ApiImplicitParam(name = "contentKeyword", value = "关键字", required =false,paramType="query"),
@ApiImplicitParam(name = "contentDetails", value = "文章内容", required =false,paramType="query"),
@ApiImplicitParam(name = "contentUrl", value = "文章跳转链接地址", required =false,paramType="query"),
@ApiImplicitParam(name = "appid", value = "文章管理的应用id", required =false,paramType="query"),
@ApiImplicitParam(name = "createBy", value = "创建人", required =false,paramType="query"),
@ApiImplicitParam(name = "createDate", value = "创建时间", required =false,paramType="query"),
@ApiImplicitParam(name = "updateBy", value = "修改人", required =false,paramType="query"),
@ApiImplicitParam(name = "updateDate", value = "修改时间", required =false,paramType="query"),
@ApiImplicitParam(name = "del", value = "删除标记", required =false,paramType="query"),
@ApiImplicitParam(name = "id", value = "编号", required =false,paramType="query"),
})
@RequestMapping("/list")
@ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model,BindingResult result) {
BasicUtil.startPage();
List contentList = contentBiz.query(content);
return ResultData.build().success(new EUListBean(contentList,(int)BasicUtil.endPage(contentList).getTotal()));
}
/**
* 获取文章
* @param content 文章实体
*/
@ApiOperation(value = "获取文章列表接口")
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
@GetMapping("/get")
@ResponseBody
public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content,HttpServletResponse response, HttpServletRequest request,@ApiIgnore ModelMap model){
if(content.getId()==null) {
return ResultData.build().error();
}
ContentEntity _content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
return ResultData.build().success(_content);
}
@ApiOperation(value = "查看文章点击数")
@ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
@GetMapping(value = "/{contentId}/hit")
@ResponseBody
public void hit(@PathVariable @ApiIgnore int contentId, HttpServletRequest request, HttpServletResponse response){
if(contentId<=0){
this.outString(response, "document.write(0)");
return;
}
ContentEntity content = (ContentEntity)contentBiz.getEntity(contentId);
if(content == null){
this.outString(response, "document.write(0)");
return;
}
if(content.getAppId() == null || content.getAppId() != BasicUtil.getAppId()){
this.outString(response, "document.write(0)");
return;
}
this.outString(response, "document.write(" + content.getContentHit() + ")");
return;
}
}
\ No newline at end of file
/**
The MIT License (MIT) * Copyright (c) 2016 铭飞科技(mingsoft.net)
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.mingsoft.cms.action.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import net.mingsoft.basic.biz.IColumnBiz;
import net.mingsoft.mdiy.biz.IContentModelBiz;
import net.mingsoft.mdiy.biz.IContentModelFieldBiz;
import net.mingsoft.basic.entity.ColumnEntity;
import net.mingsoft.mdiy.entity.ContentModelEntity;
import net.mingsoft.mdiy.entity.ContentModelFieldEntity;
import net.mingsoft.base.action.BaseAction;
import net.mingsoft.basic.util.BasicUtil;
/**
*
*
*
* <p>
* <b>铭飞科技</b>
* </p>
*
* <p>
* Copyright: Copyright (c) 2014 - 2015
* </p>
*
* @author 史爱华
*
* <p>
* Comments: 供前端页面获取自定义模型中字段实体信息
* </p>
*
* <p>
* Create Date:2015-07-11
* </p>
*
* <p>
* Modification history:
* </p>
*/
@Controller("webField")
@RequestMapping("/field")
public class FieldAction extends BaseAction{
/**
* 栏目业务层
*/
@Autowired
private IColumnBiz columnBiz;
/**
* 内容模型业务层
*/
@Autowired
private IContentModelBiz contentModelBiz;
/**
* 字段管理业务层
*/
@Autowired
private IContentModelFieldBiz fieldBiz;
/**
*
* 根据当前栏目id和字段名称获取自定义模型中的字段实体信息
* @param request
* @param response
*/
@RequestMapping("/{columId}/getEntity")
@ResponseBody
public void getEntity(@PathVariable int columId,HttpServletRequest request, HttpServletResponse response) {
System.out.println("111");
BasicUtil.setSession("xxx", "888");
System.err.println("session:"+BasicUtil.getSession("xxx"));
//获取字段名称
String fieldFieldName = request.getParameter("fieldFieldName");
//根据栏目id获取栏目实体
ColumnEntity column = (ColumnEntity) this.columnBiz.getEntity(columId);
if(column==null){
this.outJson(response, this.getResString("err"));
return;
}else{
//判断该栏目下是存在内容模型
if(column.getColumnContentModelId()>0){
//获取当前栏目对应的内容模型
ContentModelEntity contentModel = (ContentModelEntity) this.contentModelBiz.getEntity(column.getColumnContentModelId());
if(contentModel==null){
this.outJson(response, this.getResString("err"));
return;
}
//获取字段实体
ContentModelFieldEntity field = fieldBiz.getEntityByCmId(column.getColumnContentModelId(), fieldFieldName);
//返回字段实体
this.outJson(response, JSONObject.toJSONString(field));
}
}
}
}
\ No newline at end of file
......@@ -21,46 +21,40 @@
package net.mingsoft.cms.action.web;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hutool.core.io.FileUtil;
import com.github.pagehelper.PageHelper;
import net.mingsoft.base.constant.Const;
import net.mingsoft.basic.util.SpringUtil;
import net.mingsoft.cms.constant.e.ColumnTypeEnum;
import net.mingsoft.mdiy.biz.IContentModelBiz;
import net.mingsoft.mdiy.entity.ContentModelEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.PageUtil;
import freemarker.core.ParseException;
import freemarker.template.MalformedTemplateNameException;
import freemarker.template.TemplateNotFoundException;
import net.mingsoft.basic.biz.IColumnBiz;
import net.mingsoft.basic.entity.ColumnEntity;
import net.mingsoft.base.constant.Const;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.bean.ColumnArticleIdBean;
import net.mingsoft.cms.biz.IArticleBiz;
import net.mingsoft.cms.entity.ArticleEntity;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.bean.ContentBean;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.entity.CategoryEntity;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.cms.util.CmsParserUtil;
import net.mingsoft.mdiy.bean.PageBean;
import net.mingsoft.mdiy.biz.IModelBiz;
import net.mingsoft.mdiy.biz.IPageBiz;
import net.mingsoft.mdiy.entity.ModelEntity;
import net.mingsoft.mdiy.entity.PageEntity;
import net.mingsoft.mdiy.parser.TagParser;
import net.mingsoft.mdiy.util.ParserUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 动态生成页面,需要后台配置自定义页数据
......@@ -82,49 +76,27 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
* 文章管理业务处理层
*/
@Autowired
private IArticleBiz articleBiz;
private IContentBiz contentBiz;
/**
* 栏目业务层
*/
@Autowired
private IColumnBiz columnBiz;
private ICategoryBiz categoryBiz;
// 如商城就为:/mall/{key}.do
/**
* 前段会员中心所有页面都可以使用该方法 请求地址例如: /{diy}.do,例如登陆界面,与注册界面都可以使用
*
* @param key
* 搜索标签;
*/
@RequestMapping("/{diy}.do")
@ExceptionHandler(java.lang.NullPointerException.class)
public void diy(@PathVariable(value = "diy") String diy, HttpServletRequest req, HttpServletResponse resp) {
Map map = BasicUtil.assemblyRequestMap();
map.put(ParserUtil.URL, BasicUtil.getUrl());
//动态解析
map.put(ParserUtil.IS_DO,true);
//设置动态请求的模块路径
map.put(ParserUtil.MODEL_NAME, "mcms");
//解析后的内容
String content = "";
PageEntity page = new PageEntity();
page.setPageKey(diy);
//根据请求路径查询模版文件
PageEntity _page = (PageEntity) pageBiz.getEntity(page);
try {
content = CmsParserUtil.generate(_page.getPagePath(), map, isMobileDevice(req));
} catch (TemplateNotFoundException e) {
e.printStackTrace();
} catch (MalformedTemplateNameException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
this.outString(resp, content);
}
public static final String SEARCH = "search";
/**
* 自定义模型
*/
@Autowired
private IModelBiz modelBiz;
/**
* 动态列表页
......@@ -158,9 +130,6 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
* 动态列表页
* @param req
* @param resp
* @param pageNumber 设置列表当前页
* @param typeid 栏目编号
* @param size 显示条数
*/
@GetMapping("/list.do")
public void list(HttpServletRequest req, HttpServletResponse resp) {
......@@ -170,7 +139,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
int size = BasicUtil.getInt(ParserUtil.SIZE,10);
//获取文章总数
List<ColumnArticleIdBean> columnArticles = articleBiz.queryIdsByCategoryIdForParser(typeId, null, null);
List<ContentBean> columnArticles = contentBiz.queryIdsByCategoryIdForParser(String.valueOf(typeId), null, null);
//判断栏目下是否有文章
if(columnArticles.size()==0){
this.outJson(resp, false);
......@@ -196,7 +165,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
String content = "";
try {
//根据模板路径,参数生成
content = CmsParserUtil.generate(columnArticles.get(0).getColumnListUrl(),map, isMobileDevice(req));
content = CmsParserUtil.generate(columnArticles.get(0).getCategoryListUrl(),map, isMobileDevice(req));
} catch (TemplateNotFoundException e) {
e.printStackTrace();
} catch (MalformedTemplateNameException e) {
......@@ -216,7 +185,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
@GetMapping("/view.do")
public void view(String orderby,String order,HttpServletRequest req, HttpServletResponse resp) {
//参数文章编号
ArticleEntity article = (ArticleEntity) articleBiz.getEntity(BasicUtil.getInt(ParserUtil.ID));
ContentEntity article = (ContentEntity) contentBiz.getEntity(BasicUtil.getInt(ParserUtil.ID));
if(ObjectUtil.isNull(article)){
this.outJson(resp, null,false,getResString("err.empty", this.getResString("id")));
return;
......@@ -230,7 +199,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
PageBean page = new PageBean();
//根据文章编号查询栏目详情模版
ColumnEntity column = (ColumnEntity) columnBiz.getEntity(article.getBasicCategoryId());
CategoryEntity column = (CategoryEntity) categoryBiz.getEntity(Integer.parseInt(article.getContentCategoryId()));
//解析后的内容
String content = "";
Map map = BasicUtil.assemblyRequestMap();
......@@ -240,39 +209,38 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
map.put(ParserUtil.MODEL_NAME, "mcms");
map.put(ParserUtil.URL, BasicUtil.getUrl());
map.put(ParserUtil.PAGE, page);
map.put(ParserUtil.ID, article.getArticleID());
List<ColumnArticleIdBean> articleIdList = articleBiz.queryIdsByCategoryIdForParser(column.getCategoryCategoryId(), null, null,orderby,order);
map.put(ParserUtil.ID, article.getId());
List<ContentBean> articleIdList = contentBiz.queryIdsByCategoryIdForParser(column.getCategoryId(), null, null,orderby,order);
Map<Object, Object> contentModelMap = new HashMap<Object, Object>();
ContentModelEntity contentModel = null;
ModelEntity contentModel = null;
for (int artId = 0; artId < articleIdList.size();) {
//如果不是当前文章则跳过
if(articleIdList.get(artId).getArticleId() != article.getArticleID()){
if(articleIdList.get(artId).getArticleId() != Integer.parseInt(article.getId())){
artId++;
continue;
}
// 文章的栏目路径
String articleColumnPath = articleIdList.get(artId).getColumnPath();
String articleColumnPath = articleIdList.get(artId).getCategoryPath();
// 文章的栏目模型编号
int columnContentModelId = articleIdList.get(artId).getColumnContentModelId();
String columnContentModelId = articleIdList.get(artId).getMdiyModelId();
Map<String, Object> parserParams = new HashMap<String, Object>();
parserParams.put(ParserUtil.COLUMN, articleIdList.get(artId));
// 判断当前栏目是否有自定义模型
if (columnContentModelId > 0) {
if ( StringUtils.isNotBlank(columnContentModelId)) {
// 通过当前栏目的模型编号获取,自定义模型表名
if (contentModelMap.containsKey(columnContentModelId)) {
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getCmTableName());
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
} else {
// 通过栏目模型编号获取自定义模型实体
contentModel = (ContentModelEntity) SpringUtil.getBean(IContentModelBiz.class)
.getEntity(columnContentModelId);
contentModel=(ModelEntity)modelBiz.getEntity(Integer.parseInt(columnContentModelId));
// 将自定义模型编号设置为key值
contentModelMap.put(columnContentModelId, contentModel.getCmTableName());
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getCmTableName());
contentModelMap.put(columnContentModelId, contentModel.getModelTableName());
parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
}
}
// 第一篇文章没有上一篇
if (artId > 0) {
ColumnArticleIdBean preCaBean = articleIdList.get(artId - 1);
ContentBean preCaBean = articleIdList.get(artId - 1);
//判断当前文档是否与上一页文章在同一栏目下,并且不能使用父栏目字符串,因为父栏目中没有所属栏目编号
if(articleColumnPath.contains(preCaBean.getCategoryId()+"")){
page.setPreId(preCaBean.getArticleId());
......@@ -280,7 +248,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
// 最后一篇文章没有下一篇
if (artId + 1 < articleIdList.size()) {
ColumnArticleIdBean nextCaBean = articleIdList.get(artId + 1);
ContentBean nextCaBean = articleIdList.get(artId + 1);
//判断当前文档是否与下一页文章在同一栏目下并且不能使用父栏目字符串,因为父栏目中没有所属栏目编号
if(articleColumnPath.contains(nextCaBean.getCategoryId()+"")){
page.setNextId(nextCaBean.getArticleId());
......@@ -290,7 +258,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
try {
//根据模板路径,参数生成
content = CmsParserUtil.generate(column.getColumnUrl(), map, isMobileDevice(req));
content = CmsParserUtil.generate(column.getCategoryUrl(), map, isMobileDevice(req));
} catch (TemplateNotFoundException e) {
e.printStackTrace();
} catch (MalformedTemplateNameException e) {
......@@ -302,4 +270,206 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction {
}
this.outString(resp, content);
}
/**
* 实现前端页面的文章搜索
*
* @param request
* 搜索id
* @param response
*/
@RequestMapping(value = "search")
@ResponseBody
public void search(HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> map = new HashMap<>();
// 读取请求字段
Map<String, String[]> field = request.getParameterMap();
// 文章字段集合
Map<String, Object> articleFieldName = new HashMap<String, Object>();
// 自定义字段集合
Map<String, String> diyFieldName = new HashMap<String, String>();
CategoryEntity column = null; // 当前栏目
ModelEntity contentModel = null; // 栏目对应模型
List<DiyModelMap> fieldValueList = new ArrayList<DiyModelMap>(); // 栏目对应字段的值
int typeId = 0;
String categoryIds = BasicUtil.getString("categoryId");
//当传递了栏目编号,但不是栏目集合
if(!StringUtil.isBlank(categoryIds) && !categoryIds.contains(",")){
typeId = Integer.parseInt(categoryIds);
}
//记录自定义模型字段名
List filedStr = new ArrayList<>();
//根据栏目确定自定义模型
if(typeId>0){
column = (CategoryEntity) categoryBiz.getEntity(Integer.parseInt(typeId+""));
// 获取表单类型的id
if (column != null&&ObjectUtil.isNotNull(column.getMdiyModelId())) {
contentModel = (ModelEntity) modelBiz.getEntity(Integer.parseInt(column.getMdiyModelId()));
if (contentModel != null) {
Map<String,String> fieldMap = contentModel.getFieldMap();
for (String s : fieldMap.keySet()) {
filedStr.add(fieldMap.get(s));
}
map.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName());
}
}
map.put(ParserUtil.COLUMN, column);
}
// 遍历取字段集合
if (field != null) {
for (Map.Entry<String, String[]> entry : field.entrySet()) {
if (entry != null) {
String value = entry.getValue()[0]; // 处理由get方法请求中文乱码问题
if (ObjectUtil.isNull(value)) {
continue;
}
if (request.getMethod().equals(RequestMethod.GET)) { // 如果是get方法需要将请求地址参数转码
try {
value = new String(value.getBytes("ISO-8859-1"), Const.UTF8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
// 保存至自定义字段集合
if (!StringUtil.isBlank(value)) {
diyFieldName.put(entry.getKey(), value);
//判断请求中的是否是自定义模型中的字段
if(filedStr.contains(entry.getKey())){
//设置自定义模型字段和值
DiyModelMap diyMap = new DiyModelMap();
diyMap.setKey(entry.getKey());
diyMap.setValue(value);
fieldValueList.add(diyMap);
}
}
}
}
}
//添加自定义模型的字段和值
if(fieldValueList.size()>0){
map.put("diyModel", fieldValueList);
}
//设置分页类
PageBean page = new PageBean();
//读取模板的分页数量
int size = BasicUtil.getInt(ParserUtil.SIZE,10);
try {
size = TagParser.getPageSize(ParserUtil.read(SEARCH+ParserUtil.HTM_SUFFIX,false ));
} catch (TemplateNotFoundException e1) {
e1.printStackTrace();
} catch (MalformedTemplateNameException e1) {
e1.printStackTrace();
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
//查询数量
int count= contentBiz.getSearchCount(contentModel,fieldValueList,BasicUtil.assemblyRequestMap(),BasicUtil.getAppId(),categoryIds);
int total = PageUtil.totalPage(count, size);
int pageNo = BasicUtil.getInt(ParserUtil.PAGE_NO, 1);
if(pageNo >= total && total!=0) {
pageNo = total;
}
//获取总数
page.setTotal(total);
//设置页面显示数量
page.setSize(size);
//设置列表当前页
page.setPageNo(pageNo);
String str = ParserUtil.PAGE_NO+","+ParserUtil.SIZE;
//设置分页的统一链接
String url = BasicUtil.getUrl()+request.getServletPath() +"?" + BasicUtil.assemblyRequestUrlParams(str.split(","));
String pageNoStr = "&"+ParserUtil.SIZE+"="+size+"&"+ParserUtil.PAGE_NO+"=";
//下一页
String nextUrl = url + pageNoStr+((pageNo+1 > total)?total:pageNo+1);
//首页
String indexUrl = url + pageNoStr + 1;
//尾页
String lastUrl = url + pageNoStr + total;
//上一页 当前页为1时,上一页就是1
String preUrl = url + pageNoStr + ((pageNo==1) ? 1:pageNo-1);
page.setIndexUrl(indexUrl);
page.setNextUrl(nextUrl);
page.setPreUrl(preUrl);
page.setLastUrl(lastUrl);
map.put(ParserUtil.URL, BasicUtil.getUrl());
Map<String, Object> searchMap = BasicUtil.assemblyRequestMap();
searchMap.put(ParserUtil.PAGE_NO, pageNo);
map.put(SEARCH, searchMap);
map.put(ParserUtil.PAGE, page);
//动态解析
map.put(ParserUtil.IS_DO,false);
//设置动态请求的模块路径
map.put(ParserUtil.MODEL_NAME, "mcms");
//解析后的内容
String content = "";
try {
//根据模板路径,参数生成
content = CmsParserUtil.generate(SEARCH+ParserUtil.HTM_SUFFIX,map, isMobileDevice(request));
} catch (TemplateNotFoundException e) {
e.printStackTrace();
} catch (MalformedTemplateNameException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
this.outString(response, content);
}
private Map get(String key, List<Map> fields) {
for (Map field : fields) {
if(key.equals(field.get("key"))){
return field;
}
}
return null;
}
/**
* 存储自定义模型字段和接口参数
* @author 铭飞开源团队
* @date 2019年3月5日
*/
public class DiyModelMap {
String key;
Object value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
}
\ No newline at end of file
/**
The MIT License (MIT) * Copyright (c) 2016 铭飞科技(mingsoft.net)
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.mingsoft.cms.action.web;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.PageUtil;
import freemarker.core.ParseException;
import freemarker.template.MalformedTemplateNameException;
import freemarker.template.TemplateNotFoundException;
import net.mingsoft.base.constant.Const;
import net.mingsoft.basic.action.BaseAction;
import net.mingsoft.basic.biz.ICategoryBiz;
import net.mingsoft.basic.biz.IColumnBiz;
import net.mingsoft.basic.biz.IModelBiz;
import net.mingsoft.basic.entity.ColumnEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.IArticleBiz;
import net.mingsoft.cms.util.CmsParserUtil;
import net.mingsoft.mdiy.bean.PageBean;
import net.mingsoft.mdiy.biz.IContentModelBiz;
import net.mingsoft.mdiy.biz.IContentModelFieldBiz;
import net.mingsoft.mdiy.biz.ISearchBiz;
import net.mingsoft.mdiy.entity.ContentModelEntity;
import net.mingsoft.mdiy.entity.ContentModelFieldEntity;
import net.mingsoft.mdiy.entity.SearchEntity;
import net.mingsoft.mdiy.parser.TagParser;
import net.mingsoft.mdiy.util.ParserUtil;
/**
* 根据搜索结果动态解析模版内容
* @author 铭飞开源团队-Administrator
* @date 2018年12月18日
*/
@Controller(value = "webSearchAction")
@RequestMapping("/cms")
public class SearchAction extends BaseAction {
/**
* 搜索标签;
*/
public static final String SEARCH = "search";
/**
* 搜索的标题;
*/
public static final String BASIC_TITLE = "basic_title";
/**
* 注入文章业务层
*/
@Autowired
private IArticleBiz articleBiz;
/**
* 注入搜索业务层
*/
@Autowired
private ISearchBiz searchBiz;
/**
* 注入栏目业务层
*/
@Autowired
private IColumnBiz columnBiz;
/**
* 内容模型业务层
*/
@Autowired
private IContentModelBiz contentModelBiz;
/**
* 内容字段业务层
*/
@Autowired
private IContentModelFieldBiz fieldBiz;
/**
* 注入分类业务层
*/
@Autowired
private ICategoryBiz categoryBiz;
/**
* 模块管理biz
*/
@Autowired
private IModelBiz modelBiz;
/**
* 实现前端页面的文章搜索
*
* @param request
* @param searchId
* 搜索id
* @param response
*/
@RequestMapping(value = "/{searchId}/search")
@ResponseBody
public void search(HttpServletRequest request, @PathVariable int searchId, HttpServletResponse response) {
SearchEntity _search = new SearchEntity();
_search.setAppId(BasicUtil.getAppId());
_search.setSearchId(searchId);
// 获取对应搜索模型
SearchEntity search = (SearchEntity) searchBiz.getEntity(_search);
//判断当前搜索是否有模板文件
if (ObjectUtil.isNull(search)) {
this.outJson(response, false);
}
Map<String, Object> map = new HashMap<>();
// 读取请求字段
Map<String, String[]> field = request.getParameterMap();
Map<String, String> basicField = getMapByProperties(net.mingsoft.mdiy.constant.Const.BASIC_FIELD);
// 文章字段集合
Map<String, Object> articleFieldName = new HashMap<String, Object>();
// 自定义字段集合
Map<String, String> diyFieldName = new HashMap<String, String>();
ColumnEntity column = null; // 当前栏目
ContentModelEntity contentModel = null; // 栏目对应模型
List<ContentModelFieldEntity> fieldList = new ArrayList<ContentModelFieldEntity>(); // 栏目对应字段
List<DiyModelMap> fieldValueList = new ArrayList<DiyModelMap>(); // 栏目对应字段的值
int typeId = 0;
String categoryIds = BasicUtil.getString("categoryId");
//当传递了栏目编号,但不是栏目集合
if(!StringUtil.isBlank(categoryIds) && !categoryIds.contains(",")){
typeId = Integer.parseInt(categoryIds);
}
//记录自定义模型字段名
List filedStr = new ArrayList<>();
//根据栏目确定自定义模型
if(typeId>0){
column = (ColumnEntity) columnBiz.getEntity(Integer.parseInt(typeId+""));
// 获取表单类型的id
if (column != null) {
contentModel = (ContentModelEntity) contentModelBiz.getEntity(column.getColumnContentModelId());
if (contentModel != null) {
fieldList = fieldBiz.queryListByCmid(contentModel.getCmId());
for (ContentModelFieldEntity cmField : fieldList) {
filedStr.add(cmField.getFieldFieldName());
}
map.put(ParserUtil.TABLE_NAME, contentModel.getCmTableName());
}
}
map.put(ParserUtil.COLUMN, column);
//设置栏目编号
// map.put(ParserUtil.TYPE_ID, typeId);
}
// 遍历取字段集合
if (field != null) {
for (Entry<String, String[]> entry : field.entrySet()) {
if (entry != null) {
String value = entry.getValue()[0]; // 处理由get方法请求中文乱码问题
if (ObjectUtil.isNull(value)) {
continue;
}
if (request.getMethod().equals(RequestMethod.GET)) { // 如果是get方法需要将请求地址参数转吗
try {
value = new String(value.getBytes("ISO-8859-1"),Const.UTF8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
// 若为文章字段,则保存至文章字段集合;否则保存至自定义字段集合
if (ObjectUtil.isNotNull(basicField.get(entry.getKey())) && ObjectUtil.isNotNull(value)) {
articleFieldName.put(entry.getKey(), value);
} else {
if (!StringUtil.isBlank(value)) {
diyFieldName.put(entry.getKey(), value);
//判断请求中的是否是自定义模型中的字段
if(filedStr.contains(entry.getKey())){
//设置自定义模型字段和值
DiyModelMap diyMap = new DiyModelMap();
diyMap.setKey(entry.getKey());
diyMap.setValue(value);
fieldValueList.add(diyMap);
}
}
}
}
}
}
//添加自定义模型的字段和值
if(fieldValueList.size()>0){
map.put("diyModel", fieldValueList);
}
//组织where查询条件
Map whereMap = this.searchMap(articleFieldName, diyFieldName, fieldList);
// 获取符合条件的文章总数
int count = articleBiz.getSearchCount(contentModel, whereMap, BasicUtil.getAppId(), categoryIds);
//设置分页类
PageBean page = new PageBean();
//读取模板的分页数量
int size = BasicUtil.getInt(ParserUtil.SIZE,10);
try {
size = TagParser.getPageSize(ParserUtil.read(search.getSearchTemplets(),false ));
} catch (TemplateNotFoundException e1) {
e1.printStackTrace();
} catch (MalformedTemplateNameException e1) {
e1.printStackTrace();
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
int total = PageUtil.totalPage(count, size);
int pageNo = BasicUtil.getInt(ParserUtil.PAGE_NO, 1);
if(pageNo >= total && total!=0) {
pageNo = total;
}
//获取总数
page.setTotal(total);
//设置页面显示数量
page.setSize(size);
//设置列表当前页
page.setPageNo(pageNo);
String str = ParserUtil.PAGE_NO+","+ParserUtil.SIZE;
//设置分页的统一链接
String url = BasicUtil.getUrl()+request.getServletPath() +"?" + BasicUtil.assemblyRequestUrlParams(str.split(","));
String pageNoStr = "&"+ParserUtil.SIZE+"="+size+"&"+ParserUtil.PAGE_NO+"=";
//下一页
String nextUrl = url + pageNoStr+((pageNo+1 > total)?total:pageNo+1);
//首页
String indexUrl = url + pageNoStr + 1;
//尾页
String lastUrl = url + pageNoStr + total;
//上一页 当前页为1时,上一页就是1
String preUrl = url + pageNoStr + ((pageNo==1) ? 1:pageNo-1);
page.setIndexUrl(indexUrl);
page.setNextUrl(nextUrl);
page.setPreUrl(preUrl);
page.setLastUrl(lastUrl);
map.put(ParserUtil.URL, BasicUtil.getUrl());
Map<String, Object> searchMap = BasicUtil.assemblyRequestMap();
searchMap.put(ParserUtil.PAGE_NO, pageNo);
map.put(SEARCH, searchMap);
map.put(ParserUtil.PAGE, page);
//动态解析
map.put(ParserUtil.IS_DO,false);
//设置动态请求的模块路径
map.put(ParserUtil.MODEL_NAME, "mcms");
//解析后的内容
String content = "";
try {
//根据模板路径,参数生成
content = CmsParserUtil.generate(search.getSearchTemplets(),map, isMobileDevice(request));
} catch (TemplateNotFoundException e) {
e.printStackTrace();
} catch (MalformedTemplateNameException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
this.outString(response, content);
}
/**
* 动态组织查询where条件 获取查询条件的Map key:字段名 value:List 字段的各种判断值 list[0]:是否为自定义字段
* list[1]:是否为整形 list[2]:是否是等值查询 list[3]:字段的值
*
* @param articleField
* 文章字段
* @param diyFieldName
* 动态字段
* @param fields
* 模型对应的字段类型
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
private Map<String, List> searchMap(Map<String, Object> articleField, Map<String, String> diyFieldName,
List fields) {
Map<String, List> map = new HashMap<String, List>();
// 遍历文章中的字段
for (Iterator iter = articleField.keySet().iterator(); iter.hasNext();) {
String key = iter.next().toString();
String fieldValue = articleField.get(key).toString();
List list = new ArrayList();
List listValue = new ArrayList();
// 是否为自定义字段
list.add(false);
// 是否是数字类型,true:不是
list.add(true);
// 是否是模糊查询3
list.add(true);
// 字段值
listValue.add(articleField.get(key));
list.add(listValue);
map.put(key, list);
}
// 遍历字段自定义字段
for (Iterator iter = diyFieldName.keySet().iterator(); iter.hasNext();) {
String key = iter.next().toString();
String fieldValue = diyFieldName.get(key);
// 获取字段实体
ContentModelFieldEntity field = this.get(key, fields);
if (field != null) {
List list = new ArrayList();
// 是否为自定义字段0
list.add(0, true);
List listValue = new ArrayList();
// 字段的值
if (field.getFieldType() == IContentModelFieldBiz.INT || field.getFieldType() == IContentModelFieldBiz.FLOAT) {
// 判断是否为区间查询
if (diyFieldName.get(key).toString().indexOf("-") > 0) {
String[] values = fieldValue.toString().split("-");
// 是否是数字类型,false:是
list.add(false);
// 是否是区间比较 false:是
list.add(false);
// 字段值1
listValue.add(values[0]);
listValue.add(values[1]);
} else {
// 是否是数字类型,false:是2
list.add(false);
// 是否是区间比较 true:不是3
list.add(true);
// 字段值 1
listValue.add(fieldValue);
}
} else {
// 是否是数字类型,true:不是2
list.add(true);
list.add(false);
// 字段值 1
listValue.add(fieldValue);
}
list.add(listValue);
map.put(key, list);
}
}
return map;
}
/**
* 根据字段名称获取字段类型
*
* @param columnName
* 字段名称
* @return 字段实体
*/
private ContentModelFieldEntity get(String columnName, List<ContentModelFieldEntity> fields) {
if (fields == null) {
return null;
}
for (ContentModelFieldEntity field : fields) {
if (field.getFieldFieldName().equals(columnName)) {
return field;
}
}
return null;
}
/**
* 存储自定义模型字段和接口参数
* @author 铭飞开源团队
* @date 2019年3月5日
*/
public class DiyModelMap {
String key;
Object value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
}
}
package net.mingsoft.cms.aop;
import net.mingsoft.basic.aop.BaseAop;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.biz.IHistoryLogBiz;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.cms.entity.HistoryLogEntity;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @author 铭飞开源团队
* @date 2019/12/23
*/
@Component
@Aspect
public class CotentAop extends BaseAop {
/**
* 注入文章业务
*/
@Autowired
private IContentBiz contentBiz;
/**
* 注入浏览记录业务
*/
@Autowired
private IHistoryLogBiz historyLogBiz;
/**
* 文章浏览记录,
* 如果该文章该ip已经记录过,则不在重复记录
* @param pjp
* @return
* @throws Throwable
*/
@Around("execution(* net.mingsoft.cms.action.web.ContentAction.get(..))")
public Object get(ProceedingJoinPoint pjp) throws Throwable{
// 获取方法参数
ContentEntity content = getType(pjp, ContentEntity.class);
// 如果id为空则直接发行
if(content.getId()==null) {
return pjp.proceed();
}
content = (ContentEntity)contentBiz.getEntity(Integer.parseInt(content.getId()));
//如果文章不存在则直接发行
if(content == null){
return pjp.proceed();
}
//查询判断该ip是否已经有浏览记录了
HistoryLogEntity historyLog = new HistoryLogEntity();
historyLog.setContentId(content.getId());
historyLog.setHlIp(BasicUtil.getIp());
historyLog.setHlIsMobile(BasicUtil.isMobileDevice());
HistoryLogEntity _historyLog = (HistoryLogEntity)historyLogBiz.getEntity(historyLog);
//如果该ip该文章没有浏览记录则保存浏览记录
//并且更新点击数
if(_historyLog == null || StringUtils.isBlank(_historyLog.getId())){
historyLog.setCreateDate(new Date());
historyLogBiz.saveEntity(historyLog);
//更新点击数
ContentEntity updateContent = new ContentEntity();
updateContent.setId(content.getId());
if(content.getContentHit() == null){
updateContent.setContentHit(1);
}else{
updateContent.setContentHit(content.getContentHit()+1);
}
contentBiz.updateEntity(updateContent);
}
return pjp.proceed();
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package net.mingsoft.cms.biz;
import net.mingsoft.base.biz.IBaseBiz;
/**
* 文章浏览记录业务
* @author 铭飞开发团队
* 创建日期:2019-12-23 9:24:03<br/>
* 历史修订:<br/>
*/
public interface IHistoryLogBiz extends IBaseBiz {
}
\ No newline at end of file
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment