This commit is contained in:
mashuai 2026-01-14 15:24:19 +08:00
parent f87b1bc314
commit df611f681b
10 changed files with 549 additions and 82 deletions

View File

@ -84,6 +84,12 @@ public class SysPasswordService {
return SecurityUtils.matchesPassword(rawPassword, user.getPassword());
}
public static void main(String[] args) {
System.out.println(SecurityUtils.encryptPassword("NxCc@2024*Bns!"));
System.out.println(SecurityUtils.matchesPassword("NxCc@2024*Bns!", "$2a$10$kPdpRcLif0NpVabK6WEgZOiBzR8LN.sChQYWBuxL5bdVLb0LXIHU2"));
}
public void clearLoginRecordCache(String loginName) {
if (redisService.hasKey(getCacheKey(loginName))) {
redisService.deleteObject(getCacheKey(loginName));

View File

@ -0,0 +1,78 @@
package com.bonus.sgzb.common.core.domain;
import java.util.ArrayList;
import java.util.List;
/**
* @Author ma_sh
* @create 2026/1/13 13:48
*/
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;
}
}

View File

@ -0,0 +1,57 @@
package com.bonus.sgzb.common.core.domain;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
/**
* @Author ma_sh
* @create 2026/1/13 13:46
*/
@Data
public class TreeNode {
private long id;
private String label;
private long parentId;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String level;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String unitName;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String companyId;
private String code;
/** 原值 */
@ApiModelProperty(value = "原值")
private BigDecimal buyPrice;
/** 实时库存 */
@ApiModelProperty(value = "实时库存")
private Long storageNum;
private Long num;
private String remark;
@ApiModelProperty(value = "类型")
private String manageType;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeNode> children = new ArrayList<>();
@ApiModelProperty("机具类型1机具2安全工器具")
private int jiJuType;
private int unitValue;
}

View File

@ -1,23 +1,24 @@
package com.bonus.sgzb.base.controller;
import cn.hutool.core.convert.Convert;
import com.bonus.sgzb.base.domain.MaPartType;
import com.bonus.sgzb.base.domain.vo.MaPartTypeVo;
import com.bonus.sgzb.base.service.IPartTypeService;
import com.bonus.sgzb.common.core.utils.ListPagingUtil;
import com.bonus.sgzb.common.core.utils.ServletUtils;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
;
/**
* 配件类型管理ma_part_type(MaPartType)表控制层
*
@ -45,6 +46,39 @@ public class MaPartTypeController extends BaseController {
return AjaxResult.success(list);
}
/**
* 配件类型所属上级树
* @param dto
* @return
*/
@ApiOperation(value = "配件类型所属上级树")
@GetMapping("/getPartTree")
public AjaxResult getPartTree(MaPartType dto) {
return maPartTypeService.getPartTree(dto);
}
/**
* 根据左列表类型id查询右表格
*
* @param partType
* @return
*/
@ApiOperation(value = "根据左列表类型id查询右表格")
@GetMapping("/getListByPartType")
public AjaxResult getListByPartType(MaPartType partType) {
List<Integer> parentIds = maPartTypeService.selectParentId(partType);
if (CollectionUtils.isEmpty(parentIds)) {
return AjaxResult.success(new ArrayList<>());
}
List<MaPartType> maTypeVos = new ArrayList<>();
Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
for (Integer parentId : parentIds) {
maTypeVos.addAll(maPartTypeService.getListByParentId(parentId.longValue(), partType));
}
return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, maTypeVos));
}
/**
* 查询配件类型列表
* @param maPartType
@ -58,55 +92,67 @@ public class MaPartTypeController extends BaseController {
return AjaxResult.success(getDataTable(list));
}
/**
* 导出配件类型管理列表
* @param response
* @param partType
*/
@ApiOperation(value = "导出配件类型库存管理列表")
@PostMapping("/exportList")
public void exportList(HttpServletResponse response, MaPartType partType) {
List<MaPartTypeVo> list = maPartTypeService.getList(partType);
ExcelUtil<MaPartTypeVo> util = new ExcelUtil<>(MaPartTypeVo.class);
util.exportExcel(response, list, "配件类型管理数据");
}
/**
* 新增配件管理
* @param maPartType
* @return
*/
@PostMapping
public AjaxResult add(@Validated @RequestBody MaPartType maPartType){
if (!maPartTypeService.checkPaNameUnique(maPartType)) {
return error("新增配件名称'" + maPartType.getPaName() + "'失败,配件名称已存在");
}
maPartType.setCreateBy(SecurityUtils.getUsername());
return toAjax(maPartTypeService.insertMaPart(maPartType));
public AjaxResult add(@Validated @RequestBody MaPartType maPartType) {
return maPartTypeService.insertMaPart(maPartType);
}
/**
* 导出配件类型管理
* @param response
* @param maPartType
* @param partType
*/
@ApiOperation(value = "导出配件类型管理列表")
@PostMapping("/export")
public void export(HttpServletResponse response, MaPartType maPartType)
{
List<MaPartType> list = maPartTypeService.selectMyPartTypeList(maPartType);
ExcelUtil<MaPartType> util = new ExcelUtil<MaPartType>(MaPartType.class);
util.exportExcel(response, list, "配件类型管理数据");
public void export(HttpServletResponse response, MaPartType partType) {
List<Integer> parentIds = maPartTypeService.selectParentId(partType);
ExcelUtil<MaPartType> util = new ExcelUtil<>(MaPartType.class);
if (CollectionUtils.isEmpty(parentIds)) {
util.exportExcel(response, null, "配件类型管理数据");
}
List<MaPartType> maTypeVos = new ArrayList<>();
for (Integer parentId : parentIds) {
maTypeVos.addAll(maPartTypeService.getListByParentId(parentId.longValue(), partType));
}
util.exportExcel(response, maTypeVos, "配件类型管理数据");
}
/**
* 删除配件管理类型
* @param paId
* @param id
* @return
*/
@DeleteMapping("/{paId}")
public AjaxResult delete(@PathVariable("paId") Long paId){
if (maPartTypeService.hasChildBypaId(paId))
{
return warn("存在下级仓库列表,不允许删除");
}
return toAjax(maPartTypeService.deletePaById(paId));
@DeleteMapping("/{id}")
public AjaxResult delete(@PathVariable("id") Long id) {
return maPartTypeService.deletePaById(id);
}
/**
* 根据id获取数据
* @param paId
* @param id
* @return
*/
@GetMapping("/{paId}")
public AjaxResult getById(@PathVariable("paId") Long paId){
MaPartType bean = maPartTypeService.getById(paId);
@GetMapping("/{id}")
public AjaxResult getById(@PathVariable("id") Long id) {
MaPartType bean = maPartTypeService.getById(id);
return AjaxResult.success(bean);
}
@ -116,9 +162,8 @@ public class MaPartTypeController extends BaseController {
* @return
*/
@PostMapping("/updateById")
public AjaxResult updateById(@RequestBody MaPartType maPartType){
maPartType.setUpdateBy(SecurityUtils.getUsername());
return toAjax(maPartTypeService.updateById(maPartType));
public AjaxResult updateById(@RequestBody MaPartType maPartType) {
return maPartTypeService.updateById(maPartType);
}

View File

@ -2,6 +2,7 @@ package com.bonus.sgzb.base.domain;
import com.bonus.sgzb.common.core.annotation.Excel;
import com.bonus.sgzb.common.core.web.domain.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Size;
@ -21,13 +22,19 @@ public class MaPartType extends BaseEntity {
//类型ID
@Excel(name = "类型ID")
private Long paId;
private Long id;
//类型名称
@Excel(name = "类型名称")
@Size(max = 30, message = "类型名称长度不能超过30")
private String paName;
@ApiModelProperty("配件名称")
private String partName;
@ApiModelProperty("配件类型")
private String partType;
//上级ID
@Excel(name = "上级ID")
private Long parentId;
@ -44,6 +51,9 @@ public class MaPartType extends BaseEntity {
@Excel(name = "计量单位ID")
private String unitId;
@Excel(name = "计量单位")
private String unitName;
//原值
@Excel(name = "原值")
private String buyPrice;
@ -84,6 +94,9 @@ public class MaPartType extends BaseEntity {
@Excel(name = "数据所属组织")
private String companyId;
@ApiModelProperty("关键字")
private String keyWord;
}

View File

@ -14,7 +14,7 @@ import java.util.Date;
*/
@SuppressWarnings("serial")
@Data
public class MaPartTypeVo extends BaseEntity {
public class MaPartTypeVo {
private static final long serialVersionUID = 1L;
@ -39,18 +39,18 @@ public class MaPartTypeVo extends BaseEntity {
@Excel(name = "配件名称")
private String paName;
@Excel(name = "配件规格")
@Excel(name = "规格型号")
private String paSpec;
private Long parentId;
@Excel(name = "实时库存")
private String num;
@Excel(name = "计量单位")
private String unitName;
@Excel(name = "购置价格")
@Excel(name = "数量")
private String num;
//@Excel(name = "购置价格")
private String buyPrice;
/**
@ -86,6 +86,7 @@ public class MaPartTypeVo extends BaseEntity {
/**
* 备注
*/
@Excel(name = "备注")
private String remark;
/**

View File

@ -2,7 +2,9 @@ package com.bonus.sgzb.base.mapper;
import com.bonus.sgzb.base.domain.MaPartType;
import com.bonus.sgzb.base.domain.vo.MaPartTypeVo;
import com.bonus.sgzb.common.core.domain.TreeNode;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -50,7 +52,12 @@ public interface MaPartTypeMapper {
*/
int deletePaById(Long paId);
MaPartType getById(Long paId);
/**
* 根据id获取数据
* @param id
* @return
*/
MaPartType getById(Long id);
int updateById(MaPartType maPartType);
@ -60,5 +67,41 @@ public interface MaPartTypeMapper {
* @return
*/
List<MaPartTypeVo> getList(MaPartType maPartType);
/**
* 配件类型所属上级树
* @param dto
* @return
*/
List<TreeNode> getPartTree(MaPartType dto);
/**
* 根据左列表类型id查询右表格
* @param partType
* @return
*/
List<Integer> selectParentId(MaPartType partType);
/**
* 根据左列表类型id查询右表格
* @param id
* @param type
* @return
*/
List<MaPartType> getListByParentId(@Param("paId") Long id, @Param("type") MaPartType type);
/**
* 查询配件名称
* @param maPartType
* @return
*/
MaPartType selectByName(MaPartType maPartType);
/**
* 根据id查询配件列表
* @param id
* @return
*/
int selectById(Long id);
}

View File

@ -3,7 +3,9 @@ package com.bonus.sgzb.base.service;
import com.bonus.sgzb.base.domain.MaPartType;
import com.bonus.sgzb.base.domain.vo.MaPartTypeVo;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import java.util.Collection;
import java.util.List;
/**
@ -26,7 +28,7 @@ public interface IPartTypeService {
* @param maPartType
* @return
*/
int insertMaPart(MaPartType maPartType);
AjaxResult insertMaPart(MaPartType maPartType);
/**
* 查询配件类型列表
@ -54,11 +56,16 @@ public interface IPartTypeService {
* @param paId
* @return
*/
int deletePaById(Long paId);
AjaxResult deletePaById(Long paId);
MaPartType getById(Long paId);
/**
* 根据id获取数据
* @param id
* @return
*/
MaPartType getById(Long id);
int updateById(MaPartType maPartType);
AjaxResult updateById(MaPartType maPartType);
/**
* 查询配件类型列表
@ -66,6 +73,28 @@ public interface IPartTypeService {
* @return
*/
List<MaPartTypeVo> getList(MaPartType maPartType);
/**
* 配件类型所属上级树
* @param dto
* @return
*/
AjaxResult getPartTree(MaPartType dto);
/**
* 根据左列表类型id查询右表格
* @param partType
* @return
*/
List<Integer> selectParentId(MaPartType partType);
/**
* 根据左列表类型id查询右表格
* @param id
* @param type
* @return
*/
List<MaPartType> getListByParentId(Long id, MaPartType type);
}

View File

@ -5,11 +5,21 @@ import com.bonus.sgzb.base.domain.vo.MaPartTypeVo;
import com.bonus.sgzb.base.mapper.MaPartTypeMapper;
import com.bonus.sgzb.base.service.IPartTypeService;
import com.bonus.sgzb.common.core.constant.UserConstants;
import com.bonus.sgzb.common.core.domain.TreeBuild;
import com.bonus.sgzb.common.core.domain.TreeNode;
import com.bonus.sgzb.common.core.enums.HttpCodeEnum;
import com.bonus.sgzb.common.core.utils.DateUtils;
import com.bonus.sgzb.common.core.utils.StringUtils;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 配件类型管理ma_part_type(MaPartType)表服务实现类
@ -18,6 +28,7 @@ import java.util.List;
* @since 2023-11-27 16:44:20
*/
@Service("maPartTypeService")
@Slf4j
public class MaPartTypeServiceImpl implements IPartTypeService {
@Autowired
@ -29,9 +40,9 @@ public class MaPartTypeServiceImpl implements IPartTypeService {
*/
@Override
public boolean checkPaNameUnique(MaPartType maPartType) {
Long paId = StringUtils.isNull(maPartType.getPaId()) ? -1L : maPartType.getPaId();
MaPartType info = maPartTypeMapper.checkPartNameUnique(maPartType.getPaId());
if (StringUtils.isNotNull(info) && info.getPaId().longValue() != paId.longValue())
Long paId = StringUtils.isNull(maPartType.getId()) ? -1L : maPartType.getId();
MaPartType info = maPartTypeMapper.checkPartNameUnique(maPartType.getId());
if (StringUtils.isNotNull(info) && info.getId().longValue() != paId.longValue())
{
return UserConstants.NOT_UNIQUE;
}
@ -44,9 +55,24 @@ public class MaPartTypeServiceImpl implements IPartTypeService {
* @return
*/
@Override
public int insertMaPart(MaPartType maPartType) {
return maPartTypeMapper.insertMaPartType(maPartType);
public AjaxResult insertMaPart(MaPartType maPartType) {
if (maPartType == null || maPartType.getPaName() == null) {
return AjaxResult.error("参数不能为空");
}
//新增判重二级和三级不同类型下面可以重复一级不能重复
MaPartType type = maPartTypeMapper.selectByName(maPartType);
if (type != null) {
return AjaxResult.error("配件名称重复,请重新输入");
}
maPartType.setCreateTime(DateUtils.getNowDate());
maPartType.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString());
maPartType.setParentId(maPartType.getId() != 0 ? maPartType.getId() : 0L);
maPartType.setLevel(maPartType.getLevel() != null ? String.valueOf(Integer.parseInt(maPartType.getLevel()) + 1) : "1");
int result = maPartTypeMapper.insertMaPartType(maPartType);
if (result == 0) {
return AjaxResult.success("新增失败");
}
return AjaxResult.success("新增成功");
}
/**
@ -82,22 +108,57 @@ public class MaPartTypeServiceImpl implements IPartTypeService {
/**
* 删除配件类型
* @param paId
* @param id
* @return
*/
@Override
public int deletePaById(Long paId) {
return maPartTypeMapper.deletePaById(paId);
public AjaxResult deletePaById(Long id) {
//判断配件类型下是否有下级配件
int count = maPartTypeMapper.selectById(id);
if (count > 0) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "该类型下有下级配件,不允许删除");
}
/*//判断配件是否在用在用则不能删除
int i = maPartTypeMapper.selectPart(id);
if (i > 0) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "该配件类型处于在用状态,不允许删除");
}*/
int result = maPartTypeMapper.deletePaById(id);
if (result > 0) {
return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result);
}
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg());
}
/**
* 根据id获取数据
* @param id
* @return
*/
@Override
public MaPartType getById(Long id) {
return maPartTypeMapper.getById(id);
}
@Override
public MaPartType getById(Long paId) {
return maPartTypeMapper.getById(paId);
}
@Override
public int updateById(MaPartType maPartType) {
return maPartTypeMapper.updateById(maPartType);
public AjaxResult updateById(MaPartType maPartType) {
if (maPartType == null || maPartType.getPaName() == null || maPartType.getParentId() == null || maPartType.getId() == null) {
return AjaxResult.error("参数不能为空");
}
//修改判重二级和三级不同类型下面可以重复一级不能重复
MaPartType type = maPartTypeMapper.selectByName(maPartType);
if (type != null) {
if (!Objects.equals(type.getId(), maPartType.getId())) {
return AjaxResult.error("配件名称重复,请重新输入");
}
}
maPartType.setUpdateTime(DateUtils.getNowDate());
maPartType.setUpdateBy(SecurityUtils.getLoginUser().getUserid().toString());
int result = maPartTypeMapper.updateById(maPartType);
if (result == 0) {
return AjaxResult.success("修改失败");
}
return AjaxResult.success("修改成功");
}
/**
@ -109,5 +170,49 @@ public class MaPartTypeServiceImpl implements IPartTypeService {
public List<MaPartTypeVo> getList(MaPartType maPartType) {
return maPartTypeMapper.getList(maPartType);
}
/**
* 配件类型所属上级树
* @param dto
* @return
*/
@Override
public AjaxResult getPartTree(MaPartType dto) {
List<TreeNode> groupList = new ArrayList<>();
List<TreeNode> list = new ArrayList<>();
try {
list = maPartTypeMapper.getPartTree(dto);
if (CollectionUtils.isNotEmpty(list)) {
// 创建树形结构数据集合作为参数
TreeBuild treeBuild = new TreeBuild(list);
// 原查询结果转换树形结构
groupList = treeBuild.buildTree();
}
} catch (Exception e) {
log.error("配件所属上级树-查询失败", e);
}
return AjaxResult.success(groupList);
}
/**
* 根据左列表类型id查询右表格
* @param partType
* @return
*/
@Override
public List<Integer> selectParentId(MaPartType partType) {
return maPartTypeMapper.selectParentId(partType);
}
/**
* 根据左列表类型id查询右表格
* @param id
* @param type
* @return
*/
@Override
public List<MaPartType> getListByParentId(Long id, MaPartType type) {
return maPartTypeMapper.getListByParentId(id, type);
}
}

View File

@ -4,11 +4,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.sgzb.base.mapper.MaPartTypeMapper">
<resultMap type="com.bonus.sgzb.base.domain.MaPartType" id="MaPartTypeResult">
<result property="paId" column="pa_id" />
<result property="id" column="pa_id" />
<result property="paName" column="pa_name" />
<result property="parentId" column="parent_id" />
<result property="status" column="status" />
<result property="num" column="num" />
<result property="storageNum" column="num" />
<result property="unitId" column="unit_id" />
<result property="buyPrice" column="buy_price" />
<result property="level" column="level" />
@ -23,19 +23,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectMaPartTypeVo">
select pa_id, pa_name, parent_id, status, num, unit_id, buy_price, level, warn_num, del_flag, create_by, create_time, remark, company_id
select pa_id, pa_name, parent_id, status, num, unit_name, buy_price, level, warn_num, del_flag, create_by, create_time, remark, company_id
from ma_part_type
</sql>
<insert id="insertMaPartType" parameterType="com.bonus.sgzb.base.mapper.MaPartTypeMapper" useGeneratedKeys="true" keyProperty="paId">
<insert id="insertMaPartType" parameterType="com.bonus.sgzb.base.mapper.MaPartTypeMapper" useGeneratedKeys="true" keyProperty="id">
insert into ma_part_type(
<if test="paId != null and paId != 0">pa_id,</if>
<if test="paName != null and paName != ''">pa_name,</if>
<if test="parentId != null and parentId != 0">parent_id,</if>
<if test="parentId != null">parent_id,</if>
<if test="status != null and status != ''">status,</if>
<if test="num != null and num != 0">num,</if>
<if test="unitId != null and unitId != ''">unit_id,</if>
<if test="unitName != null and unitName != ''">unit_name,</if>
<if test="buyPrice != null and buyPrice != 0">buy_price,</if>
<if test="level != null and level != 0">level,</if>
<if test="warnNum != null and warnNum != 0">warn_num,</if>
@ -44,12 +43,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="companyId != null and companyId != ''">company_id,</if>
create_time
)values(
<if test="paId != null and paId != 0">#{paId},</if>
<if test="paName != null and paName != ''">#{paName},</if>
<if test="parentId != null and parentId != 0">#{parentId},</if>
<if test="parentId != null">#{parentId},</if>
<if test="status != null and status != ''">#{status},</if>
<if test="num != null and num != ''">#{num},</if>
<if test="unitId != null and unitId != ''">#{unitId},</if>
<if test="unitName != null and unitName != ''">#{unitName},</if>
<if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
<if test="level != null and level != ''">#{level},</if>
<if test="warnNum != null and warnNum != ''">#{warnNum},</if>
@ -59,17 +57,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sysdate()
)
</insert>
<update id="updateById">
update ma_part_type
set pa_name = #{paName},
num = #{num},
unit_id = #{unitId},
buy_price = #{buyPrice},
update_by = #{updateBy},
update_time = now(),
remark = #{remark},
company_id = #{companyId}
where pa_id = #{paId}
<trim prefix="SET" suffixOverrides=",">
<if test="paName != null and paName != ''">pa_name = #{paName},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="status != null">status = #{status},</if>
<if test="num != null">num = #{num},</if>
<if test="unitName != null and unitName != ''">unit_name = #{unitName},</if>
<if test="buyPrice != null">buy_price = #{buyPrice},</if>
<if test="level != null">level = #{level},</if>
<if test="warnNum != null">warn_num = #{warnNum},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="companyId != null">company_id = #{companyId},</if>
</trim>
where pa_id = #{id}
</update>
<delete id="deletePaById">
@ -94,10 +99,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(1) from ma_part_type
where del_flag = '0' and parent_id = #{paId} limit 1
</select>
<select id="getById" resultType="com.bonus.sgzb.base.domain.MaPartType">
select pa_id, pa_name, parent_id, status, num, unit_id, buy_price, level, warn_num, del_flag, create_by, create_time, remark, company_id
select pa_id AS id,
pa_name AS paName,
parent_id AS parentId,
num AS num,
unit_name AS unitName,
buy_price AS buyPrice,
level AS level,
create_by AS createBy,
create_time AS createTime,
remark AS remark
from ma_part_type
where pa_id = #{paId}
where pa_id = #{id}
</select>
<select id="getList" resultType="com.bonus.sgzb.base.domain.vo.MaPartTypeVo">
@ -111,7 +126,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
mt.num AS num,
mt.LEVEL AS level,
mt.remark AS remark,
mt.unit_id AS unitName,
mt.unit_name AS unitName,
mt.buy_price AS buyPrice
FROM
ma_part_type mt
@ -123,8 +138,83 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="keyWord != null and keyWord != ''">
AND ( mt2.pa_name like concat('%', #{keyWord}, '%') or
mt1.pa_name like concat('%', #{keyWord}, '%') or
mt.pa_name like concat('%', #{keyWord}, '%')
mt.pa_name like concat('%', #{keyWord}, '%') or
mt.remark like concat('%', #{keyWord}, '%')
)
</if>
</select>
<select id="getPartTree" resultType="com.bonus.sgzb.common.core.domain.TreeNode">
SELECT pa_id AS id,
pa_name AS label,
parent_id AS parentId,
level
FROM ma_part_type
WHERE del_flag = '0' and level != '3'
ORDER BY create_time
</select>
<select id="selectParentId" resultType="java.lang.Integer">
SELECT DISTINCT
mt2.pa_id
FROM
ma_part_type mt
LEFT JOIN ma_part_type mt2 ON mt.parent_id = mt2.pa_id
LEFT JOIN ma_part_type mt3 ON mt2.parent_id = mt3.pa_id
<where>
<if test="level == 0">
and mt.level = 3
</if>
<if test="level == 1">
and mt3.pa_id = #{id}
</if>
<if test="level == 2">
and mt2.pa_id = #{id}
</if>
and mt2.pa_id is not null
and mt2.del_flag = '0'
</where>
</select>
<select id="getListByParentId" resultType="com.bonus.sgzb.base.domain.MaPartType">
SELECT DISTINCT
m.pa_id AS id,
m.pa_name AS paName,
m1.pa_name AS partName,
m2.pa_name As partType,
m.parent_id as parentId,
m.unit_name as unitName,
m.num as storageNum,
m.buy_price as buyPrice,
m.LEVEL as level,
m.remark as remark
FROM
ma_part_type m
LEFT JOIN ma_part_type m1 ON m.parent_id = m1.pa_id
and m1.del_flag = '0'
LEFT JOIN ma_part_type m2 ON m1.parent_id = m2.pa_id
and m2.del_flag = '0'
WHERE m.parent_id = #{paId} and m.del_flag = '0'
<if test="type.keyWord != null and type.keyWord !=''">
AND (m.pa_name like concat('%',#{type.keyWord},'%')
or m1.pa_name like concat('%',#{type.keyWord},'%')
or m2.pa_name like concat('%',#{type.keyWord},'%')
)
</if>
</select>
<select id="selectByName" resultType="com.bonus.sgzb.base.domain.MaPartType">
select pa_id as id, pa_name as paName, parent_id as parentId, num as storageNum, unit_name as unitName, buy_price as buyPrice, level as level, remark as remark from ma_part_type
where del_flag = '0'
<if test="paName != null and paName != ''">
AND pa_name = #{paName}
</if>
<if test="parentId != null">
AND parent_id = #{parentId}
</if>
</select>
<select id="selectById" resultType="java.lang.Integer">
select count(*) from ma_part_type where del_flag = '0' and parent_id = #{id}
</select>
</mapper>