From 9b472191ec49132b6bcb8bd649408a41874c2ebe Mon Sep 17 00:00:00 2001 From: XinYi Song <2037158277@qq.com> Date: Thu, 16 Dec 2021 15:52:28 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E4=BA=86=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=95=86=E5=93=81=E7=9A=84=E4=BB=A3=E7=A0=81=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=89=E5=B1=82?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E5=92=8C=E4=B8=8A=E4=BC=A0=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=AD=98=E5=82=A8=E6=A0=BC=E5=BC=8F=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A8=A1=E5=9D=97=E3=80=82=202=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=B8=8A=E6=9E=B6=E6=9F=A5=E7=9C=8B=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=9E=B6=E5=95=86=E5=93=81=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A8=A1=E5=9D=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/ProductController.java | 21 ++++++ src/main/java/com/xkrs/dao/ProductDao.java | 13 +++- .../com/xkrs/model/entity/ProductEntity.java | 48 +++++++++++++- .../java/com/xkrs/service/ProductService.java | 9 +++ .../xkrs/service/impl/ProductServiceImpl.java | 51 +++++++++----- src/main/java/com/xkrs/utils/Query.java | 66 ++++++++++++++----- 6 files changed, 170 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/xkrs/controller/ProductController.java b/src/main/java/com/xkrs/controller/ProductController.java index ce270f5..1beb4ac 100644 --- a/src/main/java/com/xkrs/controller/ProductController.java +++ b/src/main/java/com/xkrs/controller/ProductController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.Locale; +import java.util.Map; import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -48,4 +49,24 @@ public class ProductController { } return productService.addingProduct(productQo,sysUserEntity.getId(),sysUserEntity.getIdentity()); } + + /** + * 商家查看商品上下架的信息(0 待审核,1上架,2下架) + * @param map + * @param token + * @return + */ + @PostMapping("/selectProductShelfType") + public String selectProductShelfType(@RequestBody Map map, @RequestHeader(value="Authorization") String token){ + Locale locale = LocaleContextHolder.getLocale(); + String productCounty = (String) map.get("productCounty"); + String shelfType = (String) map.get("shelfType"); + // 验证token + String tokenUserName = TokenUtil.getTokenUserName(token); + SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName); + if(sysUserEntity == null){ + return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale); + } + return productService.selectProductShelfType(sysUserEntity.getId(),productCounty,shelfType); + } } diff --git a/src/main/java/com/xkrs/dao/ProductDao.java b/src/main/java/com/xkrs/dao/ProductDao.java index eff0fcd..d2589c4 100644 --- a/src/main/java/com/xkrs/dao/ProductDao.java +++ b/src/main/java/com/xkrs/dao/ProductDao.java @@ -2,12 +2,15 @@ package com.xkrs.dao; import com.xkrs.model.entity.ProductEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +import java.util.List; /** * @Author: XinYi Song * @Date: 2021/12/15 15:21 */ -public interface ProductDao extends JpaRepository { +public interface ProductDao extends JpaRepository, JpaSpecificationExecutor { /** * 根据商品名称查询商品信息 @@ -15,4 +18,12 @@ public interface ProductDao extends JpaRepository { * @return */ ProductEntity findByProductName(String productName); + + /** + * 商家查看商品信息 + * @param businessId + * @param shelfType + * @return + */ + List findAllByBusinessIdAndAndShelfType(Integer businessId,String shelfType); } diff --git a/src/main/java/com/xkrs/model/entity/ProductEntity.java b/src/main/java/com/xkrs/model/entity/ProductEntity.java index fb677a0..d7289c3 100644 --- a/src/main/java/com/xkrs/model/entity/ProductEntity.java +++ b/src/main/java/com/xkrs/model/entity/ProductEntity.java @@ -79,16 +79,32 @@ public class ProductEntity { @Column(length = 32, columnDefinition = "varchar(32)") private String userIdentity; + /** + * 商品封面 + */ + private String productCover; + + /** + * 商品内容图片 + */ + private String productContent; + /** * 商品上架的时间 */ @Column(length = 65, columnDefinition = "varchar(65)") private String productTime; + /** + * 提交时间 + */ + @Column(length = 65, columnDefinition = "varchar(65)") + private String submitTime; + public ProductEntity() { } - public ProductEntity(Integer id, String productName, String productPro, String productCity, String productCounty, String productDescription, Integer productCategories, BigDecimal productPrice, String shelfType, String reviewType, Integer businessId, String userIdentity, String productTime) { + public ProductEntity(Integer id, String productName, String productPro, String productCity, String productCounty, String productDescription, Integer productCategories, BigDecimal productPrice, String shelfType, String reviewType, Integer businessId, String userIdentity, String productCover, String productContent, String productTime, String submitTime) { this.id = id; this.productName = productName; this.productPro = productPro; @@ -101,7 +117,10 @@ public class ProductEntity { this.reviewType = reviewType; this.businessId = businessId; this.userIdentity = userIdentity; + this.productCover = productCover; + this.productContent = productContent; this.productTime = productTime; + this.submitTime = submitTime; } public Integer getId() { @@ -200,6 +219,22 @@ public class ProductEntity { this.userIdentity = userIdentity; } + public String getProductCover() { + return productCover; + } + + public void setProductCover(String productCover) { + this.productCover = productCover; + } + + public String getProductContent() { + return productContent; + } + + public void setProductContent(String productContent) { + this.productContent = productContent; + } + public String getProductTime() { return productTime; } @@ -208,6 +243,14 @@ public class ProductEntity { this.productTime = productTime; } + public String getSubmitTime() { + return submitTime; + } + + public void setSubmitTime(String submitTime) { + this.submitTime = submitTime; + } + @Override public String toString() { return "ProductEntity{" + @@ -223,7 +266,10 @@ public class ProductEntity { ", reviewType='" + reviewType + '\'' + ", businessId=" + businessId + ", userIdentity='" + userIdentity + '\'' + + ", productCover='" + productCover + '\'' + + ", productContent='" + productContent + '\'' + ", productTime='" + productTime + '\'' + + ", submitTime='" + submitTime + '\'' + '}'; } } diff --git a/src/main/java/com/xkrs/service/ProductService.java b/src/main/java/com/xkrs/service/ProductService.java index 618d0c7..7c5c61d 100644 --- a/src/main/java/com/xkrs/service/ProductService.java +++ b/src/main/java/com/xkrs/service/ProductService.java @@ -17,4 +17,13 @@ public interface ProductService { * @return */ String addingProduct(ProductQo productQo,Integer business, String userIdentity); + + /** + * 商家查看上下架商品的信息 + * @param businessId + * @param productCounty + * @param shelfType + * @return + */ + String selectProductShelfType(Integer businessId, String productCounty, String shelfType); } diff --git a/src/main/java/com/xkrs/service/impl/ProductServiceImpl.java b/src/main/java/com/xkrs/service/impl/ProductServiceImpl.java index dd81e48..0a230e7 100644 --- a/src/main/java/com/xkrs/service/impl/ProductServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/ProductServiceImpl.java @@ -12,6 +12,7 @@ import com.xkrs.model.entity.ProductEntity; import com.xkrs.model.qo.ProductQo; import com.xkrs.service.ProductService; import com.xkrs.utils.DateTimeUtil; +import com.xkrs.utils.Query; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; @@ -42,6 +43,9 @@ public class ProductServiceImpl implements ProductService { @Resource private ProductContentPhotoDao productContentPhotoDao; + @Resource + private Query query; + /** * 添加商品信息 * @param productQo 商品信息 @@ -77,29 +81,40 @@ public class ProductServiceImpl implements ProductService { productEntity.setBusinessId(business); productEntity.setShelfType("0"); productEntity.setUserIdentity(userIdentity); - productEntity.setReviewType("0"); - productEntity.setProductTime(DateTimeUtil.dateTimeToString(LocalDateTime.now())); - - List coverEntities = new ArrayList<>(); - for(String cover : productCover){ - ProductCoverEntity productCoverEntity = new ProductCoverEntity(); - productCoverEntity.setProductCoverPhoto(cover); - productCoverEntity.setProductId(productEntity.getId()); - coverEntities.add(productCoverEntity); + if("affiliate_merchant".equals(userIdentity)){ + productEntity.setReviewType("0"); + }else if("county".equals(userIdentity)){ + productEntity.setReviewType("1"); + }else if("city".equals(userIdentity)){ + productEntity.setReviewType("2"); + }else { + productEntity.setReviewType("0"); } - productCoverDao.saveAll(coverEntities); - List contentPhotoEntities = new ArrayList<>(); - for(String content : productContent){ - ProductContentPhotoEntity productContentPhotoEntity = new ProductContentPhotoEntity(); - productContentPhotoEntity.setProductContentPhoto(content); - productContentPhotoEntity.setProductId(productEntity.getId()); - contentPhotoEntities.add(productContentPhotoEntity); - } - productContentPhotoDao.saveAll(contentPhotoEntities); + productEntity.setSubmitTime(DateTimeUtil.dateTimeToString(LocalDateTime.now())); + + productEntity.setProductCover(productCover.toString()); + productEntity.setProductContent(productContent.toString()); productDao.save(productEntity); return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"商品添加成功!",locale); } + + /**\ + * 商家查看商品上下架的信息 + * @param businessId + * @param productCounty + * @param shelfType + * @return + */ + @Override + public String selectProductShelfType(Integer businessId, String productCounty, String shelfType) { + Locale locale = LocaleContextHolder.getLocale(); + List productEntities = query.selectAllProduct(businessId, productCounty, shelfType); + if(productEntities == null || productEntities.size() == 0){ + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有任何商品信息!",locale); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,productEntities,locale); + } } diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index 344b7b8..d6fb54b 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -1,5 +1,7 @@ package com.xkrs.utils; +import com.xkrs.dao.ProductDao; +import com.xkrs.model.entity.ProductEntity; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; @@ -19,36 +21,64 @@ import java.util.List; @Component public class Query { + @Resource + private ProductDao productDao; + /** - * 查询近一个月的火点信息(县) - * @param countyCode - * @param startTime - * @param endTime + * 查看要审核的商品信息 + * @param businessId + * @param productCounty + * @param reviewType * @return */ - /*public List selectFirePointByMonthCounty(String proName, String countyCode,String startTime,String endTime) { - Specification specification = new Specification() { + public List selectProductCounty(Integer businessId, String productCounty, String reviewType) { + Specification specification = new Specification() { @Override - public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { List list = new ArrayList<>(); - if(countyCode != null && !"".equals(countyCode)){ - list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), countyCode)); + if(businessId != null){ + list.add(criteriaBuilder.equal(root.get("businessId").as(Integer.class), businessId)); } - if(startTime != null && !"".equals(startTime)){ - list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("satelliteTime").as(String.class), startTime)); + if(productCounty != null && !"".equals(productCounty)){ + list.add(criteriaBuilder.equal(root.get("productCounty").as(String.class), productCounty)); } - if(endTime != null && !"".equals(endTime)){ - list.add(criteriaBuilder.lessThanOrEqualTo(root.get("satelliteTime").as(String.class), endTime)); - } - if(proName.equals("山东省")){ - list.add(criteriaBuilder.notEqual(root.get("landType").as(String.class), "耕地")); + if(reviewType != null && !"".equals(reviewType)){ + list.add(criteriaBuilder.equal(root.get("reviewType").as(String.class), reviewType)); } Predicate[] predicates = new Predicate[list.size()]; return criteriaBuilder.and(list.toArray(predicates)); } }; - return firePointDao.findAll(specification); - }*/ + return productDao.findAll(specification); + } + + /** + * 查看商品信息 + * @param businessId + * @param productCounty + * @param shelfType + * @return + */ + public List selectAllProduct(Integer businessId, String productCounty, String shelfType) { + Specification specification = new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + List list = new ArrayList<>(); + if(businessId != null){ + list.add(criteriaBuilder.equal(root.get("businessId").as(Integer.class), businessId)); + } + if(productCounty != null && !"".equals(productCounty)){ + list.add(criteriaBuilder.equal(root.get("productCounty").as(String.class), productCounty)); + } + if(shelfType != null && !"".equals(shelfType)){ + list.add(criteriaBuilder.equal(root.get("shelfType").as(String.class), shelfType)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + } + }; + return productDao.findAll(specification); + } } \ No newline at end of file