|  |  |  | 
|---|
|  |  |  | private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model,List<Multifile> fileList ) { | 
|---|
|  |  |  | Multifile f = new Multifile(); | 
|---|
|  |  |  | f.setObjId(model.getId()); | 
|---|
|  |  |  | f.setObjType(Constants.ONE); | 
|---|
|  |  |  | f.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | f.setObjType(Constants.ONE); | 
|---|
|  |  |  | List<Multifile> multifileList =multifileMapper.selectList(new QueryWrapper<>(f)); | 
|---|
|  |  |  | if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ | 
|---|
|  |  |  | for (int i = 0; i < multifileList.size(); i++) { | 
|---|
|  |  |  | 
|---|
|  |  |  | if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ | 
|---|
|  |  |  | for (int i = 0; i < multifileList.size(); i++) { | 
|---|
|  |  |  | Multifile multifile = multifileList.get(i); | 
|---|
|  |  |  | if(StringUtils.isBlank(multifile.getFileurl())){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | multifile.setCreator(user.getId()); | 
|---|
|  |  |  | multifile.setCreateDate(new Date()); | 
|---|
|  |  |  | multifile.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | if(!Objects.isNull(category)){ | 
|---|
|  |  |  | goods.setCategoryName(category.getName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",id))); | 
|---|
|  |  |  | goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_TYPE",Constants.ZERO).eq("OBJ_ID",id))); | 
|---|
|  |  |  | return goods; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | Goods::getPrice,goods.getSPrice(),goods.getEPrice()); | 
|---|
|  |  |  | queryWrapper.orderByDesc(Goods::getId); | 
|---|
|  |  |  | List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper); | 
|---|
|  |  |  | this.dealGoodsMsg(goodsList); | 
|---|
|  |  |  | if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){ | 
|---|
|  |  |  | this.dealGoodsMsg(goodsList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return goodsList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
|---|
|  |  |  | goodsIPage.getRecords().forEach(i->{ | 
|---|
|  |  |  | i.setPrefixUrl(prefixUrl); | 
|---|
|  |  |  | if(i.getType().equals(Constants.ONE)){ | 
|---|
|  |  |  | i.setBasePrice(Constants.formatBigdecimal(i.getBasePrice()).multiply(Constants.formatBigdecimal(i.getBasePriceRate())).setScale(0,BigDecimal.ROUND_CEILING)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return PageData.from(goodsIPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(mulFiles !=null && mulFiles.size()>0){ | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @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(); | 
|---|
|  |  |  | 
|---|
|  |  |  | .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getEPrice()), "  t.PRICE <=  "+pageWrap.getModel().getEPrice()+" "); | 
|---|
|  |  |  | queryWrapper.orderByDesc(Goods::getId); | 
|---|
|  |  |  | IPage<Goods> goodsIPage =  goodsJoinMapper.selectJoinPage(page, Goods.class, queryWrapper); | 
|---|
|  |  |  | this.dealGoodsMsg(goodsIPage.getRecords()); | 
|---|
|  |  |  | if(!Objects.isNull(goodsIPage.getRecords())&&goodsIPage.getRecords().size()>Constants.ZERO){ | 
|---|
|  |  |  | this.dealGoodsMsg(goodsIPage.getRecords()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(goodsIPage); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
|---|
|  |  |  | String prefixUrlCategory = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
|---|
|  |  |  | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode(); | 
|---|
|  |  |  | List<Integer> integerList = goodsList.stream().map(Goods::getId).collect(Collectors.toList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Multifile> mFileList = multifileMapper.selectList(new QueryWrapper<Multifile>() | 
|---|
|  |  |  | .in("OBJ_ID",integerList).eq("TYPE",Constants.ZERO)); | 
|---|
|  |  |  | .lambda().in(Multifile::getObjId,integerList) | 
|---|
|  |  |  | .eq(Multifile::getType,Constants.ZERO) | 
|---|
|  |  |  | .eq(Multifile::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(Multifile::getObjType,Constants.ZERO)); | 
|---|
|  |  |  | List<GoodsParam> goodsParamList = goodsParamMapper.selectList(new QueryWrapper<GoodsParam>() | 
|---|
|  |  |  | .in("GOODS_ID",integerList) | 
|---|
|  |  |  | .orderByAsc(" SORTNUM ")); | 
|---|
|  |  |  | 
|---|
|  |  |  | .apply(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getEPrice()), "  t.PRICE <=  "+goodsRequest.getEPrice()+" "); | 
|---|
|  |  |  | queryWrapper.orderByDesc(Goods::getId); | 
|---|
|  |  |  | List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper); | 
|---|
|  |  |  | this.dealGoodsMsg(goodsList); | 
|---|
|  |  |  | if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){ | 
|---|
|  |  |  | this.dealGoodsMsg(goodsList); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return goodsList; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|