jiangping
2023-09-19 0ad62ef3a9bcc2d8f0e3ae988f0a17cfd2384c26
修改
已修改5个文件
94 ■■■■■ 文件已修改
server/platform/src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/core/utils/Constants.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/BaseGoods.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java 82 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/platform/src/main/resources/application.yml
@@ -5,7 +5,7 @@
  env: development
#  env: production
server:
  port: 10011
  port: 10023
spring:
#  application:
server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -306,6 +306,12 @@
            this.noteInfo = noteInfo;
        }
    }
    public interface BasegoodsOrigin{
         int userAdd = 0;
         int imported = 1;
         int basedata = 2;
    }
    /**
     * 关联对象类型 0企业营业执照 1工商变更登记  2项目申报企业资料 3企业评分表 4诊断报告 5诊断服务资料 6专家评分报告 7服务机构上传服务资料 8企业资质 9企业中标通知书 10项目图片
     */
server/service/src/main/java/com/doumee/dao/business/model/BaseGoods.java
@@ -93,6 +93,9 @@
    @ApiModelProperty(value = "入手价格(元)", example = "1")
    @ExcelColumn(name="入手价格(元)")
    private BigDecimal price;
    @ApiModelProperty(value = "数据来源 0手动录入 1批量导入 2数据源同步", example = "1")
    @ExcelColumn(name="数据来源 0手动录入 1批量导入 2数据源同步")
    private Integer origin;
    @ApiModelProperty(value = "商品详情")
    @ExcelColumn(name="商品详情")
server/service/src/main/java/com/doumee/service/business/impl/BaseDataServiceImpl.java
@@ -373,6 +373,7 @@
        goods.setRemark(data.getTitle());
        goods.setContent(data.getTitle());
        goods.setStatus(Constants.ZERO);
        goods.setOrigin(Constants.BasegoodsOrigin.basedata);
        goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
        goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
        goods.setZdPrice(data.getPrice());
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java
@@ -434,32 +434,26 @@
            if(dataList == null || dataList.size() ==0){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!");
            }
            List<String> comNameList = dataList.stream().map(s -> s.getName().trim()).distinct().collect(Collectors.toList());
            if (!(dataList.size() == comNameList.size())){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品名称有已存在");
            //处理批量上传
            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode();
            String basePath = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
                    + proDir + File.separator ;
            OssModel ossModel = baseDataService.initOssModel();
            for (int index = 0; index < dataList.size(); index++) {
                BaseGoodsImportDTO  s = dataList.get(index);
                if(existedIdInList(s.getId(),index,dataList)){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"第【"+(1+index)+"行】商品编号【"+s.getId()+"】在表格中重复");
            }
//            List<String> collect1 = dataList.stream().filter(s->{
//                if (StringUtils.isBlank(s.getBrandName())){
//                    throw new BusinessException(ResponseStatus.BAD_REQUEST);
//                }else {
//                    return true;
//                }
//            }).map(s -> s.getCategoryName()).collect(Collectors.toList());
//            QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>();
//            wrapper.lambda()
//                    .in(BaseCategory::getName,collect1);
//            List<BaseCategory> baseCategories = baseCategoryMapper.selectList(wrapper);
            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()+"】已存在");
                if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().lambda().eq(BaseGoods::getIsdeleted, Constants.ZERO)
                        .eq(BaseGoods::getBaseDataId,s.getId())
                        .eq(BaseGoods::getOrigin,Constants.BasegoodsOrigin.imported))>0){
                    throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"第【"+(1+index)+"行】商品编号【"+s.getId()+"】已导入!");
                }
                BaseGoods baseGoods = new BaseGoods();
                baseGoods.setCreator(user.getId());
                baseGoods.setOrigin(Constants.BasegoodsOrigin.imported);
                baseGoods.setBaseDataId(s.getId());
                baseGoods.setCreateDate(new Date());
                baseGoods.setEditor(user.getId());
                baseGoods.setEditDate(new Date());
@@ -469,39 +463,39 @@
                baseGoods.setZdPrice(new BigDecimal(s.getZdPrice()));
                baseGoods.setPrice(new BigDecimal(s.getPrice()));
                if (StringUtils.isBlank(s.getCategoryName())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品类别不可为空");
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"第【"+(1+index)+"行】商品类别不可为空");
                }
                QueryWrapper<BaseCategory> categoryQuery = new QueryWrapper<>();
                categoryQuery.lambda()
                    .eq(BaseCategory::getName,s.getCategoryName());
                BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery);
                categoryQuery.lambda()
                    .eq(BaseCategory::getIsdeleted,Constants.ZERO);
                BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery.last(" limit 1"));
                if (Objects.isNull(baseCategory)){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品类别不存在");
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"第【"+(1+index)+"行】商品类别【"+s.getCategoryName()+"】不存在");
                }
                QueryWrapper<Brand> brandQuery = new QueryWrapper<>();
                brandQuery.lambda()
                        .eq(Brand::getName,s.getBrandName());
                Brand brand = brandMapper.selectOne(brandQuery);
                brandQuery.lambda()
                        .eq(Brand::getIsdeleted,Constants.ZERO);
                brandQuery.lambda()
                        .eq(Brand::getType,Constants.ZERO);
                Brand brand = brandMapper.selectOne(brandQuery.last("limit 1"));
                if (Objects.isNull(brand)){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品品牌不存在");
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"第【"+(1+index)+"行】商品品牌【"+s.getBrandName()+"】不存在");
                }
                //处理批量上传
                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();
                String path =basePath+ 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)){
                                if(StringUtils.isBlank(baseCategory.getImgurl()) && isImgFile(f)){
                                    //取第一张图片作为列表图
                                    baseGoods.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
                                }
@@ -523,8 +517,6 @@
                        }
                    }
                }
//                baseGoods.setImgurl();
                baseGoods.setCategoryId(baseCategory.getId());
                baseGoods.setBrandId(brand.getId());
@@ -552,13 +544,12 @@
                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;
                    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(),"配置参数不存在"));
                                    .orElseThrow(() -> new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "配置参数【】不存在"));
                            BaseGoodsParam baseGoodsParam = new BaseGoodsParam();
                            baseGoodsParam.setCreator(user.getId());
                            baseGoodsParam.setCreateDate(new Date());
@@ -575,11 +566,11 @@
                            baseGoodsParamMapper.insert(baseGoodsParam);
                        }
                    };
                    }
                    ;
                }
            });
            }
        }catch (Exception e) {
            log.error(String.format("批量插入异常%s ",e.getMessage()));
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),e.getMessage());
@@ -589,6 +580,15 @@
        return null;
    }
    private boolean existedIdInList(String id,int index, List<BaseGoodsImportDTO> dataList) {
        for (int j = 0; j <dataList.size(); j++) {
            if(index!=j && StringUtils.equals(id,dataList.get(j).getId())){
                return true;
            }
        }
        return false;
    }
    private boolean isImgFile(File f) {
        if(f!=null && f.isFile() ){
            String name = f.getName();