ltkj-admin/src/main/java/com/ltkj/web/controller/service/TjSysAsyncServiceImpl.java
@@ -568,10 +568,26 @@ @Override @Async("async") public void dockerSetCustomerLisByRedis(List<Long> ksproList, String ksId) { List<TjCustomer> yjAjaxResult = getYjAjaxResult(ksproList); List<TjCustomer> wjAjaxResult = getWjAjaxResult(ksproList); redisCache.setCacheMapValue(ksId + "ks", "wj", wjAjaxResult); redisCache.setCacheMapValue(ksId + "ks", "yj", yjAjaxResult); } @Override @Async("async") public void dockerSetYjCustomerByRedis(Long orderId,Long ksId) { //已检(单个存入)0未检,1已检 getDgYjAjaxResult(orderId,ksId); } @Override @Async("async") public void dockerSetWjCustomerByRedis(Long orderId,Long ksId) { //未检(单个存入)0未检,1已检 getDgWjAjaxResult(orderId,ksId); } @Override @@ -1282,7 +1298,7 @@ } } //已检 //已检(整体存入) public List<TjCustomer> getYjAjaxResult(List<Long> ksproList) { List<TjCustomer> customerLis = new ArrayList<>(); LambdaQueryWrapper<TjOrderDetail> wq1 = new LambdaQueryWrapper<>(); @@ -1297,6 +1313,7 @@ () -> new TreeSet<>(Comparator.comparing(TjOrderDetail::getOrderId)) ), ArrayList::new)).stream().map(TjOrderDetail::getOrderId).collect(Collectors.toList()); for (Long orderId : orderIds) { if (null != orderId) { TjOrder order = orderService.getById(orderId); if (null == order) { @@ -1345,6 +1362,7 @@ for (TjOrderRemark remark : list) { TjProject byId = projectService.getById(remark.getProId()); stringBuilder.append(byId.getProName()).append(";"); getDgYjAjaxResult(orderId,remark.getDeptId()); } customer.setNotCheckeds(String.valueOf(stringBuilder)); if (null == customer.getNotCheckeds()) customer.setNotCheckeds("全部已检"); @@ -1357,7 +1375,7 @@ return customerLis; } //未检 //未检(整体存入) public List<TjCustomer> getWjAjaxResult(List<Long> ksproList) { List<TjCustomer> customerLis = new ArrayList<>(); LambdaQueryWrapper<TjOrderDetail> wq1 = new LambdaQueryWrapper<>(); @@ -1372,6 +1390,9 @@ () -> new TreeSet<>(Comparator.comparing(TjOrderDetail::getOrderId)) ), ArrayList::new)).stream().map(TjOrderDetail::getOrderId).collect(Collectors.toList()); for (Long orderId : orderIds) { // for (Long aLong : ksproList) { // getDgWjAjaxResult(orderId,aLong); // } if (null != orderId) { TjOrder order = orderService.getById(orderId); if (null == order) { @@ -1420,6 +1441,7 @@ for (TjOrderRemark remark : list) { TjProject byId = projectService.getById(remark.getProId()); stringBuilder.append(byId.getProName()).append(";"); getDgWjAjaxResult(orderId,remark.getDeptId()); } customer.setNotCheckeds(String.valueOf(stringBuilder)); if (null == customer.getNotCheckeds()) customer.setNotCheckeds("全部已检"); @@ -1432,6 +1454,120 @@ return customerLis; } //已检(单个存入)0未检,1已检 public void getDgYjAjaxResult(Long orderId,Long ksId) { if (null != orderId) { TjOrder order = orderService.getById(orderId); if (null != order) { LambdaQueryWrapper<TjOrderDetail> qww = new LambdaQueryWrapper<>(); qww.eq(TjOrderDetail::getOrderId, order.getOrderId()); qww.eq(TjOrderDetail::getTjStatus, 0); qww.isNotNull(TjOrderDetail::getFlowingWaterId); TjCustomer customer = tjCustomerService.getById(order.getUserId()); List<TjOrderDetail> lists = tjOrderDetailService.list(qww); if (null == lists || lists.size() == 0) { redisCache.deleteCacheMapValue("ks"+ksId+customer.getCusId(),"1"); } if (null != customer) { //遍历项目 判断是否有重大阳性 标记 for (TjOrderDetail tjOrderDetail11 : lists) { customer.setIsPositive(tjOrderDetail11.getIsPositive()); if (tjOrderDetail11.getIsPositive() == 1) { break; } } customer.setCusName(hideCusName(customer.getCusName())); customer.setCusPhone(hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(hideIdCardNum(customer.getCusIdcard())); if (order.getTjType().equals("1")) { customer.setTjType("团体"); } if (order.getTjType().equals("2")) { customer.setTjType("个人"); } customer.setTjTime(order.getCreateTime()); customer.setTjNumber(order.getTjNumber()); customer.setTjStatus(1L); customer.setOrderId(order.getOrderId()); customer.setIsHz(order.getIsHz()); customer.setTjCategory(order.getTjCategory()); LambdaQueryWrapper<TjOrderRemark> wq = new LambdaQueryWrapper<>(); wq.eq(TjOrderRemark::getTjNumber, order.getTjNumber()); wq.in(TjOrderRemark::getType, 0, 3); List<TjOrderRemark> list = orderRemarkService.list(wq); if (null != list && list.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (TjOrderRemark remark : list) { TjProject byId = projectService.getById(remark.getProId()); stringBuilder.append(byId.getProName()).append(";"); } customer.setNotCheckeds(String.valueOf(stringBuilder)); if (null == customer.getNotCheckeds()) customer.setNotCheckeds("全部已检"); } redisCache.setCacheMapValue("ks:"+ksId+":"+customer.getCusId(),"1",customer); } } } } //未检(单个存入)0未检,1已检 public void getDgWjAjaxResult(Long orderId,Long ksId) { if (null != orderId) { TjOrder order = orderService.getById(orderId); if (null == order) { TjCustomer customer = tjCustomerService.getById(order.getUserId()); if (null != customer) { LambdaQueryWrapper<TjOrderDetail> qww = new LambdaQueryWrapper<>(); qww.eq(TjOrderDetail::getOrderId, order.getOrderId()); qww.isNotNull(TjOrderDetail::getFlowingWaterId); List<TjOrderDetail> lists = tjOrderDetailService.list(qww); if (null != lists) { //遍历项目 判断是否有重大阳性 标记 for (TjOrderDetail tjOrderDetail11 : lists) { customer.setIsPositive(tjOrderDetail11.getIsPositive()); if (tjOrderDetail11.getIsPositive()==1){ break; } } } customer.setCusName(hideCusName(customer.getCusName())); customer.setCusPhone(hidePhoneNum(customer.getCusPhone())); customer.setCusIdcard(hideIdCardNum(customer.getCusIdcard())); if (order.getTjType().equals("1")) { customer.setTjType("团体"); } if (order.getTjType().equals("2")) { customer.setTjType("个人"); } customer.setTjTime(order.getCreateTime()); customer.setTjNumber(order.getTjNumber()); customer.setOrderId(order.getOrderId()); customer.setIsHz(order.getIsHz()); customer.setTjCategory(order.getTjCategory()); customer.setTjStatus(0L); LambdaQueryWrapper<TjOrderRemark> wq = new LambdaQueryWrapper<>(); wq.eq(TjOrderRemark::getTjNumber, order.getTjNumber()); wq.in(TjOrderRemark::getType, 0, 3); List<TjOrderRemark> list = orderRemarkService.list(wq); if (null != list && list.size() > 0) { StringBuilder stringBuilder = new StringBuilder(); for (TjOrderRemark remark : list) { TjProject byId = projectService.getById(remark.getProId()); stringBuilder.append(byId.getProName()).append(";"); } customer.setNotCheckeds(String.valueOf(stringBuilder)); if (null == customer.getNotCheckeds()) customer.setNotCheckeds("全部已检"); } redisCache.setCacheMapValue("ks"+ksId+":"+customer.getCusId(),"0",customer); } } } } //已审 private List<TjCustomer> getYsResult(String config) { List<TjOrder> orderList = null; ltkj-admin/src/main/java/com/ltkj/web/controller/sqlserver/TjSqlController.java
@@ -2,6 +2,7 @@ import com.ltkj.common.core.controller.BaseController; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.core.redis.RedisCache; import com.ltkj.common.enums.DataSourceType; import com.ltkj.framework.datasource.DynamicDataSourceContextHolder; import com.ltkj.hosp.service.*; @@ -10,11 +11,21 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.ConvertingCursor; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static com.ltkj.framework.datasource.DynamicDataSourceContextHolder.log; import static org.apache.poi.hemf.record.emfplus.HemfPlusRecordType.save; @@ -41,6 +52,36 @@ private LtkjHybgdService ltkjHybgdService; @Resource private LtkjHysqdService ltkjHysqdService; @Autowired public RedisTemplate<Object,Object> redisTemplate; @Resource private RedisCache redisCache; @GetMapping("/getRedisValue") @ApiOperation(value = "测试redis模糊查询") public AjaxResult getRedisValue(@RequestParam String aa) { long start = System.currentTimeMillis(); //需要匹配的key ScanOptions options = ScanOptions.scanOptions() //这里指定每次扫描key的数量(很多博客瞎说要指定Integer.MAX_VALUE,这样的话跟 keys有什么区别?) .count(10000) .match(aa+"*").build(); RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer(); Cursor cursor = redisTemplate.executeWithStickyConnection(redisConnection -> new ConvertingCursor<>(redisConnection.scan(options), redisSerializer::deserialize)); List<Object> result = new ArrayList<>(); while(cursor.hasNext()){ String s = cursor.next().toString(); redisCache.deleteObject(s); } //切记这里一定要关闭,否则会耗尽连接数。报Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a cursor.close(); // System.out.println(result); log.info("scan扫描共耗时:{} ms key数量:{}",System.currentTimeMillis()-start,result.size()); Map<String,Object>map=new HashMap<>(); map.put("result",result); map.put("scan扫描共耗时:{} ms key数量:{}",System.currentTimeMillis()-start+result.size()); return AjaxResult.success(map); } @GetMapping("/getMiddleDetail") ltkj-admin/src/main/java/com/ltkj/web/controller/system/SysDeptController.java
@@ -27,6 +27,11 @@ import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.ConvertingCursor; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -89,7 +94,8 @@ @Autowired private ITjRulesService tjRulesService; @Autowired public RedisTemplate<Object,Object> redisTemplate; /** @@ -279,14 +285,47 @@ } } List<TjCustomer> customerLists = new ArrayList<>(); // String key="*"; // if(sysUser.isAdmin()){ // key="ks"+":*"; // }else { // key="ks:"+ksId+":*"; // } // ScanOptions options = ScanOptions.scanOptions() // //这里指定每次扫描key的数量(很多博客瞎说要指定Integer.MAX_VALUE,这样的话跟 keys有什么区别?) // .count(10000) // .match(key).build(); // RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer(); // 0未检,1已检 if (type == 0) { // Cursor cursor = redisTemplate.executeWithStickyConnection(redisConnection -> new ConvertingCursor<>(redisConnection.scan(options), redisSerializer::deserialize)); // while(cursor.hasNext()){ // String s = cursor.next().toString(); // TjCustomer wj = redisCache.getCacheMapValue(s,"0"); // if(null !=wj){ // customerLists.add(wj); // } // } // //切记这里一定要关闭,否则会耗尽连接数。报Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a // cursor.close(); customerLists = redisCache.getCacheMapValue(ksId + "ks", "wj"); } if (type == 1) { // Cursor cursor = redisTemplate.executeWithStickyConnection(redisConnection -> new ConvertingCursor<>(redisConnection.scan(options), redisSerializer::deserialize)); // while(cursor.hasNext()){ // String s = cursor.next().toString(); // TjCustomer wj = redisCache.getCacheMapValue(s,"1"); // if(null !=wj){ // customerLists.add(wj); // } // } // //切记这里一定要关闭,否则会耗尽连接数。报Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a // cursor.close(); customerLists = redisCache.getCacheMapValue(ksId + "ks", "yj"); } asyncService.dockerSetCustomerLisByRedis(ksproList, String.valueOf(ksId)); if (customerLists != null && customerLists.size() > 0) { if (null !=customerLists && customerLists.size() > 0) { Collections.reverse(customerLists); List<TjCustomer> customerList = customerLists.stream().skip((long) (page - 1) * pageSize).limit(pageSize).collect(Collectors.toList()); Map<String, Object> map = new HashMap<>(); ltkj-admin/src/test/java/zjhTest.java
@@ -14,11 +14,14 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -45,11 +48,11 @@ // @Resource // private ITjOrderRemarkService remarkService; // // @Resource // private RedisCache redisCache; @Resource private RedisCache redisCache; // // @Autowired // public RedisTemplate<String,String> redisTemplate; @Autowired public RedisTemplate<Object,Object> redisTemplate; // @Resource // private StringRedisTemplate stringRedisTemplate; @Resource @@ -68,6 +71,22 @@ // System.out.println(dateTime1); // System.out.println("================================================="); // System.out.println(mallMerchantSecretKey); // List<Object> list=new ArrayList<>(); // ScanOptions options = ScanOptions.scanOptions().match("cS*").build(); // try (Cursor<byte[]> cursor = redisTemplate.executeWithStickyConnection(redisConnection -> { // return redisConnection.scan(options); // })) { // while (cursor.hasNext()) { // byte[] keyBytes = cursor.next(); // String key = new String(keyBytes); // // 处理匹配的key // List<Object> multiCacheMapValue = redisCache.getMultiCacheMapValue(key, null); // list.add(multiCacheMapValue); // } // } // System.out.println(list); System.out.println(redisCache.getMultiCacheMapValue("check",null)); // } } ltkj-hosp/src/main/java/com/ltkj/hosp/service/TjAsyncService.java
@@ -38,9 +38,13 @@ void iundividualCharges(TjFlowingWater tjFlowingWater, TjOrder order, TjCustomer customer, SysUser sysUser); //医生检查向缓存中添加数据 //医生检查向缓存中添加数据(整体存入) void dockerSetCustomerLisByRedis(List<Long> ksproList,String ksId); //医生检查向缓存中添加数据(单个存入) void dockerSetYjCustomerByRedis(Long orderId,Long ksId); void dockerSetWjCustomerByRedis(Long orderId,Long ksId); //总检 void checkSetCustomerLisByRedis(String config);