@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional ;
import java.util.HashMap ;
import java.util.HashSet ;
@Service
@RequiredArgsConstructor
@@ -965,85 +966,121 @@ public class MesToLmsServiceImpl implements MesToLmsService {
String SaleOrderItem = param . getString ( " SaleOrderItem " ) ;
String CustomerName = param . getString ( " CustomerName " ) ;
String DemandDate = param . getString ( " DemandDate " ) ;
double total_qty = 0 ;
double detail_count = 0 ;
String changeinv_id = IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) + " " ;
if ( ObjectUtil . isEmpty ( rows ) | | rows . size ( ) = = 0 ) {
throw new BadRequestException ( " item长度不能为0! " ) ;
}
// 定义set集合储存仓库
HashSet < String > storSet = new HashSet < > ( ) ;
for ( int i = 0 ; i < rows . size ( ) ; i + + ) {
JSONObject row = rows . getJSONObject ( i ) ;
String PackageBoxSN = row . getString ( " PackageBoxSN " ) ;
String isRePrintPackageBoxLabel = row . getString ( " isRePrintPackageBoxLabel " ) ;
String isUnPackBox = row . getString ( " isUnPackBox " ) ;
String UpdatedDateOfProduction = row . getString ( " UpdatedDateOfProduction " ) ;
//查询该木箱内子卷数量
JSONArray container_rows = WQLObject . getWQLObject ( " pdm_bi_subpackagerelation " ) . query ( " package_box_sn = ' " + PackageBoxSN + " ' " ) . getResultJSONArray ( 0 ) ;
for ( int j = 0 ; j < container_rows . size ( ) ; j + + ) {
JSONObject container_ row = container_rows . getJSONObject ( j ) ;
JSONObject change_jo = new JSONObject ( ) ;
change_jo . put ( " changeinvdtl_id " , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) + " " ) ;
change_jo . put ( " changeinv_id " , changeinv_id ) ;
change_jo . put ( " seq_no " , detail_count + 1 ) ;
JSONObject mater_jo = WQLObject . getWQLObject ( " md_me_materialbase " ) . query ( " material_code = ' " + container_row . getString ( " product_name " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( mater_jo ) )
throw new BadRequestException ( " 物料不存在: " + container_row . getString ( " product_name " ) ) ;
change_jo . put ( " material_id " , mater_jo . getString ( " material_id " ) ) ;
change_jo . put ( " pcsn " , container_row . getString ( " container_name " ) ) ;
change_jo . put ( " package_box_sn " , container_row . getString ( " package_box_sn " ) ) ;
change_jo . put ( " mfg_order_name " , SaleOrderItem ) ;
change_jo . put ( " demand_date " , DemandDate ) ;
change_jo . put ( " customer_name " , CustomerName ) ;
//查询对应的客户
JSONObject customer_jo = WQLObject . getWQLObject ( " md_cs_customerbase " ) . query ( " cust_code = ' " + CustomerName + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( customer_jo ) ) throw new BadRequestException ( " 客户不存在: " + CustomerName ) ;
change_jo . put ( " customer_description " , customer_jo . getString ( " cust_name " ) ) ;
change_jo . put ( " isRePrintPackageBoxLabel " , isRePrintPackageBoxLabel ) ;
change_jo . put ( " isUnPackBox " , isUnPackBox ) ;
change_jo . put ( " UpdatedDateOfProduction " , UpdatedDateOfProduction ) ;
JSONObject unit = WQLObject . getWQLObject ( " md_pb_measureunit " ) . query ( " measure_unit_id = ' " + mater_jo . getString ( " base_unit_id " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( unit ) )
throw new BadRequestException ( " 计量单位不存在: " + mater_jo . getString ( " base_unit_id " ) ) ;
change_jo . put ( " qty_unit_id " , mater_jo . getString ( " base_unit_id " ) ) ;
change_jo . put ( " qty_unit_name " , unit . getString ( " unit_name " ) ) ;
change_jo . put ( " qty " , container_row . getString ( " net_weight " ) ) ;
WQLObject . getWQLObject ( " ST_IVT_StructIvtChangeDtl " ) . insert ( change_jo ) ;
total_qty + = container_row . getDoubleValue ( " net_weight " ) ;
detail_count + = 1 ;
JSONObject json = rows . getJSONObject ( i ) ;
String PackageBoxSN = json . getString ( " PackageBoxSN " ) ;
// 查询此木箱在哪个仓库
JSONObject jsonBox = WQLObject . getWQLObject ( " st_ivt_structattr " )
. query ( " storagevehicle_code = ' " + PackageBoxSN + " ' and is_delete = '0' and is_used = '1' and lock_type = '1' " ) . uniqueResult ( 0 ) ;
i f ( ObjectUtil . isEmpty ( jsonBox ) ) {
th row new BadRequestException ( " 此木箱不在库内: " + PackageBoxSN ) ;
}
storSet . add ( jsonBox . getString ( " stor_code " ) ) ;
}
String currentUserId = SecurityUtils . getCurrentUserId ( ) ;
String nickName = SecurityUtils . getCurrentNickName ( ) ;
String now = DateUtil . now ( ) ;
JSONObject mst_jo = new JSONObject ( ) ;
mst_jo . put ( " changeinv_id " , changeinv_id ) ;
mst_jo . put ( " bill_code " , CodeUtil . getNewCode ( " CHANGE_CODE " ) ) ;
mst_jo . put ( " buss_type " , " 2001 " ) ;
mst_jo . put ( " bill_type " , " 2001 " ) ;
mst_jo . put ( " biz_date " , DateUtil . today ( ) ) ;
JSONObject stor = WQLObject . getWQLObject ( " st_ivt_bsrealstorattr " ) . query ( " is_delete = '0' AND is_used = '1' AND is_productstore = '1' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( stor ) ) throw new BadRequestException ( " 仓库不存在! " ) ;
mst_jo . put ( " stor_id " , stor . getString ( " stor_id " ) ) ;
mst_jo . put ( " stor_code " , stor . getString ( " stor_code " ) ) ;
mst_jo . put ( " stor_name " , stor . getString ( " stor_name " ) ) ;
mst_jo . put ( " total_qty " , total_qty ) ;
mst_jo . put ( " detail_count " , detail_count ) ;
mst_jo . put ( " bill_status " , " 10 " ) ;
mst_jo . put ( " create_mode " , " 03 " ) ;
mst_jo . put ( " input_optid " , currentUserId + " " ) ;
mst_jo . put ( " input_optname " , nickName ) ;
mst_jo . put ( " input_time " , now ) ;
mst_jo . put ( " update_optid " , currentUserId + " " ) ;
mst_jo . put ( " update_optname " , nickName ) ;
mst_jo . put ( " update_time " , now ) ;
mst_jo . put ( " is_delete " , " 0 " ) ;
mst_jo . put ( " is_upload " , " 0 " ) ;
Long deptId = SecurityUtils . getDeptId ( ) ;
mst_jo . put ( " sysdeptid " , deptId + " " ) ;
mst_jo . put ( " syscompanyid " , deptId + " " ) ;
WQLObject . getWQLObject ( " ST_IVT_StructIvtChange " ) . insert ( mst_jo ) ;
// 根据仓库生成多个库存变更单据
for ( String stor_code : storSet ) {
double total_qty = 0 ;
double detail_count = 0 ;
String changeinv_id = IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) + " " ;
JSONObject jsonStor = WQLObject . getWQLObject ( " st_ivt_bsrealstorattr " ) . query ( " stor_code = ' " + stor_code + " ' " ) . uniqueResult ( 0 ) ;
JSONArray rowsDtl = new JSONArray ( ) ;
for ( int i = 0 ; i < rows . size ( ) ; i + + ) {
JSONObject row = rows . getJSONObject ( i ) ;
String PackageBoxSN = row . getString ( " PackageBoxSN " ) ;
JSONObject jsonBox = WQLObject . getWQLObject ( " st_ivt_structattr " )
. query ( " storagevehicle_code = ' " + PackageBoxSN + " ' and is_delete = '0' and is_used = '1' and lock_type = '1' " ) . uniqueResult ( 0 ) ;
if ( StrUtil . equals ( jsonBox . getString ( " stor_code " ) , stor_code ) ) {
rowsDtl . add ( row ) ;
}
}
// 插入库存变更主表明细表
for ( int i = 0 ; i < rowsDtl . size ( ) ; i + + ) {
JSONObject row = rowsDtl . getJSONObject ( i ) ;
String PackageBoxSN = row . getString ( " PackageBoxSN " ) ;
String isRePrintPackageBoxLabel = row . getString ( " isRePrintPackageBoxLabel " ) ;
String isUnPackBox = row . getString ( " isUnPackBox " ) ;
String UpdatedDateOfProduction = row . getString ( " UpdatedDateOfProduction " ) ;
//查询该木箱内子卷数量
JSONArray container_rows = WQLObject . getWQLObject ( " pdm_bi_subpackagerelation " ) . query ( " package_box_sn = ' " + PackageBoxSN + " ' " ) . getResultJSONArray ( 0 ) ;
for ( int j = 0 ; j < container_rows . size ( ) ; j + + ) {
JSONObject container_row = container_rows . getJSONObject ( j ) ;
JSONObject change_jo = new JSONObject ( ) ;
change_jo . put ( " changeinvdtl_id " , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) + " " ) ;
change_jo . put ( " changeinv_id " , changeinv_id ) ;
change_jo . put ( " seq_no " , detail_count + 1 ) ;
JSONObject mater_jo = WQLObject . getWQLObject ( " md_me_materialbase " ) . query ( " material_code = ' " + container_row . getString ( " product_name " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( mater_jo ) )
throw new BadRequestException ( " 物料不存在: " + container_row . getString ( " product_name " ) ) ;
change_jo . put ( " material_id " , mater_jo . getString ( " material_id " ) ) ;
change_jo . put ( " pcsn " , container_row . getString ( " container_name " ) ) ;
change_jo . put ( " package_box_sn " , container_row . getString ( " package_box_sn " ) ) ;
change_jo . put ( " mfg_order_name " , SaleOrderItem ) ;
change_jo . put ( " demand_date " , DemandDate ) ;
change_jo . put ( " customer_name " , CustomerName ) ;
//查询对应的客户
JSONObject customer_jo = WQLObject . getWQLObject ( " md_cs_customerbase " ) . query ( " cust_code = ' " + CustomerName + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( customer_jo ) ) throw new BadRequestException ( " 客户不存在: " + CustomerName ) ;
change_jo . put ( " customer_description " , customer_jo . getString ( " cust_name " ) ) ;
change_jo . put ( " isRePrintPackageBoxLabel " , isRePrintPackageBoxLabel ) ;
change_jo . put ( " isUnPackBox " , isUnPackBox ) ;
change_jo . put ( " UpdatedDateOfProduction " , UpdatedDateOfProduction ) ;
JSONObject unit = WQLObject . getWQLObject ( " md_pb_measureunit " ) . query ( " measure_unit_id = ' " + mater_jo . getString ( " base_unit_id " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( unit ) )
throw new BadRequestException ( " 计量单位不存在: " + mater_jo . getString ( " base_unit_id " ) ) ;
change_jo . put ( " qty_unit_id " , mater_jo . getString ( " base_unit_id " ) ) ;
change_jo . put ( " qty_unit_name " , unit . getString ( " unit_name " ) ) ;
change_jo . put ( " qty " , container_row . getString ( " net_weight " ) ) ;
WQLObject . getWQLObject ( " ST_IVT_StructIvtChangeDtl " ) . insert ( change_jo ) ;
total_qty + = container_row . getDoubleValue ( " net_weight " ) ;
detail_count + = 1 ;
}
}
String currentUserId = SecurityUtils . getCurrentUserId ( ) ;
String nickName = SecurityUtils . getCurrentNickName ( ) ;
String now = DateUtil . now ( ) ;
JSONObject mst_jo = new JSONObject ( ) ;
mst_jo . put ( " changeinv_id " , changeinv_id ) ;
mst_jo . put ( " bill_code " , CodeUtil . getNewCode ( " CHANGE_CODE " ) ) ;
mst_jo . put ( " buss_type " , " 2001 " ) ;
mst_jo . put ( " bill_type " , " 2001 " ) ;
mst_jo . put ( " biz_date " , DateUtil . today ( ) ) ;
mst_jo . put ( " stor_id " , jsonStor . getString ( " stor_id " ) ) ;
mst_jo . put ( " stor_code " , jsonStor . getString ( " stor_code " ) ) ;
mst_jo . put ( " stor_name " , jsonStor . getString ( " stor_name " ) ) ;
mst_jo . put ( " total_qty " , total_qty ) ;
mst_jo . put ( " detail_count " , detail_count ) ;
mst_jo . put ( " bill_status " , " 10 " ) ;
mst_jo . put ( " create_mode " , " 03 " ) ;
mst_jo . put ( " input_optid " , currentUserId + " " ) ;
mst_jo . put ( " input_optname " , nickName ) ;
mst_jo . put ( " input_time " , now ) ;
mst_jo . put ( " update_optid " , currentUserId + " " ) ;
mst_jo . put ( " update_optname " , nickName ) ;
mst_jo . put ( " update_time " , now ) ;
mst_jo . put ( " is_delete " , " 0 " ) ;
mst_jo . put ( " is_upload " , " 0 " ) ;
Long deptId = SecurityUtils . getDeptId ( ) ;
mst_jo . put ( " sysdeptid " , deptId + " " ) ;
mst_jo . put ( " syscompanyid " , deptId + " " ) ;
WQLObject . getWQLObject ( " ST_IVT_StructIvtChange " ) . insert ( mst_jo ) ;
}
result . put ( " RTYPE " , " S " ) ;
result . put ( " RTMSG " , " 操作成功! " ) ;
result . put ( " RTOAL " , 1 ) ;