From 2a8241df4493a36b046855f2283b1c3da9e6bfbe Mon Sep 17 00:00:00 2001
From: jiaosong <jiaosong6760@dingtalk.com>
Date: 星期一, 18 九月 2023 18:37:36 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev
---
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 100 insertions(+), 17 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
index 562835a..f0f4f19 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
@@ -13,10 +13,8 @@
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.BaseGoodsJoinMapper;
import com.doumee.dao.business.model.*;
-import com.doumee.dao.business.model.dto.BaseGoodsCreateOrUpdateRequest;
-import com.doumee.dao.business.model.dto.BaseGoodsDTO;
-import com.doumee.dao.business.model.dto.BaseGoodsImportDTO;
-import com.doumee.dao.business.model.dto.BaseGoodsParamCreatRequest;
+import com.doumee.dao.business.model.dto.*;
+import com.doumee.service.business.BaseDataService;
import com.doumee.service.business.BaseGoodsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -33,10 +31,9 @@
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -74,6 +71,11 @@
@Autowired
private BaseCategoryMapper baseCategoryMapper;
+
+
+ @Autowired
+ @Lazy
+ private BaseDataService baseDataService;
@Override
@@ -305,8 +307,8 @@
.eq(BaseGoods::getId,id);
BaseGoodsDTO baseGoodsDTO = baseGoodsJoinMapper.selectJoinOne(BaseGoodsDTO.class, queryWrapper);
- String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
- + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
+ String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
+ + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
baseGoodsDTO.setImgfullurl(prefixUrl+baseGoodsDTO.getImgurl());
List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>()
@@ -374,7 +376,7 @@
return baseGoodsMapper.selectCount(wrapper);
}
-
+ @Transactional(rollbackFor = {Exception.class,BusinessException.class})
@Override
public Integer importBaseGoodsBatch(MultipartFile file) {
@@ -406,6 +408,10 @@
dataList.forEach(s->{
+ if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",s.getName()))>0){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+s.getName()+"銆戝凡瀛樺湪");
+ }
+
BaseGoods baseGoods = new BaseGoods();
baseGoods.setCreator(user.getId());
baseGoods.setCreateDate(new Date());
@@ -414,7 +420,8 @@
baseGoods.setIsdeleted(Constants.ZERO);
baseGoods.setName(s.getName());
baseGoods.setStatus(Constants.ZERO);
-
+ baseGoods.setZdPrice(new BigDecimal(s.getZdPrice()));
+ baseGoods.setPrice(new BigDecimal(s.getPrice()));
if (StringUtils.isBlank(s.getCategoryName())){
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧绫诲埆涓嶅彲涓虹┖");
}
@@ -422,26 +429,87 @@
categoryQuery.lambda()
.eq(BaseCategory::getName,s.getCategoryName());
BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery);
-
+ if (Objects.isNull(baseCategory)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧绫诲埆涓嶅瓨鍦�");
+ }
QueryWrapper<Brand> brandQuery = new QueryWrapper<>();
brandQuery.lambda()
.eq(Brand::getName,s.getBrandName());
Brand brand = brandMapper.selectOne(brandQuery);
+ if (Objects.isNull(brand)){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鍝佺墝涓嶅瓨鍦�");
+ }
+ //澶勭悊鎵归噺涓婁紶
+ String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode();
+
+ String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
+ + proDir + File.separator + s.getId();
+
+ List<String> mulFiles = new ArrayList<>();
+ if(StringUtils.isNotBlank(path)){
+ OssModel ossModel = baseDataService.initOssModel();
+ File dir =new File(path+File.separator);
+ if(dir!=null && dir.isDirectory()){
+ File[] files = dir.listFiles();
+ if(files!=null && files.length>0){
+ for(File f:files){
+ if(isImgFile(f)){
+ //鍙栫涓�寮犲浘鐗囦綔涓哄垪琛ㄥ浘
+ baseGoods.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
+ }
+ if(f.isDirectory()){
+ //濡傛灉鏄枃浠跺す
+ File[] fs = f.listFiles();
+ if(fs != null && fs.length > 0){
+ for(File mf : fs){
+ if(isImgFile(mf)){
+ if(mulFiles==null){
+ mulFiles = new ArrayList<>();
+ }
+ mulFiles.add(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),mf));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
// baseGoods.setImgurl();
baseGoods.setCategoryId(baseCategory.getId());
baseGoods.setBrandId(brand.getId());
baseGoodsMapper.insert(baseGoods);
+ if(mulFiles !=null && mulFiles.size()>0){
+ for(int i=0;i<mulFiles.size();i++){
+ String str = mulFiles.get(i);
+ Multifile f = new Multifile();
+ f.setObjType(Constants.ZERO);
+ f.setName(str);
+ f.setType(Constants.ZERO);
+ f.setObjId(baseGoods.getId());
+ f.setCreateDate(new Date());
+ f.setCreator(user.getId());
+ f.setIsdeleted(Constants.ZERO);
+ f.setSortnum(i);
+ f.setCompanyId(user.getCompanyId());
+ f.setFileurl(str);
+ multifileMapper.insert(f);
+ }
+ }
+
String baseGoodsParamString = s.getBaseGoodsParamString();
List<List<String>> collect = Arrays.asList(baseGoodsParamString.split("\n"))
.stream().map(s1 -> Arrays.asList(s1.split("[锛�,:]")) ).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(collect)){
- Integer i = 0;
- collect.forEach(s2->{
+// Integer i = 0;
+ for (int i = 0; i < collect.size(); i++){
if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){
-
+ List<String> s2 = collect.get(i);
BaseCateParam baseCateParam = baseCategory.getBaseCateParamList()
.stream().filter(s3 -> s3.getName().equals(s2.get(0))).findFirst()
.orElseThrow(()->new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"閰嶇疆鍙傛暟涓嶅瓨鍦�"));
@@ -461,7 +529,7 @@
baseGoodsParamMapper.insert(baseGoodsParam);
}
- });
+ };
}
@@ -474,4 +542,19 @@
}
return null;
}
+
+ private boolean isImgFile(File f) {
+ if(f!=null && f.isFile() ){
+ String name = f.getName();
+ if(name.endsWith(".jpg")
+ ||name.endsWith(".JPG")
+ ||name.endsWith(".JPEG")
+ ||name.endsWith(".jpeg")
+ ||name.endsWith(".PNG")
+ ||name.endsWith(".png")){
+ return true;
+ }
+ }
+ return false;
+ }
}
--
Gitblit v1.9.3