Commit 64448fbf authored by 肖健鑫's avatar 肖健鑫
Browse files

更新mcms/src/main/java/net/mingsoft/cms/action/BaseAction.java,...

更新mcms/src/main/java/net/mingsoft/cms/action/BaseAction.java, mcms/src/main/java/net/mingsoft/cms/action/ContentAction.java, mcms/src/main/java/net/mingsoft/cms/action/GeneraterAction.java, mcms/src/main/java/net/mingsoft/cms/action/CategoryAction.java
parent 3407664c
Pipeline #55 failed with stage
in 2 minutes and 3 seconds
/**
* The MIT License (MIT)
* Copyright (c) 2012-present 铭软科技(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;
import java.util.MissingResourceException;
/**
* @Author: 铭飞开源团队--huise
* @Date: 2019/8/9 20:47
*/
public class BaseAction extends net.mingsoft.basic.action.BaseAction{
@Override
protected String getResString(String key) {
// TODO Auto-generated method stub
String str = "";
try {
str = super.getResString(key);
} catch (MissingResourceException e) {
str = getLocaleString(key,net.mingsoft.cms.constant.Const.RESOURCES);
}
return str;
}
}
/**
* The MIT License (MIT)
* Copyright (c) 2012-present 铭软科技(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:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p>
* 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;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.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.PinYinUtil;
import net.mingsoft.basic.util.StringUtil;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.constant.e.CategoryTypeEnum;
import net.mingsoft.cms.entity.CategoryEntity;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.mdiy.util.ParserUtil;
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.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
* 分类管理控制层
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Api(tags = {"后端-内容模块接口"})
@Controller("cmsCategoryAction")
@RequestMapping("/${ms.manager.path}/cms/category")
public class CategoryAction extends BaseAction {
/**
* 注入分类业务层
*/
@Autowired
private ICategoryBiz categoryBiz;
/**
* 返回主界面index
* @return
*/
@GetMapping("/index")
@RequiresPermissions("cms:category:view")
public String index() {
return "/cms/category/index";
}
/**
* 查询分类列表接口
* @param category 栏目实体
* @return
*/
@ApiOperation(value = "查询分类列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required = false, paramType = "query"),
})
@RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category) {
List categoryList = categoryBiz.list(new LambdaQueryWrapper<CategoryEntity>(category));
return ResultData.build().success(new EUListBean(categoryList, categoryList.size()));
}
/**
* 返回编辑界面category_form
* @param category 栏目
* @return
*/
@GetMapping("/form")
public String form(@ModelAttribute CategoryEntity category, ModelMap model) {
model.addAttribute("appId", BasicUtil.getApp().getAppId());
return "/cms/category/form";
}
/**
* 获取分类
* @param category 分类实体
*/
@ApiOperation(value = "获取分类列表接口")
@ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query")
@GetMapping("/get")
@RequiresPermissions("cms:category:view")
@ResponseBody
public ResultData get(@ModelAttribute @ApiIgnore CategoryEntity category) {
if (category.getId() == null) {
return ResultData.build().error();
}
CategoryEntity _category = (CategoryEntity) categoryBiz.getById(category.getId());
return ResultData.build().success(_category);
}
/**
* 保存分类
* @param 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 = "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"),
})
@PostMapping("/save")
@ResponseBody
@LogAnn(title = "保存分类", businessType = BusinessTypeEnum.INSERT)
@RequiresPermissions("cms:category:save")
public ResultData save(@ModelAttribute @ApiIgnore CategoryEntity category) {
//验证缩略图参数值是否合法
if (category.getCategoryImg() == null || !category.getCategoryImg().matches("^\\[.{1,}]$")) {
category.setCategoryImg("");
}
//验证栏目管理名称的值是否合法
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.getCategoryPinyin() + "", 0, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.pinyin"), "1", "100"));
}
// 过滤非法路径
if (FileNameUtil.containsInvalid(category.getCategoryPinyin())) {
return ResultData.build().error(this.getResString("err.error",this.getResString("category.pinyin")));
}
if (!StringUtil.checkLength(category.getCategoryParentIds() + "", 1, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
}
//判断拼音是否重复
if (StrUtil.isNotBlank(category.getCategoryPinyin())) {
if (!category.getCategoryPinyin().matches("^[a-zA-Z0-9]*$")){
return ResultData.build().error(this.getResString("err.error",this.getResString("category.pinyin")));
}
CategoryEntity _category = new CategoryEntity();
_category.setCategoryPinyin(category.getCategoryPinyin());
List<CategoryEntity> query = categoryBiz.query(_category);
if (query.size() > 0) {
return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin")));
}
}
categoryBiz.saveEntity(category);
return ResultData.build().success(category);
}
/**
* 批量删除分类列表接口
* @param categorys
* @return
*/
@ApiOperation(value = "批量删除分类列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "categorys", value = "删除的栏目集合", allowMultiple = true, dataType = "CategoryEntity", required = true)
})
@PostMapping("/delete")
@ResponseBody
@LogAnn(title = "删除分类", businessType = BusinessTypeEnum.DELETE)
@RequiresPermissions("cms:category:del")
public ResultData delete(@RequestBody List<CategoryEntity> categorys) {
for (int i = 0; i < categorys.size(); i++) {
categoryBiz.delete(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 = "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"),
})
@PostMapping("/update")
@ResponseBody
@LogAnn(title = "更新分类", businessType = BusinessTypeEnum.UPDATE)
@RequiresPermissions("cms:category:update")
public ResultData update(@ModelAttribute @ApiIgnore CategoryEntity category) {
//验证缩略图参数值是否合法
if (category.getCategoryImg() == null || !category.getCategoryImg().matches("^\\[.{1,}]$")) {
category.setCategoryImg("");
}
if (StringUtils.isEmpty(category.getId())){
return ResultData.build().error(getResString("err.empty", this.getResString("category.id")));
}
//验证栏目管理名称的值是否合法
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.getCategoryPinyin() + "", 1, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.pinyin"), "1", "100"));
}
if (!StringUtil.checkLength(category.getCategoryParentIds() + "", 0, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
}
// 过滤非法路径
if (FileNameUtil.containsInvalid(category.getCategoryPinyin())) {
return ResultData.build().error(this.getResString("err.error",this.getResString("category.pinyin")));
}
//判断拼音是否重复并且是否和原拼音相同
if (StrUtil.isNotBlank(category.getCategoryPinyin()) && !categoryBiz.getById(category.getId()).getCategoryPinyin().equals(category.getCategoryPinyin())) {
if (!category.getCategoryPinyin().matches("^[a-zA-Z0-9]*$")){
return ResultData.build().error(this.getResString("err.error",this.getResString("category.pinyin")));
}
CategoryEntity _category = new CategoryEntity();
_category.setCategoryPinyin(category.getCategoryPinyin());
List<CategoryEntity> query = categoryBiz.query(_category);
if (query.size() > 0) {
return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin")));
}
}
String pingYin = PinYinUtil.getPingYin(category.getCategoryTitle());
//如果用户填写了拼音则使用用户填写的
if (StrUtil.isNotBlank(category.getCategoryPinyin())) {
pingYin = category.getCategoryPinyin();
}
CategoryEntity categoryEntity = new CategoryEntity();
categoryEntity.setCategoryPinyin(pingYin);
CategoryEntity categoryBizEntity = categoryBiz.getEntity(categoryEntity);
category.setCategoryPinyin(pingYin);
//如果存在此拼音栏目则拼接上id
if (categoryBizEntity != null && !categoryBizEntity.getId().equals(category.getId())) {
category.setCategoryPinyin(pingYin + category.getId());
}
//判断是否选择子级为所属栏目
CategoryEntity _category = new CategoryEntity();
_category.setId(category.getId());
List<CategoryEntity> categoryList = categoryBiz.queryChildren(_category);
if (categoryList.size() > 1) {
for (CategoryEntity item : categoryList) {
if (item.getId().equals(category.getCategoryId())) {
return ResultData.build().error(getResString("cannot.select.child"));
}
}
category.setLeaf(false);
} else {
category.setLeaf(true);
}
// 这里不能使用mybitsplus 存在业务
categoryBiz.updateEntity(category);
return ResultData.build().success(category);
}
/**
* 验证拼音
* @param category 栏目
* @return
*/
@ApiOperation(value = "验证拼音")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query"),
@ApiImplicitParam(name = "categoryPinyin", value = "栏目管拼音", required = true, paramType = "query"),
})
@GetMapping("/verifyPingYin")
@ResponseBody
public ResultData verifyPingYin(@ModelAttribute @ApiIgnore CategoryEntity category) {
long count = categoryBiz.count(Wrappers.<CategoryEntity>lambdaQuery()
.ne(StrUtil.isNotBlank(category.getId()), CategoryEntity::getId, category.getId())
.eq(CategoryEntity::getCategoryPinyin, category.getCategoryPinyin()));
if (count > 0) {
return ResultData.build().error("存在相同拼音的栏目");
}
return ResultData.build().success();
}
/**
* 批量更新模板
* @param category 栏目实体
* @return
*/
@ApiOperation(value = "批量更新模板")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query"),
@ApiImplicitParam(name = "dictId", value = "字典", required = true, paramType = "query")
})
@GetMapping("/updateTemplate")
@ResponseBody
@RequiresPermissions("cms:category:update")
public ResultData updateTemplate(@ModelAttribute @ApiIgnore CategoryEntity category) {
if (category == null || StringUtils.isEmpty(category.getId())) {
return ResultData.build().error(getResString("err.error", this.getResString("id")));
}
category = categoryBiz.getById(category.getId());
category.setCategoryParentIds(null);
List<CategoryEntity> childs = categoryBiz.queryChildren(category);
//更新与父节点相同类型的子栏目的模板内容
for (int i = 0; i < childs.size(); i++) {
if (childs.get(i).getCategoryType().equals(category.getCategoryType())) {
childs.get(i).setCategoryUrl(category.getCategoryUrl());
childs.get(i).setCategoryListUrl(category.getCategoryListUrl());
categoryBiz.updateEntity(childs.get(i));
}
}
return ResultData.build().success();
}
/**
* 复制栏目
* @param category 栏目实体
* @return
*/
@ApiOperation(value = "复制栏目")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query")
})
@GetMapping("/copyCategory")
@ResponseBody
@RequiresPermissions("cms:category:save")
public ResultData copyCategory(@ModelAttribute @ApiIgnore CategoryEntity category) {
if (category == null || StringUtils.isEmpty(category.getId())) {
return ResultData.build().error(getResString("err.error", this.getResString("id")));
}
categoryBiz.copyCategory(category);
return ResultData.build().success();
}
@ApiOperation(value = "强制转换类型接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "typeid", value = "编号", required =true,paramType="query"),
@ApiImplicitParam(name = "categoryType", value = "栏目类型,1:列表,2:单篇,3:链接", required =true,paramType="query")
})
@GetMapping("/changeType")
@ResponseBody
@RequiresPermissions("cms:category:update")
public ResultData changeType(){
String typeId = BasicUtil.getString(ParserUtil.TYPE_ID);
String categoryType = BasicUtil.getString("categoryType");
CategoryEntity category = categoryBiz.getById(typeId);
if (category == null){
return ResultData.build().error(getResString("err.error",getResString("id")));
}
if (CategoryTypeEnum.get(categoryType).equals(CategoryTypeEnum.UN_KNOW)){
return ResultData.build().error(getResString("err.error",getResString("category.type")));
}
categoryBiz.changeCategoryType(category,categoryType);
return ResultData.build().success(category);
}
}
/**
* The MIT License (MIT)
* Copyright (c) 2012-present 铭软科技(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;
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.ResultData;
import net.mingsoft.base.util.SqlInjectionUtil;
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.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.mdiy.biz.IModelBiz;
import net.mingsoft.mdiy.entity.ModelEntity;
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.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 文章管理控制层
* @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Api(tags={"后端-内容模块接口"})
@Controller("cmsContentAction")
@RequestMapping("/${ms.manager.path}/cms/content")
public class ContentAction extends BaseAction {
/**
* 注入文章业务层
*/
@Autowired
private IContentBiz contentBiz;
@Autowired
private ICategoryBiz categoryBiz;
@Resource(name="mdiyModelBizImpl")
private IModelBiz modelBiz;
/**
* 返回主界面index
*/
@ApiIgnore
@GetMapping("/index")
public String index(){
return "/cms/content/index";
}
/**
* 返回主界面main
*/
@ApiIgnore
@GetMapping("/main")
public String main(){
return "/cms/content/main";
}
/**
* 查询文章列表
* @param content 文章实体
*/
@ApiOperation(value = "查询文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "contentTitle", value = "文章标题", required =false,paramType="query"),
@ApiImplicitParam(name = "categoryId", 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"),
})
@RequestMapping(value = "/list",method = {RequestMethod.GET,RequestMethod.POST})
@ResponseBody
@RequiresPermissions("cms:content:view")
public ResultData list(@ModelAttribute @ApiIgnore ContentBean content) {
// 检查SQL注入
SqlInjectionUtil.filterContent(content.getCategoryId());
BasicUtil.startPage();
List contentList = contentBiz.queryContent(content);
return ResultData.build().success(new EUListBean(contentList,(int) BasicUtil.endPage(contentList).getTotal()));
}
/**
* 返回编辑界面content_form
*/
@GetMapping("/form")
public String form(@ModelAttribute ContentEntity content, ModelMap model){
model.addAttribute("appId", BasicUtil.getApp().getAppId());
return "/cms/content/form";
}
/**
* 获取文章
* @param content 文章实体
*/
@ApiOperation(value = "获取文章详情接口")
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query")
@GetMapping("/get")
@ResponseBody
@RequiresPermissions("cms:content:view")
public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content){
if(content.getId()==null) {
return ResultData.build().error();
}
ContentEntity _content = contentBiz.getById(content.getId());
return ResultData.build().success(_content);
}
/**
* 获取文章
* @param content 文章实体
*/
@ApiOperation(value = "根据封面获取文章列表接口")
@ApiImplicitParam(name = "categoryId", value = "分类编号", required =true,paramType="query")
@GetMapping("/getFromFengMian")
@ResponseBody
public ResultData getFromFengMian(@ModelAttribute @ApiIgnore ContentEntity content){
if(content.getCategoryId() == null) {
return ResultData.build().error();
}
List<ContentEntity> list = contentBiz.lambdaQuery().eq(ContentEntity::getCategoryId, content.getCategoryId()).list();
if (list.size() > 1) {
LOG.error("获取封面文章异常");
}
return ResultData.build().success(list.size() > 0 ? list.get(0) : null);
}
/**
* 保存文章
* @param content 文章实体
*/
@ApiOperation(value = "保存文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "contentTitle", value = "文章标题", required =true,paramType="query"),
@ApiImplicitParam(name = "categoryId", 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"),
})
@PostMapping("/save")
@ResponseBody
@LogAnn(title = "保存文章", businessType = BusinessTypeEnum.INSERT)
@RequiresPermissions("cms:content:save")
public ResultData save(@ModelAttribute @ApiIgnore ContentEntity content) {
//验证缩略图参数值是否合法
if (content.getContentImg()==null || !content.getContentImg().matches("^\\[.{1,}]$")){
content.setContentImg("");
}
//验证文章标题的值是否合法
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")));
}
contentBiz.save(content);
return ResultData.build().success(content);
}
/**
* @param contents 文章实体
*/
@ApiOperation(value = "批量删除文章列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "contents", value = "文章集合", allowMultiple = true, dataType = "ContentEntity", required = true)
})
@PostMapping("/delete")
@ResponseBody
@LogAnn(title = "删除文章", businessType = BusinessTypeEnum.DELETE)
@RequiresPermissions("cms:content:del")
public ResultData delete(@RequestBody List<ContentEntity> contents) {
List<String> ids = new ArrayList<>();
for(int i = 0;i<contents.size();i++){
ids.add(contents.get(i).getId());
//获取栏目实体
CategoryEntity categoryEntity = categoryBiz.getById(contents.get(i).getCategoryId());
//如果栏目绑定的模型ID为空
if (StringUtils.isBlank(categoryEntity.getMdiyModelId())){
continue;
}
//获取到配置模型实体
ModelEntity modelEntity = modelBiz.getById(categoryEntity.getMdiyModelId());
//删除模型表的数据
Map<String, String> map = new HashMap<>();
map.put("link_id", contents.get(i).getId());
modelBiz.deleteBySQL(modelEntity.getModelTableName(), map);
}
contentBiz.removeByIds(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 = "categoryId", 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"),
})
@PostMapping("/update")
@ResponseBody
@LogAnn(title = "更新文章", businessType = BusinessTypeEnum.UPDATE)
@RequiresPermissions("cms:content:update")
public ResultData update(@ModelAttribute @ApiIgnore ContentEntity content) {
//验证缩略图参数值是否合法
if (content.getContentImg()==null || !content.getContentImg().matches("^\\[.{1,}]$")){
content.setContentImg("");
}
//验证文章标题的值是否合法
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")));
}
contentBiz.saveOrUpdate(content);
return ResultData.build().success(content);
}
}
/**
* The MIT License (MIT)
* Copyright (c) 2012-present 铭软科技(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;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.date.DateException;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.annotation.LogAnn;
import net.mingsoft.basic.biz.IModelBiz;
import net.mingsoft.basic.constant.e.BusinessTypeEnum;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.bean.CategoryBean;
import net.mingsoft.cms.bean.ContentBean;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.constant.e.CategoryDisplayEnum;
import net.mingsoft.cms.constant.e.CategoryTypeEnum;
import net.mingsoft.cms.entity.CategoryEntity;
import net.mingsoft.cms.util.CmsParserUtil;
import net.mingsoft.mdiy.util.ParserUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
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.Date;
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.
*/
@Api(tags={"后端-静态化"})
@Controller("cmsGenerater")
@RequestMapping("/${ms.manager.path}/cms/generate")
@Scope("request")
public class GeneraterAction extends BaseAction {
/*
* log4j日志记录
*/
protected final Logger LOG = LoggerFactory.getLogger(this.getClass());
/**
* 文章管理业务层
*/
@Autowired
private IContentBiz contentBiz;
/**
* 栏目管理业务层
*/
@Autowired
private ICategoryBiz categoryBiz;
/**
* 模块管理业务层
*/
@Autowired
private IModelBiz modelBiz;
@Value("${ms.manager.path}")
private String managerPath;
@Value("${ms.diy.html-dir:html}")
private String htmlDir;
/**
* /**
* 更新主页
*
* @return
*/
@GetMapping("/index")
public String index(HttpServletRequest request, ModelMap model) {
return "/cms/generate/index";
}
/**
* 生成主页
*
* @param request
* @param response
*/
@ApiOperation(value = "生成主页接口")
@RequestMapping(value = "/generateIndex", method = {RequestMethod.GET, RequestMethod.POST})
@RequiresPermissions("cms:generate:index")
@LogAnn(title = "生成主页", businessType = BusinessTypeEnum.UPDATE)
@ResponseBody
public ResultData generateIndex(HttpServletRequest request, HttpServletResponse response) throws IOException {
// 模板文件名称
String tmpFileName = request.getParameter("url");
// 生成后的文件名称
String generateFileName = request.getParameter("position");
// 防止篡改主页
if (tmpFileName.contains("..") || tmpFileName.contains("../") || tmpFileName.contains("\\..")){
return ResultData.build().error(getResString("template.file"));
}
if (generateFileName.contains("..") || generateFileName.contains("../") || generateFileName.contains("\\..")){
return ResultData.build().error(getResString("template.file"));
}
// 获取文件所在路径 首先判断用户输入的模板文件是否存在
if (!FileUtil.exist(ParserUtil.buildTemplatePath())) {
return ResultData.build().error(getResString("template.file"));
} else {
CmsParserUtil.generate(tmpFileName, generateFileName, htmlDir);
return ResultData.build().success();
}
}
/**
* 生成列表的静态页面
*
* @param request
* @param response
* @param categoryId
*/
@ApiOperation(value = "生成栏目接口")
@RequestMapping(value = "/{categoryId}/generateColumn", method = {RequestMethod.GET, RequestMethod.POST})
@LogAnn(title = "生成栏目", businessType = BusinessTypeEnum.UPDATE)
@RequiresPermissions("cms:generate:column")
@ResponseBody
public ResultData generateColumn(HttpServletRequest request, HttpServletResponse response, @PathVariable String categoryId) throws IOException {
// 获取站点id
AppEntity app = BasicUtil.getApp();
//栏目列表
List<CategoryEntity> columns = new ArrayList<CategoryEntity>();
if ("0".equals(categoryId)) {// 0更新所有栏目
CategoryEntity categoryEntity = new CategoryEntity();
columns = categoryBiz.query(categoryEntity);
} else { //选择栏目更新
CategoryEntity categoryEntity = new CategoryEntity();
categoryEntity.setId(categoryId);
columns = categoryBiz.queryChildren(categoryEntity);
}
//文章列表
List<CategoryBean> articleIdList = null;
// 获取栏目列表模板
for (CategoryEntity column : columns) {
// 如果栏目被禁用则跳过
if (CategoryDisplayEnum.DISABLE.toString().equalsIgnoreCase(column.getCategoryDisplay())){
continue;
}
//如果是链接就跳过生成
if (column.getCategoryType().equals(CategoryTypeEnum.LINK.toString())) {
continue;
}
ContentBean contentBean = new ContentBean();
contentBean.setCategoryId(column.getId());
contentBean.setCategoryType(column.getCategoryType());
articleIdList = contentBiz.queryIdsByCategoryIdForParser(contentBean);
// 判断列表类型
switch (CategoryTypeEnum.get(column.getCategoryType())) {
//TODO 暂时先用字符串代替
case LIST: // 列表
// 判断模板文件是否存在
if (StringUtils.isEmpty(column.getCategoryListUrl()) || !FileUtil.exist(ParserUtil.buildTemplatePath(column.getCategoryListUrl()))) {
LOG.error("{} 模板不存在:{}", column.getCategoryTitle(), column.getCategoryUrl());
continue;
}
CmsParserUtil.generateList(column, articleIdList.size(), htmlDir);
break;
case COVER:// 单页
// 判断模板文件是否存在
if (StringUtils.isEmpty(column.getCategoryUrl()) || !FileUtil.exist(ParserUtil.buildTemplatePath(column.getCategoryUrl()))) {
LOG.error("{} 模板不存在:{}", column.getCategoryTitle(), column.getCategoryUrl());
continue;
}
if (articleIdList.size() == 0) {
CategoryBean columnArticleIdBean = new CategoryBean();
CopyOptions copyOptions = CopyOptions.create();
copyOptions.setIgnoreError(true);
BeanUtil.copyProperties(column, columnArticleIdBean, copyOptions);
articleIdList.add(columnArticleIdBean);
}
CmsParserUtil.generateBasic(articleIdList, htmlDir,null);
break;
}
}
return ResultData.build().success();
}
/**
* 根据栏目id更新所有的文章
*
* @param request
* @param response
* @param columnId
*/
@ApiOperation(value = "生成文章接口")
@RequestMapping(value = "/{columnId}/generateArticle", method = {RequestMethod.GET, RequestMethod.POST})
@RequiresPermissions("cms:generate:article")
@LogAnn(title = "生成文章", businessType = BusinessTypeEnum.UPDATE)
@ResponseBody
public ResultData generateArticle(HttpServletRequest request, HttpServletResponse response, @PathVariable String columnId) throws IOException {
String dateTime = request.getParameter("dateTime");
// 网站风格物理路径
List<CategoryBean> articleIdList = null;
List<CategoryEntity> categoryList = new ArrayList<CategoryEntity>();
ContentBean contentBean = new ContentBean();
contentBean.setBeginTime(dateTime);
// 时间格式化
Date contentUpdateTime = null;
try {
contentUpdateTime = DateUtil.parse(dateTime);
} catch (DateException e) {
e.printStackTrace();
return ResultData.build().error(getResString("err.error",this.getResString("datetime.format")));
}
if ("0".equals(columnId)) {
categoryList = categoryBiz.list();
} else { //选择栏目更新
CategoryEntity categoryEntity = new CategoryEntity();
categoryEntity.setId(columnId);
categoryList = categoryBiz.queryChildren(categoryEntity);
}
for (CategoryEntity category : categoryList) {
// 如果栏目被禁用则跳过
if (CategoryDisplayEnum.DISABLE.toString().equalsIgnoreCase(category.getCategoryDisplay())){
continue;
}
//如果是链接就跳过生成
if (category.getCategoryType().equals(CategoryTypeEnum.LINK.toString())) {
continue;
}
contentBean.setCategoryId(category.getId());
contentBean.setCategoryType(category.getCategoryType());
contentBean.setOrderBy("date");
//将文章列表标签中的中的参数
articleIdList = contentBiz.queryIdsByCategoryIdForParser(contentBean);
// 分类是列表
if (category.getCategoryType().equals(CategoryTypeEnum.LIST.toString())) {
// 判断模板文件是否存在
if (!FileUtil.exist(ParserUtil.buildTemplatePath(category.getCategoryListUrl())) || StringUtils.isEmpty(category.getCategoryListUrl())) {
LOG.error("{} 模板不存在:{}", category.getCategoryTitle(), category.getCategoryListUrl());
continue;
}
} else if (category.getCategoryType().equals(CategoryTypeEnum.COVER.toString())) {
continue;
}
// 有符合条件的就更新
if (articleIdList.size() > 0) {
CmsParserUtil.generateBasic(articleIdList, htmlDir,contentUpdateTime);
}
}
return ResultData.build().success();
}
/**
* 用户预览主页
*
* @param request
* @return
*/
@ApiOperation(value = "预览主页接口")
@RequestMapping(value = "/{position}/viewIndex", method = {RequestMethod.GET, RequestMethod.POST})
public String viewIndex(HttpServletRequest request, @PathVariable String position, HttpServletResponse response) {
AppEntity app = BasicUtil.getApp();
// 组织主页预览地址
String indexPosition = app.getAppHostUrl() + htmlDir + File.separator + app.getAppDir()
+ File.separator + position + ParserUtil.HTML_SUFFIX;
return "redirect:" + indexPosition;
}
}
Markdown is supported
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