Merge remote-tracking branch 'origin/master'

master
YTD 2 years ago
commit d6d869cedb
  1. 35
      jeecg-boot/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java
  2. 7
      jeecg-boot/jeecg-boot-module-cms/src/main/java/org/jeecg/modules/cms/admin/controller/CmsArticleController.java
  3. 18
      jeecg-boot/jeecg-boot-module-cms/src/main/java/org/jeecg/modules/cms/admin/controller/CmsColumnController.java

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.PropertyUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.hibernate.procedure.spi.ParameterRegistrationImplementor;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.system.vo.LoginUser;
@ -37,11 +38,15 @@ import java.util.stream.Collectors;
*/ */
@Slf4j @Slf4j
public class JeecgController<T, S extends IService<T>> { public class JeecgController<T, S extends IService<T>> {
public static final Boolean HAS_QUERY = Boolean.TRUE.booleanValue();
@Autowired @Autowired
S service; S service;
@Value("${jeecg.path.upload}") @Value("${jeecg.path.upload}")
private String upLoadPath; private String upLoadPath;
/** /**
* 导出excel * 导出excel
* *
@ -53,10 +58,9 @@ public class JeecgController<T, S extends IService<T>> {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String getRealname="佚名"; String getRealname = "佚名";
if(sysUser!=null) if (sysUser != null) {
{ getRealname = sysUser.getRealname();
getRealname=sysUser.getRealname();
} }
// Step.2 获取导出数据 // Step.2 获取导出数据
@ -76,13 +80,14 @@ public class JeecgController<T, S extends IService<T>> {
mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下 mv.addObject(NormalExcelConstants.FILE_NAME, title); //此处设置的filename无效 ,前端会重更新设置一下
mv.addObject(NormalExcelConstants.CLASS, clazz); mv.addObject(NormalExcelConstants.CLASS, clazz);
//update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + getRealname, title); ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + getRealname, title);
exportParams.setImageBasePath(upLoadPath); exportParams.setImageBasePath(upLoadPath);
//update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
mv.addObject(NormalExcelConstants.PARAMS,exportParams); mv.addObject(NormalExcelConstants.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, exportList); mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
return mv; return mv;
} }
/** /**
* 根据每页sheet数量导出多sheet * 根据每页sheet数量导出多sheet
* *
@ -94,16 +99,16 @@ public class JeecgController<T, S extends IService<T>> {
* @param pageNum 每个sheet的数据条数 * @param pageNum 每个sheet的数据条数
* @param request * @param request
*/ */
protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title,String exportFields,Integer pageNum) { protected ModelAndView exportXlsSheet(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields, Integer pageNum) {
// Step.1 组装查询条件 // Step.1 组装查询条件
QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap()); QueryWrapper<T> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
// Step.2 计算分页sheet数据 // Step.2 计算分页sheet数据
double total = service.count(); double total = service.count();
int count = (int)Math.ceil(total/pageNum); int count = (int) Math.ceil(total / pageNum);
// Step.3 多sheet处理 // Step.3 多sheet处理
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
for (int i = 1; i <=count ; i++) { for (int i = 1; i <= count; i++) {
Page<T> page = new Page<T>(i, pageNum); Page<T> page = new Page<T>(i, pageNum);
IPage<T> pageList = service.page(page, queryWrapper); IPage<T> pageList = service.page(page, queryWrapper);
List<T> records = pageList.getRecords(); List<T> records = pageList.getRecords();
@ -117,11 +122,11 @@ public class JeecgController<T, S extends IService<T>> {
exportList = records; exportList = records;
} }
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title+i,upLoadPath); ExportParams exportParams = new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title + i, upLoadPath);
exportParams.setType(ExcelType.XSSF); exportParams.setType(ExcelType.XSSF);
//map.put("title",exportParams);//表格Title //map.put("title",exportParams);//表格Title
map.put(NormalExcelConstants.PARAMS,exportParams);//表格Title map.put(NormalExcelConstants.PARAMS, exportParams);//表格Title
map.put(NormalExcelConstants.CLASS,clazz);//表格对应实体 map.put(NormalExcelConstants.CLASS, clazz);//表格对应实体
map.put(NormalExcelConstants.DATA_LIST, exportList);//数据集合 map.put(NormalExcelConstants.DATA_LIST, exportList);//数据集合
listMap.add(map); listMap.add(map);
} }
@ -138,9 +143,9 @@ public class JeecgController<T, S extends IService<T>> {
* *
* @param request * @param request
*/ */
protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title,String exportFields) { protected ModelAndView exportXls(HttpServletRequest request, T object, Class<T> clazz, String title, String exportFields) {
ModelAndView mv = this.exportXls(request,object,clazz,title); ModelAndView mv = this.exportXls(request, object, clazz, title);
mv.addObject(NormalExcelConstants.EXPORT_FIELDS,exportFields); mv.addObject(NormalExcelConstants.EXPORT_FIELDS, exportFields);
return mv; return mv;
} }

@ -55,7 +55,7 @@ public class CmsArticleController extends JeecgController<CmsArticle, ICmsArticl
* @param req * @param req
* @return * @return
*/ */
// @AutoLog(value = "文章管理-分页列表查询") @AutoLog(value = "文章管理-分页列表查询")
@ApiOperation(value = "文章管理-分页列表查询", notes = "文章管理-分页列表查询") @ApiOperation(value = "文章管理-分页列表查询", notes = "文章管理-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/list")
public Result<?> queryPageList(CmsArticle cmsArticle, public Result<?> queryPageList(CmsArticle cmsArticle,
@ -74,7 +74,6 @@ public class CmsArticleController extends JeecgController<CmsArticle, ICmsArticl
* @param cmsArticle * @param cmsArticle
* @return * @return
*/ */
// @AutoLog(value = "文章管理-添加")
@ApiOperation(value = "文章管理-添加", notes = "文章管理-添加") @ApiOperation(value = "文章管理-添加", notes = "文章管理-添加")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result<?> add(@RequestBody CmsArticle cmsArticle) { public Result<?> add(@RequestBody CmsArticle cmsArticle) {
@ -106,7 +105,6 @@ public class CmsArticleController extends JeecgController<CmsArticle, ICmsArticl
* @param cmsArticle * @param cmsArticle
* @return * @return
*/ */
// @AutoLog(value = "文章管理-编辑")
@ApiOperation(value = "文章管理-编辑", notes = "文章管理-编辑") @ApiOperation(value = "文章管理-编辑", notes = "文章管理-编辑")
@PutMapping(value = "/edit") @PutMapping(value = "/edit")
public Result<?> edit(@RequestBody CmsArticle cmsArticle) { public Result<?> edit(@RequestBody CmsArticle cmsArticle) {
@ -125,7 +123,6 @@ public class CmsArticleController extends JeecgController<CmsArticle, ICmsArticl
* @param id * @param id
* @return * @return
*/ */
// @AutoLog(value = "文章管理-通过id删除")
@ApiOperation(value = "文章管理-通过id删除", notes = "文章管理-通过id删除") @ApiOperation(value = "文章管理-通过id删除", notes = "文章管理-通过id删除")
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "id", required = true) String id) { public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
@ -139,7 +136,6 @@ public class CmsArticleController extends JeecgController<CmsArticle, ICmsArticl
* @param ids * @param ids
* @return * @return
*/ */
// @AutoLog(value = "文章管理-批量删除")
@ApiOperation(value = "文章管理-批量删除", notes = "文章管理-批量删除") @ApiOperation(value = "文章管理-批量删除", notes = "文章管理-批量删除")
@DeleteMapping(value = "/deleteBatch") @DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
@ -153,7 +149,6 @@ public class CmsArticleController extends JeecgController<CmsArticle, ICmsArticl
* @param id * @param id
* @return * @return
*/ */
// @AutoLog(value = "文章管理-通过id查询")
@ApiOperation(value = "文章管理-通过id查询", notes = "文章管理-通过id查询") @ApiOperation(value = "文章管理-通过id查询", notes = "文章管理-通过id查询")
@GetMapping(value = "/queryById") @GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {

@ -46,6 +46,8 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
@Autowired @Autowired
private ICmsColumnService cmsColumnService; private ICmsColumnService cmsColumnService;
private static final String ADMIN_COLUMN_KEY = "99";
@ApiOperation(value = "文章栏目-获取栏目树型列表", notes = "文章栏目-获取栏目树型列表") @ApiOperation(value = "文章栏目-获取栏目树型列表", notes = "文章栏目-获取栏目树型列表")
@GetMapping(value = "/getColumnTree") @GetMapping(value = "/getColumnTree")
public Result<?> getColumnTree(HttpServletRequest req) { public Result<?> getColumnTree(HttpServletRequest req) {
@ -76,7 +78,6 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
* @param req * @param req
* @return * @return
*/ */
// @AutoLog(value = "文章栏目-分页列表查询")
@ApiOperation(value = "文章栏目-分页列表查询", notes = "文章栏目-分页列表查询") @ApiOperation(value = "文章栏目-分页列表查询", notes = "文章栏目-分页列表查询")
@GetMapping(value = "/rootList") @GetMapping(value = "/rootList")
public Result<?> queryPageList(CmsColumn cmsColumn, public Result<?> queryPageList(CmsColumn cmsColumn,
@ -84,7 +85,7 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
String hasQuery = req.getParameter("hasQuery"); String hasQuery = req.getParameter("hasQuery");
if (hasQuery != null && "true".equals(hasQuery)) { if (hasQuery != null && HAS_QUERY.equals(hasQuery)) {
QueryWrapper<CmsColumn> queryWrapper = QueryGenerator.initQueryWrapper(cmsColumn, req.getParameterMap()); QueryWrapper<CmsColumn> queryWrapper = QueryGenerator.initQueryWrapper(cmsColumn, req.getParameterMap());
List<CmsColumn> list = cmsColumnService.queryTreeListNoPage(queryWrapper); List<CmsColumn> list = cmsColumnService.queryTreeListNoPage(queryWrapper);
IPage<CmsColumn> pageList = new Page<>(1, 10, list.size()); IPage<CmsColumn> pageList = new Page<>(1, 10, list.size());
@ -105,7 +106,6 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
Page<CmsColumn> page = new Page<CmsColumn>(pageNo, pageSize); Page<CmsColumn> page = new Page<CmsColumn>(pageNo, pageSize);
IPage<CmsColumn> pageList = cmsColumnService.page(page, queryWrapper); IPage<CmsColumn> pageList = cmsColumnService.page(page, queryWrapper);
List<CmsColumn> records = pageList.getRecords(); List<CmsColumn> records = pageList.getRecords();
// records.sort(Comparator.comparing(CmsColumn::getSort));
Collections.sort(records, Comparator.comparingInt(CmsColumn::getSort)); Collections.sort(records, Comparator.comparingInt(CmsColumn::getSort));
return Result.OK(pageList); return Result.OK(pageList);
@ -119,7 +119,6 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
* @param req * @param req
* @return * @return
*/ */
// @AutoLog(value = "文章栏目-获取子数据")
@ApiOperation(value = "文章栏目-获取子数据", notes = "文章栏目-获取子数据") @ApiOperation(value = "文章栏目-获取子数据", notes = "文章栏目-获取子数据")
@GetMapping(value = "/childList") @GetMapping(value = "/childList")
public Result<?> queryPageList(CmsColumn cmsColumn, HttpServletRequest req) { public Result<?> queryPageList(CmsColumn cmsColumn, HttpServletRequest req) {
@ -138,7 +137,6 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
* @return 返回 IPage * @return 返回 IPage
* @return * @return
*/ */
// @AutoLog(value = "文章栏目-批量获取子数据")
@ApiOperation(value = "文章栏目-批量获取子数据", notes = "文章栏目-批量获取子数据") @ApiOperation(value = "文章栏目-批量获取子数据", notes = "文章栏目-批量获取子数据")
@GetMapping("/getChildListBatch") @GetMapping("/getChildListBatch")
public Result getChildListBatch(@RequestParam("parentIds") String parentIds) { public Result getChildListBatch(@RequestParam("parentIds") String parentIds) {
@ -162,7 +160,6 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
* @param cmsColumn * @param cmsColumn
* @return * @return
*/ */
// @AutoLog(value = "文章栏目-添加")
@ApiOperation(value = "文章栏目-添加", notes = "文章栏目-添加") @ApiOperation(value = "文章栏目-添加", notes = "文章栏目-添加")
@PostMapping(value = "/add") @PostMapping(value = "/add")
public Result<?> add(@RequestBody CmsColumn cmsColumn) { public Result<?> add(@RequestBody CmsColumn cmsColumn) {
@ -178,7 +175,6 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
* @param cmsColumn * @param cmsColumn
* @return * @return
*/ */
// @AutoLog(value = "文章栏目-编辑")
@ApiOperation(value = "文章栏目-编辑", notes = "文章栏目-编辑") @ApiOperation(value = "文章栏目-编辑", notes = "文章栏目-编辑")
@PutMapping(value = "/edit") @PutMapping(value = "/edit")
public Result<?> edit(@RequestBody CmsColumn cmsColumn) { public Result<?> edit(@RequestBody CmsColumn cmsColumn) {
@ -196,9 +192,13 @@ public class CmsColumnController extends JeecgController<CmsColumn, ICmsColumnSe
@DeleteMapping(value = "/delete") @DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "id", required = true) String id) { public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
CmsColumn cmsColumn = cmsColumnService.getById(id); CmsColumn cmsColumn = cmsColumnService.getById(id);
if (StringUtils.equals("99", cmsColumn.getId())) throw new JeecgBootException("文章总栏目不可删除"); if (StringUtils.equals(ADMIN_COLUMN_KEY, cmsColumn.getId())) {
throw new JeecgBootException("文章总栏目不可删除");
}
int count = cmsColumnService.count(new LambdaQueryWrapper<CmsColumn>().eq(CmsColumn::getPid, cmsColumn.getId())); int count = cmsColumnService.count(new LambdaQueryWrapper<CmsColumn>().eq(CmsColumn::getPid, cmsColumn.getId()));
if (count > 0) throw new JeecgBootException("存在子栏目暂不可删除"); if (count > 0) {
throw new JeecgBootException("存在子栏目暂不可删除");
}
cmsColumnService.deleteCmsColumn(id); cmsColumnService.deleteCmsColumn(id);
return Result.OK("删除成功!"); return Result.OK("删除成功!");
} }

Loading…
Cancel
Save