소스 검색

林武泰/新增设备统计接口

LinWuTai 2 년 전
부모
커밋
2a4b2701e2

+ 10 - 0
lab-admin/src/main/java/com/ruoyi/asset/controller/TbAssetController.java

@@ -152,4 +152,14 @@ public class TbAssetController extends BaseController
         }
         return AjaxResult.success(tbAssetDTOS);
     }
+
+    /**
+     * 资产信息统计
+     */
+    @ApiOperation("资产信息统计")
+    @PreAuthorize("@ss.hasPermi('asset:asset:query')")
+    @GetMapping(value = "/count")
+    public AjaxResult countTbAsset() {
+        return tbAssetService.countTbAsset();
+    }
 }

+ 9 - 0
lab-admin/src/main/java/com/ruoyi/asset/mapper/TbAssetBorrowRecordMapper.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.asset.domain.TbAssetBorrowRecord;
 import com.ruoyi.asset.domain.dto.TbCountAssetDTO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 
 /**
  * 设备借用记录Mapper接口
@@ -69,4 +70,12 @@ public interface TbAssetBorrowRecordMapper extends BaseMapper<TbAssetBorrowRecor
      * @return
      */
     public List<TbCountAssetDTO> countAssetDto();
+
+    /**
+     * 统计借出资产设备
+     *
+     * @return 条数
+     */
+    @Select("SELECT COUNT(id) from tb_asset_borrow_record where isReturn = 0")
+    public int countTbAssetBorrowRecordForNotReturn();
 }

+ 17 - 0
lab-admin/src/main/java/com/ruoyi/asset/mapper/TbAssetMapper.java

@@ -79,4 +79,21 @@ public interface TbAssetMapper extends BaseMapper<TbAsset>
 
     @Update("update tb_asset set status = #{status} where bar_code = #{barCode}")
     public int updateTbAssetStatus(@Param("barCode") String barCode, @Param("status") Long status);
+
+    /**
+     * 统计全部资产设备
+     *
+     * @return 条数
+     */
+    @Select("SELECT COUNT(id) FROM tb_asset")
+    public int countTbAssetAll();
+
+    /**
+     * 统计全部资产设备
+     *
+     * @param status 资产设备状态
+     * @return 条数
+     */
+    @Select("SELECT COUNT(id) FROM tb_asset where status = #{status}")
+    public int countTbAssetByStatus(long status);
 }

+ 8 - 0
lab-admin/src/main/java/com/ruoyi/asset/service/ITbAssetService.java

@@ -5,6 +5,7 @@ import java.util.List;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.asset.domain.TbAsset;
 import com.ruoyi.asset.domain.dto.TbAssetDTO;
+import com.ruoyi.common.core.domain.AjaxResult;
 import org.springframework.transaction.annotation.Transactional;
 
 /**
@@ -87,4 +88,11 @@ public interface ITbAssetService extends IService<TbAsset>
      * @return 资产信息列表
      */
     List<TbAssetDTO> selectTbAsset(String barCode, String numberOrName);
+
+    /**
+     * 资产信息统计
+     *
+     * @return 结果
+     */
+    AjaxResult countTbAsset();
 }

+ 17 - 0
lab-admin/src/main/java/com/ruoyi/asset/service/impl/TbAssetServiceImpl.java

@@ -10,8 +10,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.asset.domain.TbAssetBorrowRecord;
 import com.ruoyi.asset.domain.TbAssetCategory;
 import com.ruoyi.asset.domain.dto.TbAssetDTO;
+import com.ruoyi.asset.domain.enums.TbAssetStatusEnum;
 import com.ruoyi.asset.mapper.TbAssetBorrowRecordMapper;
 import com.ruoyi.asset.mapper.TbAssetCategoryMapper;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.UserUtils;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
@@ -248,4 +250,19 @@ public class TbAssetServiceImpl extends ServiceImpl<TbAssetMapper, TbAsset> impl
 
         return assetDTOList;
     }
+
+    @Override
+    public AjaxResult countTbAsset() {
+        int allAsset = tbAssetMapper.countTbAssetAll();
+        int faultAsset = tbAssetMapper.countTbAssetByStatus(TbAssetStatusEnum.fault.getStatusCode());
+        int scrapAsset = tbAssetMapper.countTbAssetByStatus(TbAssetStatusEnum.scrap.getStatusCode());
+        int borrowAsset = tbAssetBorrowRecordMapper.countTbAssetBorrowRecordForNotReturn();
+
+        Map<String, Integer> resultMap = new HashMap<>();
+        resultMap.put("allAsset", allAsset); // 全部设备
+        resultMap.put("faultAsset", faultAsset); // 故障设备
+        resultMap.put("scrapAsset", scrapAsset); // 报废设备
+        resultMap.put("borrowAsset", borrowAsset); // 借出设备
+        return AjaxResult.success("查询成功", resultMap);
+    }
 }