| package com.xzx.gc.order.service;  | 
|   | 
| import cn.hutool.core.collection.CollUtil;  | 
| import cn.hutool.core.convert.Convert;  | 
| import cn.hutool.core.date.DateUtil;  | 
| import cn.hutool.core.util.StrUtil;  | 
| 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.utils.gdmap.GdTraceUtil;  | 
| import com.xzx.gc.entity.CityPartner;  | 
| import com.xzx.gc.entity.OtherUserInfo;  | 
| import com.xzx.gc.entity.PartnerTrace;  | 
| import com.xzx.gc.order.mapper.PartnerTraceMapper;  | 
| import org.springframework.beans.factory.annotation.Autowired;  | 
| import org.springframework.stereotype.Service;  | 
| import org.springframework.transaction.annotation.Transactional;  | 
|   | 
| import java.util.List;  | 
|   | 
| @Service  | 
| @Transactional  | 
| public class PartnerTraceService {  | 
|   | 
|   | 
|     @Autowired  | 
|     private OtherUserService otherUserService;  | 
|     @Autowired  | 
|     private PartnerTraceMapper partnerTraceMapper;  | 
|   | 
|     public void add(PartnerTrace partnerTrace){  | 
|         partnerTrace.setCreateTime(DateUtil.now());  | 
|         partnerTrace.setUpdateTime(DateUtil.now());  | 
|         partnerTrace.setDelFlag(Convert.toShort(Constants.DEL_NOT_FLAG));  | 
|         partnerTraceMapper.insertSelective(partnerTrace);  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 创建轨迹服务  | 
|      * @param cityPartner  | 
|      * @param orderEnum  | 
|      */  | 
|     public String createService(CityPartner cityPartner,OrderEnum orderEnum){  | 
|         Result service = GdTraceUtil.createService(cityPartner.getPartnerKey(), cityPartner.getPartnerKey()+"_"+orderEnum.name());  | 
|         if(service.getCode()==0){  | 
|             PartnerTrace partnerTrace=new PartnerTrace();  | 
|             partnerTrace.setPartnerId(cityPartner.getId()+"");  | 
|             partnerTrace.setPartnerKey(cityPartner.getPartnerKey());  | 
|             partnerTrace.setPartnerServiceId(service.getData().toString());  | 
|             partnerTrace.setPartnerServiceType( Convert.toShort(orderEnum.getValue()));  | 
|             add(partnerTrace);  | 
|             return partnerTrace.getPartnerServiceId();  | 
|         }  | 
|         return null;  | 
|     }  | 
|     /**  | 
|      * 根据合伙人id和服务类型查找  | 
|      * @param partnerId  | 
|      * @param serviceType  | 
|      * @return  | 
|      */  | 
|     public PartnerTrace findByPartnerIdAndType(String partnerId,Short serviceType){  | 
|         PartnerTrace partnerGaode=new PartnerTrace();  | 
|         partnerGaode.setDelFlag(Convert.toShort(Constants.DEL_NOT_FLAG));  | 
|         partnerGaode.setPartnerId(partnerId);  | 
|         partnerGaode.setPartnerServiceType(serviceType);  | 
|         List<PartnerTrace> partnerGaode1 = partnerTraceMapper.select(partnerGaode);  | 
|         if(CollUtil.isNotEmpty(partnerGaode1)){  | 
|             return partnerGaode1.get(0);  | 
|         }  | 
|         return null;  | 
|     }  | 
|   | 
|     /**  | 
|      * 根据合伙人id查找  | 
|      * @param partnerId  | 
|      * @return  | 
|      */  | 
|     public List<PartnerTrace> findByPartnerId(String partnerId){  | 
|         PartnerTrace partnerGaode=new PartnerTrace();  | 
|         partnerGaode.setDelFlag(Convert.toShort(Constants.DEL_NOT_FLAG));  | 
|         partnerGaode.setPartnerId(partnerId);  | 
|         List<PartnerTrace> partnerGaode1 = partnerTraceMapper.select(partnerGaode);  | 
|         return partnerGaode1;  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 根据用户id和类型找对应的服务  | 
|      * @param userId  | 
|      * @param userType  | 
|      * @return  | 
|      */  | 
|     public PartnerTrace findByUserIdAndType(String userId,String  userType) {  | 
|   | 
|         OtherUserInfo byId = otherUserService.findById(userId);  | 
|   | 
|         if(StrUtil.isBlank(userType)){  | 
|             userType=byId.getUserType();  | 
|         }  | 
|   | 
|         //外部骑手  | 
|         String partnerId = byId.getPartnerId();  | 
|         if(StrUtil.isBlank(partnerId)){  | 
|             return null;  | 
|         }  | 
|   | 
|         //1:回收员 2:推广员 服务类型  | 
|         Short serviceType = null;  | 
|   | 
|         if (CommonEnum.回收员.getValue().equals(userType)) {  | 
|             serviceType = Convert.toShort(OrderEnum.回收员订单轨迹.getValue());  | 
|         } else if (CommonEnum.推广员.getValue().equals(userType)) {  | 
|             serviceType = Convert.toShort(OrderEnum.推广员全天轨迹.getValue());  | 
|         }else if(Constants.DEFAULT_ID.equals(userType)){  | 
|             serviceType=Convert.toShort(OrderEnum.回收员全天轨迹.getValue());  | 
|         }  | 
|   | 
|         PartnerTrace partnerTrace = findByPartnerIdAndType(partnerId, serviceType);  | 
|   | 
|         if(partnerTrace!=null){  | 
|             partnerTrace.setOtherUserInfo(byId);  | 
|         }  | 
|   | 
|   | 
|   | 
|         return partnerTrace;  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 根据id更新各属性  | 
|      * @param partnerTrace  | 
|      */  | 
|     public void updateById(PartnerTrace partnerTrace){  | 
|         partnerTraceMapper.updateByPrimaryKeySelective(partnerTrace);  | 
|     }  | 
| }  |