diff --git a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java index 775d63e0..40085b4e 100644 --- a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java +++ b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java @@ -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)); diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/TreeBuild.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/TreeBuild.java new file mode 100644 index 00000000..8b1f0744 --- /dev/null +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/TreeBuild.java @@ -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 nodeList = new ArrayList<>(); + + /** + * 构造方法 + * @param nodeList 将数据集合赋值给nodeList,即所有数据作为所有节点。 + */ + public TreeBuild(List nodeList){ + this.nodeList = nodeList; + } + + /** + * 获取需构建的所有根节点(顶级节点) "0" + * @return 所有根节点List集合 + */ + public List getRootNode(){ + // 保存所有根节点(所有根节点的数据) + List rootNodeList = new ArrayList<>(); + // treeNode:查询出的每一条数据(节点) + for (TreeNode treeNode : nodeList){ + // 判断当前节点是否为根节点,此处注意:若parentId类型是String,则要采用equals()方法判断。 + if (0 == treeNode.getParentId()) { + // 是,添加 + rootNodeList.add(treeNode); + } + } + return rootNodeList; + } + + /** + * 根据每一个顶级节点(根节点)进行构建树形结构 + * @return 构建整棵树 + */ + public List buildTree(){ + // treeNodes:保存一个顶级节点所构建出来的完整树形 + List treeNodes = new ArrayList(); + // getRootNode():获取所有的根节点 + for (TreeNode treeRootNode : getRootNode()) { + // 将顶级节点进行构建子树 + treeRootNode = buildChildTree(treeRootNode); + // 完成一个顶级节点所构建的树形,增加进来 + treeNodes.add(treeRootNode); + } + return treeNodes; + } + + /** + * 递归-----构建子树形结构 + * @param pNode 根节点(顶级节点) + * @return 整棵树 + */ + public TreeNode buildChildTree(TreeNode pNode){ + List childTree = new ArrayList(); + // nodeList:所有节点集合(所有数据) + for (TreeNode treeNode : nodeList) { + // 判断当前节点的父节点ID是否等于根节点的ID,即当前节点为其下的子节点 + if (treeNode.getParentId() == pNode.getId()) { + // 再递归进行判断当前节点的情况,调用自身方法 + childTree.add(buildChildTree(treeNode)); + } + } + // for循环结束,即节点下没有任何节点,树形构建结束,设置树结果 + pNode.setChildren(childTree); + return pNode; + } + +} + diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/TreeNode.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/TreeNode.java new file mode 100644 index 00000000..92c0660c --- /dev/null +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/TreeNode.java @@ -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 children = new ArrayList<>(); + + @ApiModelProperty("机具类型(1机具,2安全工器具)") + private int jiJuType; + + private int unitValue; +} diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java index ff7d61a1..1ee1fd20 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/controller/MaPartTypeController.java @@ -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 parentIds = maPartTypeService.selectParentId(partType); + if (CollectionUtils.isEmpty(parentIds)) { + return AjaxResult.success(new ArrayList<>()); + } + List 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 list = maPartTypeService.getList(partType); + ExcelUtil 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 list = maPartTypeService.selectMyPartTypeList(maPartType); - ExcelUtil util = new ExcelUtil(MaPartType.class); - util.exportExcel(response, list, "配件类型管理数据"); + public void export(HttpServletResponse response, MaPartType partType) { + List parentIds = maPartTypeService.selectParentId(partType); + ExcelUtil util = new ExcelUtil<>(MaPartType.class); + if (CollectionUtils.isEmpty(parentIds)) { + util.exportExcel(response, null, "配件类型管理数据"); + } + List 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); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java index 5ef555a1..72718a01 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/MaPartType.java @@ -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; + } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/MaPartTypeVo.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/MaPartTypeVo.java index ab5dce2f..c899362b 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/MaPartTypeVo.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/domain/vo/MaPartTypeVo.java @@ -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; /** diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/MaPartTypeMapper.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/MaPartTypeMapper.java index c19c68fd..123e4454 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/MaPartTypeMapper.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/mapper/MaPartTypeMapper.java @@ -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 getList(MaPartType maPartType); + + /** + * 配件类型所属上级树 + * @param dto + * @return + */ + List getPartTree(MaPartType dto); + + /** + * 根据左列表类型id查询右表格 + * @param partType + * @return + */ + List selectParentId(MaPartType partType); + + /** + * 根据左列表类型id查询右表格 + * @param id + * @param type + * @return + */ + List getListByParentId(@Param("paId") Long id, @Param("type") MaPartType type); + + /** + * 查询配件名称 + * @param maPartType + * @return + */ + MaPartType selectByName(MaPartType maPartType); + + /** + * 根据id查询配件列表 + * @param id + * @return + */ + int selectById(Long id); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java index 150e7778..767044c9 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/IPartTypeService.java @@ -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 getList(MaPartType maPartType); + + /** + * 配件类型所属上级树 + * @param dto + * @return + */ + AjaxResult getPartTree(MaPartType dto); + + /** + * 根据左列表类型id查询右表格 + * @param partType + * @return + */ + List selectParentId(MaPartType partType); + + /** + * 根据左列表类型id查询右表格 + * @param id + * @param type + * @return + */ + List getListByParentId(Long id, MaPartType type); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java index 8b475a40..a5c5e65a 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/base/service/impl/MaPartTypeServiceImpl.java @@ -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 getList(MaPartType maPartType) { return maPartTypeMapper.getList(maPartType); } + + /** + * 配件类型所属上级树 + * @param dto + * @return + */ + @Override + public AjaxResult getPartTree(MaPartType dto) { + List groupList = new ArrayList<>(); + List 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 selectParentId(MaPartType partType) { + return maPartTypeMapper.selectParentId(partType); + } + + /** + * 根据左列表类型id查询右表格 + * @param id + * @param type + * @return + */ + @Override + public List getListByParentId(Long id, MaPartType type) { + return maPartTypeMapper.getListByParentId(id, type); + } } diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml index 955c92e4..0679af64 100644 --- a/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/base/MaPartTypeMapper.xml @@ -4,11 +4,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + - + @@ -23,19 +23,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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 - + insert into ma_part_type( - pa_id, pa_name, - parent_id, + parent_id, status, num, - unit_id, + unit_name, buy_price, level, warn_num, @@ -44,12 +43,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" company_id, create_time )values( - #{paId}, #{paName}, - #{parentId}, + #{parentId}, #{status}, #{num}, - #{unitId}, + #{unitName}, #{buyPrice}, #{level}, #{warnNum}, @@ -59,17 +57,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sysdate() ) + 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} + + pa_name = #{paName}, + parent_id = #{parentId}, + status = #{status}, + num = #{num}, + unit_name = #{unitName}, + buy_price = #{buyPrice}, + level = #{level}, + warn_num = #{warnNum}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + company_id = #{companyId}, + + where pa_id = #{id} @@ -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 + + + + + + + + + + + \ No newline at end of file