@Override
  public List<SalesBackGoodsData> getSalesBackGoodsData(
      String goodsName, String backType, String salesSerialNumber) {
    List<SalesBackGoodsData> salesBackGoodsDatasList = new ArrayList<SalesBackGoodsData>();
    int saleCount = 0;
    SalesGoodsExample salesGoodsExample = new SalesGoodsExample();
    Criteria criteria = salesGoodsExample.createCriteria();
    criteria.andGoodsNameEqualTo(goodsName);
    criteria.andSalesSerialNumberEqualTo(salesSerialNumber);
    List<SalesGoods> salesGoodsList = new ArrayList<SalesGoods>();
    salesGoodsList = salesGoodsService.selectSalesGoods(salesGoodsExample);
    for (SalesGoods salesGoods : salesGoodsList) {
      saleCount += salesGoods.getSalesGoodsAmount();
    }
    if (backType.equals(Constants.BackType.BACKGOODS)) {
      for (SalesGoods salesGoods : salesGoodsList) {
        SalesBackGoodsData salesBackGoodsData = new SalesBackGoodsData();
        salesBackGoodsData.setGoodsExpirationDate(salesGoods.getSalesGoodsExpirationDate());
        salesBackGoodsData.setGoodsName(salesGoods.getGoodsName());
        salesBackGoodsData.setGoodsProductionDate(salesGoods.getSalesGoodsProductionDate());
        salesBackGoodsData.setImportGoodsUnit(salesGoods.getSalesGoodsUnit());
        salesBackGoodsData.setSalesCount(salesGoods.getSalesGoodsAmount());
        salesBackGoodsData.setStorageId(salesGoods.getStorageId());
        salesBackGoodsData.setSalesGoodsId(salesGoods.getSalesGoodsId());
        salesBackGoodsDatasList.add(salesBackGoodsData);
      }

    } else {
      TbStoragecheckExample storagecheckExample = new TbStoragecheckExample();
      storagecheckExample.createCriteria().andGoodsNameEqualTo(goodsName);
      List<TbStoragecheck> storagechecksList =
          storagecheckService.selectByExample(storagecheckExample);
      for (TbStoragecheck storagecheck : storagechecksList) {
        SalesBackGoodsData salesBackGoodsData = new SalesBackGoodsData();
        salesBackGoodsData.setGoodsExpirationDate(storagecheck.getGoodsExpirationDate());
        salesBackGoodsData.setGoodsName(storagecheck.getGoodsName());
        salesBackGoodsData.setGoodsProductionDate(storagecheck.getGoodsProductionDate());
        salesBackGoodsData.setImportGoodsUnit(storagecheck.getImportGoodsUnit());
        salesBackGoodsData.setStorageId(storagecheck.getStorageId());
        salesBackGoodsData.setStorageRateCurrent(storagecheck.getStorageRateCurrent());
        salesBackGoodsData.setSalesCount(saleCount);
        salesBackGoodsDatasList.add(salesBackGoodsData);
      }
    }
    return salesBackGoodsDatasList;
  }
 @Override
 public String updateSalesbackInfo(
     String goodsAmountList,
     String salesbackSerialNumber,
     String salesbackType,
     String salesbackReason,
     String storageIdList) {
   Salesback salesback = salesbackService.selectByPrimaryKey(salesbackSerialNumber);
   SalesbackGoodsExample example = new SalesbackGoodsExample();
   example.createCriteria().andSalesbackSerialNumberEqualTo(salesbackSerialNumber);
   List<SalesbackGoods> salesbackGoodsList = salesbackGoodsService.selectByExample(example);
   String[] goodsAmounts = goodsAmountList.split(",");
   String[] storageIds = storageIdList.split(",");
   for (int i = 0; i < salesbackGoodsList.size(); i++) {
     int count = salesbackGoodsList.get(i).getGoodsAmount() - Integer.parseInt(goodsAmounts[i]);
     if (count != 0) {
       salesbackGoodsList.get(i).setGoodsAmount(Integer.parseInt(goodsAmounts[i]));
       TbStoragecheck storagecheck = new TbStoragecheck();
       storagecheck = storagecheckService.selectByKey(Integer.parseInt(storageIds[i]));
       if (storagecheck.getStorageRateCurrent() == count) {
         storagecheck.setStorageRateCurrent(0);
         storagecheck.setEndtime(new java.util.Date());
       } else if (storagecheck.getStorageRateCurrent() + count < 0) {
         return "ERROE";
       } else {
         storagecheck.setStorageRateCurrent(storagecheck.getStorageRateCurrent() + count);
       }
       salesbackGoodsService.update(salesbackGoodsList.get(i));
       storagecheckService.updateTbStoragecheck(storagecheck);
     }
   }
   salesback.setSalesbackReason(salesbackReason);
   salesback.setSalesbackType(salesbackType);
   salesbackService.update(salesback);
   return "SUCCESS";
 }
 @Override
 public String deleteSalesbackData(String salesbackSerialNumber) {
   SalesbackGoodsExample example = new SalesbackGoodsExample();
   example.createCriteria().andSalesbackSerialNumberEqualTo(salesbackSerialNumber);
   List<SalesbackGoods> salesbackGoodsList = salesbackGoodsService.selectByExample(example);
   for (SalesbackGoods salesbackGoods : salesbackGoodsList) {
     TbStoragecheck storagecheck = new TbStoragecheck();
     storagecheck = storagecheckService.selectByKey(salesbackGoods.getStorageId());
     if (storagecheck.getEndtime() != null) {
       storagecheck.setEndtime(null);
       storagecheck.setStorageRateCurrent(salesbackGoods.getGoodsAmount());
       storagecheckService.updateTbStoragecheck(storagecheck);
     } else {
       storagecheck.setStorageRateCurrent(
           storagecheck.getStorageRateCurrent() + salesbackGoods.getGoodsAmount());
       storagecheckService.updateTbStoragecheck(storagecheck);
     }
     salesbackGoodsService.deleteByPrimaryKey(salesbackGoods.getSalesbackGoodsId());
   }
   salesbackService.deleteByPrimaryKey(salesbackSerialNumber);
   return "SUCCESS";
 }
  @Override
  public String addSalesbackList(AddSalesbackData addSalesbackData) {
    java.util.Date date = new java.util.Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    String number = sdf.format(date);
    String salesbackSerialNumber = salesbackService.getSalesbackSerialNumber(number);
    if (salesbackSerialNumber == null) {
      salesbackSerialNumber = number + "0000";
    } else {
      salesbackSerialNumber = Long.toString((Long.parseLong(salesbackSerialNumber) + 1L));
    }
    String[] storageIds = addSalesbackData.getStorageIdList().split(",");
    String[] changeCounts = addSalesbackData.getChangeCountList().split(",");
    String salesSerialNumber = addSalesbackData.getSalesSerialNumber();
    String backReson = addSalesbackData.getBackReson();
    String backgoodsTime = addSalesbackData.getBackgoodsTime();

    for (int i = 0; i < changeCounts.length; i++) {
      SalesbackGoods salesbackGoods = new SalesbackGoods();
      TbStoragecheck storagecheck = new TbStoragecheck();
      storagecheck = storagecheckService.selectByKey(Integer.parseInt(storageIds[i]));
      salesbackGoods.setSalesbackSerialNumber(salesbackSerialNumber);
      salesbackGoods.setGoodsId(storagecheck.getGoodsId());
      salesbackGoods.setGoodsName(storagecheck.getGoodsName());
      salesbackGoods.setGoodsType(Constants.SalesStatus.DOWNORDER);
      salesbackGoods.setGoodsAmount(Integer.parseInt(changeCounts[i]));
      salesbackGoods.setGoodsUnit(storagecheck.getGoodsUnit());
      salesbackGoods.setGoodsProduction(storagecheck.getGoodsProductionDate());
      salesbackGoods.setGoodsExpiration(storagecheck.getGoodsExpirationDate());
      salesbackGoods.setCreatetime(Date.valueOf(backgoodsTime));
      salesbackGoods.setStorageId(storagecheck.getStorageId());

      if (storagecheck.getStorageRateCurrent() == Integer.parseInt(changeCounts[i])) {
        storagecheck.setStorageRateCurrent(0);
        storagecheck.setEndtime(new java.util.Date());
        storagecheckService.updateTbStoragecheck(storagecheck);
      } else {
        storagecheck.setStorageRateCurrent(
            storagecheck.getStorageRateCurrent() - Integer.parseInt(changeCounts[i]));
        storagecheckService.updateTbStoragecheck(storagecheck);
      }
      salesbackGoodsService.insert(salesbackGoods);
    }
    Sales sales = new Sales();
    sales = salesService.selectByKey(salesSerialNumber);
    Salesback salesback = new Salesback();
    salesback.setSalesbackSerialNumber(salesbackSerialNumber);
    salesback.setSalesSerialNumber(salesSerialNumber);
    salesback.setCustomerId(sales.getCustomerId());
    salesback.setCustomerName(sales.getCustomerName());
    salesback.setStorehouseId(sales.getStorehouseId());
    salesback.setStorehouseName(sales.getStorehouseName());
    salesback.setEmployeeId(sales.getEmployeeId());
    salesback.setEmployeeName(sales.getEmployeeName());
    salesback.setSalesbackType(Constants.BackType.CHANGEGOODS);
    salesback.setSalesbackReason(backReson);
    salesback.setSalesbackTime(Date.valueOf(backgoodsTime));
    salesbackService.insert(salesback);

    return "SUCCESS";
  }