|
|
@@ -527,70 +527,75 @@ public class ProductServiceImpl implements ProductService {
|
|
|
return exportGoodsByProduct(productList);
|
|
|
}
|
|
|
|
|
|
+ @javax.transaction.Transactional
|
|
|
@Override
|
|
|
- public void deleteBatch(List<Long> ids, Integer isPerson) {
|
|
|
- for (Long id : ids) {
|
|
|
- if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
- List<ProductPerson> productPersonList = productPersonDao.findByProductIdAndUserUU(id,SystemSession.getUser().getUserUU());
|
|
|
- if (!CollectionUtils.isEmpty(productPersonList)) {
|
|
|
-// Map<String,Object> requestMap = new HashMap<>();
|
|
|
-// requestMap.put("userUU",productPersonList.get(0).getUserUU());
|
|
|
-// requestMap.put("productId",productPersonList.get(0).getProductId());
|
|
|
-// String res = restTemplate.postForEntity( productServiceIp+"/product/assign/delete", null, String.class, requestMap).getBody();
|
|
|
- Long ppid = productPersonList.get(0).getId();
|
|
|
- productPersonDao.delete(ppid);
|
|
|
+ public ResultMap deleteBatch(List<Long> ids, Integer isPerson) {
|
|
|
+ if (CollectionUtils.isEmpty(ids)) {
|
|
|
+ return new ResultMap(CodeType.NO_INFO, "没有传入有效信息");
|
|
|
+ }
|
|
|
+ if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
+ String sql = "delete from product$users where pu_prid in (:ids) and pu_useruu = " + SystemSession.getUser().getUserUU();
|
|
|
+ Map<String, List<Long>> map = new HashedMap();
|
|
|
+ map.put("ids", ids);
|
|
|
+ namedParameterJdbcTemplate.update(sql, map);
|
|
|
+ return ResultMap.success("删除成功");
|
|
|
+ } else {
|
|
|
+ String message = "";
|
|
|
+ List<Goods> goodsList = goodsDao.findByProductIds(ids);
|
|
|
+ String codes = OrderStatus.UNAVAILABLE.getCodes() + "-" + Status.TOBECONFIRMED.value();
|
|
|
+ List<OrderDetail> orderDetailList = orderDetailService.findOrderDetailByProductids(ids);
|
|
|
+ for (OrderDetail detail : orderDetailList) {
|
|
|
+ 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())) {
|
|
|
+ if (!message.contains("存在已下单的在售产品信息,不能删除")) {
|
|
|
+ message += "存在已下单的在售产品信息,不能删除";
|
|
|
+ }
|
|
|
+ StringUtilB2C.removeFromList(ids, detail.getProductId());
|
|
|
+ }
|
|
|
}
|
|
|
- continue;
|
|
|
}
|
|
|
- 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<ProductPerson> productPersons = productPersonDao.findByProductIds(ids);
|
|
|
+ for (ProductPerson productPerson : productPersons) {
|
|
|
+ if (!message.contains("存在物料已被个人收录,不能删除")) {
|
|
|
+ if (org.apache.commons.lang.StringUtils.isNotEmpty(message)) {
|
|
|
+ message += ",";
|
|
|
}
|
|
|
+ message += "存在物料已被个人收录,不能删除";
|
|
|
}
|
|
|
- if (isExistOrder) {
|
|
|
- break;
|
|
|
- }
|
|
|
+ StringUtilB2C.removeFromList(ids, productPerson.getProductId());
|
|
|
}
|
|
|
- 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 = productPrivateService.findByPrId(product.getId());
|
|
|
- if (productPrivate == null) {
|
|
|
- productPrivate = new ProductPrivate();
|
|
|
- productPrivate.setPrId(product.getId());
|
|
|
- }
|
|
|
+ //删除匹配结果信息
|
|
|
+ productMatchResultDao.deleteByProductids(ids);
|
|
|
+
|
|
|
+ //更新在售产品信息
|
|
|
+ List<Goods> goodses = goodsService.findByProductids(ids);
|
|
|
+ goodsService.deleteGoods(goodses);
|
|
|
+
|
|
|
+ //调整物料为禁用状态。
|
|
|
+ List<ProductPrivate> productPrivates = productPrivateService.findByPrIds(ids);
|
|
|
+ for (ProductPrivate productPrivate : productPrivates) {
|
|
|
productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
- productPrivateDao.save(productPrivate);
|
|
|
- //productDao.delete(id); 不允许删除
|
|
|
- } else {
|
|
|
- throw new
|
|
|
- IllegalOperatorException("该产品中存在已下单的在售产品信息,不能删除");
|
|
|
+ StringUtilB2C.removeFromList(ids, productPrivate.getPrId());
|
|
|
+ }
|
|
|
+ ProductPrivate pPrivate = null;
|
|
|
+ for (Long id : ids) {
|
|
|
+ pPrivate = new ProductPrivate(id);
|
|
|
+ if (CollectionUtils.isEmpty(productPrivates)) {
|
|
|
+ productPrivates = new ArrayList<>();
|
|
|
+ }
|
|
|
+ productPrivates.add(pPrivate);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(productPrivates)) {
|
|
|
+ productPrivateDao.save(productPrivates);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(message)) {
|
|
|
+ message = "删除成功";
|
|
|
}
|
|
|
+ return ResultMap.success(message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -613,7 +618,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
standard = IntegerConstant.NO_SHORT;
|
|
|
}
|
|
|
List<Product> products = productDao.findProductByEnuuAndStandardAndEnabled(uu, standard, IntegerConstant.YES_SHORT);
|
|
|
- Set<String> uuids = new HashSet<>();
|
|
|
for (Product product : products) {
|
|
|
if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
|
|
|
List<ProductPerson> productPersonList = productPersonDao.findByProductIdAndUserUU(product.getId(),SystemSession.getUser().getUserUU());
|
|
|
@@ -656,7 +660,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
Set<ProductMatchResult> productMatchResultSet = product.getMatchresults();
|
|
|
productMatchResultDao.delete(productMatchResultSet);
|
|
|
goodsService.deleteGoods(goodses);
|
|
|
- //productDao.delete(product.getId());
|
|
|
ProductPrivate productPrivate = productPrivateService.findByPrId(product.getId());
|
|
|
if (null == productPrivate) {
|
|
|
productPrivate = new ProductPrivate();
|
|
|
@@ -671,9 +674,6 @@ public class ProductServiceImpl implements ProductService {
|
|
|
}
|
|
|
productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
|
|
|
productPrivateDao.save(productPrivate);
|
|
|
- if (!StringUtils.isEmpty(product.getCmpUuId())) {
|
|
|
- uuids.add(product.getCmpUuId());
|
|
|
- }
|
|
|
} else {
|
|
|
fail++;
|
|
|
}
|
|
|
@@ -691,15 +691,12 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if(success != 0) {
|
|
|
message += ",";
|
|
|
}
|
|
|
- message += "删除失败" + (fail-isHave) + "条,原因:该产品可能已经被其他单据或个人物料库引用,无法删除";
|
|
|
+ message += "删除失败" + (fail - isHave) + "条,原因:该产品可能已经被其他单据或个人物料库引用,无法删除";
|
|
|
}
|
|
|
// 如果是全部都不能删除,才能设置失败的状态码
|
|
|
if ((products.size() != 0) && (products.size() == fail)) {
|
|
|
status = CodeType.ERROR_STATE.code();
|
|
|
}
|
|
|
- for (String uuid : uuids) {
|
|
|
- goodsService.updateComponentTradeInfos(uuid);
|
|
|
- }
|
|
|
return new ResultMap(status, message);
|
|
|
}
|
|
|
|
|
|
@@ -1422,9 +1419,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
if (product == null)
|
|
|
throw new IllegalOperatorException("此物料信息不存在,请重新确认");
|
|
|
ProductDetail productDetail = productDetailDao.findByProductId(productId);
|
|
|
- if (productDetail == null)
|
|
|
+ if (productDetail == null) {
|
|
|
productDetail = new ProductDetail();
|
|
|
-
|
|
|
+ }
|
|
|
productDetail.setBreakUp(goods.getBreakUp());
|
|
|
productDetail.setProduceDate(goods.getProduceDate());
|
|
|
productDetail.setProductId(productId);
|
|
|
@@ -1437,8 +1434,9 @@ public class ProductServiceImpl implements ProductService {
|
|
|
productDetail.setMinPackQty(goods.getMinPackQty());
|
|
|
productDetail.setPackaging(goods.getPackaging());
|
|
|
|
|
|
- if (enterpriseService.getCurrencyByRegisterAddress().getData() == null)
|
|
|
+ if (enterpriseService.getCurrencyByRegisterAddress().getData() == null) {
|
|
|
throw new IllegalOperatorException("注册地址为空,无法确认币别信息,请前往-优软云补充注册地址信息");
|
|
|
+ }
|
|
|
String currency = enterpriseService.getCurrencyByRegisterAddress().getData().toString();
|
|
|
List<GoodsQtyPrice> qtyPrice = FastjsonUtils.fromJsonArray(goods.getQtyPrice(), GoodsQtyPrice.class);
|
|
|
if (!CollectionUtils.isEmpty(qtyPrice)) {
|