Browse Source

[update]:BOM导入功能

dev
youjianchi 9 months ago
parent
commit
5e1547bc0e
  1. 28
      ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java
  2. 72
      ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpBomImportVo.java
  3. 1
      ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java
  4. 2
      ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpMaterialMapper.java
  5. 3
      ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java
  6. 147
      ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java
  7. 30
      ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml
  8. 11
      ruoyi-admin/src/main/resources/mapper/erp/ErpMaterialMapper.xml
  9. 20
      ruoyi-admin/src/main/resources/templates/erp/bom/bom.html

28
ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java

@ -1,5 +1,6 @@
package com.ruoyi.erp.controller;
import com.ruoyi.ck.domain.ItemInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
@ -8,12 +9,15 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erp.domain.ErpBom;
import com.ruoyi.erp.domain.ErpBomImportVo;
import com.ruoyi.erp.service.IErpBomService;
import com.ruoyi.web.controller.demo.domain.UserOperateModel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
@ -260,4 +264,28 @@ public class ErpBomController extends BaseController
return erpBomService.checkMaterialNoUnique(materialNo);
}
/**
* 导出模板
*/
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate()
{
ExcelUtil<ErpBomImportVo> util = new ExcelUtil<ErpBomImportVo>(ErpBomImportVo.class);
return util.importTemplateExcel("物料模板");
}
/**
* 导入数据
*/
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
{
ExcelUtil<ErpBomImportVo> util = new ExcelUtil<ErpBomImportVo>(ErpBomImportVo.class);
List<ErpBomImportVo> bomImportVos = util.importExcel(file.getInputStream());
String message = erpBomService.importData(bomImportVos, updateSupport);
return AjaxResult.success(message);
}
}

72
ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpBomImportVo.java

@ -0,0 +1,72 @@
package com.ruoyi.erp.domain;
import com.ruoyi.common.annotation.Excel;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @Description bom导入vo
* @Author youjianchi
* @Date 2024/02/15 16:52
*/
public class ErpBomImportVo implements Serializable {
private static final long serialVersionUID = 1L;
/** 料号 */
@Excel(name = "料号",sort = 1)
private String materialNo;
/** 用量 */
@Excel(name = "用量",sort = 2)
private Long useNum;
/** 损耗率 */
@Excel(name = "损耗率",sort = 3)
private BigDecimal lossRate;
/** 备注 */
@Excel(name = "备注",sort = 4)
private String remark;
public String getMaterialNo() {
return materialNo;
}
public void setMaterialNo(String materialNo) {
this.materialNo = materialNo;
}
public Long getUseNum() {
return useNum;
}
public void setUseNum(Long useNum) {
this.useNum = useNum;
}
public BigDecimal getLossRate() {
return lossRate;
}
public void setLossRate(BigDecimal lossRate) {
this.lossRate = lossRate;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "ErpBomImportVo{" +
"materialNo='" + materialNo + '\'' +
", useNum=" + useNum +
", lossRate=" + lossRate +
", remark='" + remark + '\'' +
'}';
}
}

1
ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java

@ -127,4 +127,5 @@ public interface ErpBomMapper
public List<ErpBom> selectErpBomList1();
}

2
ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpMaterialMapper.java

@ -91,4 +91,6 @@ public interface ErpMaterialMapper
* 修改物料的关联bom
*/
public int updateMaterialBomNo(ErpMaterial erpMaterial);
ErpMaterialVo selectErpMaterialByMaterialNo(String materialNo);
}

3
ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java

@ -1,6 +1,7 @@
package com.ruoyi.erp.service;
import com.ruoyi.erp.domain.ErpBom;
import com.ruoyi.erp.domain.ErpBomImportVo;
import java.util.List;
@ -103,4 +104,6 @@ public interface IErpBomService
List<ErpBom> getExportList(ErpBom erpBom);
String importData(List<ErpBomImportVo> bomImportVos,boolean updateSupport);
}

147
ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java

@ -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信息
*

30
ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml

@ -134,20 +134,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertErpBom" parameterType="ErpBom" useGeneratedKeys="true" keyProperty="id">
insert into erp_bom
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="delFlag != null and delFlag!= ''">del_flag,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="bomNo != null">bom_no,</if>
<if test="materialNo != null">material_no,</if>
<if test="materialName != null">material_name,</if>
<if test="materialType != null">material_type,</if>
<if test="processMethod != null">process_method,</if>
<if test="unit != null">unit,</if>
<if test="brand != null">brand,</if>
<if test="describe != null">`describe`,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="bomNo != null and bomNo != '' ">bom_no,</if>
<if test="materialNo != null and materialNo != '' ">material_no,</if>
<if test="materialName != null and materialName != '' ">material_name,</if>
<if test="materialType != null and materialType != '' ">material_type,</if>
<if test="processMethod != null and processMethod != '' ">process_method,</if>
<if test="unit != null and unit != '' ">unit,</if>
<if test="brand != null and brand != '' ">brand,</if>
<if test="describe != null and describe != '' ">`describe`,</if>
<if test="useNum != null">use_num,</if>
<if test="lossRate != null">loss_rate,</if>
<if test="parentId != null">parent_id,</if>
@ -157,10 +157,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
use_status
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="delFlag != null and delFlag!= ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null and remark != '' ">#{remark},</if>
<if test="bomNo != null and bomNo != '' ">#{bomNo},</if>

11
ruoyi-admin/src/main/resources/mapper/erp/ErpMaterialMapper.xml

@ -112,6 +112,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="checkMaterialNoUnique" resultType="java.lang.Integer">
select count(1) from erp_material where material_no = #{materialNo} limit 1
</select>
<select id="selectErpMaterialByMaterialNo" resultMap="ErpMaterialResult">
select erp.id, erp.del_flag, erp.create_by, erp.create_time, erp.update_by, erp.update_time, erp.remark,erp.bomNo, erp.material_no
, erp.material_name, erp.audit_status, erp.use_status, erp.hava_product_tem,erp.product_item,erp.itemName, erp.material_type
, erp.process_method, erp.unit, erp.brand, erp.describe, erp.warehouse_dept
,erp.instance_id,erp.instance_type,erp.submit_instance_id,erp.cancel_instance_id,erp.restore_instance_id,erp.apply_title,erp.apply_user,erp.apply_time
,att.id as photo_attach_id
from erp_material erp
left join sys_attach att
on erp.id = att.rel_id and att.source_type = 'erpMaterial' and att.source_sub_type = 'photo'
where erp.material_no = #{materialNo}
</select>
<insert id="insertErpMaterial" parameterType="ErpMaterial" useGeneratedKeys="true" keyProperty="id">
insert into erp_material

20
ruoyi-admin/src/main/resources/templates/erp/bom/bom.html

@ -84,6 +84,9 @@
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:bom:export">
<i class="fa fa-download"></i> 导出
</a>
<a class="btn btn-info" onclick="$.table.importExcel()">
<i class="fa fa-upload"></i> 导入
</a>
<a class="btn btn-success" onclick="bomEqulas()" shiro:hasPermission="erp:bom:equals">
<i class="fa fa-edit"></i> bom对比
</a>
@ -120,6 +123,8 @@
cancelUrl: prefix + "/cancel/{id}",
restoreUrl: prefix + "/restore/{id}",
exportUrl: prefix + "/export",
importUrl: prefix + "/importData",
importTemplateUrl: prefix + "/importTemplate",
fixedColumns:true,
fixedRightNumber:1,
fixedNumber:1,
@ -754,4 +759,19 @@
}
</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
<div class="col-xs-offset-1">
<input type="file" id="file" name="file"/>
<div class="mt10 pt5">
<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在,更新这条数据。"> 是否更新已经存在的用户数据
&nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
</div>
<font color="red" class="pull-left mt10">
提示:仅允许导入“xls”或“xlsx”格式文件!
</font>
</div>
</form>
</script>
</html>
Loading…
Cancel
Save