Browse Source

[update]:bom模块功能实现

erp、
youjianchi 1 year ago
parent
commit
a9b7c0fad7
  1. 25
      ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpBomController.java
  2. 9
      ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpMaterialController.java
  3. 172
      ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpBom.java
  4. 29
      ruoyi-admin/src/main/java/com/ruoyi/erp/mapper/ErpBomMapper.java
  5. 4
      ruoyi-admin/src/main/java/com/ruoyi/erp/service/IErpBomService.java
  6. 75
      ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpBomServiceImpl.java
  7. 144
      ruoyi-admin/src/main/resources/mapper/erp/ErpBomMapper.xml
  8. 40
      ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js
  9. 324
      ruoyi-admin/src/main/resources/templates/erp/bom/add.html
  10. 172
      ruoyi-admin/src/main/resources/templates/erp/bom/bom.html
  11. 421
      ruoyi-admin/src/main/resources/templates/erp/bom/edit.html
  12. 115
      ruoyi-admin/src/main/resources/templates/erp/material/select.html
  13. 27
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/DictService.java
  14. 6
      ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java

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

@ -5,11 +5,7 @@ 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ErpBom;
@ -23,7 +19,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
* bomController
*
* @author ruoyi
* @date 2023-11-19
* @date 2023-11-21
*/
@Controller
@RequestMapping("/erp/bom")
@ -54,6 +50,19 @@ public class ErpBomController extends BaseController
return getDataTable(list);
}
/**
* 查询bom子列表
*/
@RequiresPermissions("erp:bom:list")
@PostMapping("/subList")
@ResponseBody
public TableDataInfo subList(ErpBom erpBom)
{
startPage();
List<ErpBom> list = erpBomService.selectErpBomSubList(erpBom);
return getDataTable(list);
}
/**
* 导出bom列表
*/
@ -84,7 +93,7 @@ public class ErpBomController extends BaseController
@Log(title = "bom", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(ErpBom erpBom)
public AjaxResult addSave(@RequestBody ErpBom erpBom)
{
return toAjax(erpBomService.insertErpBom(erpBom));
}
@ -107,7 +116,7 @@ public class ErpBomController extends BaseController
@Log(title = "bom", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(ErpBom erpBom)
public AjaxResult editSave(@RequestBody ErpBom erpBom)
{
return toAjax(erpBomService.updateErpBom(erpBom));
}

9
ruoyi-admin/src/main/java/com/ruoyi/erp/controller/ErpMaterialController.java

@ -158,4 +158,13 @@ public class ErpMaterialController extends BaseController
{
return erpMaterialService.checkMaterialNoUnique(material.getMaterialNo());
}
/**
* 选择料号
*/
@GetMapping("/select")
public String select()
{
return prefix + "/select";
}
}

172
ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpBom.java

@ -1,5 +1,7 @@
package com.ruoyi.erp.domain;
import java.math.BigDecimal;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
@ -9,7 +11,7 @@ import com.ruoyi.common.core.domain.BaseEntity;
* bom对象 erp_bom
*
* @author ruoyi
* @date 2023-11-19
* @date 2023-11-21
*/
public class ErpBom extends BaseEntity
{
@ -29,6 +31,50 @@ public class ErpBom extends BaseEntity
@Excel(name = "料号")
private String materialNo;
/** 物料名称 */
@Excel(name = "物料名称")
private String materialName;
/** 物料类型 */
@Excel(name = "物料类型")
private String materialType;
/** 加工方式 */
@Excel(name = "加工方式")
private String processMethod;
/** 单位 */
@Excel(name = "单位")
private String unit;
/** 品牌 */
@Excel(name = "品牌")
private String brand;
/** 描述 */
@Excel(name = "描述")
private String describe;
/** 用量 */
@Excel(name = "用量")
private Long useNum;
/** 损耗率 */
@Excel(name = "损耗率")
private BigDecimal lossRate;
/** 父级id */
@Excel(name = "父级id")
private Long parentId;
/** 层级 */
@Excel(name = "层级")
private Long level;
/** 排序 */
@Excel(name = "排序")
private Long sortNo;
/** 审核状态 */
@Excel(name = "审核状态")
private String auditStatus;
@ -37,6 +83,9 @@ public class ErpBom extends BaseEntity
@Excel(name = "使用状态")
private String useStatus;
/** bom信息 */
private List<ErpBom> erpBomList;
public void setId(Long id)
{
this.id = id;
@ -73,6 +122,105 @@ public class ErpBom extends BaseEntity
{
return materialNo;
}
public void setMaterialName(String materialName)
{
this.materialName = materialName;
}
public String getMaterialName()
{
return materialName;
}
public void setMaterialType(String materialType)
{
this.materialType = materialType;
}
public String getMaterialType()
{
return materialType;
}
public void setProcessMethod(String processMethod)
{
this.processMethod = processMethod;
}
public String getProcessMethod()
{
return processMethod;
}
public void setUnit(String unit)
{
this.unit = unit;
}
public String getUnit()
{
return unit;
}
public void setBrand(String brand)
{
this.brand = brand;
}
public String getBrand()
{
return brand;
}
public void setDescribe(String describe)
{
this.describe = describe;
}
public String getDescribe()
{
return describe;
}
public void setUseNum(Long useNum)
{
this.useNum = useNum;
}
public Long getUseNum()
{
return useNum;
}
public void setLossRate(BigDecimal lossRate)
{
this.lossRate = lossRate;
}
public BigDecimal getLossRate()
{
return lossRate;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getParentId()
{
return parentId;
}
public void setLevel(Long level)
{
this.level = level;
}
public Long getLevel()
{
return level;
}
public void setSortNo(Long sortNo)
{
this.sortNo = sortNo;
}
public Long getSortNo()
{
return sortNo;
}
public void setAuditStatus(String auditStatus)
{
this.auditStatus = auditStatus;
@ -92,6 +240,16 @@ public class ErpBom extends BaseEntity
return useStatus;
}
public List<ErpBom> getErpBomList()
{
return erpBomList;
}
public void setErpBomList(List<ErpBom> erpBomList)
{
this.erpBomList = erpBomList;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@ -104,8 +262,20 @@ public class ErpBom extends BaseEntity
.append("remark", getRemark())
.append("bomNo", getBomNo())
.append("materialNo", getMaterialNo())
.append("materialName", getMaterialName())
.append("materialType", getMaterialType())
.append("processMethod", getProcessMethod())
.append("unit", getUnit())
.append("brand", getBrand())
.append("describe", getDescribe())
.append("useNum", getUseNum())
.append("lossRate", getLossRate())
.append("parentId", getParentId())
.append("level", getLevel())
.append("sortNo", getSortNo())
.append("auditStatus", getAuditStatus())
.append("useStatus", getUseStatus())
.append("erpBomList", getErpBomList())
.toString();
}
}

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

@ -2,12 +2,13 @@ package com.ruoyi.erp.mapper;
import java.util.List;
import com.ruoyi.erp.domain.ErpBom;
import com.ruoyi.erp.domain.ErpBom;
/**
* bomMapper接口
*
* @author ruoyi
* @date 2023-11-19
* @date 2023-11-21
*/
public interface ErpBomMapper
{
@ -27,6 +28,8 @@ public interface ErpBomMapper
*/
public List<ErpBom> selectErpBomList(ErpBom erpBom);
List<ErpBom> selectErpBomSubList(ErpBom erpBom);
/**
* 新增bom
*
@ -74,4 +77,28 @@ public interface ErpBomMapper
* @return 结果
*/
public int restoreErpBomById(Long id);
/**
* 批量删除bom
*
* @param customerIds 需要删除的数据ID
* @return 结果
*/
public int deleteErpBomByParentIds(String[] ids);
/**
* 批量新增bom
*
* @param erpBomList bom列表
* @return 结果
*/
public int batchErpBom(List<ErpBom> erpBomList);
/**
* 通过bomID删除bom信息
*
* @param roleId 角色ID
* @return 结果
*/
public int deleteErpBomByParentId(Long id);
}

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

@ -7,7 +7,7 @@ import com.ruoyi.erp.domain.ErpBom;
* bomService接口
*
* @author ruoyi
* @date 2023-11-19
* @date 2023-11-21
*/
public interface IErpBomService
{
@ -27,6 +27,8 @@ public interface IErpBomService
*/
public List<ErpBom> selectErpBomList(ErpBom erpBom);
List<ErpBom> selectErpBomSubList(ErpBom erpBom);
/**
* 新增bom
*

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

@ -1,12 +1,18 @@
package com.ruoyi.erp.service.impl;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.erp.domain.ErpBom;
import com.ruoyi.erp.mapper.ErpBomMapper;
import com.ruoyi.erp.domain.ErpBom;
import com.ruoyi.erp.service.IErpBomService;
@ -16,7 +22,7 @@ import com.ruoyi.common.core.text.Convert;
* bomService业务层处理
*
* @author ruoyi
* @date 2023-11-19
* @date 2023-11-21
*/
@Service
public class ErpBomServiceImpl implements IErpBomService
@ -51,21 +57,30 @@ public class ErpBomServiceImpl implements IErpBomService
return erpBomMapper.selectErpBomList(erpBom);
}
@Override
public List<ErpBom> selectErpBomSubList(ErpBom erpBom) {
return erpBomMapper.selectErpBomSubList(erpBom);
}
/**
* 新增bom
*
* @param erpBom bom
* @return 结果
*/
@Transactional
@Override
public int insertErpBom(ErpBom erpBom)
{
String billNo = redisCache.generateBillNo("BOM");
erpBom.setBomNo(billNo);
String loginName = ShiroUtils.getLoginName();
erpBom.setCreateBy(loginName);
erpBom.setCreateTime(DateUtils.getNowDate());
return erpBomMapper.insertErpBom(erpBom);
erpBom.setParentId(0L);
String billNo = redisCache.generateBillNo("BOM");
erpBom.setBomNo(billNo);
int rows = erpBomMapper.insertErpBom(erpBom);
insertErpBomSub(erpBom);
return rows;
}
/**
@ -74,13 +89,30 @@ public class ErpBomServiceImpl implements IErpBomService
* @param erpBom bom
* @return 结果
*/
@Transactional
@Override
public int updateErpBom(ErpBom erpBom)
{
String loginName = ShiroUtils.getLoginName();
erpBom.setUpdateBy(loginName);
erpBom.setUpdateTime(DateUtils.getNowDate());
return erpBomMapper.updateErpBom(erpBom);
int editFlag = erpBomMapper.updateErpBom(erpBom);
Long id = erpBom.getId();
erpBomMapper.deleteErpBomByParentId(id);
List<ErpBom> erpBomSubList = erpBom.getErpBomList();
if(CollectionUtils.isNotEmpty(erpBomSubList)){
for (int i=0;i<erpBomSubList.size();i++)
{
ErpBom erpBom1 = erpBomSubList.get(i);
erpBom1.setId(null);
erpBom1.setSortNo((i+1L));
erpBom1.setParentId(id);
erpBom1.setCreateBy(ShiroUtils.getLoginName());
erpBom1.setCreateTime(DateUtils.getNowDate());
erpBomMapper.insertErpBom(erpBom1);
}
}
return editFlag;
}
/**
@ -89,9 +121,11 @@ public class ErpBomServiceImpl implements IErpBomService
* @param ids 需要删除的数据ID
* @return 结果
*/
@Transactional
@Override
public int deleteErpBomByIds(String ids)
{
erpBomMapper.deleteErpBomByParentIds(Convert.toStrArray(ids));
return erpBomMapper.deleteErpBomByIds(Convert.toStrArray(ids));
}
@ -104,6 +138,7 @@ public class ErpBomServiceImpl implements IErpBomService
@Override
public int deleteErpBomById(Long id)
{
erpBomMapper.deleteErpBomByParentId(id);
return erpBomMapper.deleteErpBomById(id);
}
@ -130,4 +165,34 @@ public class ErpBomServiceImpl implements IErpBomService
{
return erpBomMapper.restoreErpBomById(id);
}
/**
* 新增bom信息
*
* @param erpBom bom对象
*/
public void insertErpBomSub(ErpBom erpBom)
{
List<ErpBom> erpBomList = erpBom.getErpBomList();
Long id = erpBom.getId();
if (StringUtils.isNotNull(erpBomList))
{
// List<ErpBom> list = new ArrayList<ErpBom>();
for (int i=0;i<erpBomList.size();i++)
{
ErpBom erpBom1 = erpBomList.get(i);
erpBom1.setId(null);
erpBom1.setSortNo((i+1L));
erpBom1.setParentId(id);
erpBom1.setCreateBy(ShiroUtils.getLoginName());
erpBom1.setCreateTime(DateUtils.getNowDate());
erpBomMapper.insertErpBom(erpBom1);
// list.add(erpBom1);
}
// if (list.size() > 0)
// {
// erpBomMapper.batchErpBom(list);
// }
}
}
}

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

@ -14,19 +14,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="bomNo" column="bom_no" />
<result property="materialNo" column="material_no" />
<result property="materialName" column="material_name" />
<result property="materialType" column="material_type" />
<result property="processMethod" column="process_method" />
<result property="unit" column="unit" />
<result property="brand" column="brand" />
<result property="describe" column="describe" />
<result property="useNum" column="use_num" />
<result property="lossRate" column="loss_rate" />
<result property="parentId" column="parent_id" />
<result property="level" column="level" />
<result property="sortNo" column="sort_no" />
<result property="auditStatus" column="audit_status" />
<result property="useStatus" column="use_status" />
</resultMap>
<resultMap id="ErpBomErpBomSubResult" type="ErpBom" extends="ErpBomResult">
<collection property="erpBomList" notNullColumn="sub_id" javaType="java.util.List" resultMap="ErpBomSubResult" />
</resultMap>
<resultMap type="ErpBom" id="ErpBomSubResult">
<result property="id" column="sub_id" />
<result property="delFlag" column="sub_del_flag" />
<result property="createBy" column="sub_create_by" />
<result property="createTime" column="sub_create_time" />
<result property="updateBy" column="sub_update_by" />
<result property="updateTime" column="sub_update_time" />
<result property="remark" column="sub_remark" />
<result property="bomNo" column="sub_bom_no" />
<result property="materialNo" column="sub_material_no" />
<result property="materialName" column="sub_material_name" />
<result property="materialType" column="sub_material_type" />
<result property="processMethod" column="sub_process_method" />
<result property="unit" column="sub_unit" />
<result property="brand" column="sub_brand" />
<result property="describe" column="sub_describe" />
<result property="useNum" column="sub_use_num" />
<result property="lossRate" column="sub_loss_rate" />
<result property="parentId" column="sub_parent_id" />
<result property="level" column="sub_level" />
<result property="sortNo" column="sub_sort_no" />
<result property="auditStatus" column="sub_audit_status" />
<result property="useStatus" column="sub_use_status" />
</resultMap>
<sql id="selectErpBomVo">
select id, del_flag, create_by, create_time, update_by, update_time, remark, bom_no, material_no, audit_status, use_status from erp_bom
select id, del_flag, create_by, create_time, update_by, update_time, remark, bom_no, material_no, material_name, material_type, process_method, unit, brand, `describe`, use_num, loss_rate, parent_id, level, sort_no, audit_status, use_status from erp_bom
</sql>
<select id="selectErpBomList" parameterType="ErpBom" resultMap="ErpBomResult">
<include refid="selectErpBomVo"/>
<where>
<where>
<if test="id != null "> and id = #{id}</if>
<if test="delFlag != null and delFlag != ''"> and del_flag = #{delFlag}</if>
<if test="createBy != null and createBy != ''"> and create_by = #{createBy}</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and update_by = #{updateBy}</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="remark != null and remark != ''"> and remark = #{remark}</if>
<if test="bomNo != null and bomNo != ''"> and bom_no = #{bomNo}</if>
<if test="materialNo != null and materialNo != ''"> and material_no = #{materialNo}</if>
<if test="materialName != null and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
<if test="materialType != null and materialType != ''"> and material_type = #{materialType}</if>
<if test="processMethod != null and processMethod != ''"> and process_method = #{processMethod}</if>
<if test="unit != null and unit != ''"> and unit = #{unit}</if>
<if test="brand != null and brand != ''"> and brand = #{brand}</if>
<if test="describe != null and describe != ''"> and `describe` = #{describe}</if>
<if test="useNum != null "> and use_num = #{useNum}</if>
<if test="lossRate != null "> and loss_rate = #{lossRate}</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="level != null "> and level = #{level}</if>
<if test="sortNo != null "> and sort_no = #{sortNo}</if>
<if test="auditStatus != null and auditStatus != ''"> and audit_status = #{auditStatus}</if>
<if test="useStatus != null and useStatus != ''"> and use_status = #{useStatus}</if>
</where>
@ -36,7 +94,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectErpBomVo"/>
where id = #{id}
</select>
<select id="selectErpBomSubList" parameterType="ErpBom" resultMap="ErpBomResult">
<include refid="selectErpBomVo"/>
<where>
<if test="id != null "> and id = #{id}</if>
<if test="delFlag != null and delFlag != ''"> and del_flag = #{delFlag}</if>
<if test="createBy != null and createBy != ''"> and create_by = #{createBy}</if>
<if test="createTime != null "> and create_time = #{createTime}</if>
<if test="updateBy != null and updateBy != ''"> and update_by = #{updateBy}</if>
<if test="updateTime != null "> and update_time = #{updateTime}</if>
<if test="remark != null and remark != ''"> and remark = #{remark}</if>
<if test="bomNo != null and bomNo != ''"> and bom_no = #{bomNo}</if>
<if test="materialNo != null and materialNo != ''"> and material_no = #{materialNo}</if>
<if test="materialName != null and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
<if test="materialType != null and materialType != ''"> and material_type = #{materialType}</if>
<if test="processMethod != null and processMethod != ''"> and process_method = #{processMethod}</if>
<if test="unit != null and unit != ''"> and unit = #{unit}</if>
<if test="brand != null and brand != ''"> and brand = #{brand}</if>
<if test="describe != null and describe != ''"> and `describe` = #{describe}</if>
<if test="useNum != null "> and use_num = #{useNum}</if>
<if test="lossRate != null "> and loss_rate = #{lossRate}</if>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="level != null "> and level = #{level}</if>
<if test="sortNo != null "> and sort_no = #{sortNo}</if>
<if test="auditStatus != null and auditStatus != ''"> and audit_status = #{auditStatus}</if>
<if test="useStatus != null and useStatus != ''"> and use_status = #{useStatus}</if>
</where>
order by sort_no asc
</select>
<insert id="insertErpBom" parameterType="ErpBom" useGeneratedKeys="true" keyProperty="id">
insert into erp_bom
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -48,6 +135,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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="useNum != null">use_num,</if>
<if test="lossRate != null">loss_rate,</if>
<if test="parentId != null">parent_id,</if>
<if test="level != null">level,</if>
<if test="sortNo != null">sort_no,</if>
<if test="auditStatus != null">audit_status,</if>
<if test="useStatus != null">use_status,</if>
</trim>
@ -60,6 +158,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">#{remark},</if>
<if test="bomNo != null">#{bomNo},</if>
<if test="materialNo != null">#{materialNo},</if>
<if test="materialName != null">#{materialName},</if>
<if test="materialType != null">#{materialType},</if>
<if test="processMethod != null">#{processMethod},</if>
<if test="unit != null">#{unit},</if>
<if test="brand != null">#{brand},</if>
<if test="describe != null">#{describe},</if>
<if test="useNum != null">#{useNum},</if>
<if test="lossRate != null">#{lossRate},</if>
<if test="parentId != null">#{parentId},</if>
<if test="level != null">#{level},</if>
<if test="sortNo != null">#{sortNo},</if>
<if test="auditStatus != null">#{auditStatus},</if>
<if test="useStatus != null">#{useStatus},</if>
</trim>
@ -76,6 +185,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark = #{remark},</if>
<if test="bomNo != null">bom_no = #{bomNo},</if>
<if test="materialNo != null">material_no = #{materialNo},</if>
<if test="materialName != null">material_name = #{materialName},</if>
<if test="materialType != null">material_type = #{materialType},</if>
<if test="processMethod != null">process_method = #{processMethod},</if>
<if test="unit != null">unit = #{unit},</if>
<if test="brand != null">brand = #{brand},</if>
<if test="describe != null">`describe` = #{describe},</if>
<if test="useNum != null">use_num = #{useNum},</if>
<if test="lossRate != null">loss_rate = #{lossRate},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="level != null">level = #{level},</if>
<if test="sortNo != null">sort_no = #{sortNo},</if>
<if test="auditStatus != null">audit_status = #{auditStatus},</if>
<if test="useStatus != null">use_status = #{useStatus},</if>
</trim>
@ -100,5 +220,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="restoreErpBomById" parameterType="Long">
update erp_bom set del_flag = '0' where id = #{id}
</update>
<delete id="deleteErpBomByParentIds" parameterType="String">
delete from erp_bom where parent_id in
<foreach item="parentId" collection="array" open="(" separator="," close=")">
#{parentId}
</foreach>
</delete>
<delete id="deleteErpBomByParentId" parameterType="Long">
delete from erp_bom where parent_id = #{parentId}
</delete>
<insert id="batchErpBom">
insert into erp_bom( id, del_flag, create_by, create_time, update_by, update_time, remark, bom_no, material_no, material_name, material_type, process_method, unit, brand, describe, use_num, loss_rate, parent_id, level, sort_no, audit_status, use_status) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.id}, #{item.delFlag}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark}, #{item.bomNo}, #{item.materialNo}, #{item.materialName}, #{item.materialType}, #{item.processMethod}, #{item.unit}, #{item.brand}, #{item.describe}, #{item.useNum}, #{item.lossRate}, #{item.parentId}, #{item.level}, #{item.sortNo}, #{item.auditStatus}, #{item.useStatus})
</foreach>
</insert>
</mapper>

40
ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js

@ -297,6 +297,10 @@ var table = {
var tableParams = $("#" + currentId).bootstrapTable('getOptions');
var pageSize = $.common.isNotEmpty(tableParams.pageSize) ? tableParams.pageSize: table.options.pageSize;
var pageNumber = $.common.isNotEmpty(tableParams.pageNumber) ? tableParams.pageNumber: table.options.pageNumber;
var sidePagination = $.common.isNotEmpty(tableParams.sidePagination) ? tableParams.sidePagination: table.options.sidePagination;
if (sidePagination == 'client') {
return index + 1;
}
return pageSize * (pageNumber - 1) + index + 1;
},
// 列超出指定长度浮动提示 target(copy单击复制文本 open弹窗打开文本)
@ -847,7 +851,12 @@ var table = {
}
if ($.common.isEmpty(options.yes)) {
options.yes = function(index, layero) {
options.callBack(index, layero);
// 传递唯一键
if(options.uniqueId){
options.callBack(index, layero,options.uniqueId);
}else{
options.callBack(index, layero);
}
}
}
var btnCallback = {};
@ -1173,6 +1182,27 @@ var table = {
};
$.ajax(config)
},
// 保存信息 刷新表格
saveJson: function(url, data, callback) {
var config = {
url: url,
type: "post",
dataType: "json",
contentType: "application/json;charset=utf-8",
data: data,
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
$.modal.disable();
},
success: function(result) {
if (typeof callback == "function") {
callback(result);
}
$.operate.successCallback(result);
}
};
$.ajax(config)
},
// 保存信息 弹出提示框
saveModal: function(url, data, callback) {
var config = {
@ -1651,6 +1681,14 @@ var table = {
});
return json;
},
// formData数据转json字符串
formDataToJson: function(formData) {
let obj = {};
formData.forEach((element) =>{
obj[element.name] = element.value;
});
return JSON.stringify(obj);
},
// 数据字典转下拉框
dictToSelect: function(datas, value, name) {
var actions = [];

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

@ -3,35 +3,29 @@
<head>
<th:block th:include="include :: header('新增bom')" />
<th:block th:include="include :: select2-css" />
<th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-bom-add">
<div class="form-group">
<label class="col-sm-3 control-label is-required">料号:</label>
<div class="col-sm-8">
<!--<div class="input-group">
<input name="materialNo" onclick="selMaterialTb()" id="materialNo" type="text" placeholder="请选择料号" class="form-control" required>
<span class="input-group-addon"><i class="fa fa-search"></i></span>
</div>-->
<select class="form-control" id="materialNo" name="materialNo" required>
</select>
</div>
</div>
<div class="form-group">
<div class="form-group">
<label class="col-sm-3 control-label">物料名称:</label>
<div class="col-sm-8">
<input name="materialName" class="form-control" type="text" disabled>
<input name="materialName" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<div class="form-group">
<label class="col-sm-3 control-label">物料类型:</label>
<div class="col-sm-8">
<select id="selectMaterialType" class="form-control m-b select2-multiple" th:with="childList=${@category.getChildByCode('materialType')}" disabled>
<select id="selectMaterialType" class="form-control m-b select2-multiple" th:with="childList=${@category.getChildByCode('materialType')}" readonly>
<optgroup>
<option value=""></option>
</optgroup>
@ -42,44 +36,105 @@
</div>
<input type="text" id="materialType" name="materialType" hidden />
</div>
<div class="form-group">
<div class="form-group">
<label class="col-sm-3 control-label">加工方式:</label>
<div class="col-sm-8">
<select name="processMethod" class="form-control m-b" th:with="type=${@dict.getType('processMethod')}" disabled>
<select name="processMethod" class="form-control m-b" th:with="type=${@dict.getType('processMethod')}" readonly>
<option value=""></option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
<div class="form-group">
<div class="form-group">
<label class="col-sm-3 control-label">单位:</label>
<div class="col-sm-8">
<select name="unit" class="form-control m-b" th:with="type=${@dict.getType('sys_unit_class')}" disabled>
<select name="unit" class="form-control m-b" th:with="type=${@dict.getType('sys_unit_class')}" readonly>
<option value=""></option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
<div class="form-group">
<div class="form-group">
<label class="col-sm-3 control-label">品牌:</label>
<div class="col-sm-8">
<input name="brand" class="form-control" type="text" disabled>
<input name="brand" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">描述:</label>
<div class="col-sm-8">
<textarea name="describe" class="form-control" disabled></textarea>
<textarea name="describe" class="form-control" readonly></textarea>
</div>
</div>
</form>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="insertRow()">
<i class="fa fa-plus"></i> 新增行
</a>
<a class="btn btn-danger multiple disabled" onclick="removeRow()">
<i class="fa fa-remove"></i> 删除选择行
</a>
</div>
<div class="row">
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-sub-table-1"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
var prefix = ctx + "erp/bom"
$(function(){
function selMaterialTb(){
var options = {
title: '物料选择',
url: ctx + "/erp/material/select",
callBack: doSubmit
};
$.modal.openOptions(options);
}
function doSubmit(index, layero){
var body = layer.getChildFrame('body', index);
$("#treeId").val(body.find('#treeId').val());
$("#treeName").val(body.find('#treeName').val());
layer.close(index);
}
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var bomLevelSelectDatas = [[${@dict.getTypeSelect('bomLevel')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
$("#form-bom-add").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var formData = $("#form-bom-add").serializeArray();
console.log("formData",formData);
var tableData = $("#bootstrap-sub-table-1").bootstrapTable('getData');
console.log("tableData",JSON.stringify(tableData))
var rows = tableData.length;
if(rows==0){
$.modal.alertWarning("子表数据不能为空!");
}else{
formData.push({"name": "erpBomList", "value": tableData});
var jsonData = $.common.formDataToJson(formData);
console.log("jsonData");
console.log(jsonData);
$.operate.saveJson(prefix + "/add", jsonData);
}
}
}
$(function() {
$("#materialNo").select2({
theme: "bootstrap",
allowClear: true,
@ -130,41 +185,232 @@
$("input[name='brand']").val(data.brand);
$("textarea[name='describe']").val(data.describe);
$("#selectMaterialType").val([data.materialType]).trigger("change");
$("input[name='materialType']").val(data.materialType);
$("select[name='processMethod']").val([data.processMethod]).trigger("change");
$("select[name='unit']").val([data.unit]).trigger("change");
});
})
var options = {
id: 'bootstrap-sub-table-1',
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
uniqueId: "id",
pagination: false, // 设置不分页
sidePagination: "client",
columns: [{
checkbox: true
},
{
field: 'id',
title: 'bom主键id',
visible: false
},
{
field: 'index',
align: 'center',
title: "序号",
formatter: function (value, row, index) {
var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
return columnIndex + $.table.serialNumber(index);
}
},
{
title: '选择料号',
events: optEvent,
formatter: optFormatter
},
{
field: 'level',
align: 'center',
title: '层级',
editable : {
type : 'select',
title : '层级',
source : bomLevelSelectDatas,
validate : function(value) {
if (!value) {
return '层级不能为空';
}
}
}
},
{
field: 'materialNo',
align: 'center',
title: '料号'
},
{
field: 'materialName',
align: 'center',
title: '物料名称',
},
{
field: 'materialType',
align: 'center',
title: '物料类型',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
field: 'describe',
align: 'center',
title: '描述'
},
{
field: 'brand',
align: 'center',
title: '品牌'
},
{
field: 'unit',
align: 'center',
title: '单位',
formatter: function(value, row, index) {
return $.table.selectDictLabel(sysUnitClassDatas, value);
}
},
{
field: 'useNum',
align: 'center',
title: '用量',
editable : {
type : 'text',
title : '用量',
validate : function(value) {
if (!value) {
return '用量不能为空';
}
if (isNaN(value)) {
return '用量必须为数字';
}
}
}
},
{
field: 'lossRate',
align: 'center',
title: '损耗率',
editable : {
type : 'text',
title : '损耗率',
validate : function(value) {
if (!value) {
return '损耗率不能为空';
}
if (isNaN(value)) {
return '损耗率必须为数字';
}
}
}
},
{
field: 'processMethod',
align: 'center',
title: '加工方式',
formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
field: 'remark',
align: 'center',
title: '备注',
editable: true
}
]
};
$.table.init(options);
$("#form-bom-add").validate({
focusCleanup: true
function optFormatter(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-search btn-xs optRow" href="javascript:void(0)"><i class="fa fa-search"></i>选择</a> ');
return actions.join('');
}
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/add", $('#form-bom-add').serialize());
}
}
window.optEvent = {
'click .optRow': function(e, value, row, index) {
console.log("optRow");
console.log(row);
var url = ctx + "erp/material/select";
var options = {
title: '选择料号',
url: url,
uniqueId: row.id,
callBack: doSubmit
};
$.modal.openOptions(options);
},
};
function doSubmit(index, layero,uniqueId){
console.log(uniqueId);
var iframeWin = window[layero.find('iframe')[0]['name']];
var rowData = iframeWin.$('#bootstrap-select-table').bootstrapTable('getSelections')[0];
console.log(rowData.materialName);
$("#bootstrap-sub-table-1").bootstrapTable('updateByUniqueId', {
id: uniqueId,
replace:true,
row: {
materialNo: rowData.materialNo,
materialName: rowData.materialName,
materialType: rowData.materialType,
describe: rowData.describe,
brand: rowData.brand,
unit: rowData.unit,
processMethod: rowData.processMethod,
}
})
function selMaterialTb(){
var options = {
title: '物料选择',
url: ctx + "/erp/material/select",
callBack: doSubmit
};
$.modal.openOptions(options);
layer.close(index);
}
function doSubmit(index, layero){
var body = layer.getChildFrame('body', index);
$("#treeId").val(body.find('#treeId').val());
$("#treeName").val(body.find('#treeName').val());
layer.close(index);
/* 新增表格行 */
function insertRow(){
// var uuidStr = uuid();
var timestamp = new Date().getTime();
var totalNum = $("#bootstrap-sub-table-1").bootstrapTable('getData').length;
$("#bootstrap-sub-table-1").bootstrapTable('insertRow', {
index: totalNum, // 你想插入到哪,0表示第一行
row: {
id: timestamp,
index: $.table.serialNumber(totalNum,'bootstrap-sub-table-1'),
remark: "",
bomNo: "",
materialNo: "",
materialName: "",
materialType: "",
processMethod: "",
unit: "",
brand: "",
describe: "",
level: "",
}
})
}
/* 删除指定表格行 */
function removeRow(){
var ids = $.table.selectColumns("id");
if (ids.length == 0) {
$.modal.alertWarning("请至少选择一条记录");
return;
}
$("#bootstrap-sub-table-1").bootstrapTable('remove', {
field: 'id',
values: ids
})
}
</script>
</body>
</html>

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

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('bom列表')" />
<th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
@ -18,6 +19,22 @@
<label>料号:</label>
<input type="text" name="materialNo"/>
</li>
<li>
<label>物料名称:</label>
<input type="text" name="materialName"/>
</li>
<li>
<label>物料类型:</label>
<select id="selectMaterialType" class="form-control m-b select2-multiple" th:with="childList=${@category.getChildByCode('materialType')}">
<optgroup>
<option value=""></option>
</optgroup>
<optgroup th:each="child: ${childList}" th:label="${child.name}">
<option th:each="childSon: ${child.children}" th:value="${childSon.code}" th:text="${#strings.concat(child.name,'-',childSon.name)}"></option>
</optgroup>
</select>
<input type="text" id="materialType" name="materialType" hidden />
</li>
<li>
<label>审核状态:</label>
<select name="auditStatus" th:with="type=${@dict.getType('auditStatus')}">
@ -32,6 +49,8 @@
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</li>
<!--默认查询层级0-->
<input type="text" name="parentId" value="0" hidden/>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
@ -61,16 +80,26 @@
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('erp:bom:edit')}]];
var removeFlag = [[${@permission.hasPermi('erp:bom:remove')}]];
var cancelFlag = [[${@permission.hasPermi('erp:bom:cancel')}]];
var restoreFlag = [[${@permission.hasPermi('erp:bom:restore')}]];
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var levelDatas = [[${@dict.getType('bomLevel')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var auditStatusDatas = [[${@dict.getType('auditStatus')}]];
var useStatusDatas = [[${@dict.getType('useStatus')}]];
var prefix = ctx + "erp/bom";
$(function() {
$('#selectMaterialType').on('select2:select', function (e) {
var data = e.params.data;
$("#materialType").val(data.id);
});
var options = {
url: prefix + "/list",
createUrl: prefix + "/add",
@ -80,6 +109,10 @@
restoreUrl: prefix + "/restore/{id}",
exportUrl: prefix + "/export",
modalName: "bom",
detailView: true,
onExpandRow : function(index, row, $detail) {
initChildTable(index, row, $detail);
},
columns: [{
checkbox: true
},
@ -88,10 +121,6 @@
title: '主键ID',
visible: false
},
{
field: 'remark',
title: '备注'
},
{
field: 'bomNo',
title: 'bom号'
@ -100,6 +129,59 @@
field: 'materialNo',
title: '料号'
},
{
field: 'materialName',
title: '物料名称'
},
{
field: 'materialType',
title: '物料类型',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
field: 'processMethod',
title: '加工方式',
formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
field: 'unit',
title: '单位'
},
{
field: 'brand',
title: '品牌'
},
{
field: 'describe',
title: '描述'
},
{
field: 'useNum',
title: '用量'
},
{
field: 'lossRate',
title: '损耗率'
},
{
field: 'parentId',
title: '父级id'
},
{
field: 'level',
title: '层级',
formatter: function(value, row, index) {
return $.table.selectDictLabel(levelDatas, value);
}
},
{
field: 'sortNo',
title: '排序'
},
{
field: 'auditStatus',
title: '审核状态',
@ -132,6 +214,88 @@
};
$.table.init(options);
});
initChildTable = function(index, row, $detail) {
var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
$(childTable).bootstrapTable({
url: prefix + "/subList",
method: 'post',
sidePagination: "server",
contentType: "application/x-www-form-urlencoded",
queryParams : {
parentId: row.id
},
columns: [{
field: 'id',
title: '主键id',
visible: false
},
{
field: 'level',
title: '层级',
formatter: function(value, row, index) {
return $.table.selectDictLabel(levelDatas, value);
}
},
{
field: 'bomNo',
title: 'bom号'
},
{
field: 'materialNo',
title: '料号'
},
{
field: 'materialName',
title: '物料名称'
},
{
field: 'materialType',
title: '物料类型',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
field: 'describe',
title: '描述'
},
{
field: 'brand',
title: '品牌'
},
{
field: 'unit',
title: '单位'
},
{
field: 'useNum',
title: '用量'
},
{
field: 'lossRate',
title: '损耗率'
},
{
field: 'processMethod',
title: '加工方式',
formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
field: 'parentId',
title: '父级id',
visible: false,
},
{
field: 'sortNo',
title: '排序',
visible: false
}]
});
};
</script>
</body>
</html>

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

@ -2,61 +2,446 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改bom')" />
<th:block th:include="include :: select2-css" />
<th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-bom-edit" th:object="${erpBom}">
<input name="id" th:field="*{id}" type="hidden">
<input id="id" name="id" th:field="*{id}" type="text" hidden>
<input name="bomNo" th:field="*{bomNo}" type="text" hidden>
<div class="form-group">
<label class="col-sm-3 control-label">备注:</label>
<label class="col-sm-3 control-label">料号:</label>
<div class="col-sm-8">
<textarea name="remark" class="form-control">[[*{remark}]]</textarea>
<select class="form-control" id="selMaterialNo" required>
<option th:value="*{materialNo}" selected="selected" th:text="*{materialNo}"></option>
</select>
<input type="text" id="materialNo" name="materialNo" th:field="*{materialNo}" hidden />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">bom号:</label>
<label class="col-sm-3 control-label">物料名称</label>
<div class="col-sm-8">
<input name="bomNo" th:field="*{bomNo}" class="form-control" type="text">
<input name="materialName" th:field="*{materialName}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">料号:</label>
<label class="col-sm-3 control-label">物料类型:</label>
<div class="col-sm-8">
<select id="selectMaterialType" class="form-control m-b select2-multiple" th:with="childList=${@category.getChildByCode('materialType')}" readonly>
<optgroup>
<option value=""></option>
</optgroup>
<optgroup th:each="child: ${childList}" th:label="${child.name}">
<option th:each="childSon: ${child.children}" th:value="${childSon.code}" th:text="${#strings.concat(child.name,'-',childSon.name)}" th:field="*{materialType}"></option>
</optgroup>
</select>
</div>
<input type="text" id="materialType" name="materialType" th:field="*{materialType}" hidden />
</div>
<div class="form-group">
<label class="col-sm-3 control-label">加工方式:</label>
<div class="col-sm-8">
<input name="materialNo" th:field="*{materialNo}" class="form-control" type="text">
<select name="processMethod" class="form-control m-b" th:with="type=${@dict.getType('processMethod')}" readonly>
<option value=""></option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{processMethod}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">审核状态:</label>
<label class="col-sm-3 control-label">单位</label>
<div class="col-sm-8">
<div class="radio-box" th:each="dict : ${@dict.getType('auditStatus')}">
<input type="radio" th:id="${'auditStatus_' + dict.dictCode}" name="auditStatus" th:value="${dict.dictValue}" th:field="*{auditStatus}">
<label th:for="${'auditStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
</div>
<select name="unit" class="form-control m-b" th:with="type=${@dict.getType('sys_unit_class')}" readonly>
<option value=""></option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{unit}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">使用状态:</label>
<label class="col-sm-3 control-label">品牌</label>
<div class="col-sm-8">
<div class="radio-box" th:each="dict : ${@dict.getType('useStatus')}">
<input type="radio" th:id="${'useStatus_' + dict.dictCode}" name="useStatus" th:value="${dict.dictValue}" th:field="*{useStatus}">
<label th:for="${'useStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
</div>
<input name="brand" th:field="*{brand}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">描述:</label>
<div class="col-sm-8">
<textarea name="describe" class="form-control" readonly>[[*{describe}]]</textarea>
</div>
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="insertRow()">
<i class="fa fa-plus"></i> 新增行
</a>
<a class="btn btn-danger multiple disabled" onclick="removeRow()">
<i class="fa fa-remove"></i> 删除选择行
</a>
</div>
<div class="row">
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-sub-table-1"></table>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-table-editable-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
var prefix = ctx + "erp/bom";
function selMaterialTb(){
var options = {
title: '物料选择',
url: ctx + "/erp/material/select",
callBack: doSubmit
};
$.modal.openOptions(options);
}
function doSubmit(index, layero){
var body = layer.getChildFrame('body', index);
$("#treeId").val(body.find('#treeId').val());
$("#treeName").val(body.find('#treeName').val());
layer.close(index);
}
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var bomLevelSelectDatas = [[${@dict.getTypeSelect('bomLevel')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
$("#form-bom-edit").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-bom-edit').serialize());
var formData = $("#form-bom-edit").serializeArray();
console.log("formData",formData);
var tableData = $("#bootstrap-sub-table-1").bootstrapTable('getData');
console.log("tableData",JSON.stringify(tableData))
var rows = tableData.length;
if(rows==0){
$.modal.alertWarning("子表数据不能为空!");
}else{
formData.push({"name": "erpBomList", "value": tableData});
var jsonData = $.common.formDataToJson(formData);
console.log("jsonData");
console.log(jsonData);
$.operate.saveJson(prefix + "/edit", jsonData);
}
}
}
$(function() {
$("#selMaterialNo").select2({
theme: "bootstrap",
allowClear: true,
placeholder: "请选择一个料号",
ajax:{
type: "post",
url:ctx+"erp/material/list",
dataType:"json",
delay:250,
data:function(params){
var searchVal = params.term;
var obj = {
params:{
materialNo: searchVal
}
};
return obj;
/*return {
materialNo: params.term,
// page: params.page || 1
};*/
},
cache:true,
processResults: function (res, params) {
var resultList = res.rows;
var options = [];
for(var i= 0, len=resultList.length;i<len;i++){
var option = resultList[i];
option.id = resultList[i]["materialNo"];
option.text = resultList[i]["materialNo"];
options.push(option);
}
return {
results: options,
pagination: {
// more:res["data"]["more"]
}
};
},
escapeMarkup: function (markup) { return markup; },
// minimumInputLength: 1
}
});
var materialNo = $("#materialNo").val();
$("#selMaterialNo").val([materialNo]).trigger("change");
$('#selMaterialNo').on('select2:select', function (e) {
var data = e.params.data;
$("input[name='materialNo']").val(data.materialNo);
$("input[name='materialName']").val(data.materialName);
$("input[name='brand']").val(data.brand);
$("textarea[name='describe']").val(data.describe);
$("#selectMaterialType").val([data.materialType]).trigger("change");
$("input[name='materialType']").val(data.materialType);
$("select[name='processMethod']").val([data.processMethod]).trigger("change");
$("select[name='unit']").val([data.unit]).trigger("change");
});
var options = {
url: prefix + "/subList",
id: 'bootstrap-sub-table-1',
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
uniqueId: "id",
pagination: false, // 设置不分页
sidePagination: "client",
queryParams: queryParams,
columns: [{
checkbox: true
},
{
field: 'id',
title: 'bom主键id',
visible: false
},
{
field: 'parentId',
title: '父级id',
visible: false
},
{
field: 'index',
align: 'center',
title: "序号",
formatter: function (value, row, index) {
var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
return columnIndex + $.table.serialNumber(index);
}
},
{
title: '选择料号',
events: optEvent,
formatter: optFormatter
},
{
field: 'level',
align: 'center',
title: '层级',
editable : {
type : 'select',
title : '层级',
source : bomLevelSelectDatas,
validate : function(value) {
if (!value) {
return '层级不能为空';
}
}
}
},
{
field: 'materialNo',
align: 'center',
title: '料号'
},
{
field: 'materialName',
align: 'center',
title: '物料名称',
},
{
field: 'materialType',
align: 'center',
title: '物料类型',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
field: 'describe',
align: 'center',
title: '描述'
},
{
field: 'brand',
align: 'center',
title: '品牌'
},
{
field: 'unit',
align: 'center',
title: '单位',
formatter: function(value, row, index) {
return $.table.selectDictLabel(sysUnitClassDatas, value);
}
},
{
field: 'useNum',
align: 'center',
title: '用量',
editable : {
type : 'text',
title : '用量',
validate : function(value) {
if (!value) {
return '用量不能为空';
}
if (isNaN(value)) {
return '用量必须为数字';
}
}
}
},
{
field: 'lossRate',
align: 'center',
title: '损耗率',
editable : {
type : 'text',
title : '损耗率',
validate : function(value) {
if (!value) {
return '损耗率不能为空';
}
if (isNaN(value)) {
return '损耗率必须为数字';
}
}
}
},
{
field: 'processMethod',
align: 'center',
title: '加工方式',
formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
field: 'remark',
align: 'center',
title: '备注',
editable: true
}
]
};
$.table.init(options);
function optFormatter(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-search btn-xs optRow" href="javascript:void(0)"><i class="fa fa-search"></i>选择</a> ');
return actions.join('');
}
});
function queryParams(params) {
var curParams = {
// 传递参数查询参数
pageSize: params.limit,
pageNum: params.offset / params.limit + 1,
searchValue: params.search,
orderByColumn: params.sort,
isAsc: params.order
};
// 额外传参
curParams.parentId = $("#id").val();
return curParams;
}
window.optEvent = {
'click .optRow': function(e, value, row, index) {
console.log("optRow");
console.log(row);
var url = ctx + "erp/material/select";
var options = {
title: '选择料号',
url: url,
uniqueId: row.id,
callBack: doSubmit
};
$.modal.openOptions(options);
},
};
function doSubmit(index, layero,uniqueId){
console.log(uniqueId);
var iframeWin = window[layero.find('iframe')[0]['name']];
var rowData = iframeWin.$('#bootstrap-select-table').bootstrapTable('getSelections')[0];
console.log(rowData.materialName);
$("#bootstrap-sub-table-1").bootstrapTable('updateByUniqueId', {
id: uniqueId,
replace:true,
row: {
materialNo: rowData.materialNo,
materialName: rowData.materialName,
materialType: rowData.materialType,
describe: rowData.describe,
brand: rowData.brand,
unit: rowData.unit,
processMethod: rowData.processMethod,
}
})
layer.close(index);
}
/* 新增表格行 */
function insertRow(){
// var uuidStr = uuid();
var timestamp = new Date().getTime();
var totalNum = $("#bootstrap-sub-table-1").bootstrapTable('getData').length;
$("#bootstrap-sub-table-1").bootstrapTable('insertRow', {
index: totalNum, // 你想插入到哪,0表示第一行
row: {
id: timestamp,
index: $.table.serialNumber(totalNum,'bootstrap-sub-table-1'),
remark: "",
bomNo: "",
materialNo: "",
materialName: "",
materialType: "",
processMethod: "",
unit: "",
brand: "",
describe: "",
level: "",
}
})
}
/* 删除指定表格行 */
function removeRow(){
var ids = $.table.selectColumns("id");
if (ids.length == 0) {
$.modal.alertWarning("请至少选择一条记录");
return;
}
$("#bootstrap-sub-table-1").bootstrapTable('remove', {
field: 'id',
values: ids
})
}
</script>
</body>
</html>

115
ruoyi-admin/src/main/resources/templates/erp/material/select.html

@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<th:block th:include="include :: header('物料信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="formId">
<div class="select-list">
<ul>
<li>
<label>料号:</label>
<input type="text" name="materialNo"/>
</li>
<li>
<label>物料名称:</label>
<input type="text" name="materialName"/>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
</li>
</ul>
</div>
</form>
</div>
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-select-table"></table>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('erp:material:edit')}]];
var auditFlag = [[${@permission.hasPermi('erp:material:audit')}]];
var removeFlag = [[${@permission.hasPermi('erp:material:remove')}]];
var cancelFlag = [[${@permission.hasPermi('erp:material:cancel')}]];
var restoreFlag = [[${@permission.hasPermi('erp:material:restore')}]];
var auditStatusDatas = [[${@dict.getType('auditStatus')}]];
var useStatusDatas = [[${@dict.getType('useStatus')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var sysUnitClassDatas = [[${@dict.getType('sysUnitClassDatas')}]];
var warehouseDeptDatas = [[${@dict.getType('warehouseDept')}]];
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var prefix = ctx + "erp/material";
$(function() {
var options = {
id: 'bootstrap-select-table',
clickToSelect: true, // 点击选中行
singleSelect: true, // 单选
url: prefix + "/list",
modalName: "物料信息",
columns: [{
checkbox: true
},
{
field: 'id',
title: '主键ID',
visible: false
},
{
field: 'materialNo',
title: '料号'
},
{
field: 'photoUrl',
title: '图片',
formatter: function(value, row, index) {
return $.table.imageView(value);
}
},
{
field: 'materialName',
title: '物料名称'
},
{
field: 'materialType',
title: '物料类型',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
field: 'brand',
title: '品牌'
},
{
field: 'unit',
title: '单位',
formatter: function(value, row, index) {
return $.table.selectDictLabel(sysUnitClassDatas, value);
}
},
{
field: 'describe',
title: '描述'
},
{
field: 'processMethod',
title: '加工方式',
formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
}
]
};
$.table.init(options);
});
</script>
</body>
</html>

27
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/DictService.java

@ -1,6 +1,11 @@
package com.ruoyi.framework.web.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.domain.entity.SysDictData;
@ -43,4 +48,26 @@ public class DictService
{
return dictDataService.selectDictLabel(dictType, dictValue);
}
/**
* 根据字典类型转换成select值
* @param dictType
* @return
*/
public List<Map<String,String>> getTypeSelect(String dictType)
{
List<Map<String,String>> result = new ArrayList<>();
List<SysDictData> sysDictDataList = dictTypeService.selectDictDataByType(dictType);
if(CollectionUtils.isNotEmpty(sysDictDataList)){
for(SysDictData sysDictData:sysDictDataList){
Map<String,String> dictOne = new HashMap<>();
String value = sysDictData.getDictValue();
String text = sysDictData.getDictLabel();
dictOne.put("value",value);
dictOne.put("text",text);
result.add(dictOne);
}
}
return result;
}
}

6
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java

@ -134,8 +134,8 @@ public class GenController extends BaseController
List<CxSelect> cxSelect = new ArrayList<CxSelect>();
for (GenTable genTable : genTables)
{
if (!StringUtils.equals(table.getTableName(), genTable.getTableName()))
{
// if (!StringUtils.equals(table.getTableName(), genTable.getTableName()))
// {
CxSelect cxTable = new CxSelect(genTable.getTableName(), genTable.getTableName() + ':' + genTable.getTableComment());
List<CxSelect> cxColumns = new ArrayList<CxSelect>();
for (GenTableColumn tableColumn : genTable.getColumns())
@ -144,7 +144,7 @@ public class GenController extends BaseController
}
cxTable.setS(cxColumns);
cxSelect.add(cxTable);
}
// }
}
mmap.put("table", table);
mmap.put("data", JSON.toJSON(cxSelect));

Loading…
Cancel
Save