From b53f63403fa307ac3feb635db55ca7bc49894f1d Mon Sep 17 00:00:00 2001 From: mashuai Date: Tue, 13 Aug 2024 13:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E8=B5=84=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/bonus/base/api/domain/MaType.java | 89 ++++++ .../com/bonus/base/api/domain/TreeSelect.java | 99 +++++++ .../material/controller/MaTypeController.java | 72 +++++ .../bonus/material/mapper/MaTypeMapper.java | 80 ++++++ .../bonus/material/service/MaTypeService.java | 50 ++++ .../service/impl/MaTypeServiceImpl.java | 166 +++++++++++ .../main/resources/mapper/MaTypeMapper.xml | 264 ++++++++++++++++++ 7 files changed, 820 insertions(+) create mode 100644 bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java create mode 100644 bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java create mode 100644 bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java new file mode 100644 index 0000000..4f2dcef --- /dev/null +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java @@ -0,0 +1,89 @@ +package com.bonus.base.api.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 机具类型表ma_type(MaType)实体类 + * + * @author makejava + * @since 2024-08-13 10:13:47 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MaType implements Serializable { + private static final long serialVersionUID = 135108051525707131L; + /** + * id + */ + private Integer id; + /** + * 上级id + */ + private Integer parentId; + /** + * 名称 + */ + private String name; + /** + * 层级 + */ + private String level; + /** + * 库存 + */ + private String storageNum; + /** + * 计量单位id + */ + private String unitId; + /** + * 采购单价 + */ + private String buyPrice; + /** + * 租赁单价 + */ + private String leasePrice; + /** + * 管理类型0是编码1计数 + */ + private String manageType; + /** + * 是否启用 + */ + private String isActive; + /** + * 额定载荷 + */ + private String rateLoad; + /** + * 试验载荷 + */ + private String testLoad; + /** + * 持荷时间 + */ + private String holdTime; + /** + * 文件路径 + */ + private String fileUrl; + /** + * 数据所属 + */ + private String companyId; + + /** 子节点 */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children = new ArrayList<>(); + +} + diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java new file mode 100644 index 0000000..92dc8d6 --- /dev/null +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java @@ -0,0 +1,99 @@ +package com.bonus.base.api.domain; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.io.Serializable; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Treeselect树结构实体类 + * + * @author ruoyi + */ +public class TreeSelect implements Serializable +{ + private static final long serialVersionUID = 1L; + + /** 节点ID */ + private Integer id; + + /** 节点名称 */ + private String label; + + private Integer level; + + private Integer parentId; + + private String companyId; + + /** 子节点 */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; + + public TreeSelect(MaType maType) + { + this.parentId = maType.getParentId(); + this.level = Integer.valueOf(maType.getLevel()); + this.id = maType.getId(); + this.label = maType.getName(); + this.companyId = maType.getCompanyId(); + this.children = maType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + + public Integer getParentId() { + return parentId; + } + + public void setParentId(Integer parentId) { + this.parentId = parentId; + } + + + public Integer getId() + { + return id; + } + + public void setId(Integer id) + { + this.id = id; + } + + public Integer getLevel() { + return level; + } + + public void setLevel(Integer level) { + this.level = level; + } + + public String getLabel() + { + return label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getCompanyId() { + return companyId; + } + + public void setCompanyId(String companyId) { + this.companyId = companyId; + } + + public List getChildren() + { + return children; + } + + public void setChildren(List children) + { + this.children = children; + } +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java new file mode 100644 index 0000000..f171de7 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java @@ -0,0 +1,72 @@ +package com.bonus.material.controller; + +import com.bonus.base.api.domain.MaType; +import com.bonus.base.api.domain.TreeSelect; +import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.service.MaTypeService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 机具类型表ma_type(MaType)表控制层 + * + * @author makejava + * @since 2024-08-13 10:12:04 + */ +@Api(tags = "机具类型管理") +@RestController +@RequestMapping("/maType") +public class MaTypeController extends BaseController { + /** + * 服务对象 + */ + @Resource + private MaTypeService maTypeService; + + /** + * 根据类型名称查询类型树 + * + * @param typeName 类型名称 + * @return 查询结果 + */ + @ApiOperation(value = "根据类型名称查询类型树") + @GetMapping("/getMaTypeList") + public AjaxResult queryByPage(@RequestParam(required = false, value = "typeName") String typeName) { + List maTypeList = maTypeService.getMaTypeList(typeName); + return AjaxResult.success(maTypeList); + } + + /** + * 新增数据 + * + * @param maType 实体 + * @return 新增结果 + */ + @ApiOperation(value = "新增数据") + @PostMapping("/add") + public AjaxResult add(@RequestBody MaType maType) { + return maTypeService.insert(maType); + } + + /** + * 编辑数据 + * + * @param maType 实体 + * @return 编辑结果 + */ + @ApiOperation(value = "编辑数据") + @PostMapping("/update") + public AjaxResult edit(@RequestBody MaType maType) { + return maTypeService.update(maType); + } + +} + diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java new file mode 100644 index 0000000..1750043 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java @@ -0,0 +1,80 @@ +package com.bonus.material.mapper; + +import com.bonus.base.api.domain.MaType; +import org.apache.ibatis.annotations.Param; +import org.springframework.data.domain.Pageable; +import java.util.List; + +/** + * 机具类型表ma_type(MaType)表数据库访问层 + * + * @author makejava + * @since 2024-08-13 10:15:27 + */ +public interface MaTypeMapper { + + /** + * 查询指定行数据 + * + * @param maType 查询条件 + * @param pageable 分页对象 + * @return 对象列表 + */ + List queryAllByLimit(MaType maType, @Param("pageable") Pageable pageable); + + /** + * 统计总行数 + * + * @param maType 查询条件 + * @return 总行数 + */ + long count(MaType maType); + + /** + * 新增数据 + * + * @param maType 实例对象 + * @return 影响行数 + */ + int insert(MaType maType); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param maType 实例对象 + * @return 影响行数 + */ + int update(MaType maType); + + /** + * 根据名称查询 + * @param name + * @return + */ + MaType queryByName(String name); + + /** + * 根据名称查询 + * @param typeName + * @return + */ + List selectMaTypeTree(String typeName); +} + diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java new file mode 100644 index 0000000..dc02ee3 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java @@ -0,0 +1,50 @@ +package com.bonus.material.service; + +import com.bonus.base.api.domain.MaType; +import com.bonus.base.api.domain.TreeSelect; +import com.bonus.common.core.web.domain.AjaxResult; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.util.List; + +/** + * 机具类型表ma_type(MaType)表服务接口 + * + * @author makejava + * @since 2024-08-13 10:14:27 + */ +public interface MaTypeService { + + /** + * 分页查询 + * + * @param maType 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + Page queryByPage(MaType maType, PageRequest pageRequest); + + /** + * 新增数据 + * + * @param maType 实例对象 + * @return 实例对象 + */ + AjaxResult insert(MaType maType); + + /** + * 修改数据 + * + * @param maType 实例对象 + * @return 实例对象 + */ + AjaxResult update(MaType maType); + + /** + * 根据类型名称查询类型树 + * @param typeName + * @return + */ + List getMaTypeList(String typeName); +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java new file mode 100644 index 0000000..c95ec31 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java @@ -0,0 +1,166 @@ +package com.bonus.material.service.impl; + +import com.bonus.base.api.domain.MaType; +import com.bonus.base.api.domain.TreeSelect; +import com.bonus.common.core.utils.StringUtils; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.mapper.MaTypeMapper; +import com.bonus.material.service.MaTypeService; +import org.springframework.stereotype.Service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 机具类型表ma_type(MaType)表服务实现类 + * + * @author makejava + * @since 2024-08-13 10:14:28 + */ +@Service("maTypeService") +public class MaTypeServiceImpl implements MaTypeService { + @Resource + private MaTypeMapper maTypeDao; + + /** + * 分页查询 + * + * @param maType 筛选条件 + * @param pageRequest 分页对象 + * @return 查询结果 + */ + @Override + public Page queryByPage(MaType maType, PageRequest pageRequest) { + long total = this.maTypeDao.count(maType); + return new PageImpl<>(this.maTypeDao.queryAllByLimit(maType, pageRequest), pageRequest, total); + } + + /** + * 新增数据 + * + * @param maType 实例对象 + * @return 实例对象 + */ + @Override + public AjaxResult insert(MaType maType) { + //根据类型名称判断,去重 + MaType type = maTypeDao.queryByName(maType.getName()); + if (type!=null){ + return AjaxResult.error("类型名称重复"); + } + int result = maTypeDao.insert(maType); + if (result > 0) { + return AjaxResult.success("添加成功"); + } + return AjaxResult.error("添加失败"); + } + + /** + * 修改数据 + * + * @param maType 实例对象 + * @return 实例对象 + */ + @Override + public AjaxResult update(MaType maType) { + //根据类型名称判断,去重 + MaType type = maTypeDao.queryByName(maType.getName()); + if (type != null) { + return AjaxResult.error("类型名称重复"); + } + int result = maTypeDao.update(maType); + if (result > 0) { + return AjaxResult.success("修改成功"); + } + return AjaxResult.error("修改失败"); + } + + /** + * 根据类型名称查询类型树 + * @param typeName + * @return + */ + @Override + public List getMaTypeList(String typeName) { + List maTypes = maTypeDao.selectMaTypeTree(typeName); + List treeSelectList = buildDeptTreeSelect(maTypes); + //如果没有查询到那么返回空 + return treeSelectList; + } + + /** + * 构建前端所需要下拉树结构 + * + * @param depts 部门列表 + * @return 下拉树结构列表 + */ + public List buildDeptTreeSelect(List depts) { + List deptTrees = buildDeptTree(depts); + return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + /** + * 构建前端所需要树结构 + * + * @param maTypeList 部门列表 + * @return 树结构列表 + */ + public List buildDeptTree(List maTypeList) { + List returnList = new ArrayList(); + List tempList = maTypeList.stream().map(MaType::getId).collect(Collectors.toList()); + for (MaType maType : maTypeList) { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(maType.getParentId())) { + recursionFn(maTypeList, maType); + returnList.add(maType); + } + } + if (returnList.isEmpty()) { + returnList = maTypeList; + } + return returnList; + } + + /** + * 递归列表 + */ + private void recursionFn(List list, MaType t) { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (MaType tChild : childList) { + if (hasChild(list, tChild)) { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, MaType t) { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) { + MaType n = (MaType) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, MaType t) { + return getChildList(list, t).size() > 0 ? true : false; + } + +} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml new file mode 100644 index 0000000..a17c296 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + update ma_type + + + parent_id = #{parentId}, + + + name = #{name}, + + + level = #{level}, + + + storage_num = #{storageNum}, + + + unit_id = #{unitId}, + + + buy_price = #{buyPrice}, + + + lease_price = #{leasePrice}, + + + manage_type = #{manageType}, + + + is_active = #{isActive}, + + + rate_load = #{rateLoad}, + + + test_load = #{testLoad}, + + + hold_time = #{holdTime}, + + + file_url = #{fileUrl}, + + + company_id = #{companyId}, + + where id = #{id} + + + + + + + + + + + + + + insert into ma_type(id, parent_id, name, level, storage_num, unit_id, buy_price, lease_price, manage_type, is_active, rate_load, test_load, hold_time, file_url, company_id) + values + + (#{entity.id}, #{entity.parentId}, #{entity.name}, #{entity.level}, #{entity.storageNum}, #{entity.unitId}, #{entity.buyPrice}, #{entity.leasePrice}, #{entity.manageType}, #{entity.isActive}, #{entity.rateLoad}, #{entity.testLoad}, #{entity.holdTime}, #{entity.fileUrl}, #{entity.companyId}) + + + + + insert into ma_type(id, parent_id, name, level, storage_num, unit_id, buy_price, lease_price, manage_type, is_active, rate_load, test_load, hold_time, file_url, company_id) + values + + (#{entity.id}, #{entity.parentId}, #{entity.name}, #{entity.level}, #{entity.storageNum}, #{entity.unitId}, #{entity.buyPrice}, #{entity.leasePrice}, #{entity.manageType}, #{entity.isActive}, #{entity.rateLoad}, #{entity.testLoad}, #{entity.holdTime}, #{entity.fileUrl}, #{entity.companyId}) + + on duplicate key update + id = values(id), + parent_id = values(parent_id), + name = values(name), + level = values(level), + storage_num = values(storage_num), + unit_id = values(unit_id), + buy_price = values(buy_price), + lease_price = values(lease_price), + manage_type = values(manage_type), + is_active = values(is_active), + rate_load = values(rate_load), + test_load = values(test_load), + hold_time = values(hold_time), + file_url = values(file_url), + company_id = values(company_id) + + + INSERT INTO ma_type + + id, + parent_id, + name, + level, + storage_num, + unit_id, + buy_price, + lease_price, + manage_type, + is_active, + rate_load, + test_load, + hold_time, + file_url, + company_id, + + VALUES + + #{id}, + #{parentId}, + #{name}, + #{level}, + #{storageNum}, + #{unitId}, + #{buyPrice}, + #{leasePrice}, + #{manageType}, + 1, + #{rateLoad}, + #{testLoad}, + #{holdTime}, + #{fileUrl}, + #{companyId}, + + + + +