import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.io.FileUtil; import cn.hutool.core.text.StrFormatter; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; 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.common.utils.wxpay.WxUtil; import com.xzx.gc.entity.*; import com.xzx.gc.user.mapper.UserBatchMapper; import com.xzx.gc.user.service.*; import lombok.extern.slf4j.Slf4j; 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.io.File; import java.io.InputStream; 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; @Slf4j @RunWith(SpringRunner.class) @SpringBootTest(classes = {GcUserApplication.class}) @ActiveProfiles(profiles = {"xc"}) 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 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 list=new ArrayList<>(); List 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 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 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 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("执行完成"); } @Autowired private WxUtil wxUtil; @Test public void acodeTest() { String path = "pages/login/login?poster=18390984915&chiefId=YH1417670707298828288"; String imgPath = "/Users/helius/Desktop/YH1417670707298828288_acode.jpg"; String url = StrFormatter.format("https://api.weixin.qq.com/wxa/getwxacode?access_token={}", wxUtil.getAccessToken()); cn.hutool.json.JSONObject obj = JSONUtil.createObj(); obj.put("path", path); //最小 280px,最大 1280px obj.put("width", "800px"); obj.put("auto_color", false); cn.hutool.json.JSONObject obj2 = JSONUtil.createObj(); obj2.put("r", 0); obj2.put("g", 0); obj2.put("b", 0); obj.put("line_color", obj2); //是否需要透明底色,为 true 时,生成透明底色的小程序码 obj.put("is_hyaline", false); try { InputStream inputStream = HttpRequest.post(url).body(obj.toString(), "application/json").execute().bodyStream(); File file = new File(imgPath); FileUtil.writeFromStream(inputStream, file); long uploadUrl = FileUtil.size(file); //小于10kb重新生成 if(uploadUrl<= Constants.MIN_FILE_SIZE){ log.error("生成微信小程序码失败:图片大小异常:{}",uploadUrl); } } catch (Exception e) { log.error("生成微信小程序码失败",e); } } }