diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java new file mode 100644 index 000000000..2c57a4cee --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerService.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.module.market.service.banner; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityCreateReqVO; +import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityPageReqVO; +import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityUpdateReqVO; +import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; + +import javax.validation.Valid; +import java.util.Collection; +import java.util.List; + +/** + * 首页Banner Service 接口 + * + * @author xia + */ +public interface ActivityService { + + /** + * 创建促销活动 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createActivity(@Valid ActivityCreateReqVO createReqVO); + + /** + * 更新促销活动 + * + * @param updateReqVO 更新信息 + */ + void updateActivity(@Valid ActivityUpdateReqVO updateReqVO); + + /** + * 删除促销活动 + * + * @param id 编号 + */ + void deleteActivity(Long id); + + /** + * 获得促销活动 + * + * @param id 编号 + * @return 促销活动 + */ + ActivityDO getActivity(Long id); + + /** + * 获得促销活动列表 + * + * @param ids 编号 + * @return 促销活动列表 + */ + List getActivityList(Collection ids); + + /** + * 获得促销活动分页 + * + * @param pageReqVO 分页查询 + * @return 促销活动分页 + */ + PageResult getActivityPage(ActivityPageReqVO pageReqVO); + +} diff --git a/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java new file mode 100644 index 000000000..70157c817 --- /dev/null +++ b/yudao-module-mall/yudao-module-market-biz/src/main/java/cn/iocoder/yudao/module/market/service/banner/BannerServiceImpl.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.module.market.service.banner; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityCreateReqVO; +import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityPageReqVO; +import cn.iocoder.yudao.module.market.controller.admin.activity.vo.ActivityUpdateReqVO; +import cn.iocoder.yudao.module.market.convert.activity.ActivityConvert; +import cn.iocoder.yudao.module.market.dal.dataobject.activity.ActivityDO; +import cn.iocoder.yudao.module.market.dal.mysql.activity.ActivityMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collection; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.market.enums.ErrorCodeConstants.ACTIVITY_NOT_EXISTS; + +/** + * 首页banner 实现类 + * + * @author xia + */ +@Service +@Validated +public class ActivityServiceImpl implements ActivityService { + + @Resource + private ActivityMapper activityMapper; + + @Override + public Long createActivity(ActivityCreateReqVO createReqVO) { + // 插入 + ActivityDO activity = ActivityConvert.INSTANCE.convert(createReqVO); + activityMapper.insert(activity); + // 返回 + return activity.getId(); + } + + @Override + public void updateActivity(ActivityUpdateReqVO updateReqVO) { + // 校验存在 + this.validateActivityExists(updateReqVO.getId()); + // 更新 + ActivityDO updateObj = ActivityConvert.INSTANCE.convert(updateReqVO); + activityMapper.updateById(updateObj); + } + + @Override + public void deleteActivity(Long id) { + // 校验存在 + this.validateActivityExists(id); + // 删除 + activityMapper.deleteById(id); + } + + private void validateActivityExists(Long id) { + if (activityMapper.selectById(id) == null) { + throw exception(ACTIVITY_NOT_EXISTS); + } + } + + @Override + public ActivityDO getActivity(Long id) { + return activityMapper.selectById(id); + } + + @Override + public List getActivityList(Collection ids) { + return activityMapper.selectBatchIds(ids); + } + + @Override + public PageResult getActivityPage(ActivityPageReqVO pageReqVO) { + return activityMapper.selectPage(pageReqVO); + } + +}