添加开屏广告管理

This commit is contained in:
sonjinyon 2024-11-14 19:41:15 +08:00
parent 7ae5762c78
commit 58a27586a3
13 changed files with 1083 additions and 0 deletions

View File

@ -0,0 +1,50 @@
import request from '@/config/axios'
// 开屏广告 VO
export interface AdvertisingVO {
id: number // id
status: number // 广告状态
time: number // 广告时间(秒)
property: string // 广告属性
picData: []
stat: boolean,
}
// 开屏广告 API
export const AdvertisingApi = {
// 查询开屏广告分页
getAdvertisingPage: async (params: any) => {
return await request.get({ url: `/promotion/advertising/page`, params })
},
// 查询开屏广告详情
getAdvertising: async () => {
return await request.get({ url: `/promotion/advertising/getAdvertising`})
},
// 新增开屏广告
createAdvertising: async (data: AdvertisingVO) => {
return await request.post({ url: `/promotion/advertising/create`, data })
},
// 修改开屏广告
updateAdvertising: async (data: AdvertisingVO) => {
return await request.put({ url: `/promotion/advertising/update`, data })
},
// 删除开屏广告
deleteAdvertising: async (id: number) => {
return await request.delete({ url: `/promotion/advertising/delete?id=` + id })
},
// 导出开屏广告 Excel
exportAdvertising: async (params) => {
return await request.download({ url: `/promotion/advertising/export-excel`, params })
},
// 新增修稿开屏广告
saveAdvertising: async (data: AdvertisingVO) => {
return await request.post({ url: `/promotion/advertising/saveAdvertising`, data })
},
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,118 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="广告状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.PROMOTION_DIY_ADVERTISING)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="广告时间(秒)" prop="time">
<el-date-picker
v-model="formData.time"
type="date"
value-format="x"
placeholder="选择广告时间(秒)"
/>
</el-form-item>
<el-form-item label="广告属性" prop="property">
<el-input v-model="formData.property" placeholder="请输入广告属性" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { AdvertisingApi, AdvertisingVO } from '@/api/mall/promotion/advertising'
/** 开屏广告 表单 */
defineOptions({ name: 'AdvertisingForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
status: undefined,
time: undefined,
property: undefined
})
const formRules = reactive({
status: [{ required: true, message: '广告状态不能为空', trigger: 'blur' }],
time: [{ required: true, message: '广告时间(秒)不能为空', trigger: 'blur' }],
property: [{ required: true, message: '广告属性不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await AdvertisingApi.getAdvertising(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
formLoading.value = true
try {
const data = formData.value as unknown as AdvertisingVO
if (formType.value === 'create') {
await AdvertisingApi.createAdvertising(data)
message.success(t('common.createSuccess'))
} else {
await AdvertisingApi.updateAdvertising(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
status: undefined,
time: undefined,
property: undefined
}
formRef.value?.resetFields()
}
</script>

View File

@ -0,0 +1,225 @@
<template>
<ContentWrap>
<span>数据配置</span>
<el-button type="primary" @click="baocun" style="margin-left:85%">保存</el-button>
</ContentWrap>
<ContentWrap>
<div class="container">
<div class="left" >
<img :src="image"
style="width: 100%;height: 100%;border-radius: 10px;" v-show="check == 1" />
<span v-show="check == 2" style="margin-left:80px">暂无图片请添加~</span>
</div>
<div class="right">
<div>
<p style="font-weight: 700;">引导页设置</p>
<span>开屏广告</span><span> <el-switch v-model="formData.stat" size="large" /> </span>
<br />
<span>广告时间</span><span> <el-input v-model="formData.time" style="width: 240px"
placeholder="请输入秒" /></span><span> 单位()</span>
<br />
</div>
<div>
<div v-for="(item, index) in timeRanges" :key="index" class="rectangle-container">
<div class="imageLeft">
<UploadImg width="100px" height="100px" v-model="item.pic" />
</div>
<div class="inputRight">
<div style="margin-top: 3%;">
<span>图片名称</span><span><el-input style="width: 200px;" type="text" v-model="item.name"
placeholder="请输入名称" /></span>
</div>
<br />
<div>
<span>链接地址</span><span><el-input style="width: 200px;" type="text" v-model="item.url"
placeholder="请输入地址" /></span>
</div>
</div>
<div class="top-right-image">
<img @click="removePic(index)" style="width: 25px;height: 25px;"
src="@/assets/imgs/quxiao.png" />
</div>
<br />
</div>
<br />
<el-button type="primary" @click="addNewPic">添加图片</el-button>
</div>
</div>
</div>
</ContentWrap>
</template>
<script setup lang="ts">
import { AdvertisingApi, AdvertisingVO } from '@/api/mall/promotion/advertising'
/** 开屏广告 列表 */
defineOptions({ name: 'Advertising' })
const message = useMessage() //
const { t } = useI18n() //
const formData = ref({
id: undefined,
status: undefined,
stat: false,
time: undefined,
property: undefined,
picData: [{ pic: '', name: '', url: '' }]
})
const image = ref('')
const check = ref(2)
const timeRanges = ref([{ pic: '', name: '', url: '' }]);
//
const addNewPic = () => {
if (timeRanges.value.length <= 5) {
timeRanges.value.push({ pic: '', name: '', url: '' });
}
};
//
const removePic = (index : number) => {
if (timeRanges.value.length >= 1) {
timeRanges.value.splice(index, 1);
}
};
//
const baocun = async () => {
formData.value.picData = timeRanges.value
const data = formData.value as unknown as AdvertisingVO
await AdvertisingApi.saveAdvertising(data)
getAdvertising()
message.success('保存成功')
}
/** 查询开屏广告数据配置 */
const getAdvertising = async () => {
formData.value = await AdvertisingApi.getAdvertising()
if(formData.value.id == null){
console.log('11111:',formData.value)
}else{
console.log('22222:',formData.value)
check.value = 1
timeRanges.value = formData.value.picData
if (formData.value.picData && formData.value.picData.length > 0) {
image.value = formData.value.picData[0].pic
}
}
// if(formData.value.picData.length < 1){
// timeRanges.value = [{ pic: '', name: '', url: '' }]
// }
// if(formData.value.picData.length > 0){
//
// }
}
/** 初始化 **/
onMounted(() => {
getAdvertising()
})
</script>
<style>
.container {
display: flex;
/* justify-content: space-between; /* 左右分布 */
width: 1000px;
}
.left {
margin-left: 20px;
margin-top: 20px;
margin-bottom: 20px;
width: 300px;
height: 550px;
border-radius: 10px;
border: 1px solid #ddd;
/* background-color: lightblue; */
}
.right {
margin-left: 50px;
/* background-color: lightgreen; */
}
/**
* 上传图片
*/
.rectangle-container {
display: flex;
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 8px;
position: relative;
margin-top: 13px;
}
.imageLeft {
width: 100px;
height: 100px;
margin-right: 20px;
/* position: relative; */
}
.inputRight {
display: flex;
flex-direction: column;
}
.top-right-image {
position: absolute;
/* 使图片定位到父容器的右上角 */
top: 1px;
/* 控制图片与上边缘的距离 */
right: 1px;
/* 控制图片与右边缘的距离 */
cursor: pointer;
}
.image-preview {
width: 50px;
height: 50px;
/* object-fit: cover;
border-radius: 8px; */
}
/* .inputRight input {
margin-bottom: 10px;
padding: 8px;
width: 200px;
border: 1px solid #ccc;
border-radius: 4px;
} */
</style>

View File

@ -0,0 +1,228 @@
<template>
<ContentWrap>
<span>数据配置</span>
<el-button style="margin-left:85%">重置</el-button>
</ContentWrap>
<ContentWrap>
<div class="container">
<div class="left">
<img src="../../../kefu/components/asserts/aini.png" style="width: 100%;height: 100%;" />
</div>
<div class="right">
<div>
<p style="font-weight: 700;">引导页设置</p>
<span>开屏广告</span><span> <el-switch v-model="value" size="large" /> </span>
<br />
<span>广告时间</span><span> <el-input v-model="input" style="width: 240px" placeholder="请输入秒" /></span><span> 单位()</span>
<br />
</div>
<br/>
<div>
<!-- 动态生成多个长方体区域 -->
<div class="rectangle-container">
<div class="imageLeft">
<UploadImg width="100px" height="100px" v-model="pic" />
<!-- <img v-if="pic" :src="pic" alt="Uploaded image" class="image-preview" /> -->
</div>
<div class="inputRight">
<!-- 上下排列的输入框 -->
<input type="text" v-model="input1" placeholder="输入框 1" />
<input type="text" v-model="input2" placeholder="输入框 2" />
</div>
</div>
<!-- 添加按钮 -->
<el-button type="primary" @click="addNewItem">添加图片</el-button>
</div>
</div>
</div>
<div>
<p style="font-weight: 700;">引导页设置</p>
<span>开屏广告</span><span> <el-switch v-model="value" size="large" /> </span>
<br />
<span>广告时间</span><span> <el-input v-model="input" style="width: 240px" placeholder="请输入秒" /></span><span> 单位()</span>
<br />
</div>
<br/>
<div>
<div class="rectangle-container">
<div class="imageLeft">
<UploadImg width="100px" height="100px" v-model="pic" />
</div>
<div class="inputRight">
<input type="text" v-model="input1" placeholder="输入框 1" />
<input type="text" v-model="input2" placeholder="输入框 2" />
</div>
</div>
<el-button type="primary" @click="addNewItem">添加图片</el-button>
</div>
</ContentWrap>
</template>
<script>
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { AdvertisingApi, AdvertisingVO } from '@/api/mall/promotion/'
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
// const list = ref<AdvertisingVO[]>([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
status: undefined,
time: [],
property: undefined,
createTime: []
})
const input1 = '0'
const input2 = ''
const items = [{id: '', image: '', input1: '', input2: '' }]
// const addNewItem = () => {
// items.push({id: '', image: '', input1: '', input2: '' });
// }
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await AdvertisingApi.getAdvertisingPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
// /** / */
// const formRef = ref()
// const openForm = (type: string, id?: number) => {
// formRef.value.open(type, id)
// }
// /** **/
// onMounted(() => {
// getList()
// })
</script>
<style>
.container {
display: flex;
/* justify-content: space-between; /* 左右分布 */
width: 100%;
}
.left {
width: 300px;
height: 500px;
border-radius: 10px;
border: 1px solid #ddd;
border-radius: 8px;
/* background-color: lightblue; */
}
.right {
margin-left: 50px;
/* background-color: lightgreen; */
}
/**
* 上传图片
*/
.rectangle-container {
display: flex;
/* align-items: center;
justify-content: flex-start;
width: 100%;
margin-bottom: 20px; /* 给每个区域之间添加间隔 */
padding: 10px;
border: 1px solid #ddd;
border-radius: 8px;
}
.imageLeft {
width: 100px;
height: 100px;
margin-right: 20px;
/* position: relative; */
}
/* .imageLeft input[type="file"] {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 50%;
opacity: 0;
cursor: pointer;
} */
.image-preview {
width: 50px;
height: 50px;
/* object-fit: cover;
border-radius: 8px; */
}
.inputRight {
display: flex;
flex-direction: column;
}
.inputRight input {
margin-bottom: 10px;
padding: 8px;
width: 200px;
border: 1px solid #ccc;
border-radius: 4px;
}
/* button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
} */
/* button:hover {
background-color: #45a049;
} */
</style>

View File

@ -0,0 +1,102 @@
package cn.iocoder.yudao.module.promotion.controller.admin.advertising;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo.*;
import cn.iocoder.yudao.module.promotion.dal.dataobject.advertising.AdvertisingDO;
import cn.iocoder.yudao.module.promotion.service.advertising.AdvertisingService;
@Tag(name = "管理后台 - 开屏广告")
@RestController
@RequestMapping("/promotion/advertising")
@Validated
public class AdvertisingController {
@Resource
private AdvertisingService advertisingService;
@PostMapping("/create")
@Operation(summary = "创建开屏广告")
@PreAuthorize("@ss.hasPermission('promotion:advertising:create')")
public CommonResult<Long> createAdvertising(@Valid @RequestBody AdvertisingSaveReqVO createReqVO) {
return success(advertisingService.createAdvertising(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新开屏广告")
@PreAuthorize("@ss.hasPermission('promotion:advertising:update')")
public CommonResult<Boolean> updateAdvertising(@Valid @RequestBody AdvertisingSaveReqVO updateReqVO) {
advertisingService.updateAdvertising(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除开屏广告")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('promotion:advertising:delete')")
public CommonResult<Boolean> deleteAdvertising(@RequestParam("id") Long id) {
advertisingService.deleteAdvertising(id);
return success(true);
}
@GetMapping("/page")
@Operation(summary = "获得开屏广告分页")
@PreAuthorize("@ss.hasPermission('promotion:advertising:query')")
public CommonResult<PageResult<AdvertisingRespVO>> getAdvertisingPage(@Valid AdvertisingPageReqVO pageReqVO) {
PageResult<AdvertisingDO> pageResult = advertisingService.getAdvertisingPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, AdvertisingRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出开屏广告 Excel")
@PreAuthorize("@ss.hasPermission('promotion:advertising:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportAdvertisingExcel(@Valid AdvertisingPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<AdvertisingDO> list = advertisingService.getAdvertisingPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "开屏广告.xls", "数据", AdvertisingRespVO.class,
BeanUtils.toBean(list, AdvertisingRespVO.class));
}
//添加修改开屏广告
@PostMapping("/saveAdvertising")
public CommonResult<Long> saveAdvertising(@Valid @RequestBody AdvertisingSaveReqVO createReqVO) {
return success(advertisingService.saveAdvertising(createReqVO));
}
@GetMapping("/getAdvertising")
public CommonResult<AdvertisingRespVO> getAdvertising() {
AdvertisingDO advertising = advertisingService.getAdvertising();
return success(BeanUtils.toBean(advertising, AdvertisingRespVO.class));
}
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 开屏广告分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AdvertisingPageReqVO extends PageParam {
@Schema(description = "广告状态", example = "2")
private Integer status;
@Schema(description = "广告时间(秒)")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Integer[] time;
@Schema(description = "广告属性")
private String property;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 开屏广告 Response VO")
@Data
@ExcelIgnoreUnannotated
public class AdvertisingRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "684")
@ExcelProperty("id")
private Long id;
@Schema(description = "广告状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty(value = "广告状态", converter = DictConvert.class)
@DictFormat("promotion_diy_advertising") // TODO 代码优化建议设置到对应的 DictTypeConstants 枚举类中
private Integer status;
@Schema(description = "广告时间(秒)", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("广告时间(秒)")
private Integer time;
@Schema(description = "广告属性", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("广告属性")
private String property;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
private List<Object> picData;
private Boolean stat;
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 开屏广告新增/修改 Request VO")
@Data
public class AdvertisingSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "684")
private Long id;
@Schema(description = "广告状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
private Integer status;
@Schema(description = "广告时间(秒)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "广告时间(秒)不能为空")
private Integer time;
@Schema(description = "广告属性", requiredMode = Schema.RequiredMode.REQUIRED)
private String property;
@Schema(description = "图片添加不能为空", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Object> picData;
private Boolean stat;
}

View File

@ -0,0 +1,59 @@
package cn.iocoder.yudao.module.promotion.dal.dataobject.advertising;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 开屏广告 DO
*
* @author 管理员
*/
@TableName("promotion_diy_template_advertising")
@KeySequence("promotion_diy_template_advertising_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AdvertisingDO extends BaseDO {
/**
* id
*/
@TableId
private Long id;
/**
* 广告状态
*
* 枚举 {@link TODO promotion_diy_advertising 对应的类}
*/
private Integer status;
/**
* 广告时间()
*/
private Integer time;
/**
* 广告属性
*/
private String property;
/**
* 图片数据
*/
@TableField(exist = false)
private List<Object> picData;
/**
* 开屏状态
*/
@TableField(exist = false)
private Boolean stat;
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.advertising;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.promotion.dal.dataobject.advertising.AdvertisingDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo.*;
/**
* 开屏广告 Mapper
*
* @author 管理员
*/
@Mapper
public interface AdvertisingMapper extends BaseMapperX<AdvertisingDO> {
default PageResult<AdvertisingDO> selectPage(AdvertisingPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AdvertisingDO>()
.eqIfPresent(AdvertisingDO::getStatus, reqVO.getStatus())
.betweenIfPresent(AdvertisingDO::getTime, reqVO.getTime())
.eqIfPresent(AdvertisingDO::getProperty, reqVO.getProperty())
.betweenIfPresent(AdvertisingDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(AdvertisingDO::getId));
}
}

View File

@ -0,0 +1,58 @@
package cn.iocoder.yudao.module.promotion.service.advertising;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo.*;
import cn.iocoder.yudao.module.promotion.dal.dataobject.advertising.AdvertisingDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 开屏广告 Service 接口
*
* @author 管理员
*/
public interface AdvertisingService {
/**
* 创建开屏广告
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createAdvertising(@Valid AdvertisingSaveReqVO createReqVO);
/**
* 更新开屏广告
*
* @param updateReqVO 更新信息
*/
void updateAdvertising(@Valid AdvertisingSaveReqVO updateReqVO);
/**
* 删除开屏广告
*
* @param id 编号
*/
void deleteAdvertising(Long id);
/**
* 获得开屏广告
*
* @return 开屏广告
*/
AdvertisingDO getAdvertising();
/**
* 获得开屏广告分页
*
* @param pageReqVO 分页查询
* @return 开屏广告分页
*/
PageResult<AdvertisingDO> getAdvertisingPage(AdvertisingPageReqVO pageReqVO);
Long saveAdvertising(@Valid AdvertisingSaveReqVO createReqVO);
}

View File

@ -0,0 +1,108 @@
package cn.iocoder.yudao.module.promotion.service.advertising;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.promotion.controller.admin.advertising.vo.*;
import cn.iocoder.yudao.module.promotion.dal.dataobject.advertising.AdvertisingDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.dal.mysql.advertising.AdvertisingMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
/**
* 开屏广告 Service 实现类
*
* @author 管理员
*/
@Service
@Validated
public class AdvertisingServiceImpl implements AdvertisingService {
@Resource
private AdvertisingMapper advertisingMapper;
@Override
public Long createAdvertising(AdvertisingSaveReqVO createReqVO) {
// 插入
AdvertisingDO advertising = BeanUtils.toBean(createReqVO, AdvertisingDO.class);
advertisingMapper.insert(advertising);
// 返回
return advertising.getId();
}
@Override
public void updateAdvertising(AdvertisingSaveReqVO updateReqVO) {
// 校验存在
validateAdvertisingExists(updateReqVO.getId());
// 更新
AdvertisingDO updateObj = BeanUtils.toBean(updateReqVO, AdvertisingDO.class);
advertisingMapper.updateById(updateObj);
}
@Override
public void deleteAdvertising(Long id) {
// 校验存在
validateAdvertisingExists(id);
// 删除
advertisingMapper.deleteById(id);
}
private void validateAdvertisingExists(Long id) {
if (advertisingMapper.selectById(id) == null) {
throw exception(ADVERTISING_NOT_EXISTS);
}
}
@Override
public AdvertisingDO getAdvertising() {
List<AdvertisingDO> advertisingDOS = advertisingMapper.selectList();
if (advertisingDOS.isEmpty()){
return new AdvertisingDO();
}
AdvertisingDO advertisingDO = advertisingDOS.get(0);
advertisingDO.setPicData(JSON.parseArray(advertisingDO.getProperty()));
if (advertisingDO.getStatus() == 1){
advertisingDO.setStat(true);
}
if (advertisingDO.getStatus() == 2){
advertisingDO.setStat(false);
}
return advertisingDO;
}
@Override
public PageResult<AdvertisingDO> getAdvertisingPage(AdvertisingPageReqVO pageReqVO) {
return advertisingMapper.selectPage(pageReqVO);
}
@Override
public Long saveAdvertising(@Valid AdvertisingSaveReqVO createReqVO) {
if (createReqVO.getStat()){
createReqVO.setStatus(1);
}else {
createReqVO.setStatus(2);
}
List<AdvertisingDO> advertisingDOS = advertisingMapper.selectList();
if (advertisingDOS.isEmpty()){
createReqVO.setProperty(JSON.toJSONString(createReqVO.getPicData()));
AdvertisingDO advertising = BeanUtils.toBean(createReqVO, AdvertisingDO.class);
return (long) advertisingMapper.insert(advertising);
}
AdvertisingDO advertisingDO = advertisingDOS.get(0);
advertisingDO.setProperty(JSON.toJSONString(createReqVO.getPicData()));
return (long)advertisingMapper.updateById(advertisingDO);
}
}