diff --git a/yudao-admin-vue3/src/api/mall/promotion/advertising/index.ts b/yudao-admin-vue3/src/api/mall/promotion/advertising/index.ts new file mode 100644 index 0000000..2756c6e --- /dev/null +++ b/yudao-admin-vue3/src/api/mall/promotion/advertising/index.ts @@ -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 }) + }, + +} \ No newline at end of file diff --git a/yudao-admin-vue3/src/assets/imgs/quxiao.png b/yudao-admin-vue3/src/assets/imgs/quxiao.png new file mode 100644 index 0000000..b6b0bab Binary files /dev/null and b/yudao-admin-vue3/src/assets/imgs/quxiao.png differ diff --git a/yudao-admin-vue3/src/views/mall/promotion/advertising/AdvertisingForm.vue b/yudao-admin-vue3/src/views/mall/promotion/advertising/AdvertisingForm.vue new file mode 100644 index 0000000..2cfc310 --- /dev/null +++ b/yudao-admin-vue3/src/views/mall/promotion/advertising/AdvertisingForm.vue @@ -0,0 +1,118 @@ + + \ No newline at end of file diff --git a/yudao-admin-vue3/src/views/mall/promotion/advertising/index.vue b/yudao-admin-vue3/src/views/mall/promotion/advertising/index.vue new file mode 100644 index 0000000..f74e33e --- /dev/null +++ b/yudao-admin-vue3/src/views/mall/promotion/advertising/index.vue @@ -0,0 +1,225 @@ + + + + \ No newline at end of file diff --git a/yudao-admin-vue3/src/views/mall/promotion/diy/template/dataAllocation/advertising.vue b/yudao-admin-vue3/src/views/mall/promotion/diy/template/dataAllocation/advertising.vue new file mode 100644 index 0000000..d1c050c --- /dev/null +++ b/yudao-admin-vue3/src/views/mall/promotion/diy/template/dataAllocation/advertising.vue @@ -0,0 +1,228 @@ + + + + + diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/AdvertisingController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/AdvertisingController.java new file mode 100644 index 0000000..71fa427 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/AdvertisingController.java @@ -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 createAdvertising(@Valid @RequestBody AdvertisingSaveReqVO createReqVO) { + return success(advertisingService.createAdvertising(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新开屏广告") + @PreAuthorize("@ss.hasPermission('promotion:advertising:update')") + public CommonResult 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 deleteAdvertising(@RequestParam("id") Long id) { + advertisingService.deleteAdvertising(id); + return success(true); + } + + + @GetMapping("/page") + @Operation(summary = "获得开屏广告分页") + @PreAuthorize("@ss.hasPermission('promotion:advertising:query')") + public CommonResult> getAdvertisingPage(@Valid AdvertisingPageReqVO pageReqVO) { + PageResult 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 list = advertisingService.getAdvertisingPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "开屏广告.xls", "数据", AdvertisingRespVO.class, + BeanUtils.toBean(list, AdvertisingRespVO.class)); + } + + + //添加修改开屏广告 + @PostMapping("/saveAdvertising") + public CommonResult saveAdvertising(@Valid @RequestBody AdvertisingSaveReqVO createReqVO) { + return success(advertisingService.saveAdvertising(createReqVO)); + } + + @GetMapping("/getAdvertising") + public CommonResult getAdvertising() { + AdvertisingDO advertising = advertisingService.getAdvertising(); + return success(BeanUtils.toBean(advertising, AdvertisingRespVO.class)); + } + + + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingPageReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingPageReqVO.java new file mode 100644 index 0000000..273f6a8 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingPageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingRespVO.java new file mode 100644 index 0000000..032034d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingRespVO.java @@ -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 picData; + + private Boolean stat; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingSaveReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingSaveReqVO.java new file mode 100644 index 0000000..99fd068 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/advertising/vo/AdvertisingSaveReqVO.java @@ -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 picData; + + private Boolean stat; + + + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/advertising/AdvertisingDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/advertising/AdvertisingDO.java new file mode 100644 index 0000000..4f31b6c --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/advertising/AdvertisingDO.java @@ -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") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 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 picData; + + /** + * 开屏状态 + */ + @TableField(exist = false) + private Boolean stat; + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/advertising/AdvertisingMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/advertising/AdvertisingMapper.java new file mode 100644 index 0000000..bc0f1e4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/advertising/AdvertisingMapper.java @@ -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 { + + default PageResult selectPage(AdvertisingPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(AdvertisingDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(AdvertisingDO::getTime, reqVO.getTime()) + .eqIfPresent(AdvertisingDO::getProperty, reqVO.getProperty()) + .betweenIfPresent(AdvertisingDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(AdvertisingDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/advertising/AdvertisingService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/advertising/AdvertisingService.java new file mode 100644 index 0000000..83124c4 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/advertising/AdvertisingService.java @@ -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 getAdvertisingPage(AdvertisingPageReqVO pageReqVO); + + + Long saveAdvertising(@Valid AdvertisingSaveReqVO createReqVO); + + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/advertising/AdvertisingServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/advertising/AdvertisingServiceImpl.java new file mode 100644 index 0000000..a89010a --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/advertising/AdvertisingServiceImpl.java @@ -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 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 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 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); + } + +} \ No newline at end of file