1、修改了添加商品的代码模块,修改了三层审核和上传的图片存储格式的代码模块。

2、添加了上架查看上下架商品信息的代码模块。
This commit is contained in:
XinYi Song 2021-12-16 15:52:28 +08:00
parent 093db2928b
commit 9b472191ec
6 changed files with 170 additions and 38 deletions

View File

@ -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);
}
}

View File

@ -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<ProductEntity,Long> {
public interface ProductDao extends JpaRepository<ProductEntity,Long>, JpaSpecificationExecutor<ProductEntity> {
/**
* 根据商品名称查询商品信息
@ -15,4 +18,12 @@ public interface ProductDao extends JpaRepository<ProductEntity,Long> {
* @return
*/
ProductEntity findByProductName(String productName);
/**
* 商家查看商品信息
* @param businessId
* @param shelfType
* @return
*/
List<ProductEntity> findAllByBusinessIdAndAndShelfType(Integer businessId,String shelfType);
}

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -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);
}

View File

@ -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);
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");
productEntity.setProductTime(DateTimeUtil.dateTimeToString(LocalDateTime.now()));
List<ProductCoverEntity> coverEntities = new ArrayList<>();
for(String cover : productCover){
ProductCoverEntity productCoverEntity = new ProductCoverEntity();
productCoverEntity.setProductCoverPhoto(cover);
productCoverEntity.setProductId(productEntity.getId());
coverEntities.add(productCoverEntity);
}
productCoverDao.saveAll(coverEntities);
List<ProductContentPhotoEntity> 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<ProductEntity> productEntities = query.selectAllProduct(businessId, productCounty, shelfType);
if(productEntities == null || productEntities.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有任何商品信息!",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,productEntities,locale);
}
}

View File

@ -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<FirePointEntity> selectFirePointByMonthCounty(String proName, String countyCode,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
public List<ProductEntity> selectProductCounty(Integer businessId, String productCounty, String reviewType) {
Specification<ProductEntity> specification = new Specification<ProductEntity>() {
@Override
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public Predicate toPredicate(Root<ProductEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> 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<ProductEntity> selectAllProduct(Integer businessId, String productCounty, String shelfType) {
Specification<ProductEntity> specification = new Specification<ProductEntity>() {
@Override
public Predicate toPredicate(Root<ProductEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> 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);
}
}