问题修改
This commit is contained in:
parent
8435db8876
commit
40f857458b
|
|
@ -0,0 +1,123 @@
|
|||
package com.bonus.material.tool.controller;
|
||||
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.common.log.annotation.SysLog;
|
||||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.material.basic.domain.BmSlideShow;
|
||||
import com.bonus.material.common.annotation.PreventRepeatSubmit;
|
||||
import com.bonus.material.tool.domain.ToolEntity;
|
||||
import com.bonus.material.tool.service.ToolService;
|
||||
import com.bonus.system.api.domain.SysRole;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/tool")
|
||||
@Api(value = "工具类型管理", tags = "工具类型管理")
|
||||
public class ToolController extends BaseController {
|
||||
@Resource
|
||||
private ToolService toolService;
|
||||
|
||||
/**
|
||||
* 工具类型树
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 树结构
|
||||
*/
|
||||
@ApiOperation(value = "工具类型树")
|
||||
@GetMapping("/getTreeSelect")
|
||||
public AjaxResult getTreeSelect(ToolEntity entity) {
|
||||
return toolService.getTreeSelect(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具类型表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具类型表格")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ToolEntity entity) {
|
||||
try {
|
||||
startPage();
|
||||
List<ToolEntity> list = toolService.list(entity);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return getDataTableError(new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具类型新增")
|
||||
@PostMapping("/add")
|
||||
public AjaxResult add(@RequestBody ToolEntity entity) {
|
||||
return toolService.add(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具类型修改")
|
||||
@PostMapping("/update")
|
||||
public AjaxResult update(@RequestBody ToolEntity entity) {
|
||||
return toolService.update(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具类型删除")
|
||||
@PostMapping("/delete")
|
||||
public AjaxResult delete(@RequestBody ToolEntity entity) {
|
||||
return toolService.delete(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具类型下拉选")
|
||||
@PostMapping("/getSelect")
|
||||
public AjaxResult getSelect(@RequestBody ToolEntity entity) {
|
||||
return toolService.getSelect(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出列表
|
||||
*/
|
||||
@ApiOperation(value = "导出工具类型列表", notes = "按条件筛选后导出Excel,支持分页外的所有查询条件")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ToolEntity entity) {
|
||||
List<ToolEntity> list = toolService.list(entity);
|
||||
ExcelUtil<ToolEntity> util = new ExcelUtil<ToolEntity>(ToolEntity.class);
|
||||
util.exportExcel(response, list, "工具类型配置数据");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.bonus.material.tool.domain;
|
||||
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ToolEntity implements Serializable {
|
||||
|
||||
private Long typeId;
|
||||
|
||||
/**
|
||||
* 4级父节点名称
|
||||
*/
|
||||
@Excel(name = "工具专业")
|
||||
private String fourthParentName;
|
||||
/**
|
||||
* 3级父节点名称
|
||||
*/
|
||||
@Excel(name = "施工类型")
|
||||
private String greatGrandparentName;
|
||||
|
||||
/**
|
||||
* 2级父节点名称
|
||||
*/
|
||||
@Excel(name = "工具类型")
|
||||
private String grandparentTypeName;
|
||||
|
||||
/**
|
||||
* 1级父节点名称
|
||||
*/
|
||||
@Excel(name = "工具名称")
|
||||
private String parentTypeName;
|
||||
/**
|
||||
* 类型名称(非空)
|
||||
*/
|
||||
@Excel(name = "规格型号")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 上级ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 计量单位名称
|
||||
*/
|
||||
private String unitName;
|
||||
|
||||
/**
|
||||
* 管理方式(0编号 1计数)
|
||||
*/
|
||||
private String manageType;
|
||||
|
||||
/**
|
||||
* 层级
|
||||
*/
|
||||
private String level;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除),默认值0
|
||||
*/
|
||||
private String delFlag = "0";
|
||||
|
||||
/**
|
||||
* 创建者,默认空字符串
|
||||
*/
|
||||
private String createBy = "";
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
* 注:数据库字段为 datetime,Java 8+ 推荐使用 LocalDateTime(兼容日期时间,无时区问题)
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新者,默认空字符串
|
||||
*/
|
||||
private String updateBy = "";
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
// 子节点列表(非数据库字段,用于构建树形结构)
|
||||
private List<ToolEntity> children = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.bonus.material.tool.mapper;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.tool.domain.ToolEntity;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ToolMapper {
|
||||
/**
|
||||
* 工具类型树
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 树结构
|
||||
*/
|
||||
List<ToolEntity> getTreeSelect(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolEntity> list(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
Integer add(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型修改
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
Integer update(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型删除
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
Integer delete(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型详情
|
||||
*
|
||||
* @param typeId typeId
|
||||
* @return 表格
|
||||
*/
|
||||
ToolEntity getToolByTypeId(Long typeId);
|
||||
|
||||
/**
|
||||
* 获取同一父类下是否已经存在数据
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
|
||||
Integer getToolByTypeIdAndTypeName(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 修改 校验同层级下是否存在同名节点(排除自身)
|
||||
*
|
||||
* @param query 条件
|
||||
* @return
|
||||
*/
|
||||
Integer countSameNameInSameLevel(ToolEntity query);
|
||||
|
||||
/**
|
||||
* 查询删除 下是否存在节点
|
||||
*
|
||||
* @param query
|
||||
* @return
|
||||
*/
|
||||
Integer countChildren(ToolEntity query);
|
||||
|
||||
/**
|
||||
* 新增台账记录
|
||||
*
|
||||
* @param typeId 类型id
|
||||
*/
|
||||
void addLedger(Long typeId);
|
||||
|
||||
/**
|
||||
* 获取下拉选
|
||||
*
|
||||
* @return 集合
|
||||
*/
|
||||
@MapKey("id")
|
||||
List<Map<String, Object>> getSelect(ToolEntity query);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,313 @@
|
|||
package com.bonus.material.tool.service.Impl;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.tool.domain.ToolEntity;
|
||||
import com.bonus.material.tool.mapper.ToolMapper;
|
||||
import com.bonus.material.tool.service.ToolService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ToolServiceImpl implements ToolService {
|
||||
private static final Logger log = LoggerFactory.getLogger(ToolServiceImpl.class);
|
||||
@Resource
|
||||
private ToolMapper toolMapper;
|
||||
|
||||
/**
|
||||
* 工具类型树
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 树结构
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getTreeSelect(ToolEntity entity) {
|
||||
// 1. 按条件查询目标节点(符合筛选条件的节点)
|
||||
List<ToolEntity> allNodes = toolMapper.getTreeSelect(entity);
|
||||
// 2. 找出所有根节点(parent_id = null 或 parent_id = 0,根据业务调整)
|
||||
List<ToolEntity> rootNodes = allNodes.stream().filter(node -> node.getParentId() == null || node.getParentId() == 0).collect(Collectors.toList());
|
||||
// 3. 为每个根节点递归添加子节点
|
||||
for (ToolEntity root : rootNodes) {
|
||||
addChildren(root, allNodes);
|
||||
}
|
||||
return AjaxResult.success(rootNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具类型表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@Override
|
||||
public List<ToolEntity> list(ToolEntity entity) {
|
||||
return toolMapper.list(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult add(ToolEntity entity) {
|
||||
// 1. 校验父节点ID是否存在(避免空指针)
|
||||
Long parentId = entity.getParentId();
|
||||
if (parentId == null) {
|
||||
log.warn("新增工具类型失败:父节点ID不能为空");
|
||||
return AjaxResult.error("父节点ID不能为空,新增失败");
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 查询父节点信息(校验父节点有效性)
|
||||
ToolEntity parentTool = toolMapper.getToolByTypeId(parentId);
|
||||
if (parentTool == null) {
|
||||
log.warn("新增工具类型失败:父节点不存在,parentId={}", parentId);
|
||||
return AjaxResult.error("父节点不存在,新增失败");
|
||||
}
|
||||
|
||||
// 3. 校验父节点层级(限制最大层级为5,子节点即6级)
|
||||
String parentLevel = parentTool.getLevel();
|
||||
if (parentLevel == null || parentLevel.trim().isEmpty()) {
|
||||
log.error("新增工具类型失败:父节点层级未设置,parentId={}", parentId);
|
||||
return AjaxResult.error("父节点信息异常,新增失败");
|
||||
}
|
||||
int parentLevelNum;
|
||||
try {
|
||||
parentLevelNum = Integer.parseInt(parentLevel.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("新增工具类型失败:父节点层级格式错误(非数字),parentLevel={}", parentLevel, e);
|
||||
return AjaxResult.error("父节点层级异常,新增失败");
|
||||
}
|
||||
if (parentLevelNum > 4) {
|
||||
log.warn("新增工具类型失败:父节点层级超过限制(最大4级),parentLevel={}", parentLevel);
|
||||
return AjaxResult.error("父节点层级超过上限(最大支持4级),无法新增子节点");
|
||||
}
|
||||
|
||||
// 4. 校验同层级下名称是否重复(避免重复新增)
|
||||
int sameNameCount = toolMapper.getToolByTypeIdAndTypeName(entity);
|
||||
if (sameNameCount > 0) {
|
||||
log.warn("新增工具类型失败:同层级下名称已存在,typeName={}, parentId={}", entity.getTypeName(), parentId);
|
||||
return AjaxResult.error("当前分类下已存在同名类型,新增失败");
|
||||
}
|
||||
|
||||
|
||||
// 5. 设置当前节点层级(父层级+1)
|
||||
entity.setLevel(String.valueOf(parentLevelNum + 1));
|
||||
entity.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
||||
// 7. 执行新增操作
|
||||
int insertNum = toolMapper.add(entity);
|
||||
if (insertNum > 0) {
|
||||
toolMapper.addLedger(entity.getTypeId());
|
||||
log.info("新增工具类型成功:typeId={}, typeName={}", entity.getTypeId(), entity.getTypeName());
|
||||
return AjaxResult.success("新增成功", entity.getTypeId()); // 返回新增ID,便于前端使用
|
||||
} else {
|
||||
log.error("新增工具类型失败:数据库插入受影响行数为0,entity={}", entity);
|
||||
return AjaxResult.error("新增失败,请重试");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 捕获所有未预期异常,记录详细日志
|
||||
log.error("新增工具类型发生异常:entity={}", entity, e);
|
||||
return AjaxResult.error("系统异常,新增失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改工具类型
|
||||
*
|
||||
* @param entity 工具类型实体(含更新后的数据)
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult update(ToolEntity entity) {
|
||||
// 1. 校验主键ID是否存在
|
||||
Long typeId = entity.getTypeId();
|
||||
if (typeId == null) {
|
||||
log.warn("修改工具类型失败:主键ID不能为空");
|
||||
return AjaxResult.error("主键ID不能为空,修改失败");
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 查询当前节点原始信息(用于对比变更和校验)
|
||||
ToolEntity originalTool = toolMapper.getToolByTypeId(typeId);
|
||||
if (originalTool == null) {
|
||||
log.warn("修改工具类型失败:当前节点不存在,typeId={}", typeId);
|
||||
return AjaxResult.error("当前节点不存在,修改失败");
|
||||
}
|
||||
|
||||
// 3. 处理父节点变更(若父节点ID有修改)
|
||||
Long newParentId = entity.getParentId();
|
||||
Long oldParentId = originalTool.getParentId();
|
||||
ToolEntity newParentTool = null;
|
||||
|
||||
if (!Objects.equals(newParentId, oldParentId)) {
|
||||
// 3.1 新父节点ID非空校验
|
||||
if (newParentId == null) {
|
||||
log.warn("修改工具类型失败:新父节点ID不能为空,typeId={}", typeId);
|
||||
return AjaxResult.error("新父节点ID不能为空,修改失败");
|
||||
}
|
||||
|
||||
// 3.2 校验新父节点是否存在
|
||||
newParentTool = toolMapper.getToolByTypeId(newParentId);
|
||||
if (newParentTool == null) {
|
||||
log.warn("修改工具类型失败:新父节点不存在,newParentId={}, typeId={}", newParentId, typeId);
|
||||
return AjaxResult.error("新父节点不存在,修改失败");
|
||||
}
|
||||
|
||||
// 3.3 禁止自引用(父节点ID不能是自身ID)
|
||||
if (newParentId.equals(typeId)) {
|
||||
log.warn("修改工具类型失败:新父节点ID不能是自身,typeId={}", typeId);
|
||||
return AjaxResult.error("父节点不能选择自身,修改失败");
|
||||
}
|
||||
|
||||
// 3.4 校验新父节点层级(最大5级,子节点即6级)
|
||||
String newParentLevel = newParentTool.getLevel();
|
||||
if (newParentLevel == null || newParentLevel.trim().isEmpty()) {
|
||||
log.error("修改工具类型失败:新父节点层级未设置,newParentId={}", newParentId);
|
||||
return AjaxResult.error("新父节点信息异常,修改失败");
|
||||
}
|
||||
int newParentLevelNum;
|
||||
try {
|
||||
newParentLevelNum = Integer.parseInt(newParentLevel.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("修改工具类型失败:新父节点层级格式错误,newParentLevel={}", newParentLevel, e);
|
||||
return AjaxResult.error("新父节点层级异常,修改失败");
|
||||
}
|
||||
if (newParentLevelNum > 4) {
|
||||
log.warn("修改工具类型失败:新父节点层级超过上限,newParentLevel={}", newParentLevel);
|
||||
return AjaxResult.error("新父节点层级超过上限(最大支持4级),无法作为父节点");
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 校验名称是否重复(同层级下不允许重名)
|
||||
// 构建查询条件:同父节点+同名称+排除自身ID
|
||||
ToolEntity query = new ToolEntity();
|
||||
query.setParentId(Objects.isNull(newParentId) ? oldParentId : newParentId); // 父节点取新值(若有变更)
|
||||
query.setTypeName(entity.getTypeName());
|
||||
query.setTypeId(typeId); // 用于排除自身
|
||||
|
||||
int sameNameCount = toolMapper.countSameNameInSameLevel(query);
|
||||
if (sameNameCount > 0) {
|
||||
log.warn("修改工具类型失败:同层级下名称已存在,typeName={}, parentId={}, typeId={}", entity.getTypeName(), query.getParentId(), typeId);
|
||||
return AjaxResult.error("当前分类下已存在同名类型,修改失败");
|
||||
}
|
||||
// 5. 调整层级(若父节点变更,需同步更新自身层级)
|
||||
if (newParentTool != null) {
|
||||
int newParentLevelNum = Integer.parseInt(newParentTool.getLevel().trim());
|
||||
entity.setLevel(String.valueOf(newParentLevelNum + 1));
|
||||
}
|
||||
entity.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
||||
// 6. 补充更新信息
|
||||
entity.setUpdateTime(LocalDateTime.now()); // 强制更新时间为当前时间
|
||||
|
||||
// 7. 执行更新操作
|
||||
int updateNum = toolMapper.update(entity);
|
||||
if (updateNum > 0) {
|
||||
log.info("修改工具类型成功:typeId={}, typeName={}", typeId, entity.getTypeName());
|
||||
return AjaxResult.success("修改成功");
|
||||
} else {
|
||||
log.error("修改工具类型失败:数据库更新受影响行数为0,entity={}", entity);
|
||||
return AjaxResult.error("修改失败,请重试");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("修改工具类型发生异常:typeId={}, entity={}", typeId, entity, e);
|
||||
return AjaxResult.error("系统异常,修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除工具类型(逻辑删除)
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 操作结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult delete(ToolEntity entity) {
|
||||
// 1. 校验主键ID
|
||||
if (entity.getTypeId() == null) {
|
||||
log.warn("删除工具类型失败:主键ID不能为空");
|
||||
return AjaxResult.error("主键ID不能为空,删除失败");
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 校验当前节点是否存在
|
||||
ToolEntity tool = toolMapper.getToolByTypeId(entity.getTypeId());
|
||||
if (tool == null) {
|
||||
log.warn("删除工具类型失败:节点不存在,typeId={}", entity.getTypeId());
|
||||
return AjaxResult.error("节点不存在,删除失败");
|
||||
}
|
||||
|
||||
// 3. 校验是否存在子节点(核心逻辑)
|
||||
int childrenCount = toolMapper.countChildren(entity);
|
||||
if (childrenCount > 0) {
|
||||
log.warn("删除工具类型失败:存在子节点,不允许删除,typeId={}, 子节点数量={}", entity.getTypeId(), childrenCount);
|
||||
return AjaxResult.error("该节点存在子节点,请先删除子节点后再试");
|
||||
}
|
||||
|
||||
// 4. 执行逻辑删除
|
||||
ToolEntity deleteEntity = new ToolEntity();
|
||||
deleteEntity.setTypeId(entity.getTypeId());
|
||||
deleteEntity.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getNickName());
|
||||
deleteEntity.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
int deleteNum = toolMapper.delete(deleteEntity);
|
||||
if (deleteNum > 0) {
|
||||
log.info("删除工具类型成功:typeId={}, operator={}", entity.getTypeId(), SecurityUtils.getLoginUser().getSysUser().getNickName());
|
||||
return AjaxResult.success("删除成功");
|
||||
} else {
|
||||
log.error("删除工具类型失败:数据库更新受影响行数为0,typeId={}", entity.getTypeId());
|
||||
return AjaxResult.error("删除失败,请重试");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("删除工具类型发生异常:typeId={}", entity.getTypeId(), e);
|
||||
return AjaxResult.error("系统异常,删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下拉选
|
||||
*
|
||||
* @param query
|
||||
* @return 集合
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult getSelect(ToolEntity query) {
|
||||
try {
|
||||
List<Map<String, Object>> select = toolMapper.getSelect(query);
|
||||
return !select.isEmpty() ? AjaxResult.success(select) : AjaxResult.error();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return AjaxResult.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 递归为父节点添加子节点
|
||||
*
|
||||
* @param parent 父节点
|
||||
* @param allNodes 所有节点列表
|
||||
*/
|
||||
private void addChildren(ToolEntity parent, List<ToolEntity> allNodes) {
|
||||
// 筛选当前父节点的子节点(parent_id = 父节点的 type_id)
|
||||
List<ToolEntity> children = allNodes.stream().filter(node -> parent.getTypeId().equals(node.getParentId())).collect(Collectors.toList());
|
||||
|
||||
// 为父节点设置子节点
|
||||
parent.setChildren(children);
|
||||
|
||||
// 递归为子节点添加它们的子节点
|
||||
for (ToolEntity child : children) {
|
||||
addChildren(child, allNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.bonus.material.tool.service;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.tool.domain.ToolEntity;
|
||||
import org.apache.ibatis.annotations.MapKey;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ToolService {
|
||||
/**
|
||||
* 工具类型树
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 树结构
|
||||
*/
|
||||
AjaxResult getTreeSelect(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolEntity> list(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 工具类型新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
AjaxResult add(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 修改节点
|
||||
*
|
||||
* @param entity 条件
|
||||
* @return 结果
|
||||
*/
|
||||
AjaxResult update(ToolEntity entity);
|
||||
|
||||
/**
|
||||
* 删除节点
|
||||
*
|
||||
* @param entity 条件
|
||||
* @return 结果
|
||||
*/
|
||||
AjaxResult delete(ToolEntity entity);
|
||||
|
||||
|
||||
/**
|
||||
* 获取下拉选
|
||||
*
|
||||
* @return 集合
|
||||
*/
|
||||
AjaxResult getSelect(ToolEntity query);
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.bonus.material.toolLedger.controller;
|
||||
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.material.tool.domain.ToolEntity;
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
import com.bonus.material.toolLedger.service.ToolLedgerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/toolLedger")
|
||||
@Api(value = "工具台账", tags = "工具台账")
|
||||
public class ToolLedgerController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private ToolLedgerService toolLedgerService;
|
||||
|
||||
|
||||
/**
|
||||
* 工具台账表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具台账表格")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ToolLedgerEntity entity) {
|
||||
try {
|
||||
startPage();
|
||||
List<ToolLedgerEntity> list = toolLedgerService.list(entity);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return getDataTableError(new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.bonus.material.toolLedger.domain;
|
||||
|
||||
import com.bonus.common.core.annotation.Excel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ToolLedgerEntity implements Serializable {
|
||||
|
||||
private Long typeId;
|
||||
|
||||
/**
|
||||
* 4级父节点id
|
||||
*/
|
||||
private String fourthParentId;
|
||||
/**
|
||||
* 4级父节点名称
|
||||
*/
|
||||
@Excel(name = "工具专业")
|
||||
private String fourthParentName;
|
||||
|
||||
/**
|
||||
* 3级父节点id
|
||||
*/
|
||||
private String greatGrandparentId;
|
||||
/**
|
||||
* 3级父节点名称
|
||||
*/
|
||||
@Excel(name = "施工类型")
|
||||
private String greatGrandparentName;
|
||||
/**
|
||||
* 2级父节点id
|
||||
*/
|
||||
private String grandparentTypeId;
|
||||
/**
|
||||
* 2级父节点名称
|
||||
*/
|
||||
@Excel(name = "工具类型")
|
||||
private String grandparentTypeName;
|
||||
/**
|
||||
* 1级父节点id
|
||||
*/
|
||||
private String parentTypeId;
|
||||
/**
|
||||
* 1级父节点名称
|
||||
*/
|
||||
@Excel(name = "工具名称")
|
||||
private String parentTypeName;
|
||||
/**
|
||||
* 类型名称(非空)
|
||||
*/
|
||||
@Excel(name = "规格型号")
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 计量单位名称
|
||||
*/
|
||||
private String unitName;
|
||||
|
||||
/**
|
||||
* 管理方式(0编号 1计数)
|
||||
*/
|
||||
private String manageType;
|
||||
|
||||
/**
|
||||
* 在库数量(库存中可用的数量)
|
||||
*/
|
||||
@Excel(name = "在库数量")
|
||||
private float stockQuantity;
|
||||
|
||||
/**
|
||||
* 自用数量(本单位内部使用的数量)
|
||||
*/
|
||||
@Excel(name = "自用数量")
|
||||
private float selfUseQuantity;
|
||||
|
||||
/**
|
||||
* 共享数量(对外共享/借出的数量)
|
||||
*/
|
||||
@Excel(name = "共享数量")
|
||||
private float shareQuantity;
|
||||
|
||||
/**
|
||||
* 在修数量(正在维修的数量)
|
||||
*/
|
||||
@Excel(name = "在修数量")
|
||||
private float repairingQuantity;
|
||||
/**
|
||||
* 设备总数
|
||||
*/
|
||||
private float count;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.bonus.material.toolLedger.mapper;
|
||||
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ToolLedgerMapper {
|
||||
/**
|
||||
* 工具台账表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolLedgerEntity> list(ToolLedgerEntity entity);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.bonus.material.toolLedger.service.Impl;
|
||||
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
import com.bonus.material.toolLedger.mapper.ToolLedgerMapper;
|
||||
import com.bonus.material.toolLedger.service.ToolLedgerService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ToolLedgerServiceImpl implements ToolLedgerService {
|
||||
@Resource
|
||||
private ToolLedgerMapper mapper;
|
||||
|
||||
/**
|
||||
* 工具台账表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@Override
|
||||
public List<ToolLedgerEntity> list(ToolLedgerEntity entity) {
|
||||
return mapper.list(entity);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.bonus.material.toolLedger.service;
|
||||
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ToolLedgerService {
|
||||
/**
|
||||
* 工具台账表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolLedgerEntity> list(ToolLedgerEntity entity);
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
package com.bonus.material.toolProcess.controller;
|
||||
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.material.tool.domain.ToolEntity;
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
import com.bonus.material.toolProcess.domain.ToolApplyEntity;
|
||||
import com.bonus.material.toolProcess.service.ToolApplyService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/toolApply")
|
||||
@Api(value = "工具录入单", tags = "工具录入单")
|
||||
public class ToolApplyController extends BaseController {
|
||||
@Resource
|
||||
private ToolApplyService toolApplyService;
|
||||
|
||||
/**
|
||||
* 工具申请单表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@ApiOperation(value = "工具录入表格")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ToolApplyEntity entity) {
|
||||
try {
|
||||
startPage();
|
||||
List<ToolLedgerEntity> list = toolApplyService.list(entity);
|
||||
return getDataTable(list);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return getDataTableError(new ArrayList<>());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具录入新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation(value = "工具录入新增")
|
||||
@PostMapping("/add")
|
||||
public AjaxResult add(@RequestBody ToolApplyEntity entity) {
|
||||
return toolApplyService.add(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具录入修改
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation(value = "工具录入修改")
|
||||
@PostMapping("/update")
|
||||
public AjaxResult update(@RequestBody ToolApplyEntity entity) {
|
||||
return toolApplyService.update(entity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 工具录入删除
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
@ApiOperation(value = "工具录入删除")
|
||||
@PostMapping("/delete")
|
||||
public AjaxResult delete(@RequestBody ToolApplyEntity entity) {
|
||||
return toolApplyService.delete(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.bonus.material.toolProcess.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ToolApplyEntity {
|
||||
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 申请单号
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 申请人(用户ID)
|
||||
*/
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 申请时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 状态(0草稿 1审批中 2通过 3驳回)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 审批人(用户ID)
|
||||
*/
|
||||
private Long reviewBy;
|
||||
|
||||
/**
|
||||
* 审批时间
|
||||
*/
|
||||
private LocalDateTime reviewTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.bonus.material.toolProcess.mapper;
|
||||
|
||||
import com.bonus.material.toolProcess.domain.ToolApplyEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ToolApplyMapper {
|
||||
/**
|
||||
* 工具申请单表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolApplyEntity> list(ToolApplyEntity entity);
|
||||
|
||||
/**
|
||||
* 工具录入删除
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
Integer delete(ToolApplyEntity entity);
|
||||
|
||||
Integer add(ToolApplyEntity entity);
|
||||
|
||||
Integer update(ToolApplyEntity entity);
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.bonus.material.toolProcess.service.Impl;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
import com.bonus.material.toolProcess.domain.ToolApplyEntity;
|
||||
import com.bonus.material.toolProcess.mapper.ToolApplyMapper;
|
||||
import com.bonus.material.toolProcess.service.ToolApplyService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ToolApplyServiceImpl implements ToolApplyService {
|
||||
private static final Logger log = LoggerFactory.getLogger(ToolApplyServiceImpl.class);
|
||||
@Resource
|
||||
private ToolApplyMapper toolApplyMapper;
|
||||
|
||||
/**
|
||||
* 工具申请单表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
@Override
|
||||
public List<ToolLedgerEntity> list(ToolApplyEntity entity) {
|
||||
return toolApplyMapper.list(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具录入新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult add(ToolApplyEntity entity) {
|
||||
try {
|
||||
Integer num = toolApplyMapper.add(entity);
|
||||
return num > 0 ? AjaxResult.success("新增成功") : AjaxResult.error("新增失败");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error("新增失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具录入修改
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult update(ToolApplyEntity entity) {
|
||||
try {
|
||||
Integer num = toolApplyMapper.update(entity);
|
||||
return num > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error("修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具录入删除
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult delete(ToolApplyEntity entity) {
|
||||
try {
|
||||
Integer num = toolApplyMapper.delete(entity);
|
||||
return num > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return AjaxResult.error("修改失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.bonus.material.toolProcess.service;
|
||||
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.material.toolLedger.domain.ToolLedgerEntity;
|
||||
import com.bonus.material.toolProcess.domain.ToolApplyEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ToolApplyService {
|
||||
/**
|
||||
* 工具申请单表格
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 表格
|
||||
*/
|
||||
List<ToolLedgerEntity> list(ToolApplyEntity entity);
|
||||
|
||||
/**
|
||||
* 工具录入新增
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
AjaxResult add(ToolApplyEntity entity);
|
||||
|
||||
/**
|
||||
* 工具录入修改
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
AjaxResult update(ToolApplyEntity entity);
|
||||
|
||||
/**
|
||||
* 工具录入删除
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return 结果
|
||||
*/
|
||||
AjaxResult delete(ToolApplyEntity entity);
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
<?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.bonus.material.tool.mapper.ToolMapper">
|
||||
<insert id="add" parameterType="com.bonus.material.tool.domain.ToolEntity" useGeneratedKeys="true"
|
||||
keyProperty="typeId">
|
||||
INSERT INTO tool_type (
|
||||
type_name,
|
||||
<if test="parentId != null">parent_id,</if>
|
||||
<if test="unitName != null and unitName != ''">unit_name,</if>
|
||||
<if test="manageType != null and manageType != ''">manage_type,</if>
|
||||
<if test="level != null and level != ''">level,</if>
|
||||
del_flag,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time
|
||||
) VALUES (
|
||||
#{typeName},
|
||||
<if test="parentId != null">#{parentId},</if>
|
||||
<if test="unitName != null and unitName != ''">#{unitName},</if>
|
||||
<if test="manageType != null and manageType != ''">#{manageType},</if>
|
||||
<if test="level != null and level != ''">#{level},</if>
|
||||
'0',
|
||||
#{createBy},
|
||||
now(),
|
||||
#{updateBy},
|
||||
now()
|
||||
)
|
||||
</insert>
|
||||
<insert id="addLedger">
|
||||
INSERT INTO tool_ledger (type_id)
|
||||
VALUES (#{typeId});
|
||||
|
||||
</insert>
|
||||
<update id="update" parameterType="com.bonus.material.tool.domain.ToolEntity">
|
||||
UPDATE tool_type
|
||||
<set>
|
||||
<!-- 类型名称:非空且非空字符串才更新 -->
|
||||
<if test="typeName != null and typeName != ''">
|
||||
type_name = #{typeName},
|
||||
</if>
|
||||
<!-- 上级ID:允许为null(根节点),但需明确传入才更新 -->
|
||||
<if test="parentId != null">
|
||||
parent_id = #{parentId},
|
||||
</if>
|
||||
<!-- 计量单位:非空且非空字符串才更新 -->
|
||||
<if test="unitName != null and unitName != ''">
|
||||
unit_name = #{unitName},
|
||||
</if>
|
||||
<!-- 管理方式:非空且非空字符串才更新(只允许0或1) -->
|
||||
<if test="manageType != null and manageType != ''">
|
||||
manage_type = #{manageType},
|
||||
</if>
|
||||
<!-- 层级:非空且非空字符串才更新 -->
|
||||
<if test="level != null and level != ''">
|
||||
level = #{level},
|
||||
</if>
|
||||
<!-- 更新人:非空且非空字符串才更新 -->
|
||||
<if test="updateBy != null and updateBy != ''">
|
||||
update_by = #{updateBy},
|
||||
</if>
|
||||
<!-- 更新时间:强制更新为当前时间(若未传则用数据库时间) -->
|
||||
update_time = #{updateTime, jdbcType=TIMESTAMP}
|
||||
</set>
|
||||
WHERE
|
||||
type_id = #{typeId} <!-- 主键ID必传 -->
|
||||
AND del_flag = '0' <!-- 只更新未删除的节点 -->
|
||||
</update>
|
||||
|
||||
<!-- 1. 查询当前节点的子节点数量(未删除的) -->
|
||||
<select id="countChildren" parameterType="java.lang.Long" resultType="java.lang.Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM tool_type
|
||||
WHERE parent_id = #{typeId} <!-- 子节点的parent_id等于当前节点的typeId -->
|
||||
AND del_flag = '0' <!-- 只统计未删除的子节点 -->
|
||||
</select>
|
||||
|
||||
<!-- 2. 逻辑删除当前节点(更新del_flag为2) -->
|
||||
<update id="delete" parameterType="com.bonus.material.tool.domain.ToolEntity">
|
||||
UPDATE tool_type
|
||||
SET del_flag = '2', <!-- 标记为删除 -->
|
||||
update_by = #{updateBy}, <!-- 更新操作人 -->
|
||||
update_time = #{updateTime} <!-- 更新时间 -->
|
||||
WHERE type_id = #{typeId}
|
||||
AND del_flag = '0' <!-- 只删除未删除的节点 -->
|
||||
</update>
|
||||
|
||||
<select id="getTreeSelect" resultType="com.bonus.material.tool.domain.ToolEntity">
|
||||
SELECT type_id AS typeId,
|
||||
type_name AS typeName,
|
||||
parent_id AS parentId,
|
||||
unit_name AS unitName,
|
||||
manage_type AS manageType,
|
||||
level AS level
|
||||
FROM tool_type
|
||||
WHERE del_flag = '0' and level !='5'
|
||||
<if test="typeName != null and typeName != ''">
|
||||
AND type_name LIKE CONCAT('%', #{typeName}, '%')
|
||||
</if>
|
||||
</select>
|
||||
<select id="list" resultType="com.bonus.material.tool.domain.ToolEntity">
|
||||
SELECT
|
||||
tt.type_id AS typeId,
|
||||
tt.type_name AS typeName,
|
||||
tt.parent_id AS parentId,
|
||||
tt.unit_name AS unitName,
|
||||
tt.manage_type AS manageType,
|
||||
tt.level AS level,
|
||||
tt1.type_name AS parentTypeName, -- 1级父节点名称
|
||||
tt2.type_name AS grandparentTypeName, -- 2级父节点名称
|
||||
tt3.type_name AS greatGrandparentName, -- 3级父节点名称
|
||||
tt4.type_name AS fourthParentName -- 4级父节点名称
|
||||
FROM
|
||||
tool_type tt
|
||||
-- 关联1级父节点(直接父节点)
|
||||
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
|
||||
-- 关联2级父节点(祖父节点)
|
||||
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
|
||||
-- 关联3级父节点(曾祖父节点)
|
||||
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
|
||||
-- 关联4级父节点
|
||||
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
|
||||
WHERE
|
||||
tt.del_flag = '0'
|
||||
AND tt1.del_flag = '0'
|
||||
AND tt2.del_flag = '0'
|
||||
AND tt3.del_flag = '0'
|
||||
AND tt4.del_flag = '0'
|
||||
<!-- 动态条件:筛选上级节点(1-4级)中包含指定typeId的记录 -->
|
||||
<if test="typeId != null"> <!-- 注意:typeId是Long类型,无需判断是否为空字符串 -->
|
||||
AND (
|
||||
tt1.type_id = #{typeId} OR
|
||||
tt2.type_id = #{typeId} OR
|
||||
tt3.type_id = #{typeId} OR
|
||||
tt4.type_id = #{typeId}
|
||||
)
|
||||
</if>
|
||||
<if test="typeName != null and typeName != ''">
|
||||
AND tt.type_name LIKE CONCAT('%', #{typeName}, '%')
|
||||
</if>
|
||||
ORDER BY
|
||||
tt.create_time DESC
|
||||
</select>
|
||||
<select id="getToolByTypeId" resultType="com.bonus.material.tool.domain.ToolEntity">
|
||||
SELECT type_id AS typeId,
|
||||
type_name AS typeName,
|
||||
parent_id AS parentId,
|
||||
unit_name AS unitName,
|
||||
manage_type AS manageType,
|
||||
level AS level,
|
||||
del_flag AS delFlag,
|
||||
create_by AS createBy,
|
||||
create_time AS createTime,
|
||||
update_by AS updateBy,
|
||||
update_time AS updateTime
|
||||
FROM tool_type
|
||||
WHERE type_id = #{typeId} -- 传入的主键ID
|
||||
AND del_flag = '0' -- 只查询未删除的记录(逻辑删除校验)
|
||||
</select>
|
||||
<select id="getToolByTypeIdAndTypeName" resultType="java.lang.Integer">
|
||||
SELECT count(1)
|
||||
FROM tool_type
|
||||
WHERE parent_id = #{parentId} -- 传入的主键ID
|
||||
AND type_name = #{typeName}
|
||||
AND del_flag = '0' -- 只查询未删除的记录(逻辑删除校验)
|
||||
</select>
|
||||
|
||||
<select id="countSameNameInSameLevel" parameterType="com.bonus.material.tool.domain.ToolEntity"
|
||||
resultType="java.lang.Integer">
|
||||
SELECT COUNT(*) FROM tool_type
|
||||
WHERE del_flag = '0'
|
||||
AND parent_id = #{parentId}
|
||||
AND type_name = #{typeName}
|
||||
AND type_id != #{typeId} <!-- 排除自身 -->
|
||||
</select>
|
||||
<select id="getSelect" resultType="java.util.Map">
|
||||
SELECT type_id AS id,
|
||||
type_name AS label
|
||||
FROM tool_type
|
||||
WHERE del_flag = '0'
|
||||
and parent_id = #{parentId}
|
||||
and level = #{level}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
<?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.bonus.material.toolLedger.mapper.ToolLedgerMapper">
|
||||
|
||||
<select id="list" resultType="com.bonus.material.toolLedger.domain.ToolLedgerEntity">
|
||||
SELECT
|
||||
tt.type_id AS typeId,
|
||||
tt.type_name AS typeName,
|
||||
tt.unit_name AS unitName,
|
||||
tt.manage_type AS manageType,
|
||||
tt1.type_name AS parentTypeName, -- 1级父节点名称
|
||||
tt2.type_name AS grandparentTypeName, -- 2级父节点名称
|
||||
tt3.type_name AS greatGrandparentName, -- 3级父节点名称
|
||||
tt4.type_name AS fourthParentName, -- 4级父节点名称
|
||||
tl.stock_quantity / 1000 AS stockQuantity,
|
||||
tl.self_use_quantity / 1000 AS selfUseQuantity,
|
||||
tl.share_quantity / 1000 AS shareQuantity,
|
||||
tl.repairing_quantity / 1000 AS repairingQuantity,
|
||||
(IFNULL(tl.stock_quantity, 0) + IFNULL(tl.self_use_quantity, 0) +
|
||||
IFNULL(tl.share_quantity, 0) + IFNULL(tl.repairing_quantity, 0)) / 1000 AS count
|
||||
FROM
|
||||
tool_type tt
|
||||
INNER JOIN tool_ledger tl ON tl.type_id = tt.type_id
|
||||
-- 关联1级父节点(直接父节点)
|
||||
INNER JOIN tool_type tt1 ON tt.parent_id = tt1.type_id
|
||||
-- 关联2级父节点(祖父节点)
|
||||
INNER JOIN tool_type tt2 ON tt1.parent_id = tt2.type_id
|
||||
-- 关联3级父节点(曾祖父节点)
|
||||
INNER JOIN tool_type tt3 ON tt2.parent_id = tt3.type_id
|
||||
-- 关联4级父节点
|
||||
INNER JOIN tool_type tt4 ON tt3.parent_id = tt4.type_id
|
||||
WHERE
|
||||
tt.del_flag = '0'
|
||||
AND tt1.del_flag = '0'
|
||||
AND tt2.del_flag = '0'
|
||||
AND tt3.del_flag = '0'
|
||||
AND tt4.del_flag = '0'
|
||||
<if test="fourthParentId != null and fourthParentId != ''">
|
||||
AND tt4.type_id =#{fourthParentId}
|
||||
</if>
|
||||
<if test="greatGrandparentId != null and greatGrandparentId != ''">
|
||||
AND tt3.type_id = #{greatGrandparentId}
|
||||
</if>
|
||||
<if test="grandparentTypeId != null and grandparentTypeId != ''">
|
||||
AND tt2.type_id = #{grandparentTypeId}
|
||||
</if>
|
||||
<if test="parentTypeId != null and parentTypeId != ''">
|
||||
AND tt1.type_id = #{parentTypeId}
|
||||
</if>
|
||||
<if test="typeName != null and typeName != ''">
|
||||
AND tt.type_name LIKE CONCAT('%', #{typeName}, '%')
|
||||
</if>
|
||||
ORDER BY
|
||||
tt.create_time DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?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.bonus.material.toolProcess.mapper.ToolApplyMapper">
|
||||
<update id="delete">
|
||||
|
||||
</update>
|
||||
|
||||
<select id="list" resultType="com.bonus.material.toolProcess.domain.ToolApplyEntity">
|
||||
SELECT id AS id,
|
||||
code AS code,
|
||||
create_by AS createBy,
|
||||
create_time AS createTime,
|
||||
status AS status,
|
||||
review_by AS reviewBy,
|
||||
review_time AS reviewTime
|
||||
from tool_apply
|
||||
WHERE del_flag = '0'
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue