@@ -10,9 +10,13 @@ import org.nl.exception.BadRequestException;
import org.nl.modules.security.service.dto.JwtUserDto ;
import org.nl.modules.system.util.CodeUtil ;
import org.nl.wms.basedata.master.service.ClassstandardService ;
import org.nl.wms.basedata.st.service.StorattrService ;
import org.nl.wms.basedata.st.service.dto.StorattrDto ;
import org.nl.wms.sb.core.service.impl.SparePartInServiceImpl ;
import org.nl.wms.sb.repair.service.DevicerepairmstService ;
import org.nl.wms.sb.repair.service.dto.DevicerepairmstDto ;
import org.nl.wql.WQL ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
@@ -43,6 +47,8 @@ import cn.hutool.core.util.ObjectUtil;
@Slf4j
public class DevicerepairmstServiceImpl implements DevicerepairmstService {
private final ClassstandardService classstandardService ;
private final StorattrService storattrService ;
private final SparePartInServiceImpl sparePartInService ;
@Override
public Map < String , Object > queryAll ( Map whereJson , Pageable page ) {
@@ -514,6 +520,7 @@ public class DevicerepairmstServiceImpl implements DevicerepairmstService {
String material_id = whereJson . getString ( " material_id " ) ;
String device_id = whereJson . getString ( " device_id " ) ;
String device_code = whereJson . getString ( " device_code " ) ;
String repair_dtl_id = whereJson . getString ( " repair_dtl_id " ) ;
int qty = whereJson . getIntValue ( " qty " ) ;
WQLObject itemTab = WQLObject . getWQLObject ( " EM_BI_DeviceRepairItems " ) ;
@@ -542,8 +549,186 @@ public class DevicerepairmstServiceImpl implements DevicerepairmstService {
jsonObject . put ( " repair_item_code " , jsonItem . getString ( " repair_item_code " ) ) ;
jsonObject . put ( " device_id " , device_id ) ;
jsonObject . put ( " device_code " , device_code ) ;
jsonObject . put ( " repair_dtl_id " , repair_dtl_id ) ;
}
return resultArr ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void submitReceive ( JSONObject whereJson ) {
JSONObject jsonMst = whereJson . getJSONObject ( " mst " ) ; // 维修单主表
JSONArray tableData = whereJson . getJSONArray ( " tableData " ) ; // 更换备件明细
WQLObject recoudTab = WQLObject . getWQLObject ( " EM_BI_DeviceRepairReplaceRecord " ) ; // 设备维修单更换记录表
WQLObject spareBOMTab = WQLObject . getWQLObject ( " EM_BI_EquipmentSpareBOM " ) ; // 设备档案BOM备件表
WQLObject mst_wql = WQLObject . getWQLObject ( " EM_BI_IOStorInv " ) ; // 出入库主表
WQLObject dtl_wql = WQLObject . getWQLObject ( " EM_BI_IOStorInvDtl " ) ; // 出入库明细表
WQLObject dis_wql = WQLObject . getWQLObject ( " EM_BI_IOStorInvDis " ) ; // 出入库分配表
Long currentUserId = SecurityUtils . getCurrentUserId ( ) ;
String nickName = SecurityUtils . getNickName ( ) ;
String now = DateUtil . now ( ) ;
JSONObject stor = WQLObject . getWQLObject ( " st_ivt_bsrealstorattr " ) . query ( " is_attachment = '1' " ) . uniqueResult ( 0 ) ;
String stor_id = stor . getString ( " stor_id " ) ;
// 出库单主表标识
String iostorinv_id = IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) + " " ;
for ( int i = 0 ; i < tableData . size ( ) ; i + + ) {
JSONObject json = tableData . getJSONObject ( i ) ;
// 插入设备维修单更换记录表
JSONObject jsonRecord = new JSONObject ( ) ;
jsonRecord . put ( " repair_recode_id " , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) ) ;
jsonRecord . put ( " repair_dtl_id " , json . get ( " repair_dtl_id " ) ) ;
jsonRecord . put ( " repair_id " , jsonMst . get ( " repair_id " ) ) ;
jsonRecord . put ( " repair_item_id " , json . get ( " repair_item_id " ) ) ;
jsonRecord . put ( " old_sparepart_only_id " , json . get ( " sparepart_only_id " ) ) ;
jsonRecord . put ( " new_sparepart_only_id " , json . get ( " change_only_id " ) ) ;
jsonRecord . put ( " material_id " , json . get ( " material_id " ) ) ;
jsonRecord . put ( " pcsn " , json . getString ( " pcsn " ) ) ;
jsonRecord . put ( " real_qty " , json . get ( " qty " ) ) ;
jsonRecord . put ( " qty_unit_id " , json . get ( " qty_unit_id " ) ) ;
jsonRecord . put ( " qty_unit_name " , json . get ( " qty_unit_name " ) ) ;
recoudTab . insert ( jsonRecord ) ;
// 如果维修更换记录表中 ‘原备件唯一标识为空’ 则插入 ‘ 设备档案BOM备件表’
String old_sparepart_only_id = jsonRecord . getString ( " old_sparepart_only_id " ) ;
if ( ObjectUtil . isEmpty ( old_sparepart_only_id ) ) {
JSONObject jsonSpareBom = new JSONObject ( ) ;
jsonSpareBom . put ( " device_file_spare_id " , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) ) ;
jsonSpareBom . put ( " devicerecord_id " , jsonMst . get ( " devicerecord_id " ) ) ;
jsonSpareBom . put ( " sparepart_only_id " , json . get ( " change_only_id " ) ) ;
jsonSpareBom . put ( " material_id " , json . get ( " material_id " ) ) ;
jsonSpareBom . put ( " pcsn " , json . getString ( " pcsn " ) ) ;
jsonSpareBom . put ( " qty " , json . get ( " qty " ) ) ;
jsonSpareBom . put ( " qty_unit_id " , json . get ( " qty_unit_id " ) ) ;
jsonSpareBom . put ( " qty_unit_name " , json . getString ( " qty_unit_name " ) ) ;
spareBOMTab . insert ( jsonSpareBom ) ;
} else {
JSONObject jsonSpareBom = spareBOMTab . query ( " sparepart_only_id = ' " + old_sparepart_only_id + " ' " ) . uniqueResult ( 0 ) ;
jsonSpareBom . put ( " sparepart_only_id " , json . get ( " change_only_id " ) ) ;
jsonSpareBom . put ( " material_id " , json . get ( " material_id " ) ) ;
jsonSpareBom . put ( " pcsn " , json . getString ( " pcsn " ) ) ;
jsonSpareBom . put ( " qty " , json . get ( " qty " ) ) ;
jsonSpareBom . put ( " qty_unit_id " , json . get ( " qty_unit_id " ) ) ;
jsonSpareBom . put ( " qty_unit_name " , json . getString ( " qty_unit_name " ) ) ;
spareBOMTab . update ( jsonSpareBom ) ;
}
// 插入备件出入库明细
JSONObject dis_jo = new JSONObject ( ) ;
//判断该分配是否存在明细
JSONObject dtl = dtl_wql . query ( " iostorinv_id = ' " + iostorinv_id + " ' AND material_id = ' " + json . getString ( " material_id " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( dtl ) ) {
//插入一条入库明细
dtl = new JSONObject ( ) ;
dtl . put ( " iostorinvdtl_id " , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) + " " ) ;
dtl . put ( " iostorinv_id " , iostorinv_id ) ;
JSONArray dtl_rows = dtl_wql . query ( " iostorinv_id = ' " + iostorinv_id + " ' " ) . getResultJSONArray ( 0 ) ;
dtl . put ( " seq_no " , ( dtl_rows . size ( ) + 1 ) + " " ) ;
dtl . put ( " bill_status " , " 40 " ) ;
dtl . put ( " material_id " , json . get ( " material_id " ) ) ;
dtl . put ( " pcsn " , json . getString ( " pcsn " ) ) ;
dtl . put ( " qty_unit_id " , json . get ( " qty_unit_id " ) ) ;
dtl . put ( " qty_unit_name " , json . getString ( " qty_unit_name " ) ) ;
dtl . put ( " source_billdtl_id " , jsonMst . getString ( " repair_id " ) ) ;
dtl . put ( " base_billdtl_id " , jsonMst . getString ( " repair_id " ) ) ;
dtl . put ( " source_bill_type " , jsonMst . getString ( " maintenancecycle " ) ) ;
dtl . put ( " base_bill_type " , jsonMst . getString ( " maintenancecycle " ) ) ;
dtl . put ( " source_bill_code " , jsonMst . getString ( " repair_code " ) ) ;
dtl . put ( " base_bill_code " , jsonMst . getString ( " repair_code " ) ) ;
dtl . put ( " source_bill_table " , " EM_BI_DeviceRepairMst " ) ;
dtl . put ( " base_bill_table " , " EM_BI_DeviceRepairMst " ) ;
dtl . put ( " plan_qty " , " 1 " ) ;
dtl . put ( " real_qty " , " 1 " ) ;
WQLObject . getWQLObject ( " EM_BI_IOStorInvDtl " ) . insert ( dtl ) ;
} else {
dtl . put ( " plan_qty " , dtl . getDoubleValue ( " plan_qty " ) + 1 ) ;
dtl . put ( " real_qty " , dtl . getDoubleValue ( " real_qty " ) + 1 ) ;
WQLObject . getWQLObject ( " EM_BI_IOStorInvDtl " ) . update ( dtl ) ;
}
dis_jo . put ( " iostorinvdis_id " , IdUtil . getSnowflake ( 1 , 1 ) . nextId ( ) ) ;
dis_jo . put ( " iostorinv_id " , iostorinv_id ) ;
dis_jo . put ( " iostorinvdtl_id " , dtl . getString ( " iostorinvdtl_id " ) ) ;
dis_jo . put ( " disseq_no " , i + 1 ) ;
dis_jo . put ( " material_id " , dtl . getString ( " material_id " ) ) ;
dis_jo . put ( " pcsn " , " 999999 " ) ;
dis_jo . put ( " real_qty " , json . get ( " qty " ) ) ;
dis_jo . put ( " work_status " , " 99 " ) ;
dis_jo . put ( " qty_unit_id " , dtl . getString ( " qty_unit_id " ) ) ;
dis_jo . put ( " qty_unit_name " , dtl . getString ( " qty_unit_name " ) ) ;
JSONObject jsonIvt = WQLObject . getWQLObject ( " ST_IVT_StructIvt " ) . query ( " stor_id = ' " + stor . getString ( " stor_id " ) + " ' and material_id = ' " + json . getString ( " material_id " ) + " ' and pcsn = ' " + json . getString ( " pcsn " ) + " ' " ) . uniqueResult ( 0 ) ;
if ( ObjectUtil . isEmpty ( jsonIvt ) ) throw new BadRequestException ( " 库存不足 " ) ;
JSONObject struct = WQLObject . getWQLObject ( " st_ivt_structattr " ) . query ( " struct_id = ' " + jsonIvt . getString ( " struct_id " ) + " ' " ) . uniqueResult ( 0 ) ;
dis_jo . put ( " sect_id " , struct . getString ( " sect_id " ) ) ;
dis_jo . put ( " sect_code " , struct . getString ( " sect_code " ) ) ;
dis_jo . put ( " sect_name " , struct . getString ( " sect_name " ) ) ;
dis_jo . put ( " struct_id " , struct . getString ( " struct_id " ) ) ;
dis_jo . put ( " struct_code " , struct . getString ( " struct_code " ) ) ;
dis_jo . put ( " struct_name " , struct . getString ( " struct_name " ) ) ;
dis_jo . put ( " sparepart_only_id " , json . get ( " change_only_id " ) ) ;
dis_jo . put ( " operate_optid " , currentUserId ) ;
dis_jo . put ( " operate_optname " , nickName ) ;
dis_jo . put ( " operate_time " , now ) ;
dis_wql . insert ( dis_jo ) ;
}
//插入主表
JSONObject io_mst = new JSONObject ( ) ;
String bill_code = CodeUtil . getNewCode ( " IO_CODE " ) ;
io_mst . put ( " iostorinv_id " , iostorinv_id ) ;
io_mst . put ( " bill_code " , bill_code ) ;
io_mst . put ( " buss_type " , " 0109 " ) ;
io_mst . put ( " io_type " , " 1 " ) ;
io_mst . put ( " bill_type " , " 010901 " ) ;
io_mst . put ( " biz_date " , DateUtil . today ( ) ) ;
StorattrDto storattrDto = storattrService . findById ( Long . parseLong ( stor_id ) ) ;
String stor_code = storattrDto . getStor_code ( ) ;
String stor_name = storattrDto . getStor_name ( ) ;
io_mst . put ( " stor_id " , stor_id ) ;
io_mst . put ( " stor_code " , stor_code ) ;
io_mst . put ( " stor_name " , stor_name ) ;
JSONArray dis_num = dis_wql . query ( " iostorinv_id = ' " + iostorinv_id + " ' " ) . getResultJSONArray ( 0 ) ;
io_mst . put ( " total_qty " , dis_num . size ( ) ) ;
JSONArray dtl_num = dtl_wql . query ( " iostorinv_id = ' " + iostorinv_id + " ' " ) . getResultJSONArray ( 0 ) ;
io_mst . put ( " detail_count " , dtl_num . size ( ) ) ;
io_mst . put ( " bill_status " , " 40 " ) ;
io_mst . put ( " create_mode " , " 01 " ) ;
io_mst . put ( " input_optid " , currentUserId + " " ) ;
io_mst . put ( " input_optname " , nickName ) ;
io_mst . put ( " input_time " , now ) ;
io_mst . put ( " update_optid " , currentUserId + " " ) ;
io_mst . put ( " update_optname " , nickName ) ;
io_mst . put ( " update_time " , now ) ;
io_mst . put ( " device_id " , jsonMst . get ( " device_id " ) ) ;
io_mst . put ( " device_code " , jsonMst . get ( " device_code " ) ) ;
io_mst . put ( " device_name " , jsonMst . get ( " device_name " ) ) ;
io_mst . put ( " is_delete " , " 0 " ) ;
io_mst . put ( " is_upload " , " 0 " ) ;
JwtUserDto currentUser = ( JwtUserDto ) SecurityUtils . getCurrentUser ( ) ;
Long deptId = currentUser . getDeptId ( ) ;
io_mst . put ( " sysdeptid " , deptId + " " ) ;
io_mst . put ( " syscompanyid " , deptId + " " ) ;
io_mst . put ( " bizdeptid " , deptId + " " ) ;
mst_wql . insert ( io_mst ) ;
sparePartInService . confirmMst ( iostorinv_id ) ;
}
@Override
public Map < String , Object > queryBom ( Map whereJson , Pageable page ) {
String sparepart_only_id = MapUtil . getStr ( whereJson , " sparepart_only_id " ) ;
HashMap < String , String > map = new HashMap < > ( ) ;
map . put ( " flag " , " 5 " ) ;
if ( ObjectUtil . isNotEmpty ( sparepart_only_id ) ) map . put ( " sparepart_only_id " , " % " + sparepart_only_id + " '% " ) ;
JSONObject jsonObject = WQL . getWO ( " EM_BI_DEVICEREPAIR001 " ) . addParamMap ( map ) . pageQuery ( WqlUtil . getHttpContext ( page ) , " " ) ;
return jsonObject ;
}
}