@ -1,9 +1,7 @@
package com.ruoyi.quality.service.impl ;
import java.text.DecimalFormat ;
import java.text.SimpleDateFormat ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.List ;
import com.ruoyi.common.core.redis.RedisCache ;
@ -16,9 +14,12 @@ import com.ruoyi.quality.domain.QualityRefundsExchangesUnqualified;
import com.ruoyi.quality.domain.VO.QualityRefundsExchangesExportVO ;
import com.ruoyi.quality.mapper.QualityRefundsExchangesDetailMapper ;
import com.ruoyi.quality.mapper.QualityRefundsExchangesUnqualifiedMapper ;
import com.ruoyi.storehouse.domain.WarehousingInInfo ;
import com.ruoyi.warehouse.domain.WarehouseOutOrder ;
import com.ruoyi.warehouse.domain.WarehouseOutOrderDetail ;
import com.ruoyi.warehouse.domain.WarehouseStorageOrder ;
import com.ruoyi.warehouse.domain.WarehouseStorageOrderDetail ;
import com.ruoyi.warehouse.mapper.WarehouseOutOrderDetailMapper ;
import com.ruoyi.warehouse.mapper.WarehouseOutOrderMapper ;
import com.ruoyi.warehouse.mapper.WarehouseStorageOrderDetailMapper ;
import com.ruoyi.warehouse.mapper.WarehouseStorageOrderMapper ;
import lombok.extern.slf4j.Slf4j ;
@ -29,6 +30,7 @@ import com.ruoyi.quality.domain.QualityRefundsExchanges;
import com.ruoyi.quality.service.IQualityRefundsExchangesService ;
import com.ruoyi.common.core.text.Convert ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.CollectionUtils ;
/ * *
* 品质管理退换货单Service业务层处理
@ -56,7 +58,10 @@ public class QualityRefundsExchangesServiceImpl implements IQualityRefundsExchan
private WarehouseStorageOrderDetailMapper warehouseStorageOrderDetailMapper ;
@Autowired
private WarehouseStorageOrderDetailMapper storageOrderDetailMapper ;
private WarehouseOutOrderMapper warehouseOutOrderMapper ;
@Autowired
private WarehouseOutOrderDetailMapper warehouseOutOrderDetailMapper ;
@Autowired
private RedisCache redisCache ;
@ -91,6 +96,7 @@ public class QualityRefundsExchangesServiceImpl implements IQualityRefundsExchan
* @param qualityRefundsExchanges 品质管理退换货单
* @return 结果
* /
@Transactional ( rollbackFor = Exception . class )
@Override
public int insertQualityRefundsExchanges ( QualityRefundsExchanges qualityRefundsExchanges )
{
@ -143,7 +149,7 @@ public class QualityRefundsExchangesServiceImpl implements IQualityRefundsExchan
List < WarehouseStorageOrderDetail > warehouseStorageOrderDetails = createWarehouseStorageDetail ( qualityRefundsExchanges , warehouseStorageOrder . getWarehouseStorageCode ( ) ) ;
warehouseStorageOrderMapper . batchWarehouseStorageOrderDetail ( warehouseStorageOrderDetails ) ;
qualityRefundsExchanges . setQualityWarehouseStatus ( "0 " ) ;
qualityRefundsExchanges . setQualityWarehouseStatus ( "1 " ) ;
qualityRefundsExchanges . setInStorageCode ( warehouseStorageOrder . getWarehouseStorageCode ( ) ) ;
qualityRefundsExchangesMapper . insertQualityRefundsExchanges ( qualityRefundsExchanges ) ;
return 1 ;
@ -281,10 +287,38 @@ public class QualityRefundsExchangesServiceImpl implements IQualityRefundsExchan
return 1 ;
}
/ * *
* 保存入库前退货 - 确认供应商 - 有供应商
* /
@Transactional ( rollbackFor = Exception . class )
@Override
public int updateBeforeConfirmSupplier ( QualityRefundsExchanges qualityRefundsExchanges )
{
QualityRefundsExchanges refundsExchanges = qualityRefundsExchangesMapper . selectQualityRefundsExchangesById ( qualityRefundsExchanges . getRefundsExchangesId ( ) ) ;
List < QualityRefundsExchangesDetail > details = refundsExchangesDetailMapper . selectRefundsExchangesDetailListByCode ( refundsExchanges . getRefundsExchangesCode ( ) ) ;
if ( CollectionUtils . isEmpty ( details ) ) {
throw new BusinessException ( "退换货详情为空!" ) ;
}
refundsExchanges . setRefundsExchangesDetails ( details ) ;
WarehouseOutOrder warehouseOutOrder = generateWarehouseOutOrder ( refundsExchanges ) ;
int insertOutResult = warehouseOutOrderMapper . insertWarehouseOutOrder ( warehouseOutOrder ) ;
if ( insertOutResult < = 0 ) {
throw new BusinessException ( "新增退换货出库单失败!" ) ;
}
qualityRefundsExchanges . setQualityWarehouseStatus ( "2" ) ;
String loginName = ShiroUtils . getLoginName ( ) ;
qualityRefundsExchanges . setUpdateBy ( loginName ) ;
qualityRefundsExchanges . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
int updateResult = qualityRefundsExchangesMapper . updateQualityRefundsExchanges ( qualityRefundsExchanges ) ;
return updateResult ;
}
/ * *
* 保存入库后退货 - 选择供应商 - 无供应商
* /
@Transactional
@Transactional ( rollbackFor = Exception . class )
@Override
public int updateAfterNoConfirmSupplier ( QualityRefundsExchanges qualityRefundsExchanges ) {
String loginName = ShiroUtils . getLoginName ( ) ;
@ -317,13 +351,85 @@ public class QualityRefundsExchangesServiceImpl implements IQualityRefundsExchan
//更新数据库记录
updateRows + = refundsExchangesDetailMapper . updateQualityRefundsExchangesDetail ( refundsExchangesDetail ) ;
}
WarehouseOutOrder warehouseOutOrder = generateWarehouseOutOrder ( qualityRefundsExchanges ) ;
int insertOutResult = warehouseOutOrderMapper . insertWarehouseOutOrder ( warehouseOutOrder ) ;
if ( insertOutResult < = 0 ) {
throw new BusinessException ( "新增退换货出库单失败!" ) ;
}
qualityRefundsExchanges . setQualityPurchaseStatus ( "1" ) ;
qualityRefundsExchanges . setUpdateBy ( loginName ) ;
qualityRefundsExchanges . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
qualityRefundsExchangesMapper . updateQualityRefundsExchanges ( qualityRefundsExchanges ) ;
qualityRefundsExchanges . setOutStorageCode ( warehouseOutOrder . getOutOrderCode ( ) ) ;
int updateResult = qualityRefundsExchangesMapper . updateQualityRefundsExchanges ( qualityRefundsExchanges ) ;
if ( updateResult < = 0 ) {
throw new BusinessException ( "更新退换货订单失败!" ) ;
}
return updateRows ;
}
// 根据退换货订单生成出库单
public WarehouseOutOrder generateWarehouseOutOrder ( QualityRefundsExchanges refundsExchanges ) {
WarehouseOutOrder warehouseOutOrder = new WarehouseOutOrder ( ) ;
String outOrderCode = redisCache . generateBillNo ( "CK" ) ;
warehouseOutOrder . setOutOrderCode ( outOrderCode ) ;
warehouseOutOrder . setWarehouseOutStatus ( "4" ) ; //出库状态:待出库
warehouseOutOrder . setWarehouseOrderType ( "4" ) ; //出库订单类型:退换货订单
warehouseOutOrder . setWarehouseOutType ( "4" ) ; //出库类型:公司退货
warehouseOutOrder . setRelatedOrderCode ( refundsExchanges . getRefundsExchangesCode ( ) ) ;
warehouseOutOrder . setBusinessName ( ShiroUtils . getLoginName ( ) ) ;
warehouseOutOrder . setMaterialSum ( refundsExchanges . getMaterialTotal ( ) ) ;
warehouseOutOrder . setEnterpriseSum ( refundsExchanges . getNumTotal ( ) ) ;
warehouseOutOrder . setApplyName ( ShiroUtils . getLoginName ( ) ) ;
warehouseOutOrder . setCreateBy ( ShiroUtils . getLoginName ( ) ) ;
warehouseOutOrder . setCreateTime ( DateUtils . getNowDate ( ) ) ;
int insertResult = 0 ;
List < QualityRefundsExchangesDetail > refundsExchangesDetails = refundsExchanges . getRefundsExchangesDetails ( ) ;
if ( CollectionUtils . isEmpty ( refundsExchangesDetails ) ) {
throw new BusinessException ( "新增出库单详情失败!退换货详情数据为空!" ) ;
}
for ( QualityRefundsExchangesDetail detail : refundsExchangesDetails ) {
insertResult + = generateWarehouseOutOrderDetail ( detail , outOrderCode ) ;
}
if ( insertResult ! = refundsExchangesDetails . size ( ) ) {
throw new BusinessException ( "新增出库单详情失败!" ) ;
}
return warehouseOutOrder ;
}
// 根据退换货单详情生成出库单详情
public int generateWarehouseOutOrderDetail ( QualityRefundsExchangesDetail exchangeDetail , String outOrderCode ) {
WarehouseOutOrderDetail outOrderDetail = new WarehouseOutOrderDetail ( ) ;
outOrderDetail . setOutOrderCode ( outOrderCode ) ;
outOrderDetail . setRelatedOrderCode ( exchangeDetail . getRefundsExchangesCode ( ) ) ;
outOrderDetail . setWarehouseOutStatus ( "4" ) ; //出库状态:待出库
outOrderDetail . setWarehouseOrderType ( "4" ) ; //出库订单类型:退换货订单
outOrderDetail . setWarehouseOutType ( "4" ) ; //出库类型:公司退货
outOrderDetail . setBusinessName ( ShiroUtils . getLoginName ( ) ) ;
outOrderDetail . setMaterialNo ( exchangeDetail . getMaterialNo ( ) ) ;
outOrderDetail . setMaterialName ( exchangeDetail . getMaterialName ( ) ) ;
outOrderDetail . setMaterialType ( exchangeDetail . getMaterialType ( ) ) ;
outOrderDetail . setMaterialPhotourl ( exchangeDetail . getMaterialPhotourl ( ) ) ;
outOrderDetail . setMaterialBrand ( exchangeDetail . getMaterialBrand ( ) ) ;
outOrderDetail . setMaterialUnit ( exchangeDetail . getMaterialUnit ( ) ) ;
outOrderDetail . setMaterialDescribe ( exchangeDetail . getMaterialDescribe ( ) ) ;
outOrderDetail . setMaterialProcessMethod ( exchangeDetail . getMaterialProcessMethod ( ) ) ;
outOrderDetail . setMaterialSum ( exchangeDetail . getMaterialTotal ( ) ) ;
outOrderDetail . setEnterpriseSum ( exchangeDetail . getNumTotal ( ) ) ;
outOrderDetail . setApplyOutOrderSum ( exchangeDetail . getRefundsExchangesNum ( ) ) ;
outOrderDetail . setSupplierCode ( exchangeDetail . getSupplierCode ( ) ) ;
outOrderDetail . setSupplierName ( exchangeDetail . getSupplierName ( ) ) ;
outOrderDetail . setDeliveryName ( exchangeDetail . getCustomerContact ( ) ) ;
outOrderDetail . setDeliveryNumber ( exchangeDetail . getContactNumber ( ) ) ;
outOrderDetail . setDeliveryAddress ( exchangeDetail . getSupplierAddress ( ) ) ;
outOrderDetail . setApplyName ( ShiroUtils . getLoginName ( ) ) ;
outOrderDetail . setCreateBy ( ShiroUtils . getLoginName ( ) ) ;
outOrderDetail . setCreateTime ( DateUtils . getNowDate ( ) ) ;
int insertResult = warehouseOutOrderDetailMapper . insertWarehouseOutOrderDetail ( outOrderDetail ) ;
return insertResult ;
}
/ * *
* 保存入库前退货 - 确认收货
* /