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