change - 采购申请单导入、排产逻辑修改
parent
720682f03c
commit
470b8bb782
@ -0,0 +1,49 @@
|
|||||||
|
package com.hw.mes.controller;
|
||||||
|
|
||||||
|
import com.hw.common.core.utils.poi.ExcelUtil;
|
||||||
|
import com.hw.common.core.web.controller.BaseController;
|
||||||
|
import com.hw.common.core.web.domain.AjaxResult;
|
||||||
|
import com.hw.common.log.annotation.Log;
|
||||||
|
import com.hw.common.log.enums.BusinessType;
|
||||||
|
import com.hw.common.security.utils.SecurityUtils;
|
||||||
|
import com.hw.mes.domain.MesPurchaseRequisitionTemplate;
|
||||||
|
import com.hw.mes.service.IMesBasePalletInfoService;
|
||||||
|
import com.hw.mes.service.IMesImportService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MES excel导入Controller
|
||||||
|
*
|
||||||
|
* @author Yinq
|
||||||
|
* @date 2024-07-18
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/import")
|
||||||
|
public class MesImportController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesImportService mesImportService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采购申请单excel导入
|
||||||
|
*/
|
||||||
|
@Log(title = "采购申请单", businessType = BusinessType.IMPORT)
|
||||||
|
@PostMapping(("/purchaseRequisitionImportData"))
|
||||||
|
public AjaxResult purchaseRequisitionImportData(MultipartFile file, boolean updateSupport) throws Exception
|
||||||
|
{
|
||||||
|
ExcelUtil<MesPurchaseRequisitionTemplate> util = new ExcelUtil<>(MesPurchaseRequisitionTemplate.class);
|
||||||
|
List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList = util.importExcel(file.getInputStream());
|
||||||
|
String operName = SecurityUtils.getUsername();
|
||||||
|
String message = mesImportService.importPurchaseRequisition(purchaseRequisitionTemplateList, operName);
|
||||||
|
return success(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.hw.mes.service;
|
||||||
|
|
||||||
|
import com.hw.mes.domain.MesPurchaseRequisitionTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* excel导入Service接口
|
||||||
|
*
|
||||||
|
* @author Yinq
|
||||||
|
* @date 2024-01-26
|
||||||
|
*/
|
||||||
|
public interface IMesImportService
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采购申请单导入
|
||||||
|
* @param purchaseRequisitionTemplateList 数据列表
|
||||||
|
* @param operName 操作用户
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String importPurchaseRequisition(List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList, String operName);
|
||||||
|
}
|
@ -0,0 +1,117 @@
|
|||||||
|
package com.hw.mes.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.hw.common.core.constant.SecurityConstants;
|
||||||
|
import com.hw.common.core.domain.R;
|
||||||
|
import com.hw.common.core.exception.ServiceException;
|
||||||
|
import com.hw.common.core.utils.StringUtils;
|
||||||
|
import com.hw.common.core.utils.bean.BeanValidators;
|
||||||
|
import com.hw.common.core.web.domain.AjaxResult;
|
||||||
|
import com.hw.common.security.utils.SecurityUtils;
|
||||||
|
import com.hw.jindie.api.RemoteJindieService;
|
||||||
|
import com.hw.mes.api.RemoteMesService;
|
||||||
|
import com.hw.mes.api.domain.MesBaseMaterialInfo;
|
||||||
|
import com.hw.mes.domain.MesPurchaseRequisitionTemplate;
|
||||||
|
|
||||||
|
import com.hw.mes.service.IMesBaseMaterialInfoService;
|
||||||
|
import com.hw.mes.service.IMesImportService;
|
||||||
|
import com.hw.system.api.domain.SysUser;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* excel导入Service业务层处理
|
||||||
|
*
|
||||||
|
* @author Yinq
|
||||||
|
* @date 2024-01-25
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MesImportImpl implements IMesImportService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMesBaseMaterialInfoService materialInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteJindieService remoteJindieService;
|
||||||
|
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(MesImportImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 采购申请单导入
|
||||||
|
*
|
||||||
|
* @param purchaseRequisitionTemplateList 数据列表
|
||||||
|
* @param operName 操作用户
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String importPurchaseRequisition(List<MesPurchaseRequisitionTemplate> purchaseRequisitionTemplateList, String operName) {
|
||||||
|
if (StringUtils.isNull(purchaseRequisitionTemplateList) || purchaseRequisitionTemplateList.size() == 0) {
|
||||||
|
throw new ServiceException("导入采购申请单数据不能为空!");
|
||||||
|
}
|
||||||
|
int successNum = 0;
|
||||||
|
int failureNum = 0;
|
||||||
|
StringBuilder successMsg = new StringBuilder();
|
||||||
|
StringBuilder failureMsg = new StringBuilder();
|
||||||
|
for (MesPurchaseRequisitionTemplate purchaseRequisitionTemplate : purchaseRequisitionTemplateList) {
|
||||||
|
try {
|
||||||
|
String materialName = purchaseRequisitionTemplate.getMaterialName();
|
||||||
|
String productModel = purchaseRequisitionTemplate.getProductModel();
|
||||||
|
//产品规格型号把excel中的除.的符号都去掉(包括空格换行)
|
||||||
|
productModel = productModel.replaceAll("[^\\w.]", "");
|
||||||
|
MesBaseMaterialInfo materialInfo = new MesBaseMaterialInfo();
|
||||||
|
materialInfo.setMaterialName(materialName);
|
||||||
|
List<MesBaseMaterialInfo> materialInfoList = materialInfoService.selectMesBaseMaterialInfoList(materialInfo);
|
||||||
|
|
||||||
|
int successFlag = 0;
|
||||||
|
MesBaseMaterialInfo findMaterialInfo = new MesBaseMaterialInfo();
|
||||||
|
for (MesBaseMaterialInfo baseMaterialInfo : materialInfoList) {
|
||||||
|
String materialSpec = baseMaterialInfo.getMaterialSpec();
|
||||||
|
materialSpec = materialSpec.replaceAll("[^\\w.]", "");
|
||||||
|
if (materialSpec.equals(productModel)) {
|
||||||
|
successFlag++;
|
||||||
|
findMaterialInfo = baseMaterialInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (successFlag == 1) {
|
||||||
|
//导入ERP
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
data.put("FMaterialId", findMaterialInfo.getMaterialCode());
|
||||||
|
data.put("FMaterialDesc", findMaterialInfo.getMaterialSpec());
|
||||||
|
data.put("FUnitId", purchaseRequisitionTemplate.getUnit());
|
||||||
|
data.put("FReqQty", purchaseRequisitionTemplate.getAmount());
|
||||||
|
data.put("FTAXPRICE", purchaseRequisitionTemplate.getTaxUnitPrice());
|
||||||
|
String params = data.toJSONString();
|
||||||
|
R<AjaxResult> ajaxResult = remoteJindieService.singleSavePurchaseRequisition(params, SecurityConstants.INNER);
|
||||||
|
successNum++;
|
||||||
|
successMsg.append("<br/>").append(materialName).append(" 导入成功");
|
||||||
|
log.info(purchaseRequisitionTemplate.toString(), ajaxResult);
|
||||||
|
} else if (successFlag > 1) {
|
||||||
|
failureNum++;
|
||||||
|
failureMsg.append("<br/>").append(failureNum).append(" 查出多条物料记录 导入失败");
|
||||||
|
} else {
|
||||||
|
failureNum++;
|
||||||
|
failureMsg.append("<br/>").append(failureNum).append(" 未找到物料记录 导入失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
failureNum++;
|
||||||
|
String msg = "<br/>" + failureNum + " 导入失败:";
|
||||||
|
failureMsg.append(msg + e.getMessage());
|
||||||
|
log.error(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (failureNum > 0) {
|
||||||
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||||
|
throw new ServiceException(failureMsg.toString());
|
||||||
|
} else {
|
||||||
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||||
|
}
|
||||||
|
return successMsg.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue