物资类型管理--新增tree树形下拉框
This commit is contained in:
parent
38ad174175
commit
e5703fa5fc
|
|
@ -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<TreeSelect> 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));
|
||||
|
|
|
|||
|
|
@ -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<TreeSelect> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<Type> children = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Type> selectMaTypeTree(@Param("level") Integer level);
|
||||
|
||||
/**
|
||||
* 查询物资类型列表
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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<TreeSelect> getMaTypeTree(String typeName, String parentId);
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param maTypeList 状态列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
List<Type> buildMaTypeTree(List<Type> maTypeList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<TreeSelect> getMaTypeTree(String typeName, String parentId) {
|
||||
List<Type> maTypes = typeMapper.selectMaTypeTree(TYPE_MIN_LEVEL);
|
||||
List<Type> treeSelectList = buildMaTypeTree(maTypes);
|
||||
//如果没有查询到那么返回空
|
||||
return treeSelectList.stream().map(TreeSelect::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端所需要树结构
|
||||
*
|
||||
* @param maTypeList 部门列表
|
||||
* @return 树结构列表
|
||||
*/
|
||||
@Override
|
||||
public List<Type> buildMaTypeTree(List<Type> maTypeList) {
|
||||
List<Type> returnList = new ArrayList<Type>();
|
||||
List<Long> 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<Type> list, Type t) {
|
||||
// 得到子节点列表
|
||||
List<Type> childList = getChildList(list, t);
|
||||
t.setChildren(childList);
|
||||
for (Type tChild : childList) {
|
||||
if (hasChild(list, tChild)) {
|
||||
recursionFn(list, tChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到子节点列表
|
||||
*/
|
||||
private List<Type> getChildList(List<Type> list, Type t) {
|
||||
List<Type> tlist = new ArrayList<Type>();
|
||||
for (Type n : list) {
|
||||
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getTypeId().longValue()) {
|
||||
tlist.add(n);
|
||||
}
|
||||
}
|
||||
return tlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有子节点
|
||||
*/
|
||||
private boolean hasChild(List<Type> list, Type t) {
|
||||
return !getChildList(list, t).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,4 +181,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<update id="logicDeleteTypeByTypeId">
|
||||
update ma_type set del_flag = 2 where type_id = #{typeId,jdbcType=BIGINT}
|
||||
</update>
|
||||
|
||||
<select id="selectMaTypeTree" resultMap="TypeResult">
|
||||
<include refid="selectTypeVo" />
|
||||
where del_flag = 0 and level != #{level}
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue