Exemplo n.º 1
0
  @Override
  public void delete(ProductParam param) {
    // 删除描述信息
    ProductDescriptionParam dParam = new ProductDescriptionParam();
    dParam.setProductId(param.getId());
    dParam.setStatus(StatusType.DEL.getValue());
    productDescriptionDao.update(dParam);

    // 删除图片
    ImgParam imgParam = new ImgParam();
    imgParam.setToId(param.getId());
    imgParam.setStatus(StatusType.DEL.getValue());
    imgDao.update(imgParam);

    // 商品
    param.setStatus(StatusType.DEL.getValue());
    productDao.update(param);
  }
Exemplo n.º 2
0
  @Override
  public void update(ProductParam param) {
    // 保存描述信息
    ProductDescriptionParam dParam = new ProductDescriptionParam();
    dParam.setDescription(param.getDescription());
    dParam.setId(param.getDescriptionId());
    dParam.setProductId(param.getId());
    if (dParam.getId() == null) {
      productDescriptionDao.insert(dParam);
    } else {
      productDescriptionDao.update(dParam);
    }

    // 保存主图
    ImgParam imgParam = new ImgParam();
    imgParam.setId(param.getPrimaryImgId());
    imgParam.setTypes(ImgType.PRIMARY.getValue());
    imgParam.setToId(param.getId());
    if (imgParam.getId() == null) {
      imgParam.setName(param.getPrimaryImg());
      imgDao.insert(imgParam);
    } else {
      // 如果用户修改了图片,则删除原来的图片
      List<ImgModel> imgs = imgDao.getList(imgParam);
      if (!CollectionUtils.isEmpty(imgs)) {
        File file = new File(Constants.PRODUCT_IMG_ABSOLUTE_PATH + imgs.get(0).getName());
        if (file.exists()) {
          file.delete();
        }
      }
      imgDao.update(imgParam);
    }

    // 商品
    productDao.update(param);
  }
Exemplo n.º 3
0
  @Override
  public void add(ProductParam param) {
    // 获取公司id
    CompanyModel company = companyDao.getByUserId(param.getUserId());
    if (company != null) {
      param.setCompanyId(company.getId());
    }

    // 必须先保存商品,因为返回的商品主键以后要使用
    productDao.insert(param);

    // 保存描述信息
    ProductDescriptionParam dParam = new ProductDescriptionParam();
    dParam.setDescription(param.getDescription());
    dParam.setProductId(param.getId());
    productDescriptionDao.insert(dParam);

    // 保存主图
    ImgParam imgParam = new ImgParam();
    imgParam.setName(param.getPrimaryImg());
    imgParam.setToId(param.getId());
    imgParam.setTypes(ImgType.PRIMARY.getValue());
    imgDao.insert(imgParam);
  }
Exemplo n.º 4
0
  @Override
  public List<ProductVO> getList(ProductParam param) {
    List<ProductVO> vos = new ArrayList<ProductVO>();
    List<ProductModel> models = productDao.getList(param);

    List<Long> companyIds = new ArrayList<Long>();
    List<Long> cityIds = new ArrayList<Long>();
    List<Long> productIds = new ArrayList<Long>();
    List<Long> provinceIds = new ArrayList<Long>();
    if (!CollectionUtils.isEmpty(models)) {
      for (ProductModel model : models) {
        vos.add(model2VO(model));

        productIds.add(model.getId());

        // 公司
        Long companyId = model.getCompanyId();
        if (companyId != null && !companyIds.contains(companyId)) {
          companyIds.add(companyId);
        }

        // 城市
        Long cityId = model.getCityId();
        Long toCityId = model.getToCityId();
        if (cityId != null && !cityIds.contains(cityId)) {
          cityIds.add(cityId);
        }
        if (toCityId != null && !cityIds.contains(toCityId)) {
          cityIds.add(toCityId);
        }

        // 省份
        Long provinceId = model.getProvinceId();
        Long toProvinceId = model.getToProvinceId();
        if (provinceId != null && !provinceIds.contains(provinceId)) {
          provinceIds.add(provinceId);
        }
        if (toProvinceId != null && !provinceIds.contains(toProvinceId)) {
          provinceIds.add(toProvinceId);
        }
      }
    }

    // 公司
    Map<Long, String> companyMap = new HashMap<Long, String>();
    if (companyIds.size() > 0) {
      CompanyParam companyParam = new CompanyParam();
      companyParam.setIds(companyIds);
      List<CompanyModel> companys = companyDao.getList(companyParam);
      for (CompanyModel company : companys) {
        companyMap.put(company.getId(), company.getName());
      }
    }

    // 城市
    Map<Long, String> cityMap = new HashMap<Long, String>();
    if (cityIds.size() > 0) {
      CityParam cityParam = new CityParam();
      cityParam.setIds(cityIds);
      List<CityModel> citys = cityDao.getList(cityParam);
      for (CityModel city : citys) {
        cityMap.put(city.getId(), city.getName());
      }
    }

    // 省份
    Map<Long, String> provinceMap = new HashMap<Long, String>();
    if (provinceIds.size() > 0) {
      ProvinceParam provinceParam = new ProvinceParam();
      provinceParam.setIds(provinceIds);
      List<ProvinceModel> provinces = provinceDao.getList(provinceParam);
      for (ProvinceModel province : provinces) {
        provinceMap.put(province.getId(), province.getName());
      }
    }

    // 图片
    Map<Long, ImgModel> primaryImgMap = new HashMap<Long, ImgModel>();
    Map<Long, List<ImgModel>> secondaryImgMap = new HashMap<Long, List<ImgModel>>();
    if (productIds.size() > 0) {
      ImgParam imgParam = new ImgParam();

      // 如果查询多个商品,只查询附图,一般情况下,查询单个商品时才查询所有的图片
      if (productIds.size() > 1) {
        imgParam.setTypes(ImgType.PRIMARY.getValue());
        imgParam.setPageSize(50);
      }

      imgParam.setToIds(productIds);
      List<ImgModel> imgs = imgDao.getList(imgParam);
      if (!CollectionUtils.isEmpty(imgs)) {
        for (ImgModel img : imgs) {
          if (ImgType.SECONDARY.getValue().endsWith(img.getTypes())) {
            List<ImgModel> secondaryImgs = secondaryImgMap.get(img.getToId());
            if (secondaryImgs == null) {
              secondaryImgs = new ArrayList<ImgModel>();
            }
            secondaryImgs.add(img);
            secondaryImgMap.put(img.getToId(), secondaryImgs);
          } else if (ImgType.PRIMARY.getValue().endsWith(img.getTypes())) {
            primaryImgMap.put(img.getToId(), img);
          }
        }
      }
    }

    for (ProductVO productVO : vos) {
      // 公司名
      productVO.setCompanyName(companyMap.get(productVO.getCompanyId()));

      // 城市
      String city = cityMap.get(productVO.getCityId());
      if (StringUtils.isNotBlank(city)) {
        productVO.setCityName(city + "市");
      }
      // 配送城市
      productVO.setToCityName(cityMap.get(productVO.getToCityId()));

      // 所在省份
      String province = provinceMap.get(productVO.getProvinceId());
      if (StringUtils.isNotBlank(province)) {
        productVO.setProvinceName(province + "省");
      }

      // 配送省份
      productVO.setToProvinceName(provinceMap.get(productVO.getToProvinceId()));

      // 主图
      ImgModel primaryImg = primaryImgMap.get(productVO.getId());
      if (primaryImg != null) {
        productVO.setPrimaryImgId(primaryImg.getId());
        productVO.setPrimaryImgUrl(URIUtils.getProductFullImgUrl(primaryImg.getName()));
      } else {
        productVO.setPrimaryImgUrl(URIUtils.getNoneFullImgUrl());
      }

      // 附图
      List<ImgModel> secondaryImgs = secondaryImgMap.get(productVO.getId());
      if (!CollectionUtils.isEmpty(secondaryImgs)) {
        List<String> secondaryImgsUrl = new ArrayList<String>(secondaryImgs.size());
        for (ImgModel secondaryImg : secondaryImgs) {
          secondaryImgsUrl.add(URIUtils.getProductFullImgUrl(secondaryImg.getName()));
        }
        productVO.setSecondaryImgsUrl(secondaryImgsUrl);
      }
    }

    return vos;
  }
Exemplo n.º 5
0
 public int getCount(ProductParam param) {
   return productDao.getCount(param);
 }