wangchangsheng il y a 1 an
Parent
commit
3aed01a900

+ 89 - 2
ims-service/ims-eval/src/main/java/com/ims/eval/controller/MultipleBrandController.java

@@ -1,9 +1,16 @@
 package com.ims.eval.controller;
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
+import com.ims.eval.config.CustomException;
+import com.ims.eval.entity.MultipleBrand;
+import com.ims.eval.entity.dto.result.R;
+import com.ims.eval.service.IMultipleBrandService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
-import org.springframework.web.bind.annotation.RestController;
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * <p>
@@ -17,4 +24,84 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("//multiple-brand")
 public class MultipleBrandController {
 
+	@Autowired
+	private IMultipleBrandService multipleBrandService;
+
+
+	/**
+	 * 查询
+	 *
+	 * @param id         主键ID
+	 * @param parentId      父类id
+	 * @return
+	 */
+		@GetMapping(value = "list")
+	public R list(@RequestParam(value = "id", required = false) String id,
+				  @RequestParam(value = "parentId", required = false) String parentId) {
+
+		List<MultipleBrand> list  =multipleBrandService.getMultipleBranList(id,parentId);
+		return R.ok().data(list);
+	}
+
+
+
+	/**
+	 * 查询
+	 *
+	 * @param id         主键ID
+	 * @param parentId      父类id
+	 * @return
+	 */
+	@GetMapping(value = "tree")
+	public R tree(@RequestParam(value = "id", required = false) String id,
+				  @RequestParam(value = "parentId", required = false) String parentId) {
+
+		List<MultipleBrand> list  =multipleBrandService.getMultipleBranTree(id,parentId);
+		return R.ok().data(list);
+	}
+
+
+
+	/**
+	 * 添加
+	 *
+	 * @param multipleBrand
+	 * @return
+	 */
+
+	@PostMapping(value = "/save")
+	@ApiOperation(value = "新增(修改)", notes = "新增(修改)")
+	public R addAll(@RequestBody MultipleBrand multipleBrand) {
+
+		try {
+			boolean b = multipleBrandService.saveOrUpdate(multipleBrand);
+			if (b) {
+				return R.ok().data(b);
+			} else {
+				return R.error().data("保存失败!");
+			}
+		} catch (CustomException e){
+			return R.customError(e.getMessage()).data("失败!");
+		}
+	}
+
+
+	/**
+	 * 批量删除
+	 *
+	 * @param ids
+	 * @return
+	 */
+	@PostMapping(value = "/remove/{ids}")
+	@ApiOperation(value = "删除", notes = "删除")
+	public R deleteAll(@PathVariable("ids") String ids) {
+		String[] strings = ids.split(",");
+		boolean b = multipleBrandService.removeByIds(Arrays.asList(strings));
+		if (b) {
+			return R.ok().data(b);
+		} else {
+			return R.error().data("删除失败!");
+		}
+	}
+
 }

+ 7 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/dao/MultipleBrandMapper.java

@@ -2,6 +2,9 @@ package com.ims.eval.dao;
 
 import com.ims.eval.entity.MultipleBrand;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +16,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface MultipleBrandMapper extends BaseMapper<MultipleBrand> {
 
+	List<MultipleBrand> selectMultipleBranTree(@Param("id")String id , @Param("parentId")String parentId);
+
+	List<MultipleBrand> selectMultipleBranList(@Param("id")String id ,@Param("parentId") String parentId);
+
 }

+ 15 - 4
ims-service/ims-eval/src/main/java/com/ims/eval/entity/MultipleBrand.java

@@ -1,7 +1,11 @@
 package com.ims.eval.entity;
 
 import java.math.BigDecimal;
+import java.util.List;
+
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.ims.eval.entity.custom.Menu;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -24,10 +28,7 @@ public class MultipleBrand extends Model {
      */
     private String id;
 
-    /**
-     * 主牌子id
-     */
-    private String organizationId;
+
 
     /**
      * 主牌子name
@@ -54,6 +55,13 @@ public class MultipleBrand extends Model {
      */
     private String binSection;
 
+
+	/**
+	 * 业务版块name
+	 */
+	@TableField(exist = false)
+	private String binSectionName;
+
     /**
      * 周期
      */
@@ -75,4 +83,7 @@ public class MultipleBrand extends Model {
     private String remark;
 
 
+	@TableField(exist = false)
+	private List<MultipleBrand> children;
+
 }

+ 6 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/IMultipleBrandService.java

@@ -3,6 +3,8 @@ package com.ims.eval.service;
 import com.ims.eval.entity.MultipleBrand;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +15,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IMultipleBrandService extends IService<MultipleBrand> {
 
+	List<MultipleBrand> getMultipleBranTree(String id , String parentId);
+
+	List<MultipleBrand> getMultipleBranList(String id , String parentId);
+
 }

+ 67 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/MultipleBrandServiceImpl.java

@@ -1,11 +1,16 @@
 package com.ims.eval.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.ims.eval.entity.MultipleBrand;
 import com.ims.eval.dao.MultipleBrandMapper;
 import com.ims.eval.service.IMultipleBrandService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +22,66 @@ import org.springframework.stereotype.Service;
 @Service
 public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, MultipleBrand> implements IMultipleBrandService {
 
+	@Override
+	public List<MultipleBrand> getMultipleBranTree(String id, String parentId) {
+		List<MultipleBrand> list  =  baseMapper.selectMultipleBranTree(id,parentId);
+		List<MultipleBrand> tree = convert(list);
+		return tree;
+	}
+
+	@Override
+	public List<MultipleBrand> getMultipleBranList(String id, String parentId) {
+		List<MultipleBrand> list  = baseMapper.selectMultipleBranList(id,parentId);
+		return list;
+	}
+
+
+
+
+
+	/**
+	 * 转换为有树形结构的列表
+	 *
+	 * @param brands 源数据所有数据
+	 * @return
+	 */
+	public List<MultipleBrand> convert(List<MultipleBrand> brands) {
+		if (CollectionUtil.isEmpty(brands)) {
+			return new ArrayList<>();
+		}
+		List<MultipleBrand> result = new ArrayList<>();
+		List<String> idList = brands.stream().map(MultipleBrand::getId).collect(Collectors.toList());
+		// 设置最外层顶级
+		for (MultipleBrand brandsVO : brands) {
+			// 判断所有列表里面父级未在集合中放置到一级
+			if (!idList.contains(brandsVO.getParentId())) {
+				result.add(brandsVO);
+			}
+		}
+		for (MultipleBrand brandsVO : result) {
+			// 循环一级之后子级
+			getChildren(brands, brandsVO);
+		}
+		return result;
+	}
+
+
+	/**
+	 * 循环设置子级
+	 *
+	 * @param list         所有元素列表
+	 * @param treeSelectVO 父级元素
+	 * @return 父级元素
+	 */
+	public static MultipleBrand getChildren(List<MultipleBrand> list, MultipleBrand treeSelectVO) {
+		for (MultipleBrand MultipleBrand : list) {
+			if (treeSelectVO.getId().equals(MultipleBrand.getParentId())) {
+				List<MultipleBrand> children = CollectionUtil.isEmpty(treeSelectVO.getChildren()) ? new ArrayList<>() : treeSelectVO.getChildren();
+				children.add(getChildren(list, MultipleBrand));
+				treeSelectVO.setChildren(children);
+
+			}
+		}
+		return treeSelectVO;
+	}
 }

+ 49 - 0
ims-service/ims-eval/src/main/resources/mappers/MultipleBrandMapper.xml

@@ -0,0 +1,49 @@
+<?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.ims.eval.dao.MultipleBrandMapper">
+
+
+    <select id="selectMultipleBranTree" resultType="com.ims.eval.entity.MultipleBrand">
+
+        select
+            *,
+            b.section_name binsectionname
+        from
+            multiple_brand
+            m left join bin_section b on m.bin_section = b.id
+            <where>
+                <if test="id !=null and id !=''">
+                    AND m.id = #{id}
+                </if>
+                <if test="parentId !=null and parentId !=''">
+                    AND m.parent_id  = #{parentId}
+                </if>
+            </where>
+
+
+    </select>
+
+
+
+    <select id="selectMultipleBranList" resultType="com.ims.eval.entity.MultipleBrand">
+
+        select
+            *,
+            b.section_name binsectionname
+        from
+            multiple_brand
+            m left join bin_section b on m.bin_section = b.id
+            <where>
+                <if test="id !=null and id !=''">
+                    AND m.id = #{id}
+                </if>
+                <if test="parentId !=null and parentId !=''">
+                    AND m.parent_id  = #{parentId}
+                </if>
+
+            </where>
+
+    </select>
+
+
+</mapper>