|
|
@@ -0,0 +1,146 @@
|
|
|
+package cn.iocoder.yudao.module.rd.controller.admin.news;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+import cn.iocoder.yudao.module.rd.controller.admin.news.vo.NewsPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.rd.controller.admin.news.vo.NewsRespVO;
|
|
|
+import cn.iocoder.yudao.module.rd.controller.admin.news.vo.NewsSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.rd.dal.dataobject.news.NewsDO;
|
|
|
+import cn.iocoder.yudao.module.rd.service.news.NewsService;
|
|
|
+import cn.iocoder.yudao.module.rd.utils.DictDataUtils;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+
|
|
|
+@Tag(name = "管理后台 - 资讯(政策信息 行业科技动态)")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/rd/news")
|
|
|
+@Validated
|
|
|
+public class NewsController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private NewsService newsService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DictDataUtils dictDataUtils;
|
|
|
+
|
|
|
+ @PostMapping("/create")
|
|
|
+ @Operation(summary = "创建资讯(政策信息 行业科技动态)")
|
|
|
+ @PreAuthorize("@ss.hasPermission('rd:news:create')")
|
|
|
+ public CommonResult<Long> createNews(@Valid @RequestBody NewsSaveReqVO createReqVO) {
|
|
|
+ return success(newsService.createNews(createReqVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/update")
|
|
|
+ @Operation(summary = "更新资讯(政策信息 行业科技动态)")
|
|
|
+ @PreAuthorize("@ss.hasPermission('rd:news:update')")
|
|
|
+ public CommonResult<Boolean> updateNews(@Valid @RequestBody NewsSaveReqVO updateReqVO) {
|
|
|
+ newsService.updateNews(updateReqVO);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/delete")
|
|
|
+ @Operation(summary = "删除资讯(政策信息 行业科技动态)")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true)
|
|
|
+ @PreAuthorize("@ss.hasPermission('rd:news:delete')")
|
|
|
+ public CommonResult<Boolean> deleteNews(@RequestParam("id") Long id) {
|
|
|
+ newsService.deleteNews(id);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get")
|
|
|
+ @Operation(summary = "获得资讯(政策信息 行业科技动态)")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
+ @PreAuthorize("@ss.hasPermission('rd:news:query')")
|
|
|
+ public CommonResult<NewsRespVO> getNews(@RequestParam("id") Long id) {
|
|
|
+ NewsDO news = newsService.getNews(id);
|
|
|
+ return success(buildNews(news));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询 资讯 详情
|
|
|
+ * @param news
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private NewsRespVO buildNews(NewsDO news) {
|
|
|
+ // 如果 news 为空 返回空对象
|
|
|
+ if (ObjUtil.isEmpty(news)) {
|
|
|
+ return new NewsRespVO();
|
|
|
+ }
|
|
|
+ NewsRespVO newsVO = BeanUtils.toBean(news, NewsRespVO.class);
|
|
|
+ // 查询 资讯类别 字典数据
|
|
|
+ Map<String, String> newsCategoryPair = dictDataUtils.getDictData("rd_news_category");
|
|
|
+ // 资讯类别
|
|
|
+ String category = newsVO.getNewsCategory();
|
|
|
+ if (StrUtil.isNotBlank(category) && newsCategoryPair.containsKey(category)) {
|
|
|
+ newsVO.setNewsCategoryLabel(newsCategoryPair.get(category));
|
|
|
+ }
|
|
|
+ return newsVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/page")
|
|
|
+ @Operation(summary = "获得资讯(政策信息 行业科技动态)分页")
|
|
|
+ @PreAuthorize("@ss.hasPermission('rd:news:query')")
|
|
|
+ public CommonResult<PageResult<NewsRespVO>> getNewsPage(@Valid NewsPageReqVO pageReqVO) {
|
|
|
+ PageResult<NewsDO> pageResult = newsService.getNewsPage(pageReqVO);
|
|
|
+ return success(new PageResult<>(buildNews(pageResult.getList()), pageResult.getTotal()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置日报的关联信息 部门(施工队伍) 项目 任务 带班干部 日报填报人
|
|
|
+ * @param news
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<NewsRespVO> buildNews(List<NewsDO> news) {
|
|
|
+ if (CollUtil.isEmpty(news)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 查询数据字典值列表
|
|
|
+ // 资讯类别 key字典键值 value字典标签
|
|
|
+ // 查询 核心技术-状态 字典数据
|
|
|
+ Map<String, String> newsCategoryPair = dictDataUtils.getDictData("rd_news_category");
|
|
|
+ return BeanUtils.toBean(news, NewsRespVO.class, (newsVO) -> {
|
|
|
+ if (StrUtil.isNotBlank(newsVO.getNewsCategory())) {
|
|
|
+ if (newsCategoryPair.containsKey(newsVO.getNewsCategory())) {
|
|
|
+ newsVO.setNewsCategoryLabel(newsCategoryPair.get(newsVO.getNewsCategory()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/export-excel")
|
|
|
+ @Operation(summary = "导出资讯(政策信息 行业科技动态) Excel")
|
|
|
+ @PreAuthorize("@ss.hasPermission('rd:news:export')")
|
|
|
+ @ApiAccessLog(operateType = EXPORT)
|
|
|
+ public void exportNewsExcel(@Valid NewsPageReqVO pageReqVO,
|
|
|
+ HttpServletResponse response) throws IOException {
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<NewsDO> list = newsService.getNewsPage(pageReqVO).getList();
|
|
|
+ // 导出 Excel
|
|
|
+ ExcelUtils.write(response, "资讯(政策信息 行业科技动态).xls", "数据", NewsRespVO.class,
|
|
|
+ BeanUtils.toBean(list, NewsRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|