|
|
@ -6,20 +6,29 @@ import com.ruoyi.common.utils.DateUtils; |
|
|
|
import com.ruoyi.common.utils.ShiroUtils; |
|
|
|
import com.ruoyi.common.utils.StringUtils; |
|
|
|
import com.ruoyi.erp.domain.ErpBom; |
|
|
|
import com.ruoyi.erp.domain.ErpBomImportVo; |
|
|
|
import com.ruoyi.erp.domain.ErpMaterial; |
|
|
|
import com.ruoyi.erp.domain.ErpMaterialVo; |
|
|
|
import com.ruoyi.erp.mapper.ErpBomMapper; |
|
|
|
import com.ruoyi.erp.mapper.ErpMaterialMapper; |
|
|
|
import com.ruoyi.erp.service.IErpBomService; |
|
|
|
import com.ruoyi.erp.service.IErpMaterialService; |
|
|
|
import com.ruoyi.web.controller.demo.domain.UserOperateModel; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.logging.Level; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static org.apache.shiro.web.filter.mgt.DefaultFilter.user; |
|
|
|
|
|
|
|
/** |
|
|
|
* bomService业务层处理 |
|
|
|
* |
|
|
@ -38,6 +47,9 @@ public class ErpBomServiceImpl implements IErpBomService |
|
|
|
@Autowired |
|
|
|
private IErpMaterialService iErpMaterialService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ErpMaterialMapper materialMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询bom |
|
|
|
* |
|
|
@ -275,6 +287,141 @@ public class ErpBomServiceImpl implements IErpBomService |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入数据 |
|
|
|
* |
|
|
|
* @param bomImportVos 数据列表 |
|
|
|
* @param updateSupport 是否更新支持,如果已存在,则进行更新数据 |
|
|
|
* @return 结果 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String importData(List<ErpBomImportVo> bomImportVos, boolean updateSupport) { |
|
|
|
|
|
|
|
if (StringUtils.isNull(bomImportVos) || bomImportVos.size() == 0) |
|
|
|
{ |
|
|
|
throw new RuntimeException("导入数据不能为空!"); |
|
|
|
} |
|
|
|
int successNum = 0; |
|
|
|
int failureNum = 0; |
|
|
|
StringBuilder successMsg = new StringBuilder(); |
|
|
|
StringBuilder failureMsg = new StringBuilder(); |
|
|
|
for (int i=0;i<bomImportVos.size();i++){ |
|
|
|
ErpBomImportVo bomImportVo = bomImportVos.get(i); |
|
|
|
String materialNo = bomImportVo.getMaterialNo(); |
|
|
|
if(StringUtils.isBlank(materialNo)){ |
|
|
|
failureNum++; |
|
|
|
failureMsg.append("<br/>" + failureNum + "、料号 " + materialNo + " 不能为空"); |
|
|
|
}else{ |
|
|
|
ErpMaterialVo erpMaterialVo = materialMapper.selectErpMaterialByMaterialNo(materialNo); |
|
|
|
if(erpMaterialVo==null){ |
|
|
|
failureNum++; |
|
|
|
failureMsg.append("<br/>" + failureNum + "、料号 " + materialNo + " 不存在"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (failureNum > 0) |
|
|
|
{ |
|
|
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); |
|
|
|
throw new RuntimeException(failureMsg.toString()); |
|
|
|
} |
|
|
|
failureNum = 0; |
|
|
|
Long parentId = null; |
|
|
|
String loginName = ShiroUtils.getLoginName(); |
|
|
|
Date now = DateUtils.getNowDate(); |
|
|
|
for (int i=0;i<bomImportVos.size();i++) |
|
|
|
{ |
|
|
|
ErpBomImportVo bomImportVo = bomImportVos.get(i); |
|
|
|
String materialNo = bomImportVo.getMaterialNo(); |
|
|
|
Long useNum = bomImportVo.getUseNum(); |
|
|
|
BigDecimal lossRate = bomImportVo.getLossRate(); |
|
|
|
String remark = bomImportVo.getRemark(); |
|
|
|
ErpMaterialVo erpMaterialVo = materialMapper.selectErpMaterialByMaterialNo(materialNo); |
|
|
|
try |
|
|
|
{ |
|
|
|
// 第一行为父级
|
|
|
|
if(i==0){ |
|
|
|
ErpBom erpBom = erpBomMapper.selectErpBomByOneMaterialNo(materialNo); |
|
|
|
// 更新父级
|
|
|
|
if(erpBom!=null){ |
|
|
|
parentId = erpBom.getId(); |
|
|
|
// 删除子集
|
|
|
|
erpBomMapper.deleteErpBomByParentId(parentId); |
|
|
|
erpBom.setRemark(remark); |
|
|
|
erpBom.setUpdateBy(loginName); |
|
|
|
erpBom.setUpdateTime(now); |
|
|
|
erpBomMapper.updateErpBom(erpBom); |
|
|
|
successNum++; |
|
|
|
successMsg.append("<br/>" + successNum + "、料号 " + materialNo + " 更新成功"); |
|
|
|
} |
|
|
|
// 新增父级
|
|
|
|
else{ |
|
|
|
ErpBom fatherBom = new ErpBom(); |
|
|
|
fatherBom.setDelFlag("0"); |
|
|
|
fatherBom.setRemark(remark); |
|
|
|
fatherBom.setCreateBy(loginName); |
|
|
|
fatherBom.setCreateTime(now); |
|
|
|
fatherBom.setUpdateBy(loginName); |
|
|
|
fatherBom.setUpdateTime(now); |
|
|
|
String billNo = redisCache.generateBillNo("BOM"); |
|
|
|
fatherBom.setBomNo(billNo); |
|
|
|
fatherBom.setMaterialNo(materialNo); |
|
|
|
fatherBom.setMaterialName(erpMaterialVo.getMaterialName()); |
|
|
|
fatherBom.setMaterialType(erpMaterialVo.getMaterialType()); |
|
|
|
fatherBom.setProcessMethod(erpMaterialVo.getProcessMethod()); |
|
|
|
fatherBom.setUnit(erpMaterialVo.getUnit()); |
|
|
|
fatherBom.setBrand(erpMaterialVo.getBrand()); |
|
|
|
fatherBom.setDescribe(erpMaterialVo.getDescribe()); |
|
|
|
fatherBom.setParentId(0L); |
|
|
|
fatherBom.setLevel(0L); |
|
|
|
erpBomMapper.insertErpBom(fatherBom); |
|
|
|
parentId = fatherBom.getId(); |
|
|
|
successNum++; |
|
|
|
successMsg.append("<br/>" + successNum + "、料号 " + materialNo + " 新增成功"); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
ErpBom subBom = new ErpBom(); |
|
|
|
subBom.setDelFlag("0"); |
|
|
|
subBom.setRemark(remark); |
|
|
|
subBom.setCreateBy(loginName); |
|
|
|
subBom.setCreateTime(now); |
|
|
|
subBom.setUpdateBy(loginName); |
|
|
|
subBom.setUpdateTime(now); |
|
|
|
subBom.setMaterialNo(materialNo); |
|
|
|
subBom.setMaterialName(erpMaterialVo.getMaterialName()); |
|
|
|
subBom.setMaterialType(erpMaterialVo.getMaterialType()); |
|
|
|
subBom.setProcessMethod(erpMaterialVo.getProcessMethod()); |
|
|
|
subBom.setUnit(erpMaterialVo.getUnit()); |
|
|
|
subBom.setBrand(erpMaterialVo.getBrand()); |
|
|
|
subBom.setDescribe(erpMaterialVo.getDescribe()); |
|
|
|
subBom.setUseNum(useNum); |
|
|
|
subBom.setLossRate(lossRate); |
|
|
|
subBom.setParentId(parentId); |
|
|
|
subBom.setLevel(1L); |
|
|
|
subBom.setSortNo(i+0L); |
|
|
|
erpBomMapper.insertErpBom(subBom); |
|
|
|
successNum++; |
|
|
|
successMsg.append("<br/>" + successNum + "、料号 " + materialNo + " 新增成功"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
failureNum++; |
|
|
|
String msg = "<br/>" + failureNum + "、料号 " + materialNo + " 导入失败:"; |
|
|
|
failureMsg.append(msg + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (failureNum > 0) |
|
|
|
{ |
|
|
|
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); |
|
|
|
throw new RuntimeException(failureMsg.toString()); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); |
|
|
|
} |
|
|
|
return successMsg.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增bom信息 |
|
|
|
* |
|
|
|