diff --git a/pom.xml b/pom.xml
index 4188830..ac3af71 100644
--- a/pom.xml
+++ b/pom.xml
@@ -261,6 +261,13 @@
${paho.mqtt.version}
+
+
+ com.belerweb
+ pinyin4j
+ 2.5.0
+
+
diff --git a/src/main/java/com/shzg/project/worn/controller/WornMaterialTypeController.java b/src/main/java/com/shzg/project/worn/controller/WornMaterialTypeController.java
index c363bd7..e08b649 100644
--- a/src/main/java/com/shzg/project/worn/controller/WornMaterialTypeController.java
+++ b/src/main/java/com/shzg/project/worn/controller/WornMaterialTypeController.java
@@ -22,7 +22,7 @@ import com.shzg.common.utils.poi.ExcelUtil;
import com.shzg.framework.web.page.TableDataInfo;
/**
- * 废旧系统物料类型(支持父子级树结构)Controller
+ * 物料类型Controller
*
* @author shzg
* @date 2026-03-11
@@ -35,7 +35,7 @@ public class WornMaterialTypeController extends BaseController
private IWornMaterialTypeService wornMaterialTypeService;
/**
- * 查询废旧系统物料类型(支持父子级树结构)列表
+ * 查询物料类型列表
*/
@PreAuthorize("@ss.hasPermi('worn:type:list')")
@GetMapping("/list")
@@ -46,21 +46,22 @@ public class WornMaterialTypeController extends BaseController
return getDataTable(list);
}
+
/**
- * 导出废旧系统物料类型(支持父子级树结构)列表
+ * 导出物料类型列表
*/
@PreAuthorize("@ss.hasPermi('worn:type:export')")
- @Log(title = "废旧系统物料类型(支持父子级树结构)", businessType = BusinessType.EXPORT)
+ @Log(title = "物料类型", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, WornMaterialType wornMaterialType)
{
List list = wornMaterialTypeService.selectWornMaterialTypeList(wornMaterialType);
ExcelUtil util = new ExcelUtil(WornMaterialType.class);
- util.exportExcel(response, list, "废旧系统物料类型(支持父子级树结构)数据");
+ util.exportExcel(response, list, "物料类型数据");
}
/**
- * 获取废旧系统物料类型(支持父子级树结构)详细信息
+ * 获取物料类型详细信息
*/
@PreAuthorize("@ss.hasPermi('worn:type:query')")
@GetMapping(value = "/{id}")
@@ -70,10 +71,10 @@ public class WornMaterialTypeController extends BaseController
}
/**
- * 新增废旧系统物料类型(支持父子级树结构)
+ * 新增物料类型
*/
@PreAuthorize("@ss.hasPermi('worn:type:add')")
- @Log(title = "废旧系统物料类型(支持父子级树结构)", businessType = BusinessType.INSERT)
+ @Log(title = "物料类型", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody WornMaterialType wornMaterialType)
{
@@ -81,10 +82,10 @@ public class WornMaterialTypeController extends BaseController
}
/**
- * 修改废旧系统物料类型(支持父子级树结构)
+ * 修改物料类型
*/
@PreAuthorize("@ss.hasPermi('worn:type:edit')")
- @Log(title = "废旧系统物料类型(支持父子级树结构)", businessType = BusinessType.UPDATE)
+ @Log(title = "物料类型", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody WornMaterialType wornMaterialType)
{
@@ -92,13 +93,25 @@ public class WornMaterialTypeController extends BaseController
}
/**
- * 删除废旧系统物料类型(支持父子级树结构)
+ * 删除物料类型
*/
@PreAuthorize("@ss.hasPermi('worn:type:remove')")
- @Log(title = "废旧系统物料类型(支持父子级树结构)", businessType = BusinessType.DELETE)
+ @Log(title = "物料类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(wornMaterialTypeService.deleteWornMaterialTypeByIds(ids));
}
+
+ /**
+ * 查询物料类型树结构
+ */
+ @PreAuthorize("@ss.hasPermi('worn:type:list')")
+ @GetMapping("/tree")
+ public AjaxResult tree()
+ {
+ List tree = wornMaterialTypeService.selectWornMaterialTypeTree();
+ return AjaxResult.success(tree);
+ }
+
}
diff --git a/src/main/java/com/shzg/project/worn/domain/WornMaterial.java b/src/main/java/com/shzg/project/worn/domain/WornMaterial.java
index 13036a6..11bd998 100644
--- a/src/main/java/com/shzg/project/worn/domain/WornMaterial.java
+++ b/src/main/java/com/shzg/project/worn/domain/WornMaterial.java
@@ -9,7 +9,7 @@ import com.shzg.framework.aspectj.lang.annotation.Excel;
/**
* 物料对象 worn_material
- *
+ *
* @author shzg
* @date 2026-03-11
*/
@@ -80,189 +80,249 @@ public class WornMaterial extends BaseEntity
@Excel(name = "逻辑删除", readConverterExp = "0=正常,1=删除")
private String isDelete;
- public void setId(Long id)
- {
- this.id = id;
- }
- public Long getId()
+ // ================== 查询展示字段(不落库) ==================
+
+ /** 单位名称 */
+ private String unitName;
+
+ /** 当前类型名称 */
+ private String typeName;
+
+ /** 类型祖级ID */
+ private String typeAncestors;
+
+ /** 父级类型名称 */
+ private String typeParentNames;
+
+
+ public Long getId()
{
return id;
}
- public void setMaterialName(String materialName)
+ public void setId(Long id)
{
- this.materialName = materialName;
+ this.id = id;
}
- public String getMaterialName()
+ public String getMaterialName()
{
return materialName;
}
- public void setMaterialShortName(String materialShortName)
+ public void setMaterialName(String materialName)
{
- this.materialShortName = materialShortName;
+ this.materialName = materialName;
}
- public String getMaterialShortName()
+ public String getMaterialShortName()
{
return materialShortName;
}
- public void setMaterialCode(String materialCode)
+ public void setMaterialShortName(String materialShortName)
{
- this.materialCode = materialCode;
+ this.materialShortName = materialShortName;
}
- public String getMaterialCode()
+ public String getMaterialCode()
{
return materialCode;
}
- public void setTypeId(Long typeId)
+ public void setMaterialCode(String materialCode)
{
- this.typeId = typeId;
+ this.materialCode = materialCode;
}
- public Long getTypeId()
+ public Long getTypeId()
{
return typeId;
}
- public void setUnitId(Long unitId)
+ public void setTypeId(Long typeId)
{
- this.unitId = unitId;
+ this.typeId = typeId;
}
- public Long getUnitId()
+ public Long getUnitId()
{
return unitId;
}
- public void setMaterialCategory(String materialCategory)
+ public void setUnitId(Long unitId)
{
- this.materialCategory = materialCategory;
+ this.unitId = unitId;
}
- public String getMaterialCategory()
+ public String getMaterialCategory()
{
return materialCategory;
}
- public void setKgFactor(BigDecimal kgFactor)
+ public void setMaterialCategory(String materialCategory)
{
- this.kgFactor = kgFactor;
+ this.materialCategory = materialCategory;
}
- public BigDecimal getKgFactor()
+ public BigDecimal getKgFactor()
{
return kgFactor;
}
- public void setSpecification(String specification)
+ public void setKgFactor(BigDecimal kgFactor)
{
- this.specification = specification;
+ this.kgFactor = kgFactor;
}
- public String getSpecification()
+ public String getSpecification()
{
return specification;
}
- public void setModel(String model)
+ public void setSpecification(String specification)
{
- this.model = model;
+ this.specification = specification;
}
- public String getModel()
+ public String getModel()
{
return model;
}
- public void setBarcode(String barcode)
+ public void setModel(String model)
{
- this.barcode = barcode;
+ this.model = model;
}
- public String getBarcode()
+ public String getBarcode()
{
return barcode;
}
- public void setWeight(BigDecimal weight)
+ public void setBarcode(String barcode)
{
- this.weight = weight;
+ this.barcode = barcode;
}
- public BigDecimal getWeight()
+ public BigDecimal getWeight()
{
return weight;
}
- public void setDescription(String description)
+ public void setWeight(BigDecimal weight)
{
- this.description = description;
+ this.weight = weight;
}
- public String getDescription()
+ public String getDescription()
{
return description;
}
- public void setOrderNum(Long orderNum)
+ public void setDescription(String description)
{
- this.orderNum = orderNum;
+ this.description = description;
}
- public Long getOrderNum()
+ public Long getOrderNum()
{
return orderNum;
}
- public void setStatus(String status)
+ public void setOrderNum(Long orderNum)
{
- this.status = status;
+ this.orderNum = orderNum;
}
- public String getStatus()
+ public String getStatus()
{
return status;
}
- public void setIsDelete(String isDelete)
+ public void setStatus(String status)
+ {
+ this.status = status;
+ }
+
+ public String getIsDelete()
+ {
+ return isDelete;
+ }
+
+ public void setIsDelete(String isDelete)
{
this.isDelete = isDelete;
}
- public String getIsDelete()
+ public String getUnitName()
{
- return isDelete;
+ return unitName;
+ }
+
+ public void setUnitName(String unitName)
+ {
+ this.unitName = unitName;
+ }
+
+ public String getTypeName()
+ {
+ return typeName;
+ }
+
+ public void setTypeName(String typeName)
+ {
+ this.typeName = typeName;
+ }
+
+ public String getTypeAncestors()
+ {
+ return typeAncestors;
+ }
+
+ public void setTypeAncestors(String typeAncestors)
+ {
+ this.typeAncestors = typeAncestors;
+ }
+
+ public String getTypeParentNames()
+ {
+ return typeParentNames;
+ }
+
+ public void setTypeParentNames(String typeParentNames)
+ {
+ this.typeParentNames = typeParentNames;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
- .append("id", getId())
- .append("materialName", getMaterialName())
- .append("materialShortName", getMaterialShortName())
- .append("materialCode", getMaterialCode())
- .append("typeId", getTypeId())
- .append("unitId", getUnitId())
- .append("materialCategory", getMaterialCategory())
- .append("kgFactor", getKgFactor())
- .append("specification", getSpecification())
- .append("model", getModel())
- .append("barcode", getBarcode())
- .append("weight", getWeight())
- .append("description", getDescription())
- .append("orderNum", getOrderNum())
- .append("status", getStatus())
- .append("isDelete", getIsDelete())
- .append("createBy", getCreateBy())
- .append("createTime", getCreateTime())
- .append("updateBy", getUpdateBy())
- .append("updateTime", getUpdateTime())
- .toString();
+ .append("id", getId())
+ .append("materialName", getMaterialName())
+ .append("materialShortName", getMaterialShortName())
+ .append("materialCode", getMaterialCode())
+ .append("typeId", getTypeId())
+ .append("unitId", getUnitId())
+ .append("materialCategory", getMaterialCategory())
+ .append("kgFactor", getKgFactor())
+ .append("specification", getSpecification())
+ .append("model", getModel())
+ .append("barcode", getBarcode())
+ .append("weight", getWeight())
+ .append("description", getDescription())
+ .append("orderNum", getOrderNum())
+ .append("status", getStatus())
+ .append("isDelete", getIsDelete())
+ .append("unitName", getUnitName())
+ .append("typeName", getTypeName())
+ .append("typeAncestors", getTypeAncestors())
+ .append("typeParentNames", getTypeParentNames())
+ .append("createBy", getCreateBy())
+ .append("createTime", getCreateTime())
+ .append("updateBy", getUpdateBy())
+ .append("updateTime", getUpdateTime())
+ .toString();
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/shzg/project/worn/domain/WornMaterialType.java b/src/main/java/com/shzg/project/worn/domain/WornMaterialType.java
index 07fb0f7..2147c49 100644
--- a/src/main/java/com/shzg/project/worn/domain/WornMaterialType.java
+++ b/src/main/java/com/shzg/project/worn/domain/WornMaterialType.java
@@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.shzg.framework.aspectj.lang.annotation.Excel;
+import java.util.List;
+
/**
* 废旧系统物料类型(支持父子级树结构)对象 worn_material_type
*
@@ -58,6 +60,9 @@ public class WornMaterialType extends BaseEntity
@Excel(name = "逻辑删除")
private String isDelete;
+ /** 子节点 */
+ private List children;
+
public void setId(Long id)
{
this.id = id;
@@ -168,6 +173,16 @@ public class WornMaterialType extends BaseEntity
return isDelete;
}
+ public List getChildren()
+ {
+ return children;
+ }
+
+ public void setChildren(List children)
+ {
+ this.children = children;
+ }
+
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
diff --git a/src/main/java/com/shzg/project/worn/mapper/WornMaterialMapper.java b/src/main/java/com/shzg/project/worn/mapper/WornMaterialMapper.java
index 1b335db..96acc4b 100644
--- a/src/main/java/com/shzg/project/worn/mapper/WornMaterialMapper.java
+++ b/src/main/java/com/shzg/project/worn/mapper/WornMaterialMapper.java
@@ -58,4 +58,9 @@ public interface WornMaterialMapper
* @return 结果
*/
public int deleteWornMaterialByIds(Long[] ids);
+
+ /**
+ * 查询当前最大物料编码
+ */
+ String selectMaxMaterialCode();
}
diff --git a/src/main/java/com/shzg/project/worn/mapper/WornMaterialTypeMapper.java b/src/main/java/com/shzg/project/worn/mapper/WornMaterialTypeMapper.java
index 6b7e99a..adaeaed 100644
--- a/src/main/java/com/shzg/project/worn/mapper/WornMaterialTypeMapper.java
+++ b/src/main/java/com/shzg/project/worn/mapper/WornMaterialTypeMapper.java
@@ -4,7 +4,7 @@ import java.util.List;
import com.shzg.project.worn.domain.WornMaterialType;
/**
- * 废旧系统物料类型(支持父子级树结构)Mapper接口
+ * 物料类型Mapper接口
*
* @author shzg
* @date 2026-03-11
@@ -12,50 +12,71 @@ import com.shzg.project.worn.domain.WornMaterialType;
public interface WornMaterialTypeMapper
{
/**
- * 查询废旧系统物料类型(支持父子级树结构)
+ * 查询物料类型
*
- * @param id 废旧系统物料类型(支持父子级树结构)主键
- * @return 废旧系统物料类型(支持父子级树结构)
+ * @param id 物料类型主键
+ * @return 物料类型
*/
public WornMaterialType selectWornMaterialTypeById(Long id);
/**
- * 查询废旧系统物料类型(支持父子级树结构)列表
+ * 查询物料类型列表
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
- * @return 废旧系统物料类型(支持父子级树结构)集合
+ * @param wornMaterialType 物料类型
+ * @return 物料类型集合
*/
public List selectWornMaterialTypeList(WornMaterialType wornMaterialType);
/**
- * 新增废旧系统物料类型(支持父子级树结构)
+ * 新增物料类型
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
+ * @param wornMaterialType 物料类型
* @return 结果
*/
public int insertWornMaterialType(WornMaterialType wornMaterialType);
/**
- * 修改废旧系统物料类型(支持父子级树结构)
+ * 修改物料类型
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
+ * @param wornMaterialType 物料类型
* @return 结果
*/
public int updateWornMaterialType(WornMaterialType wornMaterialType);
/**
- * 删除废旧系统物料类型(支持父子级树结构)
+ * 删除物料类型
*
- * @param id 废旧系统物料类型(支持父子级树结构)主键
+ * @param id 物料类型主键
* @return 结果
*/
public int deleteWornMaterialTypeById(Long id);
/**
- * 批量删除废旧系统物料类型(支持父子级树结构)
+ * 批量删除物料类型
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteWornMaterialTypeByIds(Long[] ids);
+
+ /**
+ * 查询最大类型编码
+ * @return
+ */
+ String selectMaxTypeCode();
+
+ /**
+ * 查询子节点数量
+ */
+ int selectChildCountByParentId(Long parentId);
+
+ /**
+ * 查询所有子节点
+ */
+ List selectChildrenById(Long id);
+
+ /**
+ * 更新子节点祖级信息
+ */
+ int updateChildrenAncestors(WornMaterialType wornMaterialType);
}
diff --git a/src/main/java/com/shzg/project/worn/service/IWornMaterialTypeService.java b/src/main/java/com/shzg/project/worn/service/IWornMaterialTypeService.java
index 39a561e..53b3598 100644
--- a/src/main/java/com/shzg/project/worn/service/IWornMaterialTypeService.java
+++ b/src/main/java/com/shzg/project/worn/service/IWornMaterialTypeService.java
@@ -4,7 +4,7 @@ import java.util.List;
import com.shzg.project.worn.domain.WornMaterialType;
/**
- * 废旧系统物料类型(支持父子级树结构)Service接口
+ * 物料类型Service接口
*
* @author shzg
* @date 2026-03-11
@@ -12,50 +12,49 @@ import com.shzg.project.worn.domain.WornMaterialType;
public interface IWornMaterialTypeService
{
/**
- * 查询废旧系统物料类型(支持父子级树结构)
+ * 查询物料类型
*
- * @param id 废旧系统物料类型(支持父子级树结构)主键
- * @return 废旧系统物料类型(支持父子级树结构)
+ * @param id 物料类型主键
+ * @return 物料类型
*/
public WornMaterialType selectWornMaterialTypeById(Long id);
/**
- * 查询废旧系统物料类型(支持父子级树结构)列表
+ * 查询物料类型列表
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
- * @return 废旧系统物料类型(支持父子级树结构)集合
+ * @param wornMaterialType 物料类型
+ * @return 物料类型集合
*/
public List selectWornMaterialTypeList(WornMaterialType wornMaterialType);
/**
- * 新增废旧系统物料类型(支持父子级树结构)
+ * 物料类型
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
+ * @param wornMaterialType 物料类型
* @return 结果
*/
public int insertWornMaterialType(WornMaterialType wornMaterialType);
/**
- * 修改废旧系统物料类型(支持父子级树结构)
+ * 修改物料类型
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
+ * @param wornMaterialType 物料类型
* @return 结果
*/
public int updateWornMaterialType(WornMaterialType wornMaterialType);
/**
- * 批量删除废旧系统物料类型(支持父子级树结构)
- *
- * @param ids 需要删除的废旧系统物料类型(支持父子级树结构)主键集合
+ * 批量删除物料类型
+ *
+ * @param ids 需要删除的物料类型主键集合
* @return 结果
*/
public int deleteWornMaterialTypeByIds(Long[] ids);
/**
- * 删除废旧系统物料类型(支持父子级树结构)信息
- *
- * @param id 废旧系统物料类型(支持父子级树结构)主键
- * @return 结果
+ * 查询物料类型树结构
*/
- public int deleteWornMaterialTypeById(Long id);
+ List selectWornMaterialTypeTree();
+
+
}
diff --git a/src/main/java/com/shzg/project/worn/service/impl/WornMaterialServiceImpl.java b/src/main/java/com/shzg/project/worn/service/impl/WornMaterialServiceImpl.java
index 74f4ba5..e988275 100644
--- a/src/main/java/com/shzg/project/worn/service/impl/WornMaterialServiceImpl.java
+++ b/src/main/java/com/shzg/project/worn/service/impl/WornMaterialServiceImpl.java
@@ -54,6 +54,26 @@ public class WornMaterialServiceImpl implements IWornMaterialService
public int insertWornMaterial(WornMaterial wornMaterial)
{
wornMaterial.setCreateTime(DateUtils.getNowDate());
+
+ // 生成物料编码
+ String maxCode = wornMaterialMapper.selectMaxMaterialCode();
+
+ String newCode;
+
+ if (maxCode == null)
+ {
+ newCode = "F0001";
+ }
+ else
+ {
+ int num = Integer.parseInt(maxCode.substring(1));
+ num++;
+
+ newCode = "F" + String.format("%04d", num);
+ }
+
+ wornMaterial.setMaterialCode(newCode);
+
return wornMaterialMapper.insertWornMaterial(wornMaterial);
}
diff --git a/src/main/java/com/shzg/project/worn/service/impl/WornMaterialTypeServiceImpl.java b/src/main/java/com/shzg/project/worn/service/impl/WornMaterialTypeServiceImpl.java
index 100488b..4875964 100644
--- a/src/main/java/com/shzg/project/worn/service/impl/WornMaterialTypeServiceImpl.java
+++ b/src/main/java/com/shzg/project/worn/service/impl/WornMaterialTypeServiceImpl.java
@@ -1,30 +1,35 @@
package com.shzg.project.worn.service.impl;
+import java.util.ArrayList;
import java.util.List;
+
+import com.shzg.common.exception.ServiceException;
import com.shzg.common.utils.DateUtils;
+import com.shzg.project.worn.unit.PinyinUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shzg.project.worn.mapper.WornMaterialTypeMapper;
import com.shzg.project.worn.domain.WornMaterialType;
import com.shzg.project.worn.service.IWornMaterialTypeService;
+import org.springframework.transaction.annotation.Transactional;
/**
- * 废旧系统物料类型(支持父子级树结构)Service业务层处理
+ * 物料类型Service业务层处理
*
* @author shzg
* @date 2026-03-11
*/
@Service
-public class WornMaterialTypeServiceImpl implements IWornMaterialTypeService
+public class WornMaterialTypeServiceImpl implements IWornMaterialTypeService
{
@Autowired
private WornMaterialTypeMapper wornMaterialTypeMapper;
/**
- * 查询废旧系统物料类型(支持父子级树结构)
+ * 查询物料类型
*
- * @param id 废旧系统物料类型(支持父子级树结构)主键
- * @return 废旧系统物料类型(支持父子级树结构)
+ * @param id 物料类型主键
+ * @return 物料类型
*/
@Override
public WornMaterialType selectWornMaterialTypeById(Long id)
@@ -33,10 +38,10 @@ public class WornMaterialTypeServiceImpl implements IWornMaterialTypeService
}
/**
- * 查询废旧系统物料类型(支持父子级树结构)列表
+ * 查询物料类型列表
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
- * @return 废旧系统物料类型(支持父子级树结构)
+ * @param wornMaterialType 物料类型
+ * @return 物料类型
*/
@Override
public List selectWornMaterialTypeList(WornMaterialType wornMaterialType)
@@ -44,53 +49,214 @@ public class WornMaterialTypeServiceImpl implements IWornMaterialTypeService
return wornMaterialTypeMapper.selectWornMaterialTypeList(wornMaterialType);
}
- /**
- * 新增废旧系统物料类型(支持父子级树结构)
- *
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
- * @return 结果
- */
- @Override
- public int insertWornMaterialType(WornMaterialType wornMaterialType)
- {
- wornMaterialType.setCreateTime(DateUtils.getNowDate());
- return wornMaterialTypeMapper.insertWornMaterialType(wornMaterialType);
- }
/**
- * 修改废旧系统物料类型(支持父子级树结构)
+ * 新增物料类型
*
- * @param wornMaterialType 废旧系统物料类型(支持父子级树结构)
* @return 结果
*/
@Override
+ public int insertWornMaterialType(WornMaterialType type)
+ {
+ Long parentId = type.getParentId();
+
+ /** ==============================
+ * 1 处理 parent_id / ancestors / level
+ * ============================== */
+
+ // 一级类型
+ if (parentId == null || parentId == 0)
+ {
+ type.setParentId(0L);
+ type.setAncestors("0");
+ type.setLevel(1L);
+ }
+ // 子级类型
+ else
+ {
+ WornMaterialType parent = wornMaterialTypeMapper.selectWornMaterialTypeById(parentId);
+
+ if (parent == null)
+ {
+ throw new RuntimeException("父级类型不存在");
+ }
+
+ type.setParentId(parentId);
+
+ // ancestors = 父级 ancestors + 父级id
+ type.setAncestors(parent.getAncestors() + "," + parentId);
+
+ // level = 父级level + 1
+ type.setLevel(parent.getLevel() + 1);
+ }
+
+
+ /** ==============================
+ * 2 自动生成类型编码 type_code
+ * ============================== */
+
+ String maxCode = wornMaterialTypeMapper.selectMaxTypeCode();
+
+ int nextNum = 1;
+
+ if (maxCode != null)
+ {
+ nextNum = Integer.parseInt(maxCode.substring(2)) + 1;
+ }
+
+ String newCode = "MT" + String.format("%04d", nextNum);
+
+ type.setTypeCode(newCode);
+
+
+ /** ==============================
+ * 3 自动生成首字母
+ * ============================== */
+
+ String firstLetter = PinyinUtils.getFirstLetter(type.getTypeName());
+
+ type.setFirstLetter(firstLetter);
+
+
+ /** ==============================
+ * 4 默认字段
+ * ============================== */
+
+ type.setIsDelete("0");
+ type.setStatus("0");
+ type.setCreateTime(DateUtils.getNowDate());
+
+
+ /** ==============================
+ * 5 插入数据库
+ * ============================== */
+
+ return wornMaterialTypeMapper.insertWornMaterialType(type);
+ }
+ /**
+ * 修改物料类型
+ *
+ * @param wornMaterialType 物料类型
+ * @return 结果
+ */
+ @Override
+ @Transactional
public int updateWornMaterialType(WornMaterialType wornMaterialType)
{
- wornMaterialType.setUpdateTime(DateUtils.getNowDate());
- return wornMaterialTypeMapper.updateWornMaterialType(wornMaterialType);
+ Long id = wornMaterialType.getId();
+ Long newParentId = wornMaterialType.getParentId();
+
+ // 查询当前节点原始数据
+ WornMaterialType old = wornMaterialTypeMapper.selectWornMaterialTypeById(id);
+
+ // 查询新的父节点
+ WornMaterialType parent = null;
+ if (newParentId != null && newParentId != 0)
+ {
+ parent = wornMaterialTypeMapper.selectWornMaterialTypeById(newParentId);
+ }
+
+ String newAncestors;
+ Long newLevel;
+
+ if (parent != null)
+ {
+ newAncestors = parent.getAncestors() + "," + parent.getId();
+ newLevel = parent.getLevel() + 1;
+ }
+ else
+ {
+ newAncestors = "0";
+ newLevel = 1L;
+ }
+
+ wornMaterialType.setAncestors(newAncestors);
+ wornMaterialType.setLevel(newLevel);
+
+ // 更新当前节点
+ int rows = wornMaterialTypeMapper.updateWornMaterialType(wornMaterialType);
+
+ // 如果父节点发生变化,需要更新所有子节点 ancestors
+ if (!old.getParentId().equals(newParentId))
+ {
+ List children = wornMaterialTypeMapper.selectChildrenById(id);
+
+ for (WornMaterialType child : children)
+ {
+ String childAncestors = child.getAncestors().replace(old.getAncestors(), newAncestors);
+ child.setAncestors(childAncestors);
+ wornMaterialTypeMapper.updateChildrenAncestors(child);
+ }
+ }
+
+ return rows;
}
/**
- * 批量删除废旧系统物料类型(支持父子级树结构)
+ * 批量删除物料类型
*
- * @param ids 需要删除的废旧系统物料类型(支持父子级树结构)主键
+ * @param ids 需要删除的物料类型主键
* @return 结果
*/
@Override
public int deleteWornMaterialTypeByIds(Long[] ids)
{
+ for (Long id : ids)
+ {
+ // 查询是否存在子节点
+ int count = wornMaterialTypeMapper.selectChildCountByParentId(id);
+
+ if (count > 0)
+ {
+ throw new ServiceException("该物料类型存在子类型,不能删除");
+ }
+ }
+
return wornMaterialTypeMapper.deleteWornMaterialTypeByIds(ids);
}
- /**
- * 删除废旧系统物料类型(支持父子级树结构)信息
- *
- * @param id 废旧系统物料类型(支持父子级树结构)主键
- * @return 结果
- */
@Override
- public int deleteWornMaterialTypeById(Long id)
+ public List selectWornMaterialTypeTree()
{
- return wornMaterialTypeMapper.deleteWornMaterialTypeById(id);
+ List list = wornMaterialTypeMapper.selectWornMaterialTypeList(new WornMaterialType());
+ return buildTree(list);
+ }
+
+ /**
+ * 构建树结构
+ */
+ private List buildTree(List list)
+ {
+ List roots = new ArrayList<>();
+
+ for (WornMaterialType node : list)
+ {
+ if (node.getParentId() != null && node.getParentId() == 0)
+ {
+ recursionFn(list, node);
+ roots.add(node);
+ }
+ }
+
+ return roots;
+ }
+
+ /**
+ * 递归子节点
+ */
+ private void recursionFn(List list, WornMaterialType node)
+ {
+ List children = new ArrayList<>();
+
+ for (WornMaterialType t : list)
+ {
+ if (node.getId().equals(t.getParentId()))
+ {
+ recursionFn(list, t);
+ children.add(t);
+ }
+ }
+
+ node.setChildren(children);
}
}
diff --git a/src/main/java/com/shzg/project/worn/unit/PinyinUtils.java b/src/main/java/com/shzg/project/worn/unit/PinyinUtils.java
new file mode 100644
index 0000000..ba9427c
--- /dev/null
+++ b/src/main/java/com/shzg/project/worn/unit/PinyinUtils.java
@@ -0,0 +1,34 @@
+package com.shzg.project.worn.unit;
+
+import net.sourceforge.pinyin4j.PinyinHelper;
+
+public class PinyinUtils
+{
+
+ /**
+ * 获取中文首字母
+ */
+ public static String getFirstLetter(String chinese)
+ {
+ StringBuilder sb = new StringBuilder();
+
+ for (char c : chinese.toCharArray())
+ {
+ if (String.valueOf(c).matches("[\\u4E00-\\u9FA5]+"))
+ {
+ String[] pinyin = PinyinHelper.toHanyuPinyinStringArray(c);
+ if (pinyin != null)
+ {
+ sb.append(Character.toUpperCase(pinyin[0].charAt(0)));
+ }
+ }
+ else
+ {
+ sb.append(c);
+ }
+ }
+
+ return sb.toString();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 93d913a..2932ab1 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -34,7 +34,8 @@ server:
# 日志配置
logging:
level:
- com.ruoyi: debug
+ root: info
+ com.shzg: debug
org.springframework: warn
# 用户配置
@@ -64,7 +65,7 @@ spring:
devtools:
restart:
# 热部署开关
- enabled: true
+ enabled: false
# redis 配置
redis:
# 地址
diff --git a/src/main/resources/mybatis/worn/WornMaterialMapper.xml b/src/main/resources/mybatis/worn/WornMaterialMapper.xml
index 86c7f8e..4b34057 100644
--- a/src/main/resources/mybatis/worn/WornMaterialMapper.xml
+++ b/src/main/resources/mybatis/worn/WornMaterialMapper.xml
@@ -1,111 +1,232 @@
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- select id, material_name, material_short_name, material_code, type_id, unit_id, material_category, kg_factor, specification, model, barcode, weight, description, order_num, status, is_delete, create_by, create_time, update_by, update_time from worn_material
+
+ SELECT
+ wm.id,
+ wm.material_name,
+ wm.material_short_name,
+ wm.material_code,
+ wm.type_id,
+ wm.unit_id,
+ wm.material_category,
+ wm.kg_factor,
+ wm.specification,
+ wm.model,
+ wm.barcode,
+ wm.weight,
+ wm.description,
+ wm.order_num,
+ wm.status,
+ wm.is_delete,
+ wm.create_by,
+ wm.create_time,
+ wm.update_by,
+ wm.update_time,
+
+ u.unit_name,
+
+ t.type_name,
+ t.ancestors,
+
+ (
+ SELECT GROUP_CONCAT(tp.type_name ORDER BY tp.id)
+ FROM worn_material_type tp
+ WHERE FIND_IN_SET(tp.id, t.ancestors)
+ ) AS type_parent_names
+
+ FROM worn_material wm
+
+ LEFT JOIN worn_material_unit u
+ ON wm.unit_id = u.id
+
+ LEFT JOIN worn_material_type t
+ ON wm.type_id = t.id
+
-
\ No newline at end of file
diff --git a/src/main/resources/mybatis/worn/WornMaterialTypeMapper.xml b/src/main/resources/mybatis/worn/WornMaterialTypeMapper.xml
index f63f91c..1e8551d 100644
--- a/src/main/resources/mybatis/worn/WornMaterialTypeMapper.xml
+++ b/src/main/resources/mybatis/worn/WornMaterialTypeMapper.xml
@@ -28,7 +28,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-
+
+ is_delete = '0'
and parent_id = #{parentId}
and ancestors = #{ancestors}
and type_code = #{typeCode}
@@ -39,7 +40,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and order_num = #{orderNum}
and status = #{status}
and is_delete = #{isDelete}
-
+
+ order by order_num
@@ -114,4 +116,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
+
+
+ SELECT type_code
+ FROM worn_material_type
+ WHERE type_code LIKE 'MT%'
+ ORDER BY type_code DESC
+ LIMIT 1
+
+
+
+ SELECT COUNT(1)
+ FROM worn_material_type
+ WHERE parent_id = #{parentId}
+ AND is_delete = '0'
+
+
+
+
+ SELECT *
+ FROM worn_material_type
+ WHERE ancestors LIKE CONCAT('%,', #{id}, ',%')
+ AND is_delete = '0'
+
+
+
+
+ UPDATE worn_material_type
+ SET ancestors = #{ancestors}
+ WHERE id = #{id}
+
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/worn/WornMaterialUnitMapper.xml b/src/main/resources/mybatis/worn/WornMaterialUnitMapper.xml
index 6c85cd0..b7ec7a1 100644
--- a/src/main/resources/mybatis/worn/WornMaterialUnitMapper.xml
+++ b/src/main/resources/mybatis/worn/WornMaterialUnitMapper.xml
@@ -1,44 +1,92 @@
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- select id, unit_name, description, order_num, status, is_delete, create_by, create_time, update_by, update_time from worn_material_unit
+ SELECT
+ id,
+ unit_name,
+ description,
+ order_num,
+ status,
+ is_delete,
+ create_by,
+ create_time,
+ update_by,
+ update_time
+ FROM worn_material_unit
-
+
+
+
-
- and unit_name like concat('%', #{unitName}, '%')
- and description = #{description}
- and order_num = #{orderNum}
- and status = #{status}
- and is_delete = #{isDelete}
+
+
+
+
+ AND unit_name LIKE CONCAT('%',#{unitName},'%')
+
+
+
+ AND description = #{description}
+
+
+
+ AND order_num = #{orderNum}
+
+
+
+ AND status = #{status}
+
+
+
+ AND is_delete = #{isDelete}
+
+
-
-
-
-
- where id = #{id}
+
-
- insert into worn_material_unit
+
+
+
+
+
+ WHERE id = #{id}
+
+
+
+
+
+
+ INSERT INTO worn_material_unit
+
unit_name,
description,
@@ -49,8 +97,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
create_time,
update_by,
update_time,
-
-
+
+
+
#{unitName},
#{description},
#{orderNum},
@@ -60,11 +109,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{createTime},
#{updateBy},
#{updateTime},
-
+
+
-
- update worn_material_unit
+
+
+
+ UPDATE worn_material_unit
+
unit_name = #{unitName},
description = #{description},
@@ -76,17 +130,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_by = #{updateBy},
update_time = #{updateTime},
- where id = #{id}
+
+ WHERE id = #{id}
+
+
- delete from worn_material_unit where id = #{id}
+ DELETE FROM worn_material_unit
+ WHERE id = #{id}
+
- delete from worn_material_unit where id in
+ DELETE FROM worn_material_unit
+ WHERE id IN
#{id}
+
\ No newline at end of file