zjh
2023-12-14 448a0c22ec89d5962cbf78d737517aaf176c0240
ltkj-admin/src/main/java/com/ltkj/web/controller/sqlserver/TjSqlController.java
@@ -1,13 +1,19 @@
package com.ltkj.web.controller.sqlserver;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
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.domain.TjOrder;
import com.ltkj.hosp.domain.TjOrderRemark;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.sqlDomain.*;
import com.ltkj.hosp.mapper.TestMapper;
import com.ltkj.system.service.ISysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
@@ -20,6 +26,8 @@
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -56,30 +64,63 @@
    public RedisTemplate<Object,Object> redisTemplate;
    @Resource
    private RedisCache redisCache;
    @Resource
    private TjAsyncService asyncService;
    @Resource
    private ITjOrderRemarkService remarkService;
    @Resource
    private ITjOrderService orderService;
    @Resource
    private ISysDeptService deptService;
    @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());
    public AjaxResult getRedisValue(@RequestParam int aa,
                                    @RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @RequestParam(required = false) String deptId,
                                    @RequestParam(required = false) String tjName,
                                    @RequestParam(required = false) String tjNum) throws SQLException, JsonProcessingException {
//        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());
//        List<TjOrderRemark> list = remarkService.list(new LambdaQueryWrapper<TjOrderRemark>().ne(TjOrderRemark::getType,2).groupBy(TjOrderRemark::getTjNumber));
//        for (TjOrderRemark remark : list) {
//            TjOrder orderByTjNum = orderService.getOrderByTjNum(remark.getTjNumber());
//            if(null !=orderByTjNum){
//                asyncService.dockerSetWjCustomerByRedis(orderByTjNum.getOrderId(),remark.getDeptId());
//                asyncService.dockerSetYjCustomerByRedis(orderByTjNum.getOrderId(),remark.getDeptId());
//            }
//        }
        if(null==deptId) deptId="";
        if(null==tjName) tjName="";
        if(null==tjNum) tjNum="";
//        List<Map<String, Object>> map = deptService.getSysDeptYjWjCustomerList(deptId, tjName, tjNum, aa, page, pageSize);
//        List<ResultSet> map = deptService.getSysDeptYjWjCustomerList1(deptId, tjName, tjNum, aa, page, pageSize);
//        ResultSet resultSet = deptService.getSysDeptYjWjCustomerList12(deptId, tjName, tjNum, aa, page, pageSize);
//        while (resultSet.next()){
//            String anInt = resultSet.getString(1);
//            System.out.println(anInt);
//        }
        Map<String,Object> map = deptService.getSysDeptYjWjCustomerList13(deptId, tjName, tjNum, aa, page, pageSize);
        return AjaxResult.success(map);
    }