添加了商家添加商品的功能模块
This commit is contained in:
parent
6655ed64c5
commit
48e73a708b
51
src/main/java/com/xkrs/controller/ProductController.java
Normal file
51
src/main/java/com/xkrs/controller/ProductController.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.common.tool.TokenUtil;
|
||||
import com.xkrs.dao.SysUserDao;
|
||||
import com.xkrs.model.entity.SysUserEntity;
|
||||
import com.xkrs.model.qo.ProductQo;
|
||||
import com.xkrs.service.ProductService;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 15:42
|
||||
*/
|
||||
@RestController
|
||||
public class ProductController {
|
||||
|
||||
@Resource
|
||||
private ProductService productService;
|
||||
|
||||
@Resource
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
/**
|
||||
* 添加商品信息
|
||||
* @param productQo
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/addingProduct")
|
||||
public String addingProduct(@RequestBody ProductQo productQo, @RequestHeader(value="Authorization") String token){
|
||||
// 获取区域信息
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 验证token
|
||||
String tokenUserName = TokenUtil.getTokenUserName(token);
|
||||
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
|
||||
if(sysUserEntity == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
|
||||
}
|
||||
return productService.addingProduct(productQo,sysUserEntity.getId());
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import com.xkrs.model.validation.ProductQoInsert;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
@ -34,6 +35,10 @@ public class ProductQo {
|
||||
@NotBlank(message = "{Product.productPrice.null}",groups={ProductQoInsert.class})
|
||||
private BigDecimal productPrice;
|
||||
|
||||
private List<String> productCover;
|
||||
|
||||
private List<String> productContent;
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
@ -65,4 +70,20 @@ public class ProductQo {
|
||||
public void setProductPrice(BigDecimal productPrice) {
|
||||
this.productPrice = productPrice;
|
||||
}
|
||||
|
||||
public List<String> getProductCover() {
|
||||
return productCover;
|
||||
}
|
||||
|
||||
public void setProductCover(List<String> productCover) {
|
||||
this.productCover = productCover;
|
||||
}
|
||||
|
||||
public List<String> getProductContent() {
|
||||
return productContent;
|
||||
}
|
||||
|
||||
public void setProductContent(List<String> productContent) {
|
||||
this.productContent = productContent;
|
||||
}
|
||||
}
|
||||
|
20
src/main/java/com/xkrs/service/ProductService.java
Normal file
20
src/main/java/com/xkrs/service/ProductService.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.xkrs.service;
|
||||
|
||||
import com.xkrs.model.qo.ProductQo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 15:38
|
||||
*/
|
||||
public interface ProductService {
|
||||
|
||||
/**
|
||||
* 添加商品信息
|
||||
* @param productQo 商品信息
|
||||
* @param business 商家用户id
|
||||
* @return
|
||||
*/
|
||||
String addingProduct(ProductQo productQo,Integer business);
|
||||
}
|
100
src/main/java/com/xkrs/service/impl/ProductServiceImpl.java
Normal file
100
src/main/java/com/xkrs/service/impl/ProductServiceImpl.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.xkrs.service.impl;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.dao.BusinessDao;
|
||||
import com.xkrs.dao.ProductContentPhotoDao;
|
||||
import com.xkrs.dao.ProductCoverDao;
|
||||
import com.xkrs.dao.ProductDao;
|
||||
import com.xkrs.model.entity.BusinessEntity;
|
||||
import com.xkrs.model.entity.ProductContentPhotoEntity;
|
||||
import com.xkrs.model.entity.ProductCoverEntity;
|
||||
import com.xkrs.model.entity.ProductEntity;
|
||||
import com.xkrs.model.qo.ProductQo;
|
||||
import com.xkrs.service.ProductService;
|
||||
import com.xkrs.utils.DateTimeUtil;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
/**
|
||||
* @Author: XinYi Song
|
||||
* @Date: 2021/12/15 15:38
|
||||
*/
|
||||
@Service
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@Resource
|
||||
private ProductDao productDao;
|
||||
|
||||
@Resource
|
||||
private BusinessDao businessDao;
|
||||
|
||||
@Resource
|
||||
private ProductCoverDao productCoverDao;
|
||||
|
||||
@Resource
|
||||
private ProductContentPhotoDao productContentPhotoDao;
|
||||
|
||||
/**
|
||||
* 添加商品信息
|
||||
* @param productQo 商品信息
|
||||
* @param business 商家用户id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String addingProduct(ProductQo productQo, Integer business) {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
// 商品封面图片
|
||||
List<String> productCover = productQo.getProductCover();
|
||||
// 商品内容图片
|
||||
List<String> productContent = productQo.getProductContent();
|
||||
BusinessEntity byBusinessId = businessDao.findByBusinessId(business);
|
||||
if(byBusinessId == null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"您还未入驻,请先入驻!",locale);
|
||||
}
|
||||
ProductEntity byProductName = productDao.findByProductName(productQo.getProductName());
|
||||
if(byProductName != null){
|
||||
return outputEncapsulationObject(PromptMessageEnum.FILE_EXISTS,"您已添加该商品,请勿重复添加!",locale);
|
||||
}
|
||||
if(productCover == null || productCover.size() == 0 || productContent == null || productContent.size() == 0){
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"商品封面或商品内容图片不能未空!",locale);
|
||||
}
|
||||
ProductEntity productEntity = new ProductEntity();
|
||||
productEntity.setProductName(productQo.getProductName());
|
||||
productEntity.setProductDescription(productQo.getProductDescription());
|
||||
productEntity.setProductCategories(productQo.getProductCategories());
|
||||
productEntity.setProductPrice(productQo.getProductPrice());
|
||||
productEntity.setBusinessId(business);
|
||||
productEntity.setShelfType("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);
|
||||
|
||||
productDao.save(productEntity);
|
||||
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"商品添加成功!",locale);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user