|
|
@ -13,18 +13,34 @@ import com.hw.jindie.api.RemoteJindieService;
|
|
|
|
import com.hw.mes.api.RemoteMesService;
|
|
|
|
import com.hw.mes.api.RemoteMesService;
|
|
|
|
import com.hw.mes.api.domain.MesBaseMaterialInfo;
|
|
|
|
import com.hw.mes.api.domain.MesBaseMaterialInfo;
|
|
|
|
import com.hw.mes.domain.MesBaseUnitInfo;
|
|
|
|
import com.hw.mes.domain.MesBaseUnitInfo;
|
|
|
|
|
|
|
|
import com.hw.mes.domain.MesMaterialBom;
|
|
|
|
import com.hw.mes.domain.MesPurchaseRequisitionTemplate;
|
|
|
|
import com.hw.mes.domain.MesPurchaseRequisitionTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.hw.mes.mapper.MesBaseMaterialInfoMapper;
|
|
|
|
import com.hw.mes.mapper.MesBaseUnitInfoMapper;
|
|
|
|
import com.hw.mes.mapper.MesBaseUnitInfoMapper;
|
|
|
|
|
|
|
|
import com.hw.mes.mapper.MesMaterialBomMapper;
|
|
|
|
import com.hw.mes.service.IMesBaseMaterialInfoService;
|
|
|
|
import com.hw.mes.service.IMesBaseMaterialInfoService;
|
|
|
|
import com.hw.mes.service.IMesImportService;
|
|
|
|
import com.hw.mes.service.IMesImportService;
|
|
|
|
|
|
|
|
import com.hw.mes.service.IMesMaterialBomService;
|
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.poi.ss.usermodel.CellType.NUMERIC;
|
|
|
|
|
|
|
|
import static org.apache.poi.ss.usermodel.CellType.STRING;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* excel导入Service业务层处理
|
|
|
|
* excel导入Service业务层处理
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -34,15 +50,17 @@ import java.util.List;
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class MesImportImpl implements IMesImportService {
|
|
|
|
public class MesImportImpl implements IMesImportService {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private IMesBaseMaterialInfoService materialInfoService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private MesBaseUnitInfoMapper mesBaseUnitInfoMapper;
|
|
|
|
private MesBaseUnitInfoMapper mesBaseUnitInfoMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RemoteJindieService remoteJindieService;
|
|
|
|
private RemoteJindieService remoteJindieService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private IMesMaterialBomService mesMaterialBomService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MesBaseMaterialInfoMapper mesBaseMaterialInfoMapper;
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(MesImportImpl.class);
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(MesImportImpl.class);
|
|
|
|
|
|
|
|
|
|
|
@ -54,6 +72,7 @@ public class MesImportImpl implements IMesImportService {
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = ServiceException.class)
|
|
|
|
public String importPurchaseRequisition(List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList, String operName) {
|
|
|
|
public String importPurchaseRequisition(List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList, String operName) {
|
|
|
|
if (StringUtils.isNull(purchaseRequisitionTemplateList) || purchaseRequisitionTemplateList.size() == 0) {
|
|
|
|
if (StringUtils.isNull(purchaseRequisitionTemplateList) || purchaseRequisitionTemplateList.size() == 0) {
|
|
|
|
throw new ServiceException("导入采购申请单数据不能为空!");
|
|
|
|
throw new ServiceException("导入采购申请单数据不能为空!");
|
|
|
@ -71,7 +90,7 @@ public class MesImportImpl implements IMesImportService {
|
|
|
|
productModel = productModel.replaceAll("[^\\w.]", "");
|
|
|
|
productModel = productModel.replaceAll("[^\\w.]", "");
|
|
|
|
MesBaseMaterialInfo materialInfo = new MesBaseMaterialInfo();
|
|
|
|
MesBaseMaterialInfo materialInfo = new MesBaseMaterialInfo();
|
|
|
|
materialInfo.setMaterialName(materialName);
|
|
|
|
materialInfo.setMaterialName(materialName);
|
|
|
|
List<MesBaseMaterialInfo> materialInfoList = materialInfoService.selectMesBaseMaterialInfoList(materialInfo);
|
|
|
|
List<MesBaseMaterialInfo> materialInfoList = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoList(materialInfo);
|
|
|
|
|
|
|
|
|
|
|
|
int successFlag = 0;
|
|
|
|
int successFlag = 0;
|
|
|
|
MesBaseMaterialInfo findMaterialInfo = new MesBaseMaterialInfo();
|
|
|
|
MesBaseMaterialInfo findMaterialInfo = new MesBaseMaterialInfo();
|
|
|
@ -126,4 +145,115 @@ public class MesImportImpl implements IMesImportService {
|
|
|
|
return successMsg.toString();
|
|
|
|
return successMsg.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 物料BOM信息excel导入
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param file
|
|
|
|
|
|
|
|
* @param updateSupport
|
|
|
|
|
|
|
|
* @param operName
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = ServiceException.class)
|
|
|
|
|
|
|
|
public String BOMImportData(MultipartFile file, boolean updateSupport, String operName) {
|
|
|
|
|
|
|
|
InputStream is = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
is = file.getInputStream();
|
|
|
|
|
|
|
|
Workbook workbook = new XSSFWorkbook(is);
|
|
|
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
|
|
|
|
int lastRowNum = sheet.getLastRowNum();
|
|
|
|
|
|
|
|
for (int i = 0; i < lastRowNum; i++) {
|
|
|
|
|
|
|
|
Row rowT = sheet.getRow(i);
|
|
|
|
|
|
|
|
if (rowT == null) {
|
|
|
|
|
|
|
|
continue; // 如果行为空,跳过
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell cellT = rowT.getCell(2);
|
|
|
|
|
|
|
|
if (StringUtils.isNull(cellT)) {
|
|
|
|
|
|
|
|
throw new ServiceException("Excel格式错误!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String productBom = cellT.getStringCellValue();
|
|
|
|
|
|
|
|
productBom = productBom.replaceAll("(.*?)", "");
|
|
|
|
|
|
|
|
MesBaseMaterialInfo productMaterial = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByMaterialCode(productBom);
|
|
|
|
|
|
|
|
if (productMaterial == null) {
|
|
|
|
|
|
|
|
throw new ServiceException("Excel格式错误:找不到父级BOM信息!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = i + 3;//标题下一行
|
|
|
|
|
|
|
|
MesMaterialBom selectBom = new MesMaterialBom();
|
|
|
|
|
|
|
|
selectBom.setMaterialId(productMaterial.getMaterialId());
|
|
|
|
|
|
|
|
selectBom.setMaterialNameDesc(productMaterial.getMaterialName());
|
|
|
|
|
|
|
|
List<MesMaterialBom> productBomList = mesMaterialBomService.selectMesMaterialBomList(selectBom);
|
|
|
|
|
|
|
|
Long parentBomId = 0L;
|
|
|
|
|
|
|
|
String parentBomDesc = productMaterial.getMaterialName();
|
|
|
|
|
|
|
|
if (productBomList.size() > 0) {
|
|
|
|
|
|
|
|
MesMaterialBom mesMaterialBom = productBomList.get(0);
|
|
|
|
|
|
|
|
parentBomId = mesMaterialBom.getMaterialBomId();
|
|
|
|
|
|
|
|
MesMaterialBom materialBom = new MesMaterialBom();
|
|
|
|
|
|
|
|
materialBom.setParentId(mesMaterialBom.getMaterialBomId());
|
|
|
|
|
|
|
|
List<MesMaterialBom> mesMaterialBoms = mesMaterialBomService.selectMesMaterialBomList(materialBom);
|
|
|
|
|
|
|
|
for (MesMaterialBom bom : mesMaterialBoms) {
|
|
|
|
|
|
|
|
mesMaterialBomService.deleteMesMaterialBomByMaterialBomId(bom.getMaterialBomId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
MesMaterialBom materialBom = new MesMaterialBom();
|
|
|
|
|
|
|
|
materialBom.setMaterialId(productMaterial.getMaterialId());
|
|
|
|
|
|
|
|
materialBom.setMaterialName(productMaterial.getMaterialName());
|
|
|
|
|
|
|
|
materialBom.setMaterialBomDesc(productMaterial.getMaterialName());
|
|
|
|
|
|
|
|
materialBom.setParentId(0L);
|
|
|
|
|
|
|
|
materialBom.setActiveFlag("1");
|
|
|
|
|
|
|
|
materialBom.setStandardAmount(new BigDecimal(1));
|
|
|
|
|
|
|
|
materialBom.setCreateBy(operName);
|
|
|
|
|
|
|
|
mesMaterialBomService.insertMesMaterialBom(materialBom);
|
|
|
|
|
|
|
|
parentBomId = materialBom.getMaterialBomId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ArrayList<MesMaterialBom> bomList = new ArrayList<>();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
if (i > lastRowNum) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Row rowC = sheet.getRow(i);
|
|
|
|
|
|
|
|
Cell numberCell = rowC.getCell(0);
|
|
|
|
|
|
|
|
if (StringUtils.isNull(numberCell) || numberCell.getCellType() != NUMERIC) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell materialCodeCell = rowC.getCell(1);
|
|
|
|
|
|
|
|
String materialCode = null;
|
|
|
|
|
|
|
|
if (materialCodeCell.getCellType() == NUMERIC) {
|
|
|
|
|
|
|
|
double numericCellValue = materialCodeCell.getNumericCellValue();
|
|
|
|
|
|
|
|
materialCode = new BigDecimal(numericCellValue).toString();
|
|
|
|
|
|
|
|
} else if (materialCodeCell.getCellType() == STRING) {
|
|
|
|
|
|
|
|
materialCode = materialCodeCell.getStringCellValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell amountCell = rowC.getCell(5);
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(materialCode)) {
|
|
|
|
|
|
|
|
MesBaseMaterialInfo materialInfo = mesBaseMaterialInfoMapper.selectMesBaseMaterialInfoByMaterialCode(materialCode);
|
|
|
|
|
|
|
|
if (StringUtils.isNotNull(materialInfo)) {
|
|
|
|
|
|
|
|
MesMaterialBom materialBom = new MesMaterialBom();
|
|
|
|
|
|
|
|
materialBom.setMaterialId(materialInfo.getMaterialId());
|
|
|
|
|
|
|
|
materialBom.setMaterialName(materialInfo.getMaterialName());
|
|
|
|
|
|
|
|
materialBom.setMaterialCode(materialInfo.getMaterialName());
|
|
|
|
|
|
|
|
materialBom.setMaterialBomDesc(parentBomDesc);
|
|
|
|
|
|
|
|
materialBom.setParentId(parentBomId);
|
|
|
|
|
|
|
|
materialBom.setActiveFlag("1");
|
|
|
|
|
|
|
|
materialBom.setStandardAmount(BigDecimal.valueOf(amountCell.getNumericCellValue()));
|
|
|
|
|
|
|
|
materialBom.setCreateBy(operName);
|
|
|
|
|
|
|
|
bomList.add(materialBom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MesMaterialBom materialBom : bomList) {
|
|
|
|
|
|
|
|
mesMaterialBomService.insertMesMaterialBom(materialBom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new ServiceException("文件处理错误:" + e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
IOUtils.closeQuietly(is);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "BOM导入成功";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|