diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index 00e92bbfc..6dfbe3a12 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -87,7 +87,7 @@ public class AdminController { @ApiOperation(value = "管理员分页") @ApiImplicitParams({ @ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", example = "小王"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) public CommonResult page(@RequestParam(value = "nickname", required = false) String nickname, diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java index 2b2ca063c..a0494807b 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/RoleController.java @@ -38,7 +38,7 @@ public class RoleController { @ApiOperation(value = "角色分页") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "角色名,模糊匹配", required = true, example = "系统管理员"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) public CommonResult page(@RequestParam(value = "name", required = false) String name, diff --git a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java index d1e89acef..1a66f733e 100644 --- a/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java +++ b/admin/admin-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/AdminPageDTO.java @@ -4,6 +4,9 @@ import javax.validation.constraints.NotNull; public class AdminPageDTO { + /** + * 昵称,模糊匹配 + */ private String nickname; @NotNull(message = "页码不能为空") diff --git a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java index 1a3641226..7dca1ef26 100644 --- a/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java +++ b/admin/admin-service-impl/src/main/java/cn/iocoder/mall/admin/service/AdminServiceImpl.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -@Service("test") +@Service @com.alibaba.dubbo.config.annotation.Service(validation = "true") public class AdminServiceImpl implements AdminService { diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java index 6cea83c63..9139cfdc2 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/constant/CommonStatusEnum.java @@ -40,4 +40,12 @@ public enum CommonStatusEnum { return this; } + public static boolean isValid(Integer status) { + if (status == null) { + return false; + } + return ENABLE.value.equals(status) + || DISABLE.value.equals(status); + } + } \ No newline at end of file diff --git a/pom.xml b/pom.xml index b6880f12b..672bc88f4 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ admin ops pay + promotion pom diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java index d598b03dd..bcabd2db8 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/admins/AdminsProductSpuController.java @@ -107,7 +107,7 @@ public class AdminsProductSpuController { @ApiOperation("商品 SPU 分页列表") @ApiImplicitParams({ @ApiImplicitParam(name = "name", value = "商品名称,模糊匹配", example = "小王"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) public CommonResult spuPage(@RequestParam(value = "name", required = false) String name, diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java index d85819d7e..53f57d2fa 100644 --- a/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java +++ b/product/product-application/src/main/java/cn/iocoder/mall/product/application/controller/users/UsersProductSpuController.java @@ -36,7 +36,7 @@ public class UsersProductSpuController { @ApiOperation("商品 SPU 分页列表") @ApiImplicitParams({ @ApiImplicitParam(name = "cid", value = "分类编号", example = "1"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) public CommonResult page(@RequestParam(value = "cid", required = false) Integer cid, diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java index 1e4dc1755..8c305d682 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java @@ -20,6 +20,4 @@ public interface ProductCategoryMapper { int update(ProductCategoryDO productCategoryDO); - - } \ No newline at end of file diff --git a/promotion/pom.xml b/promotion/pom.xml new file mode 100644 index 000000000..36bb14ba5 --- /dev/null +++ b/promotion/pom.xml @@ -0,0 +1,20 @@ + + + + mall-parent + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + promotion + pom + + promotion-service-api + promotion-service-impl + promotion-application + + + \ No newline at end of file diff --git a/promotion/promotion-application/pom.xml b/promotion/promotion-application/pom.xml new file mode 100644 index 000000000..bc8ef85f5 --- /dev/null +++ b/promotion/promotion-application/pom.xml @@ -0,0 +1,141 @@ + + + + promotion + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + promotion-application + + + 1.3.0.Final + + + + + cn.iocoder.mall + promotion-service-api + 1.0-SNAPSHOT + + + cn.iocoder.mall + promotion-service-impl + 1.0-SNAPSHOT + + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alibaba + dubbo + 2.6.5 + + + + com.alibaba.boot + dubbo-spring-boot-starter + 0.2.1.RELEASE + + + + org.apache.curator + curator-framework + 2.12.0 + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + io.springfox + springfox-swagger2 + 2.9.2 + + + io.springfox + springfox-swagger-ui + 2.9.2 + + + + cn.iocoder.mall + user-service-api + 1.0-SNAPSHOT + compile + + + cn.iocoder.mall + user-sdk + 1.0-SNAPSHOT + compile + + + + cn.iocoder.mall + admin-sdk + 1.0-SNAPSHOT + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + + + \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java new file mode 100644 index 000000000..fd77f32e4 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/PromotionApplication.java @@ -0,0 +1,13 @@ +package cn.iocoder.mall.promotion.application; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"cn.iocoder.mall.promotion"}) +public class PromotionApplication { + + public static void main(String[] args) { + SpringApplication.run(PromotionApplication.class, args); + } + +} 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 new file mode 100644 index 000000000..6474ea705 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/MVCConfiguration.java @@ -0,0 +1,51 @@ +package cn.iocoder.mall.promotion.application.config; + +import cn.iocoder.common.framework.config.GlobalExceptionHandler; +import cn.iocoder.common.framework.servlet.CorsFilter; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@EnableWebMvc +@Configuration +@Import(value = {GlobalExceptionHandler.class, // 统一全局返回 +// AdminSecurityInterceptor.class +}) +public class MVCConfiguration implements WebMvcConfigurer { + +// @Autowired +// private UserSecurityInterceptor securityInterceptor; + +// @Autowired +// private AdminSecurityInterceptor adminSecurityInterceptor; +// @Autowired +// private AdminAccessLogInterceptor adminAccessLogInterceptor; +// + @Override + public void addInterceptors(InterceptorRegistry registry) { +// registry.addInterceptor(securityInterceptor).addPathPatterns("/user/**", "/admin/**"); // 只拦截我们定义的接口 +// registry.addInterceptor(adminAccessLogInterceptor).addPathPatterns("/admins/**"); +// registry.addInterceptor(adminSecurityInterceptor).addPathPatterns("/admins/**"); + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + // 解决 swagger-ui.html 的访问,参考自 https://stackoverflow.com/questions/43545540/swagger-ui-no-mapping-found-for-http-request 解决 + registry.addResourceHandler("swagger-ui.html**").addResourceLocations("classpath:/META-INF/resources/swagger-ui.html"); + registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + @Bean + public FilterRegistrationBean corsFilter() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + registrationBean.setFilter(new CorsFilter()); + registrationBean.addUrlPatterns("/*"); + return registrationBean; + } + +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/SwaggerConfiguration.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/SwaggerConfiguration.java new file mode 100644 index 000000000..7923969c5 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/config/SwaggerConfiguration.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.promotion.application.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 // TODO 生产环境时,禁用掉。 +public class SwaggerConfiguration { + + @Bean + public Docket createRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.promotion.application.controller")) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("营销子系统") + .description("营销子系统") + .termsOfServiceUrl("http://www.iocoder.cn") + .version("1.0.0") + .build(); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..f79e72131 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/controller/admins/AdminsBannerController.java @@ -0,0 +1,99 @@ +package cn.iocoder.mall.promotion.application.controller.admins; + +import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.sdk.context.AdminSecurityContextHolder; +import cn.iocoder.mall.promotion.api.BannerService; +import cn.iocoder.mall.promotion.api.bo.BannerPageBO; +import cn.iocoder.mall.promotion.api.dto.BannerAddDTO; +import cn.iocoder.mall.promotion.api.dto.BannerPageDTO; +import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; +import cn.iocoder.mall.promotion.application.convert.BannerConvert; +import cn.iocoder.mall.promotion.application.vo.BannerPageVO; +import cn.iocoder.mall.promotion.application.vo.BannerVO; +import com.alibaba.dubbo.config.annotation.Reference; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("admins/banner") +@Api("Banner 模块") +public class AdminsBannerController { + + @Reference(validation = "true") + private BannerService bannerService; + + @GetMapping("/page") + @ApiOperation(value = "Banner 分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = "title", value = "标题,模糊匹配", example = "活动 A"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), + @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), + }) + 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); + } + + @PostMapping("/add") + @ApiOperation(value = "创建 Banner") + @ApiImplicitParams({ + @ApiImplicitParam(name = "title", value = "标题", required = true, example = "活动A"), + @ApiImplicitParam(name = "url", value = "跳转链接", required = true, example = "http://www.iocoder.cn"), + @ApiImplicitParam(name = "picUrl", value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg"), + @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"), + @ApiImplicitParam(name = "memo", value = "备注", required = true, example = "活动很牛逼"), + }) + public CommonResult add(@RequestParam("title") String title, + @RequestParam("url") String url, + @RequestParam("picUrl") String picUrl, + @RequestParam("sort") Integer sort, + @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)); + } + + @PostMapping("/update") + @ApiOperation(value = "更新 Banner") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"), + @ApiImplicitParam(name = "url", value = "跳转链接", required = true, example = "http://www.iocoder.cn"), + @ApiImplicitParam(name = "picUrl", value = "图片链接", required = true, example = "http://www.iocoder.cn/01.jpg"), + @ApiImplicitParam(name = "sort", value = "排序", required = true, example = "10"), + @ApiImplicitParam(name = "memo", value = "备注", required = true, example = "活动很牛逼"), + }) + public CommonResult update(@RequestParam("id") Integer id, + @RequestParam("title") String title, + @RequestParam("url") String url, + @RequestParam("picUrl") String picUrl, + @RequestParam("sort") Integer sort, + @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); + } + + @PostMapping("/update_status") + @ApiOperation(value = "更新 Banner 状态") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "Banner 编号", required = true, example = "1"), + @ApiImplicitParam(name = "status", value = "状态。1 - 开启;2 - 禁用", required = true, example = "1"), + }) + public CommonResult updateStatus(@RequestParam("id") Integer id, + @RequestParam("status") Integer status) { + return 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); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..c6a69f11b --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/convert/BannerConvert.java @@ -0,0 +1,26 @@ +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.BannerPageVO; +import cn.iocoder.mall.promotion.application.vo.BannerVO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BannerConvert { + + BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class); + + @Mappings({}) + BannerVO convert(BannerBO bannerBO); + + @Mappings({}) + CommonResult convert2(CommonResult result); + + @Mappings({}) + CommonResult convert(CommonResult result); + +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/BannerPageVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/BannerPageVO.java new file mode 100644 index 000000000..5e3c70228 --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/BannerPageVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.promotion.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel("Banner 分页 VO") +public class BannerPageVO { + + @ApiModelProperty(value = "Banner 数组") + private List list; + @ApiModelProperty(value = "Banner 总数") + private Integer total; + + public List getList() { + return list; + } + + public BannerPageVO setList(List list) { + this.list = list; + return this; + } + + public Integer getTotal() { + return total; + } + + public BannerPageVO setTotal(Integer total) { + this.total = total; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/BannerVO.java b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/BannerVO.java new file mode 100644 index 000000000..3a5c3f35a --- /dev/null +++ b/promotion/promotion-application/src/main/java/cn/iocoder/mall/promotion/application/vo/BannerVO.java @@ -0,0 +1,99 @@ +package cn.iocoder.mall.promotion.application.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Date; + +@ApiModel("Banner VO") +public class BannerVO { + + @ApiModelProperty(value = "Banner 编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "标题", required = true, example = "活动 A") + private String title; + @ApiModelProperty(value = "跳转链接", required = true, example = "http://www.baidu.com") + private String url; + @ApiModelProperty(value = "突脸链接", required = true, example = "http://www.iocoder.cn/01.jpg") + private String picUrl; + @ApiModelProperty(value = "排序", required = true, example = "10") + private Integer sort; + @ApiModelProperty(value = "状态", required = true, example = "1") + private Integer status; + @ApiModelProperty(value = "备注", required = true, example = "这个活动很牛逼") + private String memo; + @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") + private Date createTime; + + public Integer getId() { + return id; + } + + public BannerVO setId(Integer id) { + this.id = id; + return this; + } + + public String getTitle() { + return title; + } + + public BannerVO setTitle(String title) { + this.title = title; + return this; + } + + public String getUrl() { + return url; + } + + public BannerVO setUrl(String url) { + this.url = url; + return this; + } + + public Integer getSort() { + return sort; + } + + public BannerVO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getStatus() { + return status; + } + + public BannerVO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getMemo() { + return memo; + } + + public BannerVO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public BannerVO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public BannerVO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } +} \ No newline at end of file diff --git a/promotion/promotion-application/src/main/resources/application.yaml b/promotion/promotion-application/src/main/resources/application.yaml new file mode 100644 index 000000000..3c095eebb --- /dev/null +++ b/promotion/promotion-application/src/main/resources/application.yaml @@ -0,0 +1,9 @@ +spring: + application: + name: promotion-application + +# server +server: + port: 18085 + servlet: + context-path: /promotion-api/ \ No newline at end of file diff --git a/promotion/promotion-service-api/pom.xml b/promotion/promotion-service-api/pom.xml new file mode 100644 index 000000000..d2b1af042 --- /dev/null +++ b/promotion/promotion-service-api/pom.xml @@ -0,0 +1,27 @@ + + + + promotion + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + promotion-service-api + + + + javax.validation + validation-api + + + cn.iocoder.mall + common-framework + 1.0-SNAPSHOT + compile + + + + \ No newline at end of file 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 new file mode 100644 index 000000000..c45b2b4a9 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/BannerService.java @@ -0,0 +1,22 @@ +package cn.iocoder.mall.promotion.api; + +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.api.dto.BannerAddDTO; +import cn.iocoder.mall.promotion.api.dto.BannerPageDTO; +import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; + +public interface BannerService { + + CommonResult getBannerPage(BannerPageDTO bannerPageDTO); + + CommonResult addBanner(Integer adminId, BannerAddDTO bannerAddDTO); + + CommonResult updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO); + + CommonResult updateBannerStatus(Integer adminId, Integer bannerId, Integer status); + + CommonResult deleteBanner(Integer adminId, Integer bannerId); + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/BannerBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/BannerBO.java new file mode 100644 index 000000000..db6b385b1 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/BannerBO.java @@ -0,0 +1,114 @@ +package cn.iocoder.mall.promotion.api.bo; + +import java.util.Date; + +/** + * Banner BO + */ +public class BannerBO { + + /** + * 编号 + */ + private Integer id; + /** + * 标题 + */ + private String title; + /** + * 跳转链接 + */ + private String url; + /** + * 图片链接 + */ + private String picUrl; + /** + * 排序 + */ + private Integer sort; + /** + * 状态 + */ + private Integer status; + /** + * 备注 + */ + private String memo; + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public BannerBO setId(Integer id) { + this.id = id; + return this; + } + + public String getTitle() { + return title; + } + + public BannerBO setTitle(String title) { + this.title = title; + return this; + } + + public String getUrl() { + return url; + } + + public BannerBO setUrl(String url) { + this.url = url; + return this; + } + + public Integer getSort() { + return sort; + } + + public BannerBO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public Integer getStatus() { + return status; + } + + public BannerBO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getMemo() { + return memo; + } + + public BannerBO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public BannerBO setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public BannerBO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/BannerPageBO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/BannerPageBO.java new file mode 100644 index 000000000..940f27dfa --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/bo/BannerPageBO.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.promotion.api.bo; + +import java.util.List; + +public class BannerPageBO { + + /** + * Banner 数组 + */ + private List list; + /** + * 总量 + */ + private Integer total; + + public List getList() { + return list; + } + + public BannerPageBO setList(List list) { + this.list = list; + return this; + } + + public Integer getTotal() { + return total; + } + + public BannerPageBO setTotal(Integer total) { + this.total = total; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java new file mode 100644 index 000000000..9f98a271e --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/constant/PromotionErrorCodeEnum.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.promotion.api.constant; + +/** + * 错误码枚举类 + * + * 营销系统,使用 1-006-000-000 段 + */ +public enum PromotionErrorCodeEnum { + + // ========== Banner 模块 ========== + BANNER_NOT_EXISTS(1002002000, "账号不存在"), + + ; + + private final int code; + private final String message; + + PromotionErrorCodeEnum(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public String getMessage() { + return message; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerAddDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerAddDTO.java new file mode 100644 index 000000000..d368014e3 --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerAddDTO.java @@ -0,0 +1,72 @@ +package cn.iocoder.mall.promotion.api.dto; + +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.URL; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * Banner 添加 DTO + */ +public class BannerAddDTO { + + @NotEmpty(message = "标题不能为空") + @Length(min = 6, max = 32, message = "标题长度为 6-32 位") + private String title; + @NotEmpty(message = "跳转链接不能为空") + @URL(message = "跳转链接格式不正确") + private String url; + @NotEmpty(message = "图片链接不能为空") + @URL(message = "图片链接格式不正确") + private String picUrl; + @NotNull(message = "排序不能为空") + private Integer sort; + @Length(max = 255, message = "备注最大长度为 255 位") + private String memo; + + public String getTitle() { + return title; + } + + public BannerAddDTO setTitle(String title) { + this.title = title; + return this; + } + + public String getUrl() { + return url; + } + + public BannerAddDTO setUrl(String url) { + this.url = url; + return this; + } + + public Integer getSort() { + return sort; + } + + public BannerAddDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public BannerAddDTO setMemo(String memo) { + this.memo = memo; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public BannerAddDTO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } +} diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerPageDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerPageDTO.java new file mode 100644 index 000000000..6b65b4efc --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerPageDTO.java @@ -0,0 +1,44 @@ +package cn.iocoder.mall.promotion.api.dto; + +import javax.validation.constraints.NotNull; + +public class BannerPageDTO { + + /** + * 标题,模糊匹配 + */ + private String title; + + @NotNull(message = "页码不能为空") + private Integer pageNo; + @NotNull(message = "每页条数不能为空") + private Integer pageSize; + + public Integer getPageNo() { + return pageNo; + } + + public BannerPageDTO setPageNo(Integer pageNo) { + this.pageNo = pageNo; + return this; + } + + public Integer getPageSize() { + return pageSize; + } + + public BannerPageDTO setPageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public String getTitle() { + return title; + } + + public BannerPageDTO setTitle(String title) { + this.title = title; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerUpdateDTO.java b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerUpdateDTO.java new file mode 100644 index 000000000..9f7d222ba --- /dev/null +++ b/promotion/promotion-service-api/src/main/java/cn/iocoder/mall/promotion/api/dto/BannerUpdateDTO.java @@ -0,0 +1,83 @@ +package cn.iocoder.mall.promotion.api.dto; + +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.URL; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * Banner 更新 DTO + */ +public class BannerUpdateDTO { + + @NotNull(message = "编号不能为空") + private Integer id; + @NotEmpty(message = "标题不能为空") + @Length(min = 6, max = 32, message = "标题长度为 6-32 位") + private String title; + @NotEmpty(message = "跳转链接不能为空") + @URL(message = "跳转链接格式不正确") + private String url; + @URL(message = "图片链接格式不正确") + private String picUrl; + @NotNull(message = "排序不能为空") + private Integer sort; + @Length(max = 255, message = "备注最大长度为 255 位") + private String memo; + + public Integer getId() { + return id; + } + + public BannerUpdateDTO setId(Integer id) { + this.id = id; + return this; + } + + public String getTitle() { + return title; + } + + public BannerUpdateDTO setTitle(String title) { + this.title = title; + return this; + } + + public String getUrl() { + return url; + } + + public BannerUpdateDTO setUrl(String url) { + this.url = url; + return this; + } + + public Integer getSort() { + return sort; + } + + public BannerUpdateDTO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getMemo() { + return memo; + } + + public BannerUpdateDTO setMemo(String memo) { + this.memo = memo; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public BannerUpdateDTO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/pom.xml b/promotion/promotion-service-impl/pom.xml new file mode 100644 index 000000000..f94262b13 --- /dev/null +++ b/promotion/promotion-service-impl/pom.xml @@ -0,0 +1,129 @@ + + + + promotion + cn.iocoder.mall + 1.0-SNAPSHOT + + 4.0.0 + + promotion-service-impl + + + + 1.3.0.Final + + + + + cn.iocoder.mall + promotion-service-api + 1.0-SNAPSHOT + + + cn.iocoder.mall + admin-service-api + 1.0-SNAPSHOT + compile + + + com.alibaba + dubbo + compile + + + com.google.guava + guava + 27.0.1-jre + + + + mysql + mysql-connector-java + + + org.springframework.boot + spring-boot-starter-jdbc + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.0.0 + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + com.google.guava + guava + 27.0.1-jre + + + + Pingplusplus + pingpp-java + 2.2.4 + jar + + + + com.xuxueli + xxl-job-core + 2.0.1 + + + + org.apache.rocketmq + rocketmq-spring-boot-starter + 2.0.1 + + + + + org.springframework.boot + spring-boot-starter-test + test + + + cn.iocoder.mall + user-sdk + 1.0-SNAPSHOT + compile + + + cn.iocoder.mall + product-service-api + 1.0-SNAPSHOT + compile + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/config/DatabaseConfiguration.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/config/DatabaseConfiguration.java new file mode 100644 index 000000000..82f158edd --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/config/DatabaseConfiguration.java @@ -0,0 +1,14 @@ +package cn.iocoder.mall.promotion.biz.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@MapperScan("cn.iocoder.mall.promotion.biz.dao") // 扫描对应的 Mapper 接口 +@EnableTransactionManagement(proxyTargetClass = true) // 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600 +public class DatabaseConfiguration { + + // 数据源,使用 HikariCP + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/config/ServiceExceptionConfiguration.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/config/ServiceExceptionConfiguration.java new file mode 100644 index 000000000..2931e04e5 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/config/ServiceExceptionConfiguration.java @@ -0,0 +1,26 @@ +package cn.iocoder.mall.promotion.biz.config; + +import cn.iocoder.common.framework.util.ServiceExceptionUtil; +import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.EventListener; + +@Configuration +public class ServiceExceptionConfiguration { + + @EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html + public void initMessages() { +// 从 service_exception_message.properties 加载错误码的方案 +// Properties properties; +// try { +// properties = PropertiesLoaderUtils.loadAllProperties("classpath:service_exception_message.properties"); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } + for (UserErrorCodeEnum item : UserErrorCodeEnum.values()) { + ServiceExceptionUtil.put(item.getCode(), item.getMessage()); + } + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/BannerConvert.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/BannerConvert.java new file mode 100644 index 000000000..39d7888b2 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/convert/BannerConvert.java @@ -0,0 +1,30 @@ +package cn.iocoder.mall.promotion.biz.convert; + +import cn.iocoder.mall.promotion.api.bo.BannerBO; +import cn.iocoder.mall.promotion.api.dto.BannerAddDTO; +import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; +import cn.iocoder.mall.promotion.biz.dataobject.BannerDO; +import org.mapstruct.Mapper; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface BannerConvert { + + BannerConvert INSTANCE = Mappers.getMapper(BannerConvert.class); + + @Mappings({}) + BannerBO convertToBO(BannerDO banner); + + @Mappings({}) + List convertToBO(List bannerList); + + @Mappings({}) + BannerDO convert(BannerAddDTO bannerAddDTO); + + @Mappings({}) + BannerDO convert(BannerUpdateDTO bannerUpdateDTO); + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/BannerMapper.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/BannerMapper.java new file mode 100644 index 000000000..9ce890f2f --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dao/BannerMapper.java @@ -0,0 +1,24 @@ +package cn.iocoder.mall.promotion.biz.dao; + +import cn.iocoder.mall.promotion.biz.dataobject.BannerDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface BannerMapper { + + BannerDO selectById(@Param("id") Integer id); + + List selectListByTitleLike(@Param("title") String title, + @Param("offset") Integer offset, + @Param("limit") Integer limit); + + Integer selectCountByTitleLike(@Param("title") String title); + + void insert(BannerDO bannerDO); + + int update(BannerDO bannerDO); + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/BannerDO.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/BannerDO.java new file mode 100644 index 000000000..60eafd035 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/dataobject/BannerDO.java @@ -0,0 +1,106 @@ +package cn.iocoder.mall.promotion.biz.dataobject; + +import cn.iocoder.common.framework.dataobject.DeletableDO; + +/** + * Banner 广告页 + */ +public class BannerDO extends DeletableDO { + + /** + * 编号 + */ + private Integer id; + /** + * 标题 + */ + private String title; + /** + * 跳转链接 + */ + private String url; + /** + * 图片链接 + */ + private String picUrl; + /** + * 排序 + */ + private Integer sort; + /** + * 状态 + * + * {@link cn.iocoder.common.framework.constant.CommonStatusEnum} + */ + private Integer status; + /** + * 备注 + */ + private String memo; + + // TODO 芋艿 点击次数。&& 其他数据相关 + + public Integer getId() { + return id; + } + + public BannerDO setId(Integer id) { + this.id = id; + return this; + } + + public String getTitle() { + return title; + } + + public BannerDO setTitle(String title) { + this.title = title; + return this; + } + + public String getUrl() { + return url; + } + + public BannerDO setUrl(String url) { + this.url = url; + return this; + } + + public Integer getStatus() { + return status; + } + + public BannerDO setStatus(Integer status) { + this.status = status; + return this; + } + + public String getMemo() { + return memo; + } + + public BannerDO setMemo(String memo) { + this.memo = memo; + return this; + } + + public Integer getSort() { + return sort; + } + + public BannerDO setSort(Integer sort) { + this.sort = sort; + return this; + } + + public String getPicUrl() { + return picUrl; + } + + public BannerDO setPicUrl(String picUrl) { + this.picUrl = picUrl; + return this; + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/package-info.java b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/package-info.java new file mode 100644 index 000000000..a52b7b5d9 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.mall.promotion.biz; \ 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 new file mode 100644 index 000000000..53c7933f7 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/java/cn/iocoder/mall/promotion/biz/service/BannerServiceImpl.java @@ -0,0 +1,92 @@ +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; +import cn.iocoder.mall.promotion.api.constant.PromotionErrorCodeEnum; +import cn.iocoder.mall.promotion.api.dto.BannerAddDTO; +import cn.iocoder.mall.promotion.api.dto.BannerPageDTO; +import cn.iocoder.mall.promotion.api.dto.BannerUpdateDTO; +import cn.iocoder.mall.promotion.biz.convert.BannerConvert; +import cn.iocoder.mall.promotion.biz.dao.BannerMapper; +import cn.iocoder.mall.promotion.biz.dataobject.BannerDO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + +@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示 +@com.alibaba.dubbo.config.annotation.Service(validation = "true") +public class BannerServiceImpl implements BannerService { + + @Autowired + private BannerMapper bannerMapper; + + @Override + public CommonResult getBannerPage(BannerPageDTO bannerPageDTO) { + BannerPageBO bannerPageBO = new BannerPageBO(); + // 查询分页数据 + int offset = (bannerPageDTO.getPageNo() - 1) * bannerPageDTO.getPageSize(); + bannerPageBO.setList(BannerConvert.INSTANCE.convertToBO(bannerMapper.selectListByTitleLike(bannerPageDTO.getTitle(), + offset, bannerPageDTO.getPageSize()))); + // 查询分页总数 + bannerPageBO.setTotal(bannerMapper.selectCountByTitleLike(bannerPageDTO.getTitle())); + return CommonResult.success(bannerPageBO); + } + + @Override + public CommonResult addBanner(Integer adminId, BannerAddDTO bannerAddDTO) { + // 保存到数据库 + BannerDO banner = BannerConvert.INSTANCE.convert(bannerAddDTO); + banner.setDeleted(DeletedStatusEnum.DELETED_NO.getValue()).setCreateTime(new Date()); + bannerMapper.insert(banner); + // 返回成功 + return CommonResult.success(BannerConvert.INSTANCE.convertToBO(banner)); + } + + @Override + public CommonResult updateBanner(Integer adminId, BannerUpdateDTO bannerUpdateDTO) { + // 校验 Banner 存在 + if (bannerMapper.selectById(bannerUpdateDTO.getId()) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode()); + } + // 更新到数据库 + BannerDO updateBanner = BannerConvert.INSTANCE.convert(bannerUpdateDTO); + bannerMapper.update(updateBanner); + // 返回成功 + return CommonResult.success(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 有点搓 + } + // 更新到数据库 + BannerDO updateBanner = new BannerDO().setId(bannerId).setStatus(status); + bannerMapper.update(updateBanner); + // 返回成功 + return CommonResult.success(true); + } + + @Override + public CommonResult deleteBanner(Integer adminId, Integer bannerId) { + // 校验 Banner 存在 + if (bannerMapper.selectById(bannerId) == null) { + return ServiceExceptionUtil.error(PromotionErrorCodeEnum.BANNER_NOT_EXISTS.getCode()); + } + // 更新到数据库 + BannerDO updateBanner = new BannerDO().setId(bannerId); + updateBanner.setDeleted(DeletedStatusEnum.DELETED_YES.getValue()); + bannerMapper.update(updateBanner); + // 返回成功 + return CommonResult.success(true); + } + +} \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/resources/config/application.yaml b/promotion/promotion-service-impl/src/main/resources/config/application.yaml new file mode 100644 index 000000000..a329d72bd --- /dev/null +++ b/promotion/promotion-service-impl/src/main/resources/config/application.yaml @@ -0,0 +1,30 @@ +spring: + # datasource + datasource: + url: jdbc:mysql://180.167.213.26:13306/mall_promotion?useSSL=false&useUnicode=true&characterEncoding=UTF-8 + driver-class-name: com.mysql.jdbc.Driver + username: root + password: ${MALL_MYSQL_PASSWORD} + +# mybatis +mybatis: + config-location: classpath:mybatis-config.xml + mapper-locations: classpath:mapper/*.xml + type-aliases-package: cn.iocoder.mall.promotion.biz.dataobject + +# dubbo +dubbo: + application: + name: promotion-service + registry: + address: zookeeper://127.0.0.1:2181 + protocol: + port: -1 + name: dubbo + scan: + base-packages: cn.iocoder.mall.promotion.biz.service + +# logging +logging: + level: + cn.iocoder.mall.promotion.dao: debug \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/resources/mapper/BannerMapper.xml b/promotion/promotion-service-impl/src/main/resources/mapper/BannerMapper.xml new file mode 100644 index 000000000..07adde196 --- /dev/null +++ b/promotion/promotion-service-impl/src/main/resources/mapper/BannerMapper.xml @@ -0,0 +1,98 @@ + + + + + + id, title, url, pic_url, sort, + status, memo, create_time + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO banner ( + title, url, pic_url, sort, status, + memo, create_time, deleted + ) VALUES ( + #{title}, #{url}, #{picUrl}, #{sort}, #{status}, + #{memo}, #{createTime}, #{deleted} + ) + + + + UPDATE banner + + + title = #{title}, + + + url = #{url}, + + + pic_url = #{picUrl} , + + + sort = #{sort}, + + + status = #{status}, + + + VALUES = #{VALUES}, + + + deleted = #{deleted} + + + WHERE id = #{id} + + + \ No newline at end of file diff --git a/promotion/promotion-service-impl/src/main/resources/mybatis-config.xml b/promotion/promotion-service-impl/src/main/resources/mybatis-config.xml new file mode 100644 index 000000000..7f604cc7e --- /dev/null +++ b/promotion/promotion-service-impl/src/main/resources/mybatis-config.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java index cf5a62d16..6ac5b0a5c 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/MVCConfiguration.java @@ -27,7 +27,6 @@ public class MVCConfiguration implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - // CORS // 用户 registry.addInterceptor(userAccessLogInterceptor).addPathPatterns("/users/**"); registry.addInterceptor(userSecurityInterceptor).addPathPatterns("/users/**"); // 只拦截我们定义的接口 @@ -42,15 +41,6 @@ public class MVCConfiguration implements WebMvcConfigurer { registry.addResourceHandler("webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } - // TODO 芋艿,允许跨域 -// @Override -// public void addCorsMappings(CorsRegistry registry) { -// registry.addMapping("/**") -// .allowedHeaders("*") -// .allowedMethods("*") -// .allowedOrigins("*"); -// } - @Bean public FilterRegistrationBean corsFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/SwaggerConfiguration.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/SwaggerConfiguration.java index e6987ada3..d68e15763 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/SwaggerConfiguration.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/config/SwaggerConfiguration.java @@ -19,7 +19,7 @@ public class SwaggerConfiguration { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() - .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.user.controller")) + .apis(RequestHandlerSelectors.basePackage("cn.iocoder.mall.user.application.controller")) .paths(PathSelectors.any()) .build(); } diff --git a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java index c692cc263..ecc8f2ad7 100644 --- a/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java +++ b/user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/admins/AdminsUserController.java @@ -27,7 +27,7 @@ public class AdminsUserController { @ApiOperation(value = "用户分页") @ApiImplicitParams({ @ApiImplicitParam(name = "nickname", value = "昵称,模糊匹配", example = "小王"), - @ApiImplicitParam(name = "pageNo", value = "页码,从 0 开始", example = "0"), + @ApiImplicitParam(name = "pageNo", value = "页码,从 1 开始", example = "1"), @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, example = "10"), }) public CommonResult page(@RequestParam(value = "nickname", required = false) String nickname,