Commit 644f0bdc authored by msgroup's avatar msgroup Committed by mingsoft

fix:待发布版本

Signed-off-by: 's avatarmingsoft <killfen@126.com>
parent f66c6298
...@@ -18,27 +18,27 @@ ...@@ -18,27 +18,27 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.action; package net.mingsoft.cms.action;
import java.util.MissingResourceException; import java.util.MissingResourceException;
/** /**
* @Author: 铭飞开源团队--huise * @Author: 铭飞开源团队--huise
* @Date: 2019/8/9 20:47 * @Date: 2019/8/9 20:47
*/ */
public class BaseAction extends net.mingsoft.basic.action.BaseAction{ public class BaseAction extends net.mingsoft.basic.action.BaseAction{
@Override @Override
protected String getResString(String key) { protected String getResString(String key) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
String str = ""; String str = "";
try { try {
str = super.getResString(key); str = super.getResString(key);
} catch (MissingResourceException e) { } catch (MissingResourceException e) {
str = getLocaleString(key,net.mingsoft.cms.constant.Const.RESOURCES); str = getLocaleString(key,net.mingsoft.cms.constant.Const.RESOURCES);
} }
return str; return str;
} }
} }
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * 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, * the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions: * subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
package net.mingsoft.cms.action; package net.mingsoft.cms.action;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -53,318 +54,323 @@ import java.util.List; ...@@ -53,318 +54,323 @@ import java.util.List;
* 创建日期:2019-11-28 15:12:32<br/> * 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
@Api(tags={"后端-内容模块接口"}) @Api(tags = {"后端-内容模块接口"})
@Controller("cmsCategoryAction") @Controller("cmsCategoryAction")
@RequestMapping("/${ms.manager.path}/cms/category") @RequestMapping("/${ms.manager.path}/cms/category")
public class CategoryAction extends BaseAction { public class CategoryAction extends BaseAction {
/** /**
* 注入分类业务层 * 注入分类业务层
*/ */
@Autowired @Autowired
private ICategoryBiz categoryBiz; private ICategoryBiz categoryBiz;
/** /**
* 返回主界面index * 返回主界面index
* @return * @return
*/ */
@GetMapping("/index") @GetMapping("/index")
@RequiresPermissions("cms:category:view") @RequiresPermissions("cms:category:view")
public String index(){ public String index() {
return "/cms/category/index"; return "/cms/category/index";
} }
/** /**
* 查询分类列表接口 * 查询分类列表接口
* @param category 栏目实体 * @param category 栏目实体
* @return * @return
*/ */
@ApiOperation(value = "查询分类列表接口") @ApiOperation(value = "查询分类列表接口")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =false,paramType="query"), @ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"), @ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required = false, paramType = "query"),
}) })
@RequestMapping(value="/list",method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody @ResponseBody
public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category) { public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category) {
BasicUtil.startPage(); BasicUtil.startPage();
List categoryList = categoryBiz.query(category); List categoryList = categoryBiz.list(new LambdaQueryWrapper<CategoryEntity>(category));
return ResultData.build().success(new EUListBean(categoryList,(int) BasicUtil.endPage(categoryList).getTotal())); return ResultData.build().success(new EUListBean(categoryList, (int) BasicUtil.endPage(categoryList).getTotal()));
} }
/**
* 返回编辑界面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";
}
/** /**
* 获取分类 * 返回编辑界面category_form
* @param category 分类实体 * @param category 栏目
*/ * @return
@ApiOperation(value = "获取分类列表接口") */
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query") @GetMapping("/form")
@GetMapping("/get") public String form(@ModelAttribute CategoryEntity category, ModelMap model) {
@RequiresPermissions("cms:category:view") model.addAttribute("appId", BasicUtil.getApp().getAppId());
@ResponseBody return "/cms/category/form";
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 = "获取分类列表接口")
@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 分类实体 * @param category 分类实体
*/ */
@ApiOperation(value = "保存分类列表接口") @ApiOperation(value = "保存分类列表接口")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =true,paramType="query"), @ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required = true, paramType = "query"),
@ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"), @ApiImplicitParam(name = "categoryId", value = "所属栏目", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required =false,paramType="query"), @ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required = false, paramType = "query"),
@ApiImplicitParam(name = "categorySort", value = "自定义顺序", required =false,paramType="query"), @ApiImplicitParam(name = "categorySort", value = "自定义顺序", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required =false,paramType="query"), @ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryUrl", value = "内容模板", required =false,paramType="query"), @ApiImplicitParam(name = "categoryUrl", value = "内容模板", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required =false,paramType="query"), @ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required =false,paramType="query"), @ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryImg", value = "缩略图", required =false,paramType="query"), @ApiImplicitParam(name = "categoryImg", value = "缩略图", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required =false,paramType="query"), @ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required = false, paramType = "query"),
@ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required =false,paramType="query"), @ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required =false,paramType="query"), @ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required = false, paramType = "query"),
@ApiImplicitParam(name = "dictId", value = "字典对应编号", required =false,paramType="query"), @ApiImplicitParam(name = "dictId", value = "字典对应编号", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required =false,paramType="query"), @ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryPath", value = "栏目路径", required =false,paramType="query"), @ApiImplicitParam(name = "categoryPath", value = "栏目路径", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"), @ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required = false, paramType = "query"),
}) })
@PostMapping("/save") @PostMapping("/save")
@ResponseBody @ResponseBody
@LogAnn(title = "保存分类", businessType = BusinessTypeEnum.INSERT) @LogAnn(title = "保存分类", businessType = BusinessTypeEnum.INSERT)
@RequiresPermissions("cms:category:save") @RequiresPermissions("cms:category:save")
public ResultData save(@ModelAttribute @ApiIgnore CategoryEntity category) { public ResultData save(@ModelAttribute @ApiIgnore CategoryEntity category) {
//验证缩略图参数值是否合法 //验证缩略图参数值是否合法
if (!category.getCategoryImg().matches("^\\[.{1,}]$") || category.getCategoryImg()==null){ if (!category.getCategoryImg().matches("^\\[.{1,}]$") || category.getCategoryImg() == null) {
category.setCategoryImg(""); category.setCategoryImg("");
} }
//验证栏目管理名称的值是否合法 //验证栏目管理名称的值是否合法
if(StringUtil.isBlank(category.getCategoryTitle())){ if (StringUtil.isBlank(category.getCategoryTitle())) {
return ResultData.build().error(getResString("err.empty", this.getResString("category.title"))); return ResultData.build().error(getResString("err.empty", this.getResString("category.title")));
} }
if(!StringUtil.checkLength(category.getCategoryTitle()+"", 1, 100)){ if (!StringUtil.checkLength(category.getCategoryTitle() + "", 1, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.title"), "1", "100")); return ResultData.build().error(getResString("err.length", this.getResString("category.title"), "1", "100"));
} }
if(!StringUtil.checkLength(category.getCategoryPath()+"", 1, 100)){ if (!StringUtil.checkLength(category.getCategoryPath() + "", 1, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.path"), "1", "100")); return ResultData.build().error(getResString("err.length", this.getResString("category.path"), "1", "100"));
} }
if(!StringUtil.checkLength(category.getCategoryParentIds()+"", 1, 100)){ if (!StringUtil.checkLength(category.getCategoryParentIds() + "", 1, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100")); return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
} }
//判断拼音是否重复 //判断拼音是否重复
if(StrUtil.isNotBlank(category.getCategoryPinyin())) { if (StrUtil.isNotBlank(category.getCategoryPinyin())) {
CategoryEntity _category = new CategoryEntity(); if (!category.getCategoryPinyin().matches("^[a-zA-Z0-9]*$")){
_category.setCategoryPinyin(category.getCategoryPinyin()); return ResultData.build().error(this.getResString("err.format"));
List<CategoryEntity> query = categoryBiz.query(_category); }
if (query.size() > 0) { CategoryEntity _category = new CategoryEntity();
return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin"))); _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); categoryBiz.saveEntity(category);
return ResultData.build().success(category); return ResultData.build().success(category);
} }
/** /**
* 批量删除分类列表接口 * 批量删除分类列表接口
* @param categorys * @param categorys
* @return * @return
*/ */
@ApiOperation(value = "批量删除分类列表接口") @ApiOperation(value = "批量删除分类列表接口")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "categorys", value = "删除的栏目集合", allowMultiple = true, dataType = "CategoryEntity", required = true) @ApiImplicitParam(name = "categorys", value = "删除的栏目集合", allowMultiple = true, dataType = "CategoryEntity", required = true)
}) })
@PostMapping("/delete") @PostMapping("/delete")
@ResponseBody @ResponseBody
@LogAnn(title = "删除分类", businessType = BusinessTypeEnum.DELETE) @LogAnn(title = "删除分类", businessType = BusinessTypeEnum.DELETE)
@RequiresPermissions("cms:category:del") @RequiresPermissions("cms:category:del")
public ResultData delete(@RequestBody List<CategoryEntity> categorys) { public ResultData delete(@RequestBody List<CategoryEntity> categorys) {
for(int i = 0;i<categorys.size();i++){ for (int i = 0; i < categorys.size(); i++) {
categoryBiz.delete(categorys.get(i).getId()); categoryBiz.delete(categorys.get(i).getId());
} }
return ResultData.build().success(); return ResultData.build().success();
} }
/** /**
* 更新分类列表 * 更新分类列表
* @param category 分类实体 * @param category 分类实体
*/ */
@ApiOperation(value = "更新分类列表接口") @ApiOperation(value = "更新分类列表接口")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"), @ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query"),
@ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required =true,paramType="query"), @ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required = true, paramType = "query"),
@ApiImplicitParam(name = "categoryId", value = "所属栏目", required =false,paramType="query"), @ApiImplicitParam(name = "categoryId", value = "所属栏目", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required =false,paramType="query"), @ApiImplicitParam(name = "categoryType", value = "栏目管理属性", required = false, paramType = "query"),
@ApiImplicitParam(name = "categorySort", value = "自定义顺序", required =false,paramType="query"), @ApiImplicitParam(name = "categorySort", value = "自定义顺序", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required =false,paramType="query"), @ApiImplicitParam(name = "categoryListUrl", value = "列表模板", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryUrl", value = "内容模板", required =false,paramType="query"), @ApiImplicitParam(name = "categoryUrl", value = "内容模板", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required =false,paramType="query"), @ApiImplicitParam(name = "categoryKeyword", value = "栏目管理关键字", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required =false,paramType="query"), @ApiImplicitParam(name = "categoryDescrip", value = "栏目管理描述", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryImg", value = "缩略图", required =false,paramType="query"), @ApiImplicitParam(name = "categoryImg", value = "缩略图", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required =false,paramType="query"), @ApiImplicitParam(name = "categoryDiyUrl", value = "自定义链接", required = false, paramType = "query"),
@ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required =false,paramType="query"), @ApiImplicitParam(name = "mdiyModelId", value = "栏目管理的内容模型id", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required =false,paramType="query"), @ApiImplicitParam(name = "categoryDatetime", value = "类别发布时间", required = false, paramType = "query"),
@ApiImplicitParam(name = "dictId", value = "字典对应编号", required =false,paramType="query"), @ApiImplicitParam(name = "dictId", value = "字典对应编号", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required =false,paramType="query"), @ApiImplicitParam(name = "categoryFlag", value = "栏目属性", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryPath", value = "栏目路径", required =false,paramType="query"), @ApiImplicitParam(name = "categoryPath", value = "栏目路径", required = false, paramType = "query"),
@ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required =false,paramType="query"), @ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required = false, paramType = "query"),
}) })
@PostMapping("/update") @PostMapping("/update")
@ResponseBody @ResponseBody
@LogAnn(title = "更新分类", businessType = BusinessTypeEnum.UPDATE) @LogAnn(title = "更新分类", businessType = BusinessTypeEnum.UPDATE)
@RequiresPermissions("cms:category:update") @RequiresPermissions("cms:category:update")
public ResultData update(@ModelAttribute @ApiIgnore CategoryEntity category) { public ResultData update(@ModelAttribute @ApiIgnore CategoryEntity category) {
//验证缩略图参数值是否合法 //验证缩略图参数值是否合法
if (!category.getCategoryImg().matches("^\\[.{1,}]$") || category.getCategoryImg()==null){ if (!category.getCategoryImg().matches("^\\[.{1,}]$") || category.getCategoryImg() == null) {
category.setCategoryImg(""); category.setCategoryImg("");
} }
//验证栏目管理名称的值是否合法 //验证栏目管理名称的值是否合法
if(StringUtil.isBlank(category.getCategoryTitle())){ if (StringUtil.isBlank(category.getCategoryTitle())) {
return ResultData.build().error(getResString("err.empty", this.getResString("category.title"))); return ResultData.build().error(getResString("err.empty", this.getResString("category.title")));
} }
if(!StringUtil.checkLength(category.getCategoryTitle()+"", 1, 100)){ if (!StringUtil.checkLength(category.getCategoryTitle() + "", 1, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.title"), "1", "100")); return ResultData.build().error(getResString("err.length", this.getResString("category.title"), "1", "100"));
} }
if(!StringUtil.checkLength(category.getCategoryPath()+"", 0, 100)){ if (!StringUtil.checkLength(category.getCategoryPath() + "", 0, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.path"), "1", "100")); return ResultData.build().error(getResString("err.length", this.getResString("category.path"), "1", "100"));
} }
if(!StringUtil.checkLength(category.getCategoryParentIds()+"", 0, 100)){ if (!StringUtil.checkLength(category.getCategoryParentIds() + "", 0, 100)) {
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100")); return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
} }
//判断拼音是否重复并且是否和原拼音相同 //判断拼音是否重复并且是否和原拼音相同
if(StrUtil.isNotBlank(category.getCategoryPinyin()) && !categoryBiz.getById(category.getId()).getCategoryPinyin().equals(category.getCategoryPinyin())) { if (StrUtil.isNotBlank(category.getCategoryPinyin()) && !categoryBiz.getById(category.getId()).getCategoryPinyin().equals(category.getCategoryPinyin())) {
CategoryEntity _category = new CategoryEntity(); if (!category.getCategoryPinyin().matches("^[a-zA-Z0-9]*$")){
_category.setCategoryPinyin(category.getCategoryPinyin()); return ResultData.build().error(this.getResString("err.format"));
List<CategoryEntity> query = categoryBiz.query(_category); }
if (query.size() > 0) { CategoryEntity _category = new CategoryEntity();
return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin"))); _category.setCategoryPinyin(category.getCategoryPinyin());
} List<CategoryEntity> query = categoryBiz.query(_category);
} if (query.size() > 0) {
String pingYin = PinYinUtil.getPingYin(category.getCategoryTitle()); return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin")));
//如果用户填写了拼音则使用用户填写的 }
if (StrUtil.isNotBlank(category.getCategoryPinyin())) { }
pingYin = category.getCategoryPinyin(); String pingYin = PinYinUtil.getPingYin(category.getCategoryTitle());
} //如果用户填写了拼音则使用用户填写的
CategoryEntity categoryEntity=new CategoryEntity(); if (StrUtil.isNotBlank(category.getCategoryPinyin())) {
categoryEntity.setCategoryPinyin(pingYin); pingYin = category.getCategoryPinyin();
CategoryEntity categoryBizEntity = categoryBiz.getEntity(categoryEntity); }
category.setCategoryPinyin(pingYin); CategoryEntity categoryEntity = new CategoryEntity();
//如果存在此拼音栏目则拼接上id categoryEntity.setCategoryPinyin(pingYin);
if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(category.getId())){ CategoryEntity categoryBizEntity = categoryBiz.getEntity(categoryEntity);
category.setCategoryPinyin(pingYin+category.getId()); category.setCategoryPinyin(pingYin);
} //如果存在此拼音栏目则拼接上id
//判断是否选择子级为所属栏目 if (categoryBizEntity != null && !categoryBizEntity.getId().equals(category.getId())) {
CategoryEntity _category = new CategoryEntity(); category.setCategoryPinyin(pingYin + category.getId());
_category.setId(category.getId()); }
List<CategoryEntity> categoryList = categoryBiz.queryChildren(_category); //判断是否选择子级为所属栏目
if(categoryList.size()>1) { CategoryEntity _category = new CategoryEntity();
for(CategoryEntity item:categoryList){ _category.setId(category.getId());
if(item.getId().equals(category.getCategoryId())){ List<CategoryEntity> categoryList = categoryBiz.queryChildren(_category);
return ResultData.build().error(getResString("cannot.select.child")); if (categoryList.size() > 1) {
} for (CategoryEntity item : categoryList) {
} if (item.getId().equals(category.getCategoryId())) {
category.setLeaf(false); return ResultData.build().error(getResString("cannot.select.child"));
} else { }
category.setLeaf(true); }
} category.setLeaf(false);
} else {
category.setLeaf(true);
}
// 这里不能使用mybitsplus 存在业务 // 这里不能使用mybitsplus 存在业务
categoryBiz.updateEntity(category); categoryBiz.updateEntity(category);
return ResultData.build().success(category); return ResultData.build().success(category);
} }
/** /**
* 验证拼音 * 验证拼音
* @param category 栏目 * @param category 栏目
* @return * @return
*/ */
@ApiOperation(value = "验证拼音") @ApiOperation(value = "验证拼音")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"), @ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query"),
@ApiImplicitParam(name = "categoryPinyin", value = "栏目管拼音", required =true,paramType="query"), @ApiImplicitParam(name = "categoryPinyin", value = "栏目管拼音", required = true, paramType = "query"),
}) })
@GetMapping("/verifyPingYin") @GetMapping("/verifyPingYin")
@ResponseBody @ResponseBody
public ResultData verifyPingYin(@ModelAttribute @ApiIgnore CategoryEntity category){ public ResultData verifyPingYin(@ModelAttribute @ApiIgnore CategoryEntity category) {
long count = categoryBiz.count(Wrappers.<CategoryEntity>lambdaQuery() long count = categoryBiz.count(Wrappers.<CategoryEntity>lambdaQuery()
.ne(StrUtil.isNotBlank(category.getId()), CategoryEntity::getId, category.getId()) .ne(StrUtil.isNotBlank(category.getId()), CategoryEntity::getId, category.getId())
.eq(CategoryEntity::getCategoryPinyin, category.getCategoryPinyin())); .eq(CategoryEntity::getCategoryPinyin, category.getCategoryPinyin()));
if(count>0){ if (count > 0) {
return ResultData.build().error("存在相同拼音的栏目"); return ResultData.build().error("存在相同拼音的栏目");
} }
return ResultData.build().success(); return ResultData.build().success();
} }
/** /**
* 批量更新模版 * 批量更新模版
* @param category 栏目实体 * @param category 栏目实体
* @return * @return
*/ */
@ApiOperation(value = "批量更新模版") @ApiOperation(value = "批量更新模版")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query"), @ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query"),
@ApiImplicitParam(name = "dictId", value = "字典", required =true,paramType="query") @ApiImplicitParam(name = "dictId", value = "字典", required = true, paramType = "query")
}) })
@GetMapping("/updateTemplate") @GetMapping("/updateTemplate")
@ResponseBody @ResponseBody
@RequiresPermissions("cms:category:update") @RequiresPermissions("cms:category:update")
public ResultData updateTemplate(@ModelAttribute @ApiIgnore CategoryEntity category){ public ResultData updateTemplate(@ModelAttribute @ApiIgnore CategoryEntity category) {
if (category ==null || StringUtils.isEmpty(category.getId())) { if (category == null || StringUtils.isEmpty(category.getId())) {
return ResultData.build().error(getResString("err.error", this.getResString("id"))); return ResultData.build().error(getResString("err.error", this.getResString("id")));
} }
category = categoryBiz.getById(category.getId()); category = categoryBiz.getById(category.getId());
category.setCategoryParentIds(null); category.setCategoryParentIds(null);
List<CategoryEntity> childs = categoryBiz.queryChildren(category); List<CategoryEntity> childs = categoryBiz.queryChildren(category);
//更新与父节点相同类型的子栏目的模板内容 //更新与父节点相同类型的子栏目的模板内容
for (int i =0; i < childs.size(); i++) { for (int i = 0; i < childs.size(); i++) {
if (childs.get(i).getCategoryType().equals(category.getCategoryType())) { if (childs.get(i).getCategoryType().equals(category.getCategoryType())) {
childs.get(i).setCategoryUrl(category.getCategoryUrl()); childs.get(i).setCategoryUrl(category.getCategoryUrl());
childs.get(i).setCategoryListUrl(category.getCategoryListUrl()); childs.get(i).setCategoryListUrl(category.getCategoryListUrl());
categoryBiz.updateEntity(childs.get(i)); categoryBiz.updateEntity(childs.get(i));
} }
} }
return ResultData.build().success(); return ResultData.build().success();
} }
/** /**
* 复制栏目 * 复制栏目
* @param category 栏目实体 * @param category 栏目实体
* @return * @return
*/ */
@ApiOperation(value = "复制栏目") @ApiOperation(value = "复制栏目")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "编号", required =true,paramType="query") @ApiImplicitParam(name = "id", value = "编号", required = true, paramType = "query")
}) })
@GetMapping("/copyCategory") @GetMapping("/copyCategory")
@ResponseBody @ResponseBody
@RequiresPermissions("cms:category:save") @RequiresPermissions("cms:category:save")
public ResultData copyCategory(@ModelAttribute @ApiIgnore CategoryEntity category){ public ResultData copyCategory(@ModelAttribute @ApiIgnore CategoryEntity category) {
if (category == null || StringUtils.isEmpty(category.getId())) { if (category == null || StringUtils.isEmpty(category.getId())) {
return ResultData.build().error(getResString("err.error", this.getResString("id"))); return ResultData.build().error(getResString("err.error", this.getResString("id")));
} }
categoryBiz.copyCategory(category); categoryBiz.copyCategory(category);
return ResultData.build().success(); return ResultData.build().success();
} }
} }
...@@ -18,33 +18,33 @@ ...@@ -18,33 +18,33 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.bean; package net.mingsoft.cms.bean;
import net.mingsoft.cms.entity.CategoryEntity; import net.mingsoft.cms.entity.CategoryEntity;
/** /**
* 文章实体 * 文章实体
* @author 铭飞开发团队 * @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/> * 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
public class CategoryBean extends CategoryEntity { public class CategoryBean extends CategoryEntity {
/** /**
* 文章编号 * 文章编号
*/ */
private String articleId; private String articleId;
public String getArticleId() { public String getArticleId() {
return articleId; return articleId;
} }
public void setArticleId(String articleId) { public void setArticleId(String articleId) {
this.articleId = articleId; this.articleId = articleId;
} }
} }
...@@ -18,44 +18,44 @@ ...@@ -18,44 +18,44 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.biz; package net.mingsoft.cms.biz;
import net.mingsoft.base.biz.IBaseBiz; import net.mingsoft.base.biz.IBaseBiz;
import net.mingsoft.cms.entity.CategoryEntity; import net.mingsoft.cms.entity.CategoryEntity;
import java.util.List; import java.util.List;
/** /**
* 分类业务 * 分类业务
* @author 铭飞开发团队 * @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/> * 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
public interface ICategoryBiz extends IBaseBiz<CategoryEntity> { public interface ICategoryBiz extends IBaseBiz<CategoryEntity> {
/** /**
* 查询当前分类下的所有子分类,包含自身 * 查询当前分类下的所有子分类,包含自身
* @param category 通过setId指定栏目id * @param category 通过setId指定栏目id
* @return * @return
*/ */
List<CategoryEntity> queryChildren(CategoryEntity category); List<CategoryEntity> queryChildren(CategoryEntity category);
void saveEntity(CategoryEntity entity); void saveEntity(CategoryEntity entity);
/**更新父级及子集 /**更新父级及子集
* @param entity * @param entity
*/ */
void updateEntity(CategoryEntity entity); void updateEntity(CategoryEntity entity);
/**只更新自身 /**只更新自身
* @param entity * @param entity
*/ */
void update(CategoryEntity entity); void update(CategoryEntity entity);
void delete(String categoryId); void delete(String categoryId);
void copyCategory(CategoryEntity entity); void copyCategory(CategoryEntity entity);
} }
...@@ -18,19 +18,19 @@ ...@@ -18,19 +18,19 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.biz; package net.mingsoft.cms.biz;
import net.mingsoft.base.biz.IBaseBiz; import net.mingsoft.base.biz.IBaseBiz;
/** /**
* 文章浏览记录业务 * 文章浏览记录业务
* @author 铭飞开发团队 * @author 铭飞开发团队
* 创建日期:2019-12-23 9:24:03<br/> * 创建日期:2019-12-23 9:24:03<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
public interface IHistoryLogBiz extends IBaseBiz { public interface IHistoryLogBiz extends IBaseBiz {
} }
...@@ -18,301 +18,301 @@ ...@@ -18,301 +18,301 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.biz.impl; package net.mingsoft.cms.biz.impl;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import net.mingsoft.base.biz.impl.BaseBizImpl; import net.mingsoft.base.biz.impl.BaseBizImpl;
import net.mingsoft.base.dao.IBaseDao; import net.mingsoft.base.dao.IBaseDao;
import net.mingsoft.basic.util.PinYinUtil; import net.mingsoft.basic.util.PinYinUtil;
import net.mingsoft.cms.biz.ICategoryBiz; import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.dao.ICategoryDao; import net.mingsoft.cms.dao.ICategoryDao;
import net.mingsoft.cms.dao.IContentDao; import net.mingsoft.cms.dao.IContentDao;
import net.mingsoft.cms.entity.CategoryEntity; import net.mingsoft.cms.entity.CategoryEntity;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* 分类管理持久化层 * 分类管理持久化层
* @author 铭飞开发团队 * @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/> * 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
@Service("cmscategoryBizImpl") @Service("cmscategoryBizImpl")
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> implements ICategoryBiz { public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> implements ICategoryBiz {
@Autowired @Autowired
private ICategoryDao categoryDao; private ICategoryDao categoryDao;
@Autowired @Autowired
private IContentDao contentDao; private IContentDao contentDao;
@Override @Override
protected IBaseDao getDao() { protected IBaseDao getDao() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return categoryDao; return categoryDao;
} }
@Override @Override
public List<CategoryEntity> queryChildren(CategoryEntity category) { public List<CategoryEntity> queryChildren(CategoryEntity category) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return categoryDao.queryChildren(category); return categoryDao.queryChildren(category);
} }
@Override @Override
public void saveEntity(CategoryEntity categoryEntity) { public void saveEntity(CategoryEntity categoryEntity) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
String pingYin = PinYinUtil.getPingYin(categoryEntity.getCategoryTitle()); String pingYin = PinYinUtil.getPingYin(categoryEntity.getCategoryTitle());
//如果用户自己填入了拼音则使用用户的 //如果用户自己填入了拼音则使用用户的
if (StrUtil.isNotBlank(categoryEntity.getCategoryPinyin())) { if (StrUtil.isNotBlank(categoryEntity.getCategoryPinyin())) {
pingYin = categoryEntity.getCategoryPinyin(); pingYin = categoryEntity.getCategoryPinyin();
} }
CategoryEntity category = new CategoryEntity(); CategoryEntity category = new CategoryEntity();
category.setCategoryPinyin(pingYin); category.setCategoryPinyin(pingYin);
Object categoryBizEntity = getEntity(category); Object categoryBizEntity = getEntity(category);
setParentId(categoryEntity); setParentId(categoryEntity);
categoryEntity.setCategoryPinyin(pingYin); categoryEntity.setCategoryPinyin(pingYin);
//更新新的父级 //更新新的父级
if (StrUtil.isNotBlank(categoryEntity.getCategoryId()) && !"0".equals(categoryEntity.getCategoryId())) { if (StrUtil.isNotBlank(categoryEntity.getCategoryId()) && !"0".equals(categoryEntity.getCategoryId())) {
CategoryEntity parent = getById(categoryEntity.getCategoryId()); CategoryEntity parent = getById(categoryEntity.getCategoryId());
//如果之前是叶子节点就更新 //如果之前是叶子节点就更新
if (parent.getLeaf()) { if (parent.getLeaf()) {
parent.setLeaf(false); parent.setLeaf(false);
updateById(parent); updateById(parent);
} }
} }
categoryEntity.setLeaf(false); categoryEntity.setLeaf(false);
//如果是新增栏目一定是叶子节点 //如果是新增栏目一定是叶子节点
if (StrUtil.isEmpty(categoryEntity.getId())) { if (StrUtil.isEmpty(categoryEntity.getId())) {
categoryEntity.setLeaf(true); categoryEntity.setLeaf(true);
} }
super.save(categoryEntity); super.save(categoryEntity);
//拼音存在则拼接id //拼音存在则拼接id
if (categoryBizEntity != null) { if (categoryBizEntity != null) {
categoryEntity.setCategoryPinyin(pingYin + categoryEntity.getId()); categoryEntity.setCategoryPinyin(pingYin + categoryEntity.getId());
} }
CategoryEntity parentCategory = null; CategoryEntity parentCategory = null;
if (StringUtils.isNotBlank(categoryEntity.getCategoryId())) { if (StringUtils.isNotBlank(categoryEntity.getCategoryId())) {
parentCategory = (CategoryEntity) getById(categoryEntity.getCategoryId()); parentCategory = (CategoryEntity) getById(categoryEntity.getCategoryId());
} }
//保存链接地址 //保存链接地址
String path = ObjectUtil.isNotNull(parentCategory) ? parentCategory.getCategoryPath() : ""; String path = ObjectUtil.isNotNull(parentCategory) ? parentCategory.getCategoryPath() : "";
categoryEntity.setCategoryPath(path + "/" + categoryEntity.getCategoryPinyin()); categoryEntity.setCategoryPath(path + "/" + categoryEntity.getCategoryPinyin());
setTopId(categoryEntity); setTopId(categoryEntity);
super.updateById(categoryEntity); super.updateById(categoryEntity);
} }
private void setParentId(CategoryEntity categoryEntity) { private void setParentId(CategoryEntity categoryEntity) {
String path = ""; String path = "";
if (StringUtils.isNotEmpty(categoryEntity.getCategoryId()) && Long.parseLong(categoryEntity.getCategoryId()) > 0) { if (StringUtils.isNotEmpty(categoryEntity.getCategoryId()) && Long.parseLong(categoryEntity.getCategoryId()) > 0) {
CategoryEntity category = (CategoryEntity) getById(categoryEntity.getCategoryId()); CategoryEntity category = (CategoryEntity) getById(categoryEntity.getCategoryId());
path = category.getCategoryPath(); path = category.getCategoryPath();
if (StringUtils.isEmpty(category.getCategoryParentIds())) { if (StringUtils.isEmpty(category.getCategoryParentIds())) {
categoryEntity.setCategoryParentIds(category.getId()); categoryEntity.setCategoryParentIds(category.getId());
} else { } else {
categoryEntity.setCategoryParentIds(category.getCategoryParentIds() + "," + category.getId()); categoryEntity.setCategoryParentIds(category.getCategoryParentIds() + "," + category.getId());
} }
} else { } else {
categoryEntity.setCategoryParentIds(null); categoryEntity.setCategoryParentIds(null);
} }
//保存时先保存再修改链接地址,修改时直接修改 //保存时先保存再修改链接地址,修改时直接修改
if (StringUtils.isNotBlank(categoryEntity.getId())) { if (StringUtils.isNotBlank(categoryEntity.getId())) {
categoryEntity.setCategoryPath(path + "/" + categoryEntity.getCategoryPinyin()); categoryEntity.setCategoryPath(path + "/" + categoryEntity.getCategoryPinyin());
} }
} }
private void setChildParentId(CategoryEntity categoryEntity, String topId) { private void setChildParentId(CategoryEntity categoryEntity, String topId) {
CategoryEntity category = new CategoryEntity(); CategoryEntity category = new CategoryEntity();
category.setCategoryId(categoryEntity.getId()); category.setCategoryId(categoryEntity.getId());
List<CategoryEntity> list = categoryDao.query(category); List<CategoryEntity> list = categoryDao.query(category);
list.forEach(x -> { list.forEach(x -> {
if (StringUtils.isEmpty(categoryEntity.getCategoryParentIds())) { if (StringUtils.isEmpty(categoryEntity.getCategoryParentIds())) {
x.setCategoryParentIds(categoryEntity.getId()); x.setCategoryParentIds(categoryEntity.getId());
} else { } else {
x.setCategoryParentIds(categoryEntity.getCategoryParentIds() + "," + categoryEntity.getId()); x.setCategoryParentIds(categoryEntity.getCategoryParentIds() + "," + categoryEntity.getId());
} }
//更新topid //更新topid
x.setTopId(topId); x.setTopId(topId);
String path = categoryEntity.getCategoryPath(); String path = categoryEntity.getCategoryPath();
//判断是否有parentIds //判断是否有parentIds
x.setCategoryPath(path + "/" + x.getCategoryPinyin()); x.setCategoryPath(path + "/" + x.getCategoryPinyin());
//去除多余的/符号 //去除多余的/符号
super.updateEntity(x); super.updateEntity(x);
setChildParentId(x, topId); setChildParentId(x, topId);
}); });
} }
@Override @Override
public void updateEntity(CategoryEntity entity) { public void updateEntity(CategoryEntity entity) {
setParentId(entity); setParentId(entity);
String pingYin = entity.getCategoryPinyin(); String pingYin = entity.getCategoryPinyin();
if (StrUtil.isNotBlank(pingYin)) { if (StrUtil.isNotBlank(pingYin)) {
CategoryEntity category = new CategoryEntity(); CategoryEntity category = new CategoryEntity();
category.setCategoryPinyin(pingYin); category.setCategoryPinyin(pingYin);
CategoryEntity categoryBizEntity = (CategoryEntity) getEntity(category); CategoryEntity categoryBizEntity = (CategoryEntity) getEntity(category);
//拼音存在则拼接id //拼音存在则拼接id
if (categoryBizEntity != null && !categoryBizEntity.getId().equals(entity.getId())) { if (categoryBizEntity != null && !categoryBizEntity.getId().equals(entity.getId())) {
entity.setCategoryPinyin(pingYin + entity.getId()); entity.setCategoryPinyin(pingYin + entity.getId());
} }
} }
setParentLeaf(entity); setParentLeaf(entity);
setTopId(entity); setTopId(entity);
//如果父级栏目和父级id为空字符串则转化成null //如果父级栏目和父级id为空字符串则转化成null
if (StringUtils.isEmpty(entity.getCategoryId())) { if (StringUtils.isEmpty(entity.getCategoryId())) {
entity.setCategoryId(null); entity.setCategoryId(null);
} }
if (StringUtils.isEmpty(entity.getCategoryParentIds())) { if (StringUtils.isEmpty(entity.getCategoryParentIds())) {
entity.setCategoryParentIds(null); entity.setCategoryParentIds(null);
} }
categoryDao.updateEntity(entity); categoryDao.updateEntity(entity);
//更新子节点所有父节点id和topid //更新子节点所有父节点id和topid
//如果本节点的topid为0(顶级栏目),则把自身的id作为子栏目的topid,非0所有的子栏目和本栏目使用同一个topid //如果本节点的topid为0(顶级栏目),则把自身的id作为子栏目的topid,非0所有的子栏目和本栏目使用同一个topid
String topId = entity.getTopId(); String topId = entity.getTopId();
if (topId.equals("0")) { if (topId.equals("0")) {
topId = entity.getId(); topId = entity.getId();
} }
setChildParentId(entity, topId); setChildParentId(entity, topId);
} }
@Override @Override
public void update(CategoryEntity entity) { public void update(CategoryEntity entity) {
super.updateEntity(entity); super.updateEntity(entity);
} }
@Override @Override
public void delete(String categoryId) { public void delete(String categoryId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
CategoryEntity category = (CategoryEntity) categoryDao.selectById(categoryId); CategoryEntity category = (CategoryEntity) categoryDao.selectById(categoryId);
//删除父类 //删除父类
if (category != null) { if (category != null) {
List<CategoryEntity> childrenList = categoryDao.queryChildren(category); List<CategoryEntity> childrenList = categoryDao.queryChildren(category);
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
for (int i = 0; i < childrenList.size(); i++) { for (int i = 0; i < childrenList.size(); i++) {
//删除子类 //删除子类
ids.add(childrenList.get(i).getId()); ids.add(childrenList.get(i).getId());
} }
categoryDao.deleteBatchIds(ids); categoryDao.deleteBatchIds(ids);
// 删除文章 // 删除文章
contentDao.deleteEntityByCategoryIds(ids.toArray(new String[ids.size()])); contentDao.deleteEntityByCategoryIds(ids.toArray(new String[ids.size()]));
//获取被删节点的父节点 //获取被删节点的父节点
CategoryEntity parentNode = categoryDao.selectById(category.getCategoryId()); CategoryEntity parentNode = categoryDao.selectById(category.getCategoryId());
//获取被删节点的所属栏目的其他节点 //获取被删节点的所属栏目的其他节点
List<CategoryEntity> childNode = categoryDao.queryChildren(parentNode); List<CategoryEntity> childNode = categoryDao.queryChildren(parentNode);
//判断删除的是否为主节点 //判断删除的是否为主节点
if (parentNode != null) { if (parentNode != null) {
UpdateWrapper<CategoryEntity> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<CategoryEntity> updateWrapper = new UpdateWrapper<>();
//如果没有子节点进行更新代码 //如果没有子节点进行更新代码
if (childNode.size() == 1) { if (childNode.size() == 1) {
updateWrapper.eq("id", parentNode.getId()).set("leaf", 1); updateWrapper.eq("id", parentNode.getId()).set("leaf", 1);
categoryDao.update(null, updateWrapper); categoryDao.update(null, updateWrapper);
} }
} }
} }
} }
/** /**
* 设置父级叶子节点 * 设置父级叶子节点
* @param entity * @param entity
*/ */
private void setParentLeaf(CategoryEntity entity) { private void setParentLeaf(CategoryEntity entity) {
CategoryEntity categoryEntity = getById(entity.getId()); CategoryEntity categoryEntity = getById(entity.getId());
//如果父级不为空并且修改了父级则需要更新父级 //如果父级不为空并且修改了父级则需要更新父级
if (entity.getCategoryId() != null && !entity.getCategoryId().equals(categoryEntity.getCategoryId())) { if (entity.getCategoryId() != null && !entity.getCategoryId().equals(categoryEntity.getCategoryId())) {
//更新旧的父级 //更新旧的父级
if (StrUtil.isNotBlank(categoryEntity.getCategoryId()) && !"0".equals(categoryEntity.getCategoryId())) { if (StrUtil.isNotBlank(categoryEntity.getCategoryId()) && !"0".equals(categoryEntity.getCategoryId())) {
CategoryEntity parent = getById(categoryEntity.getCategoryId()); CategoryEntity parent = getById(categoryEntity.getCategoryId());
//如果修改了父级则需要判断父级是否还有子节点 //如果修改了父级则需要判断父级是否还有子节点
boolean leaf = parent.getLeaf(); boolean leaf = parent.getLeaf();
//查找不等于当前更新的分类子集,有则不是叶子节点 //查找不等于当前更新的分类子集,有则不是叶子节点
QueryWrapper<CategoryEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<CategoryEntity> queryWrapper = new QueryWrapper<>();
parent.setLeaf(count(queryWrapper.eq("category_id", parent.getId()).ne("id", entity.getId())) == 0); parent.setLeaf(count(queryWrapper.eq("category_id", parent.getId()).ne("id", entity.getId())) == 0);
if (leaf != parent.getLeaf()) { if (leaf != parent.getLeaf()) {
updateById(parent); updateById(parent);
} }
} }
//更新新的父级 //更新新的父级
if (StrUtil.isNotBlank(entity.getCategoryId()) && !"0".equals(entity.getCategoryId())) { if (StrUtil.isNotBlank(entity.getCategoryId()) && !"0".equals(entity.getCategoryId())) {
CategoryEntity parent = getById(entity.getCategoryId()); CategoryEntity parent = getById(entity.getCategoryId());
//如果之前是叶子节点就更新 //如果之前是叶子节点就更新
if (parent.getLeaf()) { if (parent.getLeaf()) {
parent.setLeaf(false); parent.setLeaf(false);
updateById(parent); updateById(parent);
} }
} }
} }
} }
/** /**
* 设置顶级id * 设置顶级id
* @param entity * @param entity
*/ */
private void setTopId(CategoryEntity entity) { private void setTopId(CategoryEntity entity) {
String categoryParentId = entity.getCategoryParentIds(); String categoryParentId = entity.getCategoryParentIds();
if (StrUtil.isNotBlank(categoryParentId)) { if (StrUtil.isNotBlank(categoryParentId)) {
String[] ids = categoryParentId.split(","); String[] ids = categoryParentId.split(",");
//如果有ParentId就取第一个 //如果有ParentId就取第一个
if (ids.length > 0) { if (ids.length > 0) {
entity.setTopId(ids[0]); entity.setTopId(ids[0]);
return; return;
} }
} }
entity.setTopId("0"); entity.setTopId("0");
} }
@Override @Override
public void copyCategory(CategoryEntity category) { public void copyCategory(CategoryEntity category) {
String oldId = category.getId(); String oldId = category.getId();
//先保存被复制第一层栏目,因为第一层栏目不需要变更父级栏目 //先保存被复制第一层栏目,因为第一层栏目不需要变更父级栏目
category = getById(oldId); category = getById(oldId);
//id、拼音和路径按照原来的业务逻辑生成 //id、拼音和路径按照原来的业务逻辑生成
category.setId(null); category.setId(null);
category.setCategoryPinyin(null); category.setCategoryPinyin(null);
category.setCategoryPath(null); category.setCategoryPath(null);
saveEntity(category); saveEntity(category);
//传入简要被复制子栏目的id和复制后的生成的id,复制的子栏目全部使用 //传入简要被复制子栏目的id和复制后的生成的id,复制的子栏目全部使用
recursionCopyChilds(oldId, category.getId()); recursionCopyChilds(oldId, category.getId());
} }
/* /*
* 递归复制子栏目 * 递归复制子栏目
* @param oldParentId:被复制的父级栏目id(需要数据库原来存在该数据) * @param oldParentId:被复制的父级栏目id(需要数据库原来存在该数据)
* @param newParentId:复制栏目后新父级的id(新插入数据的id) * @param newParentId:复制栏目后新父级的id(新插入数据的id)
* */ * */
private void recursionCopyChilds(String oldParentId, String newParentId) { private void recursionCopyChilds(String oldParentId, String newParentId) {
CategoryEntity _category = new CategoryEntity(); CategoryEntity _category = new CategoryEntity();
_category.setCategoryId(oldParentId); _category.setCategoryId(oldParentId);
List<CategoryEntity> childs = query(_category); List<CategoryEntity> childs = query(_category);
for (CategoryEntity child : childs) { for (CategoryEntity child : childs) {
String childId = child.getId(); String childId = child.getId();
//id、拼音和路径按照原来的业务逻辑生成 //id、拼音和路径按照原来的业务逻辑生成
child.setId(null); child.setId(null);
child.setCategoryPinyin(null); child.setCategoryPinyin(null);
child.setCategoryPath(null); child.setCategoryPath(null);
child.setCategoryId(newParentId); child.setCategoryId(newParentId);
saveEntity(child); saveEntity(child);
//如果该栏目下还有子栏目则继续复制该栏目里的子栏目 //如果该栏目下还有子栏目则继续复制该栏目里的子栏目
recursionCopyChilds(childId, child.getId()); recursionCopyChilds(childId, child.getId());
} }
} }
} }
...@@ -18,17 +18,17 @@ ...@@ -18,17 +18,17 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.constant; package net.mingsoft.cms.constant;
/** /**
* @Author: 铭飞开源团队--huise * @Author: 铭飞开源团队--huise
* @Date: 2019/8/9 20:51 * @Date: 2019/8/9 20:51
*/ */
public class Const { public class Const {
/** /**
* 资源文件 * 资源文件
*/ */
public final static String RESOURCES = "net.mingsoft.cms.resources.resources"; public final static String RESOURCES = "net.mingsoft.cms.resources.resources";
} }
...@@ -18,30 +18,30 @@ ...@@ -18,30 +18,30 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.dao; package net.mingsoft.cms.dao;
import net.mingsoft.base.dao.IBaseDao; import net.mingsoft.base.dao.IBaseDao;
import net.mingsoft.cms.entity.CategoryEntity; import net.mingsoft.cms.entity.CategoryEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
/** /**
* 分类持久层 * 分类持久层
* @author 铭飞开发团队 * @author 铭飞开发团队
* 创建日期:2019-11-28 15:12:32<br/> * 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
@Component("cmsCategoryDao") @Component("cmsCategoryDao")
public interface ICategoryDao extends IBaseDao<CategoryEntity> { public interface ICategoryDao extends IBaseDao<CategoryEntity> {
/** /**
* 查询当前分类下面的所有子分类 * 查询当前分类下面的所有子分类
* @param category 必须存在categoryId categoryParentId * @param category 必须存在categoryId categoryParentId
* @return * @return
*/ */
public List<CategoryEntity> queryChildren(CategoryEntity category); public List<CategoryEntity> queryChildren(CategoryEntity category);
} }
...@@ -18,17 +18,17 @@ ...@@ -18,17 +18,17 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * 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. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
package net.mingsoft.cms.dao; package net.mingsoft.cms.dao;
import net.mingsoft.base.dao.IBaseDao; import net.mingsoft.base.dao.IBaseDao;
/** /**
* 文章浏览记录持久层 * 文章浏览记录持久层
* @author 铭飞开发团队 * @author 铭飞开发团队
* 创建日期:2019-12-23 9:24:03<br/> * 创建日期:2019-12-23 9:24:03<br/>
* 历史修订:<br/> * 历史修订:<br/>
*/ */
public interface ICmsHistoryLogDao extends IBaseDao { public interface ICmsHistoryLogDao extends IBaseDao {
} }
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * 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, * the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions: * subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all * The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. * copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
...@@ -24,6 +24,11 @@ package net.mingsoft.cms.entity; ...@@ -24,6 +24,11 @@ package net.mingsoft.cms.entity;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import net.mingsoft.base.entity.BaseEntity; import net.mingsoft.base.entity.BaseEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.config.MSProperties;
import net.mingsoft.mdiy.util.ConfigUtil;
import java.io.File;
/** /**
* 分类实体 * 分类实体
...@@ -131,6 +136,21 @@ public class CategoryEntity extends BaseEntity { ...@@ -131,6 +136,21 @@ public class CategoryEntity extends BaseEntity {
*/ */
private String topId; private String topId;
/**
* 路径url
*/
@TableField(exist = false)
private String url;
/**
* 设置url路径
*
* @param url 路径的字符串
*/
public void setUrl(String url) {
this.url = url;
}
public Boolean getLeaf() { public Boolean getLeaf() {
return leaf; return leaf;
} }
...@@ -419,7 +439,8 @@ public class CategoryEntity extends BaseEntity { ...@@ -419,7 +439,8 @@ public class CategoryEntity extends BaseEntity {
* 获取栏目Id(标签使用) * 获取栏目Id(标签使用)
*/ */
public Boolean getTypeleaf() { public Boolean getTypeleaf() {
return this.leaf; } return this.leaf;
}
/** /**
...@@ -431,6 +452,7 @@ public class CategoryEntity extends BaseEntity { ...@@ -431,6 +452,7 @@ public class CategoryEntity extends BaseEntity {
@TableField(exist = false) @TableField(exist = false)
private String typepath; private String typepath;
/** /**
* 获取栏目图片 (标签使用) * 获取栏目图片 (标签使用)
*/ */
...@@ -462,4 +484,22 @@ public class CategoryEntity extends BaseEntity { ...@@ -462,4 +484,22 @@ public class CategoryEntity extends BaseEntity {
this.childsize = childsize; this.childsize = childsize;
} }
/**
* 获取url路径
*
* @return url路径的字符串
*/
public String getUrl() {
String appDir = "";
String htmlDir = MSProperties.diy.htmlDir;
String categoryPath = this.getCategoryPath();
String categoryPinyin = this.getCategoryPinyin();
if (!(ConfigUtil.getBoolean("短链配置", "shortLinkSwitch", false))) {
//未开启短链
appDir = "/" + BasicUtil.getApp().getAppDir();
return url = "/" + htmlDir + appDir + categoryPath + "/index.html";
}
//开启短链后的url拼接
return url = "/" + htmlDir + appDir + "/" + categoryPinyin + ".html";
}
} }
...@@ -132,7 +132,8 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -132,7 +132,8 @@ public class WebConfig implements WebMvcConfigurer {
@Bean @Bean
public FilterRegistrationBean xssFilterRegistration(@Value("${ms.xss.enable:true}") boolean xssEnable, public FilterRegistrationBean xssFilterRegistration(@Value("${ms.xss.enable:true}") boolean xssEnable,
@Value("${ms.xss.filter-url}") String filterUrl, @Value("${ms.xss.filter-url}") String filterUrl,
@Value("${ms.xss.exclude-url}") String excludeUrl) { @Value("${ms.xss.exclude-url}") String excludeUrl,
@Value("${ms.xss.exclude-filed}") String excludeFiled) {
XSSEscapeFilter xssFilter = new XSSEscapeFilter(); XSSEscapeFilter xssFilter = new XSSEscapeFilter();
Map<String, String> initParameters = new HashMap(); Map<String, String> initParameters = new HashMap();
FilterRegistrationBean registration = new FilterRegistrationBean(); FilterRegistrationBean registration = new FilterRegistrationBean();
...@@ -149,6 +150,9 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -149,6 +150,9 @@ public class WebConfig implements WebMvcConfigurer {
}else { }else {
xssFilter.excludes.add(MSProperties.manager.path + "/**"); xssFilter.excludes.add(MSProperties.manager.path + "/**");
} }
if (excludeFiled != null && StrUtil.isNotBlank(excludeFiled)) {
xssFilter.excludesFiled.addAll(Arrays.asList(excludeFiled.split(",")));
}
initParameters.put("isIncludeRichText", "false"); initParameters.put("isIncludeRichText", "false");
registration.setInitParameters(initParameters); registration.setInitParameters(initParameters);
registration.setFilter(xssFilter); registration.setFilter(xssFilter);
......
...@@ -92,7 +92,6 @@ ...@@ -92,7 +92,6 @@
}, },
}, },
created() { created() {
this.likeTotal()
} }
}) })
</script> </script>
......
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