Commit 3fd65bee by qwmqiuwenmin

fix

parent 2f1adcbf
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.gic.haoban.manage.api.service.MemberUnionidRelatedApiService;
public class CountDownLatchTest implements Runnable{
private static Logger logger= LoggerFactory.getLogger(CountDownLatchTest.class);
final AtomicInteger number = new AtomicInteger();
volatile boolean bol = false;
private MemberUnionidRelatedApiService memberUnionidRelatedApiService;
private String wxUserId;
private CountDownLatch countDownLatch;
public CountDownLatchTest(MemberUnionidRelatedApiService memberUnionidRelatedApiService,String wxUserId,CountDownLatch countDownLatch){
this.memberUnionidRelatedApiService = memberUnionidRelatedApiService;
this.wxUserId = wxUserId;
this.countDownLatch = countDownLatch;
}
@Override
public void run() {
try {
// 线程等待
countDownLatch.await();
long startTime = System.currentTimeMillis();
List<String> res = memberUnionidRelatedApiService.listSelfExterialList("ca66a01b79474c40b3e7c7f93daf1a3b", wxUserId);
System.out.println(JSON.toJSONString(res));
long endTime = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName() + " ended at: " + endTime + ", cost: " + (endTime - startTime) + " ms.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.api.dto.SyncSingleDealDTO;
import com.gic.haoban.manage.api.service.DealSyncOperationApiService;
import com.gic.haoban.manage.api.service.MemberUnionidRelatedApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.StaffClerkRelationApiService;
import com.gic.haoban.manage.service.service.StaffService;
......@@ -23,6 +25,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@RunWith(SpringJUnit4ClassRunner.class)
......@@ -48,143 +53,30 @@ public class DealSyncTest {
@Autowired
private StaffClerkRelationApiService staffClerkRelationApiService;
@Autowired
private MemberUnionidRelatedApiService memberUnionidRelatedApiService;
@Test
public void test() {
List<SyncSingleDealDTO> add = new ArrayList<>();
List<SyncSingleDealDTO> edit = new ArrayList<>();
{
SyncSingleDealDTO dealDTO = new SyncSingleDealDTO();
dealDTO.setDepartmentId("ff80808166c3a1050166c43175d9000e");
dealDTO.setParentDepartmentId("a101b3a51cd549e79f3daec1aa628301");
dealDTO.setDepartmentName("西溪花园");
dealDTO.setRelatedId("ff80808166c3a1050166c43175d9000e");
dealDTO.setStoreFlag(0);
dealDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
add.add(dealDTO);
}
{
SyncSingleDealDTO dealDTO = new SyncSingleDealDTO();
dealDTO.setDepartmentId("100333808083");
dealDTO.setParentDepartmentId("a101b3a51cd549e79f3daec1aa628301");
dealDTO.setDepartmentName("测试门店1003338");
dealDTO.setRelatedId("100333808083");
dealDTO.setStoreFlag(1);
dealDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
add.add(dealDTO);
}
dealSyncOperationApiService.dealQywxDepartment("111", "ca66a01b79474c40b3e7c7f93daf1a3b");
}
@Test
public void test2() {
int i =1;
while (true) {
i++;
if (i==5){
System.out.println("close");
RedisUtil.close();
}
if (i==10||i==25){
System.out.println("creConnect");
RedisUtil.reConnect();
}
try {
RedisUtil.setCache("1", "2");
Object cache = RedisUtil.getCache("1");
System.out.println("======={}"+i+":"+cache);
Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Test
public void test3() {
staffApiService.getWxSaveNew("3e7a7c09097a40b18aef1478b04688fe", "ca66a01b79474c40b3e7c7f93daf1a3b");
}
@Test
public void test5() {
String key="test2";
RedisUtil.lock(key,100L, TimeUnit.SECONDS,0L);
// try {
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// if(RedisUtil.isLocked(key)){
// RedisUtil.unlock(key);
// }
ExecutorService pool = Executors. newCachedThreadPool();
List<String> res = memberUnionidRelatedApiService.listSelfExterialList("ca66a01b79474c40b3e7c7f93daf1a3b", "QiuWenMin");
System.out.println(JSON.toJSONString(res));
// 初始化计数器为1
CountDownLatch countDownLatch = new CountDownLatch(1);
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"12", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"13989473881", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"1545shiyao", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"15757150876", countDownLatch)).start();;
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"18758285875", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"2224324sdftgret90", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"2341578784", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"234324", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"niweizhong", countDownLatch)).start();
new Thread(new CountDownLatchTest(memberUnionidRelatedApiService,"QiuWenMin", countDownLatch)).start();
// 启动多个线程
countDownLatch.countDown();
}
@Test
public void test6() {
String key="test2";
// RedisUtil.lock(key,100L, TimeUnit.SECONDS,0L);
// try {
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
RLock lock = RedisUtil.getRedisClient().getLock(key);
try {
if (lock.tryLock(0, 10, TimeUnit.MINUTES)) {
try {
Thread.sleep(1000L);
} finally {
lock.unlock();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
// if(RedisUtil.isLocked(key)){
// RedisUtil.unlock(key);
// }
// RedisUtil.unlock();
// RedisUtil.setCache("test5511","111",2592030L);
}
@Test
public void test4() {
List<StaffDTO> retList = staffService.listByUserIdsAndWxEnterpriseId(null, "ca66a01b79474c40b3e7c7f93daf1a3b");
System.out.println(retList.size());
if (CollectionUtils.isEmpty(retList)) {
return;
}
List<StaffDTO> staffDTOS = retList.subList(2, retList.size()-1);
staffDTOS.forEach(staffDTO -> {
if (StringUtils.isNotBlank(staffDTO.getWxUserId())) {
logger.info(staffDTO.getWxUserId());
QywxExternalcontactDTO send = new QywxExternalcontactDTO();
send.setType(1);
send.setScene(1);
send.setRemark("tesst_" + staffDTO.getPhoneNumber());
List<String> userIds = new ArrayList<>();
userIds.add(staffDTO.getWxUserId());
send.setUser(userIds);
String configId = qywxUserApiService.getExternalcontactByUserId("ww9ede832a84b7ae5f", "65zze159pYb4ofbFsIREZ5X7d7iaZ-bWsVIQk2y5kTU", send);
if (StringUtils.isNotBlank(configId)) {
logger.info("staff:{}", configId, JSONObject.toJSONString(staffDTO));
com.gic.haoban.manage.service.entity.Test test = new com.gic.haoban.manage.service.entity.Test();
test.setId(configId);
test.setName(staffDTO.getWxUserId());
testService.save(test);
}
}
});
}
@Test
public void test7() {
ServiceResponse<String> memberChatConfig = staffClerkRelationApiService.getClerkMemberChatConfig("ff8080816106031401612207e9b405aa");
System.out.println(JSONObject.toJSONString(memberChatConfig));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment