@ -5,22 +5,28 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaotao.common.utils.DateUtils ;
import com.gaotao.common.utils.PageUtils ;
import com.gaotao.modules.inventoryStock.entity.InventoryStockOutData ;
import com.gaotao.modules.pms.data.QcDetailReport ;
import com.gaotao.modules.sys.entity.SysUserEntity ;
import com.gaotao.modules.trans.entity.TransNoControl ;
import com.gaotao.modules.trans.service.TransNoControlService ;
import com.gaotao.modules.wms.dao.WmsPrintDao ;
import com.gaotao.modules.wms.data.InboundQcResultData ;
import com.gaotao.modules.wms.data.PoOrderRollNoOutData ;
import com.gaotao.modules.wms.entity.PoOrderRollNoImportData ;
import com.gaotao.modules.wms.service.WmsPrintService ;
import org.apache.poi.xssf.usermodel.XSSFRow ;
import org.apache.poi.xssf.usermodel.XSSFSheet ;
import org.apache.poi.xssf.usermodel.XSSFWorkbook ;
import org.apache.shiro.SecurityUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.web.multipart.MultipartFile ;
import java.io.InputStream ;
import java.math.BigDecimal ;
import java.text.SimpleDateFormat ;
import java.util.List ;
import java.util.stream.Collectors ;
import java.util.Map ;
/ * *
* @CLASSNAME WmsPrintServiceImpl
@ -137,4 +143,150 @@ public class WmsPrintServiceImpl implements WmsPrintService {
public List < InventoryStockOutData > getWarehouseList ( InventoryStockOutData inData ) {
return wmsPrintDao . getWarehouseList ( inData ) ;
}
@Override
@Transactional
public void uploadPoPartPrintExcel ( MultipartFile file , PoOrderRollNoImportData importData ) {
InputStream is = null ;
XSSFWorkbook workbook = null ;
try {
/ / 转流
is = file . getInputStream ( ) ;
/ / 读取工作簿
workbook = new XSSFWorkbook ( is ) ;
/ / 读取工作表
XSSFSheet sheet = workbook . getSheetAt ( 0 ) ;
/ / 获取行数
int rows = sheet . getPhysicalNumberOfRows ( ) ;
/ / 查询物料有效期信息 ( 只需查询一次 )
PoOrderRollNoOutData partInfo = wmsPrintDao . getPartExpirationInfo (
importData . getSite ( ) ,
importData . getBuNo ( ) ,
importData . getPartNo ( )
) ;
/ / 遍历每一行 ( 从第二行开始 )
for ( int j = 1 ; j < rows ; j + + ) {
/ / 获得该行
XSSFRow row = sheet . getRow ( j ) ;
if ( row = = null ) {
continue ;
}
/ / 创建保存对象
PoOrderRollNoOutData saveData = new PoOrderRollNoOutData ( ) ;
/ / 从主信息行获取的字段
saveData . setSite ( importData . getSite ( ) ) ;
saveData . setBuNo ( importData . getBuNo ( ) ) ;
saveData . setInspectionNo ( importData . getInspectionNo ( ) ) ;
saveData . setOrderNo ( importData . getPoOrderNo ( ) ) ;
saveData . setItemNo ( importData . getPoItemNo ( ) ) ;
saveData . setPartNo ( importData . getPartNo ( ) ) ;
saveData . setPartDesc ( importData . getPartDesc ( ) ) ;
saveData . setSupplierId ( importData . getSupplierId ( ) ) ;
saveData . setSupplierName ( importData . getSupplierName ( ) ) ;
saveData . setOrderQty ( importData . getOrderQty ( ) ) ;
/ / 从Excel中读取的字段
/ / 标签条码 ( roll_no ) - 第1列 ( 索引0 )
String rollNo = null ;
if ( row . getCell ( 0 ) ! = null ) {
if ( row . getCell ( 0 ) . getCellType ( ) = = org . apache . poi . ss . usermodel . CellType . NUMERIC ) {
/ / 如果是数字类型 , 转换为字符串
rollNo = String . valueOf ( ( long ) row . getCell ( 0 ) . getNumericCellValue ( ) ) ;
} else {
rollNo = row . getCell ( 0 ) . getStringCellValue ( ) ;
}
} else {
throw new RuntimeException ( "第" + ( j + 1 ) + "行:标签条码不能为空" ) ;
}
/ / 校验标签条码是否重复
int existCount = wmsPrintDao . checkRollNoExists ( importData . getSite ( ) , rollNo ) ;
if ( existCount > 0 ) {
throw new RuntimeException ( "第" + ( j + 1 ) + "行:标签条码 [" + rollNo + "] 已存在,不能重复导入" ) ;
}
saveData . setRollNo ( rollNo ) ;
/ / 标签数量 ( roll_qty ) - 第2列 ( 索引1 )
if ( row . getCell ( 1 ) ! = null ) {
saveData . setRollQty ( new BigDecimal ( row . getCell ( 1 ) . getNumericCellValue ( ) ) ) ;
} else {
throw new RuntimeException ( "第" + ( j + 1 ) + "行:标签数量不能为空" ) ;
}
/ / 批次号 ( batch_no ) - 第3列 ( 索引2 )
if ( row . getCell ( 2 ) ! = null ) {
if ( row . getCell ( 2 ) . getCellType ( ) = = org . apache . poi . ss . usermodel . CellType . NUMERIC ) {
saveData . setBatchNo ( String . valueOf ( ( long ) row . getCell ( 2 ) . getNumericCellValue ( ) ) ) ;
} else {
String batchNo = row . getCell ( 2 ) . getStringCellValue ( ) ;
/ / 如果批次号是 * 则设置为空字符串
saveData . setBatchNo ( "*" . equals ( batchNo ) ? "" : batchNo ) ;
}
} else {
saveData . setBatchNo ( "" ) ;
}
/ / 生产日期 ( production_date ) - 第4列 ( 索引3 )
if ( row . getCell ( 3 ) ! = null ) {
if ( row . getCell ( 3 ) . getCellType ( ) = = org . apache . poi . ss . usermodel . CellType . NUMERIC ) {
saveData . setProductionDate ( row . getCell ( 3 ) . getDateCellValue ( ) ) ;
} else {
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
saveData . setProductionDate ( sdf . parse ( row . getCell ( 3 ) . getStringCellValue ( ) ) ) ;
}
} else {
throw new RuntimeException ( "第" + ( j + 1 ) + "行:生产日期不能为空" ) ;
}
/ / 默认值字段
saveData . setCreatedBy ( importData . getCreateBy ( ) ) ;
saveData . setDelflag ( "N" ) ;
saveData . setVersion ( 0 ) ;
saveData . setPrintFlag ( 0 ) ;
saveData . setHardtagInFlag ( "未入库" ) ;
/ / 计算有效期相关日期
if ( partInfo ! = null & & "Y" . equals ( partInfo . getExpirationFlag ( ) ) & & saveData . getProductionDate ( ) ! = null ) {
if ( partInfo . getExpirationDay ( ) ! = null & & partInfo . getExpirationDay ( ) > 0 ) {
saveData . setExpirationDate ( DateUtils . addDateDays ( saveData . getProductionDate ( ) , partInfo . getExpirationDay ( ) ) ) ;
}
if ( partInfo . getExpirationWarningDay ( ) ! = null & & partInfo . getExpirationWarningDay ( ) > 0 ) {
saveData . setExpirationWarningDate ( DateUtils . addDateDays ( saveData . getProductionDate ( ) , partInfo . getExpirationWarningDay ( ) ) ) ;
}
}
/ / 保存数据
wmsPrintDao . savePoOrderRollNo ( saveData ) ;
}
} catch ( Exception e ) {
throw new RuntimeException ( "导入失败:" + e . getMessage ( ) ) ;
} finally {
try {
if ( workbook ! = null ) {
workbook . close ( ) ;
}
if ( is ! = null ) {
is . close ( ) ;
}
} catch ( Exception e ) {
/ / 忽略关闭异常
}
}
}
@Override
public Map < String , Object > queryFileId ( Map < String , String > params ) {
String orderRef1 = params . get ( "orderRef1" ) ;
String orderRef2 = params . get ( "orderRef2" ) ;
Map < String , Object > result = wmsPrintDao . queryFileId ( orderRef1 , orderRef2 ) ;
if ( result = = null ) {
throw new RuntimeException ( "未找到模板文件" ) ;
}
return result ;
}
}