|
@@ -1,19 +1,24 @@
|
|
|
package com.ruoyi.asset.service.impl;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
|
|
|
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.mapper.TbAssetBorrowRecordMapper;
|
|
|
import com.ruoyi.asset.mapper.TbAssetCategoryMapper;
|
|
|
+import com.ruoyi.asset.utils.UserUtils;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
import com.ruoyi.system.mapper.SysDeptMapper;
|
|
|
+import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.asset.mapper.TbAssetMapper;
|
|
@@ -38,8 +43,14 @@ public class TbAssetServiceImpl extends ServiceImpl<TbAssetMapper, TbAsset> impl
|
|
|
private SysDeptMapper sysDeptMapper;
|
|
|
|
|
|
@Resource
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
private TbAssetCategoryMapper tbAssetCategoryMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TbAssetBorrowRecordMapper tbAssetBorrowRecordMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询资产信息
|
|
|
*
|
|
@@ -113,22 +124,12 @@ public class TbAssetServiceImpl extends ServiceImpl<TbAssetMapper, TbAsset> impl
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据条形码查询资产信息
|
|
|
+ * 批量新增资产信息
|
|
|
*
|
|
|
- * @param barCode 资产条形码
|
|
|
- * @return 资产信息
|
|
|
+ * @param tbAssetList 资产信息集合
|
|
|
+ * @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public TbAsset selectTbAssetByBarCode(String barCode) {
|
|
|
- // 判断条形码是否为空
|
|
|
- if (StrUtil.isBlank(barCode)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- // 查询资产信息
|
|
|
- return query().eq("bar_code", barCode).one();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
public boolean batchTbAsset(List<TbAsset> tbAssetList) {
|
|
|
int success = 0;
|
|
|
List<SysDept> deptList = sysDeptMapper.allDept();
|
|
@@ -157,6 +158,12 @@ public class TbAssetServiceImpl extends ServiceImpl<TbAssetMapper, TbAsset> impl
|
|
|
return success != 0;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param asset 资产信息
|
|
|
+ * @return 资产信息集合
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<TbAsset> exportData(TbAsset asset) {
|
|
|
List<SysDept> deptList = sysDeptMapper.allDept();
|
|
@@ -168,4 +175,70 @@ public class TbAssetServiceImpl extends ServiceImpl<TbAssetMapper, TbAsset> impl
|
|
|
}
|
|
|
return assetList;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小程序:获取资产信息
|
|
|
+ *
|
|
|
+ * @param barCode 资产条形码
|
|
|
+ * @param numberOrName 资产编号或名称
|
|
|
+ * @return 资产信息(含借用信息)集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<TbAssetDTO> selectTbAsset(String barCode, String numberOrName) {
|
|
|
+ List<SysDept> deptList = sysDeptMapper.allDept();
|
|
|
+ if (StrUtil.isBlank(barCode) && StrUtil.isBlank(numberOrName)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<TbAsset> assetList = new ArrayList<>();
|
|
|
+ if (StrUtil.isNotBlank(barCode)) {
|
|
|
+ TbAsset asset = query().eq("bar_code", barCode).one();
|
|
|
+ assetList.add(asset);
|
|
|
+ } else {
|
|
|
+ assetList = query().like("bar_code", numberOrName).or().like("number", numberOrName).or().like("name", numberOrName).list();
|
|
|
+ }
|
|
|
+
|
|
|
+ Long loginUserId = UserUtils.getLoginUserId();
|
|
|
+
|
|
|
+ ArrayList<TbAssetDTO> assetDTOList = new ArrayList<>();
|
|
|
+ for (TbAsset tbAsset : assetList) {
|
|
|
+ List<SysDept> collect = deptList.stream().filter(sysDept -> sysDept.getDeptId().equals(tbAsset.getDeptId())).collect(Collectors.toList());
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
+ SysDept sysDept = collect.get(0);
|
|
|
+ tbAsset.setDeptName(sysDept.getDeptName());
|
|
|
+ }
|
|
|
+ TbAssetDTO tbAssetDTO = BeanUtil.toBean(tbAsset, TbAssetDTO.class);
|
|
|
+ if (tbAsset.getStatus() != 1) {
|
|
|
+ tbAssetDTO.setBorrowStatus("不可借");
|
|
|
+ assetDTOList.add(tbAssetDTO);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ QueryWrapper<TbAssetBorrowRecord> borrowRecordQueryWrapper = new QueryWrapper<>();
|
|
|
+ borrowRecordQueryWrapper.eq("asset_bar_code", tbAsset.getBarCode()).orderByDesc("borrow_date").last("limit 1");
|
|
|
+ TbAssetBorrowRecord borrowRecord = tbAssetBorrowRecordMapper.selectOne(borrowRecordQueryWrapper);
|
|
|
+ if (borrowRecord == null) {
|
|
|
+ tbAssetDTO.setBorrowStatus("可借出");
|
|
|
+ assetDTOList.add(tbAssetDTO);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long isReturn = borrowRecord.getIsreturn();
|
|
|
+ if (isReturn > 0) {
|
|
|
+ tbAssetDTO.setBorrowStatus("可借出");
|
|
|
+ assetDTOList.add(tbAssetDTO);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ tbAssetDTO.setBorrowStatus("已借出");
|
|
|
+ Long userId = borrowRecord.getUserId();
|
|
|
+ SysUser sysUser = sysUserMapper.selectUserById(userId);
|
|
|
+ tbAssetDTO.setBorrowUserName(sysUser.getUserName());
|
|
|
+ tbAssetDTO.setBorrowDate(borrowRecord.getBorrowDate());
|
|
|
+ tbAssetDTO.setReturnDate(borrowRecord.getBorrowDate());
|
|
|
+ tbAssetDTO.setTel(borrowRecord.getTel());
|
|
|
+ tbAssetDTO.setMeBorrow(borrowRecord.getUserId().equals(loginUserId));
|
|
|
+
|
|
|
+ assetDTOList.add(tbAssetDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return assetDTOList;
|
|
|
+ }
|
|
|
}
|