From 877daeb6fd2b159f1627b0d6117f3156e34123a0 Mon Sep 17 00:00:00 2001 From: xuwenbo <717567226@qq.com> Date: Thu, 3 Sep 2020 13:06:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B6=B3=E8=BF=B9=EF=BC=8C?= =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=90=8E=E7=AB=AF=E7=AE=A1=E7=90=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YxStoreProductRelationService.java | 28 +++++- .../dto/YxStoreProductRelationDto.java | 54 ++++++++++++ .../YxStoreProductRelationQueryCriteria.java | 23 +++++ .../YxStoreProductRelationServiceImpl.java | 57 ++++++++++++- .../YxStoreProductRelationController.java | 85 +++++++++++++++++++ 5 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationDto.java create mode 100644 yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationQueryCriteria.java create mode 100644 yshop-shop/src/main/java/co/yixiang/modules/shop/rest/YxStoreProductRelationController.java diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductRelationService.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductRelationService.java index 4ce03dfc..8638f14d 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductRelationService.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/YxStoreProductRelationService.java @@ -10,9 +10,14 @@ package co.yixiang.modules.product.service; import co.yixiang.common.service.BaseService; +import co.yixiang.domain.PageResult; import co.yixiang.modules.product.domain.YxStoreProductRelation; +import co.yixiang.modules.product.service.dto.YxStoreProductRelationDto; +import co.yixiang.modules.product.service.dto.YxStoreProductRelationQueryCriteria; import co.yixiang.modules.product.vo.YxStoreProductRelationQueryVo; - +import javax.servlet.http.HttpServletResponse; +import org.springframework.data.domain.Pageable; +import java.io.IOException; import java.util.List; /** @@ -56,7 +61,28 @@ public interface YxStoreProductRelationService extends BaseService userCollectProduct(int page, int limit, Long uid,String type); + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + PageResult queryAll(YxStoreProductRelationQueryCriteria criteria, Pageable pageable); + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(YxStoreProductRelationQueryCriteria criteria); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; } diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationDto.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationDto.java new file mode 100644 index 00000000..860235db --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationDto.java @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2018-2020 + * All rights reserved, Designed By www.yixiang.co + * 注意: + * 本软件为www.yixiang.co开发研制,未经购买不得使用 + * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) + * 一经发现盗用、分享等行为,将追究法律责任,后果自负 + */ +package co.yixiang.modules.product.service.dto; + +import co.yixiang.modules.product.domain.YxStoreProduct; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.sql.Timestamp; +import java.io.Serializable; + +/** + * @author hupeng + * @date 2020-09-03 + */ +@Data +public class YxStoreProductRelationDto implements Serializable { + + private Long id; + + /** 用户ID */ + private Long uid; + + private String userName; + + /** 商品ID */ + private Long productId; + + private YxStoreProduct product; + + /** 类型(收藏(collect)、点赞(like)) */ + private String type; + + /** 某种类型的商品(普通商品、秒杀商品) */ + private String category; + + /** 添加时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Timestamp createTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Timestamp updateTime; + + private Integer isDel; +} + diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationQueryCriteria.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationQueryCriteria.java new file mode 100644 index 00000000..29bd2527 --- /dev/null +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/dto/YxStoreProductRelationQueryCriteria.java @@ -0,0 +1,23 @@ +/** + * Copyright (C) 2018-2020 + * All rights reserved, Designed By www.yixiang.co + * 注意: + * 本软件为www.yixiang.co开发研制,未经购买不得使用 + * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) + * 一经发现盗用、分享等行为,将追究法律责任,后果自负 + */ +package co.yixiang.modules.product.service.dto; + +import lombok.Data; +import java.util.List; +import co.yixiang.annotation.Query; + +/** + * @author hupeng + * @date 2020-09-03 + */ +@Data +public class YxStoreProductRelationQueryCriteria{ + @Query(type = Query.Type.EQUAL) + private String type; +} diff --git a/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductRelationServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductRelationServiceImpl.java index c171f878..40b5121e 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductRelationServiceImpl.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductRelationServiceImpl.java @@ -10,18 +10,33 @@ package co.yixiang.modules.product.service.impl; import co.yixiang.api.YshopException; import co.yixiang.common.service.impl.BaseServiceImpl; +import co.yixiang.common.utils.QueryHelpPlus; +import co.yixiang.domain.PageResult; +import co.yixiang.dozer.service.IGenerator; import co.yixiang.modules.product.domain.YxStoreProductRelation; import co.yixiang.modules.product.service.YxStoreProductRelationService; +import co.yixiang.modules.product.service.YxStoreProductService; +import co.yixiang.modules.product.service.dto.YxStoreProductRelationDto; +import co.yixiang.modules.product.service.dto.YxStoreProductRelationQueryCriteria; import co.yixiang.modules.product.service.mapper.YxStoreProductRelationMapper; import co.yixiang.modules.product.vo.YxStoreProductRelationQueryVo; +import co.yixiang.modules.user.service.YxUserService; +import co.yixiang.utils.FileUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.pagehelper.PageInfo; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletResponse; +import org.springframework.data.domain.Pageable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; /** @@ -39,7 +54,9 @@ import java.util.List; public class YxStoreProductRelationServiceImpl extends BaseServiceImpl implements YxStoreProductRelationService { private final YxStoreProductRelationMapper yxStoreProductRelationMapper; - + private final YxStoreProductService storeProductService; + private final YxUserService userService; + private final IGenerator generator; /** * 获取用户收藏列表 @@ -113,4 +130,42 @@ public class YxStoreProductRelationServiceImpl extends BaseServiceImpl queryAll(YxStoreProductRelationQueryCriteria criteria, Pageable pageable) { + getPage(pageable); + PageInfo page = new PageInfo<>(queryAll(criteria)); + PageResult relationDtoPageResult = generator.convertPageInfo(page, YxStoreProductRelationDto.class); + relationDtoPageResult.getContent().forEach(i ->{ + i.setProduct(storeProductService.getById(i.getProductId())); + i.setUserName(userService.getYxUserById(i.getUid()).getUsername()); + }); + return relationDtoPageResult; + } + + + @Override + //@Cacheable + public List queryAll(YxStoreProductRelationQueryCriteria criteria){ + return baseMapper.selectList(QueryHelpPlus.getPredicate(YxStoreProductRelation.class, criteria)); + } + + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (YxStoreProductRelationDto yxStoreProductRelation : all) { + Map map = new LinkedHashMap<>(); + map.put("用户ID", yxStoreProductRelation.getUid()); + map.put("商品ID", yxStoreProductRelation.getProductId()); + map.put("类型(收藏(collect)、点赞(like))", yxStoreProductRelation.getType()); + map.put("某种类型的商品(普通商品、秒杀商品)", yxStoreProductRelation.getCategory()); + map.put("添加时间", yxStoreProductRelation.getCreateTime()); + map.put(" updateTime", yxStoreProductRelation.getUpdateTime()); + map.put(" isDel", yxStoreProductRelation.getIsDel()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } } diff --git a/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/YxStoreProductRelationController.java b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/YxStoreProductRelationController.java new file mode 100644 index 00000000..75ded263 --- /dev/null +++ b/yshop-shop/src/main/java/co/yixiang/modules/shop/rest/YxStoreProductRelationController.java @@ -0,0 +1,85 @@ +/** + * Copyright (C) 2018-2020 + * All rights reserved, Designed By www.yixiang.co + * 注意: + * 本软件为www.yixiang.co开发研制,未经购买不得使用 + * 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台) + * 一经发现盗用、分享等行为,将追究法律责任,后果自负 + */ +package co.yixiang.modules.shop.rest; +import java.util.Arrays; +import co.yixiang.dozer.service.IGenerator; +import lombok.AllArgsConstructor; +import co.yixiang.logging.aop.log.Log; +import co.yixiang.modules.product.domain.YxStoreProductRelation; +import co.yixiang.modules.product.service.YxStoreProductRelationService; +import co.yixiang.modules.product.service.dto.YxStoreProductRelationQueryCriteria; +import co.yixiang.modules.product.service.dto.YxStoreProductRelationDto; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import co.yixiang.domain.PageResult; +/** + * @author hupeng + * @date 2020-09-03 + */ +@AllArgsConstructor +@Api(tags = "ProductRelation管理") +@RestController +@RequestMapping("/api/yxStoreProductRelation") +public class YxStoreProductRelationController { + + private final YxStoreProductRelationService yxStoreProductRelationService; + private final IGenerator generator; + + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('admin','yxStoreProductRelation:list')") + public void download(HttpServletResponse response, YxStoreProductRelationQueryCriteria criteria) throws IOException { + yxStoreProductRelationService.download(generator.convert(yxStoreProductRelationService.queryAll(criteria), YxStoreProductRelationDto.class), response); + } + + @GetMapping + @Log("查询ProductRelation") + @ApiOperation("查询ProductRelation") + @PreAuthorize("@el.check('admin','yxStoreProductRelation:list')") + public ResponseEntity> getYxStoreProductRelations(YxStoreProductRelationQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(yxStoreProductRelationService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增ProductRelation") + @ApiOperation("新增ProductRelation") + @PreAuthorize("@el.check('admin','yxStoreProductRelation:add')") + public ResponseEntity create(@Validated @RequestBody YxStoreProductRelation resources){ + return new ResponseEntity<>(yxStoreProductRelationService.save(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改ProductRelation") + @ApiOperation("修改ProductRelation") + @PreAuthorize("@el.check('admin','yxStoreProductRelation:edit')") + public ResponseEntity update(@Validated @RequestBody YxStoreProductRelation resources){ + yxStoreProductRelationService.updateById(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除ProductRelation") + @ApiOperation("删除ProductRelation") + @PreAuthorize("@el.check('admin','yxStoreProductRelation:del')") + @DeleteMapping + public ResponseEntity deleteAll(@RequestBody Long[] ids) { + Arrays.asList(ids).forEach(id->{ + yxStoreProductRelationService.removeById(id); + }); + return new ResponseEntity<>(HttpStatus.OK); + } +}