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

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

@ -101,7 +101,7 @@ class PicturesWall extends React.Component {
// }) // })
// .catch(onError); // .catch(onError);
let key = uuid.v4(); // TODO 芋艿可能后面要优化。MD5 let key = uuid.v4(); // TODO 芋艿可能后面要优化。MD5
let observable = qiniu.upload(e, key, this.state.token); // TODO 芋艿,最后后面去掉 qiniu 的库依赖,直接 http 请求,这样更轻量 let observable = qiniu.upload(file, key, this.state.token); // TODO 芋艿,最后后面去掉 qiniu 的库依赖,直接 http 请求,这样更轻量
observable.subscribe(function () { observable.subscribe(function () {
// next // next
}, function () { }, function () {
@ -109,6 +109,7 @@ class PicturesWall extends React.Component {
// TODO 芋艿,后续补充 // TODO 芋艿,后续补充
debugger; debugger;
}, function (response) { }, function (response) {
debugger;
// complete // complete
// debugger; // debugger;
response.url = 'http://static.shop.iocoder.cn/' + response.key; // 需要设置,用于后续 onSuccess ,合并到 file 中,从而设置到 fileList response.url = 'http://static.shop.iocoder.cn/' + response.key; // 需要设置,用于后续 onSuccess ,合并到 file 中,从而设置到 fileList

View File

@ -55,7 +55,7 @@ export default {
'menu.order.order-list': '订单管理', 'menu.order.order-list': '订单管理',
'menu.order.order-refunds': '退货维权', 'menu.order.order-refunds': '退货维权',
// 营销相关 // 营销相关
'menu.promotion.promotion-banner-list': 'Banner 管理', 'menu.promotion.promotion-banner-list': '首页广告',
'menu.promotion.product-recommend-list': '商品推荐', 'menu.promotion.product-recommend-list': '商品推荐',
'menu.promotion.coupon-card-template-list': '优惠劵管理', 'menu.promotion.coupon-card-template-list': '优惠劵管理',
}; };

View File

@ -25,9 +25,9 @@ import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from './BannerList.less'; import styles from './BannerList.less';
import moment from "moment"; import moment from "moment";
import PaginationHelper from "../../../helpers/PaginationHelper"; import PaginationHelper from "../../../helpers/PaginationHelper";
import PicturesWall from "../../components/Image/PicturesWall";
const FormItem = Form.Item; const FormItem = Form.Item;
const { TreeNode } = Tree;
const status = ['未知', '正常', '禁用']; const status = ['未知', '正常', '禁用'];
// 列表 // 列表
@ -70,11 +70,13 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
const columns = [ const columns = [
{ {
title: '标题', title: '标题',
dataIndex: 'title' dataIndex: 'title',
width: 120,
}, },
{ {
title: '跳转链接', title: '跳转链接',
dataIndex: 'url', dataIndex: 'url',
width: 120,
}, },
{ {
title: '图片', title: '图片',
@ -97,15 +99,17 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
{ {
title: '备注', title: '备注',
dataIndex: 'memo', dataIndex: 'memo',
width: 150,
}, },
{ {
title: '创建时间', title: '创建时间',
dataIndex: 'createTime', dataIndex: 'createTime',
render: val => <span>{moment(val).format('YYYY-MM-DD HH:mm')}</span>, width: 120,
render: val => <span>{moment(val).format('YYYY-MM-DD')}</span>,
}, },
{ {
title: '操作', title: '操作',
width: 360, width: 150,
render: (text, record) => { render: (text, record) => {
const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改 const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改
return ( return (
@ -214,6 +218,7 @@ const SearchForm = Form.create()(props => {
// 添加 or 修改 Form 表单 // 添加 or 修改 Form 表单
const AddOrUpdateForm = Form.create()(props => { const AddOrUpdateForm = Form.create()(props => {
const { dispatch, modalVisible, form, handleModalVisible, modalType, formVals } = props; const { dispatch, modalVisible, form, handleModalVisible, modalType, formVals } = props;
let picturesWall = null;
const okHandle = () => { const okHandle = () => {
form.validateFields((err, fields) => { form.validateFields((err, fields) => {
@ -225,6 +230,7 @@ const AddOrUpdateForm = Form.create()(props => {
payload: { payload: {
body: { body: {
...fields, ...fields,
picUrl: picturesWall ? picturesWall.getUrl() : undefined,
}, },
callback: () => { callback: () => {
// 清空表单 // 清空表单
@ -244,12 +250,13 @@ const AddOrUpdateForm = Form.create()(props => {
body: { body: {
id: formVals.id, id: formVals.id,
...fields, ...fields,
picUrl: picturesWall ? picturesWall.getUrl() : undefined,
}, },
callback: () => { callback: () => {
// 清空表单 // 清空表单
form.resetFields(); form.resetFields();
// 提示 // 提示
message.success('更新成功'); message.success('编辑成功');
// 关闭弹窗 // 关闭弹窗
handleModalVisible(); handleModalVisible();
}, },
@ -259,7 +266,7 @@ const AddOrUpdateForm = Form.create()(props => {
}); });
}; };
const title = modalType === 'add' ? '新建 Banner' : '更新 Banner'; const title = modalType === 'add' ? '新建广告' : '编辑广告';
return ( return (
<Modal <Modal
destroyOnClose destroyOnClose
@ -286,11 +293,9 @@ const AddOrUpdateForm = Form.create()(props => {
initialValue: formVals.picUrl, initialValue: formVals.picUrl,
})(<Input placeholder="请输入" />)} })(<Input placeholder="请输入" />)}
</FormItem> </FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="图片"> <FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="分类图片"
{form.getFieldDecorator('picUrl', { extra="建议尺寸640*340px大小不超过 2M" required={true}>
rules: [{ required: true, message: '请输入跳转链接!'},], <PicturesWall urls={formVals.picUrl ? [formVals.picUrl] : undefined} ref={(node) => picturesWall = node} maxLength={1} />
initialValue: formVals.picUrl,
})(<Input placeholder="请输入" />)}
</FormItem> </FormItem>
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="排序值"> <FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="排序值">
{form.getFieldDecorator('sort', { {form.getFieldDecorator('sort', {
@ -365,7 +370,7 @@ class BannerList extends PureComponent {
dispatch, dispatch,
}; };
// 添加 or 更新表单属性 // 添加 or 编辑表单属性
const addOrUpdateFormProps = { const addOrUpdateFormProps = {
modalVisible, modalVisible,
modalType, modalType,
@ -387,7 +392,7 @@ class BannerList extends PureComponent {
type="primary" type="primary"
onClick={() => this.handleModalVisible(true, 'add', {})} onClick={() => this.handleModalVisible(true, 'add', {})}
> >
新建 Banner 新建广告
</Button> </Button>
</div> </div>
</div> </div>

View File

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

View File

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

View File

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

View File

@ -30,11 +30,11 @@ public class UsersBannerController {
@PermitAll @PermitAll
public CommonResult<List<UsersBannerVO>> list() { public CommonResult<List<UsersBannerVO>> list() {
// 查询 Banner 列表 // 查询 Banner 列表
List<BannerBO> result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue()).getData(); List<BannerBO> result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue());
// 排序按照 sort 升序 // 排序按照 sort 升序
result.sort(Comparator.comparing(BannerBO::getSort)); 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; 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.BannerBO;
import cn.iocoder.mall.promotion.api.bo.BannerPageBO; import cn.iocoder.mall.promotion.api.bo.BannerPageBO;
import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO; import cn.iocoder.mall.promotion.application.vo.admins.AdminsBannerPageVO;
@ -12,21 +11,29 @@ import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
@Mapper
public interface BannerConvert { public interface BannerConvert {
BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class); Users USERS = Mappers.getMapper(Users.class);
Admins ADMINS = Mappers.getMapper(Admins.class);
@Mapper
interface Admins {
@Mappings({}) @Mappings({})
AdminsBannerVO convert(BannerBO bannerBO); AdminsBannerVO convert(BannerBO bannerBO);
@Mappings({}) @Mappings({})
CommonResult<AdminsBannerVO> convert2(CommonResult<BannerBO> result); AdminsBannerPageVO convert3(BannerPageBO bannerPageBO);
@Mappings({}) }
CommonResult<AdminsBannerPageVO> convert(CommonResult<BannerPageBO> result);
@Mapper
interface Users {
@Mappings({}) @Mappings({})
List<UsersBannerVO> convertList(List<BannerBO> banners); List<UsersBannerVO> convertList(List<BannerBO> banners);
}
} }

View File

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