diff --git a/admin-web/src/components/Image/PicturesWall.js b/admin-web/src/components/Image/PicturesWall.js
index a51f0785a..2e27ec07f 100644
--- a/admin-web/src/components/Image/PicturesWall.js
+++ b/admin-web/src/components/Image/PicturesWall.js
@@ -101,7 +101,7 @@ class PicturesWall extends React.Component {
// })
// .catch(onError);
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 () {
// next
}, function () {
@@ -109,6 +109,7 @@ class PicturesWall extends React.Component {
// TODO 芋艿,后续补充
debugger;
}, function (response) {
+ debugger;
// complete
// debugger;
response.url = 'http://static.shop.iocoder.cn/' + response.key; // 需要设置,用于后续 onSuccess ,合并到 file 中,从而设置到 fileList
diff --git a/admin-web/src/locales/zh-CN/menu.js b/admin-web/src/locales/zh-CN/menu.js
index 339bd0ca4..a9b5533bc 100644
--- a/admin-web/src/locales/zh-CN/menu.js
+++ b/admin-web/src/locales/zh-CN/menu.js
@@ -55,7 +55,7 @@ export default {
'menu.order.order-list': '订单管理',
'menu.order.order-refunds': '退货维权',
// 营销相关
- 'menu.promotion.promotion-banner-list': 'Banner 管理',
+ 'menu.promotion.promotion-banner-list': '首页广告',
'menu.promotion.product-recommend-list': '商品推荐',
'menu.promotion.coupon-card-template-list': '优惠劵管理',
};
diff --git a/admin-web/src/pages/Promotion/BannerList.js b/admin-web/src/pages/Promotion/BannerList.js
index 2ed408adb..96a6afcc3 100644
--- a/admin-web/src/pages/Promotion/BannerList.js
+++ b/admin-web/src/pages/Promotion/BannerList.js
@@ -25,9 +25,9 @@ import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from './BannerList.less';
import moment from "moment";
import PaginationHelper from "../../../helpers/PaginationHelper";
+import PicturesWall from "../../components/Image/PicturesWall";
const FormItem = Form.Item;
-const { TreeNode } = Tree;
const status = ['未知', '正常', '禁用'];
// 列表
@@ -70,11 +70,13 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
const columns = [
{
title: '标题',
- dataIndex: 'title'
+ dataIndex: 'title',
+ width: 120,
},
{
title: '跳转链接',
dataIndex: 'url',
+ width: 120,
},
{
title: '图片',
@@ -97,15 +99,17 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch,
{
title: '备注',
dataIndex: 'memo',
+ width: 150,
},
{
title: '创建时间',
dataIndex: 'createTime',
- render: val => {moment(val).format('YYYY-MM-DD HH:mm')},
+ width: 120,
+ render: val => {moment(val).format('YYYY-MM-DD')},
},
{
title: '操作',
- width: 360,
+ width: 150,
render: (text, record) => {
const statusText = record.status === 1 ? '禁用' : '开启'; // TODO 芋艿,此处要改
return (
@@ -214,6 +218,7 @@ const SearchForm = Form.create()(props => {
// 添加 or 修改 Form 表单
const AddOrUpdateForm = Form.create()(props => {
const { dispatch, modalVisible, form, handleModalVisible, modalType, formVals } = props;
+ let picturesWall = null;
const okHandle = () => {
form.validateFields((err, fields) => {
@@ -225,6 +230,7 @@ const AddOrUpdateForm = Form.create()(props => {
payload: {
body: {
...fields,
+ picUrl: picturesWall ? picturesWall.getUrl() : undefined,
},
callback: () => {
// 清空表单
@@ -244,12 +250,13 @@ const AddOrUpdateForm = Form.create()(props => {
body: {
id: formVals.id,
...fields,
+ picUrl: picturesWall ? picturesWall.getUrl() : undefined,
},
callback: () => {
// 清空表单
form.resetFields();
// 提示
- message.success('更新成功');
+ message.success('编辑成功');
// 关闭弹窗
handleModalVisible();
},
@@ -259,7 +266,7 @@ const AddOrUpdateForm = Form.create()(props => {
});
};
- const title = modalType === 'add' ? '新建 Banner' : '更新 Banner';
+ const title = modalType === 'add' ? '新建广告' : '编辑广告';
return (
{
initialValue: formVals.picUrl,
})()}
-
- {form.getFieldDecorator('picUrl', {
- rules: [{ required: true, message: '请输入跳转链接!'},],
- initialValue: formVals.picUrl,
- })()}
+
+ picturesWall = node} maxLength={1} />
{form.getFieldDecorator('sort', {
@@ -365,7 +370,7 @@ class BannerList extends PureComponent {
dispatch,
};
- // 添加 or 更新表单属性
+ // 添加 or 编辑表单属性
const addOrUpdateFormProps = {
modalVisible,
modalType,
@@ -387,7 +392,7 @@ class BannerList extends PureComponent {
type="primary"
onClick={() => this.handleModalVisible(true, 'add', {})}
>
- 新建 Banner
+ 新建广告
@@ -401,4 +406,4 @@ class BannerList extends PureComponent {
}
}
-export default BannerList;
\ No newline at end of file
+export default BannerList;
diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java
index b7ee655c4..b0f6d3979 100644
--- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java
+++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java
@@ -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
diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java
index 60fe256c2..f5424039b 100644
--- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java
+++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java
@@ -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 page(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
- CommonResult 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 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 delete(@RequestParam("id") Integer id) {
- return bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id);
+ return success(bannerService.deleteBanner(AdminSecurityContextHolder.getContext().getAdminId(), id));
}
}
diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java
index 0ac9cc84d..4fad37ff5 100644
--- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java
+++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsCouponController.java
@@ -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;
// ========== 优惠劵(码)模板 ==========
diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java
index d71237f73..3ac590887 100644
--- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java
+++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsProductRecommendController.java
@@ -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")
diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java
index 60810e9f1..537aa46aa 100644
--- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java
+++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/users/UsersBannerController.java
@@ -30,11 +30,11 @@ public class UsersBannerController {
@PermitAll
public CommonResult> list() {
// 查询 Banner 列表
- List result = bannerService.getBannerListByStatus(CommonStatusEnum.ENABLE.getValue()).getData();
+ List 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));
}
}
diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java
index a7d5502fe..5b7e2825e 100644
--- a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java
+++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java
@@ -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 convert2(CommonResult result);
+ @Mapper
+ interface Admins {
- @Mappings({})
- CommonResult convert(CommonResult result);
+ @Mappings({})
+ AdminsBannerVO convert(BannerBO bannerBO);
- @Mappings({})
- List convertList(List banners);
+ @Mappings({})
+ AdminsBannerPageVO convert3(BannerPageBO bannerPageBO);
-}
\ No newline at end of file
+ }
+
+ @Mapper
+ interface Users {
+
+ @Mappings({})
+ List convertList(List banners);
+
+ }
+
+}
diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/BannerService.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/BannerService.java
index 94a70d6b8..118e6eca4 100644
--- a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/BannerService.java
+++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/BannerService.java
@@ -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> getBannerListByStatus(Integer status);
+ List getBannerListByStatus(Integer status);
- CommonResult getBannerPage(BannerPageDTO bannerPageDTO);
+ BannerPageBO getBannerPage(BannerPageDTO bannerPageDTO);
- CommonResult addBanner(Integer adminId, BannerAddDTO bannerAddDTO);
+ BannerBO addBanner(Integer adminId, BannerAddDTO bannerAddDTO);
- CommonResult updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO);
+ Boolean updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO);
- CommonResult updateBannerStatus(Integer adminId, Integer bannerId, Integer status);
+ Boolean updateBannerStatus(Integer adminId, Integer bannerId,
+ @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") Integer status);
- CommonResult deleteBanner(Integer adminId, Integer bannerId);
+ Boolean deleteBanner(Integer adminId, Integer bannerId);
-}
\ No newline at end of file
+}
diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java
index 83e6f39d7..1d932fc7f 100644
--- a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java
+++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java
@@ -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> getBannerListByStatus(Integer status) {
+ public List getBannerListByStatus(Integer status) {
List banners = bannerMapper.selectListByStatus(status);
- return CommonResult.success(BannerConvert.INSTANCE.convertToBO(banners));
+ return BannerConvert.INSTANCE.convertToBO(banners);
}
@Override
- public CommonResult 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 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 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 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 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;
}
}