弹窗广告

This commit is contained in:
GYJ 2024-08-19 11:16:47 +08:00
parent 8e0f237e2e
commit 5643faab22
12 changed files with 498 additions and 0 deletions

View File

@ -0,0 +1,46 @@
package cn.ysk.cashier.controller;
import cn.ysk.cashier.dto.TbMiniAppPagesDto;
import cn.ysk.cashier.mybatis.service.TbMiniAppPagesService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author GYJ
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/miniAppPages")
public class TbMiniAppPagesController {
final private TbMiniAppPagesService tbMiniAppPagesService;
@PostMapping
@ApiOperation("新增/system/miniAppPages")
public ResponseEntity<Object> createTbMiniAppPages(@Validated @RequestBody TbMiniAppPagesDto pagesDto) {
return tbMiniAppPagesService.createTbMiniAppPages(pagesDto);
}
@PutMapping
@ApiOperation("修改/system/miniAppPages")
public ResponseEntity<Object> updateTbMiniAppPages(@Validated @RequestBody TbMiniAppPagesDto pagesDto) {
return tbMiniAppPagesService.updateTbMiniAppPages(pagesDto);
}
@DeleteMapping("/{pagesId}")
@ApiOperation("删除/system/miniAppPages")
public ResponseEntity<Object> deleteTbMiniAppPages(@PathVariable Integer pagesId) {
return tbMiniAppPagesService.deleteTbMiniAppPages(pagesId);
}
@GetMapping
@ApiOperation("查询/system/miniAppPages")
public ResponseEntity<Object> getTbMiniAppPages(@RequestParam Map<String, Object> params) {
return tbMiniAppPagesService.getTbMiniAppPages(params);
}
}

View File

@ -0,0 +1,39 @@
package cn.ysk.cashier.controller.shop;
import cn.ysk.cashier.dto.shop.TbShopAdDto;
import cn.ysk.cashier.mybatis.service.TbShopAdService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author GYJ
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/ad")
public class TbShopAdController {
final private TbShopAdService tbShopAdService;
@PostMapping
public ResponseEntity<Object> createTbShopAd(@RequestBody TbShopAdDto adDto) {
return tbShopAdService.createTbShopAd(adDto);
}
@PutMapping
public ResponseEntity<Object> updateTbShopAd(@RequestBody TbShopAdDto adDto) {
return tbShopAdService.updateTbShopAd(adDto);
}
@DeleteMapping("/{adId}")
public ResponseEntity<Object> deleteTbShopAd(@PathVariable Integer adId) {
return tbShopAdService.deleteTbShopAd(adId);
}
@GetMapping
public ResponseEntity<Object> getTbShopAd(@RequestParam Map<String, Object> params) {
return tbShopAdService.getTbShopAd(params);
}
}

View File

@ -0,0 +1,22 @@
package cn.ysk.cashier.dto;
import lombok.Data;
import java.util.Date;
/**
* @author GYJ
*/
@Data
public class TbMiniAppPagesDto {
private Integer id;
private Integer shopId;
private String name;
private String path;
private String icon;
private String description;
private Integer sort;
private Integer status;
private Date createTime;
private Date updateTime;
}

View File

@ -0,0 +1,40 @@
package cn.ysk.cashier.dto.shop;
import cn.ysk.cashier.mybatis.entity.TbShopAd;
import lombok.Data;
import java.util.Date;
/**
* @author GYJ
*/
@Data
public class TbShopAdDto {
private Integer id;
private Integer shopId;
private String imgUrl;
private String linkPath;
private Integer borderRadius;
private String showPosition;
private String frequency;
private Integer status;
private Integer sort;
private Date createTime;
private Date updateTime;
public TbShopAd convertToTbShopAd() {
TbShopAd tbShopAd = new TbShopAd();
tbShopAd.setId(this.id);
tbShopAd.setShopId(this.shopId);
tbShopAd.setImgUrl(this.imgUrl);
tbShopAd.setLinkPath(this.linkPath);
tbShopAd.setBorderRadius(this.borderRadius);
tbShopAd.setShowPosition(this.showPosition);
tbShopAd.setFrequency(this.frequency);
tbShopAd.setStatus(this.status);
tbShopAd.setSort(this.sort);
tbShopAd.setCreateTime(this.createTime);
tbShopAd.setUpdateTime(this.updateTime);
return tbShopAd;
}
}

View File

@ -0,0 +1,26 @@
package cn.ysk.cashier.mybatis.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @author GYJ
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("tb_mini_app_pages")
public class TbMiniAppPages extends Model<TbMiniAppPages> {
private Integer id;
private String icon;
private String name;
private String path;
private String description;
private Integer status;
private Integer sort;
private Date createTime;
private Date updateTime;
}

View File

@ -0,0 +1,28 @@
package cn.ysk.cashier.mybatis.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* @author GYJ
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("tb_shop_ad")
public class TbShopAd extends Model<TbUserStorage> {
private Integer id;
private Integer shopId;
private String imgUrl;
private String linkPath;
private Integer borderRadius;
private String showPosition;
private String frequency;
private Integer status;
private Integer sort;
private Date createTime;
private Date updateTime;
}

View File

@ -0,0 +1,10 @@
package cn.ysk.cashier.mybatis.mapper;
import cn.ysk.cashier.mybatis.entity.TbMiniAppPages;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author GYJ
*/
public interface TbMiniAppPagesMapper extends BaseMapper<TbMiniAppPages> {
}

View File

@ -0,0 +1,10 @@
package cn.ysk.cashier.mybatis.mapper;
import cn.ysk.cashier.mybatis.entity.TbShopAd;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @author GYJ
*/
public interface TbShopAdMapper extends BaseMapper<TbShopAd> {
}

View File

@ -0,0 +1,22 @@
package cn.ysk.cashier.mybatis.service;
import cn.ysk.cashier.dto.TbMiniAppPagesDto;
import cn.ysk.cashier.mybatis.entity.TbMiniAppPages;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.http.ResponseEntity;
import java.util.Map;
/**
* @author GYJ
*/
public interface TbMiniAppPagesService extends IService<TbMiniAppPages> {
ResponseEntity<Object> createTbMiniAppPages(TbMiniAppPagesDto pagesDto);
ResponseEntity<Object> updateTbMiniAppPages(TbMiniAppPagesDto pagesDto);
ResponseEntity<Object> deleteTbMiniAppPages(Integer pagesId);
ResponseEntity<Object> getTbMiniAppPages(Map<String, Object> params);
}

View File

@ -0,0 +1,22 @@
package cn.ysk.cashier.mybatis.service;
import cn.ysk.cashier.dto.shop.TbShopAdDto;
import cn.ysk.cashier.mybatis.entity.TbShopAd;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.http.ResponseEntity;
import java.util.Map;
/**
* @author GYJ
*/
public interface TbShopAdService extends IService<TbShopAd> {
ResponseEntity<Object> createTbShopAd(TbShopAdDto adDto);
ResponseEntity<Object> updateTbShopAd(TbShopAdDto adDto);
ResponseEntity<Object> deleteTbShopAd(Integer adId);
ResponseEntity<Object> getTbShopAd(Map<String, Object> params);
}

View File

@ -0,0 +1,118 @@
package cn.ysk.cashier.mybatis.service.impl;
import cn.ysk.cashier.dto.TbMiniAppPagesDto;
import cn.ysk.cashier.mybatis.entity.TbMiniAppPages;
import cn.ysk.cashier.mybatis.mapper.TbMiniAppPagesMapper;
import cn.ysk.cashier.mybatis.service.TbMiniAppPagesService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Map;
/**
* @author GYJ
*/
@Service
@RequiredArgsConstructor
public class TbMiniAppPagesServiceImpl extends ServiceImpl<TbMiniAppPagesMapper, TbMiniAppPages> implements TbMiniAppPagesService {
@Override
public ResponseEntity<Object> createTbMiniAppPages(TbMiniAppPagesDto pagesDto) {
if (pagesDto == null) {
return ResponseEntity.badRequest().body("参数不能为空");
}
if (pagesDto.getName() == null || pagesDto.getPath() == null) {
return ResponseEntity.badRequest().body("页面名称和路径不能为空");
}
QueryWrapper<TbMiniAppPages> wrapper = new QueryWrapper<>();
wrapper.eq("name", pagesDto.getName());
TbMiniAppPages tbMiniAppPages = baseMapper.selectOne(wrapper);
if (tbMiniAppPages != null) {
return ResponseEntity.badRequest().body("页面已存在");
}
tbMiniAppPages = new TbMiniAppPages();
tbMiniAppPages.setName(pagesDto.getName());
tbMiniAppPages.setPath(pagesDto.getPath());
tbMiniAppPages.setIcon(pagesDto.getIcon());
tbMiniAppPages.setSort(pagesDto.getSort());
tbMiniAppPages.setDescription(pagesDto.getDescription());
tbMiniAppPages.setStatus(pagesDto.getStatus());
tbMiniAppPages.setCreateTime(new Date());
tbMiniAppPages.setUpdateTime(new Date());
baseMapper.insert(tbMiniAppPages);
return ResponseEntity.ok().body("新增成功");
}
@Override
public ResponseEntity<Object> updateTbMiniAppPages(TbMiniAppPagesDto pagesDto) {
TbMiniAppPages appPages = baseMapper.selectById(pagesDto.getId());
if (appPages == null) {
return ResponseEntity.badRequest().body("页面不存在");
}
if (pagesDto.getName() == null || pagesDto.getPath() == null) {
return ResponseEntity.badRequest().body("页面名称和路径不能为空");
}
if (!appPages.getName().equals(pagesDto.getName())) {
QueryWrapper<TbMiniAppPages> wrapper = new QueryWrapper<>();
wrapper.eq("name", pagesDto.getName());
TbMiniAppPages tbMiniAppPages = baseMapper.selectOne(wrapper);
if (tbMiniAppPages != null) {
return ResponseEntity.badRequest().body("页面已存在");
}
}
if (pagesDto.getName() != null) {
appPages.setName(pagesDto.getName());
}
if (pagesDto.getPath() != null) {
appPages.setPath(pagesDto.getPath());
}
if (pagesDto.getIcon() != null) {
appPages.setIcon(pagesDto.getIcon());
}
if (pagesDto.getSort() != null) {
appPages.setSort(pagesDto.getSort());
}
if (pagesDto.getDescription() != null) {
appPages.setDescription(pagesDto.getDescription());
}
if (pagesDto.getStatus() != null) {
appPages.setStatus(pagesDto.getStatus());
}
appPages.setUpdateTime(new Date());
baseMapper.updateById(appPages);
return ResponseEntity.ok().body("更新成功");
}
@Override
public ResponseEntity<Object> deleteTbMiniAppPages(Integer pagesId) {
TbMiniAppPages appPages = baseMapper.selectById(pagesId);
if (appPages == null) {
return ResponseEntity.badRequest().body("页面不存在");
}
baseMapper.deleteById(pagesId);
return ResponseEntity.ok().body("删除成功");
}
@Override
public ResponseEntity<Object> getTbMiniAppPages(Map<String, Object> params) {
QueryWrapper<TbMiniAppPages> wrapper = new QueryWrapper<>();
if (params.get("status") != null) {
wrapper.eq("status", params.get("status"));
}
wrapper.orderByDesc("sort");
return ResponseEntity.ok().body(baseMapper.selectList(wrapper));
}
}

View File

@ -0,0 +1,115 @@
package cn.ysk.cashier.mybatis.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.dto.shop.TbShopAdDto;
import cn.ysk.cashier.mybatis.entity.TbShopAd;
import cn.ysk.cashier.mybatis.mapper.TbShopAdMapper;
import cn.ysk.cashier.mybatis.service.TbShopAdService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.Map;
/**
* @author GYJ
*/
@Service
@RequiredArgsConstructor
public class TbShopAdServiceImpl extends ServiceImpl<TbShopAdMapper, TbShopAd> implements TbShopAdService {
@Override
public ResponseEntity<Object> createTbShopAd(TbShopAdDto adDto) {
if (adDto.getShopId() == null || adDto.getShopId() == 0) {
return ResponseEntity.badRequest().body("店铺ID不能为空");
}
if (StrUtil.isBlank(adDto.getImgUrl())) {
return ResponseEntity.badRequest().body("图片地址不能为空");
}
TbShopAd shopAd = adDto.convertToTbShopAd();
shopAd.setCreateTime(new Date());
shopAd.setUpdateTime(new Date());
baseMapper.insert(shopAd);
return ResponseEntity.ok().body("新增成功");
}
@Override
public ResponseEntity<Object> updateTbShopAd(TbShopAdDto adDto) {
if (adDto.getShopId() == null || adDto.getShopId() == 0) {
return ResponseEntity.badRequest().body("店铺ID不能为空");
}
if (StrUtil.isBlank(adDto.getImgUrl())) {
return ResponseEntity.badRequest().body("图片地址不能为空");
}
TbShopAd shopAd = baseMapper.selectById(adDto.getId());
if (shopAd == null) {
return ResponseEntity.badRequest().body("广告不存在");
}
if (StrUtil.isNotBlank(adDto.getImgUrl())) {
shopAd.setImgUrl(adDto.getImgUrl());
}
if (StrUtil.isNotBlank(adDto.getLinkPath())) {
shopAd.setLinkPath(adDto.getLinkPath());
}
if (adDto.getBorderRadius() != null) {
shopAd.setBorderRadius(adDto.getBorderRadius());
}
if (StrUtil.isNotBlank(adDto.getShowPosition())) {
shopAd.setShowPosition(adDto.getShowPosition());
}
if (StrUtil.isNotBlank(adDto.getFrequency())) {
shopAd.setFrequency(adDto.getFrequency());
}
if (adDto.getStatus() != null) {
shopAd.setStatus(adDto.getStatus());
}
if (adDto.getSort() != null) {
shopAd.setSort(adDto.getSort());
}
shopAd.setUpdateTime(new Date());
baseMapper.updateById(shopAd);
return ResponseEntity.ok().body("修改成功");
}
@Override
public ResponseEntity<Object> deleteTbShopAd(Integer adId) {
TbShopAd shopAd = baseMapper.selectById(adId);
if (shopAd == null) {
return ResponseEntity.badRequest().body("广告不存在");
}
baseMapper.deleteById(adId);
return ResponseEntity.ok().body("删除成功");
}
@Override
public ResponseEntity<Object> getTbShopAd(Map<String, Object> params) {
QueryWrapper<TbShopAd> wrapper = new QueryWrapper<>();
if (StrUtil.isBlank((String) params.get("shopId"))) {
return ResponseEntity.badRequest().body("店铺ID不能为空");
}
if (StrUtil.isNotBlank((String) params.get("status"))) {
wrapper.eq("status", params.get("status"));
}
if (StrUtil.isNotBlank((String) params.get("showPosition"))) {
wrapper.eq("show_position", params.get("showPosition"));
}
if (StrUtil.isNotBlank((String) params.get("frequency"))) {
wrapper.eq("frequency", params.get("frequency"));
}
wrapper.orderByDesc("sort");
return ResponseEntity.ok().body(baseMapper.selectList(wrapper));
}
}