Browse Source

[update]:物料信息增加物料类型分类字典;增加分类字典公共类

erp、
youjianchi 1 year ago
parent
commit
c8c0ade99d
  1. 15
      ruoyi-admin/src/main/resources/templates/erp/material/add.html
  2. 20
      ruoyi-admin/src/main/resources/templates/erp/material/edit.html
  3. 21
      ruoyi-admin/src/main/resources/templates/erp/material/material.html
  4. 24
      ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/CategoryService.java
  5. 123
      ruoyi-system/src/main/java/com/ruoyi/system/domain/SysCategory.java
  6. 68
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysCategoryMapper.java
  7. 65
      ruoyi-system/src/main/java/com/ruoyi/system/service/ISysCategoryService.java
  8. 112
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysCategoryServiceImpl.java
  9. 114
      ruoyi-system/src/main/resources/mapper/system/SysCategoryMapper.xml

15
ruoyi-admin/src/main/resources/templates/erp/material/add.html

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('新增物料信息')" />
<th:block th:include="include :: select2-css" />
<link th:href="@{/ajax/libs/element-ui/element-ui.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
@ -46,11 +47,16 @@
<div class="form-group">
<label class="col-sm-3 control-label">物料类型:</label>
<div class="col-sm-8">
<select name="materialType" class="form-control m-b">
<option value="">所有</option>
<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>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
</div>
<input type="text" id="materialType" name="materialType" hidden />
</div>
<div class="form-group">
<label class="col-sm-3 control-label">加工方式:</label>
@ -108,6 +114,7 @@
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:src="@{/ajax/libs/vue/vue.js}"></script>
<script th:src="@{/ajax/libs/element-ui/element-ui.js}"></script>
<script type="text/javascript">
@ -203,6 +210,8 @@
function submitHandler() {
if ($.validate.form()) {
var materialType = $('#selectMaterialType').select2('val');
$('#materialType').val(materialType);
$.operate.save(prefix + "/add", $('#form-material-add').serialize());
}
}

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

@ -2,6 +2,7 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('修改物料信息')" />
<th:block th:include="include :: select2-css" />
<link th:href="@{/ajax/libs/element-ui/element-ui.css}" rel="stylesheet"/>
</head>
<body class="white-bg">
@ -47,11 +48,16 @@
<div class="form-group">
<label class="col-sm-3 control-label">物料类型:</label>
<div class="col-sm-8">
<select name="materialType" class="form-control m-b">
<option value="">所有</option>
<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>
<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
</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>
@ -111,6 +117,7 @@
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<script th:src="@{/ajax/libs/vue/vue.js}"></script>
<script th:src="@{/ajax/libs/element-ui/element-ui.js}"></script>
<script type="text/javascript">
@ -129,6 +136,11 @@
}
},
mounted() {
// 控制下拉框选中
var materialType = $("#materialType").val();
$("#selectMaterialType").val(materialType).trigger("change");
var that = this;
// 页面渲染完成,可以执行需要的操作
console.log('页面已渲染完成');
@ -251,6 +263,8 @@
function submitHandler() {
if ($.validate.form()) {
var materialType = $('#selectMaterialType').select2('val');
$('#materialType').val(materialType);
$.operate.save(prefix + "/edit", $('#form-material-edit').serialize());
}
}

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

@ -114,6 +114,7 @@
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() {
@ -167,7 +168,25 @@
},
{
field: 'materialType',
title: '物料类型'
title: '物料类型',
formatter: function(value, row, index) {
if ($.common.isEmpty(materialTypeDatas) || $.common.isEmpty(value)) {
return '';
}
var materialTypeName = '';
$.each(materialTypeDatas, function(index, category) {
var childName = category.name;
var childSonArray = category.children;
$.each(childSonArray, function(index, son) {
var sonCode = son.code;
var sonName = son.name;
if (sonCode == value) {
materialTypeName = childName+"-"+sonName;
}
});
});
return materialTypeName;
}
},
{
field: 'unit',

24
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/CategoryService.java

@ -0,0 +1,24 @@
package com.ruoyi.framework.web.service;
import com.ruoyi.system.domain.SysCategory;
import com.ruoyi.system.service.ISysCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Description thymeleaf调用得到分类字典
* @Author youjianchi
* @Date 2023/11/17 15:00
*/
@Service("category")
public class CategoryService {
@Autowired
private ISysCategoryService categoryService;
public List<SysCategory> getChildByCode(String code){
return categoryService.getChildByCode(code);
}
}

123
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysCategory.java

@ -0,0 +1,123 @@
package com.ruoyi.system.domain;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.List;
/**
* 分类字典对象 sys_category
*
* @author ruoyi
* @date 2023-11-17
*/
public class SysCategory extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键ID */
private Long id;
/** 删除标志(0代表存在 1代表删除) */
private String delFlag;
/** 父级id */
@Excel(name = "父级id")
private Long parentId;
/** 类型编码 */
@Excel(name = "类型编码")
private String code;
/** 类型名称 */
@Excel(name = "类型名称")
private String name;
/** 类型排序 */
@Excel(name = "类型排序")
private Long sortOrder;
private List<SysCategory> children;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getDelFlag()
{
return delFlag;
}
public void setParentId(Long parentId)
{
this.parentId = parentId;
}
public Long getParentId()
{
return parentId;
}
public void setCode(String code)
{
this.code = code;
}
public String getCode()
{
return code;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setSortOrder(Long sortOrder)
{
this.sortOrder = sortOrder;
}
public Long getSortOrder()
{
return sortOrder;
}
public List<SysCategory> getChildren() {
return children;
}
public void setChildren(List<SysCategory> children) {
this.children = children;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("parentId", getParentId())
.append("code", getCode())
.append("name", getName())
.append("sortOrder", getSortOrder())
.toString();
}
}

68
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysCategoryMapper.java

@ -0,0 +1,68 @@
package com.ruoyi.system.mapper;
import com.ruoyi.system.domain.SysCategory;
import java.util.List;
/**
* 分类字典Mapper接口
*
* @author ruoyi
* @date 2023-11-17
*/
public interface SysCategoryMapper
{
/**
* 查询分类字典
*
* @param id 分类字典ID
* @return 分类字典
*/
public SysCategory selectSysCategoryById(Long id);
/**
* 查询分类字典列表
*
* @param sysCategory 分类字典
* @return 分类字典集合
*/
public List<SysCategory> selectSysCategoryList(SysCategory sysCategory);
/**
* 新增分类字典
*
* @param sysCategory 分类字典
* @return 结果
*/
public int insertSysCategory(SysCategory sysCategory);
/**
* 修改分类字典
*
* @param sysCategory 分类字典
* @return 结果
*/
public int updateSysCategory(SysCategory sysCategory);
/**
* 删除分类字典
*
* @param id 分类字典ID
* @return 结果
*/
public int deleteSysCategoryById(Long id);
/**
* 批量删除分类字典
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysCategoryByIds(String[] ids);
List<SysCategory> getChildByCode(String code);
List<SysCategory> getChildByParentIdList(List<String> parentIdList);
List<SysCategory> getChildByParentId(Long parentId);
}

65
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysCategoryService.java

@ -0,0 +1,65 @@
package com.ruoyi.system.service;
import com.ruoyi.system.domain.SysCategory;
import java.util.List;
/**
* 分类字典Service接口
*
* @author ruoyi
* @date 2023-11-17
*/
public interface ISysCategoryService
{
/**
* 查询分类字典
*
* @param id 分类字典ID
* @return 分类字典
*/
public SysCategory selectSysCategoryById(Long id);
/**
* 查询分类字典列表
*
* @param sysCategory 分类字典
* @return 分类字典集合
*/
public List<SysCategory> selectSysCategoryList(SysCategory sysCategory);
/**
* 新增分类字典
*
* @param sysCategory 分类字典
* @return 结果
*/
public int insertSysCategory(SysCategory sysCategory);
/**
* 修改分类字典
*
* @param sysCategory 分类字典
* @return 结果
*/
public int updateSysCategory(SysCategory sysCategory);
/**
* 批量删除分类字典
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysCategoryByIds(String ids);
/**
* 删除分类字典信息
*
* @param id 分类字典ID
* @return 结果
*/
public int deleteSysCategoryById(Long id);
List<SysCategory> getChildByCode(String code);
}

112
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysCategoryServiceImpl.java

@ -0,0 +1,112 @@
package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysCategory;
import com.ruoyi.system.mapper.SysCategoryMapper;
import com.ruoyi.system.service.ISysCategoryService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 分类字典Service业务层处理
*
* @author ruoyi
* @date 2023-11-17
*/
@Service
public class SysCategoryServiceImpl implements ISysCategoryService
{
@Autowired
private SysCategoryMapper sysCategoryMapper;
/**
* 查询分类字典
*
* @param id 分类字典ID
* @return 分类字典
*/
@Override
public SysCategory selectSysCategoryById(Long id)
{
return sysCategoryMapper.selectSysCategoryById(id);
}
/**
* 查询分类字典列表
*
* @param sysCategory 分类字典
* @return 分类字典
*/
@Override
public List<SysCategory> selectSysCategoryList(SysCategory sysCategory)
{
return sysCategoryMapper.selectSysCategoryList(sysCategory);
}
/**
* 新增分类字典
*
* @param sysCategory 分类字典
* @return 结果
*/
@Override
public int insertSysCategory(SysCategory sysCategory)
{
sysCategory.setCreateTime(DateUtils.getNowDate());
return sysCategoryMapper.insertSysCategory(sysCategory);
}
/**
* 修改分类字典
*
* @param sysCategory 分类字典
* @return 结果
*/
@Override
public int updateSysCategory(SysCategory sysCategory)
{
sysCategory.setUpdateTime(DateUtils.getNowDate());
return sysCategoryMapper.updateSysCategory(sysCategory);
}
/**
* 删除分类字典对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteSysCategoryByIds(String ids)
{
return sysCategoryMapper.deleteSysCategoryByIds(Convert.toStrArray(ids));
}
/**
* 删除分类字典信息
*
* @param id 分类字典ID
* @return 结果
*/
@Override
public int deleteSysCategoryById(Long id)
{
return sysCategoryMapper.deleteSysCategoryById(id);
}
@Override
public List<SysCategory> getChildByCode(String code) {
List<SysCategory> childCgList = sysCategoryMapper.getChildByCode(code);
if(CollectionUtils.isNotEmpty(childCgList)){
childCgList.forEach(child->{
Long childId = child.getId();
List<SysCategory> childSonList = sysCategoryMapper.getChildByParentId(childId);
child.setChildren(childSonList);
});
}
return childCgList;
}
}

114
ruoyi-system/src/main/resources/mapper/system/SysCategoryMapper.xml

@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysCategoryMapper">
<resultMap type="SysCategory" id="SysCategoryResult">
<result property="id" column="id" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="parentId" column="parent_id" />
<result property="code" column="code" />
<result property="name" column="name" />
<result property="sortOrder" column="sort_order" />
</resultMap>
<sql id="selectSysCategoryVo">
select id, del_flag, create_by, create_time, update_by, update_time, remark, parent_id, code, name, sort_order from sys_category
</sql>
<select id="selectSysCategoryList" parameterType="SysCategory" resultMap="SysCategoryResult">
<include refid="selectSysCategoryVo"/>
<where>
<if test="parentId != null "> and parent_id = #{parentId}</if>
<if test="code != null and code != ''"> and code = #{code}</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="sortOrder != null "> and sort_order = #{sortOrder}</if>
</where>
</select>
<select id="selectSysCategoryById" parameterType="Long" resultMap="SysCategoryResult">
<include refid="selectSysCategoryVo"/>
where id = #{id}
</select>
<select id="getChildByCode" resultMap="SysCategoryResult">
<include refid="selectSysCategoryVo"/>
where parent_id = (select id from sys_category where code = #{code})
order by sort_order
</select>
<select id="getChildByParentIdList" resultMap="SysCategoryResult">
<include refid="selectSysCategoryVo"/>
where parent_id in
<foreach item="parentId" collection="parentIdList" open="(" separator="," close=")">
#{parentId}
</foreach>
order by sort_order
</select>
<select id="getChildByParentId" resultMap="SysCategoryResult">
<include refid="selectSysCategoryVo"/>
where parent_id = #{parentId}
order by sort_order
</select>
<insert id="insertSysCategory" parameterType="SysCategory" useGeneratedKeys="true" keyProperty="id">
insert into sys_category
<trim prefix="(" suffix=")" suffixOverrides=",">
<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 and updateBy != ''">update_by,</if>
<if test="updateTime != null ">update_time,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="parentId != null ">parent_id,</if>
<if test="code != null and code != ''">code,</if>
<if test="name != null and name != ''">name,</if>
<if test="sortOrder != null ">sort_order,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<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 and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null ">#{updateTime},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="parentId != null ">#{parentId},</if>
<if test="code != null and code != ''">#{code},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="sortOrder != null ">#{sortOrder},</if>
</trim>
</insert>
<update id="updateSysCategory" parameterType="SysCategory">
update sys_category
<trim prefix="SET" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null ">update_time = #{updateTime},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="parentId != null ">parent_id = #{parentId},</if>
<if test="code != null and code != ''">code = #{code},</if>
<if test="name != null and name != ''">name = #{name},</if>
<if test="sortOrder != null ">sort_order = #{sortOrder},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSysCategoryById" parameterType="Long">
delete from sys_category where id = #{id}
</delete>
<delete id="deleteSysCategoryByIds" parameterType="String">
delete from sys_category where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
Loading…
Cancel
Save