add:品类
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
|
||||
package org.nl.wms.base_manage.class_standard.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.utils.RedissonUtils;
|
||||
import org.nl.wms.base_manage.class_standard.service.IBmClassStandardService;
|
||||
import org.nl.wms.base_manage.class_standard.service.dao.BmClassStandard;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhouz
|
||||
* @date 2021-12-07
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/bmClassStandard")
|
||||
@Slf4j
|
||||
public class BmClassStandardController {
|
||||
|
||||
@Autowired
|
||||
private IBmClassStandardService classStandardService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> queryList(@RequestParam Map whereJson) {
|
||||
return new ResponseEntity<>(TableDataInfo.build(classStandardService.dropdownList(whereJson)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody JSONObject form) {
|
||||
classStandardService.create(form);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody JSONObject form) {
|
||||
classStandardService.updateForm(form);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody String[] ids) {
|
||||
classStandardService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/loadClass")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson) {
|
||||
return new ResponseEntity<>(TableDataInfo.build(classStandardService.loadClass(whereJson)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getClass")
|
||||
public ResponseEntity<Object> queryClassBycode(@RequestParam Map whereJson) {
|
||||
return new ResponseEntity<>(TableDataInfo.build(classStandardService.queryClassBycode(whereJson)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/queryClassById")
|
||||
public ResponseEntity<Object> queryClassById(@RequestParam Map whereJson) {
|
||||
return new ResponseEntity<>(TableDataInfo.build(classStandardService.queryClassById(whereJson)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getClassTable")
|
||||
public ResponseEntity<Object> queryClassTable(@RequestParam Map whereJson, Pageable page) {
|
||||
return new ResponseEntity<>(classStandardService.queryClassTable(whereJson, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/superior")
|
||||
public ResponseEntity<Object> getSuperior(@RequestBody String id) {
|
||||
BmClassStandard classStandard = classStandardService.getById(id);
|
||||
JSONArray maters = classStandardService.getSuperior(classStandard, new JSONArray());
|
||||
return new ResponseEntity<>(classStandardService.buildTree(maters), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/superior2")
|
||||
public ResponseEntity<Object> getSuperior2(@RequestBody String param) {
|
||||
JSONArray arr = JSONArray.parseArray(param);
|
||||
JSONObject parse = arr.getJSONObject(0);
|
||||
String id = parse.getString("id");
|
||||
if (StringUtils.isEmpty(id)) {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
BmClassStandard classStandard = classStandardService.getById(id);
|
||||
JSONArray maters = classStandardService.getSuperiorLimit(classStandard, new JSONArray(), parse.getString("parent_id"));
|
||||
return new ResponseEntity<>(classStandardService.buildTree(maters), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getType")
|
||||
public ResponseEntity<Object> getType(@RequestParam Map whereJson) {
|
||||
String type_id = MapUtil.getStr(whereJson, "type_id");
|
||||
int level = MapUtil.getInt(whereJson, "level");
|
||||
return new ResponseEntity<>(classStandardService.getType(type_id, level), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getClassName")
|
||||
public ResponseEntity<Object> getClassName() {
|
||||
return new ResponseEntity<>(classStandardService.getClassName(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/excelImport")
|
||||
public ResponseEntity<Object> excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
|
||||
RedissonUtils.lock(() -> {
|
||||
classStandardService.excelImport(file, request, response);
|
||||
}, "基础分类导入", null);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.nl.wms.base_manage.class_standard.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.wms.base_manage.class_standard.service.dao.BmClassStandard;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 基础数据分类标准表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-05-05
|
||||
*/
|
||||
public interface IBmClassStandardService extends IService<BmClassStandard> {
|
||||
|
||||
/**
|
||||
* 物料类型下拉选
|
||||
* @param json
|
||||
* @return
|
||||
*/
|
||||
List<Map> dropdownList(Map json);
|
||||
|
||||
/**
|
||||
* 家在物料列表
|
||||
* @param whereJson
|
||||
*/
|
||||
List<Map> loadClass(Map whereJson);
|
||||
|
||||
|
||||
List<Map> queryClassBycode(Map whereJson);
|
||||
|
||||
List<Map> queryClassById(Map whereJson);
|
||||
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param form
|
||||
* @return
|
||||
*/
|
||||
String create(JSONObject form);
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param form
|
||||
* @return
|
||||
*/
|
||||
String updateForm(JSONObject form);
|
||||
|
||||
/**
|
||||
* 删除当前及子集
|
||||
* @param ids
|
||||
*/
|
||||
void deleteAll(String[] ids);
|
||||
|
||||
/**
|
||||
* c查询子集
|
||||
* @param class_id
|
||||
* @return
|
||||
*/
|
||||
List<String> getChildIdStr(String class_id);
|
||||
|
||||
Set<String> getAllChildIdSet(String class_idStr);
|
||||
|
||||
void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||
|
||||
JSONObject queryClassTable(Map whereJson, Pageable page);
|
||||
|
||||
JSONArray getSuperior(BmClassStandard classStandard, JSONArray objects);
|
||||
|
||||
JSONObject buildTree(JSONArray maters);
|
||||
|
||||
JSONArray getSuperiorLimit(BmClassStandard classStandard, JSONArray objects, String parent_id);
|
||||
|
||||
BmClassStandard getType(String type_id, int level);
|
||||
|
||||
JSONArray getClassName();
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package org.nl.wms.base_manage.class_standard.service.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 基础数据分类标准表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-05-05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("bm_class_standard")
|
||||
public class BmClassStandard implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分类标识
|
||||
*/
|
||||
@TableId(value = "class_id")
|
||||
private String class_id;
|
||||
|
||||
/**
|
||||
* 分类编码
|
||||
*/
|
||||
private String class_code;
|
||||
|
||||
/**
|
||||
* 分类长编码
|
||||
*/
|
||||
private String long_class_code;
|
||||
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String class_name;
|
||||
|
||||
/**
|
||||
* 分类简要描述
|
||||
*/
|
||||
private String class_desc;
|
||||
|
||||
/**
|
||||
* 上级分类标识
|
||||
*/
|
||||
private String parent_class_id;
|
||||
|
||||
/**
|
||||
* 子部门数目
|
||||
*/
|
||||
private Integer sub_count;
|
||||
|
||||
/**
|
||||
* 是否叶子
|
||||
*/
|
||||
private Boolean is_leaf;
|
||||
|
||||
/**
|
||||
* 是否可修改
|
||||
*/
|
||||
private Boolean is_modify;
|
||||
|
||||
/**
|
||||
* 级别
|
||||
*/
|
||||
private String class_level;
|
||||
|
||||
/**
|
||||
* 外部标识
|
||||
*/
|
||||
private String ext_id;
|
||||
|
||||
/**
|
||||
* 外部上级标识
|
||||
*/
|
||||
private String ext_parent_id;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String create_id;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
private String create_name;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String create_time;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String update_id;
|
||||
|
||||
/**
|
||||
* 修改人姓名
|
||||
*/
|
||||
private String update_name;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String update_time;
|
||||
|
||||
private Boolean is_delete;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.nl.wms.base_manage.class_standard.service.dao.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.nl.wms.base_manage.class_standard.service.dao.BmClassStandard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description TODO
|
||||
* @Author Gengby
|
||||
* @Date 2024/3/11
|
||||
*/
|
||||
public interface BmClassStandardMapper extends BaseMapper<BmClassStandard> {
|
||||
List<String> getChildIdStr(String class_id);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?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="org.nl.wms.base_manage.class_standard.service.dao.mapper.BmClassStandardMapper">
|
||||
|
||||
<select id="getChildIdStr" resultType="java.lang.String">
|
||||
select DISTINCT class_id
|
||||
from (
|
||||
select t1.class_id,
|
||||
if(find_in_set(parent_class_id, @pids) > 0, @pids := concat(@pids, ',', class_id), 0) as ischild
|
||||
from (
|
||||
select class_id, parent_class_id
|
||||
from md_pb_classstandard t
|
||||
where t.is_delete = '0'
|
||||
order by class_code
|
||||
) t1,
|
||||
(select @pids := #{class_id}) t2
|
||||
) t3
|
||||
where ischild != 0
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,121 @@
|
||||
package org.nl.wms.base_manage.class_standard.service.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 基础数据分类标准表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-05-05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("bm_class_standard")
|
||||
public class BmClassStandardTree implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 分类标识
|
||||
*/
|
||||
@TableId(value = "class_id")
|
||||
private String class_id;
|
||||
|
||||
/**
|
||||
* 分类编码
|
||||
*/
|
||||
private String class_code;
|
||||
|
||||
/**
|
||||
* 分类长编码
|
||||
*/
|
||||
private String long_class_code;
|
||||
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
private String class_name;
|
||||
|
||||
/**
|
||||
* 分类简要描述
|
||||
*/
|
||||
private String class_desc;
|
||||
|
||||
/**
|
||||
* 上级分类标识
|
||||
*/
|
||||
private String parent_class_id;
|
||||
|
||||
/**
|
||||
* 子部门数目
|
||||
*/
|
||||
private Integer sub_count;
|
||||
|
||||
/**
|
||||
* 是否叶子
|
||||
*/
|
||||
private Boolean is_leaf;
|
||||
|
||||
/**
|
||||
* 是否可修改
|
||||
*/
|
||||
private Boolean is_modify;
|
||||
|
||||
/**
|
||||
* 级别
|
||||
*/
|
||||
private String class_level;
|
||||
|
||||
/**
|
||||
* 外部标识
|
||||
*/
|
||||
private String ext_id;
|
||||
|
||||
/**
|
||||
* 外部上级标识
|
||||
*/
|
||||
private String ext_parent_id;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String create_id;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
private String create_name;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String create_time;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String update_id;
|
||||
|
||||
/**
|
||||
* 修改人姓名
|
||||
*/
|
||||
private String update_name;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String update_time;
|
||||
|
||||
|
||||
private List<BmClassStandardTree> itemClassstrandard;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
package org.nl.wms.base_manage.class_standard.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.domain.exception.BadRequestException;
|
||||
import org.nl.common.utils.CopyUtil;
|
||||
import org.nl.common.utils.IdUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.wms.base_manage.class_standard.service.IBmClassStandardService;
|
||||
import org.nl.wms.base_manage.class_standard.service.dao.BmClassStandard;
|
||||
import org.nl.wms.base_manage.class_standard.service.dao.mapper.BmClassStandardMapper;
|
||||
import org.nl.wms.base_manage.class_standard.service.dto.BmClassStandardTree;
|
||||
import org.nl.wms.base_manage.material.service.IBmMaterialService;
|
||||
import org.nl.wms.base_manage.material.service.dao.BmMaterial;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 基础数据分类标准表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2023-05-05
|
||||
*/
|
||||
@Service
|
||||
public class BmClassStandardServiceImpl extends ServiceImpl<BmClassStandardMapper, BmClassStandard> implements IBmClassStandardService {
|
||||
|
||||
@Autowired
|
||||
private IBmMaterialService materialService;
|
||||
|
||||
@Override
|
||||
public List<Map> dropdownList(Map whereJson) {
|
||||
Assert.notNull(whereJson, "参数不能为空");
|
||||
QueryWrapper<BmClassStandard> query = new QueryWrapper<BmClassStandard>()
|
||||
.eq("parent_class_id", "0")
|
||||
.eq("is_delete", false);
|
||||
if (whereJson.get("class_code") != null) {
|
||||
query.eq("class_code", whereJson.get("class_code"));
|
||||
}
|
||||
return getMaps(this.listMaps(query));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map> loadClass(Map whereJson) {
|
||||
List<Map<String, Object>> list = this.listMaps(new QueryWrapper<BmClassStandard>()
|
||||
.eq("is_delete", false)
|
||||
.eq("parent_class_id", whereJson.get("pid") == null ? "0" : whereJson.get("pid")));
|
||||
List<Map> result = getMaps(list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Map> getMaps(List<Map<String, Object>> list) {
|
||||
List<Map> result = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map<String, Object> item = list.get(i);
|
||||
if ((int) item.get("sub_count") > 0) {
|
||||
item.put("hasChildren", true);
|
||||
item.put("leaf", false);
|
||||
} else {
|
||||
item.put("hasChildren", false);
|
||||
item.put("leaf", true);
|
||||
}
|
||||
item.put("id", item.get("class_id"));
|
||||
item.put("label", item.get("class_name"));
|
||||
item.put("create_user_name", item.get("create_name"));
|
||||
item.put("update_user_name", item.get("update_name"));
|
||||
result.add(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map> queryClassBycode(Map whereJson) {
|
||||
BmClassStandard classstandard = null;
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("parent_class_code"))) {
|
||||
classstandard = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_code", whereJson.get("parent_class_code")));
|
||||
if (classstandard == null) {
|
||||
throw new BadRequestException("请输入正确的父节点编号!");
|
||||
}
|
||||
}
|
||||
QueryWrapper<BmClassStandard> query = new QueryWrapper<BmClassStandard>().eq("is_delete", false);
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("class_code"))) {
|
||||
query.in("class_code", whereJson.get("class_code"));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("parent_class_code")) && !whereJson.get("parent_class_code").equals("0")) {
|
||||
query.eq("class_id", classstandard.getClass_id());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("parent_class_code")) || whereJson.get("parent_class_code").equals("0")) {
|
||||
query.eq("parent_class_id", "0").or().isNull("parent_class_id");
|
||||
}
|
||||
return getMaps(this.listMaps(query));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Map> queryClassById(Map whereJson) {
|
||||
QueryWrapper<BmClassStandard> query = new QueryWrapper<>();
|
||||
query.eq("1", "1");
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("material_id"))) {
|
||||
BmMaterial one = materialService.getOne(new QueryWrapper<BmMaterial>().eq("material_id", whereJson.get("material_id")));
|
||||
whereJson.put("class_idStr", one.getMaterial_type_id());
|
||||
}
|
||||
query.eq("1", "1");
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("material_id"))) {
|
||||
BmMaterial one = materialService.getOne(new QueryWrapper<BmMaterial>().eq("material_id", whereJson.get("material_id")));
|
||||
if (null != one) {
|
||||
whereJson.put("class_idStr", one.getMaterial_type_id());
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("whereStr"))) {
|
||||
query.last((String) whereJson.get("whereStr"));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("parent_class_id"))) {
|
||||
query.eq("parent_class_id", whereJson.get("parent_class_id"));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("class_idStr"))) {
|
||||
query.in("class_id", whereJson.get("class_idStr"));
|
||||
if (ObjectUtil.isNotEmpty(whereJson.get("class_idStr"))) {
|
||||
query.last("and class_id in (" + whereJson.get("class_idStr") + ")");
|
||||
}
|
||||
}
|
||||
List<Map<String, Object>> list = this.listMaps(query);
|
||||
return getMaps(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String create(JSONObject form) {
|
||||
BmClassStandard one = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_code", form.getString("class_code")));
|
||||
if (one != null) {
|
||||
throw new BadRequestException(form.getString("class_code") + "存在相同的基础类别编号");
|
||||
}
|
||||
BmClassStandard classstandard = form.toJavaObject(BmClassStandard.class);
|
||||
classstandard.setClass_id(IdUtil.getStringId());
|
||||
classstandard.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
classstandard.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
classstandard.setCreate_time(DateUtil.now());
|
||||
classstandard.setIs_leaf(true);
|
||||
classstandard.setClass_level(Math.ceil(classstandard.getClass_code().length() / 2.0) + "");
|
||||
classstandard.setSub_count(0);
|
||||
classstandard.setLong_class_code(classstandard.getClass_code());
|
||||
this.save(classstandard);
|
||||
///更新节点
|
||||
if (classstandard.getParent_class_id() != null) {
|
||||
updateSubCnt(classstandard.getParent_class_id());
|
||||
}
|
||||
return classstandard.getClass_id();
|
||||
}
|
||||
|
||||
public void updateSubCnt(String class_id) {
|
||||
if (!StringUtils.isEmpty(class_id) && !class_id.equals("0")) {
|
||||
BmClassStandard one = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_id", class_id).eq("is_delete", false));
|
||||
if (one == null) {
|
||||
throw new BadRequestException(class_id + "没有对应分类数据");
|
||||
}
|
||||
int count = this.count(new QueryWrapper<BmClassStandard>()
|
||||
.eq("parent_class_id", class_id));
|
||||
|
||||
one.setSub_count(count);
|
||||
one.setIs_leaf(count > 0 ? false : true);
|
||||
this.updateById(one);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public String updateForm(JSONObject form) {
|
||||
checkParam(form);
|
||||
BmClassStandard dto = form.toJavaObject(BmClassStandard.class);
|
||||
dto.setUpdate_time(DateUtil.now());
|
||||
dto.setUpdate_id(SecurityUtils.getCurrentUserId());
|
||||
dto.setUpdate_name(SecurityUtils.getCurrentNickName());
|
||||
this.updateById(dto);
|
||||
|
||||
//更新父节点中子节点数目
|
||||
String oldPid = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_id", form.getString("class_id"))).getParent_class_id();
|
||||
updateSubCnt(oldPid);
|
||||
updateSubCnt(form.getString("parent_class_id"));
|
||||
return null;
|
||||
}
|
||||
|
||||
private void checkParam(JSONObject form) {
|
||||
Assert.notNull(form, "参数不能为空");
|
||||
BmClassStandard onebyid = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_id", form.getString("class_id")));
|
||||
if (onebyid == null) {
|
||||
throw new BadRequestException(form.getString("class_id") + "被删除或无权限,操作失败!");
|
||||
}
|
||||
if (form.getString("parent_class_id") != null && form.getString("class_id").equals(form.getString("parent_class_id"))) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll(String[] ids) {
|
||||
final String TOP_PARENT_ID = "0";
|
||||
if (ids == null || ids.length == 0) {
|
||||
return;
|
||||
}
|
||||
List<BmClassStandardTree> list = CopyUtil.copyList(this.list(), BmClassStandardTree.class);
|
||||
Map<String, List<BmClassStandardTree>> collect = list.stream().collect(Collectors.groupingBy(BmClassStandardTree::getParent_class_id));
|
||||
|
||||
Set<String> removeCollect = new HashSet<>();
|
||||
for (String id : ids) {
|
||||
removeCollect.add(id);
|
||||
List<BmClassStandardTree> top_parent = collect.remove(id);
|
||||
if (!CollectionUtils.isEmpty(top_parent)) {
|
||||
this.getChildTree(top_parent, collect, removeCollect);
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(removeCollect)) {
|
||||
this.update(new UpdateWrapper<BmClassStandard>()
|
||||
.set("is_delete", true)
|
||||
.set("update_id", SecurityUtils.getCurrentUserId())
|
||||
.set("update_name", SecurityUtils.getCurrentNickName()).set("update_time", DateUtil.now()).in("class_id", removeCollect));
|
||||
}
|
||||
}
|
||||
|
||||
private List<BmClassStandardTree> getChildTree(List<BmClassStandardTree> top_parent, Map<String, List<BmClassStandardTree>> collect, Set<String> removeCollect) {
|
||||
removeCollect.addAll(top_parent.stream().map(BmClassStandardTree::getClass_id).collect(Collectors.toList()));
|
||||
|
||||
if (CollectionUtils.isEmpty(collect)) {
|
||||
return top_parent;
|
||||
}
|
||||
for (BmClassStandardTree parent : top_parent) {
|
||||
List<BmClassStandardTree> child = collect.remove(parent.getClass_id());
|
||||
if (CollectionUtils.isEmpty(child)) {
|
||||
continue;
|
||||
}
|
||||
List<BmClassStandardTree> childMenuTree = getChildTree(child, collect, removeCollect);
|
||||
if (!CollectionUtils.isEmpty(childMenuTree)) {
|
||||
parent.setItemClassstrandard(childMenuTree);
|
||||
}
|
||||
}
|
||||
return top_parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getChildIdStr(String class_id) {
|
||||
if (StringUtils.isEmpty(class_id)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return this.baseMapper.getChildIdStr(class_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getSuperior(BmClassStandard classStandard, JSONArray ja) {
|
||||
if (StrUtil.isEmpty(classStandard.getParent_class_id()) || classStandard.getParent_class_id().equals("0")) {
|
||||
LambdaQueryWrapper<BmClassStandard> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(BmClassStandard::getIs_delete, "0")
|
||||
.and(q -> q.eq(BmClassStandard::getParent_class_id, "0")
|
||||
.or().isNull(BmClassStandard::getParent_class_id));
|
||||
List<BmClassStandard> bmClassStandards = this.baseMapper.selectList(lqw);
|
||||
|
||||
for (int m = 0; m < bmClassStandards.size(); m++) {
|
||||
BmClassStandard bmClassStandard = bmClassStandards.get(m);
|
||||
ja.add(bmClassStandard);
|
||||
}
|
||||
return ja;
|
||||
}
|
||||
LambdaQueryWrapper<BmClassStandard> queryWrapper = new LambdaQueryWrapper<BmClassStandard>().eq(BmClassStandard::getParent_class_id, classStandard.getParent_class_id());
|
||||
List<BmClassStandard> bmClassStandards = this.baseMapper.selectList(queryWrapper);
|
||||
for (int n = 0; n < bmClassStandards.size(); n++) {
|
||||
BmClassStandard bmClassStandard = bmClassStandards.get(n);
|
||||
ja.add(bmClassStandard);
|
||||
}
|
||||
BmClassStandard bmClassStandard = this.baseMapper.selectById(classStandard.getParent_class_id());
|
||||
return getSuperior(bmClassStandard, ja);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAllChildIdSet(String class_idStr) {
|
||||
List<BmClassStandard> class_ids = this.list(new QueryWrapper<BmClassStandard>().in("class_id", class_idStr));
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add(class_idStr);
|
||||
for (BmClassStandard classstandard : class_ids) {
|
||||
set.addAll(this.getChildIdStr(classstandard.getClass_id()));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
InputStream inputStream = file.getInputStream();
|
||||
ExcelReader excelReader = ExcelUtil.getReader(inputStream);
|
||||
List<List<Object>> read = excelReader.read();
|
||||
|
||||
Map<String, String> errorMap = new HashMap();
|
||||
for (int i = 1; i < read.size(); i++) {
|
||||
List<Object> list = read.get(i);
|
||||
if (ObjectUtil.isEmpty(list)) {
|
||||
continue;
|
||||
}
|
||||
if (ObjectUtil.isEmpty(list.get(0))) {
|
||||
errorMap.put("第" + (i + 1) + "行:", "分类编码为空!");
|
||||
continue;
|
||||
}
|
||||
String class_code = String.valueOf(list.get(0));
|
||||
BmClassStandard one = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_code", class_code).eq("is_delete", false));
|
||||
if (one != null) {
|
||||
errorMap.put("第" + (i + 1) + "行:", "存在相同的分类编码:" + class_code);
|
||||
continue;
|
||||
} else {
|
||||
one = new BmClassStandard();
|
||||
}
|
||||
|
||||
String class_name = (String) list.get(1);
|
||||
if (ObjectUtil.isEmpty(class_name)) {
|
||||
errorMap.put("第" + (i + 1) + "行:", "分类名称为空!");
|
||||
continue;
|
||||
}
|
||||
String class_desc = (String) list.get(2);
|
||||
if (StrUtil.isNotEmpty(class_desc)) {
|
||||
one.setClass_desc(class_desc);
|
||||
}
|
||||
|
||||
one.setClass_id(IdUtil.getStringId());
|
||||
one.setClass_code(class_code);
|
||||
one.setClass_name(class_name);
|
||||
one.setCreate_id(SecurityUtils.getCurrentUserId());
|
||||
one.setCreate_name(SecurityUtils.getCurrentNickName());
|
||||
one.setCreate_time(DateUtil.now());
|
||||
one.setIs_leaf(true);
|
||||
one.setSub_count(0);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(list.get(3))) {
|
||||
String pareant_class_code = String.valueOf(list.get(3));
|
||||
///更新节点
|
||||
if (StrUtil.isNotEmpty(pareant_class_code)) {
|
||||
BmClassStandard parent_one = this.getOne(new QueryWrapper<BmClassStandard>().eq("class_code", pareant_class_code).eq("is_delete", false));
|
||||
if (ObjectUtil.isEmpty(parent_one)) {
|
||||
errorMap.put("第" + (i + 1) + "行:", "父节点对应的编码:" + pareant_class_code + "不存在!");
|
||||
} else {
|
||||
one.setParent_class_id(parent_one.getClass_id());
|
||||
this.save(one);
|
||||
updateSubCnt(parent_one.getParent_class_id());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(errorMap)) {
|
||||
throw new BadRequestException(JSON.toJSONString(errorMap));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject queryClassTable(Map whereJson, Pageable page) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject buildTree(JSONArray ja) {
|
||||
Set<JSONObject> trees = new LinkedHashSet<>();
|
||||
Set<JSONObject> maters = new LinkedHashSet<>();
|
||||
List<String> mater_name = new LinkedList<>();
|
||||
for (int i = 0; i < ja.size(); i++) {
|
||||
JSONObject jo = ja.getJSONObject(i);
|
||||
mater_name.add(jo.getString("class_name"));
|
||||
}
|
||||
boolean isChild;
|
||||
for (int m = 0; m < ja.size(); m++) {
|
||||
JSONObject jo1 = ja.getJSONObject(m);
|
||||
isChild = false;
|
||||
if (jo1.getString("parent_class_id").equals("0") || StrUtil.isEmpty(jo1.getString("parent_class_id"))) {
|
||||
jo1.put("id", jo1.getString("class_id"));
|
||||
jo1.put("label", jo1.getString("class_name"));
|
||||
if (jo1.getInteger("sub_count") > 0) {
|
||||
jo1.put("hasChildren", true);
|
||||
jo1.put("leaf", false);
|
||||
} else {
|
||||
jo1.put("hasChildren", false);
|
||||
jo1.put("leaf", true);
|
||||
}
|
||||
trees.add(jo1);
|
||||
}
|
||||
for (int n = 0; n < ja.size(); n++) {
|
||||
JSONObject jo2 = ja.getJSONObject(n);
|
||||
if (!jo2.getString("class_id").equals("0") && jo1.getString("class_id").equals(jo2.getString("parent_class_id"))) {
|
||||
isChild = true;
|
||||
if (jo1.getJSONArray("children") == null) {
|
||||
jo1.put("children", new JSONArray());
|
||||
}
|
||||
JSONArray child_ja = jo1.getJSONArray("children");
|
||||
jo2.put("id", jo2.getString("class_id"));
|
||||
jo2.put("label", jo2.getString("class_name"));
|
||||
if (jo2.getInteger("sub_count") > 0) {
|
||||
jo2.put("hasChildren", true);
|
||||
jo2.put("leaf", false);
|
||||
} else {
|
||||
jo2.put("hasChildren", false);
|
||||
jo2.put("leaf", true);
|
||||
}
|
||||
child_ja.add(jo2);
|
||||
}
|
||||
}
|
||||
if (isChild) {
|
||||
jo1.put("id", jo1.getString("class_id"));
|
||||
jo1.put("label", jo1.getString("class_name"));
|
||||
if (jo1.getInteger("sub_count") > 0) {
|
||||
jo1.put("hasChildren", true);
|
||||
jo1.put("leaf", false);
|
||||
} else {
|
||||
jo1.put("hasChildren", false);
|
||||
jo1.put("leaf", true);
|
||||
}
|
||||
maters.add(jo1);
|
||||
} else if (!jo1.getString("class_id").equals("0") && !mater_name.contains(jo1.getString("material_type_name"))) {
|
||||
jo1.put("id", jo1.getString("class_id"));
|
||||
jo1.put("label", jo1.getString("class_name"));
|
||||
if (jo1.getInteger("sub_count") > 0) {
|
||||
jo1.put("hasChildren", true);
|
||||
jo1.put("leaf", false);
|
||||
} else {
|
||||
jo1.put("hasChildren", false);
|
||||
jo1.put("leaf", true);
|
||||
}
|
||||
maters.add(jo1);
|
||||
}
|
||||
}
|
||||
if (maters.size() == 0) {
|
||||
maters = trees;
|
||||
}
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("totalElements", ja.size());
|
||||
jo.put("content", maters.size() == 0 ? ja : trees);
|
||||
return jo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getSuperiorLimit(BmClassStandard classStandard, JSONArray ja, String parent_id) {
|
||||
if (StrUtil.isEmpty(classStandard.getParent_class_id()) || classStandard.getParent_class_id().equals("0")) {
|
||||
LambdaQueryWrapper<BmClassStandard> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(BmClassStandard::getIs_delete, "0")
|
||||
.and(q -> q.eq(BmClassStandard::getParent_class_id, "0")
|
||||
.or().isNull(BmClassStandard::getParent_class_id));
|
||||
List<BmClassStandard> bmClassStandards = this.baseMapper.selectList(lqw);
|
||||
|
||||
for (int m = 0; m < bmClassStandards.size(); m++) {
|
||||
BmClassStandard bmClassStandard = bmClassStandards.get(m);
|
||||
ja.add(bmClassStandard);
|
||||
}
|
||||
return ja;
|
||||
}
|
||||
LambdaQueryWrapper<BmClassStandard> queryWrapper = new LambdaQueryWrapper<BmClassStandard>().eq(BmClassStandard::getParent_class_id, classStandard.getParent_class_id());
|
||||
List<BmClassStandard> bmClassStandards = this.baseMapper.selectList(queryWrapper);
|
||||
for (int n = 0; n < bmClassStandards.size(); n++) {
|
||||
BmClassStandard bmClassStandard = bmClassStandards.get(n);
|
||||
ja.add(bmClassStandard);
|
||||
}
|
||||
LambdaQueryWrapper<BmClassStandard> lambdaQueryWrapper = new LambdaQueryWrapper<BmClassStandard>().eq(BmClassStandard::getClass_id, classStandard.getParent_class_id());
|
||||
BmClassStandard bmClassStandard = this.baseMapper.selectOne(lambdaQueryWrapper);
|
||||
if (bmClassStandard.getClass_id().equals(parent_id)) {
|
||||
ja.add(bmClassStandard);
|
||||
return ja;
|
||||
}
|
||||
return getSuperiorLimit(bmClassStandard, ja, parent_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BmClassStandard getType(String type_id, int level) {
|
||||
BmClassStandard bmClassStandard = this.baseMapper.selectById(type_id);
|
||||
if (ObjectUtil.isEmpty(bmClassStandard)) {
|
||||
return null;
|
||||
}
|
||||
String class_code = bmClassStandard.getClass_code();
|
||||
if (class_code.length() / 2 == level) {
|
||||
return bmClassStandard;
|
||||
} else {
|
||||
return getType(bmClassStandard.getParent_class_id(), level);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray getClassName() {
|
||||
LambdaQueryWrapper<BmClassStandard> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(BmClassStandard::getIs_delete, "0")
|
||||
.and(q -> q.eq(BmClassStandard::getParent_class_id, "0")
|
||||
.or().isNull(BmClassStandard::getParent_class_id));
|
||||
List<BmClassStandard> bmClassStandards = this.baseMapper.selectList(lqw);
|
||||
JSONArray res = new JSONArray();
|
||||
for (int i = 0; i < bmClassStandards.size(); i++) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("label", bmClassStandards.get(i).getClass_name());
|
||||
jsonObject.put("value", bmClassStandards.get(i).getClass_code());
|
||||
res.add(jsonObject);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user