| package com.xzx.gc.order.service;  | 
|   | 
| import cn.hutool.core.bean.BeanUtil;  | 
| import cn.hutool.core.collection.CollUtil;  | 
| import cn.hutool.core.convert.Convert;  | 
| import cn.hutool.core.date.DateUtil;  | 
| import cn.hutool.core.exceptions.ExceptionUtil;  | 
| import cn.hutool.core.lang.Dict;  | 
| import cn.hutool.core.map.MapUtil;  | 
| import cn.hutool.core.util.ArrayUtil;  | 
| import cn.hutool.core.util.NumberUtil;  | 
| import cn.hutool.core.util.StrUtil;  | 
| import com.github.pagehelper.PageHelper;  | 
| import com.github.pagehelper.PageInfo;  | 
| import com.xzx.gc.common.Result;  | 
| import com.xzx.gc.common.constant.CommonEnum;  | 
| import com.xzx.gc.common.constant.Constants;  | 
| import com.xzx.gc.common.constant.OrderEnum;  | 
| import com.xzx.gc.common.constant.PayEnum;  | 
| import com.xzx.gc.common.dto.SimplePage;  | 
| import com.xzx.gc.common.exception.BusinessException;  | 
| import com.xzx.gc.common.exception.RestException;  | 
| import com.xzx.gc.common.utils.*;  | 
| import com.xzx.gc.entity.*;  | 
| import com.xzx.gc.model.admin.PayRequestInfoModel;  | 
| import com.xzx.gc.model.admin.PayStorageModel;  | 
| import com.xzx.gc.model.admin.StorageUserModel;  | 
| import com.xzx.gc.model.comon.account.AllAcountParamDto;  | 
| import com.xzx.gc.model.order.OrderInfoReq;  | 
| import com.xzx.gc.model.order.RkStatisticsStorageReceiverDto;  | 
| import com.xzx.gc.model.user.AccountVo;  | 
| import com.xzx.gc.order.dto.*;  | 
| import com.xzx.gc.order.mapper.*;  | 
| import com.xzx.gc.service.AccountContext;  | 
| import com.xzx.gc.util.DoubleUtil;  | 
| import lombok.extern.slf4j.Slf4j;  | 
| import org.springframework.beans.BeanUtils;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.stereotype.Service;  | 
| import org.springframework.transaction.annotation.Transactional;  | 
| import tk.mybatis.mapper.entity.Example;  | 
|   | 
| import javax.servlet.http.HttpServletRequest;  | 
| import java.math.BigDecimal;  | 
| import java.math.RoundingMode;  | 
| import java.text.ParseException;  | 
| import java.util.*;  | 
| import java.util.stream.Collectors;  | 
|   | 
| @Service  | 
| @Transactional  | 
| @Slf4j  | 
| public class StorageService {  | 
|   | 
|   | 
|     @Autowired  | 
|     private PayInfoMapper payInfoMapper;  | 
|   | 
|     @Autowired  | 
|     private IdUtils idUtils;  | 
|   | 
|     @Autowired  | 
|     private  OrderItemInfoMapper orderItemInfoMapper;  | 
|   | 
|     @Autowired  | 
|     private OrderBatchInfoMapper orderBatchInfoMapper;  | 
|   | 
|     @Autowired  | 
|     private OrderBatchMapper orderBatchMapper;  | 
|   | 
|   | 
|     @Autowired  | 
|     private RedisUtil redisUtil;  | 
|   | 
|     @Autowired  | 
|     private AddressMapper addressMapper;  | 
|   | 
|     @Autowired  | 
|     private OrderStorageDetailMapper orderStorageDetailMapper;  | 
|   | 
|   | 
|     @Autowired  | 
|     private SysStorageService sysStorageService;  | 
|   | 
|     @Autowired  | 
|     private OrderDetailService orderDetailService;  | 
|   | 
|     @Autowired  | 
|     private OrderClockInMapper orderClockInMapper;  | 
|   | 
|     @Autowired  | 
|     private OrderStorageInfoMapper orderStorageInfoMapper;  | 
|   | 
|     @Autowired  | 
|     private OrderDetailMapper orderDetailMapper;  | 
|   | 
|     @Autowired  | 
|     private  SysStorageMapper sysStorageMapper;  | 
|   | 
|     @Autowired  | 
|     private OrderBatchInfoService orderBatchInfoService;  | 
|   | 
|     @Autowired  | 
|     private OrderMapper orderMapper;  | 
|   | 
|     @Autowired  | 
|     private PackageGoodsInfoService packageGoodsInfoService;  | 
|   | 
|     @Autowired  | 
|     private PromotionRebateService promotionRebateService;  | 
|   | 
|     @Autowired  | 
|     private OtherUserMapper otherUserMapper;  | 
|     @Autowired  | 
|     private AccountMapper accountMapper;  | 
|     @Autowired  | 
|     private OrderService orderService;  | 
|     @Autowired  | 
|     private HttpServletRequest request;  | 
|     @Autowired  | 
|     private BusinessUtil businessUtil;  | 
|   | 
|     @Autowired  | 
|     private OtherUserService otherUserService;  | 
|   | 
|   | 
|     @Autowired  | 
|     private SysEnvironmentalInfoService sysEnvironmentalInfoService;  | 
|   | 
|     @Autowired  | 
|     private WeightItemPriceService weightItemPriceService;  | 
|   | 
|     @Autowired  | 
|     private CityPartnerService cityPartnerService;  | 
|   | 
|   | 
|     @Autowired  | 
|     private PartnerGaodeService partnerGaodeService;  | 
|   | 
|     @Autowired  | 
|     private UserVehicleInfoService userVehicleInfoService;  | 
|     @Autowired  | 
|     private OrderHomeApplianceService orderHomeApplianceService;  | 
|   | 
|     /**  | 
|      * 入库详情  | 
|      * @param storageId  | 
|      * @return  | 
|      */  | 
|     public StorageDetailBatchDto detail(String storageId){  | 
|   | 
|         StorageDetailBatchDto storageDetailBatchDto=new StorageDetailBatchDto();  | 
|         //物品清单  | 
|         OrderStorageDetailInfo orderStorageDetailInfo=new OrderStorageDetailInfo();  | 
|         orderStorageDetailInfo.setStorageId(storageId);  | 
|         List<OrderStorageDetailInfo> select = orderStorageDetailMapper.select(orderStorageDetailInfo);  | 
|   | 
|         Example example=new Example(OrderStorageInfo.class);  | 
|         Example.Criteria criteria = example.createCriteria();  | 
|         criteria.andEqualTo("storageId",storageId);  | 
|         OrderStorageInfo orderStorageInfo = orderStorageInfoMapper.selectOneByExample(example);  | 
|         Long sysStorageId = orderStorageInfo.getSysStorageId();  | 
|         Short sysStorageType = orderStorageInfo.getSysStorageType();  | 
|         if(CollUtil.isNotEmpty(select)){  | 
|   | 
|   | 
|             Map<String,Dict> map=new HashMap<>();  | 
|   | 
|             for (OrderStorageDetailInfo storageDetailInfo : select) {  | 
|                 String flag = storageDetailInfo.getFlag();  | 
|                 BigDecimal weight = storageDetailInfo.getWeight();  | 
|                 String amount = storageDetailInfo.getAmount();  | 
|                 String money = storageDetailInfo.getMoney();  | 
|                 String itemType = storageDetailInfo.getItemType();  | 
|                 String price=storageDetailInfo.getPrice();  | 
|   | 
|                 if(OrderEnum.入库型.getValue().equals(flag)&&weight!=null&&weight.compareTo(BigDecimal.ZERO)!=0){  | 
|   | 
|                     if(map.containsKey(itemType)){  | 
|                         Dict dict = map.get(itemType);  | 
|                         BigDecimal storageWeight1 = dict.getBigDecimal("storageWeight");  | 
|                         dict.set("storageWeight",NumberUtil.add(storageWeight1,weight));  | 
|                         BigDecimal storageMoney1 = dict.getBigDecimal("storageMoney");  | 
|                         dict.set("storageMoney",NumberUtil.add(storageMoney1,Convert.toBigDecimal(money)));  | 
|                         map.put(itemType,dict);  | 
|                     }else{  | 
|                         Dict dict=Dict.create();  | 
|                         dict.set("storageWeight",weight);  | 
|                         dict.set("storageMoney",new BigDecimal(money));  | 
|                         dict.set("price",price);  | 
|                         map.put(itemType,dict);  | 
|                     }  | 
|                 }  | 
|   | 
|                 if(OrderEnum.入库型.getValue().equals(flag)&&amount!=null&&Convert.toBigDecimal(amount,BigDecimal.ZERO).compareTo(BigDecimal.ZERO)!=0){  | 
|   | 
|                     if(map.containsKey(itemType)){  | 
|                         Dict dict = map.get(itemType);  | 
|                         BigDecimal storageAmount1 = dict.getBigDecimal("storageAmount");  | 
|                         dict.set("storageAmount",NumberUtil.add(storageAmount1,Convert.toBigDecimal(amount)));  | 
|                         BigDecimal storageMoney1 = dict.getBigDecimal("storageMoney");  | 
|                         dict.set("storageMoney",NumberUtil.add(storageMoney1,Convert.toBigDecimal(money)));  | 
|                         map.put(itemType,dict);  | 
|                     }else{  | 
|                         Dict dict=Dict.create();  | 
|                         dict.set("storageAmount",Convert.toBigDecimal(amount));  | 
|                         dict.set("storageMoney",new BigDecimal(money));  | 
|                         dict.set("price",price);  | 
|                         map.put(itemType,dict);  | 
|                     }  | 
|                 }  | 
|   | 
|   | 
|                 if(OrderEnum.回收型.getValue().equals(flag)&&weight!=null&&weight.compareTo(BigDecimal.ZERO)!=0){  | 
|   | 
|                     if(map.containsKey(itemType)){  | 
|                         Dict dict = map.get(itemType);  | 
|                         BigDecimal recyleweight1 = dict.getBigDecimal("recyleweight");  | 
|                         dict.set("recyleweight",NumberUtil.add(recyleweight1,weight));  | 
|                         BigDecimal recyleMoney1 = dict.getBigDecimal("recyleMoney");  | 
|                         dict.set("recyleMoney",NumberUtil.add(recyleMoney1,Convert.toBigDecimal(money)));  | 
|                         map.put(itemType,dict);  | 
|                     }else{  | 
|                         Dict dict=Dict.create();  | 
|                         dict.set("recyleweight",weight);  | 
|                         dict.set("recyleMoney",new BigDecimal(money));  | 
|                         dict.set("price",price);  | 
|                         map.put(itemType,dict);  | 
|                     }  | 
|                 }  | 
|   | 
|                 if(OrderEnum.回收型.getValue().equals(flag)&&amount!=null&&Convert.toBigDecimal(amount,BigDecimal.ZERO).compareTo(BigDecimal.ZERO)!=0){  | 
|   | 
|                     if(map.containsKey(itemType)){  | 
|                         Dict dict = map.get(itemType);  | 
|                         BigDecimal recyleAmount1 = dict.getBigDecimal("recyleAmount");  | 
|                         dict.set("recyleAmount",NumberUtil.add(recyleAmount1,Convert.toBigDecimal(amount)));  | 
|                         BigDecimal recyleMoney1 = dict.getBigDecimal("recyleMoney");  | 
|                         dict.set("recyleMoney",NumberUtil.add(recyleMoney1,Convert.toBigDecimal(money)));  | 
|                         map.put(itemType,dict);  | 
|                     }else{  | 
|                         Dict dict=Dict.create();  | 
|                         dict.set("recyleAmount",Convert.toBigDecimal(amount));  | 
|                         dict.set("recyleMoney",new BigDecimal(money));  | 
|                         dict.set("price",price);  | 
|                         map.put(itemType,dict);  | 
|                     }  | 
|                 }  | 
|             }  | 
|   | 
|   | 
|             if(MapUtil.isNotEmpty(map)){  | 
|                 List<OrderStorageDetailInfo> list=new ArrayList<>();  | 
|   | 
|   | 
|                 for (String s : map.keySet()) {  | 
|                     OrderStorageDetailInfo orderStorageDetailInfo1=new OrderStorageDetailInfo();  | 
|   | 
|                     //选取仓库价格  | 
|                     SysEnvironmentalInfo sysEnvironmentalInfo1=new SysEnvironmentalInfo();  | 
|                     if(Convert.toShort(OrderEnum.打包站.getValue()).equals(sysStorageType)){  | 
|                         PackageGoodsInfo byPackageId = packageGoodsInfoService.findByPackageIdAndItemType(sysStorageId.toString(),s);  | 
|                         BeanUtil.copyProperties(byPackageId,sysEnvironmentalInfo1);  | 
|                     }else if(Convert.toShort(OrderEnum.仓库.getValue()).equals(sysStorageType)){  | 
|                         SysStorage byId1 = sysStorageService.findById(Convert.toInt(sysStorageId));  | 
|                         Integer areaId = Convert.toInt(byId1.getArea());  | 
|                         sysEnvironmentalInfo1 = sysEnvironmentalInfoService.findByItemTypeAndArea(s, areaId);  | 
|                     }  | 
|   | 
|                     Dict dict = map.get(s);  | 
|                     String price = dict.getStr("price");  | 
|                     //设置分类价格等  | 
|                     orderStorageDetailInfo1.setItemTypeName(sysEnvironmentalInfo1.getTitle());  | 
|                     if(StrUtil.isNotBlank(price)){  | 
|                         orderStorageDetailInfo1.setItemTypePrice(price);  | 
|                     }else {  | 
|                         orderStorageDetailInfo1.setItemTypePrice(sysEnvironmentalInfo1.getPrice());  | 
|                     }  | 
|                     orderStorageDetailInfo1.setItemTypePicture(sysEnvironmentalInfo1.getPicture());  | 
|                     //上门价格  | 
|                     orderStorageDetailInfo1.setItemTypePrice2(sysEnvironmentalInfo1.getSecondPrice());  | 
|   | 
|                     BigDecimal recyleweight = dict.getBigDecimal("recyleweight");  | 
|                     BigDecimal recyleMoney = dict.getBigDecimal("recyleMoney");  | 
|                     BigDecimal recyleAmount = dict.getBigDecimal("recyleAmount");  | 
|                     BigDecimal storageWeight = dict.getBigDecimal("storageWeight");  | 
|                     BigDecimal storageMoney = dict.getBigDecimal("storageMoney");  | 
|                     BigDecimal storageAmount= dict.getBigDecimal("storageAmount");  | 
|   | 
|                     if(recyleweight!=null&&recyleweight.compareTo(BigDecimal.ZERO)!=0){  | 
|                         orderStorageDetailInfo1.setWeight(recyleweight);  | 
|                     }  | 
|   | 
|                     if(recyleMoney!=null&&recyleMoney.compareTo(BigDecimal.ZERO)!=0){  | 
|                         orderStorageDetailInfo1.setMoney(recyleMoney.toString());  | 
|                     }  | 
|   | 
|                     if(recyleAmount!=null&&recyleAmount.compareTo(BigDecimal.ZERO)!=0){  | 
|                         orderStorageDetailInfo1.setAmount(Convert.toStr(recyleAmount));  | 
|                     }  | 
|   | 
|                     if(storageWeight!=null&&storageWeight.compareTo(BigDecimal.ZERO)!=0){  | 
|                         orderStorageDetailInfo1.setStorageWeight(storageWeight);  | 
|                     }  | 
|   | 
|                     if(storageMoney!=null&&storageMoney.compareTo(BigDecimal.ZERO)!=0){  | 
|                         orderStorageDetailInfo1.setStorageMoney(storageMoney.toString());  | 
|                     }  | 
|   | 
|                     if(storageAmount!=null&&storageAmount.compareTo(BigDecimal.ZERO)!=0){  | 
|                         orderStorageDetailInfo1.setStorageAmount(storageAmount);  | 
|                     }  | 
|   | 
|                     list.add(orderStorageDetailInfo1);  | 
|                 }  | 
|   | 
|                 storageDetailBatchDto.setList(list);  | 
|             }  | 
|         }  | 
|   | 
|         //获取地称的  | 
|         OrderBatchInfo batchInfo=new OrderBatchInfo();  | 
|         | 
|         String orderId = orderStorageInfo.getOrderId();  | 
|         Example example1=new Example(OrderBatchInfo.class);  | 
|         Example.Criteria criteria1 = example1.createCriteria();  | 
|         criteria1.andEqualTo("orderId",orderId);  | 
|         criteria1.andEqualTo("status",OrderEnum.已入库.getValue());  | 
|         OrderBatchInfo orderBatchInfo = orderBatchInfoMapper.selectOneByExample(example1);  | 
|   | 
|         if(orderBatchInfo!=null){  | 
|             String weight = orderBatchInfo.getWeight();  | 
|             batchInfo.setWeight(weight);  | 
|   | 
|             OrderClockIn today = orderClockInMapper.findToday(orderStorageInfo.getReceiver(), StrUtil.split(orderBatchInfo.getCreateTime(),"")[0]);  | 
|             if(today!=null){  | 
|                 batchInfo.setEmptyWeight(today.getWeight());  | 
|             }  | 
|         }  | 
|   | 
|         //获取仓库名称  | 
|         if(Convert.toShort(OrderEnum.打包站.getValue()).equals(sysStorageType)){  | 
|             CityPartner sysStorage = cityPartnerService.findById(Convert.toInt(sysStorageId));  | 
|             if(sysStorage!=null){  | 
|                 orderStorageInfo.setSysStorageName(sysStorage.getPartnerName());  | 
|             }  | 
|         }else if(Convert.toShort(OrderEnum.仓库.getValue()).equals(sysStorageType)){  | 
|             SysStorage sysStorage = sysStorageMapper.selectByPrimaryKey(sysStorageId);  | 
|             if(sysStorage!=null){  | 
|                 orderStorageInfo.setSysStorageName(sysStorage.getStorageName());  | 
|             }  | 
|         }  | 
|   | 
|         storageDetailBatchDto.setOrderStorageInfo(orderStorageInfo);  | 
|   | 
|         //设置地称信息  | 
|         if(StrUtil.isBlank(batchInfo.getWeight())) {  | 
|             batchInfo.setWeight(Convert.toStr(Constants.WEIGHT_INIT));  | 
|         }  | 
|         if(StrUtil.isBlank(batchInfo.getEmptyWeight())) {  | 
|             batchInfo.setEmptyWeight(Convert.toStr(Constants.WEIGHT_INIT));  | 
|         }  | 
|         storageDetailBatchDto.setOrderBatchInfo(batchInfo);  | 
|         return storageDetailBatchDto;  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 查看回收订单  | 
|      * @param storageId  | 
|      * @return  | 
|      */  | 
|     public List<OrderDetailInfo> recyledDetail(String storageId) {  | 
|   | 
|         OrderStorageInfo orderStorageInfo = orderStorageInfoMapper.selectByPrimaryKey(storageId);  | 
|   | 
|         if(orderStorageInfo==null){  | 
|             throw new RestException(-1,"入库订单不存在");  | 
|         }  | 
|   | 
|         String orderId = orderStorageInfo.getOrderId();  | 
|   | 
|   | 
|         String[] split = orderId.split(",");  | 
|   | 
|   | 
|         List<OrderDetailInfo> list=new ArrayList<>();  | 
|         for (String s : split) {  | 
|             OrderDetailInfo orderDetailInfo = orderDetailMapper.selectByPrimaryKey(s);  | 
|             //地址  | 
|             Long addressId = orderDetailInfo.getAddressId();  | 
|             AddressInfo addressInfo = addressMapper.selectByPrimaryKey(addressId);  | 
|             orderDetailInfo.setAddress(StrUtil.nullToEmpty(addressInfo.getAddressArea())+addressInfo.getDetailAddress());  | 
|   | 
|             //重新赋值回收员真实名称  源于小程序这边存入的是昵称  | 
|             String receiverPhone = orderDetailInfo.getReceiverPhone();  | 
|             if(StrUtil.isNotBlank(receiverPhone)) {  | 
|                 OtherUserInfo otherUserInfo1 = otherUserService.findByMobileAndUserType(receiverPhone,CommonEnum.回收员.getValue());  | 
|                 if(otherUserInfo1!=null) {  | 
|                     orderDetailInfo.setReceiverName(otherUserInfo1.getName());  | 
|                 }  | 
|             }  | 
|   | 
|             //回收的物品  | 
|             OrderItemInfo orderItemInfo=new OrderItemInfo();  | 
|             orderItemInfo.setOrderId(s);  | 
|             List<OrderItemInfo> orderItemInfos = orderItemInfoMapper.select(orderItemInfo);  | 
|   | 
|             List<String> itemTypeNames=new ArrayList<>();  | 
|             if(CollUtil.isNotEmpty(orderItemInfos)){  | 
|                 List<OrderItemInfo> collect = orderItemInfos.stream().filter(x -> (StrUtil.isNotBlank(x.getWeight())&&Convert.toBigDecimal(x.getWeight()).compareTo(BigDecimal.ZERO)!=0)||(StrUtil.isNotBlank(x.getAmount())&&Convert.toBigDecimal(x.getAmount()).compareTo(BigDecimal.ZERO)!=0)).collect(Collectors.toList());  | 
|   | 
|                 if(CollUtil.isNotEmpty(collect)){  | 
|   | 
|                     for (OrderItemInfo itemInfo : collect) {  | 
|                         String itemType = itemInfo.getItemType();  | 
|                         SysEnvironmentalInfo sysEnvironmentalInfo1 =  sysEnvironmentalInfoService.findByItemTypeAndArea(itemType,Convert.toInt(Constants.TIANXIN_CODE));  | 
|                         if(sysEnvironmentalInfo1!=null) {  | 
|                             itemTypeNames.add(sysEnvironmentalInfo1.getTitle());  | 
|                         }  | 
|                     }  | 
|   | 
|   | 
|                     orderDetailInfo.setItemTypeName(CollUtil.join(itemTypeNames,"、"));  | 
|                 }  | 
|             }  | 
|   | 
|   | 
|             list.add(orderDetailInfo);  | 
|         }  | 
|   | 
|   | 
|         return list;  | 
|   | 
|   | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 统计  | 
|      * @param userId  | 
|      * @param userType  | 
|      * @return  | 
|      */  | 
|     public  RkStatisticsDto statistics(String userId,String userType,String data,String receiver){  | 
|         RkStatisticsDto rkStatisticsDto=new RkStatisticsDto();  | 
|         RkStatisticsStorageDto rkStatisticsStorageDto=new RkStatisticsStorageDto();  | 
|         RkStatisticsRecyleDto rkStatisticsRecyleDto=new RkStatisticsRecyleDto();  | 
|         Example example=new Example(OrderStorageInfo.class);  | 
|         Example.Criteria criteria = example.createCriteria();  | 
|         criteria.andEqualTo("storageStatus",OrderEnum.已入库.getValue());  | 
|         if(CommonEnum.回收员.getValue().equals(userType)){  | 
|             criteria.andEqualTo("receiver",userId);  | 
|         }else if(CommonEnum.入库员.getValue().equals(userType)||CommonEnum.打包员.getValue().equals(userType)){  | 
|             criteria.andEqualTo("storageUserId",userId);  | 
|         }else if(CommonEnum.打包站运营员.getValue().equals(userType)){  | 
|             criteria.andEqualTo("sysStorageType",OrderEnum.打包站.getValue());  | 
|             String partnerId = otherUserService.findById(userId).getPartnerId();  | 
|             criteria.andEqualTo("sysStorageId",partnerId);  | 
|         }else{  | 
|             throw new RestException(-1,"用户角色不正确");  | 
|         }  | 
|   | 
|   | 
|         /**********入库员*************/  | 
|         example.setOrderByClause("storage_time desc");  | 
|         List<OrderStorageInfo> orderStorageInfos = orderStorageInfoMapper.selectByExample(example);  | 
|         List<OrderStorageInfo> orderStorageInfosToday=new ArrayList<>();  | 
|         //按时间筛选  | 
|         List<OrderStorageInfo> orderStorageInfosTime=new ArrayList<>();  | 
|         if(CollUtil.isNotEmpty(orderStorageInfos)){  | 
|             rkStatisticsStorageDto.setNumSum(orderStorageInfos.size());  | 
|             BigDecimal weight=Constants.WEIGHT_INIT;  | 
|             BigDecimal money=Constants.MONEY_INIT;  | 
|             for (OrderStorageInfo orderStorageInfo : orderStorageInfos) {  | 
|                 if(StrUtil.isNotBlank(orderStorageInfo.getStorageTime())&&DateUtil.format(new Date(),DateUtils.DATE_FORMAT_YMD).equals(orderStorageInfo.getStorageTime().split(" ")[0])){  | 
|                     orderStorageInfosToday.add(orderStorageInfo);  | 
|                 }  | 
|                 if(StrUtil.isNotBlank(data)&&StrUtil.isNotBlank(orderStorageInfo.getStorageTime())&&DateUtil.formatDate(DateUtil.parseDate(data)).equals(orderStorageInfo.getStorageTime().split(" ")[0])){  | 
|                     orderStorageInfosTime.add(orderStorageInfo);  | 
|                 }  | 
|                 weight=NumberUtil.add(weight,Convert.toBigDecimal(orderStorageInfo.getStorageWeight()));  | 
|                 money=NumberUtil.add(money,Convert.toBigDecimal(orderStorageInfo.getStorageMoney()));  | 
|             }  | 
|             rkStatisticsStorageDto.setStorageMoneySum(money);  | 
|             rkStatisticsStorageDto.setStorageWeightSum(weight);  | 
|   | 
|             //当天入库  | 
|             if(CollUtil.isNotEmpty(orderStorageInfosToday)){  | 
|                 rkStatisticsStorageDto.setNum(orderStorageInfosToday.size());  | 
|                 BigDecimal weightToday=Constants.WEIGHT_INIT;  | 
|                 BigDecimal moneyToday=Constants.MONEY_INIT;  | 
|                 for (OrderStorageInfo orderStorageInfo : orderStorageInfosToday) {  | 
|                     weightToday=NumberUtil.add(weightToday,Convert.toBigDecimal(orderStorageInfo.getStorageWeight()));  | 
|                     moneyToday=NumberUtil.add(moneyToday,Convert.toBigDecimal(orderStorageInfo.getStorageMoney()));  | 
|                 }  | 
|                 rkStatisticsStorageDto.setStorageMoney(moneyToday);  | 
|                 rkStatisticsStorageDto.setStorageWeight(weightToday);  | 
|             }  | 
|   | 
|   | 
|             //按时间入库  | 
|             if(CollUtil.isNotEmpty(orderStorageInfosTime)){  | 
|   | 
|                 List<RkStatisticsStorageReceiverDto> receiverList=new ArrayList<>();  | 
|                 if(StrUtil.isNotBlank(receiver)){  | 
|                     BigDecimal weightToday=Constants.WEIGHT_INIT;  | 
|                     BigDecimal moneyToday=Constants.MONEY_INIT;  | 
|                     //根据回收员筛选  | 
|                     List<OrderStorageInfo> collect = orderStorageInfosTime.stream().filter(x -> receiver.equals(x.getReceiver())).collect(Collectors.toList());  | 
|                     for (OrderStorageInfo orderStorageInfo : collect) {  | 
|                         weightToday=NumberUtil.add(weightToday,Convert.toBigDecimal(orderStorageInfo.getStorageWeight()));  | 
|                         moneyToday=NumberUtil.add(moneyToday,Convert.toBigDecimal(orderStorageInfo.getStorageMoney()));  | 
|                     }  | 
|                     RkStatisticsStorageReceiverDto dto=new RkStatisticsStorageReceiverDto();  | 
|                     OtherUserInfo byId = otherUserService.findById(receiver);  | 
|                     dto.setUserId(byId.getUserId());  | 
|                     dto.setAvatar(byId.getAvatar());  | 
|                     dto.setName(byId.getName());  | 
|                     dto.setMoney(businessUtil.changeMoney(moneyToday));  | 
|                     dto.setWeight(businessUtil.changeWeight(weightToday.toString()));  | 
|                     dto.setTime(data);  | 
|                     receiverList.add(dto);  | 
|                 }else {  | 
|                     //按回收员分组  | 
|                     Map<String, List<OrderStorageInfo>> collect = orderStorageInfosTime.stream().collect(Collectors.groupingBy(x -> x.getReceiver()));  | 
|                     for (String s : collect.keySet()) {  | 
|                         BigDecimal weightToday=Constants.WEIGHT_INIT;  | 
|                         BigDecimal moneyToday=Constants.MONEY_INIT;  | 
|                         RkStatisticsStorageReceiverDto dto=new RkStatisticsStorageReceiverDto();  | 
|                         OtherUserInfo byId = otherUserService.findById(s);  | 
|                         dto.setUserId(byId.getUserId());  | 
|                         dto.setAvatar(byId.getAvatar());  | 
|                         dto.setName(byId.getName());  | 
|                         for (OrderStorageInfo orderStorageInfo : collect.get(s)) {  | 
|                             weightToday=NumberUtil.add(weightToday,Convert.toBigDecimal(orderStorageInfo.getStorageWeight()));  | 
|                             moneyToday=NumberUtil.add(moneyToday,Convert.toBigDecimal(orderStorageInfo.getStorageMoney()));  | 
|                         }  | 
|                         dto.setMoney(businessUtil.changeMoney(moneyToday));  | 
|                         dto.setWeight(businessUtil.changeWeight(weightToday.toString()));  | 
|                         dto.setTime(data);  | 
|                         receiverList.add(dto);  | 
|                     }  | 
|                 }  | 
|                 rkStatisticsStorageDto.setReceiverList(receiverList);  | 
|             }  | 
|   | 
|   | 
|             //回收员赋值入库信息  | 
|             if(CommonEnum.回收员.getValue().equals(userType)) {  | 
|                 BeanUtils.copyProperties(rkStatisticsStorageDto, rkStatisticsRecyleDto);  | 
|                 rkStatisticsRecyleDto.setNum(0);  | 
|                 rkStatisticsRecyleDto.setNumSum(0);  | 
|             }  | 
|         }  | 
|   | 
|         /**********回收员*************/  | 
|         if(CommonEnum.回收员.getValue().equals(userType)){  | 
|             List<OrderDetailInfo> orderRecyleInfosToday=new ArrayList<>();  | 
|             List<OrderDetailInfo> orderInfos = orderDetailService.findByReceiver(userId);  | 
|             if(CollUtil.isNotEmpty(orderInfos)){  | 
|                 rkStatisticsRecyleDto.setNumSum(orderInfos.size());  | 
|                 BigDecimal weight=Constants.WEIGHT_INIT;  | 
|                 BigDecimal money=Constants.MONEY_INIT;  | 
|                 for (OrderDetailInfo orderInfo : orderInfos) {  | 
|                     if(StrUtil.isNotBlank(orderInfo.getCompleteTime())&&DateUtil.format(new Date(),DateUtils.DATE_FORMAT_YMD).equals(orderInfo.getCompleteTime().split(" ")[0])){  | 
|                         orderRecyleInfosToday.add(orderInfo);  | 
|                     }  | 
|                     weight=NumberUtil.add(weight,Convert.toBigDecimal(orderInfo.getWeight()));  | 
|                     money=NumberUtil.add(money,Convert.toBigDecimal(orderInfo.getMoney()));  | 
|                 }  | 
|                 rkStatisticsRecyleDto.setRecycleMoneySum(money);  | 
|                 rkStatisticsRecyleDto.setRecycleWeightSum(weight);  | 
|   | 
|                 if(CollUtil.isNotEmpty(orderRecyleInfosToday)){  | 
|                     rkStatisticsRecyleDto.setNum(orderRecyleInfosToday.size());  | 
|                     BigDecimal weightToday=Constants.WEIGHT_INIT;  | 
|                     BigDecimal moneyToday=Constants.MONEY_INIT;  | 
|                     for (OrderDetailInfo orderStorageInfo : orderRecyleInfosToday) {  | 
|                         weightToday=NumberUtil.add(weightToday,Convert.toBigDecimal(orderStorageInfo.getWeight()));  | 
|                         moneyToday=NumberUtil.add(moneyToday,Convert.toBigDecimal(orderStorageInfo.getMoney()));  | 
|                     }  | 
|                     rkStatisticsRecyleDto.setRecycleMoney(moneyToday);  | 
|                     rkStatisticsRecyleDto.setRecycleWeight(weightToday);  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         if(CommonEnum.回收员.getValue().equals(userType)){  | 
|             rkStatisticsDto.setRkStatisticsRecyleDto(rkStatisticsRecyleDto);  | 
|         }else{  | 
|             rkStatisticsDto.setStatisticsStorageDto(rkStatisticsStorageDto);  | 
|         }  | 
|         return  rkStatisticsDto;  | 
|     }  | 
|   | 
|     /**  | 
|      * 入库  | 
|      * @param rk  | 
|      */  | 
|     public  void rk(RkDto rk){  | 
|         boolean lock=false;  | 
|         try {  | 
|             if(redisUtil.setnx(Constants.REDIS_ORDER_KEY+"rk:"+rk.getStorageId(),rk.getStorageId())) {  | 
|                 lock=true;  | 
|   | 
|   | 
|                 String now = DateUtil.now();  | 
|                 OtherUserInfo otherUserInfo = otherUserMapper.selectByPrimaryKey(rk.getStorageUserId());  | 
|                 //修改入库信息  | 
|                 Example example = new Example(OrderStorageInfo.class);  | 
|                 Example.Criteria criteria = example.createCriteria();  | 
|                 criteria.andEqualTo("storageId", rk.getStorageId());  | 
|                 OrderStorageInfo orderStorageInfo = orderStorageInfoMapper.selectOneByExample(example);  | 
|                 if (orderStorageInfo == null) {  | 
|                     throw new RestException(-1, "入库单不存在");  | 
|                 }  | 
|   | 
|                 Map map = new HashMap();  | 
|                 map.put("userId", orderStorageInfo.getReceiver());  | 
|                 List<AccountVo> receiverAccounts = accountMapper.queryMyMoney(map);  | 
|                 if(CollUtil.isEmpty(receiverAccounts)){  | 
|                     throw new RestException(-1, "回收员账户已被禁用");  | 
|                 }  | 
|   | 
|                 //检验是否已入库  | 
|                 if (orderStorageInfo.getStorageStatus().toString().equals(OrderEnum.已入库.getValue())) {  | 
|                     throw new RestException(-1, "订单已入库");  | 
|                 }  | 
|                 orderStorageInfo.setStorageUserId(rk.getStorageUserId());  | 
|                 orderStorageInfo.setStorageUserName(otherUserInfo.getName());  | 
|                 orderStorageInfo.setStorageUserPhone(otherUserInfo.getMobilePhone());  | 
|                 orderStorageInfo.setStorageTime(now);  | 
|                 orderStorageInfo.setStorageWeight(rk.getStorageWeight());  | 
|                 orderStorageInfo.setStorageMoney(Convert.toBigDecimal(rk.getStorageMoney()));  | 
|   | 
|                 int usertype=0;  | 
|                 String packageId=null;  | 
|                 if(otherUserInfo.getUserType().equals(CommonEnum.打包员.getValue())||otherUserInfo.getUserType().equals(CommonEnum.打包站运营员.getValue())) {  | 
|                     usertype = 2;  | 
|                     packageId = otherUserInfo.getPartnerId();  | 
|                 }else if(otherUserInfo.getUserType().equals(CommonEnum.入库员.getValue())){  | 
|                     usertype=1;  | 
|                 }  | 
|                 Map map2 = new HashMap();  | 
|                 map2.put("userId", rk.getStorageUserId());  | 
|                 List<AccountVo> storageAccount = accountMapper.queryMyMoney(map2);  | 
|                 if(CollUtil.isEmpty(storageAccount)){  | 
|                         throw new RestException(-1, "账户已被禁用");  | 
|                 }  | 
|                 AccountVo accountVo = storageAccount.get(0);  | 
|                 String overdraftLimit = accountVo.getOverdraftLimit();  | 
|                 BigDecimal limit = Convert.toBigDecimal(overdraftLimit, Constants.MONEY_INIT);  | 
|                 BigDecimal moneyDecimal=Convert.toBigDecimal(rk.getStorageMoney());  | 
|                 BigDecimal moneyDB = Convert.toBigDecimal(accountVo.getMoney(), Constants.MONEY_INIT);  | 
|                 if(usertype==2) {  | 
|                     if (NumberUtil.isLess(NumberUtil.add(limit, moneyDB), moneyDecimal)) {  | 
|                         throw new RestException(-1, "额度不足");  | 
|                     }  | 
|                 }else if(usertype==1){  | 
|                     //判断仓管员额度是否足够  | 
|                     if (NumberUtil.isGreater(moneyDecimal, limit)) {  | 
|                         throw new RestException(-1, "额度不足");  | 
|                     }  | 
|                 }  | 
|   | 
|                 orderStorageInfo.setStorageStatus(Convert.toShort(OrderEnum.已入库.getValue()));  | 
|   | 
|                 if(usertype==1){  | 
|                     //仓库ID  地磅必须在入库才知道入库id  | 
|                     OtherUserInfo byId = otherUserService.findById(rk.getStorageUserId());  | 
|                     orderStorageInfo.setSysStorageId(Convert.toLong(byId.getStorageId()));  | 
|                 }  | 
|   | 
|                 //查询废纸分类的单价  合伙人存在多个区域则按最低的单价算  | 
|                 String paperBasic=null;  | 
|                 String partnerId = otherUserService.findById(orderStorageInfo.getReceiver()).getPartnerId();  | 
|                 List<PartnerGaode> byPartnerId = partnerGaodeService.findByPartnerId(partnerId);  | 
|                 List<String> areaIds=byPartnerId.stream().map(x->x.getTownId()).collect(Collectors.toList());  | 
|                 if(usertype==2) {  | 
|                     paperBasic = sysEnvironmentalInfoService.findByMinItemPriceTypeAndAreaIds(areaIds);  | 
|                     if (paperBasic==null) {  | 
|                         throw new RestException(-1,"请设置纸类的基准价格");  | 
|                     }  | 
|                 }  | 
|   | 
|   | 
|                 orderStorageInfoMapper.updateByPrimaryKeySelective(orderStorageInfo);  | 
|                 OrderBatchInfo orderBatchInfo = new OrderBatchInfo();  | 
|                 orderBatchInfo.setStatus(Convert.toShort(OrderEnum.已入库.getValue()));  | 
|                 Example example1 = new Example(OrderBatchInfo.class);  | 
|                 example1.createCriteria().andEqualTo("orderId", orderStorageInfo.getOrderId());  | 
|                 //修改批次信息  | 
|                 orderBatchInfoMapper.updateByExampleSelective(orderBatchInfo, example1);  | 
|                 //修改物品分类信息  | 
|                 List<WeightItemPrice> list=new ArrayList<>();  | 
|   | 
|                 BigDecimal paperWeight=BigDecimal.ZERO;  | 
|                 //纸类的所有小类集合  | 
|                 List<String> paperChildType=CollUtil.newArrayList();  | 
|                 if(usertype==2) {  | 
|                     paperChildType = packageGoodsInfoService.findChildItemTypeByType(packageId, Constants.PAPER_ITEM_TYPE);  | 
|                 }  | 
|                 for (OrderItemDto orderItemReq : rk.getStorageItemList()) {  | 
|                     //修改入库的金额 和数量 重量  | 
|                     OrderStorageDetailInfo detailInfo = new OrderStorageDetailInfo();  | 
|                     detailInfo.setWeight(Convert.toBigDecimal(orderItemReq.getWeight(),Constants.WEIGHT_INIT));  | 
|                     detailInfo.setMoney(orderItemReq.getMoney());  | 
|                     detailInfo.setAmount(orderItemReq.getAmount());  | 
|                     detailInfo.setPrice(orderItemReq.getItemTypePrice());  | 
|   | 
|                     Example example2 = new Example(OrderStorageDetailInfo.class);  | 
|                     Example.Criteria criteria2 = example2.createCriteria();  | 
|                     criteria2.andEqualTo("storageId", rk.getStorageId());  | 
|                     criteria2.andEqualTo("flag", OrderEnum.入库型.getValue());  | 
|                     criteria2.andEqualTo("itemType", orderItemReq.getItemType());  | 
|                     orderStorageDetailMapper.updateByExampleSelective(detailInfo, example2);  | 
|   | 
|                     if(usertype==2) {  | 
|   | 
|                         if(orderItemReq.getWeight().compareTo(BigDecimal.ZERO)>0){  | 
|                             //计算出所有纸类的重量  | 
|                             if(paperChildType.contains(orderItemReq.getItemType())){  | 
|                                 paperWeight=NumberUtil.add(paperWeight,orderItemReq.getWeight());  | 
|                             }  | 
|                         }  | 
|   | 
|                         //提成明细  | 
|                         if (detailInfo.getWeight().compareTo(BigDecimal.ZERO) > 0) {  | 
|                             WeightItemPrice weightItemPrice = new WeightItemPrice();  | 
|                             weightItemPrice.setStorageId(rk.getStorageId());  | 
|                             weightItemPrice.setStorageTime(now);  | 
|                             weightItemPrice.setPackageId(orderStorageInfo.getSysStorageId().toString());  | 
|                             weightItemPrice.setWeight(detailInfo.getWeight().toString());  | 
|                             weightItemPrice.setReceiver(orderStorageInfo.getReceiver());  | 
|                             weightItemPrice.setProductType(orderItemReq.getItemType());  | 
|                             weightItemPrice.setPackagePrice(orderItemReq.getItemTypePrice());  | 
|                             weightItemPrice.setGoodsPrice(paperBasic);  | 
|                             //1:未审核,2:已审核 3:异常  | 
|                             weightItemPrice.setStatus("1");  | 
|                             list.add(weightItemPrice);  | 
|                         }  | 
|                     }  | 
|   | 
|                 }  | 
|   | 
|                 //添加提成明细  | 
|                 if(CollUtil.isNotEmpty(list)){  | 
|                     weightItemPriceService.addBatch(list);  | 
|                 }  | 
|   | 
|                 String payType="";  | 
|                 //修改订单相关  | 
|                 int i=0;  | 
|   | 
|                 List<OrderInfo> listOrder=new ArrayList<>();  | 
|                 for (String orderId : orderStorageInfo.getOrderId().split(",")) {  | 
|   | 
|                     //修改订单信息  | 
|                     OrderInfo orderInfo = new OrderInfo();  | 
|                     orderInfo.setOrderId(orderId);  | 
|                     orderInfo.setOrderStatus(OrderEnum.完成.getValue());  | 
|                     listOrder.add(orderInfo);  | 
| //                    orderMapper.updateByPrimaryKeySelective(orderInfo);  | 
|   | 
|                     if(i==0) {  | 
|                         PayInfo payInfo = new PayInfo();  | 
|                         payInfo.setOrderId(orderId);  | 
|                         payInfo.setCreateUserId(orderStorageInfo.getReceiver());  | 
|                         List<PayInfo> select = payInfoMapper.select(payInfo);  | 
|                         if (CollUtil.isNotEmpty(select)) {  | 
|                             String payType1 = select.get(0).getPayType();  | 
|                             if (PayEnum.现金支出.getValue().equals(payType1) || PayEnum.现金收入.getValue().equals(payType1)) {  | 
|                                 payType = PayEnum.现金支出.getValue();  | 
|                             } else {  | 
|                                 payType = PayEnum.环保金支出.getValue();  | 
|                             }  | 
|                         }  | 
|                     }  | 
|                     //修改订单详情信息   冗余字段暂时废弃  | 
| //                    OrderDetailInfo orderDetailInfo = new OrderDetailInfo();  | 
| //                    orderDetailInfo.setStorageMoney(Convert.toStr(rk.getStorageMoney()));  | 
| //                    orderDetailInfo.setStorageUserId(orderStorageInfo.getStorageUserId());  | 
| //                    orderDetailInfo.setStorageUserName(orderStorageInfo.getStorageUserName());  | 
| //                    orderDetailInfo.setStorageUserPhone(orderStorageInfo.getStorageUserPhone());  | 
| //                    Example example2 = new Example(OrderDetailInfo.class);  | 
| //                    example2.createCriteria().andEqualTo("orderId", orderId);  | 
| //                    orderDetailMapper.updateByExampleSelective(orderDetailInfo, example2);  | 
|                     i++;  | 
|                 }  | 
|   | 
|                 //批量修改订单状态  | 
|                 if(CollUtil.isNotEmpty(listOrder)){  | 
|                     orderBatchMapper.updateBatchByPrimaryKeySelective(listOrder);  | 
|                 }  | 
|   | 
|                 OrderInfoReq orderInfoReq = new OrderInfoReq();  | 
|                 orderInfoReq.setNewVersion(true);  | 
|                 orderInfoReq.setReceiver(orderStorageInfo.getReceiver());  | 
|                 orderInfoReq.setStorageUserId(orderStorageInfo.getStorageUserId());  | 
|                 orderInfoReq.setPayType(payType);  | 
|                 orderInfoReq.setStorageMoney(Convert.toStr(rk.getStorageMoney()));  | 
|                 orderInfoReq.setOrderId(orderStorageInfo.getOrderId());  | 
|                 orderInfoReq.setStorageId(orderStorageInfo.getStorageId());  | 
|                 orderInfoReq.setVersion(rk.getVersion());  | 
|                 if(paperBasic!=null){  | 
|                     orderInfoReq.setPaperMoney(NumberUtil.mul(Convert.toBigDecimal(paperBasic),paperWeight));  | 
|                 }  | 
|                 //录入支付记录  | 
|                 AccountVo receiverAccount=receiverAccounts.get(0);  | 
| //                orderService.storageOperInfo(orderInfoReq, orderStorageInfo.getStorageId(), now, accountId);  | 
|                 //更改账户信息  | 
|                 orderService.storageAccount(orderInfoReq, receiverAccount,accountVo,usertype,partnerId);  | 
|   | 
|                 //推广返利  | 
|                 AllAcountParamDto allAcountParamDto=AllAcountParamDto.builder().  | 
|                         type(6).flowNo(orderStorageInfo.getOrderId()).userId(orderInfoReq.getStorageUserId())  | 
|                         .build();  | 
| //                accountFactory.getService(6).account(allAcountParamDto);  | 
|                 new AccountContext(promotionRebateService).account(allAcountParamDto);  | 
|   | 
|                 //入库消息  | 
|                 orderService.storageMessage(orderInfoReq, now);  | 
|   | 
|                 //删除回收员的入库错误次数  | 
|                 redisUtil.hdel(Constants.REDIS_ORDER_KEY + "storage:errcount", orderStorageInfo.getReceiver());  | 
|             }  | 
|         } catch (RestException e){  | 
|             throw  new BusinessException(-1,e.getMsg(),ExceptionUtil.getMessage(e));  | 
|         }catch (Exception e) {  | 
|             ExceptionUtils.err("入库失败",e);  | 
|         }finally {  | 
|             if(lock) {  | 
|                 redisUtil.del(Constants.REDIS_ORDER_KEY + "rk:" + rk.getStorageId());  | 
|             }  | 
|         }  | 
|   | 
|   | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 已完成订单列表查询  | 
|      * @param simplePage  | 
|      * @param userId  | 
|      * @return  | 
|      */  | 
|     public   List<OrderStorageInfo>  findCompleteOrder(SimplePage simplePage,String userId){  | 
|         Example example=new Example(OrderStorageInfo.class);  | 
|         Example.Criteria criteria = example.createCriteria();  | 
|         criteria.andEqualTo("storageStatus",Convert.toShort(0));  | 
|         //rk代表入库员已完成列表查询接口  | 
|         if(StrUtil.isBlank(simplePage.getExtra())){  | 
|             criteria.andEqualTo("receiver",userId);  | 
|         }else{  | 
|             criteria.andEqualTo("storageUserId",userId);  | 
|         }  | 
|         example.setOrderByClause("storage_time desc");  | 
|         PageHelper.startPage(simplePage.getPageNo(),simplePage.getPageSize());  | 
|         List<OrderStorageInfo> select = orderStorageInfoMapper.selectByExample(example);  | 
|         //查看是否是定点下单 不可能混合 否则会拆分成2个入库单  | 
|         if(CollUtil.isNotEmpty(select)){  | 
|             for (OrderStorageInfo orderStorageInfo : select) {  | 
| //                String orderId = orderStorageInfo.getOrderId();  | 
| //                String s = orderId.split(",")[0];  | 
| //                OrderInfo orderInfo = orderMapper.selectByPrimaryKey(s);  | 
| //                if(orderInfo!=null) {  | 
| //                    orderStorageInfo.setStoreId(orderInfo.getStoreId());  | 
| //                }  | 
|                 String weight = orderStorageInfo.getStorageWeight();  | 
|                 String recycleWeight = orderStorageInfo.getRecycleWeight();  | 
|                 if(StrUtil.isBlank(weight)){  | 
|                     orderStorageInfo.setStorageWeight(Constants.WEIGHT_INIT.toString());  | 
|                 }  | 
|                 if(StrUtil.isBlank(recycleWeight)){  | 
|                     orderStorageInfo.setRecycleWeight(Constants.WEIGHT_INIT.toString());  | 
|                 }  | 
|   | 
|             }  | 
|         }  | 
|         //如果是入库员 需要显示回收员名字和其所属的车辆编号  | 
|         if(StrUtil.isNotBlank(simplePage.getExtra())) {  | 
|             for (OrderStorageInfo orderStorageInfo : select) {  | 
|                 String receiver = orderStorageInfo.getReceiver();  | 
|                 orderStorageInfo.setReceiverName(otherUserService.findById(receiver).getName());  | 
|                 VehicleInfo byUserId = userVehicleInfoService.findByUserId(receiver);  | 
|                 if (byUserId != null) {  | 
|                     orderStorageInfo.setVehicleNo(byUserId.getVehicleNo());  | 
|                 }  | 
|             }  | 
|         }else {  | 
|             //回收员  | 
|             for (OrderStorageInfo orderStorageInfo : select) {  | 
|                 String orderId = orderStorageInfo.getOrderId();  | 
|                 String[] split = orderId.split(",");  | 
|                 if(ArrayUtil.isNotEmpty(split)&&split.length==1){  | 
|                     orderId=split[0];  | 
|                     OrderInfo byId = orderService.findById(orderId);  | 
|                     //设置订单状态  | 
|                     orderStorageInfo.setOrderType(byId.getOrderType());  | 
|   | 
|                     if(OrderEnum.到家服务.getValue().equals(byId.getOrderType())){  | 
|                         orderStorageInfo.setRelaPhone(byId.getRelaPhone());  | 
|                         orderStorageInfo.setCreateUserId(byId.getCreateUserId());  | 
|                         orderStorageInfo.setOrderId(byId.getOrderId());  | 
|                     }else if(OrderEnum.家电回收.getValue().equals(byId.getOrderType())){  | 
|                         OrderDetailInfo byId1 = orderDetailService.findById(orderId);  | 
|                         Long homeApplianceId = byId1.getHomeApplianceId();  | 
|                         //家电下单的家电信息  | 
|                         if(homeApplianceId!=null) {  | 
|                             OrderHomeAppliance byOrderId = orderHomeApplianceService.findById(homeApplianceId);  | 
|                             orderStorageInfo.setOrderHomeAppliance(byOrderId);  | 
|                         }  | 
|                     }  | 
|   | 
|   | 
|                 }  | 
|             }  | 
|         }  | 
|         return select;  | 
|     }  | 
|   | 
|     /**  | 
|      * 已完成订单列表个数  | 
|      * @return  | 
|      */  | 
|     public   int  countCompleteOrder(String userId){  | 
|         Example example=new Example(OrderStorageInfo.class);  | 
|         Example.Criteria criteria = example.createCriteria();  | 
|         criteria.andEqualTo("storageStatus",Convert.toShort(OrderEnum.已入库.getValue()));  | 
|         criteria.andEqualTo("storageUserId",userId);  | 
|         int select = orderStorageInfoMapper.selectCountByExample(example);  | 
|         return select;  | 
|     }  | 
|   | 
|     /**  | 
|      * 新任务订单列表个数  | 
|      * @return  | 
|      */  | 
|     public   int  countStorageOrder(String userId){  | 
|         Example example=new Example(OrderStorageInfo.class);  | 
|         Example.Criteria criteria = example.createCriteria();  | 
|         criteria.andEqualTo("storageStatus",Convert.toShort(OrderEnum.入库检验中.getValue()));  | 
|         criteria.andEqualTo("storageUserId",userId);  | 
|         int select = orderStorageInfoMapper.selectCountByExample(example);  | 
|         return select;  | 
|     }  | 
|   | 
|   | 
|   | 
|     /**  | 
|      * 手动扫码入库新任务详情  | 
|      *  | 
|      * @param request  | 
|      * @param userId  | 
|      * @param usertype 1入库 2打包  | 
|      * @return  | 
|      */  | 
|     public Result<RkDto> rkDetail(HttpServletRequest request, String userId, int usertype, String packageId) {  | 
|         Result<RkDto> result = new Result();  | 
|         RkDto rk = new RkDto();  | 
|   | 
|         String key=Constants.REDIS_ORDER_KEY+"rkscan:"+request.getHeader("userId");  | 
|         if(redisUtil.setnx(key,"0")) {  | 
|   | 
|             try {  | 
|                 //获取用户所有待入库订单  | 
|                 List<OrderInfo> orderInfos = orderService.findDetailByReceiverAndStatus(userId, OrderEnum.待入库.getValue());  | 
|                 if (CollUtil.isEmpty(orderInfos)) {  | 
|                     return Result.error(-1, "没有待入库的订单");  | 
|                 }  | 
|   | 
|   | 
|                 //定点回收  | 
|                 List<String> collect1 = orderInfos.stream().filter(x -> x.getStoreId() != null).map(OrderInfo::getOrderId).collect(Collectors.toList());  | 
|   | 
|                 //上门回收  | 
|                 List<String> collect2 = orderInfos.stream().filter(x -> x.getStoreId() == null).map(OrderInfo::getOrderId).collect(Collectors.toList());  | 
|   | 
|                 //1为上门 2为定点  | 
|                 int type = 0;  | 
|   | 
|                 Dict dict = null;  | 
|                 if (CollUtil.isNotEmpty(collect1)) {  | 
|                     type = 2;  | 
|                     String storageId = idUtils.generate("RK", 0);  | 
|                     dict = orderBatchInfoService.addDB(userId, collect1, storageId, usertype, packageId);  | 
|                 }  | 
|   | 
|                 if (CollUtil.isNotEmpty(collect2)) {  | 
|                     type = 1;  | 
|                     String storageId = idUtils.generate("RK", 2);  | 
|                     dict = orderBatchInfoService.addDB(userId, collect2, storageId, usertype, packageId);  | 
|                 }  | 
|   | 
|   | 
|                 //混合订单直接返回到列表  | 
|                 if (CollUtil.isNotEmpty(collect1) && CollUtil.isNotEmpty(collect2)) {  | 
|                     rk.setMixOrder(true);  | 
|                     result.setData(rk);  | 
|                     return result;  | 
|                 }  | 
|   | 
|                 List<OrderItemDto> orderItemDtos = new ArrayList<>();  | 
|                 List<OrderStorageDetailInfo> select = (List<OrderStorageDetailInfo>) dict.get("detail");  | 
|                 //设置分类  | 
|                 setItem(rk, orderItemDtos, select, usertype, packageId);  | 
|                 rk.setStorageUserId(request.getHeader("userId"));  | 
|                 rk.setStorageId(dict.getStr("storageId"));  | 
|                 OrderInfoReq orderInfoReq = new OrderInfoReq();  | 
|                 orderInfoReq.setReceiver(userId);  | 
|                 List<String> strings = orderMapper.fwOrderListByUserId(orderInfoReq);  | 
|                 if (CollUtil.isNotEmpty(strings)) {  | 
|                     rk.setFwOrderNum(strings.size());  | 
|                 }  | 
|                 //回收金额  | 
|                 String recycleMoney = dict.getStr("recycleMoney");  | 
|                 rk.setMoney(recycleMoney);  | 
|                 result.setData(rk);  | 
|             } catch (Exception e) {  | 
|                 ExceptionUtils.err("扫码入库失败",e);  | 
|             } finally {  | 
|                 redisUtil.del(key);  | 
|             }  | 
|             return result;  | 
|         }else {  | 
|             throw new RestException(-1,"二维码已被扫码");  | 
|         }  | 
|   | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 设置分类信息  | 
|      * @param rk  | 
|      * @param orderItemDtos  | 
|      * @param select  | 
|      */  | 
|     public void setItem(RkDto rk, List<OrderItemDto> orderItemDtos, List<OrderStorageDetailInfo> select,  int usertype, String packageId) {  | 
|         //入库根据仓库所属地查看价格  | 
|         Long parentId = null;  | 
|   | 
|         if (usertype == 1) {  | 
|             SysStorage byId1 = sysStorageService.findById(Convert.toInt(packageId));  | 
|             Integer areaId = Convert.toInt(byId1.getArea());  | 
|             SysEnvironmentalInfo sysEnvironmentalInfo2 = sysEnvironmentalInfoService.findByItemTypeAndArea(Constants.HOUSE_HOLD_ITEM_TYPE,areaId);  | 
|             if (sysEnvironmentalInfo2 != null) {  | 
|                 parentId = sysEnvironmentalInfo2.getId();  | 
|             }  | 
|             if (CollUtil.isNotEmpty(select)) {  | 
|                 for (OrderStorageDetailInfo detailInfo : select) {  | 
|                     OrderItemDto orderItemDto = new OrderItemDto();  | 
|                     BeanUtils.copyProperties(detailInfo, orderItemDto);  | 
|   | 
|                     //设置分类名称和图片  | 
|                     String itemType = detailInfo.getItemType();  | 
|                     SysEnvironmentalInfo sysEnvironmentalInfo1 = null;  | 
|                     sysEnvironmentalInfo1 = sysEnvironmentalInfoService.findByItemTypeAndArea(itemType, areaId);  | 
|   | 
|                     if (sysEnvironmentalInfo1 != null) {  | 
|   | 
|   | 
|                         Long parentId1 = sysEnvironmentalInfo1.getParentId();  | 
|                         if (parentId != null && parentId.intValue() == (parentId1.intValue())) {  | 
|                             orderItemDto.setHouseHold(true);  | 
|                             BigDecimal mul = NumberUtil.mul(Convert.toBigDecimal(sysEnvironmentalInfo1.getPutStoragePrice()), Convert.toBigDecimal(orderItemDto.getAmount(), Constants.MONEY_INIT));  | 
|                             orderItemDto.setMoney(businessUtil.changeMoney(mul));  | 
|                         }else {  | 
|                             BigDecimal mul = NumberUtil.mul(Convert.toBigDecimal(sysEnvironmentalInfo1.getPutStoragePrice()), Convert.toBigDecimal(orderItemDto.getWeight(), Constants.MONEY_INIT));  | 
|                             orderItemDto.setMoney(businessUtil.changeMoney(mul));  | 
|                         }  | 
|                         orderItemDto.setItemPic(sysEnvironmentalInfo1.getPicture());  | 
|                         orderItemDto.setItemName(sysEnvironmentalInfo1.getTitle());  | 
|                         orderItemDto.setItemTypePrice(sysEnvironmentalInfo1.getPutStoragePrice().toString());  | 
| //                        if (type == 1) {  | 
| //                            orderItemDto.setItemTypePrice(sysEnvironmentalInfo1.getPutStoragePrice().toString());  | 
| //                        } else if (type == 2) {  | 
| //                            orderItemDto.setItemTypePrice(sysEnvironmentalInfo1.getSecondPrice());  | 
| //                        }  | 
|   | 
|                         //查找父类的itemType  | 
|                         SysEnvironmentalInfo byId = null;  | 
|                         byId = sysEnvironmentalInfoService.findById(parentId1);  | 
|                         if (byId != null) {  | 
|                             orderItemDto.setParentItemType(byId.getItemType());  | 
|                         }  | 
|                         orderItemDtos.add(orderItemDto);  | 
|                     }  | 
|                 }  | 
|                 //按重量降序排序  | 
|                 List<OrderItemDto> collect = orderItemDtos.stream().sorted(Comparator.comparing(OrderItemDto::getWeight).reversed()).collect(Collectors.toList());  | 
|                 rk.setStorageItemList(collect);  | 
|             }  | 
|         } else if (usertype == 2) {  | 
|             List<PackageGoodsInfo> byPackageId = packageGoodsInfoService.findByPackageId(packageId);  | 
|             if (CollUtil.isNotEmpty(byPackageId)) {  | 
|                 for (PackageGoodsInfo packageGoodsInfo : byPackageId) {  | 
|                     OrderItemDto orderItemDto = new OrderItemDto();  | 
|                     orderItemDto.setAmount("0");  | 
|                     orderItemDto.setWeight(Constants.WEIGHT_INIT);  | 
|                     orderItemDto.setMoney(Constants.MONEY_INIT.toString());  | 
|                     orderItemDto.setItemType(packageGoodsInfo.getItemType());  | 
|                     //设置分类名称和图片  | 
|                     Long parentId1 = packageGoodsInfo.getParentId();  | 
|                     if (parentId != null && parentId.intValue() == (parentId1.intValue())) {  | 
|                         orderItemDto.setHouseHold(true);  | 
|                     }  | 
|                     orderItemDto.setItemPic(packageGoodsInfo.getPicture());  | 
|                     orderItemDto.setItemName(packageGoodsInfo.getTitle());  | 
|   | 
|                     orderItemDto.setItemTypePrice(packageGoodsInfo.getPutStoragePrice().toString());  | 
| //                    if (type == 1) {  | 
| //                        orderItemDto.setItemTypePrice(packageGoodsInfo.getPrice());  | 
| //                    } else if (type == 2) {  | 
| //                        orderItemDto.setItemTypePrice(packageGoodsInfo.getSecondPrice());  | 
| //                    }  | 
|   | 
|                     //查找父类的itemType  | 
|                     SysEnvironmentalInfo byId = null;  | 
|                     packageGoodsInfo = packageGoodsInfoService.findById(parentId1);  | 
|                     if (packageGoodsInfo != null) {  | 
|                         byId = new SysEnvironmentalInfo();  | 
|                         BeanUtil.copyProperties(packageGoodsInfo, byId);  | 
|                     }  | 
|                     if (byId != null) {  | 
|                         orderItemDto.setParentItemType(byId.getItemType());  | 
|                     }  | 
|                     orderItemDtos.add(orderItemDto);  | 
|                 }  | 
|                 rk.setStorageItemList(orderItemDtos);  | 
|             }  | 
|   | 
|         }  | 
|   | 
|     }  | 
|   | 
|   | 
| }  |