Exemplo n.º 1
0
  public Product update(
      User user,
      Product bean,
      ProductExt ext,
      Long ctgId,
      Long brandId,
      Long[] tagIds,
      String[] keywords,
      String[] names,
      String[] values,
      Map<String, String> attr,
      String fashionSwitchPic[],
      String fashionBigPic[],
      String fashionAmpPic[],
      MultipartFile file) {
    Product entity = findById(bean.getId());
    if (entity.getParent() != null
        && entity.getParent().getId() != null
        && bean.getParent().getId() != entity.getParent().getId()) {
      //			Jysp  = jyspMng.findById(bean.getParent().getId());
      List<Jysp> jysps = jyspMng.findByProductId(entity.getParent().getId(), entity.getId());
      for (Jysp jysp : jysps) {
        jyspMng.delete(jysp.getId());
      }
    }
    if (bean.getParent() != null
        && bean.getParent().getId() != null
        && bean.getParent().getId() > 0) {
      bean.setParent(productDao.findById(bean.getParent().getId()));
    } else {
      bean.setParent(null);
    }
    ProductText text = bean.getProductText();
    // 先更新ProductText
    if (text != null) {
      ProductText ptext = entity.getProductText();
      if (ptext != null) {
        ptext.setText(text.getText());
        ptext.setText1(text.getText1());
        ptext.setText2(text.getText2());
      } else {
        text.setId(bean.getId());
        text.setProduct(entity);
        entity.setProductText(text);
        productTextMng.save(text);
      }
    }
    // 删除原tag
    entity.removeAllTags();
    // 设置类别、类型,不能为空
    Category category = categoryMng.findById(ctgId);
    entity.setCategory(category);
    entity.setType(category.getType());
    //		if(entity.getOnSale()==null){
    //			entity.setOnSale(false);
    //		}
    // 设置品牌,可以为空
    if (brandId != null) {
      entity.setBrand(brandMng.findById(brandId));
    } else {
      entity.setBrand(null);
    }
    // 设置tag,可以为空
    if (!ArrayUtils.isEmpty(tagIds)) {
      for (Long tagId : tagIds) {
        entity.addToTags(productTagMng.findById(tagId));
      }
    }
    // 设置关键字,可以为空
    if (keywords != null) {
      List<String> kw = entity.getKeywords();
      kw.clear();
      kw.addAll(Arrays.asList(keywords));
    } else {
      entity.getKeywords().clear();
    }

    // 更新其他属性
    Updater<Product> updater = new Updater<Product>(bean);
    updater.exclude(Product.PROP_WEBSITE);
    updater.exclude(Product.PROP_PRODUCT_TEXT);
    entity = productDao.updateByUpdater(updater);
    // 更新属性表
    if (attr != null) {
      Map<String, String> attrOrig = entity.getAttr();
      attrOrig.clear();
      attrOrig.putAll(attr);
    }
    // 更新规则值
    entity.getExendeds().clear();
    if (names != null && names.length > 0) {
      for (int i = 0, len = names.length; i < len; i++) {
        if (!StringUtils.isBlank(names[i])) {
          entity.addToExendeds(names[i], values[i]);
        }
      }
    }
    // 更新图片集
    entity.getPictures().clear();
    if (fashionSwitchPic != null && fashionSwitchPic.length > 0) {
      for (int i = 0, len = fashionSwitchPic.length; i < len; i++) {
        if (!StringUtils.isBlank(fashionSwitchPic[i])) {
          entity.addToPictures(fashionSwitchPic[i], fashionBigPic[i], fashionAmpPic[i]);
        }
      }
    }
    String uploadPath = realPathResolver.get(entity.getWebsite().getUploadRel());
    saveImage(entity, ext, category.getType(), file, uploadPath);
    productExtMng.saveOrUpdate(ext, entity);
    if (bean.getParent() != null && bean.getParent().getId() != null) {
      Product parent = productDao.findById(entity.getParent().getId());

      //			Jysp  = jyspMng.findById(bean.getParent().getId());
      List<Gys> gyss = jyspMng.findGysByProductId(entity.getId());
      for (Gys gys : gyss) {
        Jysp jysp = new Jysp();

        ProductSite productSite =
            productSiteDao.getProductSiteByProductIdAndWebId(
                entity.getParent().getId(), gys.getWebsite().getId());
        if (productSite == null) {
          productSite = new ProductSite();
          productSite.setAlertInventory(0);
          productSite.setCostPrice(0d);
          productSite.setCreateTime(new Date());
          productSite.setProduct(bean);
          productSite.setWebsite(gys.getWebsite());
          productSiteDao.save(productSite);
        }
        jysp.setGys(gys);
        jysp.setCreateTime(new Date());
        jysp.setGoodsMaxNum(0l);
        jysp.setGoodsMinNum(0l);
        jysp.setGoodsNum(0l);
        jysp.setGoodsPrice(0d);
        jysp.setUsername(user.getUsername());
        jysp.setProductSite(productSite);
        jyspMng.save(jysp);
      }
    }
    return entity;
  }
Exemplo n.º 2
0
  public Product save(
      User user,
      Product bean,
      ProductExt ext,
      Long webId,
      Long categoryId,
      Long brandId,
      Long[] tagIds,
      String[] keywords,
      String[] names,
      String[] values,
      String fashionSwitchPic[],
      String fashionBigPic[],
      String fashionAmpPic[],
      MultipartFile file) {
    ProductText text = bean.getProductText();
    if (text != null) {
      text.setProduct(bean);
    }
    if (bean.getParent() != null
        && bean.getParent().getId() != null
        && bean.getParent().getId() > 0) {
      bean.setParent(productDao.findById(bean.getParent().getId()));
    } else {
      bean.setParent(null);
    }

    Category category = categoryMng.findById(categoryId);
    if (brandId != null) {
      bean.setBrand(brandMng.findById(brandId));
    }
    Website web = websiteMng.findById(webId);
    bean.setWebsite(web);
    bean.setConfig(shopConfigMng.findById(webId));
    bean.setCategory(category);
    bean.setType(category.getType());
    if (!ArrayUtils.isEmpty(tagIds)) {
      for (Long tagId : tagIds) {
        bean.addToTags(productTagMng.findById(tagId));
      }
    }
    if (!ArrayUtils.isEmpty(keywords)) {
      bean.setKeywords(Arrays.asList(keywords));
    }
    bean.init();
    productDao.save(bean);
    // 保存商品规格储存
    if (names != null && names.length > 0) {
      for (int i = 0, len = names.length; i < len; i++) {
        if (!StringUtils.isBlank(names[i])) {
          bean.addToExendeds(names[i], values[i]);
        }
      }
    }
    // 保存图片/大图片/放大图片集
    if (fashionSwitchPic != null && fashionSwitchPic.length > 0) {
      for (int i = 0, len = fashionSwitchPic.length; i < len; i++) {
        if (!StringUtils.isBlank(fashionSwitchPic[i])) {
          bean.addToPictures(fashionSwitchPic[i], fashionBigPic[i], fashionAmpPic[i]);
        }
      }
    }
    String uploadPath = realPathResolver.get(web.getUploadRel());
    saveImage(bean, ext, category.getType(), file, uploadPath);
    productExtMng.save(ext, bean);
    if (bean.getParent() != null && bean.getParent().getId() != null) {

      //			Jysp  = jyspMng.findById(bean.getParent().getId());
      List<Gys> gyss = jyspMng.findGysByProductId(bean.getParent().getId());
      for (Gys gys : gyss) {
        ProductSite productSite =
            productSiteDao.getProductSiteByProductIdAndWebId(
                bean.getId(), gys.getWebsite().getId());
        if (productSite == null) {
          productSite = new ProductSite();
          productSite.setAlertInventory(0);
          productSite.setCostPrice(0d);
          productSite.setCreateTime(new Date());
          productSite.setProduct(bean);
          productSite.setWebsite(gys.getWebsite());
          productSiteDao.save(productSite);
        }
        //				Jysp jysp=jyspMng.findByProductIdAndKetaUserId(productSite.getId(),
        // gys.getKetaUser().getId());

        Jysp jysp = new Jysp();
        jysp.setGys(gys);
        jysp.setCreateTime(new Date());
        jysp.setGoodsMaxNum(0l);
        jysp.setGoodsMinNum(0l);
        jysp.setGoodsNum(0l);
        jysp.setGoodsPrice(0d);
        jysp.setUsername(user.getUsername());
        jysp.setProductSite(productSite);
        jyspMng.save(jysp);
      }
    }
    return bean;
  }