车车 4 месяцев назад
Родитель
Сommit
cfaa557f11

+ 95 - 95
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/controller/admin/materialstype/MaterialsTypeController.java

@@ -1,95 +1,95 @@
-package cn.iocoder.yudao.module.iscs.controller.admin.materialstype;
-
-import org.springframework.web.bind.annotation.*;
-import jakarta.annotation.Resource;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.security.access.prepost.PreAuthorize;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import io.swagger.v3.oas.annotations.Parameter;
-import io.swagger.v3.oas.annotations.Operation;
-
-import jakarta.validation.constraints.*;
-import jakarta.validation.*;
-import jakarta.servlet.http.*;
-import java.util.*;
-import java.io.IOException;
-
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.pojo.CommonResult;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-
-import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
-
-import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
-import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
-
-import cn.iocoder.yudao.module.iscs.controller.admin.materialstype.vo.*;
-import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
-import cn.iocoder.yudao.module.iscs.service.materialstype.MaterialsTypeService;
-
-@Tag(name = "管理后台 - 物资类型")
-@RestController
-@RequestMapping("/iscs/materials-type")
-@Validated
-public class MaterialsTypeController {
-
-    @Resource
-    private MaterialsTypeService materialsTypeService;
-
-    @PostMapping("/insertMaterialsType")
-    @Operation(summary = "创建物资类型")
-    @PreAuthorize("@ss.hasPermission('iscs:materials-type:create')")
-    public CommonResult<Long> insertMaterialsType(@Valid @RequestBody MaterialsTypeSaveReqVO createReqVO) {
-        return success(materialsTypeService.createMaterialsType(createReqVO));
-    }
-
-    @PutMapping("/updateMaterialsType")
-    @Operation(summary = "更新物资类型")
-    @PreAuthorize("@ss.hasPermission('iscs:materials-type:update')")
-    public CommonResult<Boolean> updateMaterialsType(@Valid @RequestBody MaterialsTypeSaveReqVO updateReqVO) {
-        materialsTypeService.updateMaterialsType(updateReqVO);
-        return success(true);
-    }
-
-    @DeleteMapping("/deleteMaterialsTypeList")
-    @Parameter(name = "ids", description = "编号", required = true)
-    @Operation(summary = "批量删除物资类型")
-                @PreAuthorize("@ss.hasPermission('iscs:materials-type:delete')")
-    public CommonResult<Boolean> deleteMaterialsTypeList(@RequestParam("ids") List<Long> ids) {
-        materialsTypeService.deleteMaterialsTypeListByIds(ids);
-        return success(true);
-    }
-
-    @GetMapping("/selectMaterialsTypeById")
-    @Operation(summary = "获得物资类型")
-    @Parameter(name = "id", description = "编号", required = true, example = "1024")
-    @PreAuthorize("@ss.hasPermission('iscs:materials-type:query')")
-    public CommonResult<MaterialsTypeRespVO> selectMaterialsTypeById(@RequestParam("id") Long id) {
-        MaterialsTypeDO materialsType = materialsTypeService.getMaterialsType(id);
-        return success(BeanUtils.toBean(materialsType, MaterialsTypeRespVO.class));
-    }
-
-    @GetMapping("/getMaterialsTypePage")
-    @Operation(summary = "获得物资类型分页")
-    @PreAuthorize("@ss.hasPermission('iscs:materials-type:query')")
-    public CommonResult<PageResult<MaterialsTypeRespVO>> getMaterialsTypePage(@Valid MaterialsTypePageReqVO pageReqVO) {
-        PageResult<MaterialsTypeDO> pageResult = materialsTypeService.getMaterialsTypePage(pageReqVO);
-        return success(BeanUtils.toBean(pageResult, MaterialsTypeRespVO.class));
-    }
-
-    @GetMapping("/exportMaterialsTypeExcel")
-    @Operation(summary = "导出物资类型 Excel")
-    @PreAuthorize("@ss.hasPermission('iscs:materials-type:export')")
-    @ApiAccessLog(operateType = EXPORT)
-    public void exportMaterialsTypeExcel(@Valid MaterialsTypePageReqVO pageReqVO,
-              HttpServletResponse response) throws IOException {
-        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
-        List<MaterialsTypeDO> list = materialsTypeService.getMaterialsTypePage(pageReqVO).getList();
-        // 导出 Excel
-        ExcelUtils.write(response, "物资类型.xls", "数据", MaterialsTypeRespVO.class,
-                        BeanUtils.toBean(list, MaterialsTypeRespVO.class));
-    }
-
-}
+package cn.iocoder.yudao.module.iscs.controller.admin.materialstype;
+
+import org.springframework.web.bind.annotation.*;
+import jakarta.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.security.access.prepost.PreAuthorize;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Operation;
+
+import jakarta.validation.constraints.*;
+import jakarta.validation.*;
+import jakarta.servlet.http.*;
+import java.util.*;
+import java.io.IOException;
+
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
+
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
+
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
+
+import cn.iocoder.yudao.module.iscs.controller.admin.materialstype.vo.*;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
+import cn.iocoder.yudao.module.iscs.service.materialstype.MaterialsTypeService;
+
+@Tag(name = "管理后台 - 物资类型")
+@RestController
+@RequestMapping("/iscs/materials-type")
+@Validated
+public class MaterialsTypeController {
+
+    @Resource
+    private MaterialsTypeService materialsTypeService;
+
+    @PostMapping("/insertMaterialsType")
+    @Operation(summary = "创建物资类型")
+    @PreAuthorize("@ss.hasPermission('iscs:materials-type:create')")
+    public CommonResult<Long> insertMaterialsType(@Valid @RequestBody MaterialsTypeSaveReqVO createReqVO) {
+        return success(materialsTypeService.createMaterialsType(createReqVO));
+    }
+
+    @PutMapping("/updateMaterialsType")
+    @Operation(summary = "更新物资类型")
+    @PreAuthorize("@ss.hasPermission('iscs:materials-type:update')")
+    public CommonResult<Boolean> updateMaterialsType(@Valid @RequestBody MaterialsTypeSaveReqVO updateReqVO) {
+        materialsTypeService.updateMaterialsType(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/deleteMaterialsTypeList")
+    @Parameter(name = "ids", description = "编号", required = true)
+    @Operation(summary = "批量删除物资类型")
+                @PreAuthorize("@ss.hasPermission('iscs:materials-type:delete')")
+    public CommonResult<Boolean> deleteMaterialsTypeList(@RequestParam("ids") List<Long> ids) {
+        materialsTypeService.deleteMaterialsTypeListByIds(ids);
+        return success(true);
+    }
+
+    @GetMapping("/selectMaterialsTypeById")
+    @Operation(summary = "获得物资类型")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('iscs:materials-type:query')")
+    public CommonResult<MaterialsTypeRespVO> selectMaterialsTypeById(@RequestParam("id") Long id) {
+        MaterialsTypeDO materialsType = materialsTypeService.getMaterialsType(id);
+        return success(BeanUtils.toBean(materialsType, MaterialsTypeRespVO.class));
+    }
+
+    @GetMapping("/getMaterialsTypePage")
+    @Operation(summary = "获得物资类型分页")
+    @PreAuthorize("@ss.hasPermission('iscs:materials-type:query')")
+    public CommonResult<PageResult<MaterialsTypeRespVO>> getMaterialsTypePage(@Valid MaterialsTypePageReqVO pageReqVO) {
+        PageResult<MaterialsTypeDO> pageResult = materialsTypeService.getMaterialsTypePage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, MaterialsTypeRespVO.class));
+    }
+
+    @GetMapping("/exportMaterialsTypeExcel")
+    @Operation(summary = "导出物资类型 Excel")
+    @PreAuthorize("@ss.hasPermission('iscs:materials-type:export')")
+    @ApiAccessLog(operateType = EXPORT)
+    public void exportMaterialsTypeExcel(@Valid MaterialsTypePageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<MaterialsTypeDO> list = materialsTypeService.getMaterialsTypePage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "物资类型.xls", "数据", MaterialsTypeRespVO.class,
+                        BeanUtils.toBean(list, MaterialsTypeRespVO.class));
+    }
+
+}

+ 1 - 1
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/dal/mysql/materialstype/MaterialsTypeMapper.java

@@ -38,4 +38,4 @@ public interface MaterialsTypeMapper extends BaseMapperX<MaterialsTypeDO> {
                 .orderByDesc(MaterialsTypeDO::getId));
     }
 
-}
+}

+ 63 - 63
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/materialstype/MaterialsTypeService.java

@@ -1,63 +1,63 @@
-package cn.iocoder.yudao.module.iscs.service.materialstype;
-
-import java.util.*;
-import jakarta.validation.*;
-import cn.iocoder.yudao.module.iscs.controller.admin.materialstype.vo.*;
-import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import com.baomidou.mybatisplus.extension.service.IService;
-
-/**
- * 物资类型 Service 接口
- *
- * @author 芋道源码
- */
-public interface MaterialsTypeService extends IService<MaterialsTypeDO> {
-
-    /**
-     * 创建物资类型
-     *
-     * @param createReqVO 创建信息
-     * @return 编号
-     */
-    Long createMaterialsType(@Valid MaterialsTypeSaveReqVO createReqVO);
-
-    /**
-     * 更新物资类型
-     *
-     * @param updateReqVO 更新信息
-     */
-    void updateMaterialsType(@Valid MaterialsTypeSaveReqVO updateReqVO);
-
-    /**
-     * 删除物资类型
-     *
-     * @param id 编号
-     */
-    void deleteMaterialsType(Long id);
-
-    /**
-    * 批量删除物资类型
-    *
-    * @param ids 编号
-    */
-    void deleteMaterialsTypeListByIds(List<Long> ids);
-
-    /**
-     * 获得物资类型
-     *
-     * @param id 编号
-     * @return 物资类型
-     */
-    MaterialsTypeDO getMaterialsType(Long id);
-
-    /**
-     * 获得物资类型分页
-     *
-     * @param pageReqVO 分页查询
-     * @return 物资类型分页
-     */
-    PageResult<MaterialsTypeDO> getMaterialsTypePage(MaterialsTypePageReqVO pageReqVO);
-
-}
+package cn.iocoder.yudao.module.iscs.service.materialstype;
+
+import java.util.*;
+import jakarta.validation.*;
+import cn.iocoder.yudao.module.iscs.controller.admin.materialstype.vo.*;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 物资类型 Service 接口
+ *
+ * @author 芋道源码
+ */
+public interface MaterialsTypeService extends IService<MaterialsTypeDO> {
+
+    /**
+     * 创建物资类型
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createMaterialsType(@Valid MaterialsTypeSaveReqVO createReqVO);
+
+    /**
+     * 更新物资类型
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateMaterialsType(@Valid MaterialsTypeSaveReqVO updateReqVO);
+
+    /**
+     * 删除物资类型
+     *
+     * @param id 编号
+     */
+    void deleteMaterialsType(Long id);
+
+    /**
+    * 批量删除物资类型
+    *
+    * @param ids 编号
+    */
+    void deleteMaterialsTypeListByIds(List<Long> ids);
+
+    /**
+     * 获得物资类型
+     *
+     * @param id 编号
+     * @return 物资类型
+     */
+    MaterialsTypeDO getMaterialsType(Long id);
+
+    /**
+     * 获得物资类型分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 物资类型分页
+     */
+    PageResult<MaterialsTypeDO> getMaterialsTypePage(MaterialsTypePageReqVO pageReqVO);
+
+}

+ 26 - 0
yudao-module-iscs/src/main/java/cn/iocoder/yudao/module/iscs/service/materialstype/MaterialsTypeServiceImpl.java

@@ -1,18 +1,23 @@
 package cn.iocoder.yudao.module.iscs.service.materialstype;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.iscs.controller.admin.materialstype.vo.MaterialsTypePageReqVO;
 import cn.iocoder.yudao.module.iscs.controller.admin.materialstype.vo.MaterialsTypeSaveReqVO;
+import cn.iocoder.yudao.module.iscs.dal.dataobject.materials.MaterialsDO;
 import cn.iocoder.yudao.module.iscs.dal.dataobject.materialstype.MaterialsTypeDO;
 import cn.iocoder.yudao.module.iscs.dal.mysql.materialstype.MaterialsTypeMapper;
+import cn.iocoder.yudao.module.iscs.service.materials.MaterialsService;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import jakarta.annotation.Resource;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 物资类型 Service 实现类
@@ -25,6 +30,8 @@ public class MaterialsTypeServiceImpl extends ServiceImpl<MaterialsTypeMapper, M
 
     @Resource
     private MaterialsTypeMapper materialsTypeMapper;
+    @Resource
+    private MaterialsService materialsService;
 
     @Override
     public Long createMaterialsType(MaterialsTypeSaveReqVO createReqVO) {
@@ -55,6 +62,25 @@ public class MaterialsTypeServiceImpl extends ServiceImpl<MaterialsTypeMapper, M
 
     @Override
         public void deleteMaterialsTypeListByIds(List<Long> ids) {
+        Assert.isFalse(ids.isEmpty(), "请选择需要删除的数据!");
+        // 检查删除时下面有没有物资,有的话不可以删除
+        List<MaterialsDO> materialsList = materialsService.list(Wrappers.<MaterialsDO>lambdaQuery()
+                .in(MaterialsDO::getMaterialsTypeId, ids));
+        if (!materialsList.isEmpty()) {
+            List<Long> materialsTypeIdList = materialsList.stream().map(MaterialsDO::getMaterialsTypeId).collect(Collectors.toList());
+            List<MaterialsTypeDO> isMaterialsTypes = listByIds(materialsTypeIdList);
+            String collect = isMaterialsTypes.stream().map(MaterialsTypeDO::getMaterialsTypeName).collect(Collectors.joining(","));
+            Assert.isTrue(false, collect + "分类下有物资,不可删除!");
+
+        }
+        // 查询有没有子类,有的话不能删除
+        List<MaterialsTypeDO> materialsTypes = list(Wrappers.<MaterialsTypeDO>lambdaQuery()
+                .in(MaterialsTypeDO::getParentId, ids));
+        if (!materialsTypes.isEmpty()) {
+            String collect = materialsTypes.stream().map(MaterialsTypeDO::getMaterialsTypeName).collect(Collectors.joining(","));
+            Assert.isTrue(false, collect + "分类下有子类,不可删除!");
+
+        }
         // 校验存在
         validateMaterialsTypeExists(ids);
         // 删除

+ 1 - 1
yudao-module-iscs/src/main/resources/mapper/MaterialsTypeMapper.xml

@@ -9,4 +9,4 @@
         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
      -->
 
-</mapper>
+</mapper>