| | |
| | | |
| | | 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.*; |
| | |
| | | import com.ltkj.hosp.mapper.TestMapper; |
| | | 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; |
| | | |
| | | |
| | | @RestController |
| | |
| | | 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") |
| | |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getLtkjTjPatById") |
| | | public AjaxResult getLtkjTjPatById(String id) { |
| | | LtkjTjPat one = testMapper.getTjPatById(id); |
| | | |
| | | @GetMapping("/getTjPatByCusId") |
| | | public AjaxResult getTjPatByCusId(String cusId) { |
| | | testMapper.getTjPatByCusId(cusId); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/saveMiddleHeadByPatId") |
| | | public AjaxResult saveMiddleHeadByPatId(String id) { |
| | | List<LtkjMiddleHead> one = testMapper.saveMiddleHeadByPatId(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = tjvLtkjvtjpatService.save(one); |
| | | for (LtkjMiddleHead ltkjMiddleHead : one) { |
| | | final boolean save = headService.save(ltkjMiddleHead); |
| | | } |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getMiddleDetailById") |
| | | public AjaxResult getMiddleDetailById(String id) { |
| | | LtkjMiddleDetail one = testMapper.getMiddleDetailById(id); |
| | | @GetMapping("/getMiddleDetailByHeadId") |
| | | public AjaxResult getMiddleDetailByHeadId(String id) { |
| | | List<LtkjMiddleDetail> one = testMapper.getMiddleDetailByHeadId(id); |
| | | for (LtkjMiddleDetail ltkjMiddleDetail : one) { |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = middleDetailService.save(ltkjMiddleDetail); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | } |
| | | return AjaxResult.success(one); |
| | | } |
| | | |
| | | @GetMapping("/test") |
| | | public AjaxResult getHysqdByTmh(String id) { |
| | | List<LtkjHysqd> one = testMapper.getHysqdByTmh(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = middleDetailService.save(one); |
| | | ltkjHysqdService.saveBatch(one); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | for (LtkjHysqd ltkjHysqd : one) { |
| | | List<LtkjHybgd> one1 = testMapper.getHybgdByTmh(ltkjHysqd.getTmh()); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | ltkjHybgdService.saveBatch(one1); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getMiddleHeadById") |
| | | public AjaxResult getMiddleHeadById(String id) { |
| | | LtkjMiddleHead one = testMapper.getMiddleHeadById(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = headService.save(one); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getExamJcbgdById") |
| | | public AjaxResult getExamJcbgdById(String id) { |
| | | LtkjExamJcbgd one = testMapper.getExamJcbgdById(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = ltkjExamJcbgdService.save(one); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | } |
| | | |
| | | @GetMapping("/getExamJcsqdById") |
| | | public AjaxResult getExamJcsqdById(String id) { |
| | | LtkjExamJcsqd one = testMapper.getExamJcsqdById(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = ltkjExamJcsqdService.save(one); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | } |
| | | |
| | | @GetMapping("/getHybgdById") |
| | | public AjaxResult getHybgdById(String id) { |
| | | LtkjHybgd one = testMapper.getHybgdById(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = ltkjHybgdService.save(one); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | } |
| | | |
| | | @GetMapping("/getHysqdById") |
| | | public AjaxResult getHysqdById(String id) { |
| | | LtkjHysqd one = testMapper.getHysqdById(id); |
| | | DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name()); |
| | | final boolean save = ltkjHysqdService.save(one); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | return AjaxResult.success(save); |
| | | } |
| | | } |