hyingbo
2025-06-06 a3cb768d958e64625786857e0db69335875f5d8e
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EquipmentCategoryController.java
@@ -10,6 +10,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.common.api.vo.CommonGenericTree;
@@ -25,6 +26,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.system.entity.SysDict;
import org.jeecg.modules.system.entity.SysDictItem;
import org.jeecg.modules.system.service.ISysDictItemService;
import org.jeecg.modules.system.service.ISysDictService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -54,7 +59,11 @@
public class EquipmentCategoryController extends JeecgController<EquipmentCategory, IEquipmentCategoryService> {
   @Autowired
   private IEquipmentCategoryService equipmentCategoryService;
   @Autowired
   private ISysDictService sysDictService;
   @Autowired
   private ISysDictItemService sysDictItemService;
   /**
    * 分页列表查询
    *
@@ -99,7 +108,7 @@
         String parentId2 = record.getParentId();
         if("-1".equals(parentId2)){
            record.setParentNum("-1");
            record.setParentName("故障原因");
            record.setParentName("设备分类");
         }else{
            EquipmentCategory pCategory = equipmentCategoryService.getById(parentId2);
            record.setParentNum(pCategory.getNum());
@@ -108,7 +117,8 @@
      }
      return Result.OK(pageList);
   }
   /**
    *   添加
    *
@@ -120,13 +130,24 @@
   //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_equipment_category:add")
   @PostMapping(value = "/add")
   public Result<String> add(@RequestBody EquipmentCategory equipmentCategory) {
      if(!StringUtils.isNotBlank( equipmentCategory.getParentId())){
         equipmentCategory.setParentId("-1");
      if(equipmentCategory.getParentId().equals("-1")){
         SysDict sysDict = sysDictService.getOne(new QueryWrapper<SysDict>().eq("dict_code","equipment_category"),false);
         if(ObjectUtils.isNotNull(sysDict)){
            List<SysDictItem> sysDictItems = sysDictItemService.selectItemsByMainId(sysDict.getId());
            for(SysDictItem sysDictItem:sysDictItems){
               if(equipmentCategory.getName().equals(sysDictItem.getItemText())){
                  equipmentCategory.setEquipmentCategoryUda1(sysDictItem.getItemValue());
               }
            }
         }
         else {
            return Result.error("添加失败,需要去维护数据字典设备大类!");
         }
      }
      equipmentCategoryService.save(equipmentCategory);
      return Result.OK("添加成功!");
   }
   /**
    *  编辑
    *
@@ -138,10 +159,16 @@
   //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_equipment_category:edit")
   @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
   public Result<String> edit(@RequestBody EquipmentCategory equipmentCategory) {
      List<EquipmentCategory> equipmentCategories = equipmentCategory.getEquipmentCategoryDtlList();
      for(EquipmentCategory equipmentCategoryChild:equipmentCategories){
         equipmentCategoryChild.setEquipmentCategoryUda1(equipmentCategory.getEquipmentCategoryUda1());
         equipmentCategoryChild.setEquipmentCategoryUda2(equipmentCategory.getEquipmentCategoryUda2());
      }
      equipmentCategoryService.saveOrUpdateBatch(equipmentCategories);
      equipmentCategoryService.updateById(equipmentCategory);
      return Result.OK("编辑成功!");
   }
   /**
    *   通过id删除
    *
@@ -158,7 +185,7 @@
      equipmentCategoryService.updateById(equipmentCategory);
      return Result.OK("删除成功!");
   }
   /**
    *  批量删除
    *
@@ -178,7 +205,7 @@
      }
      return Result.OK("批量删除成功!");
   }
   /**
    * 通过id查询
    *
@@ -205,7 +232,7 @@
    //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_equipment_category:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, EquipmentCategory equipmentCategory) {
        return super.exportXls(request, equipmentCategory, EquipmentCategory.class, "mom_eam_equipment_category");
        return super.exportXls(request, equipmentCategory, EquipmentCategory.class, "设备分类");
    }
    /**
@@ -227,8 +254,18 @@
     */
    @GetMapping("/loadTree")
    public Result<?> loadTree(HttpServletRequest httpServletRequest) {
       List<CommonGenericTree> list = equipmentCategoryService.loadTree();
       List<CommonGenericTree> list = equipmentCategoryService.loadTreeByRecurrence();
       return Result.ok(list);
    }
    @GetMapping(value = "/getAllChildren")
    public Result<IPage<EquipmentCategory>> getAllChildren(EquipmentCategory equipmentCategory,
                                             @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                             @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                             HttpServletRequest req){
       QueryWrapper<EquipmentCategory> queryWrapper = Wrappers.query();
       Page<EquipmentCategory> page = new Page<EquipmentCategory>(pageNo, pageSize);
       IPage<EquipmentCategory> pageList = equipmentCategoryService.getAllChildren(page, equipmentCategory);
       return Result.OK(pageList);
    }
}