change - 物料BOM信息excel导入

master
yinq 4 months ago
parent cf5583f3b6
commit 0d4755e46e

@ -45,5 +45,19 @@ public class MesImportController extends BaseController {
return success(message); return success(message);
} }
/**
* BOMexcel
* @param file
* @param updateSupport
* @return
*/
@Log(title = "物料BOM信息", businessType = BusinessType.IMPORT)
@PostMapping(("/BOMImportData"))
public AjaxResult BOMImportData(MultipartFile file, boolean updateSupport)
{
String operName = SecurityUtils.getUsername();
String message = mesImportService.BOMImportData(file, updateSupport, operName);
return success(message);
}
} }

@ -79,8 +79,13 @@ public interface MesBaseMaterialInfoMapper
*/ */
public List<MesBaseMaterialInfo> selectMaterialInfos4AllocationWarehouse(MesBaseMaterialInfo mesBaseMaterialInfo); public List<MesBaseMaterialInfo> selectMaterialInfos4AllocationWarehouse(MesBaseMaterialInfo mesBaseMaterialInfo);
/**
*
*
* @param materialCode
* @return
*/
public MesBaseMaterialInfo selectMesBaseMaterialInfoByMaterialCode(String materialCode);
/** /**
* *

@ -1,6 +1,7 @@
package com.hw.mes.service; package com.hw.mes.service;
import com.hw.mes.domain.MesPurchaseRequisitionTemplate; import com.hw.mes.domain.MesPurchaseRequisitionTemplate;
import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@ -21,4 +22,13 @@ public interface IMesImportService
* @return * @return
*/ */
String importPurchaseRequisition(List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList, String operName); String importPurchaseRequisition(List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList, String operName);
/**
* BOMexcel
* @param file
* @param updateSupport
* @param operName
* @return
*/
String BOMImportData(MultipartFile file, boolean updateSupport, String operName);
} }

@ -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;
/** /**
* excelService * excelService
* *
@ -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();
} }
/**
* BOMexcel
*
* @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导入成功";
}
} }

@ -334,4 +334,8 @@
where bmi.erp_id = #{erpId} limit 1 where bmi.erp_id = #{erpId} limit 1
</select> </select>
<select id="selectMesBaseMaterialInfoByMaterialCode" parameterType="String" resultMap="MesBaseMaterialInfoResult">
<include refid="selectMesBaseMaterialInfoVo"/>
where bmi.material_code = #{materialCode}
</select>
</mapper> </mapper>

@ -83,6 +83,16 @@
>展开/折叠 >展开/折叠
</el-button> </el-button>
</el-col> </el-col>
<el-col :span="1.5">
<el-button
type="info"
plain
icon="el-icon-upload2"
size="mini"
@click="handleImport"
>BOM导入
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
</el-row> </el-row>
@ -231,6 +241,35 @@
</div> </div>
</el-dialog> </el-dialog>
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
ref="upload"
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<div class="el-upload__tip text-center" slot="tip">
<!-- <div class="el-upload__tip" slot="tip">-->
<!-- <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据-->
<!-- </div>-->
<span>仅允许导入xlsxlsx格式文件</span>
<!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate"></el-link>-->
</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitFileForm"> </el-button>
<el-button @click="upload.open = false"> </el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
@ -246,6 +285,7 @@ import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import addBom from '@//views/mes/materialBom/addBom.vue'; import addBom from '@//views/mes/materialBom/addBom.vue';
import {verifyBOMIsProduction} from "@//api/mes/productOrder"; import {verifyBOMIsProduction} from "@//api/mes/productOrder";
import {getToken} from "@/utils/auth";
export default { export default {
name: "MaterialBom", name: "MaterialBom",
@ -312,6 +352,20 @@ export default {
{required: true, message: "激活标识不能为空", trigger: "change"} {required: true, message: "激活标识不能为空", trigger: "change"}
], ],
}, },
upload: {
//
open: false,
//
title: "",
//
isUploading: false,
//
updateSupport: 0,
//
headers: { Authorization: "Bearer " + getToken() },
//
url: process.env.VUE_APP_BASE_API + "/mes/import/BOMImportData"
},
columns: [ columns: [
{key: 0, label: `主键标识`, visible: false}, {key: 0, label: `主键标识`, visible: false},
{key: 1, label: `父级标识`, visible: false}, {key: 1, label: `父级标识`, visible: false},
@ -554,6 +608,27 @@ export default {
this.form.materialName = selectedRow.materialName; this.form.materialName = selectedRow.materialName;
this.materialOpen = false; this.materialOpen = false;
}, },
/** 导入按钮操作 */
handleImport() {
this.upload.title = "BOM导入";
this.upload.open = true;
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
//
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
},
//
submitFileForm() {
this.$refs.upload.submit();
},
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
verifyBOMIsProduction(row.materialBomId).then(res => { verifyBOMIsProduction(row.materialBomId).then(res => {

Loading…
Cancel
Save