|
|
@ -2,13 +2,17 @@ package com.win.module.wms.service.purchaseprice; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
|
import com.win.framework.datapermission.core.util.DataPermissionUtils; |
|
|
|
import com.win.module.wms.controller.bom.vo.BomImportErrorVO; |
|
|
|
import com.win.module.wms.controller.purchaseprice.vo.*; |
|
|
|
import com.win.module.wms.convert.bom.BomConvert; |
|
|
|
import com.win.module.wms.convert.purchaseprice.PurchasepriceConvert; |
|
|
|
import com.win.module.wms.dal.dataobject.bom.BomDO; |
|
|
|
import com.win.module.wms.dal.dataobject.owner.OwnerDO; |
|
|
|
import com.win.module.wms.dal.dataobject.purchaseprice.PurchasepriceDO; |
|
|
|
import com.win.module.wms.dal.mysql.purchaseprice.PurchasepriceMapper; |
|
|
@ -89,68 +93,80 @@ public class PurchasepriceServiceImpl implements PurchasepriceService { |
|
|
|
return purchasepriceMapper.selectList(exportReqVO); |
|
|
|
} |
|
|
|
|
|
|
|
private String validatePurchasepriceImport( PurchasepriceDO purchaseprice ){ |
|
|
|
StringBuilder message = new StringBuilder(); |
|
|
|
try { |
|
|
|
validatePurchasepriceExists(null); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
try { |
|
|
|
validateCodeExists(null, purchaseprice.getItemCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
try { |
|
|
|
validateSupplierCodeExists(purchaseprice.getSupplierCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
try { |
|
|
|
validateCurrencyExists(purchaseprice.getCurrency()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
try { |
|
|
|
validatePriceExists(purchaseprice.getPrice()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
try { |
|
|
|
validateAvailableExists(purchaseprice.getAvailable()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
message.append(ex.getMessage()).append(","); |
|
|
|
} |
|
|
|
return message.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<PurchasepriceDO> validatePurchaseprice( PurchasepriceDO purchaseprice){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.in("supplier_code", purchaseprice.getSupplierCode()); |
|
|
|
queryWrapper.in("item_code", purchaseprice.getItemCode()); |
|
|
|
queryWrapper.in("available",purchaseprice.getAvailable()); |
|
|
|
List<PurchasepriceDO> purchasepriceDO = purchasepriceMapper.selectList(queryWrapper); |
|
|
|
return purchasepriceDO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<PurchasepriceImportExcelVO> importPurchasepriceList(List<PurchasepriceImportExcelVO> purchaseprices, Integer mode, Boolean updatePart) { |
|
|
|
public List<PurchasepriceImportErrorVO> importPurchasepriceList(List<PurchasepriceImportExcelVO> purchaseprices, Integer mode, Boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(purchaseprices)) { |
|
|
|
throw exception(PURCHASEPRICE_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
List<PurchasepriceImportExcelVO> errorList = new ArrayList<>(); |
|
|
|
List<PurchasepriceImportErrorVO> errorList = new ArrayList<>(); |
|
|
|
purchaseprices.forEach(purchaseprice -> { |
|
|
|
// 校验,判断是否有不符合的原因
|
|
|
|
String massage = ""; |
|
|
|
if(mode != null) { |
|
|
|
try { |
|
|
|
validatePurchasepriceExists(null); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
validateCodeExists(null, purchaseprice.getItemCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
validateSupplierCodeExists(purchaseprice.getSupplierCode()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
validateCurrencyExists(purchaseprice.getCurrency()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
validatePriceExists(purchaseprice.getPrice()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
try { |
|
|
|
validateAvailableExists(purchaseprice.getAvailable()); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
massage += ex.getMessage() + ","; |
|
|
|
} |
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(massage)) { |
|
|
|
massage.substring(0, massage.length() - 1); |
|
|
|
errorList.add(purchaseprice); |
|
|
|
} |
|
|
|
if (errorList == null) { |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
OwnerDO existConfigurationSetting = null; |
|
|
|
if (existConfigurationSetting == null && mode != 3) { |
|
|
|
purchasepriceMapper.insert(PurchasepriceConvert.INSTANCE.convert(purchaseprice)); |
|
|
|
} else if (existConfigurationSetting != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
PurchasepriceDO purchasepriceDo = PurchasepriceConvert.INSTANCE.convert(purchaseprice); |
|
|
|
purchasepriceDo.setId(existConfigurationSetting.getId()); |
|
|
|
purchasepriceMapper.updateById(purchasepriceDo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
PurchasepriceDO purchasepriceDO = PurchasepriceConvert.INSTANCE.convert(purchaseprice); |
|
|
|
String message = this.validatePurchasepriceImport(purchasepriceDO); |
|
|
|
boolean flag = true; |
|
|
|
if(!message.isEmpty()){ |
|
|
|
PurchasepriceImportErrorVO importErrorVO = PurchasepriceConvert.INSTANCE.convert2(purchasepriceDO); |
|
|
|
importErrorVO.setImportStatus("失败"); |
|
|
|
importErrorVO.setImportRemark(message.substring(0, message.length() - 1)); |
|
|
|
errorList.add(importErrorVO); |
|
|
|
flag = false; |
|
|
|
} |
|
|
|
if(flag) { |
|
|
|
List<PurchasepriceDO> PurchasepriceDO = validatePurchaseprice(purchasepriceDO); |
|
|
|
for(PurchasepriceDO purchase: PurchasepriceDO){ |
|
|
|
purchase.setAvailable("FALSE"); |
|
|
|
} |
|
|
|
if(!PurchasepriceDO.isEmpty()) { |
|
|
|
purchasepriceMapper.updateBatch(PurchasepriceDO); |
|
|
|
} |
|
|
|
purchasepriceMapper.insert(purchasepriceDO); |
|
|
|
} |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if(!errorList.isEmpty() && !updatePart) { |
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} |
|
|
|
return errorList; |
|
|
|
} |
|
|
|
private void validatePurchasepriceForCreateOrUpdate(Long id,String supplierCode,String itemCode, String currency,BigDecimal price,String available) { |
|
|
|