From 965a994c0fe4c59a72638a6a4f1bb28dfd66f655 Mon Sep 17 00:00:00 2001 From: zhaowenxuan <chacca165@163.com> Date: 星期二, 17 十二月 2024 20:06:25 +0800 Subject: [PATCH] 20241217 --- src/main/resources/application-linux.yaml | 3 .gitignore | 3 src/main/java/com/example/utils/SpringUtils.java | 140 + src/main/java/com/example/service/ISysConfigService.java | 92 src/main/resources/logback.xml | 121 + src/main/java/com/example/datasource/DynamicDataSource.java | 24 src/main/java/com/example/service/impl/SysConfigServiceImpl.java | 209 ++ src/main/java/com/example/domain/SysConfig.java | 103 + pom.xml | 32 src/main/java/com/example/dto/xian/meiji/FeiYongIdDto.java | 16 src/main/java/com/example/enums/DataSourceType.java | 24 src/main/java/com/example/config/RedisConfig.java | 175 + src/main/java/com/example/controller/xian/MeiJiController.java | 11 src/main/java/com/example/exception/ServiceException.java | 61 src/main/java/com/example/utils/text/CharsetKit.java | 91 src/main/java/com/example/domain/TjProject.java | 234 ++ src/main/resources/application-win.yaml | 3 src/main/java/com/example/constant/Constants.java | 147 + src/main/java/com/example/domain/TjConsumables.java | 64 src/main/java/com/example/datasource/DynamicDataSourceContextHolder.java | 41 src/main/java/com/example/constant/UserConstants.java | 111 + src/main/java/com/example/domain/TjAdvice.java | 83 src/main/java/com/example/utils/text/Convert.java | 849 ++++++++ src/main/java/com/example/dto/xian/meiji/FeiYongMxDto.java | 34 src/main/java/com/example/utils/StringUtils.java | 542 +++++ src/main/java/com/example/domain/TjCustomer.java | 290 +++ src/main/java/com/example/domain/TjStandard.java | 74 src/main/java/com/example/mapper/SysConfigMapper.java | 76 src/main/java/com/example/utils/FastJson2JsonRedisSerializer.java | 43 src/main/java/com/example/constant/CacheConstants.java | 43 src/main/resources/application.yaml | 15 src/main/java/com/example/domain/TjAskWorkLog.java | 94 /dev/null | 3 src/main/java/com/example/config/DruidConfig.java | 129 + src/main/java/com/example/utils/RedisCache.java | 266 ++ src/main/java/com/example/dto/xian/meiji/CheXiaoMzFyDto.java | 24 src/main/java/com/example/dto/xian/meiji/CreateMenZhenFyDto.java | 38 src/main/java/com/example/service/xian/MeiJiService.java | 471 ++++ src/main/java/com/example/utils/text/StrFormatter.java | 76 src/main/java/com/example/utils/HttpClientUtils.java | 574 ++++++ src/main/java/com/example/domain/BaseEntity.java | 128 + src/main/resources/mapper/SysConfigMapper.xml | 129 + 42 files changed, 5,661 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 549e00a..52821b2 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ ### VS Code ### .vscode/ +/log.path_IS_UNDEFINED/ +/logs/ +/src/main/resources/log.log diff --git a/pom.xml b/pom.xml index b32a7c0..277f98f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ <artifactId>ltkj_peis_sjpt</artifactId> <version>0.0.1-SNAPSHOT</version> <name>ltkj_peis_sjpt</name> - <packaging>war</packaging> + <packaging>jar</packaging> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> @@ -68,6 +68,36 @@ <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.11</version> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-validation</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis</artifactId> + </dependency> + <dependency> + <groupId>io.jsonwebtoken</groupId> + <artifactId>jjwt</artifactId> + <version>0.9.1</version> + </dependency> + <dependency> + <groupId>com.alibaba.fastjson2</groupId> + <artifactId>fastjson2</artifactId> + <version>2.0.39</version> + </dependency> + <dependency> + <groupId>redis.clients</groupId> + <artifactId>jedis</artifactId> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + </dependency> </dependencies> <build> diff --git a/src/main/java/com/example/config/DruidConfig.java b/src/main/java/com/example/config/DruidConfig.java index dba1ede..9671b24 100644 --- a/src/main/java/com/example/config/DruidConfig.java +++ b/src/main/java/com/example/config/DruidConfig.java @@ -4,6 +4,9 @@ import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties; import com.alibaba.druid.util.Utils; +import com.example.datasource.DynamicDataSource; +import com.example.enums.DataSourceType; +import com.example.utils.SpringUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -106,6 +109,132 @@ return druidProperties.dataSource(dataSource); } + @Bean +// @ConfigurationProperties("spring.datasource.druid.slavehis") +// @ConditionalOnProperty(prefix = "spring.datasource.druid.slavehis", name = "enabled", havingValue = "true") + public DataSource slaveHisDataSource(DruidProperties druidProperties) { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + Properties props = new Properties(); + try { + // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 + FileInputStream fis = null; + try { + fis = new FileInputStream(CONFIG_PATH); + } catch (FileNotFoundException e) { + log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌锛�"); + } + props.load(fis); + fis.close(); + // 鑾峰彇灞炴�у�煎苟璧嬪�� + Properties properties = new Properties(); + // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� + properties.setProperty("druid.enabled",props.getProperty("hisenabled")); + properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver"); + properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("hisip")+":"+props.getProperty("hisprot")+";DatabaseName="+props.getProperty("hisname")+ + ";&characterEncoding=utf8"); + properties.setProperty("druid.username",props.getProperty("hisusername")); + properties.setProperty("druid.password",props.getProperty("hispassword")); + dataSource.restart(properties); + log.info("his鏁版嵁搴撹繛鎺ユ垚鍔�!!!"); + } catch (Exception e) { + log.info("鏁版嵁搴撹繛鎺ュけ璐� 璇疯仈绯荤鐞嗗憳锛�"); + e.printStackTrace(); + } + return druidProperties.dataSource(dataSource); + } + + @Bean +// @ConfigurationProperties("spring.datasource.druid.slavelis") +// @ConditionalOnProperty(prefix = "spring.datasource.druid.slavelis", name = "enabled", havingValue = "true") + public DataSource slaveDataLisSource(DruidProperties druidProperties) { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + Properties props = new Properties(); + try { + // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 + FileInputStream fis = null; + try { + fis = new FileInputStream(CONFIG_PATH); + } catch (FileNotFoundException e) { + log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌锛�"); + } + props.load(fis); + fis.close(); + // 鑾峰彇灞炴�у�煎苟璧嬪�� + Properties properties = new Properties(); + // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� + properties.setProperty("druid.enabled",props.getProperty("lisenabled")); + properties.setProperty("druid.url","jdbc:mysql://"+props.getProperty("lisip")+":"+props.getProperty("lisprot")+"/"+props.getProperty("lisname")+"" + + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8"); + properties.setProperty("druid.username",props.getProperty("lisusername")); + properties.setProperty("druid.password",props.getProperty("lispassword")); + dataSource.restart(properties); + log.info("鏁版嵁搴撹繛鎺ユ垚鍔�!!!"); + } catch (Exception e) { + log.info("鏁版嵁搴撹繛鎺ュけ璐� 璇疯仈绯荤鐞嗗憳锛�"); + e.printStackTrace(); + } + return druidProperties.dataSource(dataSource); + } + + @Bean +// @ConfigurationProperties("spring.datasource.druid.slavepacs") +// @ConditionalOnProperty(prefix = "spring.datasource.druid.slavepacs", name = "enabled", havingValue = "true") + public DataSource slaveDataPacsSource(DruidProperties druidProperties) { + DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); + Properties props = new Properties(); + try { + // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 + FileInputStream fis = null; + try { + fis = new FileInputStream(CONFIG_PATH); + } catch (FileNotFoundException e) { + log.info("鏁版嵁搴撹繛鎺ユ枃浠舵壘涓嶅埌"); + } + props.load(fis); + fis.close(); + // 鑾峰彇灞炴�у�煎苟璧嬪�� + Properties properties = new Properties(); + // 杩欓噷鏄祴璇曞啓娉曪紝鍏蜂綋鐨剉alue鍙互閫氳繃璇锋眰鍙傛暟浼犻�掕繃鏉� + properties.setProperty("druid.enabled",props.getProperty("pacsenabled")); + properties.setProperty("druid.driverClassName","oracle.jdbc.OracleDriver"); + properties.setProperty("druid.url","jdbc:oracle:thin:@//"+props.getProperty("pacsip")+"/"+props.getProperty("pacsname")); + properties.setProperty("druid.username",props.getProperty("pacsusername")); + properties.setProperty("druid.password",props.getProperty("pacspassword")); + dataSource.restart(properties); + log.info("鏁版嵁搴撹繛鎺ユ垚鍔�!!!"); + } catch (Exception e) { + log.info("鏁版嵁搴撹繛鎺ュけ璐� 璇疯仈绯荤鐞嗗憳锛�"); + e.printStackTrace(); + } + return druidProperties.dataSource(dataSource); + } + + @Bean(name = "dynamicDataSource") + @Primary + public DynamicDataSource dataSource(DataSource masterDataSource) { + Map<Object, Object> targetDataSources = new HashMap<>(); + targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource); + setDataSource(targetDataSources, DataSourceType.SLAVE_HIS.name(), "slaveHisDataSource"); + setDataSource(targetDataSources, DataSourceType.SLAVE_LIS.name(), "slaveDataLisSource"); + setDataSource(targetDataSources, DataSourceType.SLAVE_PACS.name(), "slaveDataPacsSource"); + return new DynamicDataSource(masterDataSource, targetDataSources); + } + + /** + * 璁剧疆鏁版嵁婧� + * + * @param targetDataSources 澶囬�夋暟鎹簮闆嗗悎 + * @param sourceName 鏁版嵁婧愬悕绉� + * @param beanName bean鍚嶇О + */ + public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName) { + try { + DataSource dataSource = SpringUtils.getBean(beanName); + targetDataSources.put(sourceName, dataSource); + } catch (Exception e) { + } + } + /** * 鍘婚櫎鐩戞帶椤甸潰搴曢儴鐨勫箍鍛� */ diff --git a/src/main/java/com/example/config/RedisConfig.java b/src/main/java/com/example/config/RedisConfig.java new file mode 100644 index 0000000..cc503cd --- /dev/null +++ b/src/main/java/com/example/config/RedisConfig.java @@ -0,0 +1,175 @@ +package com.example.config; + +import com.example.utils.FastJson2JsonRedisSerializer; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.script.DefaultRedisScript; +import org.springframework.data.redis.serializer.StringRedisSerializer; +import redis.clients.jedis.JedisPoolConfig; + +import java.io.*; +import java.util.Properties; + +/** + * redis閰嶇疆 + * + * @author ltkj + */ +@Configuration +@EnableCaching +@Slf4j +public class RedisConfig extends CachingConfigurerSupport { + + @Value ("${config.path}") + private String url; + + @Value ("${config.dir}") + private String path; + + @Bean + @SuppressWarnings(value = {"unchecked", "rawtypes"}) + public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate<Object, Object> template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + + FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); + + // 浣跨敤StringRedisSerializer鏉ュ簭鍒楀寲鍜屽弽搴忓垪鍖杛edis鐨刱ey鍊� + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(serializer); + + // Hash鐨刱ey涔熼噰鐢⊿tringRedisSerializer鐨勫簭鍒楀寲鏂瑰紡 + template.setHashKeySerializer(new StringRedisSerializer()); + template.setHashValueSerializer(serializer); + + template.afterPropertiesSet(); + return template; + } + + @Bean + public JedisPoolConfig jedisPoolConfig() { + JedisPoolConfig config = new JedisPoolConfig(); + // 璁剧疆JedisPoolConfig鐨勭浉鍏冲弬鏁帮紝渚嬪鏈�澶ц繛鎺ユ暟銆佹渶澶х┖闂叉椂闂寸瓑 +// config.setMinIdle(0); +// config.setMaxIdle(8); +// config.setMaxTotal(8); +// config.setMaxWaitMillis(-1); +// config.setTestOnBorrow(true); +// config.setTestOnReturn(true); + return config; + } + @Bean + public RedisConnectionFactory redisConnectionFactory(JedisPoolConfig jedisPoolConfig) { + JedisConnectionFactory factory = new JedisConnectionFactory(); + // 浠庢枃浠朵腑璇诲彇閰嶇疆淇℃伅 + try { + FileInputStream fis = null; + Properties props = new Properties(); + try { + fis = new FileInputStream(url); + } catch (FileNotFoundException e) { + log.info("閰嶇疆鏂囦欢鎵句笉鍒� 绯荤粺姝e湪鍒涘缓锛�"); + File f = new File(path); + if(!f.exists()){ + f.mkdirs(); + } + File file = new File(url); + try { + FileWriter fileWriter = new FileWriter(file); + fileWriter.write("ip = 浣犵殑涓绘暟鎹簱杩炴帴ip鍦板潃\n"); + fileWriter.write("prot = 浣犵殑涓绘暟鎹簱杩炴帴绔彛\n"); + fileWriter.write("name = 浣犵殑涓绘暟鎹簱杩炴帴鍚嶇О\n"); + fileWriter.write("username = 浣犵殑涓绘暟鎹簱杩炴帴鐢ㄦ埛鍚峔n"); + fileWriter.write("password = 浣犵殑涓绘暟鎹簱杩炴帴瀵嗙爜\n"); + fileWriter.write("hisenabled = 鏄惁寮�鍚� his 浠庡簱鏁版嵁搴撹繛鎺� (浠庢暟鎹簮寮�鍏�/榛樿鍏抽棴 fales)\n"); + fileWriter.write("\n"); + + fileWriter.write("hisip = 浣犵殑 his 鏁版嵁搴撹繛鎺p鍦板潃\n"); + fileWriter.write("hisprot = 浣犵殑 his 鏁版嵁搴撹繛鎺ョ鍙n"); + fileWriter.write("hisname = 浣犵殑 his 鏁版嵁搴撹繛鎺ュ悕绉癨n"); + fileWriter.write("hisusername = 浣犵殑 his 鏁版嵁搴撹繛鎺ョ敤鎴峰悕\n"); + fileWriter.write("hispassword = 浣犵殑 his 鏁版嵁搴撹繛鎺ュ瘑鐮乗n"); + fileWriter.write("\n"); + + fileWriter.write("pacsenabled = 鏄惁寮�鍚痯acs浠庡簱鏁版嵁搴撹繛鎺� (浠庢暟鎹簮寮�鍏�/榛樿鍏抽棴 fales)\n"); + fileWriter.write("pacsip = 浣犵殑pacs鏁版嵁搴撹繛鎺p鍦板潃\n"); + fileWriter.write("pacsprot = 浣犵殑pacs鏁版嵁搴撹繛鎺ョ鍙n"); + fileWriter.write("pacsname = 浣犵殑pacs鏁版嵁搴撹繛鎺ュ悕绉癨n"); + fileWriter.write("pacsusername = 浣犵殑pacs鏁版嵁搴撹繛鎺ョ敤鎴峰悕\n"); + fileWriter.write("pacspassword = 浣犵殑pacs鏁版嵁搴撹繛鎺ュ瘑鐮乗n"); + fileWriter.write("\n"); + + fileWriter.write("lisenabled = 鏄惁寮�鍚� lis 浠庡簱鏁版嵁搴撹繛鎺� (浠庢暟鎹簮寮�鍏�/榛樿鍏抽棴 fales)\n"); + fileWriter.write("lisip = 浣犵殑 lis 鏁版嵁搴撹繛鎺p鍦板潃\n"); + fileWriter.write("lisprot = 浣犵殑 lis 鏁版嵁搴撹繛鎺ョ鍙n"); + fileWriter.write("lisname = 浣犵殑 lis 鏁版嵁搴撹繛鎺ュ悕绉癨n"); + fileWriter.write("lisusername = 浣犵殑 lis 鏁版嵁搴撹繛鎺ョ敤鎴峰悕\n"); + fileWriter.write("lispassword = 浣犵殑 lis 鏁版嵁搴撹繛鎺ュ瘑鐮乗n"); + fileWriter.write("redisIp = 浣犵殑redisIp鍦板潃\n"); + fileWriter.write("redisProt = 浣犵殑redis绔彛\n"); + fileWriter.write("redisIpDatabase = 浣犵殑redis閾炬帴搴揬n"); + fileWriter.write("redisPassword = 浣犵殑redis瀵嗙爜\n"); + fileWriter.write("\n"); + fileWriter.close(); + log.info("閰嶇疆鏂囦欢鍒涘缓鎴愬姛锛�"); + } catch (IOException ioException) { + log.info("閰嶇疆鏂囦欢鍒涘缓澶辫触 璇疯仈绯荤鐞嗗憳鎵嬪姩鍒涘缓锛�"); + ioException.printStackTrace(); + } + e.printStackTrace(); + } + props.load(fis); + fis.close(); + // 鑾峰彇灞炴�у�煎苟璧嬪�� + factory.setPoolConfig(jedisPoolConfig); + // 璁剧疆Redis鏈嶅姟鍣ㄧ殑鍦板潃鍜岀鍙e彿 + factory.setHostName(props.getProperty("redisIp")); + factory.setPort(Integer.parseInt(props.getProperty("redisProt"))); + // 濡傛灉闇�瑕佸瘑鐮侀獙璇侊紝璁剧疆瀵嗙爜 + factory.setPassword(props.getProperty("redisPassword")); + // 璁剧疆鍏朵粬鍙傛暟锛屽鏁版嵁搴撶储寮曠瓑 + factory.setDatabase(Integer.parseInt(props.getProperty("redisIpDatabase"))); + // 鏈�鍚庯紝鍒濆鍖栬繛鎺� + factory.afterPropertiesSet(); + log.info("redis杩炴帴鎴愬姛!!!"); + } catch (IOException e) { + log.info("redis杩炴帴澶辫触 璇疯仈绯荤鐞嗗憳锛�"); + e.printStackTrace(); + } + return factory; + } + + + @Bean + public DefaultRedisScript<Long> limitScript() { + DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>(); + redisScript.setScriptText(limitScriptText()); + redisScript.setResultType(Long.class); + return redisScript; + } + + /** + * 闄愭祦鑴氭湰 + */ + private String limitScriptText() { + return "local key = KEYS[1]\n" + + "local count = tonumber(ARGV[1])\n" + + "local time = tonumber(ARGV[2])\n" + + "local current = redis.call('get', key);\n" + + "if current and tonumber(current) > count then\n" + + " return tonumber(current);\n" + + "end\n" + + "current = redis.call('incr', key)\n" + + "if tonumber(current) == 1 then\n" + + " redis.call('expire', key, time)\n" + + "end\n" + + "return tonumber(current);"; + } +} diff --git a/src/main/java/com/example/constant/CacheConstants.java b/src/main/java/com/example/constant/CacheConstants.java new file mode 100644 index 0000000..21506d5 --- /dev/null +++ b/src/main/java/com/example/constant/CacheConstants.java @@ -0,0 +1,43 @@ +package com.example.constant; + +/** + * 缂撳瓨鐨刱ey 甯搁噺 + * + * @author ltkj + */ +public class CacheConstants { + /** + * 鐧诲綍鐢ㄦ埛 redis key + */ + public static final String LOGIN_TOKEN_KEY = "tj_login_tokens:"; + + /** + * 楠岃瘉鐮� redis key + */ + public static final String CAPTCHA_CODE_KEY = "TJ_captcha_codes:"; + + /** + * 鍙傛暟绠$悊 cache key + */ + public static final String SYS_CONFIG_KEY = "sys_config:"; + + /** + * 瀛楀吀绠$悊 cache key + */ + public static final String SYS_DICT_KEY = "sys_dict:"; + + /** + * 闃查噸鎻愪氦 redis key + */ + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; + + /** + * 闄愭祦 redis key + */ + public static final String RATE_LIMIT_KEY = "rate_limit:"; + + /** + * 鐧诲綍璐︽埛瀵嗙爜閿欒娆℃暟 redis key + */ + public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:"; +} diff --git a/src/main/java/com/example/constant/Constants.java b/src/main/java/com/example/constant/Constants.java new file mode 100644 index 0000000..96e3b7b --- /dev/null +++ b/src/main/java/com/example/constant/Constants.java @@ -0,0 +1,147 @@ +package com.example.constant; + +import io.jsonwebtoken.Claims; + +/** + * 閫氱敤甯搁噺淇℃伅 + * + * @author ltkj + */ +public class Constants { + /** + * UTF-8 瀛楃闆� + */ + public static final String UTF8 = "UTF-8"; + + /** + * GBK 瀛楃闆� + */ + public static final String GBK = "GBK"; + + /** + * www涓诲煙 + */ + public static final String WWW = "www."; + + /** + * http璇锋眰 + */ + public static final String HTTP = "http://"; + + /** + * https璇锋眰 + */ + public static final String HTTPS = "https://"; + + /** + * 閫氱敤鎴愬姛鏍囪瘑 + */ + public static final String SUCCESS = "0"; + + /** + * 閫氱敤澶辫触鏍囪瘑 + */ + public static final String FAIL = "1"; + + /** + * 鐧诲綍鎴愬姛 + */ + public static final String LOGIN_SUCCESS = "Success"; + + /** + * 娉ㄩ攢 + */ + public static final String LOGOUT = "Logout"; + + /** + * 娉ㄥ唽 + */ + public static final String REGISTER = "Register"; + + /** + * 鐧诲綍澶辫触 + */ + public static final String LOGIN_FAIL = "Error"; + + /** + * 楠岃瘉鐮佹湁鏁堟湡锛堝垎閽燂級 + */ + public static final Integer CAPTCHA_EXPIRATION = 2; + + /** + * 浠ょ墝 + */ + public static final String TOKEN = "token"; + + /** + * 浠ょ墝鍓嶇紑 + */ + public static final String TOKEN_PREFIX = "Bearer "; + + /** + * 浠ょ墝鍓嶇紑 + */ + public static final String LOGIN_USER_KEY = "tj_login_user_key"; + + /** + * 鐢ㄦ埛ID + */ + public static final String JWT_USERID = "userid"; + + /** + * 鐢ㄦ埛鍚嶇О + */ + public static final String JWT_USERNAME = Claims.SUBJECT; + + /** + * 鐢ㄦ埛澶村儚 + */ + public static final String JWT_AVATAR = "avatar"; + + /** + * 鍒涘缓鏃堕棿 + */ + public static final String JWT_CREATED = "created"; + + /** + * 鐢ㄦ埛鏉冮檺 + */ + public static final String JWT_AUTHORITIES = "authorities"; + + /** + * 璧勬簮鏄犲皠璺緞 鍓嶇紑 + */ + public static final String RESOURCE_PREFIX = "/profile"; + + /** + * RMI 杩滅▼鏂规硶璋冪敤 + */ + public static final String LOOKUP_RMI = "rmi:"; + + /** + * LDAP 杩滅▼鏂规硶璋冪敤 + */ + public static final String LOOKUP_LDAP = "ldap:"; + + /** + * LDAPS 杩滅▼鏂规硶璋冪敤 + */ + public static final String LOOKUP_LDAPS = "ldaps:"; + + /** + * 瀹氭椂浠诲姟鐧藉悕鍗曢厤缃紙浠呭厑璁歌闂殑鍖呭悕锛屽鍏朵粬闇�瑕佸彲浠ヨ嚜琛屾坊鍔狅級 + */ + public static final String[] JOB_WHITELIST_STR = {"com.ltkj"}; + + /** + * 瀹氭椂浠诲姟杩濊鐨勫瓧绗� + */ + public static final String[] JOB_ERROR_STR = {"java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", + "org.springframework", "org.apache", "com.ltkj.common.mallOrderUtils.file"}; + + + /** + * 鐧诲綍鐢ㄦ埛缂栧彿 redis key + */ + public static final String LOGIN_USERID_KEY = "tj_login_userid:"; +} diff --git a/src/main/java/com/example/constant/UserConstants.java b/src/main/java/com/example/constant/UserConstants.java new file mode 100644 index 0000000..6649117 --- /dev/null +++ b/src/main/java/com/example/constant/UserConstants.java @@ -0,0 +1,111 @@ +package com.example.constant; + +/** + * 鐢ㄦ埛甯搁噺淇℃伅 + * + * @author ltkj + */ +public class UserConstants { + /** + * 骞冲彴鍐呯郴缁熺敤鎴风殑鍞竴鏍囧織 + */ + public static final String SYS_USER = "SYS_USER"; + + /** + * 姝e父鐘舵�� + */ + public static final String NORMAL = "0"; + + /** + * 寮傚父鐘舵�� + */ + public static final String EXCEPTION = "1"; + + /** + * 鐢ㄦ埛灏佺鐘舵�� + */ + public static final String USER_DISABLE = "1"; + + /** + * 瑙掕壊灏佺鐘舵�� + */ + public static final String ROLE_DISABLE = "1"; + + /** + * 閮ㄩ棬姝e父鐘舵�� + */ + public static final String DEPT_NORMAL = "0"; + + /** + * 閮ㄩ棬鍋滅敤鐘舵�� + */ + public static final String DEPT_DISABLE = "1"; + + /** + * 瀛楀吀姝e父鐘舵�� + */ + public static final String DICT_NORMAL = "0"; + + /** + * 鏄惁涓虹郴缁熼粯璁わ紙鏄級 + */ + public static final String YES = "Y"; + + /** + * 鏄惁鑿滃崟澶栭摼锛堟槸锛� + */ + public static final String YES_FRAME = "0"; + + /** + * 鏄惁鑿滃崟澶栭摼锛堝惁锛� + */ + public static final String NO_FRAME = "1"; + + /** + * 鑿滃崟绫诲瀷锛堢洰褰曪級 + */ + public static final String TYPE_DIR = "M"; + + /** + * 鑿滃崟绫诲瀷锛堣彍鍗曪級 + */ + public static final String TYPE_MENU = "C"; + + /** + * 鑿滃崟绫诲瀷锛堟寜閽級 + */ + public static final String TYPE_BUTTON = "F"; + + /** + * Layout缁勪欢鏍囪瘑 + */ + public final static String LAYOUT = "Layout"; + + /** + * ParentView缁勪欢鏍囪瘑 + */ + public final static String PARENT_VIEW = "ParentView"; + + /** + * InnerLink缁勪欢鏍囪瘑 + */ + public final static String INNER_LINK = "InnerLink"; + + /** + * 鏍¢獙杩斿洖缁撴灉鐮� + */ + public final static String UNIQUE = "0"; + public final static String NOT_UNIQUE = "1"; + + /** + * 鐢ㄦ埛鍚嶉暱搴﹂檺鍒� + */ + public static final int USERNAME_MIN_LENGTH = 2; + public static final int USERNAME_MAX_LENGTH = 20; + + /** + * 瀵嗙爜闀垮害闄愬埗 + */ + public static final int PASSWORD_MIN_LENGTH = 5; + public static final int PASSWORD_MAX_LENGTH = 20; +} diff --git a/src/main/java/com/example/controller/xian/MeiJiController.java b/src/main/java/com/example/controller/xian/MeiJiController.java new file mode 100644 index 0000000..01e1475 --- /dev/null +++ b/src/main/java/com/example/controller/xian/MeiJiController.java @@ -0,0 +1,11 @@ +package com.example.controller.xian; + +/** + * 瑗垮畨鐓ゆ満鍖婚櫌 + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: zhaowenxuan + * @Date: 2024/12/17 17:16 + */ +public class MeiJiController { + +} diff --git a/src/main/java/com/example/datasource/DynamicDataSource.java b/src/main/java/com/example/datasource/DynamicDataSource.java new file mode 100644 index 0000000..7470c4a --- /dev/null +++ b/src/main/java/com/example/datasource/DynamicDataSource.java @@ -0,0 +1,24 @@ +package com.example.datasource; + +import java.util.Map; +import javax.sql.DataSource; + +import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; + +/** + * 鍔ㄦ�佹暟鎹簮 + * + * @author ltkj + */ +public class DynamicDataSource extends AbstractRoutingDataSource { + public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) { + super.setDefaultTargetDataSource(defaultTargetDataSource); + super.setTargetDataSources(targetDataSources); + super.afterPropertiesSet(); + } + + @Override + protected Object determineCurrentLookupKey() { + return DynamicDataSourceContextHolder.getDataSourceType(); + } +} diff --git a/src/main/java/com/example/datasource/DynamicDataSourceContextHolder.java b/src/main/java/com/example/datasource/DynamicDataSourceContextHolder.java new file mode 100644 index 0000000..0e616e9 --- /dev/null +++ b/src/main/java/com/example/datasource/DynamicDataSourceContextHolder.java @@ -0,0 +1,41 @@ +package com.example.datasource; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 鏁版嵁婧愬垏鎹㈠鐞� + * + * @author ltkj + */ +public class DynamicDataSourceContextHolder { + public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class); + + /** + * 浣跨敤ThreadLocal缁存姢鍙橀噺锛孴hreadLocal涓烘瘡涓娇鐢ㄨ鍙橀噺鐨勭嚎绋嬫彁渚涚嫭绔嬬殑鍙橀噺鍓湰锛� + * 鎵�浠ユ瘡涓�涓嚎绋嬮兘鍙互鐙珛鍦版敼鍙樿嚜宸辩殑鍓湰锛岃�屼笉浼氬奖鍝嶅叾瀹冪嚎绋嬫墍瀵瑰簲鐨勫壇鏈�� + */ + private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>(); + + /** + * 璁剧疆鏁版嵁婧愮殑鍙橀噺 + */ + public static void setDataSourceType(String dsType) { + log.info("鍒囨崲鍒皗}鏁版嵁婧�", dsType); + CONTEXT_HOLDER.set(dsType); + } + + /** + * 鑾峰緱鏁版嵁婧愮殑鍙橀噺 + */ + public static String getDataSourceType() { + return CONTEXT_HOLDER.get(); + } + + /** + * 娓呯┖鏁版嵁婧愬彉閲� + */ + public static void clearDataSourceType() { + CONTEXT_HOLDER.remove(); + } +} diff --git a/src/main/java/com/example/domain/BaseEntity.java b/src/main/java/com/example/domain/BaseEntity.java new file mode 100644 index 0000000..d6e2a54 --- /dev/null +++ b/src/main/java/com/example/domain/BaseEntity.java @@ -0,0 +1,128 @@ +package com.example.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * Entity鍩虹被 + * + * @author ltkj + */ +@Data +public class BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 鍒涘缓鑰� + */ + @TableField(fill = FieldFill.INSERT) + private String createBy; + + /** + * 鍒涘缓鏃堕棿 + */ + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField(fill = FieldFill.INSERT) + private Date createTime; + + /** + * 鏇存柊鑰� + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private String updateBy; + + /** + * 鏇存柊鏃堕棿 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField(fill = FieldFill.INSERT_UPDATE) + private Date updateTime; + + /** + * 澶囨敞 + */ + @TableField(exist = false) + private String remark; + + /** + * 璇锋眰鍙傛暟 + */ + @TableField(exist = false) + private Map<String, Object> params; + + /** + * 0鍒犻櫎1鏈垹闄� + */ + @TableLogic + private Integer deleted; + + @TableField(fill = FieldFill.INSERT,exist = false) + private String createId; + + @TableField(fill = FieldFill.INSERT_UPDATE,exist = false) + private String updateId; + + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public String getUpdateBy() { + return updateBy; + } + + public void setUpdateBy(String updateBy) { + this.updateBy = updateBy; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Map<String, Object> getParams() { + if (params == null) { + params = new HashMap<>(); + } + return params; + } + + public void setParams(Map<String, Object> params) { + this.params = params; + } +} diff --git a/src/main/java/com/example/domain/SysConfig.java b/src/main/java/com/example/domain/SysConfig.java new file mode 100644 index 0000000..ae8f5e4 --- /dev/null +++ b/src/main/java/com/example/domain/SysConfig.java @@ -0,0 +1,103 @@ +package com.example.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +/** + * 鍙傛暟閰嶇疆琛� sys_config + * + * @author ltkj + */ +public class SysConfig extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 鍙傛暟涓婚敭 + */ + private Long configId; + + /** + * 鍙傛暟鍚嶇О + */ + private String configName; + + /** + * 鍙傛暟閿悕 + */ + private String configKey; + + /** + * 鍙傛暟閿�� + */ + private String configValue; + + /** + * 绯荤粺鍐呯疆锛圷鏄� N鍚︼級 + */ + private String configType; + + public Long getConfigId() { + return configId; + } + + public void setConfigId(Long configId) { + this.configId = configId; + } + + @NotBlank(message = "鍙傛暟鍚嶇О涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "鍙傛暟鍚嶇О涓嶈兘瓒呰繃100涓瓧绗�") + public String getConfigName() { + return configName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + @NotBlank(message = "鍙傛暟閿悕闀垮害涓嶈兘涓虹┖") + @Size(min = 0, max = 100, message = "鍙傛暟閿悕闀垮害涓嶈兘瓒呰繃100涓瓧绗�") + public String getConfigKey() { + return configKey; + } + + public void setConfigKey(String configKey) { + this.configKey = configKey; + } + + @NotBlank(message = "鍙傛暟閿�间笉鑳戒负绌�") + @Size(min = 0, max = 500, message = "鍙傛暟閿�奸暱搴︿笉鑳借秴杩�500涓瓧绗�") + public String getConfigValue() { + return configValue; + } + + public void setConfigValue(String configValue) { + this.configValue = configValue; + } + + public String getConfigType() { + return configType; + } + + public void setConfigType(String configType) { + this.configType = configType; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("configId", getConfigId()) + .append("configName", getConfigName()) + .append("configKey", getConfigKey()) + .append("configValue", getConfigValue()) + .append("configType", getConfigType()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/src/main/java/com/example/domain/TjAdvice.java b/src/main/java/com/example/domain/TjAdvice.java new file mode 100644 index 0000000..0481a62 --- /dev/null +++ b/src/main/java/com/example/domain/TjAdvice.java @@ -0,0 +1,83 @@ +package com.example.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableLogic; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.List; + +/** + * advice瀵硅薄 tj_advice + * + * @author ltkj + * @date 2022-11-24 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TjAdvice extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + @TableId(type=IdType.AUTO) + private Long id; + + /** + * 椤圭洰id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long proId; + + /** + * 鏍囬 + */ + private String title; + /** + * 寤鸿 + */ + private String advice; + + private String deptId; + + private String kjbq; + + private String adSex; + + private String isZj; + + + @TableField(exist = false) + private String proName; + + @TableField(exist = false) + private List<String> kjbqz; + + @TableField(exist = false) + private String deptName; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("proId", getProId()) + .append("title", getTitle()) + .append("advice", getAdvice()) + .append("createTime", getCreateTime()) + .append("createBy", getCreateBy()) + .append("updateTime", getUpdateTime()) + .append("updateBy", getUpdateBy()) + .append("deleted", getDeleted()) + .append("deptName", getDeptName()) + .toString(); + } +} diff --git a/src/main/java/com/example/domain/TjAskWorkLog.java b/src/main/java/com/example/domain/TjAskWorkLog.java new file mode 100644 index 0000000..7e24dd7 --- /dev/null +++ b/src/main/java/com/example/domain/TjAskWorkLog.java @@ -0,0 +1,94 @@ +package com.example.domain; + +import java.util.Date; +import java.util.List; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 闂瘖鑱屼笟鍙茶褰曞璞� tj_ask_work_log + * + * @author ltkj_璧典匠璞�&鏉庢牸 + * @date 2023-12-06 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TjAskWorkLog extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @TableId(type= IdType.AUTO) + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 浣撴鍙� + */ + private String tjNumber; + + /** + * 瀹㈡埛 + */ + private Long cusId; + + /** + * 瀹㈡埛鍚� + */ + private String cusName; + + /** + * 闂瘖id + */ + private Long askId; + + /** + * 寮�濮嬫椂闂� + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date beginTime; + + /** + * 缁撴潫鏃堕棿 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date endTime; + + /** + * 宸ヤ綔鍗曚綅 + */ + private String workCompany; + + /** + * 閮ㄩ棬 + */ + private String workDept; + + /** + * 宸ョ + */ + private String workType; + + /** + * 闃叉姢鎺柦 + */ + private String fangHu; + + + /** + * 鏈夊鍥犵礌 + */ + @TableField(exist = false) + private List<String> harmTypeLogs; + +} diff --git a/src/main/java/com/example/domain/TjConsumables.java b/src/main/java/com/example/domain/TjConsumables.java new file mode 100644 index 0000000..ff58544 --- /dev/null +++ b/src/main/java/com/example/domain/TjConsumables.java @@ -0,0 +1,64 @@ +package com.example.domain; + +import java.math.BigDecimal; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 浣撴鑰楁潗瀵硅薄 tj_consumables + * + * @author ltkj_璧典匠璞�&鏉庢牸 + * @date 2022-12-29 + */ +@Data +public class TjConsumables extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @TableId + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + /** + * 鏉愭枡鍚� + */ + private String makings; + + /** + * 鍗曚环 + */ + private BigDecimal price; + + /** + * 瑙勬牸 + */ + private String specifications; + + /** + * 鏄惁鍙備笌璁$畻 + */ + private String isCalculation; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("makings", getMakings()) + .append("price", getPrice()) + .append("specifications", getSpecifications()) + .append("isCalculation", getIsCalculation()) + .append("deleted", getDeleted()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} diff --git a/src/main/java/com/example/domain/TjCustomer.java b/src/main/java/com/example/domain/TjCustomer.java new file mode 100644 index 0000000..2b37633 --- /dev/null +++ b/src/main/java/com/example/domain/TjCustomer.java @@ -0,0 +1,290 @@ +package com.example.domain; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 瀹㈡埛淇℃伅瀵硅薄 tj_customer + * + * @author ltkj + * @date 2022-11-17 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TjCustomer extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭id + */ + @TableId + @JsonSerialize(using = ToStringSerializer.class) + private Long cusId; + + /** + * 瀹㈡埛濮撳悕 + */ + private String cusName; + + + private String pym; + + + private String cardId; + + + private String pationId; + + /** + * 瀹㈡埛鎬у埆 + */ + private Long cusSex; + + /** + * 鍑虹敓鏃ユ湡 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date cusBrithday; + + /** + * 鐜板眳浣忓湴鍧� + */ + private String cusAddr; + + /** + * 鎴峰彛鎵�鍦ㄥ湴鍧� + */ + private String addr; + + /** + * 鑱旂郴鐢佃瘽 + */ + private String cusPhone; + + /** + * 璐﹀彿瀵嗙爜 + */ + private String cusPassword; + + /** + * 閭斂缂栫爜 + */ + private String cusPostcode; + + /** + * 閭 + */ + private String cusEmail; + + /** + * 绱㈠紩鍗″彿 + */ + private String indexCard; + + /** + * 姘戞棌 + */ + private String cusNational; + + /** + * 濠氬Щ鐘跺喌 + */ + private String cusMarryStatus; + + /** + * 韬唤璇佸彿 + */ + private String cusIdcard; + + /** + * 浠嬬粛浜� + */ + private String cusIntroduce; + + /** + * 浣撴娆℃暟 + */ + private Long cusNumber; + + /** + * 鏄惁VIP + */ + private String cusIsvip; + /** + * 瑙掕壊 + */ + private Long role = 2L; + + /** + * 浣撴椤圭洰闆嗗悎 + */ + @TableField(exist = false) + private List<TjProject> tjProjects; + + /** + * 浣撴鍙� + */ + @TableField(exist = false) + private String tjNumber; + + /** + * 浣撴璁㈠崟鍙� + */ + @TableField(exist = false) + @JsonSerialize(using = ToStringSerializer.class) + private Long orderId; + + /** + * 浣撴鐘舵�� + */ + @TableField(exist = false) + private Long tjStatus; + + /** + * 浣撴绫诲埆 鍥㈤槦杩樻槸涓汉 + */ + @TableField(exist = false) + private String tjType; + + /** + * 棰勭害鎵�閫夊椁愩�佹墍閫夐」鐩� + */ + @TableField(exist = false) + private Long pacId; + + /** + * 浣撴鏃堕棿 + */ + @TableField(exist = false) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date tjTime; + + /** + * 鎵�鍦ㄥ崟浣嶅悕绉� + */ + @TableField(exist = false) + private String tjCompName; + + /** + * 鎵�鍦ㄥ崟浣峣d + */ + @TableField(exist = false) + private String compId; + + @TableField(exist = false) + private List<Long> proIds; //椤圭洰浠ラ�楀彿闅斿紑 + + /** + * 浣撴缂栧彿 + */ + @TableField(exist = false) + private String teamNo; + + @TableField(exist = false) + private String reservationId; + + @TableField(exist = false) + private String notCheckeds; + + /** + * 浣撴瀹屾垚鏃堕棿 + */ + @TableField(exist = false) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date finishTime; + + + + @TableField(exist = false) + private String discount; + + + @TableField(exist = false) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date applicationTime; + + @TableField(exist = false) + private String groupingId; + + @TableField(exist = false) + private String confirmStatus; + + private String idType; + + private String age; + + private String ageUnit; + + private String career; + + @TableField(updateStrategy = FieldStrategy.IGNORED) + private String connect; + + private String wechat; + + + @TableField(exist = false) + private Integer isHz; + + @TableField(exist = false) + private Long isPositive; + + @TableField(exist = false) + private String tjCategory; + + private String dwPhone; + + private String wenHua; + + @TableField(exist = false) + private List<TjAskWorkLog> workLogs; + + @TableField(exist = false) + private String isBlack; + + private Long dictCompId; + + private String compName; + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("cusId", getCusId()) + .append("cusName", getCusName()) + .append("cusSex", getCusSex()) + .append("cusBrithday", getCusBrithday()) + .append("cusAddr", getCusAddr()) + .append("cusPhone", getCusPhone()) + .append("cusPassword", getCusPassword()) + .append("cusPostcode", getCusPostcode()) + .append("cusEmail", getCusEmail()) + .append("indexCard", getIndexCard()) + .append("cusNational", getCusNational()) + .append("cusMarryStatus", getCusMarryStatus()) + .append("cusIdcard", getCusIdcard()) + .append("cusIntroduce", getCusIntroduce()) + .append("cusNumber", getCusNumber()) + .append("cusIsvip", getCusIsvip()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("deleted", getDeleted()) + .append("dwPhone", getDwPhone()) + .append("compId", getDictCompId()) + .append("compName", getCompName()) + .toString(); + } +} diff --git a/src/main/java/com/example/domain/TjProject.java b/src/main/java/com/example/domain/TjProject.java new file mode 100644 index 0000000..a1f7a3a --- /dev/null +++ b/src/main/java/com/example/domain/TjProject.java @@ -0,0 +1,234 @@ +package com.example.domain; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 浣撴椤圭洰瀵硅薄 tj_project + * + * @author ltkj + * @date 2022-11-17 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class TjProject extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭 + */ + @TableId + @JsonSerialize(using = ToStringSerializer.class) + private Long proId; + + /** + * 鐖堕」鐩甶d + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long proParentId; + + /** + * 椤圭洰鍚嶇О + */ + private String proName; + + /** + * 椤圭洰鑻辨枃鍚� + */ + private String proEngName; + + /** + * 椤圭洰浠锋牸 + */ + private BigDecimal proPrice; + + /** + * 椤圭洰鍘熶环 + */ + @TableField(exist = false) + private BigDecimal proOrdPrice; + + /** + * 澶囨敞 + */ + private String proRemark; + + + /** + * 妫�鏌ョ被鍒� + */ + private String proCheckType; + + /** + * 涓村簥鎰忎箟 + */ + private String proMeaning; + + /** + * 妫�鏌ユ柟寮� + */ + private String proCheckMethod; + + /** + * 鏄惁鐖剁骇 0涓虹埗1涓哄瓙 + */ + private Integer proStandard; + + /** + * 椤圭洰绫诲瀷 + */ + private String proType; + + /** + * 椤圭洰鐘舵�� + */ + private Integer proStatus; + + /** + * 濂楅鏄惁鍚湁璇ラ」鐩� + */ + @TableField(exist = false) + private Integer ischeck; + + /** + * 绉戝id + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long deptId; + + /** + * 璁¢噺鍗曚綅 + */ + private String proMetering; + + private String proDefault; + + private String proScope; + + @TableField(exist = false) + private String flag; + + @TableField(exist = false) + private List<TjProject> tjProjectList; + + @TableField(exist = false) + private List<TjStandard> tjStandardList; + + /** + * 鐖堕」鐩腑鐨勫瓙椤圭洰鍚嶇О瀛楃涓� + */ + @TableField(exist = false) + private String allSonProName; + + + /** + * 璇ラ」鐩殑鏍囧噯 + */ + @TableField(exist = false) + private TjStandard standard; + + /** + * 璇ラ」鐩殑寤鸿闆嗗悎 + */ + @TableField(exist = false) + private List<TjAdvice> adviceList; + + /** + * 璇ラ」鐩殑鑰楁潗闆嗗悎 + */ + @TableField(exist = false) + private List<TjConsumables> consumablesList; + + /** + * 璇ラ」鐩湪濂楅鍐呯幇浠� + */ + @TableField(exist = false) + private BigDecimal priceNow; + + /** + * 璇ラ」鐩墍鍦ㄩ儴闂ㄥ悕绉� + */ + @TableField(exist = false) + private String deptName; + + + /** + * 鏀惰垂椤圭洰id + */ + @TableField(exist = false) + @JsonSerialize(using = ToStringSerializer.class) + private Long sfxmId; + + + private String resultType; + + private String isSampling; + + private String specimenType; + + private String checkBw; + + + private String proSex; + + + private String isEat; + + + private String needReport; + + private String lisXmbm; + + private String lisXmmc; + + private String hisXmbm; + + private String hisXmmc; + + private String sfzhfy; + + private BigDecimal hisdj; + + private Integer sl; + + /** + * 瀛愰」鐩� + */ + @TableField(exist = false) + private List<TjProject> children = new ArrayList<TjProject>(); + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("proId", getProId()) + .append("proParentId", getProParentId()) + .append("proName", getProName()) + .append("proEngName", getProEngName()) + .append("proPrice", getProPrice()) + .append("proRemark", getProRemark()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("deleted", getDeleted()) + .append("proCheckType", getProCheckType()) + .append("proMeaning", getProMeaning()) + .append("proCheckMethod", getProCheckMethod()) + .append("proStandard", getProStandard()) + .append("proType", getProType()) + .append("ischeck", getIscheck()) + .toString(); + } +} diff --git a/src/main/java/com/example/domain/TjStandard.java b/src/main/java/com/example/domain/TjStandard.java new file mode 100644 index 0000000..fd44bff --- /dev/null +++ b/src/main/java/com/example/domain/TjStandard.java @@ -0,0 +1,74 @@ +package com.example.domain; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * standard瀵硅薄 tj_standard + * + * @author ltkj + * @date 2022-11-24 + */ +@Data +public class TjStandard extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 涓婚敭id + */ + @TableId + private String stanId; + + /** + * 椤圭洰id + */ + private Long proId; + + @TableField(exist = false) + private String proName; + + /** + * 浣撴浜烘�у埆 + */ + @TableField(updateStrategy= FieldStrategy.IGNORED) + private Integer tjSex; + + /** + * 浣撴浜虹被鍨� + */ + private Integer tjType; + + /** + * 鏍囧噯鍊� + */ + private String tjStandardGtValue; + + + /** + * 鏍囧噯鍊� + */ + private String tjStandardLtValue; + + /** + * 鍗曚綅 + */ + private String company; + + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("stanId", getStanId()) + .append("proId", getProId()) + .append("tjSex", getTjSex()) + .append("tjType", getTjType()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("deleted", getDeleted()) + .toString(); + } +} diff --git a/src/main/java/com/example/dto/xian/meiji/CheXiaoMzFyDto.java b/src/main/java/com/example/dto/xian/meiji/CheXiaoMzFyDto.java new file mode 100644 index 0000000..345bf7c --- /dev/null +++ b/src/main/java/com/example/dto/xian/meiji/CheXiaoMzFyDto.java @@ -0,0 +1,24 @@ +package com.example.dto.xian.meiji; + +import lombok.Data; + +import java.util.List; + +/** + * ClassName: CheXiaoMzFyDto <br/> + * Description: <br/> + * date: 2024/12/10 20:12<br/> + * + * @author zjh<br /> + */ +@Data +public class CheXiaoMzFyDto { + //灏辫瘖鍗″彿 + private String jiuZhenKh; + + //鐥呬汉Id(鍦℉IS涓殑鍞竴鐮�) + private String bingRenId; + + //璐圭敤id + private List<FeiYongIdDto>feiYongIdList; +} diff --git a/src/main/java/com/example/dto/xian/meiji/CreateMenZhenFyDto.java b/src/main/java/com/example/dto/xian/meiji/CreateMenZhenFyDto.java new file mode 100644 index 0000000..5c4f794 --- /dev/null +++ b/src/main/java/com/example/dto/xian/meiji/CreateMenZhenFyDto.java @@ -0,0 +1,38 @@ +package com.example.dto.xian.meiji; + +import lombok.Data; + +import java.util.List; + +/** + * ClassName: createMenZhenFyDto <br/> + * Description: <br/> + * date: 2024/12/10 11:57<br/> + * + * @author zjh<br /> + */ + +@Data +public class CreateMenZhenFyDto { + + //鐥呬汉Id(鍦℉IS涓殑鍞竴鐮�) + private String bingRenId; + //灏辫瘖鍗″彿 + private String jiuZhenKh; + //鎿嶄綔鍛�(鏀惰垂浜哄憳/浣撴/鑷姪鏈�) + private String caoZuoYuan; + //闄㈠尯Id + private String yuanQuId; + //搴旂敤Id锛堣嚜鍔╂満浼�010101锛屼綋妫� 870101锛� + private String yingYongId; + //寮�鍗曠瀹� + private String kaiDanKs; + //鐧昏娴佹按鍙� + private String dengJiLsh; + //鏀堕��鏍囧織(1:鐢熸垚寰呮敹璐�, 2鐢熸垚寰呴��璐�) + private String shouTuiBz; + //璐圭敤鏄庣粏 + private List<FeiYongMxDto> feiYongMxList; + + +} diff --git a/src/main/java/com/example/dto/xian/meiji/FeiYongIdDto.java b/src/main/java/com/example/dto/xian/meiji/FeiYongIdDto.java new file mode 100644 index 0000000..bb72d36 --- /dev/null +++ b/src/main/java/com/example/dto/xian/meiji/FeiYongIdDto.java @@ -0,0 +1,16 @@ +package com.example.dto.xian.meiji; + +import lombok.Data; + +/** + * ClassName: FeiYongIdDto <br/> + * Description: <br/> + * date: 2024/12/10 20:16<br/> + * + * @author zjh<br /> + */ +@Data +public class FeiYongIdDto { + //璐圭敤Id + private String feiYongId; +} diff --git a/src/main/java/com/example/dto/xian/meiji/FeiYongMxDto.java b/src/main/java/com/example/dto/xian/meiji/FeiYongMxDto.java new file mode 100644 index 0000000..5242d22 --- /dev/null +++ b/src/main/java/com/example/dto/xian/meiji/FeiYongMxDto.java @@ -0,0 +1,34 @@ +package com.example.dto.xian.meiji; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * ClassName: feiYongMxDto <br/> + * Description: <br/> + * date: 2024/12/10 11:57<br/> + * + * @author zjh<br /> + */ +@Data +public class FeiYongMxDto { + //璐圭敤鏄庣粏Id(閫�璐瑰繀浼�) + private String feiYongMxId; + //璐圭敤Id(閫�璐瑰繀浼�) + private String feiYongId; + //鏀惰垂椤圭洰Id(HIS鐨�) + private String shouFeiXmId; + //鏀惰垂椤圭洰鍚嶇О + private String shouFeiXmMc; + //鏁伴噺(閫�璐逛负璐�) + private Integer shuLiang; + //鍗曚环 + private BigDecimal danJia; + //缁撶畻閲戦(閫�璐逛负璐�) + private BigDecimal jieSuanJe; + //鎵ц绉戝 + private String zhiXingKs; + //鎵ц绉戝鍚嶇О + private String zhiXingKsMc; +} diff --git a/src/main/java/com/example/enums/DataSourceType.java b/src/main/java/com/example/enums/DataSourceType.java new file mode 100644 index 0000000..b68d4f1 --- /dev/null +++ b/src/main/java/com/example/enums/DataSourceType.java @@ -0,0 +1,24 @@ +package com.example.enums; + +/** + * 鏁版嵁婧� + * + * @author ruoyi + */ +public enum DataSourceType { + /** + * 涓诲簱 + */ + MASTER, + + /** + * 浠庡簱 + */ + SLAVE_PACS, + + + SLAVE_HIS, + + + SLAVE_LIS, +} diff --git a/src/main/java/com/example/exception/ServiceException.java b/src/main/java/com/example/exception/ServiceException.java new file mode 100644 index 0000000..04ad299 --- /dev/null +++ b/src/main/java/com/example/exception/ServiceException.java @@ -0,0 +1,61 @@ +package com.example.exception; + +/** + * 涓氬姟寮傚父 + */ +public final class ServiceException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** + * 閿欒鐮� + */ + private Integer code; + + /** + * 閿欒鎻愮ず + */ + private String message; + + /** + * 閿欒鏄庣粏锛屽唴閮ㄨ皟璇曢敊璇� + */ + private String detailMessage; + + /** + * 绌烘瀯閫犳柟娉曪紝閬垮厤鍙嶅簭鍒楀寲闂 + */ + public ServiceException() { + } + + public ServiceException(String message) { + this.message = message; + } + + public ServiceException(String message, Integer code) { + this.message = message; + this.code = code; + } + + public String getDetailMessage() { + return detailMessage; + } + + @Override + public String getMessage() { + return message; + } + + public Integer getCode() { + return code; + } + + public ServiceException setMessage(String message) { + this.message = message; + return this; + } + + public ServiceException setDetailMessage(String detailMessage) { + this.detailMessage = detailMessage; + return this; + } +} diff --git a/src/main/java/com/example/mapper/SysConfigMapper.java b/src/main/java/com/example/mapper/SysConfigMapper.java new file mode 100644 index 0000000..36729f0 --- /dev/null +++ b/src/main/java/com/example/mapper/SysConfigMapper.java @@ -0,0 +1,76 @@ +package com.example.mapper; + +import java.util.List; + +import com.example.domain.SysConfig; +import org.apache.ibatis.annotations.Select; + +/** + * 鍙傛暟閰嶇疆 鏁版嵁灞� + * + * @author ltkj + */ +public interface SysConfigMapper { + /** + * 鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + public SysConfig selectConfig(SysConfig config); + + /** + * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆闆嗗悎 + */ + public List<SysConfig> selectConfigList(SysConfig config); + + /** + * 鏍规嵁閿悕鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configKey 鍙傛暟閿悕 + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + public SysConfig checkConfigKeyUnique(String configKey); + + /** + * 鏂板鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int insertConfig(SysConfig config); + + /** + * 淇敼鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int updateConfig(SysConfig config); + + /** + * 鍒犻櫎鍙傛暟閰嶇疆 + * + * @param configId 鍙傛暟ID + * @return 缁撴灉 + */ + public int deleteConfigById(Long configId); + + /** + * 鎵归噺鍒犻櫎鍙傛暟淇℃伅 + * + * @param configIds 闇�瑕佸垹闄ょ殑鍙傛暟ID + * @return 缁撴灉 + */ + public int deleteConfigByIds(Long[] configIds); + + + + + + + void tbhisproprice(); +} diff --git a/src/main/java/com/example/service/ISysConfigService.java b/src/main/java/com/example/service/ISysConfigService.java new file mode 100644 index 0000000..87eab2b --- /dev/null +++ b/src/main/java/com/example/service/ISysConfigService.java @@ -0,0 +1,92 @@ +package com.example.service; + +import java.util.List; + +import com.example.domain.SysConfig; + +/** + * 鍙傛暟閰嶇疆 鏈嶅姟灞� + * + * @author ltkj + */ +public interface ISysConfigService { + /** + * 鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configId 鍙傛暟閰嶇疆ID + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + public SysConfig selectConfigById(Long configId); + + /** + * 鏍规嵁閿悕鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configKey 鍙傛暟閿悕 + * @return 鍙傛暟閿�� + */ + public String selectConfigByKey(String configKey); + + /** + * 鑾峰彇楠岃瘉鐮佸紑鍏� + * + * @return true寮�鍚紝false鍏抽棴 + */ + public boolean selectCaptchaEnabled(); + + /** + * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆闆嗗悎 + */ + public List<SysConfig> selectConfigList(SysConfig config); + + /** + * 鏂板鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int insertConfig(SysConfig config); + + /** + * 淇敼鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + public int updateConfig(SysConfig config); + + /** + * 鎵归噺鍒犻櫎鍙傛暟淇℃伅 + * + * @param configIds 闇�瑕佸垹闄ょ殑鍙傛暟ID + */ + public void deleteConfigByIds(Long[] configIds); + + /** + * 鍔犺浇鍙傛暟缂撳瓨鏁版嵁 + */ + public void loadingConfigCache(); + + /** + * 娓呯┖鍙傛暟缂撳瓨鏁版嵁 + */ + public void clearConfigCache(); + + /** + * 閲嶇疆鍙傛暟缂撳瓨鏁版嵁 + */ + public void resetConfigCache(); + + /** + * 鏍¢獙鍙傛暟閿悕鏄惁鍞竴 + * + * @param config 鍙傛暟淇℃伅 + * @return 缁撴灉 + */ + public String checkConfigKeyUnique(SysConfig config); + + + void tbhisproprice(); +} diff --git a/src/main/java/com/example/service/impl/SysConfigServiceImpl.java b/src/main/java/com/example/service/impl/SysConfigServiceImpl.java new file mode 100644 index 0000000..50de98e --- /dev/null +++ b/src/main/java/com/example/service/impl/SysConfigServiceImpl.java @@ -0,0 +1,209 @@ +package com.example.service.impl; + +import java.util.Collection; +import java.util.List; +import javax.annotation.PostConstruct; + +import com.example.constant.CacheConstants; +import com.example.constant.UserConstants; +import com.example.domain.SysConfig; +import com.example.exception.ServiceException; +import com.example.mapper.SysConfigMapper; +import com.example.service.ISysConfigService; +import com.example.utils.RedisCache; +import com.example.utils.StringUtils; +import com.example.utils.text.Convert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * 鍙傛暟閰嶇疆 鏈嶅姟灞傚疄鐜� + * + * @author ltkj + */ +@Service +public class SysConfigServiceImpl implements ISysConfigService { + @Autowired + private SysConfigMapper configMapper; + + @Autowired + private RedisCache redisCache; + + /** + * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧弬鏁板埌缂撳瓨 + */ + @PostConstruct + public void init() { + loadingConfigCache(); + } + + /** + * 鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configId 鍙傛暟閰嶇疆ID + * @return 鍙傛暟閰嶇疆淇℃伅 + */ + @Override + public SysConfig selectConfigById(Long configId) { + SysConfig config = new SysConfig(); + config.setConfigId(configId); + return configMapper.selectConfig(config); + } + + /** + * 鏍规嵁閿悕鏌ヨ鍙傛暟閰嶇疆淇℃伅 + * + * @param configKey 鍙傛暟key + * @return 鍙傛暟閿�� + */ + @Override + public String selectConfigByKey(String configKey) { + String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey))); + if (StringUtils.isNotEmpty(configValue)) { + return configValue; + } + SysConfig config = new SysConfig(); + config.setConfigKey(configKey); + SysConfig retConfig = configMapper.selectConfig(config); + if (StringUtils.isNotNull(retConfig)) { + redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue()); + return retConfig.getConfigValue(); + } + return StringUtils.EMPTY; + } + + /** + * 鑾峰彇楠岃瘉鐮佸紑鍏� + * + * @return true寮�鍚紝false鍏抽棴 + */ + @Override + public boolean selectCaptchaEnabled() { + String captchaEnabled = selectConfigByKey("sys.account.captchaEnabled"); + if (StringUtils.isEmpty(captchaEnabled)) { + return true; + } + return Convert.toBool(captchaEnabled); + } + + /** + * 鏌ヨ鍙傛暟閰嶇疆鍒楄〃 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 鍙傛暟閰嶇疆闆嗗悎 + */ + @Override + public List<SysConfig> selectConfigList(SysConfig config) { + return configMapper.selectConfigList(config); + } + + /** + * 鏂板鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertConfig(SysConfig config) { + int row = configMapper.insertConfig(config); + if (row > 0) { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + return row; + } + + /** + * 淇敼鍙傛暟閰嶇疆 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updateConfig(SysConfig config) { + int row = configMapper.updateConfig(config); + if (row > 0) { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + return row; + } + + /** + * 鎵归噺鍒犻櫎鍙傛暟淇℃伅 + * + * @param configIds 闇�瑕佸垹闄ょ殑鍙傛暟ID + */ + @Override + public void deleteConfigByIds(Long[] configIds) { + for (Long configId : configIds) { + if(configId==113){ + continue; + } + SysConfig config = selectConfigById(configId); + if (StringUtils.equals(UserConstants.YES, config.getConfigType())) { + throw new ServiceException(String.format("鍐呯疆鍙傛暟銆�%1$s銆戜笉鑳藉垹闄� ", config.getConfigKey())); + } + configMapper.deleteConfigById(configId); + redisCache.deleteObject(getCacheKey(config.getConfigKey())); + } + } + + /** + * 鍔犺浇鍙傛暟缂撳瓨鏁版嵁 + */ + @Override + public void loadingConfigCache() { + List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig()); + for (SysConfig config : configsList) { + redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue()); + } + } + + /** + * 娓呯┖鍙傛暟缂撳瓨鏁版嵁 + */ + @Override + public void clearConfigCache() { + Collection<String> keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*"); + redisCache.deleteObject(keys); + } + + /** + * 閲嶇疆鍙傛暟缂撳瓨鏁版嵁 + */ + @Override + public void resetConfigCache() { + clearConfigCache(); + loadingConfigCache(); + } + + /** + * 鏍¢獙鍙傛暟閿悕鏄惁鍞竴 + * + * @param config 鍙傛暟閰嶇疆淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkConfigKeyUnique(SysConfig config) { + Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId(); + SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey()); + if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + @Override + public void tbhisproprice() { + configMapper.tbhisproprice(); + } + + /** + * 璁剧疆cache key + * + * @param configKey 鍙傛暟閿� + * @return 缂撳瓨閿甼ey + */ + private String getCacheKey(String configKey) { + return CacheConstants.SYS_CONFIG_KEY + configKey; + } +} diff --git a/src/main/java/com/example/service/xian/MeiJiService.java b/src/main/java/com/example/service/xian/MeiJiService.java new file mode 100644 index 0000000..ff35c05 --- /dev/null +++ b/src/main/java/com/example/service/xian/MeiJiService.java @@ -0,0 +1,471 @@ +package com.example.service.xian; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSON; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.example.domain.TjCustomer; +import com.example.dto.xian.meiji.CheXiaoMzFyDto; +import com.example.dto.xian.meiji.CreateMenZhenFyDto; +import com.example.service.ISysConfigService; +import com.example.utils.HttpClientUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; + +import java.io.FileInputStream; +import java.io.IOException; +import java.time.Instant; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +/** + * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃 + * @Author: zhaowenxuan + * @Date: 2024/12/17 17:17 + */ +public class MeiJiService { + @Autowired + private ISysConfigService configService; + @Autowired + private RedisTemplate<String ,Object> redisTemplate; + + private static String HIS_URL = "http://oapi.pbkwyy.com/OAPI"; + + private static String CONFIG_PATH; + + private static String GRANT_TYPE = "client_credentials"; + private static String CLIENT_ID = "XFZZQEfXTZ7exhhi"; + private static String CLIENT_SECRET = "05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad"; +// private static String SCOP = ""; + +// http://oapi.pbkwyy.com/OAPI/oauth/token +// grant_type:client_credentials +// client_id:XFZZQEfXTZ7exhhi +// client_secret:05a192176c21edfcc9cf5fa26fc5a9e0c5b131ad + + @Value("${config.properties}") + public void setConfigPath(String configPath) { + CONFIG_PATH = configPath; + try { + FileInputStream inputStream = new FileInputStream(CONFIG_PATH); + Properties props = new Properties(); + props.load(inputStream); + String url = props.getProperty("df_his_api_url"); + String port = props.getProperty("df_his_api_port"); + GRANT_TYPE = props.getProperty("grant_type"); + CLIENT_ID= props.getProperty("client_id"); + CLIENT_SECRET = props.getProperty("client_secret"); +// SCOP = props.getProperty("scope"); + HIS_URL=url+":"+port+"/OAPI/"; + } catch (IOException throwables) { + throwables.printStackTrace(); + } + } + + + //鑾峰彇token + private JSONObject getToken () { + Map<String, Object> map = new HashMap<>(); + map.put("grant_type",GRANT_TYPE); + map.put("client_id",CLIENT_ID); + map.put("client_secret",CLIENT_SECRET); +// map.put("scope",SCOP); + String post = sendPost (HIS_URL+"/oauth/token", map); + if (StrUtil.isBlank(post)) return null; + JSONObject parseObj = JSONUtil.parseObj(post); +// Integer expiresIn = parseObj.getInt("expires_in"); +// if (expiresIn != null){ +// parseObj.putOpt("time",Instant.now().getEpochSecond()); +// redisTemplate.opsForHash().putAll("token:his:df",parseObj); +// redisTemplate.expire("token:his:df",expiresIn - 10, TimeUnit.SECONDS); +// } + return parseObj; + } + + //寤烘。 + public JSON jianDang (TjCustomer customer) { + String czy = configService.selectConfigByKey("dfhisczybm"); + + Map<String, Object> map = new HashMap<> (); + map.put ("jiuZhenKh", customer.getPationId ()); + map.put ("kaiLeiXing","4"); + map.put ("xingMing", customer.getCusName ()); + Long cusSex = customer.getCusSex(); + if(cusSex==0L){ + map.put ("xingBie","鐢�"); + }else if(cusSex==1L){ + map.put ("xingBie","濂�"); + }else { + map.put ("xingBie","鏈煡"); + } + map.put ("shenFenZh", customer.getCusIdcard ()); + map.put ("danWeiBh",""); + map.put ("chuShengRq", DateUtil.format(customer.getCusBrithday(),"yyyy-MM-dd")); + map.put ("lianXiDz", customer.getCusAddr()); + map.put ("lianXiDh", customer.getCusPhone ()); + map.put ("feiYongLb",""); + map.put ("feiYongXz",""); + map.put ("jiLuLy","3"); + map.put ("caoZuoYuan",czy); + map.put ("chongZhiJe",""); + map.put ("yiBaoKh",""); + map.put ("geRenBh",""); + map.put ("yiBaoBrXx",""); + map.put ("gongZuoDw",customer.getCompName()); + map.put ("canBaoXzMc",""); + map.put ("muLuBlLb",""); + map.put ("kunNanJzDj",""); + map.put ("yiLiaoLb",""); + map.put ("minZuDm",""); + map.put ("minZuMc",""); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/menZhenJz/jianDang", map); + return JSONUtil.parseObj(post); + } + + //楠岃瘉韬唤璇佹槸鍚﹀缓杩囨。 + public JSON getBingRenXxByShengFenZheng (TjCustomer customer) { + String czy = configService.selectConfigByKey("dfhisczybm"); + Map<String, Object> map = new HashMap<> (); + map.put ("caoZuoYuan",czy); + map.put ("shenFenZh", customer.getCusIdcard ()); + map.put ("danWeiBh",""); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/menZhenJz/getBingRenXxByShengFenZheng", map); + return JSONUtil.parseObj(post); + } + + //鐥呬汉鍩烘湰淇℃伅鍙樻洿 + public JSON saveBingRenXx (TjCustomer customer) { + String czy = configService.selectConfigByKey("dfhisczybm"); + Map<String, Object> map = new HashMap<> (); + map.put ("jiuZhenKh", customer.getPationId ()); + map.put ("kaiLeiXing","4"); + map.put ("xingMing", customer.getCusName ()); + Long cusSex = customer.getCusSex(); + if(cusSex==0L){ + map.put ("xingBie","鐢�"); + }else if(cusSex==1L){ + map.put ("xingBie","濂�"); + }else { + map.put ("xingBie","鏈煡"); + } + map.put ("shenFenZh", customer.getCusIdcard ()); + map.put ("danWeiBh",""); + map.put ("chuShengRq", DateUtil.format(customer.getCusBrithday(),"yyyy-MM-dd")); + map.put ("lianXiDz", customer.getCusAddr()); + map.put ("lianXiDh", customer.getCusPhone ()); + map.put ("feiYongLb",""); + map.put ("feiYongXz",""); + map.put ("jiLuLy","3"); + map.put ("caoZuoYuan",czy); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/menZhenJz/saveBingRenXx", map); + return JSONUtil.parseObj(post); + } + + //寰呮敹璐硅垂鐢ㄦ煡璇� + public JSON getListDaiShouFei (String bingRenId,String jiuZhenKh,String yuanQuId) { + Map<String, Object> map = new HashMap<> (); + map.put ("bingRenId",bingRenId); + map.put ("jiuZhenKh",jiuZhenKh); + map.put ("yuanQuId",yuanQuId); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/shouFei/getListDaiShouFei", map); + return JSONUtil.parseObj(post); + } + + + //鐢熸垚寰呮敹璐�/寰呴��璐� 璐圭敤 + public JSON createMenZhenFy (CreateMenZhenFyDto dto) { + String czy = configService.selectConfigByKey("dfhisczybm"); + Map<String, Object> map = new HashMap<> (); + map.put ("bingRenId",dto.getBingRenId()); + map.put ("jiuZhenKh",dto.getJiuZhenKh()); + map.put ("caoZuoYuan",czy); + map.put ("yuanQuId",dto.getYuanQuId()); + map.put ("yingYongId",dto.getYingYongId()); + map.put ("kaiDanKs",dto.getKaiDanKs()); + map.put ("dengJiLsh",dto.getDengJiLsh()); + map.put ("shouTuiBz",dto.getShouTuiBz()); + map.put ("feiYongMxList",dto.getFeiYongMxList()); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/shouFei/createMenZhenFy", map); + return JSONUtil.parseObj(post); + } + + + //闂ㄨ瘖鏈敹璐硅垂鐢ㄦ挙閿� + public JSON cheXiaoMzFy (CheXiaoMzFyDto dto) { + Map<String, Object> map = new HashMap<> (); + map.put ("bingRenId",dto.getBingRenId()); + map.put ("jiuZhenKh",dto.getJiuZhenKh()); + map.put ("feiYongIdList",dto.getFeiYongIdList()); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/shouFei/cheXiaoMzFy", map); + return JSONUtil.parseObj(post); + } + + + //鏀惰垂/閫�璐瑰畬鎴愰�氱煡绗笁鏂� + public JSON pushZhiFuMsg (String feiYongId,int yeWuLx ) { + Map<String, Object> map = new HashMap<> (); + map.put ("feiYongId",feiYongId); + map.put ("yeWuLx",yeWuLx); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/shouFei/pushZhiFuMsg", map); + return JSONUtil.parseObj(post); + } + + + //绉戝淇℃伅鏌ヨ + public JSON getKeShi (String yuanQuId,String keShiMc,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("yuanQuId",yuanQuId); + map.put ("keShiMc",keShiMc); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getKeShi", map); + return JSONUtil.parseObj(post); + } + + //鍖荤敓淇℃伅鏌ヨ + public JSON getListYiShengZd (String yuanQuId,String keShiMc,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("yuanQuId",yuanQuId); + map.put ("keShiMc",keShiMc); + map.put ("bianGengSj",""); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getListYiShengZd", map); + return JSONUtil.parseObj(post); + } + + + //鑾峰彇鏀惰垂椤圭洰鍒嗛〉 + public JSON getShouFeiXm (String queryString,String bianGengSj,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("queryString",queryString); + map.put ("bianGengSj",bianGengSj); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getShouFeiXm", map); + return JSONUtil.parseObj(post); + } + + + + /** + *绉戝淇℃伅鎺ㄩ�� + * @param xingZhiSx 缁勭粐灞炴�� 绗竴浣�1聽琛ㄧず 鎸傚彿 + * 绗簩浣� 1琛ㄧず涓村簥 + * 绗笁浣� 1琛ㄧず妫�鏌� + * 绗洓浣� 1 琛ㄧず鎵嬫湳 + * 绗簲浣� 1 琛ㄧず娌荤枟 + * 绗叚浣� 1 琛ㄧず鎶ょ悊 + * @param queryString 妯$硦鍖归厤杈撯紛鐮�1銆佺瀹ゅ悕绉� + * @param zuoFeiBz 浣滃簾鏍囧織锛�0 姝e父锛�1 浣滃簾 + * @param yuanQuId 闄㈠尯id + * @param keShiIds 绉戝ID闆嗗悎 + * @param ifPlus 鏄惁鏌ヨplus灞炴�� + * @return + */ + public JSON getKeShiByConditions (int xingZhiSx, String queryString, int zuoFeiBz, String yuanQuId, List<String> keShiIds, int ifPlus) { + Map<String, Object> map = new HashMap<> (); + map.put ("xingZhiSx",xingZhiSx); + map.put ("queryString",queryString); + map.put ("zuoFeiBz",zuoFeiBz); + map.put ("yuanQuId",yuanQuId); + map.put ("keShiIds",keShiIds); + map.put ("ifPlus",ifPlus); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getKeShiByConditions", map); + return JSONUtil.parseObj(post); + } + + + + /** + * 鍙栨牱鏈瓧鍏� + * @param queryString 鏍锋湰绫诲瀷鍚嶇О(鏍锋湰鍚嶇О/鏍锋湰绫诲瀷id) + * @param pageIndex + * @param pageSize 姣忊粴鏉℃暟锛堟渶饧や笉鑳借秴杩�100锛� + * @return + */ + public JSON getYangBen (String queryString,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("queryString",queryString); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getYangBen", map); + return JSONUtil.parseObj(post); + } + + + /** + * 鐥呭尯淇℃伅鎺ㄩ�� + * @param yuanQuId 闄㈠尯Id + * @param keShiId 绉戝Id + * @param pageIndex 褰撳墠饣� + * @param pageSize 姣忊粴鏉℃暟锛堟渶饧や笉鑳借秴杩�100锛� + * @return + */ + public JSON getListBingQuZd (String yuanQuId,String keShiId,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("yuanQuId",yuanQuId); + map.put ("keShiId",keShiId); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getListBingQuZd", map); + return JSONUtil.parseObj(post); + } + + /** + * 鑱屸集淇℃伅 + * @param bianGengSj 鍙樻洿鏃堕棿 + * @param pageIndex 褰撳墠饣� + * @param pageSize 姣忊粴鏉℃暟锛堟渶饧や笉鑳借秴杩�100锛� + * @return + */ + public JSON getZhiGongPage (String bianGengSj,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("bianGengSj",bianGengSj); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getZhiGongPage", map); + return JSONUtil.parseObj(post); + } + + + /** + * 妫�鏌ラ」鐩� + * @param queryString + * @param bianGengSj + * @param pageIndex + * @param pageSize + * @return + */ + public JSON getJianChaXm (String queryString,String bianGengSj,int pageIndex,int pageSize ) { + Map<String, Object> map = new HashMap<> (); + map.put ("queryString",queryString); + map.put ("bianGengSj",bianGengSj); + map.put ("pageIndex",pageIndex); + map.put ("pageSize",pageSize); + //鑱屼笟缂栫爜 + String post = sendPost (HIS_URL+"/zhuShuJu/getJianChaXm", map); + return JSONUtil.parseObj(post); + } + + /** + * 妫�楠岄」饨帹閫� + * @param queryCode 鏌ヨ鐮�(椤光浆缂栫爜/鎷尖境鐮� + * @param page 褰撳墠饣� + * @param size 姣忊粴鏉℃暟锛堟渶饧や笉鑳借秴杩�100 + * @return + */ + public JSON getJianYanXm(String queryCode,Integer page,Integer size){ + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("queryCode",queryCode); + hashMap.put("page",page); + hashMap.put("size",size); + String post = sendPost (HIS_URL+"/zhuShuJu/getJianYanXm", hashMap); + return JSONUtil.parse(post); + } + + /** + * 妫�楠岄」饨敹璐规帹閫� + * @param shouFeiXmId 鏀惰垂椤光浆id + * @param jiaGeTx 浠锋牸浣撶郴 + * @return + */ + public JSON getShouFeiXmJg(String shouFeiXmId,String jiaGeTx){ + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("shouFeiXmId",shouFeiXmId); + hashMap.put("jiaGeTx",jiaGeTx); + String post = sendPost (HIS_URL+"/zhuShuJu/getShouFeiXmJg", hashMap); + return JSONUtil.parse(post); + } + + /** + * 妫�楠屽鍣� + * @param queryString 瀹瑰櫒鍚嶇О(瀹瑰櫒鍚嶇О/杈撯紛鐮�1) + * @param pageIndex 褰撳墠饣� + * @param pageSize 姣忊粴鏉℃暟锛堟渶饧や笉鑳借秴杩�100锛� + * @return + */ + public JSON getRongQi(String queryString,Integer pageIndex,Integer pageSize){ + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("queryString",queryString); + hashMap.put("pageIndex",pageIndex); + hashMap.put("pageSize",pageSize); + String post = sendPost (HIS_URL+"/zhuShuJu/getRongQi", hashMap); + return JSONUtil.parse(post); + } + + /** + * 妫�楠屾牱鏈� + * @param queryString 鏍锋湰绫诲瀷鍚嶇О(鏍锋湰鍚嶇О/鏍锋湰绫诲瀷id) + * @param pageIndex 褰撳墠饣� + * @param pageSize 姣忊粴鏉℃暟锛堟渶饧や笉鑳借秴杩�100锛� + * @return + */ + public JSON getYangBen(String queryString,Integer pageIndex,Integer pageSize){ + HashMap<String, Object> hashMap = new HashMap<>(); + hashMap.put("queryString",queryString); + hashMap.put("pageIndex",pageIndex); + hashMap.put("pageSize",pageSize); + String post = sendPost (HIS_URL+"/zhuShuJu/getYangBen", hashMap); + return JSONUtil.parse(post); + } + + private String sendPost(String url,Map<String, Object> hashMap){ + Map<Object, Object> entries = redisTemplate.opsForHash().entries("token:his:df"); + if (entries != null && !entries.isEmpty()) { + String timeStr = entries.get("time").toString(); + String expiresInStr = entries.get("expires_in").toString(); + long time = Long.parseLong(timeStr); + long expiresIn = Long.parseLong(expiresInStr); + Instant tokenExpirationTime = Instant.ofEpochSecond(time).plusSeconds(expiresIn); + Instant now = Instant.now(); + if (now.isAfter(tokenExpirationTime)){ + return refreshToken(url,hashMap); + }else { + String accessToken = entries.get("access_token").toString(); + String tokenType = entries.get("token_type").toString(); + String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken); + return StrUtil.isNotBlank(string) ? string : JSONUtil.createObj().toString(); + } + }else { + return refreshToken(url, hashMap); + } + } + + private String refreshToken(String url, Map<String, Object> hashMap) { + JSONObject parseObj = getToken(); + if (parseObj != null) { + Integer expiresIn = parseObj.getInt("expires_in"); + if (expiresIn != null) { + parseObj.putOpt("time", Instant.now().getEpochSecond()); + redisTemplate.opsForHash().putAll("token:his:df", parseObj); + redisTemplate.expire("token:his:df", expiresIn - 10, TimeUnit.SECONDS); + + String accessToken = parseObj.getStr("access_token"); + String tokenType = parseObj.getStr("token_type"); + String string = HttpClientUtils.sendPostToken(url, hashMap, tokenType + " " + accessToken); + return StrUtil.isNotBlank(string) ? string : JSONUtil.createObj().toString(); + } + } + return JSONUtil.createObj().toString(); + } +} diff --git a/src/main/java/com/example/utils/FastJson2JsonRedisSerializer.java b/src/main/java/com/example/utils/FastJson2JsonRedisSerializer.java new file mode 100644 index 0000000..526d08c --- /dev/null +++ b/src/main/java/com/example/utils/FastJson2JsonRedisSerializer.java @@ -0,0 +1,43 @@ +package com.example.utils; + +import java.nio.charset.Charset; + +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.SerializationException; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONReader; +import com.alibaba.fastjson2.JSONWriter; + +/** + * Redis浣跨敤FastJson搴忓垪鍖� + * + * @author ltkj + */ +public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> { + public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); + + private Class<T> clazz; + + public FastJson2JsonRedisSerializer(Class<T> clazz) { + super(); + this.clazz = clazz; + } + + @Override + public byte[] serialize(T t) throws SerializationException { + if (t == null) { + return new byte[0]; + } + return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET); + } + + @Override + public T deserialize(byte[] bytes) throws SerializationException { + if (bytes == null || bytes.length <= 0) { + return null; + } + String str = new String(bytes, DEFAULT_CHARSET); + + return JSON.parseObject(str, clazz, JSONReader.Feature.SupportAutoType); + } +} diff --git a/src/main/java/com/example/utils/HttpClientUtils.java b/src/main/java/com/example/utils/HttpClientUtils.java new file mode 100644 index 0000000..f0a50d5 --- /dev/null +++ b/src/main/java/com/example/utils/HttpClientUtils.java @@ -0,0 +1,574 @@ +package com.example.utils; + + +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.util.PublicSuffixMatcher; +import org.apache.http.conn.util.PublicSuffixMatcherLoader; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.springframework.stereotype.Component; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + + +/** + * httpClient 宸ュ叿绫� + * + * @create 2019-02-10 涓嬪崍 2:49 + */ +@Component +@Slf4j +public class HttpClientUtils { + + /** + * 榛樿鍙傛暟璁剧疆 + * setConnectTimeout锛氳缃繛鎺ヨ秴鏃舵椂闂达紝鍗曚綅姣銆� + * setConnectionRequestTimeout锛氳缃粠connect Manager鑾峰彇Connection 瓒呮椂鏃堕棿锛屽崟浣嶆绉掋�� + * setSocketTimeout锛氳姹傝幏鍙栨暟鎹殑瓒呮椂鏃堕棿锛屽崟浣嶆绉掋�傝闂竴涓帴鍙o紝澶氬皯鏃堕棿鍐呮棤娉曡繑鍥炴暟鎹紝灏辩洿鎺ユ斁寮冩娆¤皟鐢ㄣ�� 鏆傛椂瀹氫箟15鍒嗛挓 + */ + private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(600000).setConnectTimeout(600000).setConnectionRequestTimeout(600000).build(); + + /** + * 闈欐�佸唴閮ㄧ被---浣滅敤锛氬崟渚嬩骇鐢熺被鐨勫疄渚� + * + * @author Administrator + */ + private static class LazyHolder { + private static final HttpClientUtils INSTANCE = new HttpClientUtils(); + + } + + HttpClientUtils() { + } + + public static HttpClientUtils getInstance() { + return LazyHolder.INSTANCE; + } + + /** + * 鍙戦�� post璇锋眰 + * + * @param httpUrl 鍦板潃 + */ + public String sendHttpPost(String httpUrl) { + HttpPost httpPost = new HttpPost(httpUrl);// 鍒涘缓httpPost + return sendHttpPost(httpPost); + } + + /** + * 鍙戦�� post璇锋眰 + * + * @param httpUrl 鍦板潃 + * @param params 鍙傛暟(鏍煎紡:key1=value1&key2=value2) + */ + public String sendHttpPost(String httpUrl, String params) { + HttpPost httpPost = new HttpPost(httpUrl);// 鍒涘缓httpPost + try { + //璁剧疆鍙傛暟 + StringEntity stringEntity = new StringEntity(params, "UTF-8"); + stringEntity.setContentType("application/x-www-form-urlencoded"); + httpPost.setEntity(stringEntity); + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + public static String sendPost(String httpUrl, Map<String, Object> maps) { + + try { + // 1. 鍒涘缓 URL 瀵硅薄 + URL url = new URL(httpUrl); + // 2. 鍒涘缓 HttpURLConnection 瀵硅薄 + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + // 3. 璁剧疆璇锋眰鏂规硶涓� POST + connection.setRequestMethod("POST"); + // 4. 璁剧疆 Content-Type 澶撮儴瀛楁 + connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + // 6. 鍚戞湇鍔″櫒鍙戦�佹暟鎹� + String requestBody = JSONUtil.toJsonStr(maps); + log.info(httpUrl+"鍏ュ弬: "+requestBody); +// String requestBody1 = maps.toString(); + byte[] postData = requestBody.getBytes("UTF-8"); + connection.setDoOutput(true); + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(postData); + } + + // 8. 鑾峰彇鍝嶅簲鏁版嵁 + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { + String line; + StringBuilder response = new StringBuilder(); + while ((line = reader.readLine()) != null) { + response.append(line); + } + log.info("====================================================="); + log.info(httpUrl+"鍑哄弬"); + log.info(response.toString()); + connection.disconnect(); + return response.toString(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } + + public static String sendPostToken(String httpUrl, Map<String, Object> maps,String authorization) { + + try { + // 1. 鍒涘缓 URL 瀵硅薄 + URL url = new URL(httpUrl); + // 2. 鍒涘缓 HttpURLConnection 瀵硅薄 + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + // 3. 璁剧疆璇锋眰鏂规硶涓� POST + connection.setRequestMethod("POST"); + // 4. 璁剧疆 Content-Type 澶撮儴瀛楁 + connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + connection.setRequestProperty("Authorization", authorization); + // 6. 鍚戞湇鍔″櫒鍙戦�佹暟鎹� + String requestBody = JSONUtil.toJsonStr(maps); + log.info(httpUrl+"鍏ュ弬: "+requestBody); +// String requestBody1 = maps.toString(); + byte[] postData = requestBody.getBytes("UTF-8"); + connection.setDoOutput(true); + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(postData); + } + + // 8. 鑾峰彇鍝嶅簲鏁版嵁 + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { + String line; + StringBuilder response = new StringBuilder(); + while ((line = reader.readLine()) != null) { + response.append(line); + } + log.info("====================================================="); + log.info(httpUrl+"鍑哄弬"); + log.info(response.toString()); + connection.disconnect(); + return response.toString(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } + + public static String sendPostTokenFormUrlencoded(String httpUrl, Map<String, Object> maps, String authorization) { + HttpURLConnection connection = null; + OutputStreamWriter writer = null; + BufferedReader reader = null; + StringBuilder response = new StringBuilder(); + + try { + // 鍒涘缓 URL 瀵硅薄 + URL url = new URL(httpUrl); + // 鎵撳紑杩炴帴 + connection = (HttpURLConnection) url.openConnection(); + + // 璁剧疆璇锋眰鏂规硶涓� POST + connection.setRequestMethod("POST"); + // 璁剧疆璇锋眰澶� Content-Type 涓� application/x-www-form-urlencoded + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + // 濡傛灉闇�瑕� Authorization Header + if (authorization != null && !authorization.isEmpty()) { + connection.setRequestProperty("Authorization", authorization); + } + + // 璁剧疆鍏佽杈撳嚭 + connection.setDoOutput(true); + + // 鏋勫缓琛ㄥ崟鏁版嵁 + StringBuilder postData = new StringBuilder(); + for (Map.Entry<String, Object> entry : maps.entrySet()) { + if (postData.length() > 0) { + postData.append("&"); + } + postData.append(URLEncoder.encode(entry.getKey(), "UTF-8")) + .append("=") + .append(URLEncoder.encode(entry.getValue().toString(), "UTF-8")); + } + + // 鑾峰彇杈撳嚭娴佸苟鍐欏叆琛ㄥ崟鏁版嵁 + writer = new OutputStreamWriter(connection.getOutputStream()); + writer.write(postData.toString()); + writer.flush(); + + // 鑾峰彇鍝嶅簲 + reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + // 鍏抽棴娴� + try { + if (writer != null) writer.close(); + if (reader != null) reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (connection != null) { + connection.disconnect(); + } + } + return response.toString(); + } + + public static String sendPostTokenFormData(String httpUrl, Map<String, Object> maps, String authorization) { + HttpURLConnection connection = null; + DataOutputStream outStream = null; + BufferedReader reader = null; + StringBuilder response = new StringBuilder(); + + // 杈圭晫瀛楃涓� + String boundary = "----WebKitFormBoundary" + UUID.randomUUID().toString().replaceAll("-", ""); + String CRLF = "\r\n"; // 鎹㈣绗� + + try { + // 鍒涘缓 URL 瀵硅薄 + URL url = new URL(httpUrl); + // 鎵撳紑杩炴帴 + connection = (HttpURLConnection) url.openConnection(); + + // 璁剧疆璇锋眰鏂规硶涓� POST + connection.setRequestMethod("POST"); + // 璁剧疆璇锋眰澶� Content-Type 涓� multipart/form-data + connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); + + // 濡傛灉闇�瑕� Authorization Header + if (authorization != null && !authorization.isEmpty()) { + connection.setRequestProperty("Authorization", authorization); + } + + // 璁剧疆鍏佽杈撳嚭 + connection.setDoOutput(true); + + // 鑾峰彇杈撳嚭娴� + outStream = new DataOutputStream(connection.getOutputStream()); + + // 閬嶅巻浼犲叆鐨勮〃鍗曟暟鎹紝骞舵寜鐓� multipart/form-data 鏍煎紡鍐欏叆 + for (Map.Entry<String, Object> entry : maps.entrySet()) { + outStream.writeBytes("--" + boundary + CRLF); + outStream.writeBytes("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"" + CRLF); + outStream.writeBytes("Content-Type: text/plain; charset=UTF-8" + CRLF); + outStream.writeBytes(CRLF); // 杩欓噷鏄垎闅旂锛岀┖涓�琛� + outStream.writeBytes(entry.getValue().toString() + CRLF); + } + + // 缁撴潫 multipart/form-data 鍙戦�佹暟鎹儴鍒� + outStream.writeBytes("--" + boundary + "--" + CRLF); + + // 鍒锋柊杈撳嚭娴� + outStream.flush(); + + // 鑾峰彇鍝嶅簲 + reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + // 鍏抽棴娴� + try { + if (outStream != null) outStream.close(); + if (reader != null) reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + if (connection != null) { + connection.disconnect(); + } + } + return response.toString(); + } + + /** + * 鍙戦�� post璇锋眰 + * + * @param httpUrl 鍦板潃 + * @param maps 鍙傛暟 + */ + public String sendHttpPost(String httpUrl, Map<String, String> maps) { + HttpPost httpPost = new HttpPost(httpUrl);// 鍒涘缓httpPost + // 鍒涘缓鍙傛暟闃熷垪 + List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); + for (String key : maps.keySet()) { + nameValuePairs.add(new BasicNameValuePair(key, maps.get(key))); + } + try { + httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")); + } catch (Exception e) { + e.printStackTrace(); + } + return sendHttpPost(httpPost); + } + + + /** + * 鍙戦�丳ost璇锋眰 + * + * @param httpPost + * @return + */ + private String sendHttpPost(HttpPost httpPost) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 鍒涘缓榛樿鐨刪ttpClient瀹炰緥 + httpClient = HttpClients.createDefault(); + httpPost.setConfig(requestConfig); + // 鎵ц璇锋眰 + long execStart = System.currentTimeMillis(); + response = httpClient.execute(httpPost); + long execEnd = System.currentTimeMillis(); + System.out.println("=================鎵цpost璇锋眰鑰楁椂锛�" + (execEnd - execStart) + "ms"); + long getStart = System.currentTimeMillis(); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + long getEnd = System.currentTimeMillis(); + System.out.println("=================鑾峰彇鍝嶅簲缁撴灉鑰楁椂锛�" + (getEnd - getStart) + "ms"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 鍏抽棴杩炴帴,閲婃斁璧勬簮 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 鍙戦�� get璇锋眰 + * + * @param httpUrl + */ + public String sendHttpGet(String httpUrl) { + HttpGet httpGet = new HttpGet(httpUrl);// 鍒涘缓get璇锋眰 + return sendHttpGet(httpGet); + } + + /** + * 鍙戦�� get璇锋眰Https + * + * @param httpUrl + */ + public String sendHttpsGet(String httpUrl) { + HttpGet httpGet = new HttpGet(httpUrl);// 鍒涘缓get璇锋眰 + return sendHttpsGet(httpGet); + } + + /** + * 鍙戦�丟et璇锋眰 + * + * @param httpGet + * @return + */ + private String sendHttpGet(HttpGet httpGet) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 鍒涘缓榛樿鐨刪ttpClient瀹炰緥. + + + httpClient = HttpClients.createDefault(); + + httpGet.setConfig(requestConfig); + // 鎵ц璇锋眰 + response = httpClient.execute(httpGet); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 鍏抽棴杩炴帴,閲婃斁璧勬簮 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 鍙戦�丟et璇锋眰Https + * + * @param httpGet + * @return + */ + private String sendHttpsGet(HttpGet httpGet) { + CloseableHttpClient httpClient = null; + CloseableHttpResponse response = null; + HttpEntity entity = null; + String responseContent = null; + try { + // 鍒涘缓榛樿鐨刪ttpClient瀹炰緥. + PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString())); + DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher); + httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build(); + httpGet.setConfig(requestConfig); + // 鎵ц璇锋眰 + response = httpClient.execute(httpGet); + entity = response.getEntity(); + responseContent = EntityUtils.toString(entity, "UTF-8"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + // 鍏抽棴杩炴帴,閲婃斁璧勬簮 + if (response != null) { + response.close(); + } + if (httpClient != null) { + httpClient.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + + /** + * 鍙戦�亁ml鏁版嵁 + * + * @param url + * @param xmlData + * @return + * @throws ClientProtocolException + * @throws IOException + */ + public static HttpResponse sendXMLDataByPost(String url, String xmlData) + throws ClientProtocolException, IOException { + HttpClient httpClient = HttpClients.createDefault(); + HttpPost httppost = new HttpPost(url); + StringEntity entity = new StringEntity(xmlData); + httppost.setEntity(entity); + httppost.setHeader("Content-Type", "text/xml;charset=UTF-8"); + HttpResponse response = httpClient.execute(httppost); + return response; + } + + /** + * 鑾峰緱鍝嶅簲HTTP瀹炰綋鍐呭 + * + * @param response + * @return + * @throws IOException + * @throws UnsupportedEncodingException + */ + public static String getHttpEntityContent(HttpResponse response) throws IOException, UnsupportedEncodingException { + HttpEntity entity = response.getEntity(); + if (entity != null) { + InputStream is = entity.getContent(); + BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String line = br.readLine(); + StringBuilder sb = new StringBuilder(); + while (line != null) { + sb.append(line + "\n"); + line = br.readLine(); + } + return sb.toString(); + } + return ""; + } + + + + public static String sendPost(String httpUrl, Map<String, Object> maps,String token) { + + try { + // 1. 鍒涘缓 URL 瀵硅薄 + URL url = new URL(httpUrl); + // 2. 鍒涘缓 HttpURLConnection 瀵硅薄 + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + // 3. 璁剧疆璇锋眰鏂规硶涓� POST + connection.setRequestMethod("POST"); + // 4. 璁剧疆 Content-Type 澶撮儴瀛楁 + connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + //璁剧疆璇锋眰token + connection.setRequestProperty("Authorization",token); + // 6. 鍚戞湇鍔″櫒鍙戦�佹暟鎹� + String requestBody = JSONUtil.toJsonStr(maps); + log.info(httpUrl+"鍏ュ弬: "+requestBody); +// String requestBody1 = maps.toString(); + byte[] postData = requestBody.getBytes("UTF-8"); + connection.setDoOutput(true); + try (OutputStream outputStream = connection.getOutputStream()) { + outputStream.write(postData); + } + + // 8. 鑾峰彇鍝嶅簲鏁版嵁 + try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { + String line; + StringBuilder response = new StringBuilder(); + while ((line = reader.readLine()) != null) { + response.append(line); + } + log.info("====================================================="); + log.info(httpUrl+"鍑哄弬"); + log.info(response.toString()); + connection.disconnect(); + return response.toString(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } + + +} diff --git a/src/main/java/com/example/utils/RedisCache.java b/src/main/java/com/example/utils/RedisCache.java new file mode 100644 index 0000000..4cb53c6 --- /dev/null +++ b/src/main/java/com/example/utils/RedisCache.java @@ -0,0 +1,266 @@ +package com.example.utils; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.BoundSetOperations; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +/** + * spring redis 宸ュ叿绫� + * + * @author ltkj + **/ +@SuppressWarnings(value = {"unchecked", "rawtypes"}) +@Component +public class RedisCache { + @Autowired + public RedisTemplate redisTemplate; + + public RedisTemplate setDataBase(int num) { + LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory(); + if (connectionFactory != null && num != connectionFactory.getDatabase()) { + connectionFactory.setDatabase(num); + this.redisTemplate.setConnectionFactory(connectionFactory); + connectionFactory.resetConnection(); + connectionFactory.afterPropertiesSet(); + } + return redisTemplate; + } + + /** + * 缂撳瓨鍩烘湰鐨勫璞★紝Integer銆丼tring銆佸疄浣撶被绛� + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param value 缂撳瓨鐨勫�� + */ + public <T> void setCacheObject(final String key, final Object value) { + redisTemplate.opsForValue().set(key, value); + } + + /** + * 缂撳瓨鍩烘湰鐨勫璞★紝Integer銆丼tring銆佸疄浣撶被绛� + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param value 缂撳瓨鐨勫�� + * @param timeout 鏃堕棿 + * @param timeUnit 鏃堕棿棰楃矑搴� + */ + public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) { + redisTemplate.opsForValue().set(key, value, timeout, timeUnit); + } + + /** + * 璁剧疆鏈夋晥鏃堕棿 + * + * @param key Redis閿� + * @param timeout 瓒呮椂鏃堕棿 + * @return true=璁剧疆鎴愬姛锛沠alse=璁剧疆澶辫触 + */ + public boolean expire(final String key, final long timeout) { + return expire(key, timeout, TimeUnit.SECONDS); + } + + /** + * 璁剧疆鏈夋晥鏃堕棿 + * + * @param key Redis閿� + * @param timeout 瓒呮椂鏃堕棿 + * @param unit 鏃堕棿鍗曚綅 + * @return true=璁剧疆鎴愬姛锛沠alse=璁剧疆澶辫触 + */ + public boolean expire(final String key, final long timeout, final TimeUnit unit) { + return redisTemplate.expire(key, timeout, unit); + } + + /** + * 鑾峰彇鏈夋晥鏃堕棿 + * + * @param key Redis閿� + * @return 鏈夋晥鏃堕棿 + */ + public long getExpire(final String key) { + return redisTemplate.getExpire(key); + } + + /** + * 鍒ゆ柇 key鏄惁瀛樺湪 + * + * @param key 閿� + * @return true 瀛樺湪 false涓嶅瓨鍦� + */ + public Boolean hasKey(String key) { + return redisTemplate.hasKey(key); + } + + public Boolean hasHKey(String key1,String key2) { + return redisTemplate.opsForHash().hasKey(key1,key2); + } + + /** + * 鑾峰緱缂撳瓨鐨勫熀鏈璞°�� + * + * @param key 缂撳瓨閿�� + * @return 缂撳瓨閿�煎搴旂殑鏁版嵁 + */ + public <T> T getCacheObject(final String key) { + ValueOperations<String, T> operation = redisTemplate.opsForValue(); + return operation.get(key); + } + + /** + * 鍒犻櫎鍗曚釜瀵硅薄 + * + * @param key + */ + public boolean deleteObject(final String key) { + return redisTemplate.delete(key); + } + + /** + * 鍒犻櫎闆嗗悎瀵硅薄 + * + * @param collection 澶氫釜瀵硅薄 + * @return + */ + public boolean deleteObject(final Collection collection) { + return redisTemplate.delete(collection) > 0; + } + + /** + * 缂撳瓨List鏁版嵁 + * + * @param key 缂撳瓨鐨勯敭鍊� + * @param dataList 寰呯紦瀛樼殑List鏁版嵁 + * @return 缂撳瓨鐨勫璞� + */ + public <T> long setCacheList(final String key, final List<T> dataList) { + Long count = redisTemplate.opsForList().rightPushAll(key, dataList); + return count == null ? 0 : count; + } + + /** + * 鑾峰緱缂撳瓨鐨刲ist瀵硅薄 + * + * @param key 缂撳瓨鐨勯敭鍊� + * @return 缂撳瓨閿�煎搴旂殑鏁版嵁 + */ + public <T> List<T> getCacheList(final String key) { + return redisTemplate.opsForList().range(key, 0, -1); + } + + /** + * 缂撳瓨Set + * + * @param key 缂撳瓨閿�� + * @param dataSet 缂撳瓨鐨勬暟鎹� + * @return 缂撳瓨鏁版嵁鐨勫璞� + */ + public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) { + BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key); + Iterator<T> it = dataSet.iterator(); + while (it.hasNext()) { + setOperation.add(it.next()); + } + return setOperation; + } + + /** + * 鑾峰緱缂撳瓨鐨剆et + * + * @param key + * @return + */ + public <T> Set<T> getCacheSet(final String key) { + return redisTemplate.opsForSet().members(key); + } + + /** + * 缂撳瓨Map + * + * @param key + * @param dataMap + */ + public <T> void setCacheMap(final String key, final Map<String, T> dataMap) { + if (dataMap != null) { + redisTemplate.opsForHash().putAll(key, dataMap); + } + } + + /** + * 鑾峰緱缂撳瓨鐨凪ap + * + * @param key + * @return + */ + public <T> Map<String, T> getCacheMap(final String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * 寰�Hash涓瓨鍏ユ暟鎹� + * + * @param key Redis閿� + * @param hKey Hash閿� + */ + public <T> void setCacheMapValue(final String key, final String hKey, final Object value) { + redisTemplate.opsForHash().put(key, hKey, value); + } + + public <T> void setHashKeyExpireTime(final String key, final Long time, final TimeUnit unit) { + redisTemplate.expire(key,time,unit); + } + + /** + * 鑾峰彇Hash涓殑鏁版嵁 + * + * @param key Redis閿� + * @param hKey Hash閿� + * @return Hash涓殑瀵硅薄 + */ + public <T> T getCacheMapValue(final String key, final String hKey) { + HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash(); + return opsForHash.get(key, hKey); + } + + /** + * 鑾峰彇澶氫釜Hash涓殑鏁版嵁 + * + * @param key Redis閿� + * @param hKeys Hash閿泦鍚� + * @return Hash瀵硅薄闆嗗悎 + */ + public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) { + return redisTemplate.opsForHash().multiGet(key, hKeys); + } + + /** + * 鍒犻櫎Hash涓殑鏌愭潯鏁版嵁 + * + * @param key Redis閿� + * @param hKey Hash閿� + * @return 鏄惁鎴愬姛 + */ + public boolean deleteCacheMapValue(final String key, final String hKey) { + return redisTemplate.opsForHash().delete(key, hKey) > 0; + } + + /** + * 鑾峰緱缂撳瓨鐨勫熀鏈璞″垪琛� + * + * @param pattern 瀛楃涓插墠缂� + * @return 瀵硅薄鍒楄〃 + */ + public Collection<String> keys(final String pattern) { + return redisTemplate.keys(pattern); + } +} diff --git a/src/main/java/com/example/utils/SpringUtils.java b/src/main/java/com/example/utils/SpringUtils.java new file mode 100644 index 0000000..9c6482c --- /dev/null +++ b/src/main/java/com/example/utils/SpringUtils.java @@ -0,0 +1,140 @@ +package com.example.utils; + +import org.springframework.aop.framework.AopContext; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * spring宸ュ叿绫� 鏂逛究鍦ㄩ潪spring绠$悊鐜涓幏鍙朾ean + * + * @author ruoyi + */ +@Component +public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware { + /** + * Spring搴旂敤涓婁笅鏂囩幆澧� + */ + private static ConfigurableListableBeanFactory beanFactory; + + private static ApplicationContext applicationContext; + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + SpringUtils.beanFactory = beanFactory; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringUtils.applicationContext = applicationContext; + } + + /** + * 鑾峰彇瀵硅薄 + * + * @param name + * @return Object 涓�涓互鎵�缁欏悕瀛楁敞鍐岀殑bean鐨勫疄渚� + * @throws BeansException + */ + @SuppressWarnings("unchecked") + public static <T> T getBean(String name) throws BeansException { + return (T) beanFactory.getBean(name); + } + + /** + * 鑾峰彇绫诲瀷涓簉equiredType鐨勫璞� + * + * @param clz + * @return + * @throws BeansException + */ + public static <T> T getBean(Class<T> clz) throws BeansException { + T result = (T) beanFactory.getBean(clz); + return result; + } + + /** + * 濡傛灉BeanFactory鍖呭惈涓�涓笌鎵�缁欏悕绉板尮閰嶇殑bean瀹氫箟锛屽垯杩斿洖true + * + * @param name + * @return boolean + */ + public static boolean containsBean(String name) { + return beanFactory.containsBean(name); + } + + /** + * 鍒ゆ柇浠ョ粰瀹氬悕瀛楁敞鍐岀殑bean瀹氫箟鏄竴涓猻ingleton杩樻槸涓�涓猵rototype銆� 濡傛灉涓庣粰瀹氬悕瀛楃浉搴旂殑bean瀹氫箟娌℃湁琚壘鍒帮紝灏嗕細鎶涘嚭涓�涓紓甯革紙NoSuchBeanDefinitionException锛� + * + * @param name + * @return boolean + * @throws NoSuchBeanDefinitionException + */ + public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException { + return beanFactory.isSingleton(name); + } + + /** + * @param name + * @return Class 娉ㄥ唽瀵硅薄鐨勭被鍨� + * @throws NoSuchBeanDefinitionException + */ + public static Class<?> getType(String name) throws NoSuchBeanDefinitionException { + return beanFactory.getType(name); + } + + /** + * 濡傛灉缁欏畾鐨刡ean鍚嶅瓧鍦╞ean瀹氫箟涓湁鍒悕锛屽垯杩斿洖杩欎簺鍒悕 + * + * @param name + * @return + * @throws NoSuchBeanDefinitionException + */ + public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { + return beanFactory.getAliases(name); + } + + /** + * 鑾峰彇aop浠g悊瀵硅薄 + * + * @param invoker + * @return + */ + @SuppressWarnings("unchecked") + public static <T> T getAopProxy(T invoker) { + return (T) AopContext.currentProxy(); + } + + /** + * 鑾峰彇褰撳墠鐨勭幆澧冮厤缃紝鏃犻厤缃繑鍥瀗ull + * + * @return 褰撳墠鐨勭幆澧冮厤缃� + */ + public static String[] getActiveProfiles() { + return applicationContext.getEnvironment().getActiveProfiles(); + } + + /** + * 鑾峰彇褰撳墠鐨勭幆澧冮厤缃紝褰撴湁澶氫釜鐜閰嶇疆鏃讹紝鍙幏鍙栫涓�涓� + * + * @return 褰撳墠鐨勭幆澧冮厤缃� + */ + public static String getActiveProfile() { + final String[] activeProfiles = getActiveProfiles(); + return StringUtils.isNotEmpty(activeProfiles) ? activeProfiles[0] : null; + } + + /** + * 鑾峰彇閰嶇疆鏂囦欢涓殑鍊� + * + * @param key 閰嶇疆鏂囦欢鐨刱ey + * @return 褰撳墠鐨勯厤缃枃浠剁殑鍊� + */ + public static String getRequiredProperty(String key) { + return applicationContext.getEnvironment().getRequiredProperty(key); + } +} diff --git a/src/main/java/com/example/utils/StringUtils.java b/src/main/java/com/example/utils/StringUtils.java new file mode 100644 index 0000000..3e33819 --- /dev/null +++ b/src/main/java/com/example/utils/StringUtils.java @@ -0,0 +1,542 @@ +package com.example.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import cn.hutool.core.text.StrFormatter; +import com.example.constant.Constants; +import org.springframework.util.AntPathMatcher; + +/** + * 瀛楃涓插伐鍏风被 + * + * @author ltkj + */ +public class StringUtils extends org.apache.commons.lang3.StringUtils { + /** + * 绌哄瓧绗︿覆 + */ + private static final String NULLSTR = ""; + + /** + * 涓嬪垝绾� + */ + private static final char SEPARATOR = '_'; + + /** + * 鑾峰彇鍙傛暟涓嶄负绌哄�� + * + * @param value defaultValue 瑕佸垽鏂殑value + * @return value 杩斿洖鍊� + */ + public static <T> T nvl(T value, T defaultValue) { + return value != null ? value : defaultValue; + } + + /** + * * 鍒ゆ柇涓�涓狢ollection鏄惁涓虹┖锛� 鍖呭惈List锛孲et锛孮ueue + * + * @param coll 瑕佸垽鏂殑Collection + * @return true锛氫负绌� false锛氶潪绌� + */ + public static boolean isEmpty(Collection<?> coll) { + return isNull(coll) || coll.isEmpty(); + } + + /** + * * 鍒ゆ柇涓�涓狢ollection鏄惁闈炵┖锛屽寘鍚獿ist锛孲et锛孮ueue + * + * @param coll 瑕佸垽鏂殑Collection + * @return true锛氶潪绌� false锛氱┖ + */ + public static boolean isNotEmpty(Collection<?> coll) { + return !isEmpty(coll); + } + + /** + * * 鍒ゆ柇涓�涓璞℃暟缁勬槸鍚︿负绌� + * + * @param objects 瑕佸垽鏂殑瀵硅薄鏁扮粍 + * * @return true锛氫负绌� false锛氶潪绌� + */ + public static boolean isEmpty(Object[] objects) { + return isNull(objects) || (objects.length == 0); + } + + /** + * * 鍒ゆ柇涓�涓璞℃暟缁勬槸鍚﹂潪绌� + * + * @param objects 瑕佸垽鏂殑瀵硅薄鏁扮粍 + * @return true锛氶潪绌� false锛氱┖ + */ + public static boolean isNotEmpty(Object[] objects) { + return !isEmpty(objects); + } + + /** + * * 鍒ゆ柇涓�涓狹ap鏄惁涓虹┖ + * + * @param map 瑕佸垽鏂殑Map + * @return true锛氫负绌� false锛氶潪绌� + */ + public static boolean isEmpty(Map<?, ?> map) { + return isNull(map) || map.isEmpty(); + } + + /** + * * 鍒ゆ柇涓�涓狹ap鏄惁涓虹┖ + * + * @param map 瑕佸垽鏂殑Map + * @return true锛氶潪绌� false锛氱┖ + */ + public static boolean isNotEmpty(Map<?, ?> map) { + return !isEmpty(map); + } + + /** + * * 鍒ゆ柇涓�涓瓧绗︿覆鏄惁涓虹┖涓� + * + * @param str String + * @return true锛氫负绌� false锛氶潪绌� + */ + public static boolean isEmpty(String str) { + return isNull(str) || NULLSTR.equals(str.trim()); + } + + /** + * * 鍒ゆ柇涓�涓瓧绗︿覆鏄惁涓洪潪绌轰覆 + * + * @param str String + * @return true锛氶潪绌轰覆 false锛氱┖涓� + */ + public static boolean isNotEmpty(String str) { + return !isEmpty(str); + } + + /** + * * 鍒ゆ柇涓�涓璞℃槸鍚︿负绌� + * + * @param object Object + * @return true锛氫负绌� false锛氶潪绌� + */ + public static boolean isNull(Object object) { + return object == null; + } + + /** + * * 鍒ゆ柇涓�涓璞℃槸鍚﹂潪绌� + * + * @param object Object + * @return true锛氶潪绌� false锛氱┖ + */ + public static boolean isNotNull(Object object) { + return !isNull(object); + } + + /** + * * 鍒ゆ柇涓�涓璞℃槸鍚︽槸鏁扮粍绫诲瀷锛圝ava鍩烘湰鍨嬪埆鐨勬暟缁勶級 + * + * @param object 瀵硅薄 + * @return true锛氭槸鏁扮粍 false锛氫笉鏄暟缁� + */ + public static boolean isArray(Object object) { + return isNotNull(object) && object.getClass().isArray(); + } + + /** + * 鍘荤┖鏍� + */ + public static String trim(String str) { + return (str == null ? "" : str.trim()); + } + + /** + * 鎴彇瀛楃涓� + * + * @param str 瀛楃涓� + * @param start 寮�濮� + * @return 缁撴灉 + */ + public static String substring(final String str, int start) { + if (str == null) { + return NULLSTR; + } + + if (start < 0) { + start = str.length() + start; + } + + if (start < 0) { + start = 0; + } + if (start > str.length()) { + return NULLSTR; + } + + return str.substring(start); + } + + /** + * 鎴彇瀛楃涓� + * + * @param str 瀛楃涓� + * @param start 寮�濮� + * @param end 缁撴潫 + * @return 缁撴灉 + */ + public static String substring(final String str, int start, int end) { + if (str == null) { + return NULLSTR; + } + + if (end < 0) { + end = str.length() + end; + } + if (start < 0) { + start = str.length() + start; + } + + if (end > str.length()) { + end = str.length(); + } + + if (start > end) { + return NULLSTR; + } + + if (start < 0) { + start = 0; + } + if (end < 0) { + end = 0; + } + + return str.substring(start, end); + } + + /** + * 鏍煎紡鍖栨枃鏈�, {} 琛ㄧず鍗犱綅绗�<br> + * 姝ゆ柟娉曞彧鏄畝鍗曞皢鍗犱綅绗� {} 鎸夌収椤哄簭鏇挎崲涓哄弬鏁�<br> + * 濡傛灉鎯宠緭鍑� {} 浣跨敤 \\杞箟 { 鍗冲彲锛屽鏋滄兂杈撳嚭 {} 涔嬪墠鐨� \ 浣跨敤鍙岃浆涔夌 \\\\ 鍗冲彲<br> + * 渚嬶細<br> + * 閫氬父浣跨敤锛歠ormat("this is {} for {}", "a", "b") -> this is a for b<br> + * 杞箟{}锛� format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> + * 杞箟\锛� format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> + * + * @param template 鏂囨湰妯℃澘锛岃鏇挎崲鐨勯儴鍒嗙敤 {} 琛ㄧず + * @param params 鍙傛暟鍊� + * @return 鏍煎紡鍖栧悗鐨勬枃鏈� + */ + public static String format(String template, Object... params) { + if (isEmpty(params) || isEmpty(template)) { + return template; + } + return StrFormatter.format(template, params); + } + + /** + * 鏄惁涓篽ttp(s)://寮�澶� + * + * @param link 閾炬帴 + * @return 缁撴灉 + */ + public static boolean ishttp(String link) { + return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS); + } + + /** + * 瀛楃涓茶浆set + * + * @param str 瀛楃涓� + * @param sep 鍒嗛殧绗� + * @return set闆嗗悎 + */ + public static final Set<String> str2Set(String str, String sep) { + return new HashSet<String>(str2List(str, sep, true, false)); + } + + /** + * 瀛楃涓茶浆list + * + * @param str 瀛楃涓� + * @param sep 鍒嗛殧绗� + * @param filterBlank 杩囨护绾┖鐧� + * @param trim 鍘绘帀棣栧熬绌虹櫧 + * @return list闆嗗悎 + */ + public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim) { + List<String> list = new ArrayList<String>(); + if (StringUtils.isEmpty(str)) { + return list; + } + + // 杩囨护绌虹櫧瀛楃涓� + if (filterBlank && StringUtils.isBlank(str)) { + return list; + } + String[] split = str.split(sep); + for (String string : split) { + if (filterBlank && StringUtils.isBlank(string)) { + continue; + } + if (trim) { + string = string.trim(); + } + list.add(string); + } + + return list; + } + + /** + * 鍒ゆ柇缁欏畾鐨剆et鍒楄〃涓槸鍚﹀寘鍚暟缁刟rray 鍒ゆ柇缁欏畾鐨勬暟缁刟rray涓槸鍚﹀寘鍚粰瀹氱殑鍏冪礌value + * + * @param array 缁欏畾鐨勬暟缁� + * @return boolean 缁撴灉 + */ + public static boolean containsAny(Collection<String> collection, String... array) { + if (isEmpty(collection) || isEmpty(array)) { + return false; + } else { + for (String str : array) { + if (collection.contains(str)) { + return true; + } + } + return false; + } + } + + /** + * 鏌ユ壘鎸囧畾瀛楃涓叉槸鍚﹀寘鍚寚瀹氬瓧绗︿覆鍒楄〃涓殑浠绘剰涓�涓瓧绗︿覆鍚屾椂涓插拷鐣ュぇ灏忓啓 + * + * @param cs 鎸囧畾瀛楃涓� + * @param searchCharSequences 闇�瑕佹鏌ョ殑瀛楃涓叉暟缁� + * @return 鏄惁鍖呭惈浠绘剰涓�涓瓧绗︿覆 + */ + public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) { + if (isEmpty(cs) || isEmpty(searchCharSequences)) { + return false; + } + for (CharSequence testStr : searchCharSequences) { + if (containsIgnoreCase(cs, testStr)) { + return true; + } + } + return false; + } + + /** + * 椹煎嘲杞笅鍒掔嚎鍛藉悕 + */ + public static String toUnderScoreCase(String str) { + if (str == null) { + return null; + } + StringBuilder sb = new StringBuilder(); + // 鍓嶇疆瀛楃鏄惁澶у啓 + boolean preCharIsUpperCase = true; + // 褰撳墠瀛楃鏄惁澶у啓 + boolean curreCharIsUpperCase = true; + // 涓嬩竴瀛楃鏄惁澶у啓 + boolean nexteCharIsUpperCase = true; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (i > 0) { + preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1)); + } else { + preCharIsUpperCase = false; + } + + curreCharIsUpperCase = Character.isUpperCase(c); + + if (i < (str.length() - 1)) { + nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1)); + } + + if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) { + sb.append(SEPARATOR); + } else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase) { + sb.append(SEPARATOR); + } + sb.append(Character.toLowerCase(c)); + } + + return sb.toString(); + } + + /** + * 鏄惁鍖呭惈瀛楃涓� + * + * @param str 楠岃瘉瀛楃涓� + * @param strs 瀛楃涓茬粍 + * @return 鍖呭惈杩斿洖true + */ + public static boolean inStringIgnoreCase(String str, String... strs) { + if (str != null && strs != null) { + for (String s : strs) { + if (str.equalsIgnoreCase(trim(s))) { + return true; + } + } + } + return false; + } + + /** + * 灏嗕笅鍒掔嚎澶у啓鏂瑰紡鍛藉悕鐨勫瓧绗︿覆杞崲涓洪┘宄板紡銆傚鏋滆浆鎹㈠墠鐨勪笅鍒掔嚎澶у啓鏂瑰紡鍛藉悕鐨勫瓧绗︿覆涓虹┖锛屽垯杩斿洖绌哄瓧绗︿覆銆� 渚嬪锛欻ELLO_WORLD->HelloWorld + * + * @param name 杞崲鍓嶇殑涓嬪垝绾垮ぇ鍐欐柟寮忓懡鍚嶇殑瀛楃涓� + * @return 杞崲鍚庣殑椹煎嘲寮忓懡鍚嶇殑瀛楃涓� + */ + public static String convertToCamelCase(String name) { + StringBuilder result = new StringBuilder(); + // 蹇�熸鏌� + if (name == null || name.isEmpty()) { + // 娌″繀瑕佽浆鎹� + return ""; + } else if (!name.contains("_")) { + // 涓嶅惈涓嬪垝绾匡紝浠呭皢棣栧瓧姣嶅ぇ鍐� + return name.substring(0, 1).toUpperCase() + name.substring(1); + } + // 鐢ㄤ笅鍒掔嚎灏嗗師濮嬪瓧绗︿覆鍒嗗壊 + String[] camels = name.split("_"); + for (String camel : camels) { + // 璺宠繃鍘熷瀛楃涓蹭腑寮�澶淬�佺粨灏剧殑涓嬫崲绾挎垨鍙岄噸涓嬪垝绾� + if (camel.isEmpty()) { + continue; + } + // 棣栧瓧姣嶅ぇ鍐� + result.append(camel.substring(0, 1).toUpperCase()); + result.append(camel.substring(1).toLowerCase()); + } + return result.toString(); + } + + /** + * 椹煎嘲寮忓懡鍚嶆硶 渚嬪锛歶ser_name->userName + */ + public static String toCamelCase(String s) { + if (s == null) { + return null; + } + s = s.toLowerCase(); + StringBuilder sb = new StringBuilder(s.length()); + boolean upperCase = false; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + if (c == SEPARATOR) { + upperCase = true; + } else if (upperCase) { + sb.append(Character.toUpperCase(c)); + upperCase = false; + } else { + sb.append(c); + } + } + return sb.toString(); + } + + /** + * 鏌ユ壘鎸囧畾瀛楃涓叉槸鍚﹀尮閰嶆寚瀹氬瓧绗︿覆鍒楄〃涓殑浠绘剰涓�涓瓧绗︿覆 + * + * @param str 鎸囧畾瀛楃涓� + * @param strs 闇�瑕佹鏌ョ殑瀛楃涓叉暟缁� + * @return 鏄惁鍖归厤 + */ + public static boolean matches(String str, List<String> strs) { + if (isEmpty(str) || isEmpty(strs)) { + return false; + } + for (String pattern : strs) { + if (isMatch(pattern, str)) { + return true; + } + } + return false; + } + + /** + * 鍒ゆ柇url鏄惁涓庤鍒欓厤缃�: + * ? 琛ㄧず鍗曚釜瀛楃; + * * 琛ㄧず涓�灞傝矾寰勫唴鐨勪换鎰忓瓧绗︿覆锛屼笉鍙法灞傜骇; + * ** 琛ㄧず浠绘剰灞傝矾寰�; + * + * @param pattern 鍖归厤瑙勫垯 + * @param url 闇�瑕佸尮閰嶇殑url + * @return + */ + public static boolean isMatch(String pattern, String url) { + AntPathMatcher matcher = new AntPathMatcher(); + return matcher.match(pattern, url); + } + + @SuppressWarnings("unchecked") + public static <T> T cast(Object obj) { + return (T) obj; + } + + /** + * 鏁板瓧宸﹁竟琛ラ綈0锛屼娇涔嬭揪鍒版寚瀹氶暱搴︺�傛敞鎰忥紝濡傛灉鏁板瓧杞崲涓哄瓧绗︿覆鍚庯紝闀垮害澶т簬size锛屽垯鍙繚鐣� 鏈�鍚巗ize涓瓧绗︺�� + * + * @param num 鏁板瓧瀵硅薄 + * @param size 瀛楃涓叉寚瀹氶暱搴� + * @return 杩斿洖鏁板瓧鐨勫瓧绗︿覆鏍煎紡锛岃瀛楃涓蹭负鎸囧畾闀垮害銆� + */ + public static final String padl(final Number num, final int size) { + return padl(num.toString(), size, '0'); + } + + /** + * 瀛楃涓插乏琛ラ綈銆傚鏋滃師濮嬪瓧绗︿覆s闀垮害澶т簬size锛屽垯鍙繚鐣欐渶鍚巗ize涓瓧绗︺�� + * + * @param s 鍘熷瀛楃涓� + * @param size 瀛楃涓叉寚瀹氶暱搴� + * @param c 鐢ㄤ簬琛ラ綈鐨勫瓧绗� + * @return 杩斿洖鎸囧畾闀垮害鐨勫瓧绗︿覆锛岀敱鍘熷瓧绗︿覆宸﹁ˉ榻愭垨鎴彇寰楀埌銆� + */ + public static final String padl(final String s, final int size, final char c) { + final StringBuilder sb = new StringBuilder(size); + if (s != null) { + final int len = s.length(); + if (s.length() <= size) { + for (int i = size - len; i > 0; i--) { + sb.append(c); + } + sb.append(s); + } else { + return s.substring(len - size, len); + } + } else { + for (int i = size; i > 0; i--) { + sb.append(c); + } + } + return sb.toString(); + } + + + //鏍规嵁骞撮緞 鑾峰彇骞撮緞娈� 0-1濠村効 1-4骞煎効 5-11鍎跨 12-18灏戝勾 19-35闈掑勾 36-59涓勾 60+鑰佸勾 + public static int getAgeType(Integer age) { + int type = 0; + if (1 < age && age < 4) { + type = 1; + } else if (5 < age && age < 11) { + type = 2; + } else if (12 < age && age < 18) { + type = 3; + } else if (19 < age && age < 35) { + type = 4; + } else if (36 < age && age < 59) { + type = 5; + } else if (60 < age && age < 150) { + type = 6; + } + return type; + } +} diff --git a/src/main/java/com/example/utils/text/CharsetKit.java b/src/main/java/com/example/utils/text/CharsetKit.java new file mode 100644 index 0000000..c902d58 --- /dev/null +++ b/src/main/java/com/example/utils/text/CharsetKit.java @@ -0,0 +1,91 @@ +package com.example.utils.text; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import com.example.utils.StringUtils; + +/** + * 瀛楃闆嗗伐鍏风被 + * + * @author ltkj + */ +public class CharsetKit { + /** + * ISO-8859-1 + */ + public static final String ISO_8859_1 = "ISO-8859-1"; + /** + * UTF-8 + */ + public static final String UTF_8 = "UTF-8"; + /** + * GBK + */ + public static final String GBK = "GBK"; + + /** + * ISO-8859-1 + */ + public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); + /** + * UTF-8 + */ + public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); + /** + * GBK + */ + public static final Charset CHARSET_GBK = Charset.forName(GBK); + + /** + * 杞崲涓篊harset瀵硅薄 + * + * @param charset 瀛楃闆嗭紝涓虹┖鍒欒繑鍥為粯璁ゅ瓧绗﹂泦 + * @return Charset + */ + public static Charset charset(String charset) { + return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); + } + + /** + * 杞崲瀛楃涓茬殑瀛楃闆嗙紪鐮� + * + * @param source 瀛楃涓� + * @param srcCharset 婧愬瓧绗﹂泦锛岄粯璁SO-8859-1 + * @param destCharset 鐩爣瀛楃闆嗭紝榛樿UTF-8 + * @return 杞崲鍚庣殑瀛楃闆� + */ + public static String convert(String source, String srcCharset, String destCharset) { + return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); + } + + /** + * 杞崲瀛楃涓茬殑瀛楃闆嗙紪鐮� + * + * @param source 瀛楃涓� + * @param srcCharset 婧愬瓧绗﹂泦锛岄粯璁SO-8859-1 + * @param destCharset 鐩爣瀛楃闆嗭紝榛樿UTF-8 + * @return 杞崲鍚庣殑瀛楃闆� + */ + public static String convert(String source, Charset srcCharset, Charset destCharset) { + if (null == srcCharset) { + srcCharset = StandardCharsets.ISO_8859_1; + } + + if (null == destCharset) { + destCharset = StandardCharsets.UTF_8; + } + + if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) { + return source; + } + return new String(source.getBytes(srcCharset), destCharset); + } + + /** + * @return 绯荤粺瀛楃闆嗙紪鐮� + */ + public static String systemCharset() { + return Charset.defaultCharset().name(); + } +} diff --git a/src/main/java/com/example/utils/text/Convert.java b/src/main/java/com/example/utils/text/Convert.java new file mode 100644 index 0000000..1d6df4e --- /dev/null +++ b/src/main/java/com/example/utils/text/Convert.java @@ -0,0 +1,849 @@ +package com.example.utils.text; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.text.NumberFormat; +import java.util.Set; + +import com.example.utils.StringUtils; +import org.apache.commons.lang3.ArrayUtils; + +/** + * 绫诲瀷杞崲鍣� + * + * @author ltkj + */ +public class Convert { + /** + * 杞崲涓哄瓧绗︿覆<br> + * 濡傛灉缁欏畾鐨勫�间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static String toStr(Object value, String defaultValue) { + if (null == value) { + return defaultValue; + } + if (value instanceof String) { + return (String) value; + } + return value.toString(); + } + + /** + * 杞崲涓哄瓧绗︿覆<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static String toStr(Object value) { + return toStr(value, null); + } + + /** + * 杞崲涓哄瓧绗�<br> + * 濡傛灉缁欏畾鐨勫�间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Character toChar(Object value, Character defaultValue) { + if (null == value) { + return defaultValue; + } + if (value instanceof Character) { + return (Character) value; + } + + final String valueStr = toStr(value, null); + return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); + } + + /** + * 杞崲涓哄瓧绗�<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Character toChar(Object value) { + return toChar(value, null); + } + + /** + * 杞崲涓篵yte<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Byte toByte(Object value, Byte defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Byte) { + return (Byte) value; + } + if (value instanceof Number) { + return ((Number) value).byteValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Byte.parseByte(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篵yte<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Byte toByte(Object value) { + return toByte(value, null); + } + + /** + * 杞崲涓篠hort<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Short toShort(Object value, Short defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Short) { + return (Short) value; + } + if (value instanceof Number) { + return ((Number) value).shortValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Short.parseShort(valueStr.trim()); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篠hort<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Short toShort(Object value) { + return toShort(value, null); + } + + /** + * 杞崲涓篘umber<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Number toNumber(Object value, Number defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Number) { + return (Number) value; + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return NumberFormat.getInstance().parse(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篘umber<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Number toNumber(Object value) { + return toNumber(value, null); + } + + /** + * 杞崲涓篿nt<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Integer toInt(Object value, Integer defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Integer) { + return (Integer) value; + } + if (value instanceof Number) { + return ((Number) value).intValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Integer.parseInt(valueStr.trim()); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篿nt<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Integer toInt(Object value) { + return toInt(value, null); + } + + /** + * 杞崲涓篒nteger鏁扮粍<br> + * + * @param str 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Integer[] toIntArray(String str) { + return toIntArray(",", str); + } + + /** + * 杞崲涓篖ong鏁扮粍<br> + * + * @param str 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Long[] toLongArray(String str) { + return toLongArray(",", str); + } + + /** + * 杞崲涓篒nteger鏁扮粍<br> + * + * @param split 鍒嗛殧绗� + * @param split 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Integer[] toIntArray(String split, String str) { + if (StringUtils.isEmpty(str)) { + return new Integer[]{}; + } + String[] arr = str.split(split); + final Integer[] ints = new Integer[arr.length]; + for (int i = 0; i < arr.length; i++) { + final Integer v = toInt(arr[i], 0); + ints[i] = v; + } + return ints; + } + + /** + * 杞崲涓篖ong鏁扮粍<br> + * + * @param split 鍒嗛殧绗� + * @param str 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Long[] toLongArray(String split, String str) { + if (StringUtils.isEmpty(str)) { + return new Long[]{}; + } + String[] arr = str.split(split); + final Long[] longs = new Long[arr.length]; + for (int i = 0; i < arr.length; i++) { + final Long v = toLong(arr[i], null); + longs[i] = v; + } + return longs; + } + + /** + * 杞崲涓篠tring鏁扮粍<br> + * + * @param str 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static String[] toStrArray(String str) { + return toStrArray(",", str); + } + + /** + * 杞崲涓篠tring鏁扮粍<br> + * + * @param split 鍒嗛殧绗� + * @param split 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static String[] toStrArray(String split, String str) { + return str.split(split); + } + + /** + * 杞崲涓簂ong<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Long toLong(Object value, Long defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Long) { + return (Long) value; + } + if (value instanceof Number) { + return ((Number) value).longValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + // 鏀寔绉戝璁℃暟娉� + return new BigDecimal(valueStr.trim()).longValue(); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓簂ong<br> + * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Long toLong(Object value) { + return toLong(value, null); + } + + /** + * 杞崲涓篸ouble<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Double toDouble(Object value, Double defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Double) { + return (Double) value; + } + if (value instanceof Number) { + return ((Number) value).doubleValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + // 鏀寔绉戝璁℃暟娉� + return new BigDecimal(valueStr.trim()).doubleValue(); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篸ouble<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Double toDouble(Object value) { + return toDouble(value, null); + } + + /** + * 杞崲涓篎loat<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Float toFloat(Object value, Float defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Float) { + return (Float) value; + } + if (value instanceof Number) { + return ((Number) value).floatValue(); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Float.parseFloat(valueStr.trim()); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篎loat<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Float toFloat(Object value) { + return toFloat(value, null); + } + + /** + * 杞崲涓篵oolean<br> + * String鏀寔鐨勫�间负锛歵rue銆乫alse銆亂es銆乷k銆乶o锛�1,0 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static Boolean toBool(Object value, Boolean defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof Boolean) { + return (Boolean) value; + } + String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + valueStr = valueStr.trim().toLowerCase(); + switch (valueStr) { + case "true": + case "yes": + case "ok": + case "1": + return true; + case "false": + case "no": + case "0": + return false; + default: + return defaultValue; + } + } + + /** + * 杞崲涓篵oolean<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static Boolean toBool(Object value) { + return toBool(value, null); + } + + /** + * 杞崲涓篍num瀵硅薄<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * + * @param clazz Enum鐨凜lass + * @param value 鍊� + * @param defaultValue 榛樿鍊� + * @return Enum + */ + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) { + if (value == null) { + return defaultValue; + } + if (clazz.isAssignableFrom(value.getClass())) { + @SuppressWarnings("unchecked") + E myE = (E) value; + return myE; + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return Enum.valueOf(clazz, valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓篍num瀵硅薄<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * + * @param clazz Enum鐨凜lass + * @param value 鍊� + * @return Enum + */ + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) { + return toEnum(clazz, value, null); + } + + /** + * 杞崲涓築igInteger<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static BigInteger toBigInteger(Object value, BigInteger defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof BigInteger) { + return (BigInteger) value; + } + if (value instanceof Long) { + return BigInteger.valueOf((Long) value); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return new BigInteger(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓築igInteger<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static BigInteger toBigInteger(Object value) { + return toBigInteger(value, null); + } + + /** + * 杞崲涓築igDecimal<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� + * @return 缁撴灉 + */ + public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) { + if (value == null) { + return defaultValue; + } + if (value instanceof BigDecimal) { + return (BigDecimal) value; + } + if (value instanceof Long) { + return new BigDecimal((Long) value); + } + if (value instanceof Double) { + return new BigDecimal((Double) value); + } + if (value instanceof Integer) { + return new BigDecimal((Integer) value); + } + final String valueStr = toStr(value, null); + if (StringUtils.isEmpty(valueStr)) { + return defaultValue; + } + try { + return new BigDecimal(valueStr); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * 杞崲涓築igDecimal<br> + * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> + * 杞崲澶辫触涓嶄細鎶ラ敊 + * + * @param value 琚浆鎹㈢殑鍊� + * @return 缁撴灉 + */ + public static BigDecimal toBigDecimal(Object value) { + return toBigDecimal(value, null); + } + + /** + * 灏嗗璞¤浆涓哄瓧绗︿覆<br> + * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁� 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 + * + * @param obj 瀵硅薄 + * @return 瀛楃涓� + */ + public static String utf8Str(Object obj) { + return str(obj, CharsetKit.CHARSET_UTF_8); + } + + /** + * 灏嗗璞¤浆涓哄瓧绗︿覆<br> + * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁� 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 + * + * @param obj 瀵硅薄 + * @param charsetName 瀛楃闆� + * @return 瀛楃涓� + */ + public static String str(Object obj, String charsetName) { + return str(obj, Charset.forName(charsetName)); + } + + /** + * 灏嗗璞¤浆涓哄瓧绗︿覆<br> + * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁� 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 + * + * @param obj 瀵硅薄 + * @param charset 瀛楃闆� + * @return 瀛楃涓� + */ + public static String str(Object obj, Charset charset) { + if (null == obj) { + return null; + } + + if (obj instanceof String) { + return (String) obj; + } else if (obj instanceof byte[]) { + return str((byte[]) obj, charset); + } else if (obj instanceof Byte[]) { + byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj); + return str(bytes, charset); + } else if (obj instanceof ByteBuffer) { + return str((ByteBuffer) obj, charset); + } + return obj.toString(); + } + + /** + * 灏哹yte鏁扮粍杞负瀛楃涓� + * + * @param bytes byte鏁扮粍 + * @param charset 瀛楃闆� + * @return 瀛楃涓� + */ + public static String str(byte[] bytes, String charset) { + return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); + } + + /** + * 瑙g爜瀛楄妭鐮� + * + * @param data 瀛楃涓� + * @param charset 瀛楃闆嗭紝濡傛灉姝ゅ瓧娈典负绌猴紝鍒欒В鐮佺殑缁撴灉鍙栧喅浜庡钩鍙� + * @return 瑙g爜鍚庣殑瀛楃涓� + */ + public static String str(byte[] data, Charset charset) { + if (data == null) { + return null; + } + + if (null == charset) { + return new String(data); + } + return new String(data, charset); + } + + /** + * 灏嗙紪鐮佺殑byteBuffer鏁版嵁杞崲涓哄瓧绗︿覆 + * + * @param data 鏁版嵁 + * @param charset 瀛楃闆嗭紝濡傛灉涓虹┖浣跨敤褰撳墠绯荤粺瀛楃闆� + * @return 瀛楃涓� + */ + public static String str(ByteBuffer data, String charset) { + if (data == null) { + return null; + } + + return str(data, Charset.forName(charset)); + } + + /** + * 灏嗙紪鐮佺殑byteBuffer鏁版嵁杞崲涓哄瓧绗︿覆 + * + * @param data 鏁版嵁 + * @param charset 瀛楃闆嗭紝濡傛灉涓虹┖浣跨敤褰撳墠绯荤粺瀛楃闆� + * @return 瀛楃涓� + */ + public static String str(ByteBuffer data, Charset charset) { + if (null == charset) { + charset = Charset.defaultCharset(); + } + return charset.decode(data).toString(); + } + + // ----------------------------------------------------------------------- 鍏ㄨ鍗婅杞崲 + + /** + * 鍗婅杞叏瑙� + * + * @param input String. + * @return 鍏ㄨ瀛楃涓�. + */ + public static String toSBC(String input) { + return toSBC(input, null); + } + + /** + * 鍗婅杞叏瑙� + * + * @param input String + * @param notConvertSet 涓嶆浛鎹㈢殑瀛楃闆嗗悎 + * @return 鍏ㄨ瀛楃涓�. + */ + public static String toSBC(String input, Set<Character> notConvertSet) { + char[] c = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (null != notConvertSet && notConvertSet.contains(c[i])) { + // 璺宠繃涓嶆浛鎹㈢殑瀛楃 + continue; + } + + if (c[i] == ' ') { + c[i] = '\u3000'; + } else if (c[i] < '\177') { + c[i] = (char) (c[i] + 65248); + + } + } + return new String(c); + } + + /** + * 鍏ㄨ杞崐瑙� + * + * @param input String. + * @return 鍗婅瀛楃涓� + */ + public static String toDBC(String input) { + return toDBC(input, null); + } + + /** + * 鏇挎崲鍏ㄨ涓哄崐瑙� + * + * @param text 鏂囨湰 + * @param notConvertSet 涓嶆浛鎹㈢殑瀛楃闆嗗悎 + * @return 鏇挎崲鍚庣殑瀛楃 + */ + public static String toDBC(String text, Set<Character> notConvertSet) { + char[] c = text.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (null != notConvertSet && notConvertSet.contains(c[i])) { + // 璺宠繃涓嶆浛鎹㈢殑瀛楃 + continue; + } + + if (c[i] == '\u3000') { + c[i] = ' '; + } else if (c[i] > '\uFF00' && c[i] < '\uFF5F') { + c[i] = (char) (c[i] - 65248); + } + } + String returnString = new String(c); + + return returnString; + } + + /** + * 鏁板瓧閲戦澶у啓杞崲 鍏堝啓涓畬鏁寸殑鐒跺悗灏嗗闆舵嬀鏇挎崲鎴愰浂 + * + * @param n 鏁板瓧 + * @return 涓枃澶у啓鏁板瓧 + */ + public static String digitUppercase(double n) { + String[] fraction = {"瑙�", "鍒�"}; + String[] digit = {"闆�", "澹�", "璐�", "鍙�", "鑲�", "浼�", "闄�", "鏌�", "鎹�", "鐜�"}; + String[][] unit = {{"鍏�", "涓�", "浜�"}, {"", "鎷�", "浣�", "浠�"}}; + + String head = n < 0 ? "璐�" : ""; + n = Math.abs(n); + + String s = ""; + for (int i = 0; i < fraction.length; i++) { + s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(闆�.)+", ""); + } + if (s.length() < 1) { + s = "鏁�"; + } + int integerPart = (int) Math.floor(n); + + for (int i = 0; i < unit[0].length && integerPart > 0; i++) { + String p = ""; + for (int j = 0; j < unit[1].length && n > 0; j++) { + p = digit[integerPart % 10] + unit[1][j] + p; + integerPart = integerPart / 10; + } + s = p.replaceAll("(闆�.)*闆�$", "").replaceAll("^$", "闆�") + unit[0][i] + s; + } + return head + s.replaceAll("(闆�.)*闆跺厓", "鍏�").replaceFirst("(闆�.)+", "").replaceAll("(闆�.)+", "闆�").replaceAll("^鏁�$", "闆跺厓鏁�"); + } +} diff --git a/src/main/java/com/example/utils/text/StrFormatter.java b/src/main/java/com/example/utils/text/StrFormatter.java new file mode 100644 index 0000000..5a0b50c --- /dev/null +++ b/src/main/java/com/example/utils/text/StrFormatter.java @@ -0,0 +1,76 @@ +package com.example.utils.text; + +import com.example.utils.StringUtils; + +/** + * 瀛楃涓叉牸寮忓寲 + * + * @author ltkj + */ +public class StrFormatter { + public static final String EMPTY_JSON = "{}"; + public static final char C_BACKSLASH = '\\'; + public static final char C_DELIM_START = '{'; + public static final char C_DELIM_END = '}'; + + /** + * 鏍煎紡鍖栧瓧绗︿覆<br> + * 姝ゆ柟娉曞彧鏄畝鍗曞皢鍗犱綅绗� {} 鎸夌収椤哄簭鏇挎崲涓哄弬鏁�<br> + * 濡傛灉鎯宠緭鍑� {} 浣跨敤 \\杞箟 { 鍗冲彲锛屽鏋滄兂杈撳嚭 {} 涔嬪墠鐨� \ 浣跨敤鍙岃浆涔夌 \\\\ 鍗冲彲<br> + * 渚嬶細<br> + * 閫氬父浣跨敤锛歠ormat("this is {} for {}", "a", "b") -> this is a for b<br> + * 杞箟{}锛� format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> + * 杞箟\锛� format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> + * + * @param strPattern 瀛楃涓叉ā鏉� + * @param argArray 鍙傛暟鍒楄〃 + * @return 缁撴灉 + */ + public static String format(final String strPattern, final Object... argArray) { + if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) { + return strPattern; + } + final int strPatternLength = strPattern.length(); + + // 鍒濆鍖栧畾涔夊ソ鐨勯暱搴︿互鑾峰緱鏇村ソ鐨勬�ц兘 + StringBuilder sbuf = new StringBuilder(strPatternLength + 50); + + int handledPosition = 0; + int delimIndex;// 鍗犱綅绗︽墍鍦ㄤ綅缃� + for (int argIndex = 0; argIndex < argArray.length; argIndex++) { + delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); + if (delimIndex == -1) { + if (handledPosition == 0) { + return strPattern; + } else { // 瀛楃涓叉ā鏉垮墿浣欓儴鍒嗕笉鍐嶅寘鍚崰浣嶇锛屽姞鍏ュ墿浣欓儴鍒嗗悗杩斿洖缁撴灉 + sbuf.append(strPattern, handledPosition, strPatternLength); + return sbuf.toString(); + } + } else { + if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) { + if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) { + // 杞箟绗︿箣鍓嶈繕鏈変竴涓浆涔夌锛屽崰浣嶇渚濇棫鏈夋晥 + sbuf.append(strPattern, handledPosition, delimIndex - 1); + sbuf.append(Convert.utf8Str(argArray[argIndex])); + handledPosition = delimIndex + 2; + } else { + // 鍗犱綅绗﹁杞箟 + argIndex--; + sbuf.append(strPattern, handledPosition, delimIndex - 1); + sbuf.append(C_DELIM_START); + handledPosition = delimIndex + 1; + } + } else { + // 姝e父鍗犱綅绗� + sbuf.append(strPattern, handledPosition, delimIndex); + sbuf.append(Convert.utf8Str(argArray[argIndex])); + handledPosition = delimIndex + 2; + } + } + } + // 鍔犲叆鏈�鍚庝竴涓崰浣嶇鍚庢墍鏈夌殑瀛楃 + sbuf.append(strPattern, handledPosition, strPattern.length()); + + return sbuf.toString(); + } +} diff --git a/src/main/resources/application-linux.yaml b/src/main/resources/application-linux.yaml new file mode 100644 index 0000000..ca40902 --- /dev/null +++ b/src/main/resources/application-linux.yaml @@ -0,0 +1,3 @@ +config: + path: /ltkj/ltkjprojectconf/config.properties + dir: /ltkj/ltkjprojectconf diff --git a/src/main/resources/application-win.yaml b/src/main/resources/application-win.yaml new file mode 100644 index 0000000..b303d50 --- /dev/null +++ b/src/main/resources/application-win.yaml @@ -0,0 +1,3 @@ +config: + path: D:\ltkjprojectconf\config.properties + dir: D:\ltkjprojectconf diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 51502c6..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -server.port=14765 -server.servlet.context-path=/ -logging.level.com.example=debug diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 96c4cfb..1d780c2 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,3 +1,8 @@ +server: + port: 14765 + servlet: + context-path: / + mybatis-plus: # 鎼滅储鎸囧畾鍖呭埆鍚� typeAliasesPackage: com.example.domain @@ -9,15 +14,12 @@ logic-delete-value: 1 update-strategy: not_null spring: + profiles: + active: win datasource: type: com.alibaba.druid.pool.DruidDataSource driverClassName: com.mysql.cj.jdbc.Driver druid: - # 涓诲簱鏁版嵁婧� - master: - url: jdbc:mysql://101.42.27.146:3306/ltkj_tj1.0?serverTimezone=GMT%2B8 - username: root - password: Root_ltkj123 # 鍒濆杩炴帴鏁� initialSize: 5 # 鏈�灏忚繛鎺ユ睜鏁伴噺 @@ -57,6 +59,3 @@ wall: config: multi-statement-allow: true -config: - path: D:\ltkjprojectconf\config.properties - dir: D:\ltkjprojectconf diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index ae870e0..95f3a98 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -1,25 +1,120 @@ +<?xml version="1.0" encoding="UTF-8"?> <configuration> + <!-- 鏃ュ織瀛樻斁璺緞 windows鐜--> + <springProfile name="win"> + <property name="log.path" value="logs"/> + </springProfile> - <!-- 杈撳嚭鍒版枃浠朵腑 --> - <appender name="FILE" class="ch.qos.logback.core.FileAppender"> - <file>src/main/resources/log.log</file> - <append>true</append> + <!-- 鏃ュ織瀛樻斁璺緞 linux鐜--> + <springProfile name="linux"> + <property name="log.path" value="/ltkj/jar/logs/sjpt"/> + </springProfile> + + <!-- 鏃ュ織杈撳嚭鏍煎紡 --> + <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/> + + <!-- 鎺у埗鍙拌緭鍑� --> + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <encoder> - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern> + <pattern>${log.pattern}</pattern> </encoder> </appender> <!-- 鎺у埗鍙拌緭鍑� --> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg%n</pattern> - </encoder> + <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> + <!-- 褰╄壊鏃ュ織 --> + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern> + %d{yyyy-MM-dd HH:mm:ss} [%thread] %yellow(%-5level) %white([%-50.50class]) >>> %green(%msg) %n + </pattern> + </layout> </appender> - <!-- 瀹氫箟鏃ュ織绾у埆 --> - <root level="INFO"> - <appender-ref ref="FILE"/> - <appender-ref ref="STDOUT"/> + <!-- 绯荤粺鏃ュ織杈撳嚭 --> + <appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${log.path}/sys-info.log</file> + <!-- 寰幆鏀跨瓥锛氬熀浜庢椂闂村垱寤烘棩蹇楁枃浠� --> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <!-- 鏃ュ織鏂囦欢鍚嶆牸寮� --> + <fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern> + <!-- 鏃ュ織鏈�澶х殑鍘嗗彶 60澶� --> + <maxHistory>60</maxHistory> + </rollingPolicy> + <encoder> + <pattern>${log.pattern}</pattern> + </encoder> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <!-- 杩囨护鐨勭骇鍒� --> + <level>INFO</level> + <!-- 鍖归厤鏃剁殑鎿嶄綔锛氭帴鏀讹紙璁板綍锛� --> + <onMatch>ACCEPT</onMatch> + <!-- 涓嶅尮閰嶆椂鐨勬搷浣滐細鎷掔粷锛堜笉璁板綍锛� --> + <onMismatch>DENY</onMismatch> + </filter> + </appender> + + <appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${log.path}/sys-error.log</file> + <!-- 寰幆鏀跨瓥锛氬熀浜庢椂闂村垱寤烘棩蹇楁枃浠� --> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <!-- 鏃ュ織鏂囦欢鍚嶆牸寮� --> + <fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern> + <!-- 鏃ュ織鏈�澶х殑鍘嗗彶 60澶� --> + <maxHistory>60</maxHistory> + </rollingPolicy> + <encoder> + <pattern>${log.pattern}</pattern> + </encoder> + <filter class="ch.qos.logback.classic.filter.LevelFilter"> + <!-- 杩囨护鐨勭骇鍒� --> + <level>ERROR</level> + <!-- 鍖归厤鏃剁殑鎿嶄綔锛氭帴鏀讹紙璁板綍锛� --> + <onMatch>ACCEPT</onMatch> + <!-- 涓嶅尮閰嶆椂鐨勬搷浣滐細鎷掔粷锛堜笉璁板綍锛� --> + <onMismatch>DENY</onMismatch> + </filter> + </appender> + + <!-- 鐢ㄦ埛璁块棶鏃ュ織杈撳嚭 --> + <appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${log.path}/sys-user.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + <!-- 鎸夊ぉ鍥炴粴 daily --> + <fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern> + <!-- 鏃ュ織鏈�澶х殑鍘嗗彶 60澶� --> + <maxHistory>60</maxHistory> + </rollingPolicy> + <encoder> + <pattern>${log.pattern}</pattern> + </encoder> + </appender> +<!-- <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">--> +<!-- <!– ... 鍏朵粬閰嶇疆 ... –>--> +<!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">--> +<!-- <!– ... 鍏朵粬閰嶇疆 ... –>--> +<!-- <!– 璁剧疆鏈�闀夸繚鐣欐湡闄愪负 7 澶� –>--> +<!-- <maxDays>7</maxDays>--> +<!-- </rollingPolicy>--> +<!-- </appender>--> + + + <!-- 绯荤粺妯″潡鏃ュ織绾у埆鎺у埗 --> + <logger name="com.ltkj" level="info"/> + <!-- Spring鏃ュ織绾у埆鎺у埗 --> + <logger name="org.springframework" level="warn"/> + + <root level="info"> + <appender-ref ref="console"/> </root> + <!--绯荤粺鎿嶄綔鏃ュ織--> + <root level="info"> + <appender-ref ref="file_info"/> + <appender-ref ref="file_error"/> + </root> + + <!--绯荤粺鐢ㄦ埛鎿嶄綔鏃ュ織--> + <logger name="sys-user" level="info"> + <appender-ref ref="sys-user"/> + </logger> </configuration> diff --git a/src/main/resources/mapper/SysConfigMapper.xml b/src/main/resources/mapper/SysConfigMapper.xml new file mode 100644 index 0000000..84f2a99 --- /dev/null +++ b/src/main/resources/mapper/SysConfigMapper.xml @@ -0,0 +1,129 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.example.mapper.SysConfigMapper"> + + <resultMap type="SysConfig" id="SysConfigResult"> + <id property="configId" column="config_id"/> + <result property="configName" column="config_name"/> + <result property="configKey" column="config_key"/> + <result property="configValue" column="config_value"/> + <result property="configType" column="config_type"/> + <result property="createBy" column="create_by"/> + <result property="createTime" column="create_time"/> + <result property="updateBy" column="update_by"/> + <result property="updateTime" column="update_time"/> + </resultMap> + + <sql id="selectConfigVo"> + select config_id, + config_name, + config_key, + config_value, + config_type, + create_by, + create_time, + update_by, + update_time, + remark + from sys_config + </sql> + + <!-- 鏌ヨ鏉′欢 --> + <sql id="sqlwhereSearch"> + <where> + <if test="configId !=null"> + and config_id = #{configId} + </if> + <if test="configKey !=null and configKey != ''"> + and config_key = #{configKey} + </if> + </where> + </sql> + + <select id="selectConfig" parameterType="SysConfig" resultMap="SysConfigResult"> + <include refid="selectConfigVo"/> + <include refid="sqlwhereSearch"/> + </select> + + <select id="selectConfigList" parameterType="SysConfig" resultMap="SysConfigResult"> + <include refid="selectConfigVo"/> + <where> + <if test="configName != null and configName != ''"> + AND config_name like concat('%', #{configName}, '%') + </if> + <if test="configType != null and configType != ''"> + AND config_type = #{configType} + </if> + <if test="configKey != null and configKey != ''"> + AND config_key like concat('%', #{configKey}, '%') + </if> + <if test="params.beginTime != null and params.beginTime != ''"><!-- 寮�濮嬫椂闂存绱� --> + and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') + </if> + <if test="params.endTime != null and params.endTime != ''"><!-- 缁撴潫鏃堕棿妫�绱� --> + and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') + </if> + </where> + </select> + + <select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult"> + <include refid="selectConfigVo"/> + where config_key = #{configKey} limit 1 + </select> + + <insert id="insertConfig" parameterType="SysConfig"> + insert into sys_config ( + <if test="configName != null and configName != '' ">config_name,</if> + <if test="configKey != null and configKey != '' ">config_key,</if> + <if test="configValue != null and configValue != '' ">config_value,</if> + <if test="configType != null and configType != '' ">config_type,</if> + <if test="createBy != null and createBy != ''">create_by,</if> + <if test="remark != null and remark != ''">remark,</if> + create_time + )values( + <if test="configName != null and configName != ''">#{configName},</if> + <if test="configKey != null and configKey != ''">#{configKey},</if> + <if test="configValue != null and configValue != ''">#{configValue},</if> + <if test="configType != null and configType != ''">#{configType},</if> + <if test="createBy != null and createBy != ''">#{createBy},</if> + <if test="remark != null and remark != ''">#{remark},</if> + sysdate() + ) + </insert> + + <update id="updateConfig" parameterType="SysConfig"> + update sys_config + <set> + <if test="configName != null and configName != ''">config_name = #{configName},</if> + <if test="configKey != null and configKey != ''">config_key = #{configKey},</if> + <if test="configValue != null and configValue != ''">config_value = #{configValue},</if> + <if test="configType != null and configType != ''">config_type = #{configType},</if> + <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> + <if test="remark != null">remark = #{remark},</if> + update_time = sysdate() + </set> + where config_id = #{configId} + </update> + + <delete id="deleteConfigById" parameterType="Long"> + delete + from sys_config + where config_id = #{configId} + </delete> + + <delete id="deleteConfigByIds" parameterType="Long"> + delete from sys_config where config_id in + <foreach item="configId" collection="array" open="(" separator="," close=")"> + #{configId} + </foreach> + </delete> + + + + <select id="tbhisproprice"> + {call tb_hisprodj()} + </select> + +</mapper> -- Gitblit v1.8.0