feat(advertisement): 新增广告功能及管理接口
- 新增广告实体类Advertisement,包含类型、位置、间隔、内容等字段 - 实现广告管理接口AdvertisementController,支持广告类型、位置查询 - 提供保存、启用、删除及列表查询广告接口 - 新增广告保存请求和启用批量请求的数据传输对象 - 设计广告列表视图VO,解析广告内容为广告项列表 - 增加广告服务实现类,处理广告新增、更新、启用状态切换及分页查询 - 新增MyBatis映射文件,支持按类型和位置查询广告及列表查询 - 添加对应的统一请求和响应封装类型,增强请求数据校验和API返回一致性
This commit is contained in:
parent
20bb31dc1c
commit
e0f7a08ee8
|
|
@ -3,9 +3,7 @@ package com.nflg.wms.admin.controller;
|
|||
import com.nflg.wms.common.constant.Constant;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.qo.AdvertisementRequst;
|
||||
import com.nflg.wms.common.pojo.qo.AdvertisementSaveRequest;
|
||||
import com.nflg.wms.common.pojo.qo.PageQO;
|
||||
import com.nflg.wms.common.pojo.qo.*;
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementListVO;
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementVO;
|
||||
import com.nflg.wms.common.util.MultilingualUtil;
|
||||
|
|
@ -69,6 +67,15 @@ public class AdvertisementController extends BaseController{
|
|||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用广告
|
||||
*/
|
||||
@PostMapping("enable")
|
||||
public ApiResult<Void> enableAdvertisement(@Valid @RequestBody @NotNull EnableBatchQO request){
|
||||
advertisementService.enable(request);
|
||||
return ApiResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除广告
|
||||
* @param ids 广告id列表
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementItemVO;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -16,20 +19,30 @@ public class AdvertisementSaveRequest {
|
|||
/**
|
||||
* 广告类型
|
||||
*/
|
||||
@NotNull
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 广告位置
|
||||
*/
|
||||
@NotNull
|
||||
private Integer position;
|
||||
|
||||
/**
|
||||
* 轮播间隔
|
||||
*/
|
||||
@NotNull
|
||||
private Integer interval;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable = true;
|
||||
|
||||
/**
|
||||
* 广告项
|
||||
*/
|
||||
@Valid
|
||||
@NotEmpty
|
||||
private List<AdvertisementItemVO> items;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class EnableBatchQO {
|
||||
|
||||
@NotEmpty
|
||||
private List<Long> ids;
|
||||
|
||||
// 是否启用
|
||||
@NotNull
|
||||
private Boolean enable;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.nflg.wms.common.pojo.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
|
@ -8,6 +9,7 @@ public class AdvertisementItemVO {
|
|||
/**
|
||||
* 广告url
|
||||
*/
|
||||
@NotBlank
|
||||
private String url;
|
||||
|
||||
/**
|
||||
|
|
@ -18,5 +20,5 @@ public class AdvertisementItemVO {
|
|||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
private Integer sort = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@ public class AdvertisementListVO {
|
|||
return JSONUtil.toList(content, AdvertisementItemVO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -49,6 +49,11 @@ public class Advertisement implements Serializable {
|
|||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.nflg.wms.repository.service;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.nflg.wms.common.pojo.qo.AdvertisementSaveRequest;
|
||||
import com.nflg.wms.common.pojo.qo.EnableBatchQO;
|
||||
import com.nflg.wms.common.pojo.qo.PageQO;
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementListVO;
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementVO;
|
||||
|
|
@ -23,4 +24,6 @@ public interface IAdvertisementService extends IService<Advertisement> {
|
|||
void save(AdvertisementSaveRequest request);
|
||||
|
||||
IPage<AdvertisementListVO> getList(PageQO request);
|
||||
|
||||
void enable(EnableBatchQO request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.wms.common.pojo.qo.AdvertisementSaveRequest;
|
||||
import com.nflg.wms.common.pojo.qo.EnableBatchQO;
|
||||
import com.nflg.wms.common.pojo.qo.PageQO;
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementItemVO;
|
||||
import com.nflg.wms.common.pojo.vo.AdvertisementListVO;
|
||||
|
|
@ -21,9 +22,8 @@ import java.util.Objects;
|
|||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 代码生成器生成
|
||||
* @since 2025
|
||||
*/
|
||||
|
|
@ -31,12 +31,12 @@ import java.util.Objects;
|
|||
public class AdvertisementServiceImpl extends ServiceImpl<AdvertisementMapper, Advertisement> implements IAdvertisementService {
|
||||
|
||||
@Override
|
||||
public AdvertisementVO getByType(String type,String position) {
|
||||
Advertisement ad=baseMapper.getByType(type,position);
|
||||
if (Objects.isNull(ad)){
|
||||
public AdvertisementVO getByType(String type, String position) {
|
||||
Advertisement ad = baseMapper.getByType(type, position);
|
||||
if (Objects.isNull(ad)) {
|
||||
return null;
|
||||
}
|
||||
AdvertisementVO vo=new AdvertisementVO();
|
||||
AdvertisementVO vo = new AdvertisementVO();
|
||||
vo.setInterval(ad.getInterval());
|
||||
vo.setItems(JSONUtil.toList(ad.getContent(), AdvertisementItemVO.class));
|
||||
return vo;
|
||||
|
|
@ -44,26 +44,28 @@ public class AdvertisementServiceImpl extends ServiceImpl<AdvertisementMapper, A
|
|||
|
||||
@Override
|
||||
public void save(AdvertisementSaveRequest request) {
|
||||
if (Objects.isNull(request.getId())){
|
||||
VUtil.trueThrowBusinessError(lambdaQuery().eq(Advertisement::getType,request.getType())
|
||||
.eq(Advertisement::getPosition,request.getPosition())
|
||||
.exists())
|
||||
if (Objects.isNull(request.getId())) {
|
||||
VUtil.trueThrowBusinessError(lambdaQuery().eq(Advertisement::getType, request.getType())
|
||||
.eq(Advertisement::getPosition, request.getPosition())
|
||||
.exists())
|
||||
.throwMessage("已存在相同位置的广告");
|
||||
Advertisement ad=new Advertisement()
|
||||
Advertisement ad = new Advertisement()
|
||||
.setType(request.getType())
|
||||
.setPosition(request.getPosition())
|
||||
.setInterval(request.getInterval())
|
||||
.setContent(JSONUtil.toJsonStr(request.getItems()))
|
||||
.setEnable(request.getEnable())
|
||||
.setCreateBy(UserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
save(ad);
|
||||
}else {
|
||||
Advertisement ad=new Advertisement()
|
||||
} else {
|
||||
Advertisement ad = new Advertisement()
|
||||
.setId(request.getId())
|
||||
.setType(request.getType())
|
||||
.setPosition(request.getPosition())
|
||||
.setInterval(request.getInterval())
|
||||
.setContent(JSONUtil.toJsonStr(request.getItems()))
|
||||
.setEnable(request.getEnable())
|
||||
.setUpdateBy(UserUtil.getUserName())
|
||||
.setUpdateTime(LocalDateTime.now());
|
||||
updateById(ad);
|
||||
|
|
@ -72,6 +74,16 @@ public class AdvertisementServiceImpl extends ServiceImpl<AdvertisementMapper, A
|
|||
|
||||
@Override
|
||||
public IPage<AdvertisementListVO> getList(PageQO request) {
|
||||
return baseMapper.getList(new Page<>(request.getPage(),request.getPageSize()));
|
||||
return baseMapper.getList(new Page<>(request.getPage(), request.getPageSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(EnableBatchQO request) {
|
||||
lambdaUpdate()
|
||||
.set(Advertisement::getEnable, request.getEnable())
|
||||
.set(Advertisement::getUpdateBy, UserUtil.getUserName())
|
||||
.set(Advertisement::getUpdateTime, LocalDateTime.now())
|
||||
.in(Advertisement::getId, request.getIds())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nflg.wms.repository.mapper.AdvertisementMapper">
|
||||
|
||||
<select id="getByType" resultType="com.nflg.wms.repository.entity.Advertisement">
|
||||
SELECT ad.*
|
||||
FROM advertisement ad
|
||||
INNER JOIN dictionary_item di1 ON ad.type = di1.id
|
||||
INNER JOIN dictionary_item di2 ON ad.position = di2.id
|
||||
where di1.code = #{type} AND di2.code=#{position}
|
||||
</select>
|
||||
|
||||
<select id="getList" resultType="com.nflg.wms.common.pojo.vo.AdvertisementListVO">
|
||||
SELECT ad.*,di1.value AS "typeName",di2.value AS "positionName"
|
||||
FROM advertisement ad
|
||||
INNER JOIN dictionary_item di1 ON ad.type=di1.id
|
||||
INNER JOIN dictionary_item di2 ON ad.position=di2.id
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue