|  |  | 
 |  |  | package com.matrix.system.activity.service; | 
 |  |  |  | 
 |  |  | import cn.hutool.core.collection.CollUtil; | 
 |  |  | import cn.hutool.core.util.ObjectUtil; | 
 |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | 
 |  |  | import com.matrix.system.activity.dao.ActivitySignAwardSetDao; | 
 |  |  | import com.matrix.system.activity.dao.ActivitySignReceiveRecordDao; | 
 |  |  | import com.matrix.system.activity.dao.ActivitySignWriteoffDao; | 
 |  |  | import com.matrix.system.activity.dto.LogisticsSubmitDto; | 
 |  |  | import com.matrix.system.activity.dto.SignWriteoffDto; | 
 |  |  | import com.matrix.system.activity.dto.SignWriteoffListDto; | 
 |  |  | import com.matrix.system.activity.dto.WriteoffCodeSubmitDto; | 
 |  |  | import com.matrix.system.activity.entity.ActivitySignAwardSet; | 
 |  |  | import com.matrix.system.activity.entity.ActivitySignReceiveRecord; | 
 |  |  | import com.matrix.system.activity.entity.ActivitySignWriteoff; | 
 |  |  | import com.matrix.system.activity.vo.LogisticsVo; | 
 |  |  | import com.matrix.system.activity.vo.SignWriteoffListVo; | 
 |  |  | import com.matrix.system.activity.vo.SignWriteoffVo; | 
 |  |  | import com.matrix.system.activity.vo.ZjrVo; | 
 |  |  | import com.matrix.system.common.bean.SysUsers; | 
 |  |  | import com.matrix.system.common.bean.SystemDictionary; | 
 |  |  | import com.matrix.system.common.dao.SystemDictionaryDao; | 
 |  |  | import com.matrix.system.hive.action.util.QueryUtil; | 
 |  |  | import com.matrix.system.hive.dao.SysVipInfoDao; | 
 |  |  | import com.matrix.system.shopXcx.bean.ShopActivities; | 
 |  |  | import com.matrix.system.shopXcx.bean.ShopDeliveryInfo; | 
 |  |  | import com.matrix.system.shopXcx.bean.ShopLogisticsInfo; | 
 |  |  | import com.matrix.system.shopXcx.dao.ShopActivitiesDao; | 
 |  |  | import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao; | 
 |  |  | import com.matrix.system.shopXcx.dao.ShopLogisticsInfoDao; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * @description 核销记录 | 
 |  |  | 
 |  |  |    ActivitySignReceiveRecordDao activitySignReceiveRecordDao; | 
 |  |  |    @Autowired | 
 |  |  |    SysVipInfoDao sysVipInfoDao; | 
 |  |  |    @Autowired | 
 |  |  |    SystemDictionaryDao systemDictionaryDao; | 
 |  |  |    @Autowired | 
 |  |  |    ShopDeliveryInfoDao shopDeliveryInfoDao; | 
 |  |  |    @Autowired | 
 |  |  |    ShopLogisticsInfoDao shopLogisticsInfoDao; | 
 |  |  |  | 
 |  |  |    public IPage<SignWriteoffListVo> findSignWriteoffList(Page<SignWriteoffListVo> page, | 
 |  |  |          SignWriteoffListDto signWriteoffListDto) { | 
 |  |  | 
 |  |  |            ShopActivities shopActivities = shopActivitiesDao.selectById(activitySignWriteoff.getActId()); | 
 |  |  |            signWriteoffVo.setHdmc(shopActivities.getActName()); | 
 |  |  |            signWriteoffVo.setHdbh(shopActivities.getActCode()); | 
 |  |  |            //获取收货地址信息 | 
 |  |  |            int awardWay = activitySignAwardSet.getAwardWay(); | 
 |  |  |            if(ActivitySignAwardSet.AWARDWAY_TWO == awardWay) { | 
 |  |  |               ActivitySignWriteoff activitySignWriteoffLogistics = activitySignWriteoffDao.selectById(writeoffId); | 
 |  |  |               Long receiveId = activitySignWriteoffLogistics.getReceiveId(); | 
 |  |  |               ActivitySignReceiveRecord activitySignReceiveRecordLogistic = activitySignReceiveRecordDao.selectById(receiveId); | 
 |  |  |               signWriteoffVo.setConsignee(activitySignReceiveRecordLogistic.getConsignee()); | 
 |  |  |               signWriteoffVo.setConsigneePhone(activitySignReceiveRecordLogistic.getConsigneePhone()); | 
 |  |  |               signWriteoffVo.setConsigneeAddress(activitySignReceiveRecordLogistic.getConsigneeAddress()); | 
 |  |  |         		 | 
 |  |  |               //物流跟踪 | 
 |  |  |               Integer logisticsId = activitySignWriteoffLogistics.getLogisticsId(); | 
 |  |  |               if(ObjectUtil.isNotEmpty(logisticsId)) { | 
 |  |  |                  List<ShopLogisticsInfo> shopLogisticsInfos = shopLogisticsInfoDao.selectByDelieryId(logisticsId); | 
 |  |  |                  if(CollUtil.isNotEmpty(shopLogisticsInfos)) { | 
 |  |  |                     ArrayList<LogisticsVo> logisticsVos = new ArrayList<>(); | 
 |  |  |                     for(ShopLogisticsInfo shopLogistics : shopLogisticsInfos) { | 
 |  |  |                        LogisticsVo logisticsVo = new LogisticsVo(); | 
 |  |  |                        logisticsVo.setContent(shopLogistics.getDescribe()); | 
 |  |  |                        logisticsVo.setTimestamp(shopLogistics.getLogisticsTime()); | 
 |  |  |                        logisticsVos.add(logisticsVo); | 
 |  |  |                     } | 
 |  |  |                     signWriteoffVo.setActivities(logisticsVos); | 
 |  |  |                  } | 
 |  |  |               } | 
 |  |  |         		 | 
 |  |  |            } | 
 |  |  |         } | 
 |  |  |         result.putInMap("signWriteoffVo", signWriteoffVo); | 
 |  |  |         return result; | 
 |  |  | 
 |  |  |         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "核销成功"); | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |    @Transactional | 
 |  |  |    public AjaxResult logisticsSubmit(LogisticsSubmitDto logisticsSubmitDto) { | 
 |  |  |       //设置用户公司ID | 
 |  |  |         QueryUtil.setQueryLimitCom(logisticsSubmitDto); | 
 |  |  |         SysUsers sysUsers = (SysUsers) WebUtil.getSession().getAttribute(MatrixConstance.LOGIN_KEY); | 
 |  |  |         Long writeoffId = logisticsSubmitDto.getWriteoffId(); | 
 |  |  |         /** | 
 |  |  |          * 更新领取记录表的收货信息和状态 | 
 |  |  |          * 更新核销记录表的状态和物流ID | 
 |  |  |          */ | 
 |  |  |         ActivitySignWriteoff activitySignWriteoff = activitySignWriteoffDao.selectById(writeoffId); | 
 |  |  |         //新增一条物流信息 | 
 |  |  |         ShopDeliveryInfo shopDeliveryInfo = new ShopDeliveryInfo(); | 
 |  |  |         Long receiveId = activitySignWriteoff.getReceiveId(); | 
 |  |  |         SystemDictionary systemDictionary = systemDictionaryDao.selectByCode(logisticsSubmitDto.getKdgs()); | 
 |  |  |         if (ObjectUtil.isEmpty(systemDictionary)) { | 
 |  |  |             return new AjaxResult(AjaxResult.STATUS_FAIL, "没有找到物流公司信息!"); | 
 |  |  |         } | 
 |  |  |         shopDeliveryInfo.setUserId(activitySignWriteoff.getUserId()); | 
 |  |  |         shopDeliveryInfo.setReceiveId(receiveId); | 
 |  |  |         shopDeliveryInfo.setReceiveAddress(logisticsSubmitDto.getShdz()); | 
 |  |  |  | 
 |  |  |         shopDeliveryInfo.setLogisticsCompany(systemDictionary.getName()); | 
 |  |  |         shopDeliveryInfo.setLogisticsCompanyCode(systemDictionary.getCode()); | 
 |  |  |         shopDeliveryInfo.setDeliveryWay("物流配送"); | 
 |  |  |  | 
 |  |  |         shopDeliveryInfo.setWaybillNo(logisticsSubmitDto.getKddh()); | 
 |  |  |         shopDeliveryInfo.setUpdateBy(sysUsers.getSuName()); | 
 |  |  |         shopDeliveryInfo.setCreateBy(sysUsers.getSuName()); | 
 |  |  |  | 
 |  |  |         shopDeliveryInfo.setDeliveryTime(new Date()); | 
 |  |  |         shopDeliveryInfoDao.insert(shopDeliveryInfo); | 
 |  |  | //      Integer id = shopDeliveryInfo.getId(); | 
 |  |  | //      if(ObjectUtil.isNotEmpty(id)) { | 
 |  |  | //         List<ShopLogisticsInfo> shopLogisticsList = new ArrayList<ShopLogisticsInfo>(); | 
 |  |  | //           AjaxResult result = new AjaxResult(); | 
 |  |  | //           Map<String, String> logisticsInfo = new HashMap<String, String>(); | 
 |  |  | //           try { | 
 |  |  | //               if (shopDeliveryInfo == null) { | 
 |  |  | //                   return new AjaxResult(AjaxResult.STATUS_FAIL, "找不到发货信息"); | 
 |  |  | //               } | 
 |  |  | //               if (!StringUtils.isNotBlank(shopDeliveryInfo.getWaybillNo()) || !StringUtils.isNotBlank(shopDeliveryInfo.getLogisticsCompanyCode())) { | 
 |  |  | //                   return new AjaxResult(AjaxResult.STATUS_FAIL, "物流公司信息为空"); | 
 |  |  | //               } | 
 |  |  | //               logisticsInfo.put("logisticsCompany", shopDeliveryInfo.getLogisticsCompany()); | 
 |  |  | //               logisticsInfo.put("waybillNo", shopDeliveryInfo.getWaybillNo()); | 
 |  |  | // | 
 |  |  | //               //如果已经签收直接查数据库 | 
 |  |  | //               if (AppConstance.LOGISTICS_STATUS_OF_SIGN_FOR.equals(shopDeliveryInfo.getLogisticsStatus())) { | 
 |  |  | // | 
 |  |  | //                   List<ShopLogisticsInfo> shopLogisticsInfos = shopLogisticsInfoDao.selectByDelieryId(shopDeliveryInfo.getId()); | 
 |  |  | //                   logisticsInfo.put("logisticsStatus", String.valueOf(AppConstance.LOGISTICS_STATUS_OF_SIGN_FOR)); | 
 |  |  | //                   result.setStatus(AjaxResult.STATUS_SUCCESS); | 
 |  |  | //                   result.setRows(shopLogisticsInfos); | 
 |  |  | //                   result.putInMap("logisticsInfo", logisticsInfo); | 
 |  |  | //                   return result; | 
 |  |  | //               } | 
 |  |  | //               Map<String, String> param = new HashMap<String, String>(); | 
 |  |  | //               param.put("ShipperCode", shopDeliveryInfo.getLogisticsCompanyCode()); | 
 |  |  | //               param.put("LogisticCode", shopDeliveryInfo.getWaybillNo()); | 
 |  |  | //               Map<String, String> paramsUrl = getparams(param); | 
 |  |  | //               LogUtil.info("物流查询参数" + paramsUrl); | 
 |  |  | //               String logisticsResult = HttpCurlUtil.sendPost(logisticsUrl, paramsUrl); | 
 |  |  | //               LogUtil.info("查询物流返回信息" + logisticsResult); | 
 |  |  | //               LogisticsInfoVo logisticsInfoVo = JSON.parseObject(logisticsResult, LogisticsInfoVo.class); | 
 |  |  | //               if (logisticsInfoVo.isSuccess()) { | 
 |  |  | //                   ShopDeliveryInfo shopDelivery = new ShopDeliveryInfo(); | 
 |  |  | //                   shopDelivery.setLogisticsStatus(Integer.valueOf(logisticsInfoVo.getState())); | 
 |  |  | //                   shopDelivery.setId(shopDeliveryInfo.getId()); | 
 |  |  | //                   logisticsInfo.put("logisticsStatus", logisticsInfoVo.getState()); | 
 |  |  | //                   //更新物流状态 | 
 |  |  | //                   shopDeliveryInfoDao.updateByModel(shopDelivery); | 
 |  |  | //                   if (CollectionUtils.isNotEmpty(logisticsInfoVo.getTraces())) { | 
 |  |  | //                       List<Map<String, String>> mapTraces = logisticsInfoVo.getTraces(); | 
 |  |  | //                       for (int i = 0; i < mapTraces.size(); i++) { | 
 |  |  | //                           ShopLogisticsInfo shopLogisticsInfo = new ShopLogisticsInfo(); | 
 |  |  | //                           shopLogisticsInfo.setCreateBy(AppConstance.SYSTEM_USER); | 
 |  |  | //                           shopLogisticsInfo.setUpdateBy(AppConstance.SYSTEM_USER); | 
 |  |  | //                           shopLogisticsInfo.setLogisticsTime(mapTraces.get(i).get("AcceptTime")); | 
 |  |  | //                           String acceptStation = mapTraces.get(i).get("AcceptStation"); | 
 |  |  | //                           shopLogisticsInfo.setDescribe(acceptStation); | 
 |  |  | //                           shopLogisticsInfo.setDelieryId(shopDeliveryInfo.getId()); | 
 |  |  | //                           if (acceptStation.indexOf(AppConstance.KDN_IS_SIGN) != -1) { | 
 |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_SIGN_FOR); | 
 |  |  | //                           } else if (acceptStation.indexOf(AppConstance.KDN_IS_RECEIVE) != -1) { | 
 |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_RECEIVE); | 
 |  |  | //                           } else if (acceptStation.indexOf(AppConstance.KDN_IS_ON_WAY) != -1) { | 
 |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_ON_WAY); | 
 |  |  | //                           } else if (acceptStation.indexOf(AppConstance.KDN_IS_MISTAKE) != -1) { | 
 |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_MISTAKE); | 
 |  |  | //                           } else { | 
 |  |  | //                               shopLogisticsInfo.setState(AppConstance.LOGISTICS_STATUS_OF_NONE); | 
 |  |  | //                           } | 
 |  |  | //                           shopLogisticsList.add(shopLogisticsInfo); | 
 |  |  | //                       } | 
 |  |  | //                       shopLogisticsInfoDao.deleteByDelieryId(shopDeliveryInfo.getId()); | 
 |  |  | //                       if (CollectionUtils.isNotEmpty(shopLogisticsList)) { | 
 |  |  | //                           shopLogisticsInfoDao.batchInsert(shopLogisticsList); | 
 |  |  | //                       } | 
 |  |  | //                   } | 
 |  |  | //               } else { | 
 |  |  | //                   throw new GlobleException(logisticsInfoVo.getReason()); | 
 |  |  | //               } | 
 |  |  | // | 
 |  |  | //           } catch (Exception e) { | 
 |  |  | //               throw new GlobleException("物流信息查询失败"); | 
 |  |  | //           } | 
 |  |  |            //更新核销记录 | 
 |  |  |            activitySignWriteoff.setState(ActivitySignWriteoff.STATE_THREE); | 
 |  |  |            activitySignWriteoff.setWriteoffTime(new Date()); | 
 |  |  |            activitySignWriteoff.setWriteoffUser(sysUsers.getSuName()); | 
 |  |  |            activitySignWriteoff.setWriteoffUserid(sysUsers.getSuId()); | 
 |  |  |            activitySignWriteoff.setLogisticsId(shopDeliveryInfo.getId()); | 
 |  |  |            activitySignWriteoffDao.updateById(activitySignWriteoff); | 
 |  |  |            //更新领取记录 | 
 |  |  |            ActivitySignReceiveRecord activitySignReceiveRecord = activitySignReceiveRecordDao.selectById(receiveId); | 
 |  |  |            activitySignReceiveRecord.setState(ActivitySignReceiveRecord.STATE_DONE); | 
 |  |  |            activitySignReceiveRecord.setConsignee(logisticsSubmitDto.getShr()); | 
 |  |  |            activitySignReceiveRecord.setConsigneeAddress(logisticsSubmitDto.getShdz()); | 
 |  |  |            activitySignReceiveRecord.setConsigneePhone(logisticsSubmitDto.getLxdh()); | 
 |  |  |            activitySignReceiveRecordDao.updateById(activitySignReceiveRecord); | 
 |  |  | //      } | 
 |  |  |         return new AjaxResult(AjaxResult.STATUS_SUCCESS, "发货成功"); | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  |