新闻信息管理后台完成
parent
3a844c0874
commit
80618f5a20
|
|
@ -39,8 +39,8 @@ public class SwaggerConfig {
|
|||
String email = "tinyants@163.com";
|
||||
|
||||
return new ApiInfoBuilder()
|
||||
.title("LikeAdmin【后台】接口文档")
|
||||
.description("likeadmin是一套使用流行的技术栈的快速开发管理后台")
|
||||
.title("ZJ【后台】接口文档")
|
||||
.description("这是一个后台的接口文档")
|
||||
.version(GlobalConfig.version)
|
||||
.contact(new Contact(author, url, email))
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.wyh.admin.validate.news.NewsCateSearchValidate;
|
|||
import com.wyh.admin.validate.news.NewsCateUpdateValidate;
|
||||
import com.wyh.admin.vo.news.NewsCateDetailVo;
|
||||
import com.wyh.admin.vo.news.NewsCateListedVo;
|
||||
import com.wyh.common.aop.NotPower;
|
||||
import com.wyh.common.core.AjaxResult;
|
||||
import com.wyh.common.core.PageResult;
|
||||
import com.wyh.common.validator.annotation.IDMust;
|
||||
|
|
@ -18,6 +19,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/news/cate")
|
||||
|
|
@ -35,7 +37,15 @@ public class NewsCateController {
|
|||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
@NotPower
|
||||
@GetMapping("all")
|
||||
@ApiOperation(value="新闻分类列表(下拉框)")
|
||||
public AjaxResult<List<NewsCateListedVo>> all(){
|
||||
|
||||
return AjaxResult.success(iNewsCateService.all());
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
@ApiOperation(value="新闻分类详情")
|
||||
public AjaxResult<NewsCateDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
NewsCateDetailVo detail = iNewsCateService.detail(id);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
package com.wyh.admin.controller.news;
|
||||
|
||||
import com.wyh.admin.aop.Log;
|
||||
import com.wyh.admin.service.INewsService;
|
||||
import com.wyh.admin.validate.commons.IdValidate;
|
||||
import com.wyh.admin.validate.commons.PageValidate;
|
||||
import com.wyh.admin.validate.news.NewsCreateValidate;
|
||||
import com.wyh.admin.validate.news.NewsSearchValidate;
|
||||
import com.wyh.admin.validate.news.NewsUpdateValidate;
|
||||
import com.wyh.admin.vo.NewsDetailVo;
|
||||
import com.wyh.admin.vo.news.NewsListedVo;
|
||||
import com.wyh.common.core.AjaxResult;
|
||||
import com.wyh.common.core.PageResult;
|
||||
import com.wyh.common.validator.annotation.IDMust;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/news")
|
||||
@Api(tags = "新闻信息管理")
|
||||
public class NewsController {
|
||||
|
||||
@Resource
|
||||
INewsService iNewsService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation(value="新闻信息列表")
|
||||
public AjaxResult<PageResult<NewsListedVo>> list(@Validated PageValidate pageValidate,
|
||||
@Validated NewsSearchValidate searchValidate) {
|
||||
PageResult<NewsListedVo> list = iNewsService.list(pageValidate, searchValidate);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
@ApiOperation(value="新闻信息详情")
|
||||
public AjaxResult<NewsDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
|
||||
NewsDetailVo detail = iNewsService.detail(id);
|
||||
return AjaxResult.success(detail);
|
||||
}
|
||||
|
||||
@Log(title = "新闻信息新增")
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value="新闻信息新增")
|
||||
public AjaxResult<Object> add(@Validated @RequestBody NewsCreateValidate createValidate) {
|
||||
iNewsService.add(createValidate);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Log(title = "新闻信息编辑")
|
||||
@PostMapping("/edit")
|
||||
@ApiOperation(value="新闻信息编辑")
|
||||
public AjaxResult<Object> edit(@Validated @RequestBody NewsUpdateValidate updateValidate) {
|
||||
iNewsService.edit(updateValidate);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@Log(title = "新闻信息删除")
|
||||
@PostMapping("/del")
|
||||
@ApiOperation(value="新闻信息删除")
|
||||
public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
|
||||
iNewsService.del(idValidate.getId());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,6 +9,8 @@ import com.wyh.admin.vo.news.NewsCateDetailVo;
|
|||
import com.wyh.admin.vo.news.NewsCateListedVo;
|
||||
import com.wyh.common.core.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 新闻分类服务接口类
|
||||
* @author LikeAdmin
|
||||
|
|
@ -58,4 +60,5 @@ public interface INewsCateService {
|
|||
*/
|
||||
void del(Integer id);
|
||||
|
||||
List<NewsCateListedVo> all();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
package com.wyh.admin.service;
|
||||
|
||||
import com.wyh.admin.validate.commons.PageValidate;
|
||||
import com.wyh.admin.validate.news.NewsCreateValidate;
|
||||
import com.wyh.admin.validate.news.NewsSearchValidate;
|
||||
import com.wyh.admin.validate.news.NewsUpdateValidate;
|
||||
import com.wyh.admin.vo.NewsDetailVo;
|
||||
import com.wyh.admin.vo.news.NewsListedVo;
|
||||
import com.wyh.common.core.PageResult;
|
||||
|
||||
/**
|
||||
* 新闻信息服务接口类
|
||||
* @author LikeAdmin
|
||||
*/
|
||||
public interface INewsService {
|
||||
|
||||
/**
|
||||
* 新闻信息列表
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param pageValidate 分页参数
|
||||
* @param searchValidate 搜索参数
|
||||
* @return PageResult<NewsListedVo>
|
||||
*/
|
||||
PageResult<NewsListedVo> list(PageValidate pageValidate, NewsSearchValidate searchValidate);
|
||||
|
||||
/**
|
||||
* 新闻信息详情
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param id 主键ID
|
||||
* @return NewsDetailVo
|
||||
*/
|
||||
NewsDetailVo detail(Integer id);
|
||||
|
||||
/**
|
||||
* 新闻信息新增
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param createValidate 参数
|
||||
*/
|
||||
void add(NewsCreateValidate createValidate);
|
||||
|
||||
/**
|
||||
* 新闻信息编辑
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param updateValidate 参数
|
||||
*/
|
||||
void edit(NewsUpdateValidate updateValidate);
|
||||
|
||||
/**
|
||||
* 新闻信息删除
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param id 主键ID
|
||||
*/
|
||||
void del(Integer id);
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.wyh.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
|
@ -152,4 +153,18 @@ public class NewsCateServiceImpl implements INewsCateService {
|
|||
newsCateMapper.updateById(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NewsCateListedVo> all() {
|
||||
List<NewsCate> newsCates = newsCateMapper.selectList(Wrappers.<NewsCate>lambdaQuery().eq(NewsCate::getIsDelete, 0));
|
||||
List<NewsCateListedVo> list = new LinkedList<>();
|
||||
for(NewsCate item : newsCates) {
|
||||
NewsCateListedVo vo = new NewsCateListedVo();
|
||||
BeanUtils.copyProperties(item, vo);
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(item.getCreateTime()));
|
||||
vo.setUpdateTime(TimeUtils.timestampToDate(item.getUpdateTime()));
|
||||
list.add(vo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,181 @@
|
|||
package com.wyh.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.wyh.admin.service.INewsService;
|
||||
import com.wyh.admin.validate.commons.PageValidate;
|
||||
|
||||
import com.wyh.admin.validate.news.NewsCreateValidate;
|
||||
import com.wyh.admin.validate.news.NewsSearchValidate;
|
||||
import com.wyh.admin.validate.news.NewsUpdateValidate;
|
||||
import com.wyh.admin.vo.NewsDetailVo;
|
||||
import com.wyh.admin.vo.news.NewsListedVo;
|
||||
import com.wyh.common.core.PageResult;
|
||||
import com.wyh.common.entity.News;
|
||||
import com.wyh.common.entity.news.NewsCate;
|
||||
import com.wyh.common.mapper.news.NewsCateMapper;
|
||||
import com.wyh.common.mapper.news.NewsMapper;
|
||||
import com.wyh.common.util.ListUtils;
|
||||
import com.wyh.common.util.TimeUtils;
|
||||
import com.wyh.common.util.UrlUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 新闻信息实现类
|
||||
* @author LikeAdmin
|
||||
*/
|
||||
@Service
|
||||
public class NewsServiceImpl implements INewsService {
|
||||
|
||||
@Resource
|
||||
NewsMapper newsMapper;
|
||||
@Resource
|
||||
NewsCateMapper newsCateMapper;
|
||||
|
||||
/**
|
||||
* 新闻信息列表
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param pageValidate 分页参数
|
||||
* @param searchValidate 搜索参数
|
||||
* @return PageResult<NewsListedVo>
|
||||
*/
|
||||
@Override
|
||||
public PageResult<NewsListedVo> list(PageValidate pageValidate, NewsSearchValidate searchValidate) {
|
||||
Integer page = pageValidate.getPageNo();
|
||||
Integer limit = pageValidate.getPageSize();
|
||||
|
||||
QueryWrapper<News> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("is_delete", 0);
|
||||
queryWrapper.orderByDesc(Arrays.asList("sort", "id"));
|
||||
|
||||
newsMapper.setSearch(queryWrapper, searchValidate, new String[]{
|
||||
"=:isShow@is_show:long",
|
||||
"=:sort:long",
|
||||
"like:title:str",
|
||||
"=:subhead:str",
|
||||
"=:newsImg@news_img:str",
|
||||
"=:content:str",
|
||||
"=:cateId@cate_id:long",
|
||||
});
|
||||
|
||||
IPage<News> iPage = newsMapper.selectPage(new Page<>(page, limit), queryWrapper);
|
||||
|
||||
List<NewsListedVo> list = new LinkedList<>();
|
||||
for(News item : iPage.getRecords()) {
|
||||
NewsListedVo vo = new NewsListedVo();
|
||||
BeanUtils.copyProperties(item, vo);
|
||||
if (item.getCateId() != null) {
|
||||
NewsCate newsCate = newsCateMapper.selectById(item.getCateId());
|
||||
if (newsCate != null) {
|
||||
vo.setCateName(newsCate.getName());
|
||||
}
|
||||
}
|
||||
vo.setCreateTime(TimeUtils.timestampToDate(item.getCreateTime()));
|
||||
vo.setUpdateTime(TimeUtils.timestampToDate(item.getUpdateTime()));
|
||||
list.add(vo);
|
||||
}
|
||||
|
||||
return PageResult.iPageHandle(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻信息详情
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param id 主键参数
|
||||
* @return News
|
||||
*/
|
||||
@Override
|
||||
public NewsDetailVo detail(Integer id) {
|
||||
News model = newsMapper.selectOne(
|
||||
new QueryWrapper<News>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(model, "数据不存在");
|
||||
|
||||
NewsDetailVo vo = new NewsDetailVo();
|
||||
BeanUtils.copyProperties(model, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻信息新增
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param createValidate 参数
|
||||
*/
|
||||
@Override
|
||||
public void add(NewsCreateValidate createValidate) {
|
||||
News model = new News();
|
||||
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
model.setIsShow(createValidate.getIsShow());
|
||||
model.setSort(createValidate.getSort());
|
||||
model.setTitle(createValidate.getTitle());
|
||||
model.setSubhead(createValidate.getSubhead());
|
||||
model.setNewsImg(createValidate.getNewsImg());
|
||||
model.setContent(createValidate.getContent());
|
||||
model.setCateId(createValidate.getCateId());
|
||||
newsMapper.insert(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻信息编辑
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param updateValidate 参数
|
||||
*/
|
||||
@Override
|
||||
public void edit(NewsUpdateValidate updateValidate) {
|
||||
News model = newsMapper.selectOne(
|
||||
new QueryWrapper<News>()
|
||||
.eq("id", updateValidate.getId())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(model, "数据不存在!");
|
||||
|
||||
model.setId(updateValidate.getId());
|
||||
model.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
model.setIsShow(updateValidate.getIsShow());
|
||||
model.setSort(updateValidate.getSort());
|
||||
model.setTitle(updateValidate.getTitle());
|
||||
model.setSubhead(updateValidate.getSubhead());
|
||||
model.setNewsImg(updateValidate.getNewsImg());
|
||||
model.setContent(updateValidate.getContent());
|
||||
model.setCateId(updateValidate.getCateId());
|
||||
newsMapper.updateById(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻信息删除
|
||||
*
|
||||
* @author LikeAdmin
|
||||
* @param id 主键ID
|
||||
*/
|
||||
@Override
|
||||
public void del(Integer id) {
|
||||
News model = newsMapper.selectOne(
|
||||
new QueryWrapper<News>()
|
||||
.eq("id", id)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(model, "数据不存在!");
|
||||
|
||||
model.setIsDelete(1);
|
||||
model.setDeleteTime(System.currentTimeMillis() / 1000);
|
||||
newsMapper.updateById(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.wyh.admin.validate.news;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Data
|
||||
@ApiModel("新闻信息创建参数")
|
||||
public class NewsCreateValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "isShow参数缺失")
|
||||
@ApiModelProperty(value = "是否显示")
|
||||
private Integer isShow;
|
||||
|
||||
@NotNull(message = "sort参数缺失")
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@NotNull(message = "title参数缺失")
|
||||
@ApiModelProperty(value = "新闻标题")
|
||||
private String title;
|
||||
|
||||
@NotNull(message = "subhead参数缺失")
|
||||
@ApiModelProperty(value = "副标题")
|
||||
private String subhead;
|
||||
|
||||
@NotNull(message = "newsImg参数缺失")
|
||||
@ApiModelProperty(value = "新闻主图")
|
||||
private String newsImg;
|
||||
|
||||
@NotNull(message = "content参数缺失")
|
||||
@ApiModelProperty(value = "新闻内容")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "cateId参数缺失")
|
||||
@ApiModelProperty(value = "新闻分类id")
|
||||
private Integer cateId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.wyh.admin.validate.news;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("新闻信息搜素参数")
|
||||
public class NewsSearchValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "是否显示")
|
||||
private Integer isShow;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "新闻标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "副标题")
|
||||
private String subhead;
|
||||
|
||||
@ApiModelProperty(value = "新闻主图")
|
||||
private String newsImg;
|
||||
|
||||
@ApiModelProperty(value = "新闻内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "新闻分类id")
|
||||
private Integer cateId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.wyh.admin.validate.news;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import javax.validation.constraints.*;
|
||||
import com.wyh.common.validator.annotation.IDMust;
|
||||
|
||||
/**
|
||||
* 新闻信息参数
|
||||
* @author LikeAdmin
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("新闻信息更新参数")
|
||||
public class NewsUpdateValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0")
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
@NotNull(message = "isShow参数缺失")
|
||||
@ApiModelProperty(value = "是否显示")
|
||||
private Integer isShow;
|
||||
|
||||
@NotNull(message = "sort参数缺失")
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@NotNull(message = "title参数缺失")
|
||||
@ApiModelProperty(value = "新闻标题")
|
||||
private String title;
|
||||
|
||||
@NotNull(message = "subhead参数缺失")
|
||||
@ApiModelProperty(value = "副标题")
|
||||
private String subhead;
|
||||
|
||||
@NotNull(message = "newsImg参数缺失")
|
||||
@ApiModelProperty(value = "新闻主图")
|
||||
private String newsImg;
|
||||
|
||||
@NotNull(message = "content参数缺失")
|
||||
@ApiModelProperty(value = "新闻内容")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "cateId参数缺失")
|
||||
@ApiModelProperty(value = "新闻分类id")
|
||||
private Integer cateId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.wyh.admin.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("新闻信息详情Vo")
|
||||
public class NewsDetailVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "是否显示")
|
||||
private Integer isShow;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "新闻标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "副标题")
|
||||
private String subhead;
|
||||
|
||||
@ApiModelProperty(value = "新闻主图")
|
||||
private String newsImg;
|
||||
|
||||
@ApiModelProperty(value = "新闻内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "新闻分类id")
|
||||
private Integer cateId;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.wyh.admin.vo.news;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("新闻信息列表Vo")
|
||||
public class NewsListedVo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private String createTime;
|
||||
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private String updateTime;
|
||||
|
||||
@ApiModelProperty(value = "是否显示")
|
||||
private Integer isShow;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "新闻标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "副标题")
|
||||
private String subhead;
|
||||
|
||||
@ApiModelProperty(value = "新闻主图")
|
||||
private String newsImg;
|
||||
|
||||
@ApiModelProperty(value = "新闻分类id")
|
||||
private Integer cateId;
|
||||
|
||||
@ApiModelProperty(value = "新闻分类名称")
|
||||
private String cateName;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ ZJ-java:
|
|||
# 是否开启swagger
|
||||
enabled: true
|
||||
# 请求前缀
|
||||
pathMapping: /dev-api
|
||||
pathMapping:
|
||||
|
||||
# 服务配置
|
||||
server:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package com.wyh.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("新闻信息实体")
|
||||
public class News implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "是否删除: 0=否, 1=是")
|
||||
private Integer isDelete;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Long createTime;
|
||||
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Long updateTime;
|
||||
|
||||
@ApiModelProperty(value = "删除时间")
|
||||
private Long deleteTime;
|
||||
|
||||
@ApiModelProperty(value = "是否显示")
|
||||
private Integer isShow;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty(value = "新闻标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "副标题")
|
||||
private String subhead;
|
||||
|
||||
@ApiModelProperty(value = "新闻主图")
|
||||
private String newsImg;
|
||||
|
||||
@ApiModelProperty(value = "新闻内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "新闻分类id")
|
||||
private Integer cateId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.wyh.common.mapper.news;
|
||||
|
||||
|
||||
import com.wyh.common.core.basics.IBaseMapper;
|
||||
import com.wyh.common.entity.News;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 新闻信息Mapper
|
||||
* @author LikeAdmin
|
||||
*/
|
||||
@Mapper
|
||||
public interface NewsMapper extends IBaseMapper<News> {
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 新闻信息列表
|
||||
export function newsLists(params?: Record<string, any>) {
|
||||
return request.get({ url: '/news/list', params })
|
||||
}
|
||||
|
||||
// 新闻信息详情
|
||||
export function newsDetail(params: Record<string, any>) {
|
||||
return request.get({ url: '/news/detail', params })
|
||||
}
|
||||
|
||||
// 新闻信息新增
|
||||
export function newsAdd(params: Record<string, any>) {
|
||||
return request.post({ url: '/news/add', params })
|
||||
}
|
||||
|
||||
// 新闻信息编辑
|
||||
export function newsEdit(params: Record<string, any>) {
|
||||
return request.post({ url: '/news/edit', params })
|
||||
}
|
||||
|
||||
// 新闻信息删除
|
||||
export function newsDelete(params: Record<string, any>) {
|
||||
return request.post({ url: '/news/del', params })
|
||||
}
|
||||
|
|
@ -24,3 +24,8 @@ export function newsCateEdit(params: Record<string, any>) {
|
|||
export function newsCateDelete(params: Record<string, any>) {
|
||||
return request.post({ url: '/news/cate/del', params })
|
||||
}
|
||||
|
||||
export function listAll() {
|
||||
return request.get({ url: '/news/cate/all' })
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
@confirm="handleSubmit"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
|
||||
<el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
|
||||
<el-form-item label="案例名称" prop="name" style="width: 550px">
|
||||
<el-input v-model="formData.name" placeholder="请输入案例名称" />
|
||||
</el-form-item>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,197 @@
|
|||
<template>
|
||||
<div class="edit-popup">
|
||||
<popup
|
||||
ref="popupRef"
|
||||
:title="popupTitle"
|
||||
:async="true"
|
||||
width="1000px"
|
||||
:clickModalClose="true"
|
||||
@confirm="handleSubmit"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" style="width: 70%" label-width="84px" :rules="formRules">
|
||||
<el-form-item label="新闻分类" prop="cateId">
|
||||
<el-select
|
||||
v-model="formData.cateId"
|
||||
placeholder="请选择新闻分类"
|
||||
class="flex-1"
|
||||
clearable
|
||||
>
|
||||
<el-option v-for="item in newsCateList" :label="item.name" :value="item.id" :key="item.id" >
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="新闻标题" prop="title">
|
||||
<el-input v-model="formData.title" placeholder="请输入新闻标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="副标题" prop="subhead">
|
||||
<el-input v-model="formData.subhead" placeholder="请输入副标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻主图" prop="newsImg">
|
||||
<material-picker size="260px" v-model="formData.newsImg" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻内容" prop="content">
|
||||
<editor v-model="formData.content" :height="500" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<div>
|
||||
<el-input-number v-model="formData.sort" :max="9999" />
|
||||
<div class="form-tips">数值越大越排前</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否显示" prop="isShow">
|
||||
<el-radio-group class="flex-1" v-model="formData.isShow" placeholder="请选择是否显示">
|
||||
<el-radio :label="1">显示</el-radio>
|
||||
<el-radio :label="0">不显示</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
</popup>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { newsEdit, newsAdd, newsDetail } from '@/api/news'
|
||||
import Popup from '@/components/popup/index.vue'
|
||||
import feedback from '@/utils/feedback'
|
||||
import type { PropType } from 'vue'
|
||||
import {listAll} from "@/api/newscate";
|
||||
defineProps({
|
||||
dictData: {
|
||||
type: Object as PropType<Record<string, any[]>>,
|
||||
default: () => ({})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const newsCateList = ref<any[]>([])
|
||||
const emit = defineEmits(['success', 'close'])
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const popupRef = shallowRef<InstanceType<typeof Popup>>()
|
||||
const mode = ref('add')
|
||||
const popupTitle = computed(() => {
|
||||
return mode.value == 'edit' ? '编辑新闻信息' : '新增新闻信息'
|
||||
})
|
||||
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
isShow: '',
|
||||
sort: '',
|
||||
title: '',
|
||||
subhead: '',
|
||||
newsImg: '',
|
||||
content: '',
|
||||
cateId: '',
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
id: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入主键',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
isShow: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入是否显示',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
sort: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入排序',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
title: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入新闻标题',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
subhead: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入副标题',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
newsImg: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入新闻主图',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
content: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入新闻内容',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
cateId: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入新闻分类id',
|
||||
trigger: ['blur']
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
await formRef.value?.validate()
|
||||
const data: any = { ...formData }
|
||||
mode.value == 'edit' ? await newsEdit(data) : await newsAdd(data)
|
||||
popupRef.value?.close()
|
||||
feedback.msgSuccess('操作成功')
|
||||
emit('success')
|
||||
}
|
||||
|
||||
const open = (type = 'add') => {
|
||||
mode.value = type
|
||||
popupRef.value?.open()
|
||||
}
|
||||
|
||||
const setFormData = async (data: Record<string, any>) => {
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const getDetail = async (row: Record<string, any>) => {
|
||||
const data = await newsDetail({
|
||||
id: row.id
|
||||
})
|
||||
setFormData(data)
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
const getNewsCateList = async () => {
|
||||
const res: any = await listAll()
|
||||
newsCateList.value = res || []
|
||||
}
|
||||
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
setFormData,
|
||||
getDetail,
|
||||
|
||||
})
|
||||
getNewsCateList()
|
||||
</script>
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
<template>
|
||||
<div class="index-lists">
|
||||
<el-card class="!border-none" shadow="never">
|
||||
<el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
|
||||
<el-form-item label="是否显示" prop="isShow">
|
||||
<el-select
|
||||
v-model="queryParams.isShow"
|
||||
class="w-[260px]"
|
||||
clearable
|
||||
>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option
|
||||
v-for="(item, index) in dictData.Integer"
|
||||
:key="index"
|
||||
:label="item.name"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻标题" prop="title">
|
||||
<el-input class="w-[260px]" v-model="queryParams.title" />
|
||||
</el-form-item>
|
||||
<el-form-item label="副标题" prop="subhead">
|
||||
<el-input class="w-[260px]" v-model="queryParams.subhead" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻分类" prop="cateId">
|
||||
<el-select
|
||||
v-model="queryParams.cateId"
|
||||
class="flex-1"
|
||||
clearable
|
||||
placeholder="请选择新闻分类"
|
||||
>
|
||||
<el-option v-for="item in newsCateList" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
||||
<el-button @click="resetParams">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<el-card class="!border-none mt-4" shadow="never">
|
||||
<div>
|
||||
<el-button v-perms="['news:add']" type="primary" @click="handleAdd()">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
</div>
|
||||
<el-table
|
||||
class="mt-4"
|
||||
size="large"
|
||||
v-loading="pager.loading"
|
||||
:data="pager.lists"
|
||||
>
|
||||
<el-table-column label="新闻标题" prop="title" width="200px" />
|
||||
<el-table-column label="副标题" prop="subhead" min-width="100" />
|
||||
<el-table-column label="创建时间" prop="createTime" min-width="100" />
|
||||
<el-table-column label="更新时间" prop="updateTime" min-width="100" />
|
||||
<el-table-column label="是否显示" prop="isShow" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<dict-value :options="dictData.Integer" :value="row.isShow" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="排序" prop="sort" width="50" min-width="50" />
|
||||
|
||||
<el-table-column label="新闻主图" prop="newsImg" min-width="100" >
|
||||
<template #default="{ row }">
|
||||
<image-contain
|
||||
:width="100"
|
||||
:height="80"
|
||||
:src="row.newsImg"
|
||||
:preview-src-list="[row.newsImg]"
|
||||
preview-teleported
|
||||
hide-on-click-modal
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="新闻分类" prop="cateName" min-width="100" />
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-perms="['news:edit']"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['news:del']"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
</div>
|
||||
</el-card>
|
||||
<edit-popup
|
||||
v-if="showEdit"
|
||||
ref="editRef"
|
||||
@success="getLists"
|
||||
@close="showEdit = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup name="news">
|
||||
import { newsDelete, newsLists } from '@/api/news'
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import feedback from '@/utils/feedback'
|
||||
import EditPopup from './edit.vue'
|
||||
import {useDictData} from "@/hooks/useDictOptions";
|
||||
import {listAll} from "@/api/newscate";
|
||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||
const showEdit = ref(false)
|
||||
const queryParams = reactive({
|
||||
isShow: '',
|
||||
sort: '',
|
||||
title: '',
|
||||
subhead: '',
|
||||
newsImg: '',
|
||||
content: '',
|
||||
cateId: '',
|
||||
})
|
||||
const newsCateList = ref<any[]>([])
|
||||
const { dictData } = useDictData<{
|
||||
Integer: any[]
|
||||
}>(['Integer'])
|
||||
|
||||
|
||||
const { pager, getLists, resetPage, resetParams } = usePaging({
|
||||
fetchFun: newsLists,
|
||||
params: queryParams
|
||||
})
|
||||
|
||||
|
||||
|
||||
const handleAdd = async () => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('add')
|
||||
}
|
||||
|
||||
const handleEdit = async (data: any) => {
|
||||
showEdit.value = true
|
||||
await nextTick()
|
||||
editRef.value?.open('edit')
|
||||
editRef.value?.getDetail(data)
|
||||
}
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
await feedback.confirm('确定要删除?')
|
||||
await newsDelete({ id })
|
||||
feedback.msgSuccess('删除成功')
|
||||
getLists()
|
||||
}
|
||||
|
||||
const getNewsCateList = async () => {
|
||||
const res: any = await listAll()
|
||||
newsCateList.value = res || []
|
||||
}
|
||||
|
||||
|
||||
getLists()
|
||||
getNewsCateList()
|
||||
</script>
|
||||
Loading…
Reference in New Issue