From ba3a85f2bf6dc706ba2f74e88e9d81197533f1b7 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期四, 24 十月 2024 18:30:12 +0800
Subject: [PATCH] 优化
---
server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 102 insertions(+), 2 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
index 9c42266..344e395 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -793,8 +793,8 @@
if(brand == null){
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧鍝佺墝鏃犳晥锛岃妫�鏌ヨ緭鍏ワ紒");
}
- if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){
- throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绗��"+(num)+"銆戣銆�"+m.getName()+"銆戝凡瀛樺湪");
+ if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"绗��"+(num)+"銆戣銆�"+m.getName()+"銆戝凡瀛樺湪");
}
Goods newModel = new Goods();
newModel.setRemark(m.getId());
@@ -928,6 +928,106 @@
return num;
}
+ @Transactional(rollbackFor = {Exception.class, BusinessException.class})
+ @Override
+ public Integer importBatchImg(MultipartFile file){
+ LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+ ExcelImporter ie = null;
+ List<GoodsImport> dataList =null;
+ try {
+ ie = new ExcelImporter(file,0,0);
+ dataList = ie.getDataList(GoodsImport.class,null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ if(dataList == null || dataList.size() ==0){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝褰曞叆鏁版嵁涓虹┖锛�");
+ }
+
+ int num =1;
+ for(GoodsImport m: dataList){
+ if( StringUtils.isBlank(m.getId()) ){
+ continue;
+ }
+ Goods g = new Goods();
+ g.setIsdeleted(Constants.ZERO);
+ g.setRemark(m.getId());
+ g.setCompanyId(user.getCompanyId());
+ //鍝佺被鏁版嵁
+ g = goodsMapper.selectOne(new QueryWrapper<>(g).last(" limit 1"));
+ if(g == null){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝绗��"+(num)+"銆戣鍟嗗搧涓嶅瓨鍦紝璇锋鏌ヨ緭鍏ワ紒");
+ }
+
+ Goods newModel = new Goods();
+ newModel.setId(g.getId());
+ newModel.setEditor(user.getId());
+ newModel.setEditDate(new Date());
+
+ String[] params = StringUtils.defaultString(m.getParamStr(),"").split("\n");
+ List<String> mulFiles = null;
+ String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
+
+ String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
+ + proDir + File.separator + user.getCompanyId();
+ if(StringUtils.isNotBlank(path)){
+ OssModel ossModel = baseDataService.initOssModel();
+ File dir =new File(path+File.separator+newModel.getRemark()+File.separator);
+ if(dir!=null && dir.isDirectory()){
+ File[] files = dir.listFiles();
+ if(files!=null && files.length>0){
+ for(File f:files){
+ if(StringUtils.isBlank(newModel.getImgurl()) && isImgFile(f)){
+ //鍙栫涓�寮犲浘鐗囦綔涓哄垪琛ㄥ浘
+ newModel.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
+ }
+ if((mulFiles ==null || mulFiles.size() == 0) && 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));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ //鏌ヨ鍟嗗搧淇℃伅
+ goodsMapper.updateById(newModel);
+ if(mulFiles !=null && mulFiles.size()>0){
+ multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda()
+ .set(Multifile::getIsdeleted,Constants.ONE)
+ .eq(Multifile::getIsdeleted,Constants.ZERO)
+ .eq(Multifile::getObjId,g.getId())
+ .eq(Multifile::getType,Constants.ZERO));
+ for(int i=0;i<mulFiles.size();i++){
+ String s = mulFiles.get(i);
+ Multifile f = new Multifile();
+ f.setObjType(Constants.ZERO);
+ f.setName(s);
+ f.setType(Constants.ZERO);
+ f.setObjId(newModel.getId());
+ f.setCreateDate(newModel.getCreateDate());
+ f.setCreator(newModel.getCreator());
+ f.setIsdeleted(Constants.ZERO);
+ f.setSortnum(i);
+ f.setCompanyId(user.getCompanyId());
+ f.setFileurl(s);
+ multifileMapper.insert(f);
+ }
+ }
+ num++;
+ }
+ return num;
+
+ }
--
Gitblit v1.9.3