diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSAdvertisementController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSAdvertisementController.java index 470f919..1d79a18 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSAdvertisementController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSAdvertisementController.java @@ -56,7 +56,7 @@ public class CMSAdvertisementController { @ApiOperation(value = "更新广告", notes = "更新广告") @PutMapping( "/{id}") public Result update(@ApiParam(value = "广告ID", required = true) @PathVariable String id, - @ApiParam(value = "广告信息", required = true) @RequestBody AdvertisementReqModel updateModel,BindingResult bindingResult){ + @ApiParam(value = "广告信息", required = true) @Valid @RequestBody AdvertisementReqModel updateModel,BindingResult bindingResult){ if (bindingResult.hasErrors()) return Result.failed(bindingResult.getFieldError().getDefaultMessage()); return adService.update(id, updateModel); @@ -75,4 +75,10 @@ public class CMSAdvertisementController { @ApiParam(value = "每页条数", required = true) @PathVariable int size){ return adService.search(page, size); } + + @ApiOperation(value = "查询前5条首页banner", notes = "查询前5条首页banner") + @GetMapping ("/banner") + public Result> getBanner(){ + return adService.search(1,5,"首页banner"); + } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/CMSArticleController.java b/luoo_music/src/main/java/com/luoo/music/controller/CMSArticleController.java index d3266f9..aaf7f3a 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/CMSArticleController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/CMSArticleController.java @@ -55,7 +55,7 @@ public class CMSArticleController { @ApiOperation(value = "更新文章", notes = "更新文章") @PutMapping( "/{id}") public Result update(@ApiParam(value = "文章ID", required = true) @PathVariable String id, - @ApiParam(value = "文章信息", required = true) @RequestBody ArticleAddModel updateModel, BindingResult bindingResult){ + @ApiParam(value = "文章信息", required = true) @Valid @RequestBody ArticleAddModel updateModel, BindingResult bindingResult){ if (bindingResult.hasErrors()) return Result.failed(bindingResult.getFieldError().getDefaultMessage()); return articleService.update(id, updateModel); diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/cms/AdvertisementRespDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/cms/AdvertisementRespDTO.java index 84a22fd..280c14b 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/cms/AdvertisementRespDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/cms/AdvertisementRespDTO.java @@ -34,9 +34,16 @@ public class AdvertisementRespDTO { private String userId; @ApiModelProperty(value = "发布作者昵称") private String userName; - @ApiModelProperty(value = "编辑日期,格式为: yyyy.MM.dd") + @ApiModelProperty(value = "编辑日期,格式为: yyyy-MM-dd HH:mm:ss") private String date; + + + @ApiModelProperty(value = "开始日期,格式为: yyyy-MM-dd HH:mm:ss") + private String startTime; + @ApiModelProperty(value = "结束日期,格式为: yyyy-MM-dd HH:mm:ss") + private String endTime; + public static AdvertisementRespDTO convertPojo(Advertisement ad) { AdvertisementRespDTO response = new AdvertisementRespDTO(); @@ -53,7 +60,9 @@ public class AdvertisementRespDTO { response.setContent(ad.getContent()); response.setUserId(ad.getUserId()); response.setUserName(ad.getUserName()); - response.setDate(ad.getCreateTime().toString()); + response.setDate(ad.getCreateTime().format(Constants.formatter)); + response.setStartTime(ad.getStartTime().format(Constants.formatter)); + response.setEndTime(ad.getEndTime().format(Constants.formatter)); return response; } } diff --git a/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java b/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java index 1a2be13..71d5ec9 100644 --- a/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java +++ b/luoo_music/src/main/java/com/luoo/music/dto/response/cms/ArticleRespDTO.java @@ -32,13 +32,13 @@ public class ArticleRespDTO implements Serializable { private String userId; @ApiModelProperty(value = "发布作者昵称") private String userName; - @ApiModelProperty(value = "编辑日期,格式为: yyyy.MM.dd") + @ApiModelProperty(value = "编辑日期,格式为: yyyy-MM-dd HH:mm:ss") private String date; @ApiModelProperty(value = "是否定时发布 否:0 是:1") private String isScheduled; - @ApiModelProperty(value = "发布时间,格式为: yyyy.MM.dd") + @ApiModelProperty(value = "发布时间,格式为: yyyy-MM-dd HH:mm:ss") private String pubTime; @ApiModelProperty(value = "是否允许评论 否:0 是:1") @@ -67,7 +67,7 @@ public class ArticleRespDTO implements Serializable { response.setContent(article.getContent()); response.setUserId(article.getUserId()); response.setUserName(article.getUserName()); - response.setDate(article.getPubTime().toString()); + response.setDate(article.getUpdateTime().format(Constants.formatter)); response.setCommitsNum(article.getComment()); response.setVistisNum(article.getVisits()); response.setIsScheduled(article.getIsScheduled()); diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSAdvertisementService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSAdvertisementService.java index 292c60c..24b806f 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSAdvertisementService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSAdvertisementService.java @@ -140,32 +140,17 @@ public class CMSAdvertisementService { } } - if (StringUtils.isNotBlank(param.getName())) ad.setName(param.getName()); - - if (StringUtils.isNotBlank(param.getLocation())) ad.setLocation(param.getLocation()); - - if (StringUtils.isNotBlank(param.getStartTime())) ad.setStartTime(LocalDateTime.parse(param.getStartTime(), Constants.formatter)); - - if (StringUtils.isNotBlank(param.getEndTime())) ad.setEndTime(LocalDateTime.parse(param.getEndTime(), Constants.formatter)); - - - if(StringUtils.isNotBlank(param.getType())) ad.setType(param.getType()); - - if(StringUtils.isNotBlank(param.getUrl())) ad.setUrl(param.getUrl()); - - if(StringUtils.isNotBlank(param.getIsDisplay())) ad.setDisplay(param.getIsDisplay()); - - if(StringUtils.isNotBlank(param.getContent())) { ad.setContent(param.getContent()); ad.setSummary(contentToSummary(param.getContent())); - } + + adDao.save(ad); return Result.success(); } @@ -186,9 +171,13 @@ public class CMSAdvertisementService { } public Result> search(int page, int size) { + return search(page,size,null); + } + + public Result> search(int page, int size,String location) { List result = new ArrayList<>(); PageRequest pageRequest = PageRequest.of(page - 1, size); - Specification AdSpecification = buildSearchSpecification(); + Specification AdSpecification = buildSearchSpecification(location); Page AdPage = adDao.findAll(AdSpecification,pageRequest); long totalElements = AdPage.getTotalElements(); @@ -201,12 +190,19 @@ public class CMSAdvertisementService { } return Result.success(new PageResult<>(totalElements, result)); } - private Specification buildSearchSpecification() { + private Specification buildSearchSpecification(String location) { return (Root root, CriteriaQuery query, CriteriaBuilder builder) -> { List predicateList = new ArrayList(); Predicate isDeleted = builder.equal(root.get("isDeleted"), "0"); Predicate isDisplay = builder.equal(root.get("display"), "1"); - predicateList.add(builder.and(isDeleted, isDisplay)); + Predicate predicate = builder.and(isDeleted, isDisplay); + + if(location !=null){ + Predicate locationPredicate = builder.equal(root.get("location"), location); + predicate.getExpressions().add(locationPredicate); + } + + predicateList.add(predicate); // LocalDateTime now = LocalDateTime.now(); @@ -217,6 +213,7 @@ public class CMSAdvertisementService { }; } + private String contentToSummary(String content){ String originalString = content; String[] parts = originalString.split("<.*?>"); diff --git a/luoo_music/src/main/java/com/luoo/music/service/CMSArticleService.java b/luoo_music/src/main/java/com/luoo/music/service/CMSArticleService.java index df93e5b..5875617 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/CMSArticleService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/CMSArticleService.java @@ -54,6 +54,24 @@ public class CMSArticleService { } } + Article article = buildArticle(paramAdd,image); + + Example
example = Example.of(article, ExampleMatcher.matching() + .withIgnorePaths("id") + .withIgnorePaths("image") + .withIgnorePaths("pubTime") + .withIgnorePaths("createTime") + .withIgnorePaths("updateTime") + ); + + if(!articleDao.exists(example)) { + articleDao.save(article); + } + + return Result.success(); + } + + private Article buildArticle(ArticleAddModel paramAdd,String image){ Article article = new Article(); article.setId(String.valueOf(idWorker.nextId())); article.setTitle(paramAdd.getTitle()); @@ -102,20 +120,8 @@ public class CMSArticleService { article.setIsPublish("1"); article.setPubTime(LocalDateTime.now()); }*/ + return article; - Example
example = Example.of(article, ExampleMatcher.matching() - .withIgnorePaths("id") - .withIgnorePaths("image") - .withIgnorePaths("pubTime") - .withIgnorePaths("createTime") - .withIgnorePaths("updateTime") - ); - - if(!articleDao.exists(example)) { - articleDao.save(article); - } - - return Result.success(); } private String moveArticleImage(String srcKey, String image) { @@ -156,7 +162,6 @@ public class CMSArticleService { if (!optional.isPresent()) { return Result.failed("找不到期刊: " + id); } - Article article = optional.get(); //如果图片路径存在 temp/ 则为新图片 @@ -173,29 +178,22 @@ public class CMSArticleService { } } - if (StringUtils.isNotBlank(param.getTitle())) article.setTitle(param.getTitle()); - if (StringUtils.isNotBlank(param.getType())) article.setType(param.getType()); - if (StringUtils.isNotBlank(param.getContent())) { article.setSummary(contentToSummary(param.getContent())); article.setContent(param.getContent()); - } - if (StringUtils.isNotBlank(param.getAllowCommit())) article.setAllowCommit(param.getAllowCommit()); - if (StringUtils.isNotBlank(param.getAutoPush())) article.setAutoPush(param.getAutoPush()); - if(StringUtils.isNotBlank(param.getIsScheduled())) article.setIsScheduled(param.getIsScheduled()); - if(StringUtils.isNotBlank(param.getPubTime())) article.setPubTime(LocalDateTime.parse(param.getPubTime(), Constants.formatter)); + articleDao.save(article); //TODO: 发布方式 return Result.success();