| | |
| | | package com.ruoyi.management.service.impl; |
| | | |
| | | import com.ruoyi.management.service.HomeStatisticsService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.management.domain.*; |
| | | import com.ruoyi.management.domain.dto.HomeStatisticsQuery; |
| | | import com.ruoyi.management.domain.vo.HomeStatisticsVO; |
| | | import com.ruoyi.management.domain.vo.goodsMaterialsNmVO; |
| | | import com.ruoyi.management.domain.vo.homeVO; |
| | | import com.ruoyi.management.service.*; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class HomeStatisticsServiceImpl implements HomeStatisticsService { |
| | | |
| | | @Resource |
| | | private SlVolumeProductionRkService slVolumeProductionRkService; |
| | | |
| | | @Resource |
| | | private SlGoodsMaterialsService slGoodsMaterialsService; |
| | | |
| | | @Resource |
| | | private SlStoreManagementService slStoreManagementService; |
| | | |
| | | @Resource |
| | | private SlVolumeProductionCkService slVolumeProductionCkService; |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | @Resource |
| | | private ManagementGoodsMaterialsService managementGoodsMaterialsService; |
| | | @Resource |
| | | private SlVolumeProductionZyService slVolumeProductionZyService; |
| | | |
| | | |
| | | @Override |
| | | public HomeStatisticsVO getHomeStatistics(HomeStatisticsQuery homeStatisticsQuery) { |
| | | |
| | | LambdaQueryWrapper<SlStoreManagement> wrapper= Wrappers.lambdaQuery(); |
| | | if (homeStatisticsQuery.getStoreManagementName()!=null&&homeStatisticsQuery.getStoreManagementName()!=""){ |
| | | wrapper.eq(SlStoreManagement::getId,homeStatisticsQuery.getStoreManagementName()); |
| | | } |
| | | if(homeStatisticsQuery.getStoreManagementNo()!=null&&homeStatisticsQuery.getStoreManagementNo()!=""){ |
| | | wrapper.eq(SlStoreManagement::getStoreManagementNo,homeStatisticsQuery.getStoreManagementNo()); |
| | | } |
| | | if (StringUtils.hasLength(homeStatisticsQuery.getStoreManagementGrade())&& !homeStatisticsQuery.getStoreManagementGrade().equals("0")){ |
| | | String[] split = homeStatisticsQuery.getStoreManagementGrade().split(","); |
| | | if (split.length>0){ |
| | | wrapper.in(SlStoreManagement::getStoreManagementGrade,split); |
| | | } |
| | | } |
| | | if ( homeStatisticsQuery.getStoreManagementNumber()!=null&& homeStatisticsQuery.getStoreManagementNumber()!=0 ){ |
| | | wrapper.eq(SlStoreManagement::getStoreManagementNumber,homeStatisticsQuery.getStoreManagementNumber()); |
| | | } |
| | | if (homeStatisticsQuery.getCityCode()!=null){ |
| | | wrapper.eq(SlStoreManagement::getCityCode,homeStatisticsQuery.getCityCode()); |
| | | } |
| | | if (homeStatisticsQuery.getCountyCode()!=null){ |
| | | wrapper.eq(SlStoreManagement::getCountyCode,homeStatisticsQuery.getCountyCode()); |
| | | } |
| | | if (homeStatisticsQuery.getTownCode()!=null){ |
| | | wrapper.eq(SlStoreManagement::getTownCode,homeStatisticsQuery.getTownCode()); |
| | | } |
| | | wrapper.eq(SlStoreManagement::getDelFlag,"0"); |
| | | List<SlStoreManagement> list = slStoreManagementService.list(wrapper); |
| | | Set<Long> slStoreManagementIdList = null; |
| | | slStoreManagementIdList = list.stream().map(SlStoreManagement::getId) |
| | | .collect(Collectors.toSet()); |
| | | LambdaQueryWrapper<SlGoodsMaterials> wrapper1= Wrappers.lambdaQuery(); |
| | | if (homeStatisticsQuery.getGoodsMaterialsName()!=null&&homeStatisticsQuery.getStoreManagementName()!=""){ |
| | | wrapper1.like(SlGoodsMaterials::getGoodsMaterialsName,homeStatisticsQuery.getGoodsMaterialsName()); |
| | | } |
| | | List<SlGoodsMaterials> list1 = slGoodsMaterialsService.list(wrapper1); |
| | | |
| | | Set<Long> SlGoodsMaterialsList = null; |
| | | SlGoodsMaterialsList = list1.stream().map(SlGoodsMaterials::getId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | LambdaQueryWrapper<SlVolumeProductionRk> wrapper2= Wrappers.lambdaQuery(); |
| | | if (slStoreManagementIdList.size()>0){ |
| | | wrapper2.in(SlVolumeProductionRk::getManagementId,slStoreManagementIdList); |
| | | }else{ |
| | | slStoreManagementIdList=new HashSet<>(); |
| | | slStoreManagementIdList.add(0L); |
| | | wrapper2.in(SlVolumeProductionRk::getManagementId,slStoreManagementIdList); |
| | | } |
| | | |
| | | if (SlGoodsMaterialsList.size()>0){ |
| | | wrapper2.in(SlVolumeProductionRk::getMaterialsId,SlGoodsMaterialsList); |
| | | }else{ |
| | | SlGoodsMaterialsList=new HashSet<>(); |
| | | SlGoodsMaterialsList.add(0L); |
| | | wrapper2.in(SlVolumeProductionRk::getMaterialsId,SlGoodsMaterialsList); |
| | | } |
| | | if (homeStatisticsQuery.getShelfId()!=null){ |
| | | wrapper2.eq(SlVolumeProductionRk::getShelfId,homeStatisticsQuery.getShelfId()); |
| | | } |
| | | wrapper2.isNotNull(SlVolumeProductionRk::getNewAddTime); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | SysUser data = sysUserClient.getSysUser(userId).getData(); |
| | | List<Long> collect = new ArrayList<>(); |
| | | if (data!=null){ |
| | | if (!data.getUserType().equals("00")){ |
| | | switch (data.getRoleType()){ |
| | | case 3: |
| | | collect = slStoreManagementService.lambdaQuery().eq(SlStoreManagement::getDelFlag, "0") |
| | | .ge(SlStoreManagement::getStoreManagementGrade, 3).eq(SlStoreManagement::getCityCode, data.getCityCode()) |
| | | .list().stream().map(SlStoreManagement::getId).collect(Collectors.toList()); |
| | | wrapper2.in(SlVolumeProductionRk::getManagementId, collect); |
| | | break; |
| | | case 4: |
| | | collect = slStoreManagementService.lambdaQuery().eq(SlStoreManagement::getDelFlag, "0") |
| | | .ge(SlStoreManagement::getStoreManagementGrade, 4).eq(SlStoreManagement::getCountyCode, data.getCountyCode()) |
| | | .list().stream().map(SlStoreManagement::getId).collect(Collectors.toList()); |
| | | wrapper2.in(SlVolumeProductionRk::getManagementId, collect); |
| | | break; |
| | | case 5: |
| | | collect = slStoreManagementService.lambdaQuery().eq(SlStoreManagement::getDelFlag, "0") |
| | | .ge(SlStoreManagement::getStoreManagementGrade, 5).eq(SlStoreManagement::getTownCode, data.getTownCode()) |
| | | .list().stream().map(SlStoreManagement::getId).collect(Collectors.toList()); |
| | | wrapper2.in(SlVolumeProductionRk::getManagementId, collect); |
| | | break; |
| | | case 6: |
| | | collect = slStoreManagementService.lambdaQuery().eq(SlStoreManagement::getDelFlag, "0") |
| | | .ge(SlStoreManagement::getStoreManagementGrade, 6).eq(SlStoreManagement::getTownCode, data.getTownCode()) |
| | | .list().stream().map(SlStoreManagement::getId).collect(Collectors.toList()); |
| | | wrapper2.in(SlVolumeProductionRk::getManagementId, collect); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | List<SlVolumeProductionRk> list2 = slVolumeProductionRkService.list(wrapper2); |
| | | |
| | | |
| | | Map<Long, List<SlVolumeProductionRk>> groupByUserNameMap = list2.stream().collect(Collectors.groupingBy(SlVolumeProductionRk::getMaterialsId)); |
| | | |
| | | HomeStatisticsVO homeStatisticsVO=new HomeStatisticsVO(); |
| | | // 物资总数 |
| | | Long temp = 0L; |
| | | // 将list2中的在库数量累加起来 |
| | | Double d=0.0; |
| | | List<String> longs = new ArrayList<>(); |
| | | for (SlVolumeProductionRk li:list2){ |
| | | Long repertoryZhai = li.getRepertoryZhai(); |
| | | li.setRepertoryZhai(repertoryZhai); |
| | | if (longs.isEmpty()){ |
| | | longs.add(li.getManagementId()+"-"+li.getMaterialsId()); |
| | | // 根据仓库id和物资id 查询遗失数量 |
| | | ManagementGoodsMaterials one = managementGoodsMaterialsService.lambdaQuery().eq(ManagementGoodsMaterials::getGoodsMaterialsId, li.getMaterialsId()) |
| | | .eq(ManagementGoodsMaterials::getManagementId, li.getManagementId()) |
| | | .eq(ManagementGoodsMaterials::getDelFlag, "0").one(); |
| | | if (one!=null){ |
| | | d=d+li.getRkPice().multiply(new BigDecimal(li.getRkNum()-one.getRepertoryYishi())).doubleValue(); |
| | | temp+=li.getRkNum()-one.getRepertoryYishi(); |
| | | li.setRepertoryZhai(li.getRkNum()-one.getRepertoryYishi()); |
| | | }else{ |
| | | d=d+li.getRkPice().multiply(new BigDecimal(li.getRkNum())).doubleValue(); |
| | | temp+=li.getRkNum(); |
| | | } |
| | | }else if(longs.contains(li.getManagementId()+"-"+li.getMaterialsId())){ |
| | | d=d+li.getRkPice().multiply(new BigDecimal(li.getRkNum())).doubleValue(); |
| | | temp+=li.getRkNum(); |
| | | }else{ |
| | | longs.add(li.getManagementId()+"-"+li.getMaterialsId()); |
| | | // 根据仓库id和物资id 查询遗失数量 |
| | | ManagementGoodsMaterials one = managementGoodsMaterialsService.lambdaQuery().eq(ManagementGoodsMaterials::getGoodsMaterialsId, li.getMaterialsId()) |
| | | .eq(ManagementGoodsMaterials::getManagementId, li.getManagementId()) |
| | | .eq(ManagementGoodsMaterials::getDelFlag, "0").one(); |
| | | if (one!=null){ |
| | | d=d+li.getRkPice().multiply(new BigDecimal(li.getRkNum()-one.getRepertoryYishi())).doubleValue(); |
| | | temp+=li.getRkNum()-one.getRepertoryYishi(); |
| | | li.setRepertoryZhai(li.getRkNum()-one.getRepertoryYishi()); |
| | | }else{ |
| | | d=d+li.getRkPice().multiply(new BigDecimal(li.getRkNum())).doubleValue(); |
| | | temp+=li.getRkNum(); |
| | | } |
| | | } |
| | | // 查询这个入库记录有没有转移 转移了的话 需要扣去转移数量 |
| | | Long tem = 0L; |
| | | List<SlVolumeProductionZy> list3 = slVolumeProductionZyService.lambdaQuery().eq(SlVolumeProductionZy::getRkId, li.getId()) |
| | | .eq(SlVolumeProductionZy::getDelFlag, "0").list(); |
| | | if (!list3.isEmpty()){ |
| | | tem+= list3.stream().map(SlVolumeProductionZy::getZyNum).reduce(0, Integer::sum); |
| | | } |
| | | temp-=tem; |
| | | LambdaQueryWrapper<SlVolumeProductionCk> wrapper3= Wrappers.lambdaQuery(); |
| | | wrapper3.eq(SlVolumeProductionCk::getRkId,li.getId()); |
| | | wrapper3.eq(SlVolumeProductionCk::getIsGh,1); |
| | | if (li.getRkPice() == null){ |
| | | li.setRkPice(BigDecimal.ZERO); |
| | | } |
| | | } |
| | | homeStatisticsVO.setGoodsMaterialsSumNum(temp); |
| | | homeStatisticsVO.setGoodsMaterialsSumPice(d); |
| | | |
| | | //非消耗 |
| | | List<homeVO> arr=new ArrayList<>(); |
| | | //消耗 |
| | | List<homeVO> arr1=new ArrayList<>(); |
| | | for (SlVolumeProductionRk l:list2){ |
| | | homeVO h=new homeVO(); |
| | | SlGoodsMaterials byId = slGoodsMaterialsService.getById(l.getMaterialsId()); |
| | | h.setIsConsume(byId.getIsConsume()); |
| | | h.setId(byId.getId()); |
| | | h.setGoodsMaterialsName(byId.getGoodsMaterialsName()); |
| | | h.setGoodsMaterialsNum(l.getRepertoryZhai()); |
| | | // 判断物资预警库存 |
| | | if (byId.getRepertory()==null || byId.getRepertory() == 0){ |
| | | h.setColor(1); |
| | | }else{ |
| | | if (l.getRepertoryZhai()<=byId.getRepertory()){ |
| | | h.setColor(2); |
| | | }else{ |
| | | h.setColor(1); |
| | | } |
| | | } |
| | | |
| | | if (byId.getIsConsume()==1){ |
| | | arr.add(h); |
| | | }else{ |
| | | arr1.add(h); |
| | | } |
| | | |
| | | } |
| | | |
| | | List<goodsMaterialsNmVO> goodsMaterialsNmVOS=new ArrayList<>(); |
| | | Map<String, List<homeVO>> groupByUserNameMap1 = arr.stream().collect(Collectors.groupingBy(homeVO::getGoodsMaterialsName)); |
| | | for (Map.Entry<String, List<homeVO>> entry : groupByUserNameMap1.entrySet()) { |
| | | goodsMaterialsNmVO goodsMaterialsNmVO=new goodsMaterialsNmVO(); |
| | | String key = entry.getKey(); |
| | | goodsMaterialsNmVO.setGoodsMaterialsName(key); |
| | | goodsMaterialsNmVO.setGoodsMaterialsId(entry.getValue().get(0).getId()); |
| | | List<homeVO> value = entry.getValue(); |
| | | goodsMaterialsNmVO.setColor(entry.getValue().get(0).getColor()); |
| | | // 处理键和值 |
| | | int a=0; |
| | | for (homeVO vo : value) { |
| | | if (vo.getGoodsMaterialsNum()== null){ |
| | | vo.setGoodsMaterialsNum(0L); |
| | | } |
| | | a=a+vo.getGoodsMaterialsNum().intValue(); |
| | | } |
| | | goodsMaterialsNmVO.setGoodsMaterialsNum(a); |
| | | goodsMaterialsNmVOS.add(goodsMaterialsNmVO); |
| | | } |
| | | |
| | | homeStatisticsVO.setGoodsMaterialsfxiaohao(goodsMaterialsNmVOS); |
| | | |
| | | |
| | | List<goodsMaterialsNmVO> goodsMaterialsNmVOS1=new ArrayList<>(); |
| | | Map<String, List<homeVO>> groupByUserNameMap2 = arr1.stream().collect(Collectors.groupingBy(homeVO::getGoodsMaterialsName)); |
| | | for (Map.Entry<String, List<homeVO>> entry : groupByUserNameMap2.entrySet()) { |
| | | goodsMaterialsNmVO goodsMaterialsNmVO1=new goodsMaterialsNmVO(); |
| | | String key = entry.getKey(); |
| | | goodsMaterialsNmVO1.setGoodsMaterialsName(key); |
| | | goodsMaterialsNmVO1.setGoodsMaterialsId(entry.getValue().get(0).getId()); |
| | | goodsMaterialsNmVO1.setColor(entry.getValue().get(0).getColor()); |
| | | List<homeVO> value = entry.getValue(); |
| | | // 处理键和值 |
| | | int a=0; |
| | | for (homeVO vo : value) { |
| | | if (vo.getGoodsMaterialsNum()== null){ |
| | | vo.setGoodsMaterialsNum(0L); |
| | | } |
| | | a=a+vo.getGoodsMaterialsNum().intValue(); |
| | | } |
| | | goodsMaterialsNmVO1.setGoodsMaterialsNum(a); |
| | | goodsMaterialsNmVOS1.add(goodsMaterialsNmVO1); |
| | | } |
| | | homeStatisticsVO.setGoodsMaterialsxiaohao(goodsMaterialsNmVOS1); |
| | | return homeStatisticsVO; |
| | | } |
| | | } |