diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/config/ListPagingUtil.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/config/ListPagingUtil.java new file mode 100644 index 00000000..69a5bd95 --- /dev/null +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/config/ListPagingUtil.java @@ -0,0 +1,100 @@ +package com.bonus.common.biz.config; + +import java.util.List; + +/** + * 分页索引 + */ +public class ListPagingUtil { + private Integer currentPage;//当前页 + private Integer pageSize;//每页显示记录条数 + private Integer totalPage;//总页数 + private Integer star;//开始数据 + private Integer total;//总条数 + private List rows;//每页显示的数据 + + + public Integer getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(Integer currentPage) { + this.currentPage = currentPage; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getTotalPage() { + return totalPage; + } + + public void setTotalPage(Integer totalPage) { + this.totalPage = totalPage; + } + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } + + public Integer getStar() { + return star; + } + + public void setStar(Integer star) { + this.star = star; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + @Override + public String toString() { + return "ListPagingUtil{" + + "currentPage=" + currentPage + + ", pageSize=" + pageSize + + ", totalPage=" + totalPage + + ", rows=" + rows + + ", star=" + star + + ", total=" + total + + '}'; + } + + public void pageStartInfo(Integer currentPage, Integer pageSize){ + //如果传入的pageNumber为null给pageNumber赋为1 + currentPage = currentPage == null ? 1 : currentPage; + //如果传入的pageSize为null给pageSize赋为10 + pageSize = pageSize == null ? 10 : pageSize; + this.setCurrentPage(currentPage); + this.setPageSize(pageSize); + } + + public static ListPagingUtil paging(Integer currentPage, Integer pageSize, List list) { + ListPagingUtil pagingUtil = new ListPagingUtil(); + //初始化 + pagingUtil.pageStartInfo(currentPage, pageSize); + //设置起始数据 + pagingUtil.setStar((pagingUtil.getCurrentPage()-1)*pagingUtil.getPageSize()); + //设置总数 + pagingUtil.setTotal(list.size()); + //设置总页数 + pagingUtil.setTotalPage(pagingUtil.getTotal() % pagingUtil.getPageSize() == 0 ? pagingUtil.getTotal()/pagingUtil.getPageSize() :pagingUtil.getTotal()/pagingUtil.getPageSize()+1); + //截取list + pagingUtil.setRows(list.subList(pagingUtil.getStar(), pagingUtil.getTotal()-pagingUtil.getStar()>pagingUtil.getPageSize()?pagingUtil.getStar()+pagingUtil.getPageSize():pagingUtil.getTotal())); + return pagingUtil; + } +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmUnitServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmUnitServiceImpl.java index e9059edc..646cbc67 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmUnitServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/basic/service/impl/BmUnitServiceImpl.java @@ -188,6 +188,10 @@ public class BmUnitServiceImpl implements IBmUnitService @Override public AjaxResult deleteBmUnitByUnitId(Long unitId) { + //先查看往来单位是否被绑定,绑定则不能删除 + if (bmUnitMapper.selectBmUnitPersonByUnitId(unitId) > 0) { + return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "该单位还绑定相关人员,无法删除"); + } int result = bmUnitMapper.deleteBmUnitByUnitId(unitId); if (result > 0) { return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java index 26ec40bb..9e32a676 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/TypeController.java @@ -6,7 +6,10 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; +import cn.hutool.core.convert.Convert; +import com.bonus.common.biz.config.ListPagingUtil; import com.bonus.common.biz.domain.TreeSelect; +import com.bonus.common.core.utils.ServletUtils; import com.bonus.common.log.enums.OperaType; import com.bonus.material.common.annotation.PreventRepeatSubmit; import com.bonus.material.ma.MaTypeConfigDto; @@ -50,6 +53,25 @@ public class TypeController extends BaseController { return getDataTable(list); } + /** + * 根据左列表类型id查询右表格 + * + * @param type + * @return + */ + @ApiOperation(value = "根据左列表类型id查询右表格") + @GetMapping("/getListByMaType") + public AjaxResult getListByMaType(MaTypeListVo type) { + List parentIds = typeService.selectParentId(type); + List listByMaType = new ArrayList<>(); + for (Integer parentId : parentIds) { + listByMaType.addAll(typeService.getListByParentId(parentId.longValue(), type)); + } + Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1); + Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10); + return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, listByMaType)); + } + /** * 根据物资仓库ID查询施工类型 */ @@ -152,9 +174,9 @@ public class TypeController extends BaseController { @PreventRepeatSubmit @RequiresPermissions("ma:type:remove") @SysLog(title = "物资类型管理", businessType = OperaType.DELETE, module = "仓储管理->删除物资类型") - @DeleteMapping("/{typeIds}") - public AjaxResult remove(@PathVariable Long[] typeIds) { - return toAjax(typeService.deleteTypeByTypeIds(typeIds)); + @DeleteMapping("/{typeId}") + public AjaxResult remove(@PathVariable Long typeId) { + return typeService.deleteTypeByTypeId(typeId); } /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java index 922d9bdd..f0803aab 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/domain/Type.java @@ -29,7 +29,7 @@ public class Type extends BaseEntity { private Long typeId; /** 类型名称 */ - @Excel(name = "类型名称") + @Excel(name = "规格型号") @ApiModelProperty(value = "类型名称") private String typeName; @@ -132,7 +132,7 @@ public class Type extends BaseEntity { @ApiModelProperty(value = "持荷时间") @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "持荷时间", width = 30, dateFormat = "yyyy-MM-dd") - private Date holdingTime; + private String holdingTime; /** 库存预警数量 */ @Excel(name = "库存预警数量") @@ -160,6 +160,8 @@ public class Type extends BaseEntity { @ApiModelProperty(value = "推送智慧工程定义的门类分类机具编码") private String intelligentCode; + private String keyword; + /** 子节点 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children = new ArrayList<>(); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java index 24004336..4bcb2401 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/TypeMapper.java @@ -27,10 +27,9 @@ public interface TypeMapper { /** * 根据level层级和typeID 查询父级ID - * @param typeId 物资类型主键 - * @param level 类型层级 + * @param type */ - List selectParentId( @Param("typeId")Long typeId, @Param("level")Integer level); + List selectParentId(MaTypeListVo type); /** * 根据物资仓库的ID查询物资类型列表 @@ -38,7 +37,7 @@ public interface TypeMapper { */ List selectMaTypeListByHouseId(Long houseId); - List getListByTypeName(@Param("typeId") Long typeId, @Param("typeName") String typeName); + List getListByTypeName(@Param("typeId") Long typeId, @Param("type") MaTypeListVo type); /** * 查询物资类型下拉树结构--根据上级ID @@ -123,4 +122,13 @@ public interface TypeMapper { * @return 结果 */ int logicDeleteTypeByTypeIds(Long[] typeIds); + + Type queryByName(String typeName); + + /** + * 根据ID查询 + * @param typeId + * @return + */ + List selectById(Long typeId); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java index 799153df..b6893b75 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/ITypeService.java @@ -23,13 +23,13 @@ public interface ITypeService { */ Type selectTypeByTypeId(Long typeId); - List selectParentId(Long typeId, Integer level); + List selectParentId(MaTypeListVo type); List getEquipmentType(Long typeId, String typeName); List selectMaTypeListByHouseId(Long houseId); - List getListByParentId(Long typeId, String typeName); + List getListByParentId(Long typeId, MaTypeListVo type); /** * 查询物资类型下拉树结构--根据上级ID @@ -84,7 +84,7 @@ public interface ITypeService { * @param typeId 物资类型主键 * @return 结果 */ - int deleteTypeByTypeId(Long typeId); + AjaxResult deleteTypeByTypeId(Long typeId); List getMaTypeTree(String typeName, String parentId); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java index e82182b7..a0164353 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/TypeServiceImpl.java @@ -6,9 +6,11 @@ import java.util.stream.Collectors; import cn.hutool.core.util.ArrayUtil; import com.bonus.common.biz.domain.TreeSelect; import com.bonus.common.biz.enums.DataCodeEnum; +import com.bonus.common.biz.enums.HttpCodeEnum; import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.utils.SecurityUtils; import com.bonus.material.ma.MaTypeConfigDto; import com.bonus.material.ma.domain.TypeKeeper; import com.bonus.material.ma.domain.TypeRepair; @@ -19,6 +21,7 @@ import com.bonus.material.ma.vo.MaTypeListVo; import com.bonus.material.ma.vo.MaTypeSelectVo; import com.bonus.material.warehouse.domain.WhHouseSet; import com.bonus.material.warehouse.service.IWhHouseSetService; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import com.bonus.material.ma.mapper.TypeMapper; import com.bonus.material.ma.domain.Type; @@ -61,8 +64,8 @@ public class TypeServiceImpl implements ITypeService { } @Override - public List selectParentId(Long typeId, Integer level) { - return typeMapper.selectParentId(typeId, level); + public List selectParentId(MaTypeListVo type) { + return typeMapper.selectParentId(type); } /** @@ -97,11 +100,11 @@ public class TypeServiceImpl implements ITypeService { * 根据组织树parent_id查询结果 * * @param typeId 父级id - * @param typeName 名称筛选 + * @param type 名称筛选 */ @Override - public List getListByParentId(Long typeId, String typeName) { - return typeMapper.getListByTypeName(typeId, typeName); + public List getListByParentId(Long typeId, MaTypeListVo type) { + return typeMapper.getListByTypeName(typeId, type); } @Override @@ -179,12 +182,12 @@ public class TypeServiceImpl implements ITypeService { switch (maTypeListVo.getLevel()) { case "2": // 二级节点父级是一级节点,所以要拿到父节点名称,并赋值至ONE_LEVEL_NAME字段 - maTypeListVo.setParentOneLevelName(maTypeListVo.getParentThreeLevelName() == null ? "" : maTypeListVo.getParentThreeLevelName()); + maTypeListVo.setItemType(maTypeListVo.getMaterialName() == null ? "" : maTypeListVo.getMaterialName()); break; case "3": // 三级节点父级是二级节点和一级节点, 要把祖父类型名称放入一级字段,把父类型名称存入二级字段 - maTypeListVo.setParentOneLevelName(maTypeListVo.getParentTwoLevelName() == null ? "" : maTypeListVo.getParentTwoLevelName()); - maTypeListVo.setParentTwoLevelName(maTypeListVo.getParentThreeLevelName() == null ? "" : maTypeListVo.getParentThreeLevelName()); + maTypeListVo.setItemType(maTypeListVo.getMaterialType() == null ? "" : maTypeListVo.getMaterialType()); + maTypeListVo.setMaterialType(maTypeListVo.getMaterialName() == null ? "" : maTypeListVo.getMaterialName()); break; case "4": // 四级节点父级是三级节点和二级节点和一级节点, 要把祖父类型名称放入一级字段,把父类型名称存入二级字段,子类型名称存入三级字段 @@ -245,7 +248,14 @@ public class TypeServiceImpl implements ITypeService { */ @Override public int insertType(Type type) { + //根据类型名称判断,去重 + Type maType = typeMapper.queryByName(type.getTypeName()); + if (maType != null && maType.getParentId().equals(type.getParentId())) { + throw new RuntimeException("同级下类型名称存在重复!"); + } + type.setLevel(String.valueOf(Integer.parseInt(type.getLevel()) + 1)); type.setCreateTime(DateUtils.getNowDate()); + type.setCreateBy(SecurityUtils.getUserId().toString()); return typeMapper.insertType(type); } @@ -257,7 +267,13 @@ public class TypeServiceImpl implements ITypeService { */ @Override public int updateType(Type type) { + //根据类型名称判断,去重 + Type maType = typeMapper.queryByName(type.getTypeName()); + if (maType != null && !maType.getTypeId().equals(type.getTypeId()) && maType.getParentId().equals(type.getParentId())) { + throw new RuntimeException("同级下类型名称存在重复!"); + } type.setUpdateTime(DateUtils.getNowDate()); + type.setUpdateBy(SecurityUtils.getUserId().toString()); return typeMapper.updateType(type); } @@ -279,8 +295,17 @@ public class TypeServiceImpl implements ITypeService { * @return 结果 */ @Override - public int deleteTypeByTypeId(Long typeId) { - return typeMapper.logicDeleteTypeByTypeId(typeId); + public AjaxResult deleteTypeByTypeId(Long typeId) { + //根据id查询删除类型下属是否有关联,有关联无法删除 + List list = typeMapper.selectById(typeId); + if (CollectionUtils.isNotEmpty(list)) { + return AjaxResult.error("该类型下有子类型,无法删除"); + } + int result = typeMapper.logicDeleteTypeByTypeId(typeId); + if (result > 0) { + return AjaxResult.success(HttpCodeEnum.SUCCESS.getMsg(), result); + } + return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), HttpCodeEnum.FAIL.getMsg()); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java index 377c8c22..59248010 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/vo/MaTypeListVo.java @@ -1,6 +1,9 @@ package com.bonus.material.ma.vo; +import com.bonus.common.core.annotation.Excel; import com.bonus.material.ma.domain.Type; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; import lombok.Getter; import lombok.Setter; @@ -15,12 +18,16 @@ import lombok.Setter; @Setter public class MaTypeListVo extends Type { - private String parentOneLevelName; + @Excel(name = "施工类型") + @ApiModelProperty(value = "施工类型") + private String itemType; - private String parentTwoLevelName; + @Excel(name = "物资类型") + @ApiModelProperty(value = "施工类型") + private String materialType; - private String parentThreeLevelName; - - private String parentFourLevelName; + @Excel(name = "物资名称") + @ApiModelProperty(value = "物资名称") + private String materialName; } diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index 9a70c583..a5faa174 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -70,10 +70,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - + + + @@ -321,29 +320,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - + + + + + \ No newline at end of file