物资模块

This commit is contained in:
mashuai 2024-08-13 13:51:21 +08:00
parent 7da1292da8
commit b53f63403f
7 changed files with 820 additions and 0 deletions

View File

@ -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<MaType> children = new ArrayList<>();
}

View File

@ -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<TreeSelect> 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<TreeSelect> getChildren()
{
return children;
}
public void setChildren(List<TreeSelect> children)
{
this.children = children;
}
}

View File

@ -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<TreeSelect> 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);
}
}

View File

@ -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<MaType> 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<MaType> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<MaType> entities);
/**
* 批量新增或按主键更新数据MyBatis原生foreach方法
*
* @param entities List<MaType> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<MaType> entities);
/**
* 修改数据
*
* @param maType 实例对象
* @return 影响行数
*/
int update(MaType maType);
/**
* 根据名称查询
* @param name
* @return
*/
MaType queryByName(String name);
/**
* 根据名称查询
* @param typeName
* @return
*/
List<MaType> selectMaTypeTree(String typeName);
}

View File

@ -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<MaType> queryByPage(MaType maType, PageRequest pageRequest);
/**
* 新增数据
*
* @param maType 实例对象
* @return 实例对象
*/
AjaxResult insert(MaType maType);
/**
* 修改数据
*
* @param maType 实例对象
* @return 实例对象
*/
AjaxResult update(MaType maType);
/**
* 根据类型名称查询类型树
* @param typeName
* @return
*/
List<TreeSelect> getMaTypeList(String typeName);
}

View File

@ -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<MaType> 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<TreeSelect> getMaTypeList(String typeName) {
List<MaType> maTypes = maTypeDao.selectMaTypeTree(typeName);
List<TreeSelect> treeSelectList = buildDeptTreeSelect(maTypes);
//如果没有查询到那么返回空
return treeSelectList;
}
/**
* 构建前端所需要下拉树结构
*
* @param depts 部门列表
* @return 下拉树结构列表
*/
public List<TreeSelect> buildDeptTreeSelect(List<MaType> depts) {
List<MaType> deptTrees = buildDeptTree(depts);
return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
}
/**
* 构建前端所需要树结构
*
* @param maTypeList 部门列表
* @return 树结构列表
*/
public List<MaType> buildDeptTree(List<MaType> maTypeList) {
List<MaType> returnList = new ArrayList<MaType>();
List<Integer> 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<MaType> list, MaType t) {
// 得到子节点列表
List<MaType> childList = getChildList(list, t);
t.setChildren(childList);
for (MaType tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<MaType> getChildList(List<MaType> list, MaType t) {
List<MaType> tlist = new ArrayList<MaType>();
Iterator<MaType> 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<MaType> list, MaType t) {
return getChildList(list, t).size() > 0 ? true : false;
}
}

View File

@ -0,0 +1,264 @@
<?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.mapper.MaTypeMapper">
<resultMap type="com.bonus.base.api.domain.MaType" id="MaTypeMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="parentId" column="parent_id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="level" column="level" jdbcType="VARCHAR"/>
<result property="storageNum" column="storage_num" jdbcType="VARCHAR"/>
<result property="unitId" column="unit_id" jdbcType="VARCHAR"/>
<result property="buyPrice" column="buy_price" jdbcType="VARCHAR"/>
<result property="leasePrice" column="lease_price" jdbcType="VARCHAR"/>
<result property="manageType" column="manage_type" jdbcType="VARCHAR"/>
<result property="isActive" column="is_active" jdbcType="VARCHAR"/>
<result property="rateLoad" column="rate_load" jdbcType="VARCHAR"/>
<result property="testLoad" column="test_load" jdbcType="VARCHAR"/>
<result property="holdTime" column="hold_time" jdbcType="VARCHAR"/>
<result property="fileUrl" column="file_url" jdbcType="VARCHAR"/>
<result property="companyId" column="company_id" jdbcType="VARCHAR"/>
</resultMap>
<update id="update">
update ma_type
<set>
<if test="parentId != null">
parent_id = #{parentId},
</if>
<if test="name != null and name != ''">
name = #{name},
</if>
<if test="level != null and level != ''">
level = #{level},
</if>
<if test="storageNum != null">
storage_num = #{storageNum},
</if>
<if test="unitId != null">
unit_id = #{unitId},
</if>
<if test="buyPrice != null">
buy_price = #{buyPrice},
</if>
<if test="leasePrice != null">
lease_price = #{leasePrice},
</if>
<if test="manageType != null">
manage_type = #{manageType},
</if>
<if test="isActive != null">
is_active = #{isActive},
</if>
<if test="rateLoad != null">
rate_load = #{rateLoad},
</if>
<if test="testLoad != null">
test_load = #{testLoad},
</if>
<if test="holdTime != null">
hold_time = #{holdTime},
</if>
<if test="fileUrl != null">
file_url = #{fileUrl},
</if>
<if test="companyId != null">
company_id = #{companyId},
</if>
where id = #{id}
</set>
</update>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="MaTypeMap">
select
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
from ma_type
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="parentId != null">
and parent_id = #{parentId}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="level != null and level != ''">
and level = #{level}
</if>
<if test="storageNum != null and storageNum != ''">
and storage_num = #{storageNum}
</if>
<if test="unitId != null and unitId != ''">
and unit_id = #{unitId}
</if>
<if test="buyPrice != null and buyPrice != ''">
and buy_price = #{buyPrice}
</if>
<if test="leasePrice != null and leasePrice != ''">
and lease_price = #{leasePrice}
</if>
<if test="manageType != null and manageType != ''">
and manage_type = #{manageType}
</if>
<if test="isActive != null and isActive != ''">
and is_active = #{isActive}
</if>
<if test="rateLoad != null and rateLoad != ''">
and rate_load = #{rateLoad}
</if>
<if test="testLoad != null and testLoad != ''">
and test_load = #{testLoad}
</if>
<if test="holdTime != null and holdTime != ''">
and hold_time = #{holdTime}
</if>
<if test="fileUrl != null and fileUrl != ''">
and file_url = #{fileUrl}
</if>
<if test="companyId != null and companyId != ''">
and company_id = #{companyId}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from ma_type
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="parentId != null">
and parent_id = #{parentId}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="level != null and level != ''">
and level = #{level}
</if>
<if test="storageNum != null and storageNum != ''">
and storage_num = #{storageNum}
</if>
<if test="unitId != null and unitId != ''">
and unit_id = #{unitId}
</if>
<if test="buyPrice != null and buyPrice != ''">
and buy_price = #{buyPrice}
</if>
<if test="leasePrice != null and leasePrice != ''">
and lease_price = #{leasePrice}
</if>
<if test="manageType != null and manageType != ''">
and manage_type = #{manageType}
</if>
<if test="isActive != null and isActive != ''">
and is_active = #{isActive}
</if>
<if test="rateLoad != null and rateLoad != ''">
and rate_load = #{rateLoad}
</if>
<if test="testLoad != null and testLoad != ''">
and test_load = #{testLoad}
</if>
<if test="holdTime != null and holdTime != ''">
and hold_time = #{holdTime}
</if>
<if test="fileUrl != null and fileUrl != ''">
and file_url = #{fileUrl}
</if>
<if test="companyId != null and companyId != ''">
and company_id = #{companyId}
</if>
</where>
</select>
<select id="queryByName" resultType="com.bonus.base.api.domain.MaType">
select
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
from ma_type
where name = #{name}
</select>
<select id="selectMaTypeTree" resultType="com.bonus.base.api.domain.MaType">
select
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
from ma_type
where level != 5 and is_active = '1'
</select>
<insert id="insertBatch" keyProperty="" useGeneratedKeys="true">
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
<foreach collection="entities" item="entity" separator=",">
(#{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})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="" useGeneratedKeys="true">
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
<foreach collection="entities" item="entity" separator=",">
(#{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})
</foreach>
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>
<insert id="insert">
INSERT INTO ma_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">id,</if>
<if test="parentId != null and parentId != ''">parent_id,</if>
<if test="name != null and name != ''">name,</if>
<if test="level != null and level != ''">level,</if>
<if test="storageNum != null and storageNum != ''">storage_num,</if>
<if test="unitId != null and unitId != ''">unit_id,</if>
<if test="buyPrice != null and buyPrice != ''">buy_price,</if>
<if test="leasePrice != null and leasePrice != ''">lease_price,</if>
<if test="manageType != null and manageType != ''">manage_type,</if>
<if test="isActive != null and isActive != ''">is_active,</if>
<if test="rateLoad != null and rateLoad != ''">rate_load,</if>
<if test="testLoad != null and testLoad != ''">test_load,</if>
<if test="holdTime != null and holdTime != ''">hold_time,</if>
<if test="fileUrl != null and fileUrl != ''">file_url,</if>
<if test="companyId != null and companyId != ''">company_id,</if>
</trim>
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">#{id},</if>
<if test="parentId != null and parentId != ''">#{parentId},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="level != null and level != ''">#{level},</if>
<if test="storageNum != null and storageNum != ''">#{storageNum},</if>
<if test="unitId != null and unitId != ''">#{unitId},</if>
<if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
<if test="leasePrice != null and leasePrice != ''">#{leasePrice},</if>
<if test="manageType != null and manageType != ''">#{manageType},</if>
1,
<if test="rateLoad != null and rateLoad != ''">#{rateLoad},</if>
<if test="testLoad != null and testLoad != ''">#{testLoad},</if>
<if test="holdTime != null and holdTime != ''">#{holdTime},</if>
<if test="fileUrl != null and fileUrl != ''">#{fileUrl},</if>
<if test="companyId != null and companyId != ''">#{companyId},</if>
</trim>
</insert>
</mapper>