import cn.hutool.core.collection.CollUtil;  
 | 
import cn.hutool.core.convert.Convert;  
 | 
import cn.hutool.core.thread.ThreadUtil;  
 | 
import cn.hutool.core.util.RandomUtil;  
 | 
import cn.hutool.core.util.StrUtil;  
 | 
import cn.hutool.json.JSONUtil;  
 | 
import com.xzx.gc.GcUserApplication;  
 | 
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.utils.RedisUtil;  
 | 
import com.xzx.gc.common.utils.gdmap.GdTraceUtil;  
 | 
import com.xzx.gc.entity.*;  
 | 
import com.xzx.gc.user.mapper.UserBatchMapper;  
 | 
import com.xzx.gc.user.service.*;  
 | 
import org.junit.Test;  
 | 
import org.junit.runner.RunWith;  
 | 
import org.springframework.beans.factory.annotation.Autowired;  
 | 
import org.springframework.boot.test.context.SpringBootTest;  
 | 
import org.springframework.test.context.ActiveProfiles;  
 | 
import org.springframework.test.context.junit4.SpringRunner;  
 | 
  
 | 
import java.util.ArrayList;  
 | 
import java.util.Comparator;  
 | 
import java.util.List;  
 | 
import java.util.TreeSet;  
 | 
import java.util.concurrent.CountDownLatch;  
 | 
import java.util.stream.Collectors;  
 | 
  
 | 
  
 | 
@RunWith(SpringRunner.class)  
 | 
@SpringBootTest(classes = {GcUserApplication.class})  
 | 
@ActiveProfiles(profiles = {"temp"})  
 | 
public class SpringTest {  
 | 
  
 | 
  
 | 
    @Autowired  
 | 
    private AddressLevelService addressLevelService;  
 | 
  
 | 
    @Autowired  
 | 
    private RedisUtil redisUtil;  
 | 
  
 | 
    @Autowired  
 | 
    private OtherUserService otherUserService;  
 | 
  
 | 
    @Autowired  
 | 
    private UserService userService;  
 | 
  
 | 
    @Autowired  
 | 
    private OrderService orderService;  
 | 
  
 | 
    @Autowired  
 | 
    private PartnerFenceService partnerFenceService;  
 | 
  
 | 
    @Autowired  
 | 
    private PartnerGaodeService partnerGaodeService;  
 | 
  
 | 
    @Autowired  
 | 
    private UserBatchMapper userBatchMapper;  
 | 
  
 | 
    @Test  
 | 
    public  void test(){  
 | 
//        List<AddressLevelInfo> byTownIds = addressLevelService.findByTownIds("1812");  
 | 
//        for (AddressLevelInfo byTownId : byTownIds) {  
 | 
//            System.out.println(byTownId);  
 | 
//        }  
 | 
//        if(redisUtil.exists(Constants.REDIS_USER_KEY+"token:"+"YH1197504485698961408")){  
 | 
//            System.out.println("123");  
 | 
//        }else {  
 | 
//            System.out.println("456");  
 | 
//        }  
 | 
        OtherUserInfo otherUserInfo=new OtherUserInfo();  
 | 
        otherUserInfo.setUserId(RandomUtil.randomString(11));  
 | 
        otherUserInfo.setMobilePhone("1");  
 | 
        otherUserService.add(otherUserInfo);  
 | 
  
 | 
    }  
 | 
  
 | 
    @Test  
 | 
    public void 修复用户合伙人() throws InterruptedException {  
 | 
        List<UserInfo> list=new ArrayList<>();  
 | 
  
 | 
        List<UserInfo> forBidden = userService.findForBidden();  
 | 
        CountDownLatch countDownLatch = ThreadUtil.newCountDownLatch(forBidden.size());  
 | 
        for (UserInfo userInfo : forBidden) {  
 | 
  
 | 
  
 | 
            Runnable callable=()->{  
 | 
                UserInfo userInfo1 = fixPa(userInfo);  
 | 
                if(userInfo1!=null){  
 | 
                    list.add(userInfo1);  
 | 
                }  
 | 
                countDownLatch.countDown();  
 | 
            };  
 | 
  
 | 
            ThreadUtil.execAsync(callable,true);  
 | 
        }  
 | 
  
 | 
        countDownLatch.await();  
 | 
  
 | 
        System.out.println("批量更新");  
 | 
        if(CollUtil.isNotEmpty(list)) {  
 | 
            userBatchMapper.updateBatchByPrimaryKeySelective(list);  
 | 
        }  
 | 
        System.out.println("完成");  
 | 
  
 | 
  
 | 
    }  
 | 
  
 | 
  
 | 
    public UserInfo fixPa(UserInfo userInfo){  
 | 
        //先根据用户的订单查询所属的合伙人  没有再根据经纬度查询  
 | 
        List<OrderInfo> byCreateUserIdAndNotNullTown = orderService.findByCreateUserIdAndNotNullTown(userInfo.getUserId());  
 | 
  
 | 
        //筛选正常围栏  
 | 
        byCreateUserIdAndNotNullTown = byCreateUserIdAndNotNullTown.stream().filter(x -> Convert.toInt(x.getTownId()) >= 182 && Convert.toInt(x.getTownId()) <= 209).collect(Collectors.toList());  
 | 
  
 | 
        //去重围栏ID  
 | 
        byCreateUserIdAndNotNullTown = byCreateUserIdAndNotNullTown.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(OrderInfo::getTownId))), ArrayList::new));  
 | 
  
 | 
        List<String> partnerIds = CollUtil.newArrayList();  
 | 
        for (OrderInfo orderInfo : byCreateUserIdAndNotNullTown) {  
 | 
            String townId = orderInfo.getTownId();  
 | 
            PartnerFence byFenceId = partnerFenceService.findByFenceId(townId);  
 | 
            if(byFenceId!=null){  
 | 
                partnerIds.add(byFenceId.getPartnerId());  
 | 
            }  
 | 
        }  
 | 
  
 | 
        if(CollUtil.isNotEmpty(partnerIds)){  
 | 
            partnerIds=partnerIds.stream().distinct().collect(Collectors.toList());  
 | 
  
 | 
            String join = CollUtil.join(partnerIds, ",");  
 | 
  
 | 
            userInfo.setPartnerId(join);  
 | 
  
 | 
        }else {  
 | 
  
 | 
            //根据经纬度查询  
 | 
            if(StrUtil.isNotBlank(userInfo.getLongitude())){  
 | 
                String partnerIdByLon = partnerGaodeService.findPartnerIdByLon(userInfo.getLongitude(), userInfo.getLatitude());  
 | 
                userInfo.setPartnerId(partnerIdByLon);  
 | 
            }  
 | 
        }  
 | 
  
 | 
        if(StrUtil.isNotBlank(userInfo.getPartnerId())){  
 | 
            UserInfo userInfo1=new UserInfo();  
 | 
            userInfo1.setUserId(userInfo.getUserId());  
 | 
            userInfo1.setPartnerId(userInfo.getPartnerId());  
 | 
            return userInfo1;  
 | 
        }  
 | 
        return null;  
 | 
    }  
 | 
  
 | 
  
 | 
  
 | 
    @Test  
 | 
    public void test2(){  
 | 
        UserInfo  userInfo=new UserInfo();  
 | 
        userInfo.setNickName("12321");  
 | 
  
 | 
        redisUtil.setex("aa",JSONUtil.toJsonStr(userInfo),10);  
 | 
    }  
 | 
  
 | 
    /**  
 | 
     * 给所有回收员和推广员分配终端  
 | 
     */  
 | 
    @Test  
 | 
    public void createTeramal(){  
 | 
  
 | 
        //回收员轨迹服务id  
 | 
        String serviceId11="115777";  
 | 
        //推广员轨迹服务id  
 | 
        String serviceId22="115797";  
 | 
  
 | 
        //回收员  
 | 
        List<OtherUserInfo> byUserType = otherUserService.findByUserType(CommonEnum.回收员.getValue());  
 | 
        if(CollUtil.isNotEmpty(byUserType)){  
 | 
            for (OtherUserInfo otherUserInfo : byUserType) {  
 | 
                String terminalId = otherUserInfo.getTerminalId();  
 | 
                if(StrUtil.isBlank(terminalId)){  
 | 
                    Result terminal = GdTraceUtil.createTerminal(Constants.GD_MAP_KEY, serviceId11, otherUserInfo.getUserId());  
 | 
                    if(terminal.getCode()==0){  
 | 
                        String s = terminal.getData().toString();  
 | 
                        otherUserInfo.setTerminalId(s);  
 | 
                        otherUserService.update(otherUserInfo);  
 | 
                    }  
 | 
                }  
 | 
            }  
 | 
        }  
 | 
  
 | 
  
 | 
        //回收员  
 | 
         byUserType = otherUserService.findByUserType(CommonEnum.推广员.getValue());  
 | 
        if(CollUtil.isNotEmpty(byUserType)){  
 | 
            for (OtherUserInfo otherUserInfo : byUserType) {  
 | 
                String terminalId = otherUserInfo.getTerminalId();  
 | 
                if(StrUtil.isBlank(terminalId)){  
 | 
                    Result terminal = GdTraceUtil.createTerminal(Constants.GD_MAP_KEY, serviceId22, otherUserInfo.getUserId());  
 | 
                    if(terminal.getCode()==0){  
 | 
                        String s = terminal.getData().toString();  
 | 
                        otherUserInfo.setTerminalId(s);  
 | 
                        otherUserService.update(otherUserInfo);  
 | 
                    }  
 | 
                }  
 | 
            }  
 | 
        }  
 | 
  
 | 
        System.out.println("执行完成");  
 | 
  
 | 
    }  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
}  
 |