|
|
|
@ -1,36 +1,42 @@ |
|
|
|
package org.jeecg.modules.communityPost.controller; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.URLDecoder; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.net.URLDecoder; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.common.system.query.QueryGenerator; |
|
|
|
import org.jeecg.common.util.oConvertUtils; |
|
|
|
import org.jeecg.modules.communityPost.entity.CommunityPost; |
|
|
|
import org.jeecg.modules.communityPost.service.ICommunityPostService; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil; |
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams; |
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
|
|
|
import org.jeecg.common.system.base.controller.JeecgController; |
|
|
|
import org.jeecg.common.system.vo.LoginUser; |
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.common.system.query.QueryGenerator; |
|
|
|
import org.jeecg.common.util.oConvertUtils; |
|
|
|
import org.jeecg.modules.communityPost.entity.CommunityComment; |
|
|
|
import org.jeecg.modules.communityPost.entity.CommunityPost; |
|
|
|
import org.jeecg.modules.communityPost.vo.CommunityPostPage; |
|
|
|
import org.jeecg.modules.communityPost.service.ICommunityPostService; |
|
|
|
import org.jeecg.modules.communityPost.service.ICommunityCommentService; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
@ -39,16 +45,18 @@ import org.jeecg.common.aspect.annotation.AutoLog; |
|
|
|
/** |
|
|
|
* @Description: 帖子动态信息表 |
|
|
|
* @Author: jeecg-boot |
|
|
|
* @Date: 2025-07-22 |
|
|
|
* @Date: 2025-07-28 |
|
|
|
* @Version: V1.0 |
|
|
|
*/ |
|
|
|
@Api(tags="帖子动态信息表") |
|
|
|
@RestController |
|
|
|
@RequestMapping("/communityPost/communityPost") |
|
|
|
@Slf4j |
|
|
|
public class CommunityPostController extends JeecgController<CommunityPost, ICommunityPostService> { |
|
|
|
public class CommunityPostController { |
|
|
|
@Autowired |
|
|
|
private ICommunityPostService communityPostService; |
|
|
|
@Autowired |
|
|
|
private ICommunityCommentService communityCommentService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 分页列表查询 |
|
|
|
@ -75,28 +83,36 @@ public class CommunityPostController extends JeecgController<CommunityPost, ICom |
|
|
|
/** |
|
|
|
* 添加 |
|
|
|
* |
|
|
|
* @param communityPost |
|
|
|
* @param communityPostPage |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@AutoLog(value = "帖子动态信息表-添加") |
|
|
|
@ApiOperation(value="帖子动态信息表-添加", notes="帖子动态信息表-添加") |
|
|
|
@PostMapping(value = "/add") |
|
|
|
public Result<String> add(@RequestBody CommunityPost communityPost) { |
|
|
|
communityPostService.save(communityPost); |
|
|
|
public Result<String> add(@RequestBody CommunityPostPage communityPostPage) { |
|
|
|
CommunityPost communityPost = new CommunityPost(); |
|
|
|
BeanUtils.copyProperties(communityPostPage, communityPost); |
|
|
|
communityPostService.saveMain(communityPost, communityPostPage.getCommunityCommentList()); |
|
|
|
return Result.OK("添加成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 编辑 |
|
|
|
* |
|
|
|
* @param communityPost |
|
|
|
* @param communityPostPage |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@AutoLog(value = "帖子动态信息表-编辑") |
|
|
|
@ApiOperation(value="帖子动态信息表-编辑", notes="帖子动态信息表-编辑") |
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
|
|
|
public Result<String> edit(@RequestBody CommunityPost communityPost) { |
|
|
|
communityPostService.updateById(communityPost); |
|
|
|
public Result<String> edit(@RequestBody CommunityPostPage communityPostPage) { |
|
|
|
CommunityPost communityPost = new CommunityPost(); |
|
|
|
BeanUtils.copyProperties(communityPostPage, communityPost); |
|
|
|
CommunityPost communityPostEntity = communityPostService.getById(communityPost.getId()); |
|
|
|
if(communityPostEntity==null) { |
|
|
|
return Result.error("未找到对应数据"); |
|
|
|
} |
|
|
|
communityPostService.updateMain(communityPost, communityPostPage.getCommunityCommentList()); |
|
|
|
return Result.OK("编辑成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -110,7 +126,7 @@ public class CommunityPostController extends JeecgController<CommunityPost, ICom |
|
|
|
@ApiOperation(value="帖子动态信息表-通过id删除", notes="帖子动态信息表-通过id删除") |
|
|
|
@DeleteMapping(value = "/delete") |
|
|
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) { |
|
|
|
communityPostService.removeById(id); |
|
|
|
communityPostService.delMain(id); |
|
|
|
return Result.OK("删除成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -124,8 +140,8 @@ public class CommunityPostController extends JeecgController<CommunityPost, ICom |
|
|
|
@ApiOperation(value="帖子动态信息表-批量删除", notes="帖子动态信息表-批量删除") |
|
|
|
@DeleteMapping(value = "/deleteBatch") |
|
|
|
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { |
|
|
|
this.communityPostService.removeByIds(Arrays.asList(ids.split(","))); |
|
|
|
return Result.OK("批量删除成功!"); |
|
|
|
this.communityPostService.delBatchMain(Arrays.asList(ids.split(","))); |
|
|
|
return Result.OK("批量删除成功!"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -143,6 +159,21 @@ public class CommunityPostController extends JeecgController<CommunityPost, ICom |
|
|
|
return Result.error("未找到对应数据"); |
|
|
|
} |
|
|
|
return Result.OK(communityPost); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过id查询 |
|
|
|
* |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
//@AutoLog(value = "帖子评论表通过主表ID查询") |
|
|
|
@ApiOperation(value="帖子评论表主表ID查询", notes="帖子评论表-通主表ID查询") |
|
|
|
@GetMapping(value = "/queryCommunityCommentByMainId") |
|
|
|
public Result<List<CommunityComment>> queryCommunityCommentListByMainId(@RequestParam(name="id",required=true) String id) { |
|
|
|
List<CommunityComment> communityCommentList = communityCommentService.selectByMainId(id); |
|
|
|
return Result.OK(communityCommentList); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -153,11 +184,43 @@ public class CommunityPostController extends JeecgController<CommunityPost, ICom |
|
|
|
*/ |
|
|
|
@RequestMapping(value = "/exportXls") |
|
|
|
public ModelAndView exportXls(HttpServletRequest request, CommunityPost communityPost) { |
|
|
|
return super.exportXls(request, communityPost, CommunityPost.class, "帖子动态信息表"); |
|
|
|
// Step.1 组装查询条件查询数据 |
|
|
|
QueryWrapper<CommunityPost> queryWrapper = QueryGenerator.initQueryWrapper(communityPost, request.getParameterMap()); |
|
|
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
|
|
|
|
//Step.2 获取导出数据 |
|
|
|
List<CommunityPost> queryList = communityPostService.list(queryWrapper); |
|
|
|
// 过滤选中数据 |
|
|
|
String selections = request.getParameter("selections"); |
|
|
|
List<CommunityPost> communityPostList = new ArrayList<CommunityPost>(); |
|
|
|
if(oConvertUtils.isEmpty(selections)) { |
|
|
|
communityPostList = queryList; |
|
|
|
}else { |
|
|
|
List<String> selectionList = Arrays.asList(selections.split(",")); |
|
|
|
communityPostList = queryList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
// Step.3 组装pageList |
|
|
|
List<CommunityPostPage> pageList = new ArrayList<CommunityPostPage>(); |
|
|
|
for (CommunityPost main : communityPostList) { |
|
|
|
CommunityPostPage vo = new CommunityPostPage(); |
|
|
|
BeanUtils.copyProperties(main, vo); |
|
|
|
List<CommunityComment> communityCommentList = communityCommentService.selectByMainId(main.getId()); |
|
|
|
vo.setCommunityCommentList(communityCommentList); |
|
|
|
pageList.add(vo); |
|
|
|
} |
|
|
|
|
|
|
|
// Step.4 AutoPoi 导出Excel |
|
|
|
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
|
|
|
mv.addObject(NormalExcelConstants.FILE_NAME, "帖子动态信息表列表"); |
|
|
|
mv.addObject(NormalExcelConstants.CLASS, CommunityPostPage.class); |
|
|
|
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("帖子动态信息表数据", "导出人:"+sysUser.getRealname(), "帖子动态信息表")); |
|
|
|
mv.addObject(NormalExcelConstants.DATA_LIST, pageList); |
|
|
|
return mv; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过excel导入数据 |
|
|
|
* 通过excel导入数据 |
|
|
|
* |
|
|
|
* @param request |
|
|
|
* @param response |
|
|
|
@ -165,7 +228,34 @@ public class CommunityPostController extends JeecgController<CommunityPost, ICom |
|
|
|
*/ |
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
return super.importExcel(request, response, CommunityPost.class); |
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
|
|
|
MultipartFile file = entity.getValue();// 获取上传文件对象 |
|
|
|
ImportParams params = new ImportParams(); |
|
|
|
params.setTitleRows(2); |
|
|
|
params.setHeadRows(1); |
|
|
|
params.setNeedSave(true); |
|
|
|
try { |
|
|
|
List<CommunityPostPage> list = ExcelImportUtil.importExcel(file.getInputStream(), CommunityPostPage.class, params); |
|
|
|
for (CommunityPostPage page : list) { |
|
|
|
CommunityPost po = new CommunityPost(); |
|
|
|
BeanUtils.copyProperties(page, po); |
|
|
|
communityPostService.saveMain(po, page.getCommunityCommentList()); |
|
|
|
} |
|
|
|
return Result.OK("文件导入成功!数据行数:" + list.size()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(e.getMessage(),e); |
|
|
|
return Result.error("文件导入失败:"+e.getMessage()); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
file.getInputStream().close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return Result.OK("文件导入失败!"); |
|
|
|
} |
|
|
|
|
|
|
|
} |