| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.entity.TDept; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.dto.asset.AssetTypeDTO; |
| | | import com.ruoyi.system.mapper.AssetTypeMapper; |
| | | import com.ruoyi.system.model.AssetMain; |
| | | import com.ruoyi.system.model.AssetType; |
| | | import com.ruoyi.system.query.AssetStatisticsListQuery; |
| | | import com.ruoyi.system.service.AssetMainService; |
| | | import com.ruoyi.system.service.AssetTypeService; |
| | | import com.ruoyi.system.vo.AssetStatisticsVO; |
| | | import com.ruoyi.system.vo.asset.AssetTypeTreeVO; |
| | | import com.ruoyi.system.vo.system.NotificationVO; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | return parentTypeCode + subTypeCode; |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<AssetStatisticsVO> pageList(AssetStatisticsListQuery query) { |
| | | if (StringUtils.hasLength(query.getNameOrCode())){ |
| | | // 查询出资产名称或者资产编号符合条件的code |
| | | List<Integer> assetTypeIds = assetMainService.lambdaQuery().like(AssetMain::getAssetName, query.getNameOrCode()) |
| | | .or() |
| | | .like(AssetMain::getAssetCode, query.getNameOrCode()) |
| | | .list() |
| | | .stream() |
| | | .map(AssetMain::getAssetTypeId) |
| | | .collect(Collectors.toList()); |
| | | query.setAssetTypeIds(assetTypeIds); |
| | | if (assetTypeIds.isEmpty()){ |
| | | return new PageInfo<>(); |
| | | } |
| | | } |
| | | PageInfo<AssetStatisticsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); |
| | | List<AssetStatisticsVO> list = this.baseMapper.pageList(query,pageInfo); |
| | | List<AssetStatisticsVO> listNoLimit = this.baseMapper.pageListNoLimit(query); |
| | | List<Integer> assetTypeIds = listNoLimit.stream().map(AssetStatisticsVO::getAssetTypeIdSecond).collect(Collectors.toList()); |
| | | if (assetTypeIds.isEmpty()){ |
| | | return new PageInfo<>(); |
| | | } |
| | | Map<Integer, List<AssetMain>> assetMainMap = assetMainService.lambdaQuery().in(AssetMain::getAssetTypeId, assetTypeIds).list() |
| | | .stream() |
| | | .collect(Collectors.groupingBy(AssetMain::getAssetTypeId)); |
| | | for (AssetStatisticsVO asset : list) { |
| | | Integer totalCount= 0; |
| | | Integer idleCount= 0; |
| | | Integer useCount= 0; |
| | | Integer disposeCount= 0; |
| | | Integer otherCount= 0; |
| | | BigDecimal totalValue = new BigDecimal("0"); |
| | | List<AssetMain> assetMains = assetMainMap.get(asset.getAssetTypeIdSecond()); |
| | | if (!assetMains.isEmpty()){ |
| | | for (AssetMain assetMain : assetMains) { |
| | | if (assetMain.getAssetStatus().contains("闲置")){ |
| | | idleCount += assetMain.getQuantity(); |
| | | }else if (assetMain.getAssetStatus().contains("使用中")){ |
| | | useCount += assetMain.getQuantity(); |
| | | }else if (assetMain.getAssetStatus().contains("损坏") || assetMain.getAssetStatus().contains("报废")){ |
| | | disposeCount += assetMain.getQuantity(); |
| | | }else{ |
| | | otherCount += assetMain.getQuantity(); |
| | | } |
| | | totalCount+= assetMain.getQuantity(); |
| | | totalValue = totalValue.add(new BigDecimal(assetMain.getQuantity()) |
| | | .multiply(assetMain.getUnitPrice()).setScale(2, RoundingMode.HALF_DOWN)); |
| | | } |
| | | } |
| | | asset.setIdleCount(idleCount); |
| | | asset.setUseCount(useCount); |
| | | asset.setDisposeCount(disposeCount); |
| | | asset.setOtherCount(otherCount); |
| | | asset.setTotalCount(totalCount); |
| | | asset.setTotalValue(totalValue); |
| | | } |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | |
| | | } |