select 接口搬迁

This commit is contained in:
sxu 2024-10-30 15:59:34 +08:00
parent c8a9385317
commit 7904372613
4 changed files with 658 additions and 0 deletions

View File

@ -0,0 +1,126 @@
package com.bonus.sgzb.material.controller;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.SelectDto;
import com.bonus.sgzb.material.service.SelectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author 10488
* 统一下拉选
*/
@RestController
@RequestMapping("/select/")
public class SelectController {
@Resource(name = "SelectService")
private SelectService service;
@ApiOperation(value = "往来单位下拉选")
@PostMapping("getUnitCbx")
public AjaxResult getUnitData(@RequestBody SelectDto dto) {
return service.getUnitData(dto);
}
@ApiOperation(value = "工程下拉选")
@PostMapping("getSectionEngineeringCbx")
public AjaxResult getProData(@RequestBody SelectDto dto) {
return service.getProData(dto);
}
@ApiOperation(value = "机具类型下拉选")
@PostMapping("getMaTypeData")
public AjaxResult getMaTypeData(@RequestBody SelectDto dto){
return service.getMaTypeData(dto);
}
@ApiOperation(value = "数据字典下拉选")
@PostMapping("getDictByPidCbx")
public AjaxResult getDictByPidCbx(@RequestBody SelectDto dto){
return service.getDictByPidCbx(dto);
}
@ApiOperation(value = "单位树/归属部门/所属上级")
@PostMapping("getDeptTree")
public AjaxResult getDeptTree(@RequestBody SelectDto dto){
return service.getDeptTree(dto);
}
@ApiOperation(value = "岗位下拉选")
@PostMapping("getPostCbx")
public AjaxResult getPostCbx(@RequestBody SelectDto dto){
return service.getPostCbx(dto);
}
@ApiOperation(value = "角色下拉选")
@PostMapping("getRoleCbx")
public AjaxResult getRoleCbx(@RequestBody SelectDto dto){
return service.getRoleCbx(dto);
}
@ApiOperation(value = "单位类型下拉选")
@PostMapping("getUnitTypeCbx")
public AjaxResult getUnitTypeCbx(@RequestBody SelectDto dto){
return service.getUnitTypeCbx(dto);
}
@ApiOperation(value = "设备类型树")
@PostMapping("getDeviceTypeTree")
public AjaxResult getDeviceTypeTree(@RequestBody SelectDto dto){
return service.getDeviceTypeTree(dto);
}
@ApiOperation(value = "资产属性")
@PostMapping("getAssetAttributesCbx")
public AjaxResult getAssetAttributesCbx(@RequestBody SelectDto dto){
return service.getAssetAttributesCbx(dto);
}
@ApiOperation(value = "机具厂家")
@PostMapping("getDeviceFactoryCbx")
public AjaxResult getDeviceFactoryCbx(@RequestBody SelectDto dto){
return service.getDeviceFactoryCbx(dto);
}
@ApiOperation(value = "工程项目")
@PostMapping("getProCbx")
public AjaxResult getProCbx(@RequestBody SelectDto dto){
return service.getProCbx(dto);
}
@ApiOperation(value = "配件所属上级树")
@PostMapping("getAccessoryTree")
public AjaxResult getAccessoryTree(){
return service.getAccessoryTree();
}
@ApiOperation(value = "配件所属上级树")
@PostMapping("getPartTree")
public AjaxResult getPartTree(@RequestBody SelectDto dto){
return service.getPartTree(dto);
}
@ApiOperation(value = "货架")
@PostMapping("getGoodsShelvesCbx")
public AjaxResult getGoodsShelvesCbx(@RequestBody SelectDto dto){
return service.getGoodsShelvesCbx(dto);
}
@ApiOperation(value = "用户/维修员/库管员/采购员")
@PostMapping("getUserByRoleIdCbx")
public AjaxResult getUserByRoleIdCbx(@RequestBody SelectDto dto){
return service.getUserByRoleIdCbx(dto);
}
@ApiOperation(value = "往来单位id和标段工程id获取协议信息")
@PostMapping("getAgreementInfoById")
public AjaxResult getAgreementInfoById(@RequestBody SelectDto dto){
return service.getAgreementInfoById(dto);
}
}

View File

@ -0,0 +1,178 @@
package com.bonus.sgzb.material.service;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.SelectDto;
/**
* @author 10488
* 统一下拉选
*/
public interface SelectService {
/**
* 往来单位
* @param dto
* @return AjaxResult
* @description 往来单位
* @author cwchen
* @date 2023/12/20 14:20
*/
AjaxResult getUnitData(SelectDto dto);
/**
* 工程
* @param dto
* @return AjaxResult
* @description 工程
* @author cwchen
* @date 2023/12/20 15:04
*/
AjaxResult getProData(SelectDto dto);
/**
* 机具类型
* @param dto
* @return AjaxResult
* @description 机具类型
* @author cwchen
* @date 2023/12/20 16:02
*/
AjaxResult getMaTypeData(SelectDto dto);
/**
* 数据字典下拉选
* @param dto
* @return AjaxResult
* @description 数据字典下拉选
* @author cwchen
* @date 2023/12/20 16:22
*/
AjaxResult getDictByPidCbx(SelectDto dto);
/**
* 单位树/归属部门/所属上级
* @param dto
* @return AjaxResult
* @description 单位树/归属部门/所属上级
* @author cwchen
* @date 2023/12/20 16:36
*/
AjaxResult getDeptTree(SelectDto dto);
/**
* 岗位下拉树
* @param dto
* @return AjaxResult
* @description 岗位下拉树
* @author cwchen
* @date 2023/12/20 17:45
*/
AjaxResult getPostCbx(SelectDto dto);
/**
* 角色下拉选
* @param dto
* @return AjaxResult
* @description 角色下拉选
* @author cwchen
* @date 2023/12/20 17:56
*/
AjaxResult getRoleCbx(SelectDto dto);
/**
* 单位类型下拉选
* @param dto
* @return AjaxResult
* @description 单位类型下拉选
* @author cwchen
* @date 2023/12/20 18:00
*/
AjaxResult getUnitTypeCbx(SelectDto dto);
/**
* 设备类型树
* @param dto
* @return AjaxResult
* @description 设备类型树
* @author cwchen
* @date 2023/12/20 18:14
*/
AjaxResult getDeviceTypeTree(SelectDto dto);
/**
* 资产属性
* @param dto
* @return AjaxResult
* @description 资产属性
* @author cwchen
* @date 2023/12/20 19:47
*/
AjaxResult getAssetAttributesCbx(SelectDto dto);
/**
* 机具厂家
* @param dto
* @return AjaxResult
* @description 机具厂家
* @author cwchen
* @date 2023/12/20 19:56
*/
AjaxResult getDeviceFactoryCbx(SelectDto dto);
/**
* 工程项目
* @param dto
* @return AjaxResult
* @description 工程项目
* @author cwchen
* @date 2023/12/20 20:01
*/
AjaxResult getProCbx(SelectDto dto);
/**
* 配件所属上级树
* @param
* @return AjaxResult
* @description 配件所属上级树
* @author cwchen
* @date 2023/12/20 20:25
*/
AjaxResult getAccessoryTree();
/**
* 货架
* @param dto
* @return AjaxResult
* @description 货架
* @author cwchen
* @date 2023/12/20 20:36
*/
AjaxResult getGoodsShelvesCbx(SelectDto dto);
/**
* 用户/维修员/库管员/采购员
* @param dto
* @return AjaxResult
* @description 用户/维修员/库管员/采购员
* @author cwchen
* @date 2023/12/20 20:48
*/
AjaxResult getUserByRoleIdCbx(SelectDto dto);
/**
* 往来单位id和标段工程id获取协议信息
* @param dto
* @return AjaxResult
* @description 往来单位id和标段工程id获取协议信息
* @author cwchen
* @date 2023/12/21 10:47
*/
AjaxResult getAgreementInfoById(SelectDto dto);
/**
* 配件所属上级树
* @param dto
* @return AjaxResult
*/
AjaxResult getPartTree(SelectDto dto);
}

View File

@ -0,0 +1,275 @@
package com.bonus.sgzb.material.service.impl;
import com.bonus.sgzb.common.core.utils.GlobalConstants;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.material.domain.AgreementVo;
import com.bonus.sgzb.material.domain.SelectDto;
import com.bonus.sgzb.material.domain.SelectVo;
import com.bonus.sgzb.material.domain.TreeNode;
import com.bonus.sgzb.material.mapper.SelectMapper;
import com.bonus.sgzb.material.service.SelectService;
import com.bonus.sgzb.material.utils.TreeBuild;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* @author 10488
* 统一下拉选
*/
@Service("SelectService")
@Slf4j
public class SelectServiceImpl implements SelectService {
@Resource(name = "SelectMapper")
private SelectMapper mapper;
@Override
public AjaxResult getUnitData(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getUnitData(dto);
} catch (Exception e) {
log.error("往来单位-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getProData(SelectDto dto) {
try {
List<SelectVo> list = mapper.getProData(dto);
list.removeIf(item -> item == null);
return AjaxResult.success(list);
} catch (Exception e) {
log.error("工程-查询失败", e);
}
return AjaxResult.success();
}
@Override
public AjaxResult getMaTypeData(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getMaTypeData(dto);
} catch (Exception e) {
log.error("机具类型-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getDictByPidCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getDictByPidCbx(dto);
} catch (Exception e) {
log.error("数据字典-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getDeptTree(SelectDto dto) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = mapper.getDeptTree(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("单位树/归属部门/所属上级-查询失败", e);
}
return AjaxResult.success(groupList);
}
@Override
public AjaxResult getPostCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getPostCbx(dto);
} catch (Exception e) {
log.error("岗位下拉选-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getRoleCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getRoleCbx(dto);
} catch (Exception e) {
log.error("角色下拉选-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getUnitTypeCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getUnitTypeCbx(dto);
} catch (Exception e) {
log.error("单位类型下拉选-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getDeviceTypeTree(SelectDto dto) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = mapper.getDeviceTypeTree(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("单位树/归属部门/所属上级-查询失败", e);
}
return AjaxResult.success(groupList);
}
@Override
public AjaxResult getAssetAttributesCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getAssetAttributesCbx(dto);
} catch (Exception e) {
log.error("资产属性-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getDeviceFactoryCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getDeviceFactoryCbx(dto);
} catch (Exception e) {
log.error("机具厂家-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getProCbx(SelectDto dto) {
List<SelectVo> list = new ArrayList<>();
try {
list = mapper.getProCbx(dto);
} catch (Exception e) {
log.error("工程项目-查询失败", e);
}
return AjaxResult.success(list);
}
@Override
public AjaxResult getAccessoryTree() {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = mapper.getAccessoryTree();
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("配件所属上级树-查询失败", e);
}
return AjaxResult.success(groupList);
}
@Override
public AjaxResult getPartTree(SelectDto dto) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = mapper.getPartTree(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("配件所属上级树-查询失败", e);
}
return AjaxResult.success(groupList);
}
@Override
public AjaxResult getGoodsShelvesCbx(SelectDto dto) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = mapper.getGoodsShelvesCbx(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("货架-查询失败", e);
}
return AjaxResult.success(groupList);
}
@Override
public AjaxResult getUserByRoleIdCbx(SelectDto dto) {
try {
if (Objects.equals(GlobalConstants.STRING_1, dto.getType())) {
// 用户/维修员/库管员/采购员-下拉选
List<SelectVo> list = new ArrayList<>();
list = mapper.getUserByRoleIdCbxSelect(dto);
return AjaxResult.success(list);
} else if (Objects.equals(GlobalConstants.STRING_2, dto.getType())) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
// 用户/维修员/库管员/采购员-
list = mapper.getUserByRoleIdCbxTree(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
return AjaxResult.success(groupList);
}
} catch (Exception e) {
log.error("用户/维修员/库管员/采购员-查询失败", e);
}
return AjaxResult.success(null);
}
@Override
public AjaxResult getAgreementInfoById(SelectDto dto) {
AgreementVo vo = new AgreementVo();
try {
List<AgreementVo> list = mapper.getAgreementInfoById(dto);
if (CollectionUtils.isNotEmpty(list)) {
vo = list.get(0);
}
} catch (Exception e) {
log.error("往来单位id和标段工程id获取协议信息", e);
}
return AjaxResult.success(vo);
}
}

View File

@ -0,0 +1,79 @@
package com.bonus.sgzb.material.utils;
import com.bonus.sgzb.material.domain.TreeNode;
import java.util.ArrayList;
import java.util.List;
/**
* BuildTree 构建树形结构
* @author 10488
*/
public class TreeBuild {
public List<TreeNode> nodeList = new ArrayList<>();
/**
* 构造方法
* @param nodeList 将数据集合赋值给nodeList即所有数据作为所有节点
*/
public TreeBuild(List<TreeNode> nodeList){
this.nodeList = nodeList;
}
/**
* 获取需构建的所有根节点顶级节点 "0"
* @return 所有根节点List集合
*/
public List<TreeNode> getRootNode(){
// 保存所有根节点所有根节点的数据
List<TreeNode> rootNodeList = new ArrayList<>();
// treeNode查询出的每一条数据节点
for (TreeNode treeNode : nodeList){
// 判断当前节点是否为根节点此处注意若parentId类型是String则要采用equals()方法判断
if (0 == treeNode.getParentId()) {
// 添加
rootNodeList.add(treeNode);
}
}
return rootNodeList;
}
/**
* 根据每一个顶级节点根节点进行构建树形结构
* @return 构建整棵树
*/
public List<TreeNode> buildTree(){
// treeNodes保存一个顶级节点所构建出来的完整树形
List<TreeNode> treeNodes = new ArrayList<TreeNode>();
// getRootNode()获取所有的根节点
for (TreeNode treeRootNode : getRootNode()) {
// 将顶级节点进行构建子树
treeRootNode = buildChildTree(treeRootNode);
// 完成一个顶级节点所构建的树形增加进来
treeNodes.add(treeRootNode);
}
return treeNodes;
}
/**
* 递归-----构建子树形结构
* @param pNode 根节点顶级节点
* @return 整棵树
*/
public TreeNode buildChildTree(TreeNode pNode){
List<TreeNode> childTree = new ArrayList<TreeNode>();
// nodeList所有节点集合所有数据
for (TreeNode treeNode : nodeList) {
// 判断当前节点的父节点ID是否等于根节点的ID即当前节点为其下的子节点
if (treeNode.getParentId() == pNode.getId()) {
// 再递归进行判断当前节点的情况调用自身方法
childTree.add(buildChildTree(treeNode));
}
}
// for循环结束即节点下没有任何节点树形构建结束设置树结果
pNode.setChildren(childTree);
return pNode;
}
}