Commit d80029a5 by fudahua

lock

parent 087e3ec2
package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.service.entity.Test;
/**
* Created by tgs on 2020/2/9.
*/
public interface TestService {
public void save(Test test);
}
package com.gic.haoban.manage.service.service.impl;
import com.gic.haoban.manage.service.dao.mapper.TestMapper;
import com.gic.haoban.manage.service.entity.Test;
import com.gic.haoban.manage.service.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by tgs on 2020/2/9.
*/
public class TestApiServiceImpl {
@Service
public class TestApiServiceImpl implements TestService {
@Autowired
private TestMapper testMapper;
@Override
public void save(Test test) {
testMapper.insert(test);
}
}
......@@ -8,7 +8,10 @@
<sql id="Base_Column_List">
id, name
</sql>
<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.Test" >
insert into test (id,name)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR})
</insert>
<select id="queryList" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
......
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
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.DepartmentApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.wechat.api.dto.qywx.DepartmentDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxDepartmentApiService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.haoban.manage.service.service.TestService;
import com.gic.redis.data.util.RedisUtil;
import com.gic.wechat.api.dto.qywx.QywxExternalcontactDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class DealSyncTest {
private static Logger logger= LoggerFactory.getLogger(DealSyncTest.class);
@Autowired
private DealSyncOperationApiService dealSyncOperationApiService;
@Autowired
private StaffApiService staffApiService;
@Autowired
private StaffService staffService;
@Autowired
private QywxUserApiService qywxUserApiService;
@Autowired
private TestService testService;
@Test
public void test() {
List<SyncSingleDealDTO> add = new ArrayList<>();
......@@ -64,11 +74,90 @@ public class DealSyncTest {
@Test
public void test2() {
dealSyncOperationApiService.cleanDiffrence("ca66a01b79474c40b3e7c7f93daf1a3b", "73387b7d355c416f93242f3d71a487a8");
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);
// }
}
@Test
public void test6() {
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);
}
}
@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);
}
}
});
}
}
......@@ -114,4 +114,16 @@ public class TestController extends WebBaseController {
RedisUtil.delCache(key);
return resultResponse(HaoBanErrCode.ERR_1);
}
@RequestMapping("/lock")
public HaobanResponse lock(String name,Long time,int ty) {
RedisUtil.lock(name, time, TimeUnit.SECONDS, 0L);
if (ty==0) {
if(RedisUtil.isLocked(name)){
RedisUtil.unlock(name);
}
}
return resultResponse(HaoBanErrCode.ERR_1);
}
}
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