- 前端 + 后端:完善首页广告

This commit is contained in:
YunaiV
2019-05-06 23:30:30 +08:00
parent 2890af6311
commit 9a3b708738
11 changed files with 86 additions and 69 deletions

View File

@@ -39,11 +39,11 @@ public class MVCConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 用户
registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**");
registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口
// registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**");
// registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口
// 管理员
registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**");
registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**");
// registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**");
// registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**");
}
@Override

View File

@@ -15,14 +15,18 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import static cn.iocoder.common.framework.vo.CommonResult.success;
@RestController
@RequestMapping("admins/banner")
@Api("Banner 模块")
public class AdminsBannerController {
@Reference(validation = "true")
@Autowired
private BannerService bannerService;
@GetMapping("/page")
@@ -35,8 +39,8 @@ public class AdminsBannerController {
public CommonResult<AdminsBannerPageVO> page(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
CommonResult<BannerPageBO> result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize));
return BannerConvert.INSTANCE.convert(result);
BannerPageBO result = bannerService.getBannerPage(new BannerPageDTO().setTitle(title).setPageNo(pageNo).setPageSize(pageSize));
return success(BannerConvert.ADMINS.convert3(result));
}
@PostMapping("/add")
@@ -55,7 +59,7 @@ public class AdminsBannerController {
@RequestParam(value = "memo", required = false) String memo) {
BannerAddDTO bannerAddDTO = new BannerAddDTO().setTitle(title).setUrl(url).setPicUrl(picUrl)
.setSort(sort).setMemo(memo);
return BannerConvert.INSTANCE.convert2(bannerService.addBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO));
return success(BannerConvert.ADMINS.convert(bannerService.addBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerAddDTO)));
}
@PostMapping("/update")
@@ -75,7 +79,7 @@ public class AdminsBannerController {
@RequestParam(value = "memo", required = false) String memo) {
BannerUpdateDTO bannerUpdateDTO = new BannerUpdateDTO().setId(id).setTitle(title).setUrl(url).setPicUrl(picUrl)
.setSort(sort).setMemo(memo);
return bannerService.updateBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO);
return success(bannerService.updateBanner(AdminSecurityContextHolder.getContext().getAdminId(), bannerUpdateDTO));
}
@PostMapping("/update_status")
@@ -86,14 +90,14 @@ public class AdminsBannerController {
})
public CommonResult<Boolean> updateStatus(@RequestParam("id") Integer id,
@RequestParam("status") Integer status) {
return bannerService.updateBannerStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status);
return success(bannerService.updateBannerStatus(AdminSecurityContextHolder.getContext().getAdminId(), id, status));
}
@PostMapping("/delete")
@ApiOperation(value = "删除 Banner")
@ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1")
public CommonResult<Boolean> delete(@RequestParam("id") Integer id) {
return bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id);
return success(bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id));
}
}

View File

@@ -17,6 +17,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
@@ -28,6 +29,7 @@ import java.util.Date;
public class AdminsCouponController {
@Reference(validation = "true")
@Autowired
private CouponService couponService;
// ========== 优惠劵(码)模板 ==========

View File

@@ -15,6 +15,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
public class AdminsProductRecommendController {
@Reference(validation = "true")
@Autowired
private ProductRecommendService productRecommendService;
@GetMapping("/page")

View File

@@ -30,11 +30,11 @@ public class UsersBannerController {
@PermitAll
public CommonResult<List<UsersBannerVO>> list() {
// 查询 Banner 列表
List<BannerBO> result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue()).getData();
List<BannerBO> result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue());
// 排序,按照 sort 升序
result.sort(Comparator.comparing(BannerBO::getSort));
// 返回
return CommonResult.success(BannerConvert.INSTANCE.convertList(result));
return CommonResult.success(BannerConvert.USERS.convertList(result));
}
}

View File

@@ -1,6 +1,5 @@
package cn.iocoder.mall.promotion.application.convert;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO;
@@ -12,21 +11,29 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class);
Users USERS = Mappers.getMapper(Users.class);
@Mappings({})
AdminsBannerVO convert(BannerBO bannerBO);
Admins ADMINS = Mappers.getMapper(Admins.class);
@Mappings({})
CommonResult<AdminsBannerVO> convert2(CommonResult<BannerBO> result);
@Mapper
interface Admins {
@Mappings({})
CommonResult<AdminsBannerPageVO> convert(CommonResult<BannerPageBO> result);
@Mappings({})
AdminsBannerVO convert(BannerBO bannerBO);
@Mappings({})
List<UsersBannerVO> convertList(List<BannerBO> banners);
@Mappings({})
AdminsBannerPageVO convert3(BannerPageBO bannerPageBO);
}
}
@Mapper
interface Users {
@Mappings({})
List<UsersBannerVO> convertList(List<BannerBO> banners);
}
}

View File

@@ -1,6 +1,7 @@
package cn.iocoder.mall.promotion.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.validator.InEnum;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.api.dto.BannerAddDTO;
@@ -11,16 +12,17 @@ import java.util.List;
public interface BannerService {
CommonResult<List<BannerBO>> getBannerListByStatus(Integer status);
List<BannerBO> getBannerListByStatus(Integer status);
CommonResult<BannerPageBO> getBannerPage(BannerPageDTO bannerPageDTO);
BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO);
CommonResult<BannerBO> addBanner(Integer adminId, BannerAddDTO bannerAddDTO);
BannerBO addBanner(Integer adminId, BannerAddDTO bannerAddDTO);
CommonResult<Boolean> updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO);
Boolean updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO);
CommonResult<Boolean> updateBannerStatus(Integer adminId, Integer bannerId, Integer status);
Boolean updateBannerStatus(Integer adminId, Integer bannerId,
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
CommonResult<Boolean> deleteBanner(Integer adminId, Integer bannerId);
Boolean deleteBanner(Integer adminId, Integer bannerId);
}
}

View File

@@ -2,9 +2,7 @@ package cn.iocoder.mall.promotion.biz.service;
import cn.iocoder.common.framework.constant.CommonStatusEnum;
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.promotion.api.BannerService;
import cn.iocoder.mall.promotion.api.bo.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
@@ -29,13 +27,13 @@ public class BannerServiceImpl implements BannerService {
private BannerMapper bannerMapper;
@Override
public CommonResult<List<BannerBO>> getBannerListByStatus(Integer status) {
public List<BannerBO> getBannerListByStatus(Integer status) {
List<BannerDO> banners = bannerMapper.selectListByStatus(status);
return CommonResult.success(BannerConvert.INSTANCE.convertToBO(banners));
return BannerConvert.INSTANCE.convertToBO(banners);
}
@Override
public CommonResult<BannerPageBO> getBannerPage(BannerPageDTO bannerPageDTO) {
public BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO) {
BannerPageBO bannerPageBO = new BannerPageBO();
// 查询分页数据
int offset = (bannerPageDTO.getPageNo() - 1) * bannerPageDTO.getPageSize();
@@ -43,61 +41,57 @@ public class BannerServiceImpl implements BannerService {
offset, bannerPageDTO.getPageSize())));
// 查询分页总数
bannerPageBO.setTotal(bannerMapper.selectCountByTitleLike(bannerPageDTO.getTitle()));
return CommonResult.success(bannerPageBO);
return bannerPageBO;
}
@Override
public CommonResult<BannerBO> addBanner(Integer adminId, BannerAddDTO bannerAddDTO) {
public BannerBO addBanner(Integer adminId, BannerAddDTO bannerAddDTO) {
// 保存到数据库
BannerDO banner = BannerConvert.INSTANCE.convert(bannerAddDTO).setStatus(CommonStatusEnum.ENABLE.getValue());
banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date());
bannerMapper.insert(banner);
// 返回成功
return CommonResult.success(BannerConvert.INSTANCE.convertToBO(banner));
return BannerConvert.INSTANCE.convertToBO(banner);
}
@Override
public CommonResult<Boolean> updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO) {
public Boolean updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerUpdateDTO.getId()) == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = BannerConvert.INSTANCE.convert(bannerUpdateDTO);
bannerMapper.update(updateBanner);
// 返回成功
return CommonResult.success(true);
return true;
}
@Override
public CommonResult<Boolean> updateBannerStatus(Integer adminId, Integer bannerId, Integer status) {
// 校验参数
if (!CommonStatusEnum.isValid(status)) {
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启1或关闭2"); // TODO 有点搓
}
public Boolean updateBannerStatus(Integer adminId, Integer bannerId, Integer status) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status);
bannerMapper.update(updateBanner);
// 返回成功
return CommonResult.success(true);
return true;
}
@Override
public CommonResult<Boolean> deleteBanner(Integer adminId, Integer bannerId) {
public Boolean deleteBanner(Integer adminId, Integer bannerId) {
// 校验 Banner 存在
if (bannerMapper.selectById(bannerId) == null) {
return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode());
}
// 更新到数据库
BannerDO updateBanner = new BannerDO().setId(bannerId);
updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue());
bannerMapper.update(updateBanner);
// 返回成功
return CommonResult.success(true);
return true;
}
}