|
|
@@ -544,53 +544,58 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Product product = productDao.findOne(id);
|
|
|
if (product == null)
|
|
|
throw new IllegalOperatorException("选择的产品不存在,请重新选择");
|
|
|
- //查看是否存在正常未取消的订单
|
|
|
- List<Goods> goodses = goodsDao.findByProductId(product.getId());
|
|
|
- Boolean isExistOrder = false;
|
|
|
- String codes = OrderStatus.UNAVAILABLE.getCodes() + "-" + Status.TOBECONFIRMED.value();
|
|
|
- for (Goods goods : goodses) {
|
|
|
- List<OrderDetail> orderList = orderDetailService.findOrderDetailByBatchCode(goods.getBatchCode());
|
|
|
- for (OrderDetail detail : orderList) {
|
|
|
- Order order = detail.getOrder();
|
|
|
- int status = order.getStatus() == null ? detail.getStatus() : order.getStatus();
|
|
|
- if (codes.indexOf(String.valueOf(status)) < 0) {
|
|
|
- // 区分是否是假单,or_orderids 不为空
|
|
|
- if (StringUtils.isEmpty(order.getOrderids())) {
|
|
|
- isExistOrder = true;
|
|
|
- break;
|
|
|
- }
|
|
|
+ //查看是否存在正常未取消的订单
|
|
|
+ List<Goods> goodses = goodsDao.findByProductId(product.getId());
|
|
|
+ Boolean isExistOrder = false;
|
|
|
+ String codes = OrderStatus.UNAVAILABLE.getCodes() + "-" + Status.TOBECONFIRMED.value();
|
|
|
+ for (Goods goods : goodses) {
|
|
|
+ List<OrderDetail> orderList = orderDetailService.findOrderDetailByBatchCode(goods.getBatchCode());
|
|
|
+ for (OrderDetail detail : orderList) {
|
|
|
+ Order order = detail.getOrder();
|
|
|
+ int status = order.getStatus() == null ? detail.getStatus() : order.getStatus();
|
|
|
+ if (codes.indexOf(String.valueOf(status)) < 0) {
|
|
|
+ // 区分是否是假单,or_orderids 不为空
|
|
|
+ if (StringUtils.isEmpty(order.getOrderids())) {
|
|
|
+ isExistOrder = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
- if (isExistOrder) {
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
- if (!isExistOrder) {
|
|
|
- //是否被个人物料库收录
|
|
|
- int count = productPersonDao.countByProductId(id);
|
|
|
- if ( count > 0 ){
|
|
|
- throw new IllegalOperatorException("该产品已被个人物料库收录,不能删除");
|
|
|
- }
|
|
|
- //删除外键关联的匹配结果列表,不然删除product失败
|
|
|
- Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
- productMatchResultDao.delete(productMatchResultSet);
|
|
|
- if (CollectionUtils.isNotEmpty(goodses)) {
|
|
|
- goodsService.deleteGoods(goodses);
|
|
|
- }
|
|
|
- ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
- if (productPrivate == null) {
|
|
|
- productPrivate = new ProductPrivate();
|
|
|
- productPrivate.setPrId(product.getId());
|
|
|
- }
|
|
|
- productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
- productPrivateDao.save(productPrivate);
|
|
|
- product.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
- //productDao.delete(id); 不允许删除
|
|
|
- } else {
|
|
|
- throw new
|
|
|
- IllegalOperatorException("该产品中存在已下单的在售产品信息,不能删除");
|
|
|
+ if (isExistOrder) {
|
|
|
+ break;
|
|
|
}
|
|
|
+ }
|
|
|
+ if (!isExistOrder) {
|
|
|
+ //是否被个人物料库收录
|
|
|
+ int count = productPersonDao.countByProductId(id);
|
|
|
+ if ( count > 0 ){
|
|
|
+ throw new IllegalOperatorException("该产品已被个人物料库收录,不能删除");
|
|
|
+ }
|
|
|
+ //删除外键关联的匹配结果列表,不然删除product失败
|
|
|
+ Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
+ productMatchResultDao.delete(productMatchResultSet);
|
|
|
+ if (CollectionUtils.isNotEmpty(goodses)) {
|
|
|
+ goodsService.deleteGoods(goodses);
|
|
|
+ }
|
|
|
+ ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
|
|
|
+ if (productPrivate == null) {
|
|
|
+ productPrivate = new ProductPrivate();
|
|
|
+ productPrivate.setPrId(product.getId());
|
|
|
+ }
|
|
|
+ productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
+ productPrivateDao.save(productPrivate);
|
|
|
+ product.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
+ // 设置物料不可用时,为了更新索引,也需要更新物料资料
|
|
|
+ product.setIsSale(Constant.NO);
|
|
|
+ product.setIsPurchase(Constant.NO);
|
|
|
+ product.setErpDate(new Date());
|
|
|
+ productDao.save(product);
|
|
|
+ //productDao.delete(id); 不允许删除
|
|
|
+ } else {
|
|
|
+ throw new
|
|
|
+ IllegalOperatorException("该产品中存在已下单的在售产品信息,不能删除");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|