diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java index f6c4456e..8b18c1aa 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java @@ -4,17 +4,11 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; import com.bonus.common.log.enums.OperaType; import com.bonus.material.common.annotation.PreventRepeatSubmit; +import com.bonus.material.ma.domain.TreeSelect; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.bonus.common.log.annotation.SysLog; import com.bonus.common.security.annotation.RequiresPermissions; import com.bonus.material.ma.domain.Type; @@ -48,6 +42,17 @@ public class TypeController extends BaseController { return getDataTable(list); } + /** + * 物资类型下拉树 + */ + @ApiOperation(value = "物资类型下拉树") + @RequiresPermissions("ma:type:list") + @GetMapping("/getMaTypeTreeSelect") + public AjaxResult getMaTypeTreeSelect(@RequestParam(required = false, defaultValue = "", value = "typeName") String typeName, @RequestParam(required = false, defaultValue = "", value = "parentId") String parentId) { + List maTypeList = typeService.getMaTypeTree(typeName, parentId); + return AjaxResult.success(maTypeList); + } + /** * 导出物资类型管理列表 */ @@ -78,7 +83,7 @@ public class TypeController extends BaseController { @ApiOperation(value = "新增物资类型管理") @PreventRepeatSubmit @RequiresPermissions("ma:type:add") - @SysLog(title = "物资类型管理", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增物资类型") + @SysLog(title = "物资类型管理", businessType = OperaType.INSERT, module = "仓储管理->新增物资类型") @PostMapping public AjaxResult add(@RequestBody Type type) { return toAjax(typeService.insertType(type)); @@ -90,7 +95,7 @@ public class TypeController extends BaseController { @ApiOperation(value = "修改物资类型管理") @PreventRepeatSubmit @RequiresPermissions("ma:type:edit") - @SysLog(title = "物资类型管理", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改物资类型") + @SysLog(title = "物资类型管理", businessType = OperaType.UPDATE, module = "仓储管理->修改物资类型") @PutMapping public AjaxResult edit(@RequestBody Type type) { return toAjax(typeService.updateType(type)); @@ -102,7 +107,7 @@ public class TypeController extends BaseController { @ApiOperation(value = "删除物资类型管理") @PreventRepeatSubmit @RequiresPermissions("ma:type:remove") - @SysLog(title = "物资类型管理", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除物资类型") + @SysLog(title = "物资类型管理", businessType = OperaType.DELETE, module = "仓储管理->删除物资类型") @DeleteMapping("/{typeIds}") public AjaxResult remove(@PathVariable Long[] typeIds) { return toAjax(typeService.deleteTypeByTypeIds(typeIds)); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/TreeSelect.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/TreeSelect.java new file mode 100644 index 00000000..e3c3a14c --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/TreeSelect.java @@ -0,0 +1,51 @@ +package com.bonus.material.ma.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; +import java.util.stream.Collectors; + +/** + * TreeSelect树结构实体类 + * @author syruan + */ +@Data +public class TreeSelect implements Serializable { + + private static final long serialVersionUID = 1L; + + /** 节点ID */ + private Long id; + + /** 节点名称 */ + private String label; + + /** 节点级别 */ + private Integer level; + + /** 父节点id */ + private Long parentId; + + /** 公司id */ + private String companyId; + + /** 子节点集合 */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; + + public TreeSelect() { + + } + + public TreeSelect(Type maType) { + this.parentId = maType.getParentId(); + this.level = Integer.valueOf(maType.getLevel()); + this.id = maType.getTypeId(); + this.label = maType.getTypeName(); + this.companyId = String.valueOf(maType.getUnitId()); + this.children = maType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + } + +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java index 12275cbb..6de6e0c2 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java @@ -1,9 +1,13 @@ package com.bonus.material.ma.domain; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; import com.bonus.common.core.annotation.Excel; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -132,5 +136,8 @@ public class Type extends BaseEntity { @ApiModelProperty(value = "推送智慧工程定义的门类分类机具编码") private String intelligentCode; + /** 子节点 */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children = new ArrayList<>(); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java index fe0f2947..b7c9229b 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java @@ -3,6 +3,7 @@ package com.bonus.material.ma.mapper; import java.util.List; import com.bonus.material.ma.domain.Type; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 物资类型Mapper接口 @@ -18,6 +19,12 @@ public interface TypeMapper { */ Type selectTypeByTypeId(Long typeId); + /** + * 物资类型树形结构 + * @param level 排除层级 + */ + List selectMaTypeTree(@Param("level") Integer level); + /** * 查询物资类型列表 * diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java index 1b48be9e..5b1fd50f 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java @@ -1,6 +1,8 @@ package com.bonus.material.ma.service; import java.util.List; + +import com.bonus.material.ma.domain.TreeSelect; import com.bonus.material.ma.domain.Type; /** @@ -55,4 +57,14 @@ public interface ITypeService { * @return 结果 */ int deleteTypeByTypeId(Long typeId); + + List getMaTypeTree(String typeName, String parentId); + + /** + * 构建前端所需要树结构 + * + * @param maTypeList 状态列表 + * @return 树结构列表 + */ + List buildMaTypeTree(List maTypeList); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java index 67b37bf6..08038f88 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java @@ -1,8 +1,12 @@ package com.bonus.material.ma.service.impl; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; + +import com.bonus.material.ma.domain.TreeSelect; import com.bonus.common.core.utils.DateUtils; -import org.springframework.beans.factory.annotation.Autowired; +import com.bonus.common.core.utils.StringUtils; import org.springframework.stereotype.Service; import com.bonus.material.ma.mapper.TypeMapper; import com.bonus.material.ma.domain.Type; @@ -17,14 +21,18 @@ import javax.annotation.Resource; @Service public class TypeServiceImpl implements ITypeService { + /** + * 物资类型管理树最小级别 + */ + public static final Integer TYPE_MIN_LEVEL = 4; + @Resource private TypeMapper typeMapper; /** - * 查询物资类型管理 + * 查询物资类型 -- 根据id * * @param typeId 物资类型管理主键 - * @return 物资类型管理 */ @Override public Type selectTypeByTypeId(Long typeId) { @@ -62,8 +70,7 @@ public class TypeServiceImpl implements ITypeService { * @return 结果 */ @Override - public int updateType(Type type) - { + public int updateType(Type type) { type.setUpdateTime(DateUtils.getNowDate()); return typeMapper.updateType(type); } @@ -90,4 +97,71 @@ public class TypeServiceImpl implements ITypeService { public int deleteTypeByTypeId(Long typeId) { return typeMapper.logicDeleteTypeByTypeId(typeId); } + + + @Override + public List getMaTypeTree(String typeName, String parentId) { + List maTypes = typeMapper.selectMaTypeTree(TYPE_MIN_LEVEL); + List treeSelectList = buildMaTypeTree(maTypes); + //如果没有查询到那么返回空 + return treeSelectList.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 构建前端所需要树结构 + * + * @param maTypeList 部门列表 + * @return 树结构列表 + */ + @Override + public List buildMaTypeTree(List maTypeList) { + List returnList = new ArrayList(); + List tempList = maTypeList.stream().map(Type::getTypeId).collect(Collectors.toList()); + for (Type maType : maTypeList) { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(maType.getParentId())) { + recursionFn(maTypeList, maType); + returnList.add(maType); + } + } + if (returnList.isEmpty()) { + returnList = maTypeList; + } + return returnList; + } + + /** + * 递归列表 + */ + private void recursionFn(List list, Type t) { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (Type tChild : childList) { + if (hasChild(list, tChild)) { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, Type t) { + List tlist = new ArrayList(); + for (Type n : list) { + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getTypeId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, Type t) { + return !getChildList(list, t).isEmpty(); + } + } diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index 1eb51fec..26a9449a 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -181,4 +181,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update ma_type set del_flag = 2 where type_id = #{typeId,jdbcType=BIGINT} + + \ No newline at end of file