commit c33644a788d68444a2f8e9ec829c9faa8b813d8b Author: test Date: Wed May 1 14:32:28 2024 +0800 Default Changelist diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b5f4730 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..14f8dbd --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..5c39b13 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,82 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..5a2f139 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c41fdfb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bwie-54.iml b/bwie-54.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/bwie-54.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml new file mode 100644 index 0000000..b21337e --- /dev/null +++ b/common/pom.xml @@ -0,0 +1,63 @@ + + + + bwie-54 + org.example + 1.0-SNAPSHOT + + 4.0.0 + + common + + + + + com.alibaba + fastjson + 1.2.79 + + + org.projectlombok + lombok + + + + org.apache.httpcomponents + httpcore + 4.4.12 + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + + + com.alibaba + druid-spring-boot-starter + 1.1.10 + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.3.1 + + + commons-lang + commons-lang + 2.6 + + + com.fasterxml.jackson.core + jackson-annotations + + + + + + + + \ No newline at end of file diff --git a/common/src/main/java/com/bwie/Student.java b/common/src/main/java/com/bwie/Student.java new file mode 100644 index 0000000..59283d6 --- /dev/null +++ b/common/src/main/java/com/bwie/Student.java @@ -0,0 +1,23 @@ +package com.bwie; + +import lombok.Data; + +@Data +public class Student { + /** + * 编号 + */ + private Integer id; + /** + * 姓名 + */ + private String name; + /** + * 年龄 + */ + private Integer age; + + + + +} diff --git a/common/src/main/java/com/bwie/pojo/BillDao.java b/common/src/main/java/com/bwie/pojo/BillDao.java new file mode 100644 index 0000000..ccbfa36 --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/BillDao.java @@ -0,0 +1,23 @@ +package com.bwie.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class BillDao { + /** + * 账单编号 + */ + private Integer billid; + /** + * 账单时间 + */ + private String billDate; + /** + * 账单金额 + */ + private String billMonery; +} diff --git a/common/src/main/java/com/bwie/pojo/Details.java b/common/src/main/java/com/bwie/pojo/Details.java new file mode 100644 index 0000000..092a3fb --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/Details.java @@ -0,0 +1,28 @@ +package com.bwie.pojo; + +import lombok.Data; + +@Data +public class Details { + /** + * 门店详情编号 + */ + private Integer ids; + /** + * 门店详情名称 + */ + private String names; + /** + * 门店详情特色 + */ + private String feature; + /** + * 门店详情手机号 + */ + private String phone; + /** + * 门店详情时间 + */ + private String tiemes; + +} diff --git a/common/src/main/java/com/bwie/pojo/Main.java b/common/src/main/java/com/bwie/pojo/Main.java new file mode 100644 index 0000000..3d8d16c --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/Main.java @@ -0,0 +1,32 @@ +package com.bwie.pojo; + +import lombok.Data; +import org.springframework.jdbc.CannotGetJdbcConnectionException; +@Data +public class Main { + /** + * 用户编号 + */ + private Integer id; + /** + * 用户名称 + */ + private String name; + /** + * 用户价格 + */ + private Integer age; + /** + * 用户地方名 + */ + private String city; + + /** + * 用户地方区 + */ + private String state; + /** + * 用户的Ip + */ + private String zip; +} diff --git a/common/src/main/java/com/bwie/pojo/Stort.java b/common/src/main/java/com/bwie/pojo/Stort.java new file mode 100644 index 0000000..e314761 --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/Stort.java @@ -0,0 +1,32 @@ +package com.bwie.pojo; + +import lombok.Data; + +@Data +public class Stort { + /** + * 门店编号 + */ + private Integer id; + /** + * 门店名称 + */ + private String name; + /** + * 门店地址 + */ + private String address; + /** + * 门店电话 + */ + private String phone; + /** + * 门店商品价格 + */ + private Integer price; + /** + * 门店营业时间 + */ + private String time; + +} diff --git a/common/src/main/java/com/bwie/pojo/User.java b/common/src/main/java/com/bwie/pojo/User.java new file mode 100644 index 0000000..9448a96 --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/User.java @@ -0,0 +1,32 @@ +package com.bwie.pojo; + +import lombok.Data; + +import javax.annotation.PostConstruct; +@Data +public class User { + /** + * 用户编号 + */ + private Integer uid; + /** + * 用户名称 + */ + private String userName; + /** + * 密码 + */ + private String pwd; + /** + * 用户年龄 + */ + private Integer sex; + /** + * 用户生日 + */ + private String time; + + + + +} diff --git a/common/src/main/java/com/bwie/pojo/requery/Voednit.java b/common/src/main/java/com/bwie/pojo/requery/Voednit.java new file mode 100644 index 0000000..af580da --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/requery/Voednit.java @@ -0,0 +1,36 @@ +package com.bwie.pojo.requery; + +import lombok.Data; + +@Data +public class Voednit { + /** + * 商品编号 + */ + private Integer id; + /** + * 商品名称 + */ + private String name; + /** + * 商品品牌 + */ + private String pname; + /** + * 商品介绍 + */ + private String mname; + /** + * 商品价格 + */ + private Integer price; + /** + * 商品数量 + */ + private Integer pwd; + /** + * 商品支付金额 + */ + private Integer prices; + +} diff --git a/common/src/main/java/com/bwie/pojo/util/R.java b/common/src/main/java/com/bwie/pojo/util/R.java new file mode 100644 index 0000000..ad49b94 --- /dev/null +++ b/common/src/main/java/com/bwie/pojo/util/R.java @@ -0,0 +1,28 @@ +package com.bwie.pojo.util; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class R { + private Integer code; + private Object data; + private String msg; + + + + public R(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + public R(Integer code, Object data) { + this.code = code; + this.data = data; + } +} diff --git a/common/target/classes/META-INF/common.kotlin_module b/common/target/classes/META-INF/common.kotlin_module new file mode 100644 index 0000000..a49347a Binary files /dev/null and b/common/target/classes/META-INF/common.kotlin_module differ diff --git a/common/target/classes/com/bwie/Student.class b/common/target/classes/com/bwie/Student.class new file mode 100644 index 0000000..712c716 Binary files /dev/null and b/common/target/classes/com/bwie/Student.class differ diff --git a/common/target/classes/com/bwie/pojo/BillDao.class b/common/target/classes/com/bwie/pojo/BillDao.class new file mode 100644 index 0000000..cdf2b54 Binary files /dev/null and b/common/target/classes/com/bwie/pojo/BillDao.class differ diff --git a/common/target/classes/com/bwie/pojo/Details.class b/common/target/classes/com/bwie/pojo/Details.class new file mode 100644 index 0000000..0adf895 Binary files /dev/null and b/common/target/classes/com/bwie/pojo/Details.class differ diff --git a/common/target/classes/com/bwie/pojo/Main.class b/common/target/classes/com/bwie/pojo/Main.class new file mode 100644 index 0000000..7c2d6be Binary files /dev/null and b/common/target/classes/com/bwie/pojo/Main.class differ diff --git a/common/target/classes/com/bwie/pojo/Stort.class b/common/target/classes/com/bwie/pojo/Stort.class new file mode 100644 index 0000000..761138e Binary files /dev/null and b/common/target/classes/com/bwie/pojo/Stort.class differ diff --git a/common/target/classes/com/bwie/pojo/User.class b/common/target/classes/com/bwie/pojo/User.class new file mode 100644 index 0000000..ab93b75 Binary files /dev/null and b/common/target/classes/com/bwie/pojo/User.class differ diff --git a/common/target/classes/com/bwie/pojo/requery/Voednit.class b/common/target/classes/com/bwie/pojo/requery/Voednit.class new file mode 100644 index 0000000..660868d Binary files /dev/null and b/common/target/classes/com/bwie/pojo/requery/Voednit.class differ diff --git a/common/target/classes/com/bwie/pojo/util/R.class b/common/target/classes/com/bwie/pojo/util/R.class new file mode 100644 index 0000000..7965f39 Binary files /dev/null and b/common/target/classes/com/bwie/pojo/util/R.class differ diff --git a/modules/pom.xml b/modules/pom.xml new file mode 100644 index 0000000..0005065 --- /dev/null +++ b/modules/pom.xml @@ -0,0 +1,197 @@ + + + + bwie-54 + org.example + 1.0-SNAPSHOT + + 4.0.0 + + modules + + + + + org.example + common + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-data-redis + + + io.lettuce + lettuce-core + + + + + redis.clients + jedis + + + org.redisson + redisson + 3.16.0 + + + + org.apache.httpcomponents + httpcore + 4.4.12 + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + + + org.apache.poi + poi + 3.17 + + + + org.apache.poi + poi-ooxml + 3.17 + + + org.apache.poi + poi-ooxml-schemas + 3.17 + + + org.apache.commons + commons-lang3 + 3.12.0 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + + + + + + javax.servlet + javax.servlet-api + provided + + + + mysql + mysql-connector-java + 8.0.11 + runtime + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + commons-lang + commons-lang + 2.6 + + + + com.alibaba + fastjson + 1.2.79 + + + + org.springframework.boot + spring-boot-starter-mail + + + + + com.aliyun.oss + aliyun-sdk-oss + 3.10.2 + + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.9 + + + + io.jsonwebtoken + jjwt + 0.6.0 + + + + + org.springframework.boot + spring-boot-starter-quartz + + + + + + com.github.tobato + fastdfs-client + 1.26.5 + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + com.google.guava + guava + 27.0.1-jre + + + + + + + \ No newline at end of file diff --git a/modules/src/main/java/com/bw/MapperApp.java b/modules/src/main/java/com/bw/MapperApp.java new file mode 100644 index 0000000..14cfe61 --- /dev/null +++ b/modules/src/main/java/com/bw/MapperApp.java @@ -0,0 +1,13 @@ +package com.bw; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScan("com.bw.dao") +public class MapperApp { + public static void main(String[] args) { + SpringApplication.run(MapperApp.class); + } +} diff --git a/modules/src/main/java/com/bw/Tese.java b/modules/src/main/java/com/bw/Tese.java new file mode 100644 index 0000000..1ea556f --- /dev/null +++ b/modules/src/main/java/com/bw/Tese.java @@ -0,0 +1,166 @@ +package com.bw; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.bwie.pojo.BillDao; +import com.bwie.pojo.Main; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.JsonObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Tese { + public static void main(String[] args) throws JsonProcessingException { + //创建map对象 + Map personMap= new HashMap<>(); + personMap.put("name","张三"); + personMap.put("age",25); + //完成输出对象操作 + System.out.println(personMap); + //创建map对象并且提供数据 + Map addressMap= new HashMap<>(); + addressMap.put("city","上海"); + addressMap.put("state","奉贤"); + addressMap.put("zip","10001"); + System.out.println(addressMap); + //创建李四用户信息 + Map filetMap= new HashMap<>(); + filetMap.put("name","李四"); + filetMap.put("age",27); + System.out.println(filetMap); + //地址信息 + MapendMap= new HashMap<>(); + endMap.put("city","上海"); + endMap.put("state","虹桥"); + endMap.put("zip","10002"); + System.out.println(endMap); + //创建王五用户信息 + MaphasMap= new HashMap<>(); + hasMap.put("name","王五"); + hasMap.put("age",24); + //输出 + System.out.println(hasMap); + //所在的地址信息 + MapsentMap= new HashMap<>(); + sentMap.put("city","杭州"); + sentMap.put("state","西湖"); + sentMap.put("zip","20001"); + //创建信息 + System.out.println(sentMap); + //创建ArrayList对象 + List> fiendsList= new ArrayList<>(); + //查找friends对象 + personMap.put("friends",fiendsList); + //创建ObjectMapper对象 + String jsonStringFromMap= new ObjectMapper().writeValueAsString(personMap); + //创建完成并且生成数据 + System.out.println(jsonStringFromMap); + //创建张三的JSON对象信息 + JSONObject personJSON= new JSONObject(); + personJSON.put("name","张三"); + personJSON.put("age",25); + System.out.println(personJSON); + JSONObject addressJSON= new JSONObject(); + addressJSON.put("city","上海"); + addressJSON.put("zip","10001"); + addressJSON.put("state","奉贤"); + personJSON.put("address",addressJSON); + //创建李四的JSON对象的信息参数 + JSONObject fileJSON= new JSONObject(); + fileJSON.put("name","李四"); + fileJSON.put("age","27"); + System.out.println(fileJSON); + JSONObject endJSON= new JSONObject(); + endJSON.put("city","上海"); + endJSON.put("state","虹桥"); + endJSON.put("zip","10002"); + System.out.println(endJSON); + //创建王五的对象信息参数 + JSONObject hasJSON= new JSONObject(); + hasJSON.put("name","王五"); + hasJSON.put("age",24); + System.out.println(hasJSON); + JSONObject sentJSON= new JSONObject(); + sentJSON.put("city","杭州"); + sentJSON.put("state","西湖"); + sentJSON.put("zip","20001"); + System.out.println(sentJSON); + //调用张三对象的信息以及它的参数信息 + JSONArray friendsArray = new JSONArray(); + personJSON.put("friends", friendsArray); + System.out.println(personJSON.toString()); + //调用李四的对象的信息参数以及他的地址信息 + JSONArray friendArray = new JSONArray(); + fileJSON.put("friends",friendArray); + System.out.println(fileJSON.toString()); + //调用王五的参数信息对象以及他的地址信息 + JSONArray frientArray = new JSONArray(); + hasJSON.put("friends",frientArray); + System.out.println(hasJSON.toString()); + + //创建用户张三对象信息 + Main main = new Main(); + main.setId(1); + main.setName("张三"); + main.setAge(25); + main.setCity("上海"); + main.setState("奉贤"); + main.setZip("10001"); + System.out.println(main); + //创建用户李四的对象信息 + Main main1 = new Main(); + main1.setId(2); + main1.setName("李四"); + main1.setAge(27); + main1.setCity("上海"); + main1.setState("虹桥"); + main1.setZip("10002"); + System.out.println(main1); + //创建用户王五的对象信息 + Main main2 = new Main(); + main2.setId(3); + main2.setName("王五"); + main2.setAge(24); + main2.setCity("杭州"); + main2.setState("西湖"); + main2.setZip("20001"); + System.out.println(main2); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } +} diff --git a/modules/src/main/java/com/bw/config/BloomFilterUtil.java b/modules/src/main/java/com/bw/config/BloomFilterUtil.java new file mode 100644 index 0000000..147fdf5 --- /dev/null +++ b/modules/src/main/java/com/bw/config/BloomFilterUtil.java @@ -0,0 +1,72 @@ +package com.bw.config; + + +import org.springframework.stereotype.Component; + +import java.util.BitSet; + +/** + * @BelongsProject: month-10a + * @BelongsPackage: com.bw.config + * @Author: zhupengfei + * @CreateTime: 2023-03-09 14:44 + */ +@Component +public class BloomFilterUtil { + private static final int DEFAULT_SIZE = 2 << 24; // 布隆过滤器的比特长度 + private static final int[] seeds = new int[] {7, 11, 13, 31,37, 61}; // 这里要选取质数,能很好的降低错误率 + + private BitSet bits = new BitSet(DEFAULT_SIZE); + private SimpleHash[] func = new SimpleHash[seeds.length]; + +// public static void main(String[] args) { +// String value = "crankzcool@gmail.com"; +// BloomFilterUtil filter = new BloomFilterUtil(); +// System.out.println(filter.contains(value)); +// filter.add(value); +// System.out.println(filter.contains(value)); +// } + + public BloomFilterUtil() { + for (int i = 0; i < seeds.length; i++) { + func[i] = new SimpleHash(DEFAULT_SIZE, seeds[i]); + } + } + + public void add(String value) { + for (SimpleHash f: func) { + bits.set(f.hash(value), true); + } + } + + public boolean contains(String value) { + if (value == null) { + return false; + } + boolean ret = true; + for (SimpleHash f : func) { + ret = ret && bits.get(f.hash(value)); + } + return ret; + } + public static class SimpleHash { + private int cap; + private int seed; + + public SimpleHash(int cap, int seed) { + this.cap = cap; + this.seed = seed; + } + + public int hash(String value) { + int result = 0; + int len = value.length(); + for (int i = 0; i < len; i++) { + result = seed * result + value.charAt(i); + } + return (cap - 1) & result; + } + } + + +} diff --git a/modules/src/main/java/com/bw/config/FastConfig.java b/modules/src/main/java/com/bw/config/FastConfig.java new file mode 100644 index 0000000..34cfd90 --- /dev/null +++ b/modules/src/main/java/com/bw/config/FastConfig.java @@ -0,0 +1,20 @@ +package com.bw.config; + +import com.github.tobato.fastdfs.FdfsClientConfig; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableMBeanExport; +import org.springframework.context.annotation.Import; +import org.springframework.jmx.support.RegistrationPolicy; + +/** + * @BelongsProject: demo02 + * @BelongsPackage: com.bw.config + * @Author: zhupengfei + * @CreateTime: 2022-12-16 14:37 + */ +@Configuration +// 解决 jmx 重复注册 bean 的问题 +@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) +public class FastConfig { + +} diff --git a/modules/src/main/java/com/bw/config/FastUtil.java b/modules/src/main/java/com/bw/config/FastUtil.java new file mode 100644 index 0000000..8a09d65 --- /dev/null +++ b/modules/src/main/java/com/bw/config/FastUtil.java @@ -0,0 +1,56 @@ +package com.bw.config; + +import org.springframework.stereotype.Component; +import com.github.tobato.fastdfs.domain.fdfs.StorePath; +import com.github.tobato.fastdfs.service.FastFileStorageClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; + +/** + * @BelongsProject: 0107day02 + * @BelongsPackage: com.bw.config + * @Author: zhupengfei + * @CreateTime: 2023-02-01 08:52 + */ +@Component +public class FastUtil { + private static final Logger log = LoggerFactory.getLogger(FastUtil.class); + + @Resource + private FastFileStorageClient storageClient ; + + /** + * 上传文件 + */ + public String upload(MultipartFile multipartFile) throws Exception{ + String originalFilename = multipartFile.getOriginalFilename(). + substring(multipartFile.getOriginalFilename(). + lastIndexOf(".") + 1); + StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage( + multipartFile.getInputStream(), + multipartFile.getSize(),originalFilename , null); + return storePath.getFullPath() ; + } + /** + * 删除文件 + */ + public String deleteFile(String fileUrl) { + if (StringUtils.isEmpty(fileUrl)) { + log.info("fileUrl == >>文件路径为空..."); + return "文件路径不能为空"; + } + try { + StorePath storePath = StorePath.parseFromUrl(fileUrl); + storageClient.deleteFile(storePath.getGroup(), storePath.getPath()); + } catch (Exception e) { + log.error(e.getMessage()); + } + return "删除成功"; + } + +} diff --git a/modules/src/main/java/com/bw/config/Knife4jConfiguration.java b/modules/src/main/java/com/bw/config/Knife4jConfiguration.java new file mode 100644 index 0000000..e3c7da5 --- /dev/null +++ b/modules/src/main/java/com/bw/config/Knife4jConfiguration.java @@ -0,0 +1,45 @@ +package com.bw.config; + + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +/** + * @BelongsProject: demo02 + * @BelongsPackage: com.bw.handler + * @Author: zhupengfei + * @CreateTime: 2022-12-11 14:17 + */ +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfiguration { + + @Bean(value = "defaultApi2") + public Docket defaultApi2() { + Docket docket = new Docket(DocumentationType.SWAGGER_2) + .apiInfo(new ApiInfoBuilder() + .title("测试==demo") + .description("# swagger-bootstrap-ui-demo RESTful APIs") + .termsOfServiceUrl("http://www.xx.com/") + .contact(new Contact("玉面小白龙", "", "123@qq.com")) + .version("1.0") + .build()) + //分组名称 + .groupName("2.X版本") + .select() + //这里指定文档Controller层扫描包路径 + .apis(RequestHandlerSelectors.basePackage("com.bw.controller")) + .paths(PathSelectors.any()) + .build(); + return docket; + + } +} diff --git a/modules/src/main/java/com/bw/config/QuartzConfig.java b/modules/src/main/java/com/bw/config/QuartzConfig.java new file mode 100644 index 0000000..4aa520c --- /dev/null +++ b/modules/src/main/java/com/bw/config/QuartzConfig.java @@ -0,0 +1,38 @@ +//package com.bw.config; +// +//import com.bw.job.MyJob; +//import com.bw.job.MyJob2; +//import org.quartz.*; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +///** +// * @BelongsProject: demo02 +// * @BelongsPackage: com.bw.config +// * @Author: zhupengfei +// * @CreateTime: 2022-12-22 14:59 +// */ +////把当前类定义为 一个配置文件类 +//@Configuration +//public class QuartzConfig { +// @Bean +// public JobDetail downloadDetail() { +// return JobBuilder.newJob(MyJob.class) //具体任务类 +// .withIdentity("downloadJobDetail") +// .usingJobData("job_download","download movie") +// .storeDurably() +// .build(); +// } +// //构建 Trigger 及 Scheduler +// @Bean +// public Trigger downloadTrigger() { +// return TriggerBuilder.newTrigger() +// .forJob(downloadDetail()) //关联上面的 jobDetail +// .withIdentity("downloadTrigger") +// .usingJobData("trigger_download","download") +// //cron 表达式设置每隔 15 秒执行一次 +// .withSchedule(CronScheduleBuilder.cronSchedule("*/15 * * * * ?")) +// .build(); +// } +// +//} diff --git a/modules/src/main/java/com/bw/config/QuartzConfig2.java b/modules/src/main/java/com/bw/config/QuartzConfig2.java new file mode 100644 index 0000000..4b8741a --- /dev/null +++ b/modules/src/main/java/com/bw/config/QuartzConfig2.java @@ -0,0 +1,38 @@ +//package com.bw.config; +// +//import com.bw.job.MyJob; +//import com.bw.job.MyJob2; +//import org.quartz.*; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +// +///** +// * @BelongsProject: demo02 +// * @BelongsPackage: com.bw.config +// * @Author: zhupengfei +// * @CreateTime: 2022-12-22 14:59 +// */ +////把当前类定义为 一个配置文件类 +//@Configuration +//public class QuartzConfig2 { +// @Bean +// public JobDetail downloadDetail2() { +// return JobBuilder.newJob(MyJob2.class) //具体任务类 +// .withIdentity("downloadJobDetail2") +// .usingJobData("job_download","download movie") +// .storeDurably() +// .build(); +// } +// //构建 Trigger 及 Scheduler +// @Bean +// public Trigger downloadTrigger2() { +// return TriggerBuilder.newTrigger() +// .forJob(downloadDetail2()) //关联上面的 jobDetail +// .withIdentity("downloadTrigger2") +// .usingJobData("trigger_download","download") +// //cron 表达式设置每隔 5 秒执行一次 +// .withSchedule(CronScheduleBuilder.cronSchedule("*/30 * * * * ?")) +// .build(); +// } +// +//} diff --git a/modules/src/main/java/com/bw/config/RedisConfig.java b/modules/src/main/java/com/bw/config/RedisConfig.java new file mode 100644 index 0000000..851b886 --- /dev/null +++ b/modules/src/main/java/com/bw/config/RedisConfig.java @@ -0,0 +1,43 @@ +package com.bw.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +public class RedisConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + + + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(factory); + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new + Jackson2JsonRedisSerializer(Object.class); + + ObjectMapper om = new ObjectMapper(); + om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); + jackson2JsonRedisSerializer.setObjectMapper(om); + + StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); + // key采用String的序列化方式 + template.setKeySerializer(stringRedisSerializer); + // hash的key也采用String的序列化方式 + template.setHashKeySerializer(stringRedisSerializer); + // value序列化方式采用jackson + template.setValueSerializer(jackson2JsonRedisSerializer); + // hash的value序列化方式采用jackson + template.setHashValueSerializer(jackson2JsonRedisSerializer); + template.afterPropertiesSet(); + + return template; + } +} diff --git a/modules/src/main/java/com/bw/config/RedissonConfig.java b/modules/src/main/java/com/bw/config/RedissonConfig.java new file mode 100644 index 0000000..a9264ba --- /dev/null +++ b/modules/src/main/java/com/bw/config/RedissonConfig.java @@ -0,0 +1,33 @@ +package com.bw.config; + +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.config.Config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.io.IOException; + +/** + * @BelongsProject: demo02 + * @BelongsPackage: com.bw.config + * @Author: zhupengfei + * @CreateTime: 2022-12-24 09:26 + */ + +@Configuration +public class RedissonConfig { + + @Bean(destroyMethod="shutdown") // 服务停止后调用 shutdown 方法。 + public RedissonClient redisson() throws IOException { + System.out.println("配置类初始加载......"); + // 1.创建配置 + Config config = new Config(); + // 集群模式 + // config.useClusterServers().addNodeAddress("127.0.0.1:6379", "127.0.0.1:6378"); + // 2.根据 Config 创建出 RedissonClient 实例。 + config.useSingleServer().setAddress("redis://127.0.0.1:6379"); + return Redisson.create(config); + } + +} diff --git a/modules/src/main/java/com/bw/config/WebMvcConfig.java b/modules/src/main/java/com/bw/config/WebMvcConfig.java new file mode 100644 index 0000000..8f8f598 --- /dev/null +++ b/modules/src/main/java/com/bw/config/WebMvcConfig.java @@ -0,0 +1,67 @@ +//package com.bw.config; +// +//import com.bw.interceptor.MyInterceptor; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.web.cors.CorsConfiguration; +//import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +//import org.springframework.web.filter.CorsFilter; +//import org.springframework.web.servlet.config.annotation.CorsRegistry; +//import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +//import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +// +///** +// * @BelongsProject: 0107day02 +// * @BelongsPackage: com.bw.config +// * @Author: zhupengfei +// * @CreateTime: 2023-02-01 08:51 +// */ +//@Configuration +//public class WebMvcConfig implements WebMvcConfigurer { +// +// @Autowired +// private MyInterceptor myIntercepter; +// //全局路由 +// @Override +// public void addCorsMappings(CorsRegistry registry) { +// registry.addMapping("/**") +// //.allowedOrigins("*") //注意这个变动项,这个是旧版 +// .allowedOriginPatterns("*")//这个才是新版的要求 +// .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS") +// .allowCredentials(true) +// .maxAge(3600) +// .allowedHeaders("*"); +// } +// +// +// /** +// * 静态资源 +// * @author: zhupengfei +// * @param: [registry] +// * @return: void +// **/ +// @Override +// public void addResourceHandlers(ResourceHandlerRegistry registry) { +// registry +// .addResourceHandler("/static/**") +// .addResourceLocations("classpath:/static/"); +// } +// +// /** +// * 拦截器 +// * @author: zhupengfei +// * @param: [registry] +// * @return: void +// **/ +// +// @Override +// public void addInterceptors(InterceptorRegistry registry) { +// registry.addInterceptor(myIntercepter) +// .addPathPatterns("/**") +// .excludePathPatterns("/admin/*","/admin/*/*" +// ,"/doc.html","/swagger-resources" +// ); +// } +//} diff --git a/modules/src/main/java/com/bw/controller/GetailsController.java b/modules/src/main/java/com/bw/controller/GetailsController.java new file mode 100644 index 0000000..678abcc --- /dev/null +++ b/modules/src/main/java/com/bw/controller/GetailsController.java @@ -0,0 +1,21 @@ +package com.bw.controller; + +import com.bw.service.GetailsService; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/getails") +public class GetailsController { + @Autowired + private GetailsService getailsService; + + + @PostMapping("/GetailsList") + public R GetailsList(){ + return getailsService.GetailsList(); + } +} diff --git a/modules/src/main/java/com/bw/controller/StortController.java b/modules/src/main/java/com/bw/controller/StortController.java new file mode 100644 index 0000000..406233f --- /dev/null +++ b/modules/src/main/java/com/bw/controller/StortController.java @@ -0,0 +1,20 @@ +package com.bw.controller; + +import com.bw.service.StortService; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/stort") +public class StortController { + @Autowired + private StortService stortService; + + @PostMapping("/StortList") + public R StortList(){ + return stortService.StortList(); + } +} diff --git a/modules/src/main/java/com/bw/controller/StudentController.java b/modules/src/main/java/com/bw/controller/StudentController.java new file mode 100644 index 0000000..dd74e41 --- /dev/null +++ b/modules/src/main/java/com/bw/controller/StudentController.java @@ -0,0 +1,31 @@ +package com.bw.controller; + +import com.bw.service.StudentService; +import com.bwie.Student; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/student") +public class StudentController { + @Autowired + private StudentService studentService; + //查询 + @PostMapping("/StudentList") + public R StudentList(){ + return studentService.StudentList(); + } + //添加 + @PostMapping("/add") + public R add(@RequestBody Student student){ + return studentService.add(student); + } + //删除 + @PostMapping("/delect") + public R select(@PathVariable Integer id){ + return studentService.delect(id); + } + + +} diff --git a/modules/src/main/java/com/bw/controller/UserController.java b/modules/src/main/java/com/bw/controller/UserController.java new file mode 100644 index 0000000..52ee74e --- /dev/null +++ b/modules/src/main/java/com/bw/controller/UserController.java @@ -0,0 +1,27 @@ +package com.bw.controller; + +import com.bw.service.UserService; +import com.bwie.pojo.User; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/user") +public class UserController { + @Autowired + private UserService userService; + @PostMapping("/UserList") + public R UserList(){ + return userService.UserList(); + } + @PostMapping("/login") + public R login(@RequestBody User user){ + return userService.login(user); + } + + +} diff --git a/modules/src/main/java/com/bw/dao/GetailsDao.java b/modules/src/main/java/com/bw/dao/GetailsDao.java new file mode 100644 index 0000000..e765cac --- /dev/null +++ b/modules/src/main/java/com/bw/dao/GetailsDao.java @@ -0,0 +1,11 @@ +package com.bw.dao; + +import com.bwie.pojo.Details; + +import java.util.List; + +public interface GetailsDao { + + + List
GetailsList(); +} diff --git a/modules/src/main/java/com/bw/dao/StortDao.java b/modules/src/main/java/com/bw/dao/StortDao.java new file mode 100644 index 0000000..a41c7b1 --- /dev/null +++ b/modules/src/main/java/com/bw/dao/StortDao.java @@ -0,0 +1,10 @@ +package com.bw.dao; + +import com.bwie.pojo.Stort; + +import java.util.List; + +public interface StortDao { + + List StortList(); +} diff --git a/modules/src/main/java/com/bw/dao/StudentDao.java b/modules/src/main/java/com/bw/dao/StudentDao.java new file mode 100644 index 0000000..810a3cd --- /dev/null +++ b/modules/src/main/java/com/bw/dao/StudentDao.java @@ -0,0 +1,14 @@ +package com.bw.dao; + +import com.bwie.Student; + +import java.util.List; + +public interface StudentDao { + List StudentList(); + + int add(Student student); + + int delect(Integer id); + +} diff --git a/modules/src/main/java/com/bw/dao/UserDao.java b/modules/src/main/java/com/bw/dao/UserDao.java new file mode 100644 index 0000000..dc991de --- /dev/null +++ b/modules/src/main/java/com/bw/dao/UserDao.java @@ -0,0 +1,13 @@ +package com.bw.dao; + +import com.bwie.pojo.User; + +import java.util.List; + +public interface UserDao { + User login(User user); + + + List UserList(); + +} diff --git a/modules/src/main/java/com/bw/service/GetailsService.java b/modules/src/main/java/com/bw/service/GetailsService.java new file mode 100644 index 0000000..07b83fd --- /dev/null +++ b/modules/src/main/java/com/bw/service/GetailsService.java @@ -0,0 +1,9 @@ +package com.bw.service; + +import com.bwie.pojo.util.R; + +public interface GetailsService { + + + R GetailsList(); +} diff --git a/modules/src/main/java/com/bw/service/StortService.java b/modules/src/main/java/com/bw/service/StortService.java new file mode 100644 index 0000000..5d6ae20 --- /dev/null +++ b/modules/src/main/java/com/bw/service/StortService.java @@ -0,0 +1,9 @@ +package com.bw.service; + +import com.bwie.pojo.util.R; + +public interface StortService { + + + R StortList(); +} diff --git a/modules/src/main/java/com/bw/service/StudentService.java b/modules/src/main/java/com/bw/service/StudentService.java new file mode 100644 index 0000000..37e805e --- /dev/null +++ b/modules/src/main/java/com/bw/service/StudentService.java @@ -0,0 +1,12 @@ +package com.bw.service; + +import com.bwie.Student; +import com.bwie.pojo.util.R; + +public interface StudentService { + R StudentList(); + + R add(Student student); + + R delect(Integer id); +} diff --git a/modules/src/main/java/com/bw/service/UserService.java b/modules/src/main/java/com/bw/service/UserService.java new file mode 100644 index 0000000..aae8d97 --- /dev/null +++ b/modules/src/main/java/com/bw/service/UserService.java @@ -0,0 +1,12 @@ +package com.bw.service; + +import com.bwie.pojo.User; +import com.bwie.pojo.util.R; + +public interface UserService { + R login(User user); + + + R UserList(); + +} diff --git a/modules/src/main/java/com/bw/service/impl/GetailsServiceImpl.java b/modules/src/main/java/com/bw/service/impl/GetailsServiceImpl.java new file mode 100644 index 0000000..b79762c --- /dev/null +++ b/modules/src/main/java/com/bw/service/impl/GetailsServiceImpl.java @@ -0,0 +1,22 @@ +package com.bw.service.impl; + +import com.bw.dao.GetailsDao; +import com.bw.service.GetailsService; +import com.bwie.pojo.Details; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class GetailsServiceImpl implements GetailsService { + @Autowired + private GetailsDao getailsDao; + + @Override + public R GetailsList() { + List
list=getailsDao.GetailsList(); + return new R(200,list,"成功"); + } +} diff --git a/modules/src/main/java/com/bw/service/impl/StortServiceImpl.java b/modules/src/main/java/com/bw/service/impl/StortServiceImpl.java new file mode 100644 index 0000000..9c40cc9 --- /dev/null +++ b/modules/src/main/java/com/bw/service/impl/StortServiceImpl.java @@ -0,0 +1,23 @@ +package com.bw.service.impl; + +import com.bw.dao.StortDao; +import com.bw.service.StortService; +import com.bwie.pojo.Stort; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class StortServiceImpl implements StortService { + @Autowired + private StortDao stortDao; + + + @Override + public R StortList() { + List list=stortDao.StortList(); + return new R(200,list,"成功"); + } +} diff --git a/modules/src/main/java/com/bw/service/impl/StudentServiceImpl.java b/modules/src/main/java/com/bw/service/impl/StudentServiceImpl.java new file mode 100644 index 0000000..c44dcc0 --- /dev/null +++ b/modules/src/main/java/com/bw/service/impl/StudentServiceImpl.java @@ -0,0 +1,36 @@ +package com.bw.service.impl; + +import com.bw.dao.StudentDao; +import com.bw.service.StudentService; +import com.bwie.Student; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class StudentServiceImpl implements StudentService { + @Autowired + private StudentDao studentDao; + @Override + public R StudentList() { + List list=studentDao.StudentList(); + return new R(200,list,"成功"); + } + + @Override + public R add(Student student) { + if(student.getId()!=null && student.getId()<0){ + int i=studentDao.add(student); + return new R(i>0?200:500,i>0?"添加成功":"添加失败"); + } + return null; + } + + @Override + public R delect(Integer id) { + int i=studentDao.delect(id); + return new R(i>0?200:500,i>0?"删除成功":"删除失败"); + } +} diff --git a/modules/src/main/java/com/bw/service/impl/UserServiceImpl.java b/modules/src/main/java/com/bw/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..a47a65d --- /dev/null +++ b/modules/src/main/java/com/bw/service/impl/UserServiceImpl.java @@ -0,0 +1,35 @@ +package com.bw.service.impl; + +import com.bw.dao.UserDao; +import com.bw.service.UserService; +import com.bwie.pojo.User; +import com.bwie.pojo.util.R; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class UserServiceImpl implements UserService { + @Autowired + private UserDao userDao; + @Override + public R login(User user) { + User user1=userDao.login(user); + if(user1==null){ + return new R(500,"登录失败"); + } + if(user1!=null){ + return new R(200,user1,"登录成功"); + } + return new R(500,"密码错误"); + } + + @Override + public R UserList() { + List list=userDao.UserList(); + return new R(200,list,"成功"); + } + + +} diff --git a/modules/src/main/java/com/bw/util/AliyunOssConfig.java b/modules/src/main/java/com/bw/util/AliyunOssConfig.java new file mode 100644 index 0000000..5f75fab --- /dev/null +++ b/modules/src/main/java/com/bw/util/AliyunOssConfig.java @@ -0,0 +1,32 @@ +package com.bw.util; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AliyunOssConfig { + + @Value("${aliyun.end-point}") + private String endPoint; + + + @Value("${aliyun.access-key-id}") + private String accessKeyId; + + @Value("${aliyun.access-key-secret}") + private String accesskeySecret; + + @Value("${aliyun.access-pre}") + private String accessPre; + + @Value("${aliyun.bucket-name}") + private String bucketName; + + + + public OSS getOssClient(){ + return new OSSClientBuilder().build(endPoint, accessKeyId, accesskeySecret); + } +} diff --git a/modules/src/main/java/com/bw/util/HttpPost.java b/modules/src/main/java/com/bw/util/HttpPost.java new file mode 100644 index 0000000..b022db6 --- /dev/null +++ b/modules/src/main/java/com/bw/util/HttpPost.java @@ -0,0 +1,74 @@ +package com.bw.util; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.*; +import java.util.Map.Entry; + +public class HttpPost { + public static void main(String[] args) { + //你的本地地址 配你的项目地址 这个是我电脑本地的地址 + String doGet = doGet("http://127.0.0.1:8081/sell/list"); + System.out.println("----------SSSS---DDS--S--"+doGet); + } + public static String doGet(String httpUrl){ + //链接 + HttpURLConnection connection=null; + + InputStream is=null; + BufferedReader br = null; + StringBuffer result=new StringBuffer(); + try { + //创建连接 + URL url=new URL(httpUrl); + connection= (HttpURLConnection) url.openConnection(); + //设置请求方式 + connection.setRequestMethod("GET"); + //设置连接超时时间 + connection.setConnectTimeout(15000); + //设置读取超时时间 + connection.setReadTimeout(15000); + + //开始连接 + connection.connect(); + //获取响应数据 + if(connection.getResponseCode()==200){ + //获取返回的数据 + is=connection.getInputStream(); + if(is!=null){ + br=new BufferedReader(new InputStreamReader(is,"UTF-8")); + String temp = null; + while ((temp=br.readLine())!=null){ + result.append(temp); + } + } + } + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + }finally { + if(br!=null){ + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(is!=null){ + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + connection.disconnect();// 关闭远程连接 + } + return result.toString(); + } + + + +} diff --git a/modules/src/main/java/com/bw/util/HttpUtils.java b/modules/src/main/java/com/bw/util/HttpUtils.java new file mode 100644 index 0000000..fd9fc44 --- /dev/null +++ b/modules/src/main/java/com/bw/util/HttpUtils.java @@ -0,0 +1,311 @@ +package com.bw.util; + +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicNameValuePair; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class HttpUtils { + + /** + * get + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doGet(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpGet request = new HttpGet(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + /** + * post form + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param bodys + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + Map bodys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (bodys != null) { + List nameValuePairList = new ArrayList(); + + for (String key : bodys.keySet()) { + nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); + } + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); + formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); + request.setEntity(formEntity); + } + + return httpClient.execute(request); + } + + /** + * Post String + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Post stream + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Put String + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Put stream + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Delete + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doDelete(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + private static String buildUrl(String host, String path, Map querys) throws UnsupportedEncodingException { + StringBuilder sbUrl = new StringBuilder(); + sbUrl.append(host); + if (!StringUtils.isBlank(path)) { + sbUrl.append(path); + } + if (null != querys) { + StringBuilder sbQuery = new StringBuilder(); + for (Map.Entry query : querys.entrySet()) { + if (0 < sbQuery.length()) { + sbQuery.append("&"); + } + if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { + sbQuery.append(query.getValue()); + } + if (!StringUtils.isBlank(query.getKey())) { + sbQuery.append(query.getKey()); + if (!StringUtils.isBlank(query.getValue())) { + sbQuery.append("="); + sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); + } + } + } + if (0 < sbQuery.length()) { + sbUrl.append("?").append(sbQuery); + } + } + + return sbUrl.toString(); + } + + private static HttpClient wrapClient(String host) { + HttpClient httpClient = new DefaultHttpClient(); + if (host.startsWith("https://")) { + sslClient(httpClient); + } + + return httpClient; + } + + private static void sslClient(HttpClient httpClient) { + try { + SSLContext ctx = SSLContext.getInstance("TLS"); + X509TrustManager tm = new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted(X509Certificate[] xcs, String str) { + + } + public void checkServerTrusted(X509Certificate[] xcs, String str) { + + } + }; + ctx.init(null, new TrustManager[] { tm }, null); + SSLSocketFactory ssf = new SSLSocketFactory(ctx); + ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + ClientConnectionManager ccm = httpClient.getConnectionManager(); + SchemeRegistry registry = ccm.getSchemeRegistry(); + registry.register(new Scheme("https", 443, ssf)); + } catch (KeyManagementException ex) { + throw new RuntimeException(ex); + } catch (NoSuchAlgorithmException ex) { + throw new RuntimeException(ex); + } + } +} \ No newline at end of file diff --git a/modules/src/main/java/com/bw/util/ImageVerificationCode.java b/modules/src/main/java/com/bw/util/ImageVerificationCode.java new file mode 100644 index 0000000..c94c996 --- /dev/null +++ b/modules/src/main/java/com/bw/util/ImageVerificationCode.java @@ -0,0 +1,137 @@ +package com.bw.util; + +import org.springframework.stereotype.Component; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Random; + +import javax.imageio.ImageIO; + + +public class ImageVerificationCode { + + private int weight = 100; //验证码图片的长和宽 + private int height = 40; + private String text; //用来保存验证码的文本内容 + private Random r = new Random(); //获取随机数对象 + //private String[] fontNames = {"宋体", "华文楷体", "黑体", "微软雅黑", "楷体_GB2312"}; //字体数组 + //字体数组 + private String[] fontNames = {"Georgia"}; + //验证码数组 + // private String codes = "23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ"; + private String codes = "123456780"; + /** + * 获取随机的颜色 + * + * @return + */ + private Color randomColor() { + int r = this.r.nextInt(225); //这里为什么是225,因为当r,g,b都为255时,即为白色,为了好辨认,需要颜色深一点。 + int g = this.r.nextInt(225); + int b = this.r.nextInt(225); + return new Color(r, g, b); //返回一个随机颜色 + } + + /** + * 获取随机字体 + * + * @return + */ + private Font randomFont() { + int index = r.nextInt(fontNames.length); //获取随机的字体 + String fontName = fontNames[index]; + int style = r.nextInt(4); //随机获取字体的样式,0是无样式,1是加粗,2是斜体,3是加粗加斜体 + int size = r.nextInt(10) + 24; //随机获取字体的大小 + return new Font(fontName, style, size); //返回一个随机的字体 + } + + /** + * 获取随机字符 + * + * @return + */ + private char randomChar() { + int index = r.nextInt(codes.length()); + return codes.charAt(index); + } + + /** + * 画干扰线,验证码干扰线用来防止计算机解析图片 + * + * @param image + */ + private void drawLine(BufferedImage image) { + int num = r.nextInt(10); //定义干扰线的数量 + Graphics2D g = (Graphics2D) image.getGraphics(); + for (int i = 0; i < num; i++) { + int x1 = r.nextInt(weight); + int y1 = r.nextInt(height); + int x2 = r.nextInt(weight); + int y2 = r.nextInt(height); + g.setColor(randomColor()); + g.drawLine(x1, y1, x2, y2); + } + } + + /** + * 创建图片的方法 + * + * @return + */ + private BufferedImage createImage() { + //创建图片缓冲区 + BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB); + //获取画笔 + Graphics2D g = (Graphics2D) image.getGraphics(); + //设置背景色随机 + g.setColor(new Color(255, 255, r.nextInt(245) + 10)); + g.fillRect(0, 0, weight, height); + //返回一个图片 + return image; + } + + /** + * 获取验证码图片的方法 + * + * @return + */ + public BufferedImage getImage() { + BufferedImage image = createImage(); + Graphics2D g = (Graphics2D) image.getGraphics(); //获取画笔 + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 4; i++) //画四个字符即可 + { + String s = randomChar() + ""; //随机生成字符,因为只有画字符串的方法,没有画字符的方法,所以需要将字符变成字符串再画 + sb.append(s); //添加到StringBuilder里面 + float x = i * 1.0F * weight / 4; //定义字符的x坐标 + g.setFont(randomFont()); //设置字体,随机 + g.setColor(randomColor()); //设置颜色,随机 + g.drawString(s, x, height - 5); + } + this.text = sb.toString(); + drawLine(image); + return image; + } + + /** + * 获取验证码文本的方法 + * + * @return + */ + public String getText() { + return text; + } + + public static void output(BufferedImage image, OutputStream out) throws IOException //将验证码图片写出的方法 + { + ImageIO.write(image, "JPEG", out); + } + +} diff --git a/modules/src/main/java/com/bw/util/JwtConstants.java b/modules/src/main/java/com/bw/util/JwtConstants.java new file mode 100644 index 0000000..c86144b --- /dev/null +++ b/modules/src/main/java/com/bw/util/JwtConstants.java @@ -0,0 +1,34 @@ +package com.bw.util; + +public class JwtConstants { + /** + * 用户ID字段 + */ + public static final String DETAILS_USER_ID = "user_id"; + + /** + * 用户名字段 + */ + public static final String DETAILS_USERNAME = "user_name"; + + /** + * 用户标识 + */ + public static final String USER_KEY = "user_key"; + + /** + * 令牌秘钥 + */ + public final static String SECRET = "abcdefghijklmnopqrstuvwxyz"; + + /** + * 手机 + */ + public static final String USER_PHONE = "user_phone"; + + + /** + * 用户token 的键的前缀 + */ + public static final String LOGIN_TOKEN = "login_token:"; +} diff --git a/modules/src/main/java/com/bw/util/JwtUtils.java b/modules/src/main/java/com/bw/util/JwtUtils.java new file mode 100644 index 0000000..1869f81 --- /dev/null +++ b/modules/src/main/java/com/bw/util/JwtUtils.java @@ -0,0 +1,108 @@ +package com.bw.util; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import java.util.Map; + +/** + * @description: Jwt工具类 + * @author DongZl + */ +public class JwtUtils { + + /** + * 秘钥 + */ + public static String secret = JwtConstants.SECRET; + + /** + * 从数据声明生成令牌 + * + * @param claims 数据声明 + * @return 令牌 + */ + public static String createToken(Map claims){ + String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); + return token; + } + + /** + * 从令牌中获取数据声明 + * + * @param token 令牌 + * @return 数据声明 + */ + public static Claims parseToken(String token){ + return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); + } + /** + * 根据令牌获取用户标识 + * + * @param token 令牌 + * @return 用户ID + */ + public static String getUserKey(String token){ + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.USER_KEY); + } + /** + * 根据令牌获取用户标识 + * + * @param claims 身份信息 + * @return 用户ID + */ + public static String getUserKey(Claims claims){ + return getValue(claims, JwtConstants.USER_KEY); + } + /** + * 根据令牌获取用户ID + * + * @param token 令牌 + * @return 用户ID + */ + public static String getUserId(String token){ + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.DETAILS_USER_ID); + } + /** + * 根据身份信息获取用户ID + * + * @param claims 身份信息 + * @return 用户ID + */ + public static String getUserId(Claims claims){ + return getValue(claims, JwtConstants.DETAILS_USER_ID); + } + /** + * 根据令牌获取用户名 + * + * @param token 令牌 + * @return 用户名 + */ + public static String getUserName(String token){ + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.DETAILS_USERNAME); + } + /** + * 根据身份信息获取用户名 + * + * @param claims 身份信息 + * @return 用户名 + */ + public static String getUserName(Claims claims){ + return getValue(claims, JwtConstants.DETAILS_USERNAME); + } + /** + * 根据身份信息获取键值 + * + * @param claims 身份信息 + * @param key 键 + * @return 值 + */ + public static String getValue(Claims claims, String key){ + Object obj = claims.get(key); + return obj == null ? "" : obj.toString(); + } +} diff --git a/modules/src/main/java/com/bw/util/Md5Utils.java b/modules/src/main/java/com/bw/util/Md5Utils.java new file mode 100644 index 0000000..82ddb8c --- /dev/null +++ b/modules/src/main/java/com/bw/util/Md5Utils.java @@ -0,0 +1,55 @@ +package com.bw.util; + +import java.security.MessageDigest; + +/** + * MD5工具类 + * @author 高州 + */ +public class Md5Utils { + /** + * 生成32位md5 + * + * @param str + * @return + */ + public static String string2Md5(String str) { + try { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + char[] charArray = str.toCharArray(); + byte[] byteArray = new byte[charArray.length]; + for (int i = 0; i < charArray.length; i++) { + byteArray[i] = (byte) charArray[i]; + } + byte[] md5Bytes = md5.digest(byteArray); + StringBuffer hexValue = new StringBuffer(); + for (int i = 0; i < md5Bytes.length; i++) { + int val = ((int) md5Bytes[i]) & 0xff; + if (val < 16) { + hexValue.append("0"); + } + hexValue.append(Integer.toHexString(val)); + } + return hexValue.toString(); + } catch (Exception e) { + e.printStackTrace(); + return ""; + } + } + + public static void main(String[] args) { + String md5 = string2Md5("111"); + System.out.println(md5); + } + + /** + * 生成16位md5 + * + * @param str + * @return + */ + public static String string2Md5_16(String str) { + String md5 = string2Md5(str); + return md5.substring(8, 24); + } +} diff --git a/modules/src/main/java/com/bw/util/MsgUtil.java b/modules/src/main/java/com/bw/util/MsgUtil.java new file mode 100644 index 0000000..0f67d30 --- /dev/null +++ b/modules/src/main/java/com/bw/util/MsgUtil.java @@ -0,0 +1,40 @@ +package com.bw.util; + + +import org.apache.http.HttpResponse; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author + * @version 1.0.0 + * @ClassName MsgUtil.java + * @Description TODO + * @createTime 2022年05月26日 15:49:00 + */ +public class MsgUtil { + + + public static void sendMsg(String phone,String code){ + String host = "http://dingxin.market.alicloudapi.com"; + String path = "/dx/sendSms"; + String method = "POST"; + String appcode = "dcb3dabebd3843a7a138901659ed112a"; + Map headers = new HashMap(); + headers.put("Authorization", "APPCODE " + appcode); + Map querys = new HashMap(); + querys.put("mobile", phone); + querys.put("param", "code:"+code); + querys.put("tpl_id", "TP1711063"); + Map bodys = new HashMap(); + + try { + + HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); + System.out.println(response.toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/modules/src/main/java/com/bw/util/core/date/DateUtils.java b/modules/src/main/java/com/bw/util/core/date/DateUtils.java new file mode 100644 index 0000000..9fd5e54 --- /dev/null +++ b/modules/src/main/java/com/bw/util/core/date/DateUtils.java @@ -0,0 +1,137 @@ +package com.bw.util.core.date; + +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.io.File; +import java.lang.management.ManagementFactory; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 时间工具类 + * + * @author markGuo + */ +public class DateUtils extends org.apache.commons.lang3.time.DateUtils +{ + public static String YYYY = "yyyy"; + + public static String YYYY_MM = "yyyy-MM"; + + public static String YYYY_MM_DD = "yyyy-MM-dd"; + + public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; + + public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + + private static String[] parsePatterns = { + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", + "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", + "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; + + /** + * 获取当前Date型日期 + * + * @return Date() 当前日期 + */ + public static Date getNowDate() { + return new Date(); + } + + /** + * 获取当前日期, 默认格式为yyyy-MM-dd + * + * @return String + */ + public static String getDate() { + return dateTimeNow(YYYY_MM_DD); + } + + public static final String getTime() { + return dateTimeNow(YYYY_MM_DD_HH_MM_SS); + } + + public static final String dateTimeNow() { + return dateTimeNow(YYYYMMDDHHMMSS); + } + + public static final String dateTimeNow(final String format) { + return parseDateToStr(format, new Date()); + } + + public static final String dateTime(final Date date) { + return parseDateToStr(YYYY_MM_DD, date); + } + + public static final String parseDateToStr(final String format, final Date date) { + return new SimpleDateFormat(format).format(date); + } + + public static final Date dateTime(final String format, final String ts) { + try { + return new SimpleDateFormat(format).parse(ts); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + /** + * 日期路径 即年/月/日 如2018/08/08 + */ + public static final String datePath() { + Date now = new Date(); + return DateFormatUtils.format(now, "yyyy"+File.separator+"MM"+ File.separator +"dd"); + } + + /** + * 日期路径 即年/月/日 如20180808 + */ + public static final String dateTime() { + Date now = new Date(); + return DateFormatUtils.format(now, "yyyyMMdd"); + } + + /** + * 日期型字符串转化为日期 格式 + */ + public static Date parseDate(Object str) { + if (str == null) { + return null; + } + try { + return parseDate(str.toString(), parsePatterns); + } catch (ParseException e) { + return null; + } + } + + /** + * 获取服务器启动时间 + */ + public static Date getServerStartDate() { + long time = ManagementFactory.getRuntimeMXBean().getStartTime(); + return new Date(time); + } + + /** + * 计算两个时间差 + */ + public static String getDatePoor(Date endDate, Date nowDate) { + long nd = 1000 * 24 * 60 * 60; + long nh = 1000 * 60 * 60; + long nm = 1000 * 60; + // long ns = 1000; + // 获得两个时间的毫秒时间差异 + long diff = endDate.getTime() - nowDate.getTime(); + // 计算差多少天 + long day = diff / nd; + // 计算差多少小时 + long hour = diff % nd / nh; + // 计算差多少分钟 + long min = diff % nd % nh / nm; + // 计算差多少秒//输出结果 + // long sec = diff % nd % nh % nm / ns; + return day + "天" + hour + "小时" + min + "分钟"; + } +} diff --git a/modules/src/main/java/com/bw/util/core/reflect/ReflectUtils.java b/modules/src/main/java/com/bw/util/core/reflect/ReflectUtils.java new file mode 100644 index 0000000..98dda94 --- /dev/null +++ b/modules/src/main/java/com/bw/util/core/reflect/ReflectUtils.java @@ -0,0 +1,386 @@ +package com.bw.util.core.reflect; + +import com.bw.util.core.date.DateUtils; +import com.bw.util.core.text.Convert; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.*; +import java.util.Date; + +/** + * 反射工具类. 提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class, 被AOP过的真实类等工具函数. + * + * @author markGuo + */ +@SuppressWarnings("rawtypes") +public class ReflectUtils { + /** + * set方法前缀 + */ + private static final String SETTER_PREFIX = "set"; + + /** + * get方法前缀 + */ + private static final String GETTER_PREFIX = "get"; + + /** + * CGLIB 类分隔符 + */ + private static final String CGLIB_CLASS_SEPARATOR = "$$"; + + /** + * 日志 + */ + private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class); + + /** + * 调用Getter方法. + * 支持多级,如:对象名.对象名.方法 + * @param obj + * @param propertyName + * @param + * @return + */ + @SuppressWarnings("unchecked") + public static E invokeGetter(Object obj, String propertyName) { + Object object = obj; + for (String name : StringUtils.split(propertyName, ".")) { + String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name); + object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); + } + return (E) object; + } + + /** + * 调用Setter方法, 仅匹配方法名。 + * 支持多级,如:对象名.对象名.方法 + * @param obj + * @param propertyName + * @param value + * @param + */ + public static void invokeSetter(Object obj, String propertyName, E value) { + Object object = obj; + String[] names = StringUtils.split(propertyName, "."); + for (int i = 0; i < names.length; i++) { + if (i < names.length - 1) { + String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(names[i]); + object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {}); + } else { + String setterMethodName = SETTER_PREFIX + StringUtils.capitalize(names[i]); + invokeMethodByName(object, setterMethodName, new Object[] { value }); + } + } + } + + /** + * 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数. + * @param obj + * @param fieldName + * @param + * @return + */ + @SuppressWarnings("unchecked") + public static E getFieldValue(final Object obj, final String fieldName) { + Field field = getAccessibleField(obj, fieldName); + if (field == null) { + logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); + return null; + } + E result = null; + try { + result = (E) field.get(obj); + } catch (IllegalAccessException e) { + logger.error("不可能抛出的异常{}", e.getMessage()); + } + return result; + } + + /** + * 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数. + * @param obj + * @param fieldName + * @param value + * @param + */ + public static void setFieldValue(final Object obj, final String fieldName, final E value) { + Field field = getAccessibleField(obj, fieldName); + if (field == null) { + // throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); + logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); + return; + } + try { + field.set(obj, value); + } catch (IllegalAccessException e) { + logger.error("不可能抛出的异常: {}", e.getMessage()); + } + } + + /** + * 直接调用对象方法, 无视private/protected修饰符. + * 用于一次性调用的情况,否则应使用getAccessibleMethod()函数获得Method后反复调用. + * 同时匹配方法名+参数类型, + * @param obj + * @param methodName + * @param parameterTypes + * @param args + * @param + * @return + */ + @SuppressWarnings("unchecked") + public static E invokeMethod(final Object obj, final String methodName, final Class[] parameterTypes, + final Object[] args) { + if (obj == null || methodName == null) { + return null; + } + Method method = getAccessibleMethod(obj, methodName, parameterTypes); + if (method == null) { + logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); + return null; + } + try { + return (E) method.invoke(obj, args); + } catch (Exception e) { + String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; + throw convertReflectionExceptionToUnchecked(msg, e); + } + } + + /** + * 直接调用对象方法, 无视private/protected修饰符, + * 用于一次性调用的情况,否则应使用getAccessibleMethodByName()函数获得Method后反复调用. + * 只匹配函数名,如果有多个同名函数调用第一个。 + * @param obj + * @param methodName + * @param args + * @param + * @return + */ + @SuppressWarnings("unchecked") + public static E invokeMethodByName(final Object obj, final String methodName, final Object[] args) { + Method method = getAccessibleMethodByName(obj, methodName, args.length); + if (method == null) { + // 如果为空不报错,直接返回空。 + logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); + return null; + } + try { + // 类型转换(将参数数据类型转换为目标方法参数类型) + Class[] cs = method.getParameterTypes(); + for (int i = 0; i < cs.length; i++) { + if (args[i] != null && !args[i].getClass().equals(cs[i])) { + if (cs[i] == String.class) { + args[i] = Convert.toStr(args[i]); + if (StringUtils.endsWith((String) args[i], ".0")) { + args[i] = StringUtils.substringBefore((String) args[i], ".0"); + } + } else if (cs[i] == Integer.class) { + args[i] = Convert.toInt(args[i]); + } else if (cs[i] == Long.class) { + args[i] = Convert.toLong(args[i]); + } else if (cs[i] == Double.class) { + args[i] = Convert.toDouble(args[i]); + } else if (cs[i] == Float.class) { + args[i] = Convert.toFloat(args[i]); + } else if (cs[i] == Date.class) { + if (args[i] instanceof String) { + args[i] = DateUtils.parseDate(args[i]); + } + } + } + } + return (E) method.invoke(obj, args); + } catch (Exception e) { + String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; + throw convertReflectionExceptionToUnchecked(msg, e); + } + } + + /** + * 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问. + * 如向上转型到Object仍无法找到, 返回null. + * @param obj + * @param fieldName + * @return + */ + public static Field getAccessibleField(final Object obj, final String fieldName) { + // 为空不报错。直接返回 null + if (obj == null) { + return null; + } + Validate.notBlank(fieldName, "fieldName can't be blank"); + for (Class superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) { + try { + Field field = superClass.getDeclaredField(fieldName); + makeAccessible(field); + return field; + } + catch (NoSuchFieldException e) { + continue; + } + } + return null; + } + + /** + * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. + * 如向上转型到Object仍无法找到, 返回null. + * 匹配函数名+参数类型。 + * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args) + * @param obj + * @param methodName + * @param parameterTypes + * @return + */ + public static Method getAccessibleMethod(final Object obj, final String methodName, + final Class... parameterTypes) { + // 为空不报错。直接返回 null + if (obj == null) { + return null; + } + Validate.notBlank(methodName, "methodName can't be blank"); + for (Class searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) { + try { + Method method = searchType.getDeclaredMethod(methodName, parameterTypes); + makeAccessible(method); + return method; + } catch (NoSuchMethodException e) { + continue; + } + } + return null; + } + + /** + * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. + * 如向上转型到Object仍无法找到, 返回null. + * 只匹配函数名。 + * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args) + * @param obj + * @param methodName + * @param argsNum + * @return + */ + public static Method getAccessibleMethodByName(final Object obj, final String methodName, int argsNum) { + // 为空不报错。直接返回 null + if (obj == null) { + return null; + } + Validate.notBlank(methodName, "methodName can't be blank"); + for (Class searchType = obj.getClass(); searchType != Object.class; searchType = searchType.getSuperclass()) { + Method[] methods = searchType.getDeclaredMethods(); + for (Method method : methods) { + if (method.getName().equals(methodName) && method.getParameterTypes().length == argsNum) { + makeAccessible(method); + return method; + } + } + } + return null; + } + + /** + * 改变private/protected的方法为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。 + * @param method + */ + public static void makeAccessible(Method method) { + if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) + && !method.isAccessible()) { + method.setAccessible(true); + } + } + + /** + * 改变private/protected的成员变量为public,尽量不调用实际改动的语句,避免JDK的SecurityManager抱怨。 + * @param field + */ + public static void makeAccessible(Field field) { + if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) + || Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) { + field.setAccessible(true); + } + } + + /** + * 通过反射, 获得Class定义中声明的泛型参数的类型, 注意泛型必须定义在父类处 + * 如无法找到, 返回Object.class. + * @param clazz + * @param + * @return + */ + @SuppressWarnings("unchecked") + public static Class getClassGenricType(final Class clazz) { + return getClassGenricType(clazz, 0); + } + + /** + * 通过反射, 获得Class定义中声明的父类的泛型参数的类型. + * 如无法找到, 返回Object.class. + * @param clazz + * @param index + * @return + */ + public static Class getClassGenricType(final Class clazz, final int index) { + Type genType = clazz.getGenericSuperclass(); + + if (!(genType instanceof ParameterizedType)) { + logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType"); + return Object.class; + } + + Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); + + if (index >= params.length || index < 0) { + logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + + params.length); + return Object.class; + } + if (!(params[index] instanceof Class)) { + logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); + return Object.class; + } + + return (Class) params[index]; + } + + /** + * 通过实例化对象获取反射对象 + * @param instance + * @return + */ + public static Class getUserClass(Object instance) { + if (instance == null) { + throw new RuntimeException("Instance must not be null"); + } + Class clazz = instance.getClass(); + if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { + Class superClass = clazz.getSuperclass(); + if (superClass != null && !Object.class.equals(superClass)) { + return superClass; + } + } + return clazz; + + } + + /** + * 将反射时的checked exception转换为unchecked exception. + * @param msg + * @param e + * @return + */ + public static RuntimeException convertReflectionExceptionToUnchecked(String msg, Exception e) { + if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException + || e instanceof NoSuchMethodException) { + return new IllegalArgumentException(msg, e); + } else if (e instanceof InvocationTargetException) { + return new RuntimeException(msg, ((InvocationTargetException) e).getTargetException()); + } + return new RuntimeException(msg, e); + } +} diff --git a/modules/src/main/java/com/bw/util/core/spring/SpringUtils.java b/modules/src/main/java/com/bw/util/core/spring/SpringUtils.java new file mode 100644 index 0000000..e62700b --- /dev/null +++ b/modules/src/main/java/com/bw/util/core/spring/SpringUtils.java @@ -0,0 +1,106 @@ +package com.bw.util.core.spring; + +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.stereotype.Component; + +/** + * spring工具类 方便在非spring管理环境中获取bean + * + * @author markGuo + */ +@Component +public final class SpringUtils implements BeanFactoryPostProcessor +{ + /** Spring应用上下文环境 */ + private static ConfigurableListableBeanFactory beanFactory; + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + SpringUtils.beanFactory = beanFactory; + } + + /** + * 获取对象 + * + * @param name + * @return Object 一个以所给名字注册的bean的实例 + * @throws BeansException + * + */ + @SuppressWarnings("unchecked") + public static T getBean(String name) throws BeansException { + return (T) beanFactory.getBean(name); + } + + /** + * 获取类型为requiredType的对象 + * + * @param clz + * @return + * @throws BeansException + * + */ + public static T getBean(Class clz) throws BeansException { + T result = beanFactory.getBean(clz); + return result; + } + + /** + * 如果BeanFactory包含一个与所给名称匹配的bean定义,则返回true + * + * @param name + * @return boolean + */ + public static boolean containsBean(String name) { + return beanFactory.containsBean(name); + } + + /** + * 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的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); + } + + /** + * 如果给定的bean名字在bean定义中有别名,则返回这些别名 + * + * @param name + * @return + * @throws NoSuchBeanDefinitionException + * + */ + public static String[] getAliases(String name) throws NoSuchBeanDefinitionException { + return beanFactory.getAliases(name); + } + + /** + * 获取aop代理对象 + * + * @param invoker + * @return + */ + @SuppressWarnings("unchecked") + public static T getAopProxy(T invoker) { + return (T) AopContext.currentProxy(); + } +} diff --git a/modules/src/main/java/com/bw/util/core/text/CharsetKit.java b/modules/src/main/java/com/bw/util/core/text/CharsetKit.java new file mode 100644 index 0000000..7a0b29c --- /dev/null +++ b/modules/src/main/java/com/bw/util/core/text/CharsetKit.java @@ -0,0 +1,78 @@ +package com.bw.util.core.text; + +import org.apache.commons.lang3.StringUtils; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * 字符集工具类 + * + * @author markGuo + */ +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); + + /** + * 转换为Charset对象 + * + * @param charset 字符集,为空则返回默认字符集 + * @return Charset + */ + public static Charset charset(String charset) { + return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); + } + + /** + * 转换字符串的字符集编码 + * + * @param source 字符串 + * @param srcCharset 源字符集,默认ISO-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 源字符集,默认ISO-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) { + srcCharset = 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/modules/src/main/java/com/bw/util/core/text/Convert.java b/modules/src/main/java/com/bw/util/core/text/Convert.java new file mode 100644 index 0000000..9d64780 --- /dev/null +++ b/modules/src/main/java/com/bw/util/core/text/Convert.java @@ -0,0 +1,818 @@ +package com.bw.util.core.text; + + +import org.apache.commons.lang3.StringUtils; + +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; + +/** + * 类型转换器 + * + * @author markGuo + */ +public class Convert { + /** + * 转换为字符串
+ * 如果给定的值为null,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @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(); + } + + /** + * 转换为字符串
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static String toStr(Object value) { + return toStr(value, null); + } + + /** + * 转换为字符
+ * 如果给定的值为null,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @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); + } + + /** + * 转换为字符
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Character toChar(Object value) { + return toChar(value, null); + } + + /** + * 转换为byte
+ * 如果给定的值为null,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Byte toByte(Object value, Byte defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof Byte) { + return (Byte) value; + }else 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; + } + } + + /** + * 转换为byte
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Byte toByte(Object value) { + return toByte(value, null); + } + + /** + * 转换为Short
+ * 如果给定的值为null,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Short toShort(Object value, Short defaultValue) { + if (value == null) { + return defaultValue; + }else if (value instanceof Short) { + return (Short) value; + } else 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; + } + } + + /** + * 转换为Short
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Short toShort(Object value) { + return toShort(value, null); + } + + /** + * 转换为Number
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Number toNumber(Object value, Number defaultValue) { + if (value == null) { + return defaultValue; + } else 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; + } + } + + /** + * 转换为Number
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Number toNumber(Object value) { + return toNumber(value, null); + } + + /** + * 转换为int
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Integer toInt(Object value, Integer defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof Integer) { + return (Integer) value; + } else 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; + } + } + + /** + * 转换为int
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Integer toInt(Object value) { + return toInt(value, null); + } + + /** + * 转换为Integer数组
+ * + * @param str 被转换的值 + * @return 结果 + */ + public static Integer[] toIntArray(String str) { + return toIntArray(",", str); + } + + /** + * 转换为Long数组
+ * + * @param str 被转换的值 + * @return 结果 + */ + public static Long[] toLongArray(String str) { + return toLongArray(",", str); + } + + /** + * 转换为Integer数组
+ * + * @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; + } + + /** + * 转换为Long数组
+ * + * @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; + } + + /** + * 转换为String数组
+ * + * @param str 被转换的值 + * @return 结果 + */ + public static String[] toStrArray(String str) { + return toStrArray(",", str); + } + + /** + * 转换为String数组
+ * + * @param split 分隔符 + * @param split 被转换的值 + * @return 结果 + */ + public static String[] toStrArray(String split, String str) { + return str.split(split); + } + + /** + * 转换为long
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Long toLong(Object value, Long defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof Long) { + return (Long) value; + } else 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; + } + } + + /** + * 转换为long
+ * 如果给定的值为null,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Long toLong(Object value) { + return toLong(value, null); + } + + /** + * 转换为double
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Double toDouble(Object value, Double defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof Double) { + return (Double) value; + } else 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; + } + } + + /** + * 转换为double
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Double toDouble(Object value) { + return toDouble(value, null); + } + + /** + * 转换为Float
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Float toFloat(Object value, Float defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof Float) { + return (Float) value; + } else 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; + } + } + + /** + * 转换为Float
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Float toFloat(Object value) { + return toFloat(value, null); + } + + /** + * 转换为boolean
+ * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static Boolean toBool(Object value, Boolean defaultValue) { + if (value == null) { + return defaultValue; + } else 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": + return true; + case "false": + return false; + case "yes": + return true; + case "ok": + return true; + case "no": + return false; + case "1": + return true; + case "0": + return false; + default: + return defaultValue; + } + } + + /** + * 转换为boolean
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static Boolean toBool(Object value) { + return toBool(value, null); + } + + /** + * 转换为Enum对象
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * + * @param clazz Enum的Class + * @param value 值 + * @param defaultValue 默认值 + * @return Enum + */ + public static > E toEnum(Class clazz, Object value, E defaultValue) { + if (value == null) { + return defaultValue; + } else 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; + } + } + + /** + * 转换为Enum对象
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * + * @param clazz Enum的Class + * @param value 值 + * @return Enum + */ + public static > E toEnum(Class clazz, Object value) { + return toEnum(clazz, value, null); + } + + /** + * 转换为BigInteger
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static BigInteger toBigInteger(Object value, BigInteger defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof BigInteger) { + return (BigInteger) value; + } else 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; + } + } + + /** + * 转换为BigInteger
+ * 如果给定的值为空,或者转换失败,返回默认值null
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static BigInteger toBigInteger(Object value) { + return toBigInteger(value, null); + } + + /** + * 转换为BigDecimal
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @param defaultValue 转换错误时的默认值 + * @return 结果 + */ + public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) { + if (value == null) { + return defaultValue; + } else if (value instanceof BigDecimal) { + return (BigDecimal) value; + } else if (value instanceof Long) { + return new BigDecimal((Long) value); + } else if (value instanceof Double) { + return new BigDecimal((Double) value); + } else 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; + } + } + + /** + * 转换为BigDecimal
+ * 如果给定的值为空,或者转换失败,返回默认值
+ * 转换失败不会报错 + * + * @param value 被转换的值 + * @return 结果 + */ + public static BigDecimal toBigDecimal(Object value) { + return toBigDecimal(value, null); + } + + /** + * 将对象转为字符串
+ * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 + * + * @param obj 对象 + * @return 字符串 + */ + public static String utf8Str(Object obj) { + return str(obj, CharsetKit.CHARSET_UTF_8); + } + + /** + * 将对象转为字符串
+ * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 + * + * @param obj 对象 + * @param charsetName 字符集 + * @return 字符串 + */ + public static String str(Object obj, String charsetName) { + return str(obj, Charset.forName(charsetName)); + } + + /** + * 将对象转为字符串
+ * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 + * + * @param obj 对象 + * @param charset 字符集 + * @return 字符串 + */ + public static String str(Object obj, Charset charset) { + if (null == obj) { + return null; + } else if (obj instanceof String) { + return (String) obj; + } else if (obj instanceof byte[] || obj instanceof Byte[]) { + return str(obj, charset); + } else if (obj instanceof ByteBuffer) { + return str((ByteBuffer) obj, charset); + } + return obj.toString(); + } + + /** + * 将byte数组转为字符串 + * + * @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)); + } + + /** + * 解码字节码 + * + * @param data 字符串 + * @param charset 字符集,如果此字段为空,则解码的结果取决于平台 + * @return 解码后的字符串 + */ + public static String str(byte[] data, Charset charset) { + if (data == null) { + return null; + } else 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 notConvertSet) { + char c[] = input.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (null != notConvertSet && notConvertSet.contains(c[i])) { + // 跳过不替换的字符 + continue; + } else 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 notConvertSet) { + char c[] = text.toCharArray(); + for (int i = 0; i < c.length; i++) { + if (null != notConvertSet && notConvertSet.contains(c[i])) { + // 跳过不替换的字符 + continue; + } else if (c[i] == '\u3000') { + c[i] = ' '; + } else if (c[i] > '\uFF00' && c[i] < '\uFF5F') { + c[i] = (char) (c[i] - 65248); + } + } + return new String(c); + } + + /** + * 数字金额大写转换 先写个完整的然后将如零拾替换成零 + * + * @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/modules/src/main/java/com/bw/util/poi/ExcelUtil.java b/modules/src/main/java/com/bw/util/poi/ExcelUtil.java new file mode 100644 index 0000000..d6085ec --- /dev/null +++ b/modules/src/main/java/com/bw/util/poi/ExcelUtil.java @@ -0,0 +1,787 @@ +package com.bw.util.poi; + + +import com.bw.util.core.date.DateUtils; +import com.bw.util.core.reflect.ReflectUtils; +import com.bw.util.core.spring.SpringUtils; +import com.bw.util.core.text.Convert; +import com.bw.util.poi.annotation.Excel; +import com.bw.util.poi.annotation.Excel.Type; +import com.bw.util.poi.annotation.Excels; +import com.bw.util.poi.exception.PoiException; +import lombok.extern.log4j.Log4j2; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddressList; +import org.apache.poi.util.IOUtils; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFDataValidation; + +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.util.*; + +/** + * Excel相关处理 + * + * @author + */ +@Log4j2 +public class ExcelUtil +{ + + /** + * Excel sheet最大行数,默认65536 + */ + public static final int sheetSize = 65536; + + /** + * 工作表名称 + */ + private String sheetName; + + /** + * 导出类型(EXPORT:导出数据;IMPORT:导入模板) + */ + private Type type; + + /** + * 工作薄对象 + */ + private Workbook wb; + + /** + * 工作表对象 + */ + private Sheet sheet; + + /** + * 样式列表 + */ + private Map styles; + + /** + * 导入导出数据列表 + */ + private List list; + + /** + * 注解列表 + */ + private List fields; + + /** + * 实体对象 + */ + public Class clazz; + + public ExcelUtil(Class clazz) { + this.clazz = clazz; + } + + public void init(List list, String sheetName, Type type) { + if (list == null) { + list = new ArrayList(); + } + this.list = list; + this.sheetName = sheetName; + this.type = type; + createExcelField(); + createWorkbook(); + } + + /** + * 对excel表单默认第一个索引名转换成list + * + * @param is 输入流 + * @return 转换后集合 + */ + public List importExcel(InputStream is) throws Exception { + return importExcel(StringUtils.EMPTY, is); + } + + /** + * 对excel表单指定表格索引名转换成list + * + * @param sheetName 表格索引名 + * @param is 输入流 + * @return 转换后集合 + */ + public List importExcel(String sheetName, InputStream is) throws Exception { + this.type = Type.IMPORT; + this.wb = WorkbookFactory.create(is); + List list = new ArrayList(); + Sheet sheet = null; + if (StringUtils.isNotEmpty(sheetName)) { + // 如果指定sheet名,则取指定sheet中的内容. + sheet = wb.getSheet(sheetName); + } else { + // 如果传入的sheet名不存在则默认指向第1个sheet. + sheet = wb.getSheetAt(0); + } + + if (sheet == null) { + throw new IOException("文件sheet不存在"); + } + + int rows = sheet.getPhysicalNumberOfRows(); + + if (rows > 0) { + // 定义一个map用于存放excel列的序号和field. + Map cellMap = new HashMap(); + // 获取表头 + Row heard = sheet.getRow(0); + for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) { + Cell cell = heard.getCell(i); + if (cell != null) { + String value = this.getCellValue(heard, i).toString(); + cellMap.put(value, i); + } + else { + cellMap.put(null, i); + } + } + // 有数据时才处理 得到类的所有field. + Field[] allFields = clazz.getDeclaredFields(); + // 定义一个map用于存放列的序号和field. + Map fieldsMap = new HashMap(); + for (int col = 0; col < allFields.length; col++) { + Field field = allFields[col]; + Excel attr = field.getAnnotation(Excel.class); + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { + // 设置类的私有字段属性可访问. + field.setAccessible(true); + Integer column = cellMap.get(attr.name()); + fieldsMap.put(column, field); + } + } + for (int i = 1; i < rows; i++) { + // 从第2行开始取数据,默认第一行是表头. + Row row = sheet.getRow(i); + T entity = null; + for (Map.Entry entry : fieldsMap.entrySet()) { + if (entry.getKey() == null){ + continue; + } + Object val = this.getCellValue(row, entry.getKey()); + + // 如果不存在实例则新建. + entity = (entity == null ? clazz.newInstance() : entity); + // 从map中得到对应列的field. + Field field = fieldsMap.get(entry.getKey()); + // 取得类型,并根据对象类型设置值. + Class fieldType = field.getType(); + if (String.class == fieldType) { + String s = Convert.toStr(val); + if (StringUtils.endsWith(s, ".0")) { + val = StringUtils.substringBefore(s, ".0"); + } else { + String dateFormat = field.getAnnotation(Excel.class).dateFormat(); + if (StringUtils.isNotEmpty(dateFormat)) { + val = DateUtils.parseDateToStr(dateFormat, (Date) val); + } else { + val = Convert.toStr(val); + } + } + } else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) { + val = Convert.toInt(val); + } else if ((Long.TYPE == fieldType) || (Long.class == fieldType)) { + val = Convert.toLong(val); + } else if ((Double.TYPE == fieldType) || (Double.class == fieldType)) { + val = Convert.toDouble(val); + } else if ((Float.TYPE == fieldType) || (Float.class == fieldType)) { + val = Convert.toFloat(val); + } else if (BigDecimal.class == fieldType) { + val = Convert.toBigDecimal(val); + } else if (Date.class == fieldType) { + if (val instanceof String) { + val = DateUtils.parseDate(val); + } else if (val instanceof Double) { + val = DateUtil.getJavaDate((Double) val); + } + } + if (fieldType != null) { + Excel attr = field.getAnnotation(Excel.class); + String propertyName = field.getName(); + if (StringUtils.isNotEmpty(attr.targetAttr())) { + propertyName = field.getName() + "." + attr.targetAttr(); + } else if (StringUtils.isNotEmpty(attr.readConverterExp())) { + val = reverseByExp(String.valueOf(val), attr.readConverterExp()); + } + ReflectUtils.invokeSetter(entity, propertyName, val); + } + } + list.add(entity); + } + } + return list; + } + + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param response 返回数据 + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @return 结果 + * @throws IOException + */ + public void exportExcel(HttpServletResponse response, List list, String sheetName){ + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + this.init(list, sheetName, Type.EXPORT); + writeSheet(); + exportExcel(response); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @return 结果 + */ + public void exportExcel(HttpServletResponse response){ + try{ + wb.write(response.getOutputStream()); + } catch (Exception e){ + log.error("导出Excel异常{}", e.getMessage()); + } finally { + IOUtils.closeQuietly(wb); + } + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @return 结果 + */ + public String exportExcel(List list, String sheetName) { + this.init(list, sheetName, Type.EXPORT); + return exportExcel(); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param sheetName 工作表的名称 + * @return 结果 + */ + public String importTemplateExcel(String sheetName) { + this.init(null, sheetName, Type.IMPORT); + return exportExcel(); + } + + /** + * 写入sheet数据 + */ + public void writeSheet(){ + // 取出一共有多少个sheet. + double sheetNo = Math.ceil(list.size() / sheetSize); + for (int index = 0; index <= sheetNo; index++) { + createSheet(sheetNo, index); + + // 产生一行 + Row row = sheet.createRow(0); + int column = 0; + // 写入各个字段的列头名称 + for (Object[] os : fields) { + Excel excel = (Excel) os[1]; + this.createCell(excel, row, column++); + } + if (Type.EXPORT.equals(type)) { + fillExcelData(index, row); + } + } + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @return 结果 + */ + public String exportExcel() { + OutputStream out = null; + try { + writeSheet(); + String filename = encodingFilename(sheetName); + out = new FileOutputStream(getAbsoluteFile(filename)); + wb.write(out); + return filename; + } catch (Exception e) { + log.error("导出Excel异常{}", e.getMessage()); + throw new PoiException("导出Excel失败,请联系管理员!"); + } finally { + try { + if (wb != null) { + wb.close(); + } + if (out != null) { + out.close(); + } + } catch (IOException e1) { + e1.printStackTrace(); + } + + } + } + + /** + * 填充excel数据 + * + * @param index 序号 + * @param row 单元格行 + */ + public void fillExcelData(int index, Row row) { + int startNo = index * sheetSize; + int endNo = Math.min(startNo + sheetSize, list.size()); + for (int i = startNo; i < endNo; i++) { + row = sheet.createRow(i + 1 - startNo); + // 得到导出对象. + T vo = (T) list.get(i); + int column = 0; + for (Object[] os : fields) { + Field field = (Field) os[0]; + Excel excel = (Excel) os[1]; + // 设置实体类私有属性可访问 + field.setAccessible(true); + this.addCell(excel, row, vo, field, column++); + } + } + } + + /** + * 创建表格样式 + * + * @param wb 工作薄对象 + * @return 样式列表 + */ + private Map createStyles(Workbook wb) { + // 写入各条记录,每条记录对应excel表中的一行 + Map styles = new HashMap(); + CellStyle style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setBorderRight(BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + Font dataFont = wb.createFont(); + dataFont.setFontName("Arial"); + dataFont.setFontHeightInPoints((short) 10); + style.setFont(dataFont); + styles.put("data", style); + + style = wb.createCellStyle(); + style.cloneStyleFrom(styles.get("data")); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + Font headerFont = wb.createFont(); + headerFont.setFontName("Arial"); + headerFont.setFontHeightInPoints((short) 10); + headerFont.setBold(true); + headerFont.setColor(IndexedColors.WHITE.getIndex()); + style.setFont(headerFont); + styles.put("header", style); + + return styles; + } + + /** + * 创建单元格 + */ + public Cell createCell(Excel attr, Row row, int column) { + // 创建列 + Cell cell = row.createCell(column); + // 写入列信息 + cell.setCellValue(attr.name()); + setDataValidation(attr, row, column); + cell.setCellStyle(styles.get("header")); + return cell; + } + + /** + * 设置单元格信息 + * + * @param value 单元格值 + * @param attr 注解相关 + * @param cell 单元格信息 + */ + public void setCellVo(Object value, Excel attr, Cell cell) { + if (Excel.ColumnType.STRING == attr.cellType()) { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(value == null ? attr.defaultValue() : value + attr.suffix()); + } else if (Excel.ColumnType.NUMERIC == attr.cellType()) { + cell.setCellType(CellType.NUMERIC); + cell.setCellValue(Integer.parseInt(value + "")); + } + } + + /** + * 创建表格样式 + */ + public void setDataValidation(Excel attr, Row row, int column) { + if (attr.name().indexOf("注:") >= 0) { + sheet.setColumnWidth(column, 6000); + } else { + // 设置列宽 + sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); + row.setHeight((short) (attr.height() * 20)); + } + // 如果设置了提示信息则鼠标放上去提示. + if (StringUtils.isNotEmpty(attr.prompt())) { + // 这里默认设了2-101列提示. + setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); + } + // 如果设置了combo属性则本列只能选择不能输入 + if (attr.combo().length > 0) { + // 这里默认设了2-101列只能选择不能输入. + setXSSFValidation(sheet, attr.combo(), 1, 100, column, column); + } + } + + /** + * 添加单元格 + */ + public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { + Cell cell = null; + try { + // 设置行高 + row.setHeight((short) (attr.height() * 20)); + // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. + if (attr.isExport()) { + // 创建cell + cell = row.createCell(column); + cell.setCellStyle(styles.get("data")); + + // 用于读取对象中的属性 + Object value = getTargetValue(vo, field, attr); + //时间类型格式化 + String dateFormat = attr.dateFormat(); + //读取表达式 + String readConverterExp = attr.readConverterExp(); + //分隔符 + String splitStr = attr.splitStr(); + //反射对象 + Class invokeClass = attr.invokeClass(); + //反射方法名称 + String invokeMethod = attr.invokeMethod(); + if (StringUtils.isNotEmpty(dateFormat) && value != null) { + cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); + } else if (StringUtils.isNotEmpty(readConverterExp) && value != null) { + // 判断是否有分隔符 + if (StringUtils.isNotEmpty(splitStr)){ + StringBuilder cellValue = new StringBuilder(); + String valueStr = String.valueOf(value); + String[] valueStrSplit = valueStr.split(splitStr); + int valueStrSplitLength = valueStrSplit.length; + for (int i = 0; ; i++) { + cellValue.append(convertByExp(valueStrSplit[i], readConverterExp)); + if (i == valueStrSplitLength-1){ + break; + } + cellValue.append(","); + } + cell.setCellValue(cellValue.toString()); + } else { + cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); + } + + } + // 判断是否需要取值 + else if((!invokeClass.getName().equals(String.class.getName())) && StringUtils.isNotEmpty(invokeMethod)){ + Object bean = SpringUtils.getBean(invokeClass); + Method thisMethod = null; + Method[] methods = invokeClass.getMethods(); + for (Method method : methods) { + if (method.getName().equals(invokeMethod)){ + thisMethod = method; + continue; + } + } + cell.setCellValue(thisMethod.invoke(bean,value).toString()); + } else { + // 设置列类型 + setCellVo(value, attr, cell); + } + } + } catch (Exception e) { + log.error("导出Excel失败{}", e); + } + return cell; + } + + /** + * 设置 POI XSSFSheet 单元格提示 + * + * @param sheet 表单 + * @param promptTitle 提示标题 + * @param promptContent 提示内容 + * @param firstRow 开始行 + * @param endRow 结束行 + * @param firstCol 开始列 + * @param endCol 结束列 + */ + public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, + int firstCol, int endCol) { + DataValidationHelper helper = sheet.getDataValidationHelper(); + DataValidationConstraint constraint = helper.createCustomConstraint("DD1"); + CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); + DataValidation dataValidation = helper.createValidation(constraint, regions); + dataValidation.createPromptBox(promptTitle, promptContent); + dataValidation.setShowPromptBox(true); + sheet.addValidationData(dataValidation); + } + + /** + * 设置某些列的值只能输入预制的数据,显示下拉框. + * + * @param sheet 要设置的sheet. + * @param textlist 下拉框显示的内容 + * @param firstRow 开始行 + * @param endRow 结束行 + * @param firstCol 开始列 + * @param endCol 结束列 + * @return 设置好的sheet. + */ + public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { + DataValidationHelper helper = sheet.getDataValidationHelper(); + // 加载下拉列表内容 + DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist); + // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 + CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); + // 数据有效性对象 + DataValidation dataValidation = helper.createValidation(constraint, regions); + // 处理Excel兼容性问题 + if (dataValidation instanceof XSSFDataValidation) { + dataValidation.setSuppressDropDownArrow(true); + dataValidation.setShowErrorBox(true); + } else { + dataValidation.setSuppressDropDownArrow(false); + } + + sheet.addValidationData(dataValidation); + } + + /** + * 解析导出值 0=男,1=女,2=未知 + * + * @param propertyValue 参数值 + * @param converterExp 翻译注解 + * @return 解析后值 + * @throws Exception + */ + public static String convertByExp(String propertyValue, String converterExp) throws Exception { + try { + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { + String[] itemArray = item.split("="); + if (itemArray[0].equals(propertyValue)) { + return itemArray[1]; + } + } + } catch (Exception e) { + throw e; + } + return propertyValue; + } + + /** + * 反向解析值 男=0,女=1,未知=2 + * + * @param propertyValue 参数值 + * @param converterExp 翻译注解 + * @return 解析后值 + * @throws Exception + */ + public static String reverseByExp(String propertyValue, String converterExp) throws Exception { + try { + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { + String[] itemArray = item.split("="); + if (itemArray[1].equals(propertyValue)) { + return itemArray[0]; + } + } + } catch (Exception e) { + throw e; + } + return propertyValue; + } + + /** + * 编码文件名 + */ + public String encodingFilename(String filename) { + filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx"; + return filename; + } + + /** + * 获取下载路径 + * + * @param filename 文件名称 + */ + public String getAbsoluteFile(String filename) { + String downloadPath = System.getProperty("user.dir") + File.separator + filename; + File desc = new File(downloadPath); + if (!desc.getParentFile().exists()) { + desc.getParentFile().mkdirs(); + } + return downloadPath; + } + + /** + * 获取bean中的属性值 + * + * @param vo 实体对象 + * @param field 字段 + * @param excel 注解 + * @return 最终的属性值 + * @throws Exception + */ + private Object getTargetValue(T vo, Field field, Excel excel) throws Exception { + Object o = field.get(vo); + if (StringUtils.isNotEmpty(excel.targetAttr())) { + String target = excel.targetAttr(); + if (target.indexOf(".") > -1) { + String[] targets = target.split("[.]"); + for (String name : targets) { + o = getValue(o, name); + } + } else { + o = getValue(o, target); + } + } + return o; + } + + /** + * 以类的属性的get方法方法形式获取值 + * + * @param o + * @param name + * @return value + * @throws Exception + */ + private Object getValue(Object o, String name) throws Exception { + if (StringUtils.isNotEmpty(name)) { + Class clazz = o.getClass(); + String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1); + Method method = clazz.getMethod(methodName); + o = method.invoke(o); + } + return o; + } + + /** + * 得到所有定义字段 + */ + private void createExcelField() { + this.fields = new ArrayList<>(); + List tempFields = new ArrayList<>(); + tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); + tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); + for (Field field : tempFields) { + // 单注解 + if (field.isAnnotationPresent(Excel.class)) { + putToField(field, field.getAnnotation(Excel.class)); + } + + // 多注解 + if (field.isAnnotationPresent(Excels.class)) { + Excels attrs = field.getAnnotation(Excels.class); + Excel[] excels = attrs.value(); + for (Excel excel : excels) { + putToField(field, excel); + } + } + } + } + + /** + * 放到字段集合中 + */ + private void putToField(Field field, Excel attr) { + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { + this.fields.add(new Object[] { field, attr }); + } + } + + /** + * 创建一个工作簿 + */ + public void createWorkbook() { + this.wb = new SXSSFWorkbook(500); + } + + /** + * 创建工作表 + * + * @param sheetNo sheet数量 + * @param index 序号 + */ + public void createSheet(double sheetNo, int index) { + this.sheet = wb.createSheet(); + this.styles = createStyles(wb); + // 设置工作表的名称. + if (sheetNo == 0) { + wb.setSheetName(index, sheetName); + } else { + wb.setSheetName(index, sheetName + index); + } + } + + /** + * 获取单元格值 + * + * @param row 获取的行 + * @param column 获取单元格列号 + * @return 单元格值 + */ + public Object getCellValue(Row row, int column) { + if (row == null) { + return row; + } + Object val = ""; + try { + Cell cell = row.getCell(column); + if (cell != null) { + if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA) { + val = cell.getNumericCellValue(); + if (HSSFDateUtil.isCellDateFormatted(cell)) { + val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 + } else { + if ((Double) val % 1 > 0) { + val = new DecimalFormat("0.00").format(val); + } else { + val = new DecimalFormat("0").format(val); + } + } + } else if (cell.getCellTypeEnum() == CellType.STRING) { + val = cell.getStringCellValue(); + } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { + val = cell.getBooleanCellValue(); + } else if (cell.getCellTypeEnum() == CellType.ERROR) { + val = cell.getErrorCellValue(); + } + + } + } catch (Exception e) { + return val; + } + return val; + } +} diff --git a/modules/src/main/java/com/bw/util/poi/annotation/Excel.java b/modules/src/main/java/com/bw/util/poi/annotation/Excel.java new file mode 100644 index 0000000..0e8d8ad --- /dev/null +++ b/modules/src/main/java/com/bw/util/poi/annotation/Excel.java @@ -0,0 +1,122 @@ +package com.bw.util.poi.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 自定义导出Excel数据注解 + * + * @author + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Excel +{ + /** + * 导出到Excel中的名字. + */ + public String name() default ""; + + /** + * 日期格式, 如: yyyy-MM-dd + */ + public String dateFormat() default ""; + + /** + * 读取内容转表达式 (如: 0=男,1=女,2=未知) + */ + public String readConverterExp() default ""; + + /** + * 分隔符 + */ + public String splitStr() default ""; + + /** + * 可执行的反射方法值为1个 + */ + public String invokeMethod() default ""; + + /** + * 可执行的反射类 从SpringIoc容器当中取值 + */ + public Class invokeClass() default String.class; + + /** + * 导出类型(0数字 1字符串) + */ + public ColumnType cellType() default ColumnType.STRING; + + /** + * 导出时在excel中每个列的高度 单位为字符 + */ + public double height() default 14; + + /** + * 导出时在excel中每个列的宽 单位为字符 + */ + public double width() default 16; + + /** + * 文字后缀,如% 90 变成90% + */ + public String suffix() default ""; + + /** + * 当值为空时,字段的默认值 + */ + public String defaultValue() default ""; + + /** + * 提示信息 + */ + public String prompt() default ""; + + /** + * 设置只能选择不能输入的列内容. + */ + public String[] combo() default {}; + + /** + * 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写. + */ + public boolean isExport() default true; + + /** + * 另一个类中的属性名称,支持多级获取,以小数点隔开 + */ + public String targetAttr() default ""; + + /** + * 字段类型(0:导出导入;1:仅导出;2:仅导入) + */ + Type type() default Type.ALL; + + public enum Type { + ALL(0), EXPORT(1), IMPORT(2); + private final int value; + + Type(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + } + + public enum ColumnType { + NUMERIC(0), STRING(1); + private final int value; + + ColumnType(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + } +} diff --git a/modules/src/main/java/com/bw/util/poi/annotation/Excels.java b/modules/src/main/java/com/bw/util/poi/annotation/Excels.java new file mode 100644 index 0000000..914e0af --- /dev/null +++ b/modules/src/main/java/com/bw/util/poi/annotation/Excels.java @@ -0,0 +1,18 @@ +package com.bw.util.poi.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Excel注解集 + * + * @author + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface Excels +{ + Excel[] value(); +} diff --git a/modules/src/main/java/com/bw/util/poi/exception/PoiException.java b/modules/src/main/java/com/bw/util/poi/exception/PoiException.java new file mode 100644 index 0000000..27ee107 --- /dev/null +++ b/modules/src/main/java/com/bw/util/poi/exception/PoiException.java @@ -0,0 +1,27 @@ +package com.bw.util.poi.exception; + +/** + * 业务异常 + * + * @author + */ +public class PoiException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + protected final String message; + + public PoiException(String message) { + this.message = message; + } + + public PoiException(String message, Throwable e) { + super(message, e); + this.message = message; + } + + @Override + public String getMessage() { + return message; + } +} diff --git a/modules/src/main/resources/application.yml b/modules/src/main/resources/application.yml new file mode 100644 index 0000000..30125d4 --- /dev/null +++ b/modules/src/main/resources/application.yml @@ -0,0 +1,102 @@ +# 服务器相关 + +server: + port: 10005 + +spring: + mvc: + pathmatch: + matching-strategy: ant_path_matcher + datasource: + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/day280?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false + username: root + password: 1234 + druid: + # 下面为连接池的补充设置,应用到上面所有数据源中 + # 初始化大小,最小,最大 + initial-size: 5 + min-idle: 5 + max-active: 20 + # 配置获取连接等待超时的时间 + max-wait: 60000 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + time-between-eviction-runs-millis: 60000 + # 配置一个连接在池中最小生存的时间,单位是毫秒 + min-evictable-idle-time-millis: 300000 + validation-query: SELECT 1 FROM DUAL + test-while-idle: true + test-on-borrow: false + test-on-return: false + # 打开PSCache,并且指定每个连接上PSCache的大小 + pool-prepared-statements: true + # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + max-pool-prepared-statement-per-connection-size: 20 + filters: stat,wall + use-global-data-source-stat: true + # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 + connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + application: + name: shop-server + redis: + host: 127.0.0.1 + port: 6379 + mail: + host: smtp.qq.com + username: 358795815@qq.com + password: uuyemjigqlhvbgcj + port: 587 # 这个端口根据实际情况配置,一般都是465 + protocol: smtp # 这里应该是不用改的,我没试过其他的配置 + test-connection: false + default-encoding: UTF-8 + properties: + mail: + debug: true + smtp: + auth: true + connectiontimeout: 10000 + timeout: 10000 + writetimeout: 10000 + socketFactory: + class: javax.net.ssl.SSLSocketFactory + port: 587 + starttls: + enable: true + required: true + select: + multipart: + max-file-size: 100MB # 最大支持文件大小 + max-request-size: 100MB # 最大请求大小 + enabled: true + + +# mybatis +mybatis: + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath*:mapper/*Mapper.xml + global-config: + db-config: + id-type: auto + + +aliyun: + end-point: oss-cn-shanghai.aliyuncs.com + access-key-id: LTAI5tSFAGrms29r1xwEFtRM + access-key-secret: rztMfqxdYlsMUtIoy9bIOSGEKCWQT7 + access-pre: https://dongxiaojie.oss-cn-shanghai.aliyuncs.com + bucket-name: dongxiaojie + +fdfs: + so-timeout: 1500 # socket 连接时长 + connect-timeout: 600 # 连接 tracker 服务器超时时长 + # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流 + tracker-list: 192.168.159.167:22122 + web-server-url: 192.168.159.167:8888 + pool: + jmx-enabled: false + # 生成缩略图 + thumb-image: + height: 500 + width: 500 \ No newline at end of file diff --git a/modules/src/main/resources/mapper/GomMapper.xml b/modules/src/main/resources/mapper/GomMapper.xml new file mode 100644 index 0000000..d427fd7 --- /dev/null +++ b/modules/src/main/resources/mapper/GomMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/modules/src/main/resources/mapper/SpanMapper.xml b/modules/src/main/resources/mapper/SpanMapper.xml new file mode 100644 index 0000000..3a56f1b --- /dev/null +++ b/modules/src/main/resources/mapper/SpanMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/modules/src/main/resources/mapper/StudentMapper.xml b/modules/src/main/resources/mapper/StudentMapper.xml new file mode 100644 index 0000000..ef0abc9 --- /dev/null +++ b/modules/src/main/resources/mapper/StudentMapper.xml @@ -0,0 +1,20 @@ + + + + + + insert into t_student VALUES (null,#{name},#{age}) + + + + + + + + \ No newline at end of file diff --git a/modules/src/main/resources/mapper/XXXMapper.xml b/modules/src/main/resources/mapper/XXXMapper.xml new file mode 100644 index 0000000..024c106 --- /dev/null +++ b/modules/src/main/resources/mapper/XXXMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/modules/target/classes/META-INF/modules.kotlin_module b/modules/target/classes/META-INF/modules.kotlin_module new file mode 100644 index 0000000..a49347a Binary files /dev/null and b/modules/target/classes/META-INF/modules.kotlin_module differ diff --git a/modules/target/classes/application.yml b/modules/target/classes/application.yml new file mode 100644 index 0000000..30125d4 --- /dev/null +++ b/modules/target/classes/application.yml @@ -0,0 +1,102 @@ +# 服务器相关 + +server: + port: 10005 + +spring: + mvc: + pathmatch: + matching-strategy: ant_path_matcher + datasource: + driver-class-name: com.mysql.jdbc.Driver + url: jdbc:mysql://127.0.0.1:3306/day280?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false + username: root + password: 1234 + druid: + # 下面为连接池的补充设置,应用到上面所有数据源中 + # 初始化大小,最小,最大 + initial-size: 5 + min-idle: 5 + max-active: 20 + # 配置获取连接等待超时的时间 + max-wait: 60000 + # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 + time-between-eviction-runs-millis: 60000 + # 配置一个连接在池中最小生存的时间,单位是毫秒 + min-evictable-idle-time-millis: 300000 + validation-query: SELECT 1 FROM DUAL + test-while-idle: true + test-on-borrow: false + test-on-return: false + # 打开PSCache,并且指定每个连接上PSCache的大小 + pool-prepared-statements: true + # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 + max-pool-prepared-statement-per-connection-size: 20 + filters: stat,wall + use-global-data-source-stat: true + # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 + connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + application: + name: shop-server + redis: + host: 127.0.0.1 + port: 6379 + mail: + host: smtp.qq.com + username: 358795815@qq.com + password: uuyemjigqlhvbgcj + port: 587 # 这个端口根据实际情况配置,一般都是465 + protocol: smtp # 这里应该是不用改的,我没试过其他的配置 + test-connection: false + default-encoding: UTF-8 + properties: + mail: + debug: true + smtp: + auth: true + connectiontimeout: 10000 + timeout: 10000 + writetimeout: 10000 + socketFactory: + class: javax.net.ssl.SSLSocketFactory + port: 587 + starttls: + enable: true + required: true + select: + multipart: + max-file-size: 100MB # 最大支持文件大小 + max-request-size: 100MB # 最大请求大小 + enabled: true + + +# mybatis +mybatis: + configuration: + map-underscore-to-camel-case: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + mapper-locations: classpath*:mapper/*Mapper.xml + global-config: + db-config: + id-type: auto + + +aliyun: + end-point: oss-cn-shanghai.aliyuncs.com + access-key-id: LTAI5tSFAGrms29r1xwEFtRM + access-key-secret: rztMfqxdYlsMUtIoy9bIOSGEKCWQT7 + access-pre: https://dongxiaojie.oss-cn-shanghai.aliyuncs.com + bucket-name: dongxiaojie + +fdfs: + so-timeout: 1500 # socket 连接时长 + connect-timeout: 600 # 连接 tracker 服务器超时时长 + # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流 + tracker-list: 192.168.159.167:22122 + web-server-url: 192.168.159.167:8888 + pool: + jmx-enabled: false + # 生成缩略图 + thumb-image: + height: 500 + width: 500 \ No newline at end of file diff --git a/modules/target/classes/com/bw/MapperApp.class b/modules/target/classes/com/bw/MapperApp.class new file mode 100644 index 0000000..a33894e Binary files /dev/null and b/modules/target/classes/com/bw/MapperApp.class differ diff --git a/modules/target/classes/com/bw/Tese.class b/modules/target/classes/com/bw/Tese.class new file mode 100644 index 0000000..41da585 Binary files /dev/null and b/modules/target/classes/com/bw/Tese.class differ diff --git a/modules/target/classes/com/bw/config/BloomFilterUtil$SimpleHash.class b/modules/target/classes/com/bw/config/BloomFilterUtil$SimpleHash.class new file mode 100644 index 0000000..260b296 Binary files /dev/null and b/modules/target/classes/com/bw/config/BloomFilterUtil$SimpleHash.class differ diff --git a/modules/target/classes/com/bw/config/BloomFilterUtil.class b/modules/target/classes/com/bw/config/BloomFilterUtil.class new file mode 100644 index 0000000..694a29b Binary files /dev/null and b/modules/target/classes/com/bw/config/BloomFilterUtil.class differ diff --git a/modules/target/classes/com/bw/config/FastConfig.class b/modules/target/classes/com/bw/config/FastConfig.class new file mode 100644 index 0000000..3a2513e Binary files /dev/null and b/modules/target/classes/com/bw/config/FastConfig.class differ diff --git a/modules/target/classes/com/bw/config/FastUtil.class b/modules/target/classes/com/bw/config/FastUtil.class new file mode 100644 index 0000000..29d23e9 Binary files /dev/null and b/modules/target/classes/com/bw/config/FastUtil.class differ diff --git a/modules/target/classes/com/bw/config/Knife4jConfiguration.class b/modules/target/classes/com/bw/config/Knife4jConfiguration.class new file mode 100644 index 0000000..9ba2557 Binary files /dev/null and b/modules/target/classes/com/bw/config/Knife4jConfiguration.class differ diff --git a/modules/target/classes/com/bw/config/RedisConfig.class b/modules/target/classes/com/bw/config/RedisConfig.class new file mode 100644 index 0000000..d0ef59f Binary files /dev/null and b/modules/target/classes/com/bw/config/RedisConfig.class differ diff --git a/modules/target/classes/com/bw/config/RedissonConfig.class b/modules/target/classes/com/bw/config/RedissonConfig.class new file mode 100644 index 0000000..461189b Binary files /dev/null and b/modules/target/classes/com/bw/config/RedissonConfig.class differ diff --git a/modules/target/classes/com/bw/controller/GetailsController.class b/modules/target/classes/com/bw/controller/GetailsController.class new file mode 100644 index 0000000..5943b91 Binary files /dev/null and b/modules/target/classes/com/bw/controller/GetailsController.class differ diff --git a/modules/target/classes/com/bw/controller/StortController.class b/modules/target/classes/com/bw/controller/StortController.class new file mode 100644 index 0000000..9ba78b8 Binary files /dev/null and b/modules/target/classes/com/bw/controller/StortController.class differ diff --git a/modules/target/classes/com/bw/controller/StudentController.class b/modules/target/classes/com/bw/controller/StudentController.class new file mode 100644 index 0000000..1d65b7d Binary files /dev/null and b/modules/target/classes/com/bw/controller/StudentController.class differ diff --git a/modules/target/classes/com/bw/controller/UserController.class b/modules/target/classes/com/bw/controller/UserController.class new file mode 100644 index 0000000..b34d789 Binary files /dev/null and b/modules/target/classes/com/bw/controller/UserController.class differ diff --git a/modules/target/classes/com/bw/dao/GetailsDao.class b/modules/target/classes/com/bw/dao/GetailsDao.class new file mode 100644 index 0000000..11d116c Binary files /dev/null and b/modules/target/classes/com/bw/dao/GetailsDao.class differ diff --git a/modules/target/classes/com/bw/dao/StortDao.class b/modules/target/classes/com/bw/dao/StortDao.class new file mode 100644 index 0000000..ae0080c Binary files /dev/null and b/modules/target/classes/com/bw/dao/StortDao.class differ diff --git a/modules/target/classes/com/bw/dao/StudentDao.class b/modules/target/classes/com/bw/dao/StudentDao.class new file mode 100644 index 0000000..5c9697e Binary files /dev/null and b/modules/target/classes/com/bw/dao/StudentDao.class differ diff --git a/modules/target/classes/com/bw/dao/UserDao.class b/modules/target/classes/com/bw/dao/UserDao.class new file mode 100644 index 0000000..e569cfd Binary files /dev/null and b/modules/target/classes/com/bw/dao/UserDao.class differ diff --git a/modules/target/classes/com/bw/service/GetailsService.class b/modules/target/classes/com/bw/service/GetailsService.class new file mode 100644 index 0000000..7f75456 Binary files /dev/null and b/modules/target/classes/com/bw/service/GetailsService.class differ diff --git a/modules/target/classes/com/bw/service/StortService.class b/modules/target/classes/com/bw/service/StortService.class new file mode 100644 index 0000000..af0981c Binary files /dev/null and b/modules/target/classes/com/bw/service/StortService.class differ diff --git a/modules/target/classes/com/bw/service/StudentService.class b/modules/target/classes/com/bw/service/StudentService.class new file mode 100644 index 0000000..a15d717 Binary files /dev/null and b/modules/target/classes/com/bw/service/StudentService.class differ diff --git a/modules/target/classes/com/bw/service/UserService.class b/modules/target/classes/com/bw/service/UserService.class new file mode 100644 index 0000000..935b5a5 Binary files /dev/null and b/modules/target/classes/com/bw/service/UserService.class differ diff --git a/modules/target/classes/com/bw/service/impl/GetailsServiceImpl.class b/modules/target/classes/com/bw/service/impl/GetailsServiceImpl.class new file mode 100644 index 0000000..f2b6057 Binary files /dev/null and b/modules/target/classes/com/bw/service/impl/GetailsServiceImpl.class differ diff --git a/modules/target/classes/com/bw/service/impl/StortServiceImpl.class b/modules/target/classes/com/bw/service/impl/StortServiceImpl.class new file mode 100644 index 0000000..d598c05 Binary files /dev/null and b/modules/target/classes/com/bw/service/impl/StortServiceImpl.class differ diff --git a/modules/target/classes/com/bw/service/impl/StudentServiceImpl.class b/modules/target/classes/com/bw/service/impl/StudentServiceImpl.class new file mode 100644 index 0000000..bdeb275 Binary files /dev/null and b/modules/target/classes/com/bw/service/impl/StudentServiceImpl.class differ diff --git a/modules/target/classes/com/bw/service/impl/UserServiceImpl.class b/modules/target/classes/com/bw/service/impl/UserServiceImpl.class new file mode 100644 index 0000000..b24c0cd Binary files /dev/null and b/modules/target/classes/com/bw/service/impl/UserServiceImpl.class differ diff --git a/modules/target/classes/com/bw/util/AliyunOssConfig.class b/modules/target/classes/com/bw/util/AliyunOssConfig.class new file mode 100644 index 0000000..d6b57ce Binary files /dev/null and b/modules/target/classes/com/bw/util/AliyunOssConfig.class differ diff --git a/modules/target/classes/com/bw/util/HttpPost.class b/modules/target/classes/com/bw/util/HttpPost.class new file mode 100644 index 0000000..2f0aebf Binary files /dev/null and b/modules/target/classes/com/bw/util/HttpPost.class differ diff --git a/modules/target/classes/com/bw/util/HttpUtils$1.class b/modules/target/classes/com/bw/util/HttpUtils$1.class new file mode 100644 index 0000000..4e22c8a Binary files /dev/null and b/modules/target/classes/com/bw/util/HttpUtils$1.class differ diff --git a/modules/target/classes/com/bw/util/HttpUtils.class b/modules/target/classes/com/bw/util/HttpUtils.class new file mode 100644 index 0000000..0405ba0 Binary files /dev/null and b/modules/target/classes/com/bw/util/HttpUtils.class differ diff --git a/modules/target/classes/com/bw/util/ImageVerificationCode.class b/modules/target/classes/com/bw/util/ImageVerificationCode.class new file mode 100644 index 0000000..c3bc51f Binary files /dev/null and b/modules/target/classes/com/bw/util/ImageVerificationCode.class differ diff --git a/modules/target/classes/com/bw/util/JwtConstants.class b/modules/target/classes/com/bw/util/JwtConstants.class new file mode 100644 index 0000000..3662e9f Binary files /dev/null and b/modules/target/classes/com/bw/util/JwtConstants.class differ diff --git a/modules/target/classes/com/bw/util/JwtUtils.class b/modules/target/classes/com/bw/util/JwtUtils.class new file mode 100644 index 0000000..234aa27 Binary files /dev/null and b/modules/target/classes/com/bw/util/JwtUtils.class differ diff --git a/modules/target/classes/com/bw/util/Md5Utils.class b/modules/target/classes/com/bw/util/Md5Utils.class new file mode 100644 index 0000000..cb2d1a5 Binary files /dev/null and b/modules/target/classes/com/bw/util/Md5Utils.class differ diff --git a/modules/target/classes/com/bw/util/MsgUtil.class b/modules/target/classes/com/bw/util/MsgUtil.class new file mode 100644 index 0000000..f02beda Binary files /dev/null and b/modules/target/classes/com/bw/util/MsgUtil.class differ diff --git a/modules/target/classes/com/bw/util/core/date/DateUtils.class b/modules/target/classes/com/bw/util/core/date/DateUtils.class new file mode 100644 index 0000000..03ca7d0 Binary files /dev/null and b/modules/target/classes/com/bw/util/core/date/DateUtils.class differ diff --git a/modules/target/classes/com/bw/util/core/reflect/ReflectUtils.class b/modules/target/classes/com/bw/util/core/reflect/ReflectUtils.class new file mode 100644 index 0000000..466c90a Binary files /dev/null and b/modules/target/classes/com/bw/util/core/reflect/ReflectUtils.class differ diff --git a/modules/target/classes/com/bw/util/core/spring/SpringUtils.class b/modules/target/classes/com/bw/util/core/spring/SpringUtils.class new file mode 100644 index 0000000..a6a3615 Binary files /dev/null and b/modules/target/classes/com/bw/util/core/spring/SpringUtils.class differ diff --git a/modules/target/classes/com/bw/util/core/text/CharsetKit.class b/modules/target/classes/com/bw/util/core/text/CharsetKit.class new file mode 100644 index 0000000..dadb097 Binary files /dev/null and b/modules/target/classes/com/bw/util/core/text/CharsetKit.class differ diff --git a/modules/target/classes/com/bw/util/core/text/Convert.class b/modules/target/classes/com/bw/util/core/text/Convert.class new file mode 100644 index 0000000..cdd31b1 Binary files /dev/null and b/modules/target/classes/com/bw/util/core/text/Convert.class differ diff --git a/modules/target/classes/com/bw/util/poi/ExcelUtil.class b/modules/target/classes/com/bw/util/poi/ExcelUtil.class new file mode 100644 index 0000000..54596ce Binary files /dev/null and b/modules/target/classes/com/bw/util/poi/ExcelUtil.class differ diff --git a/modules/target/classes/com/bw/util/poi/annotation/Excel$ColumnType.class b/modules/target/classes/com/bw/util/poi/annotation/Excel$ColumnType.class new file mode 100644 index 0000000..eb3da1d Binary files /dev/null and b/modules/target/classes/com/bw/util/poi/annotation/Excel$ColumnType.class differ diff --git a/modules/target/classes/com/bw/util/poi/annotation/Excel$Type.class b/modules/target/classes/com/bw/util/poi/annotation/Excel$Type.class new file mode 100644 index 0000000..b4fff32 Binary files /dev/null and b/modules/target/classes/com/bw/util/poi/annotation/Excel$Type.class differ diff --git a/modules/target/classes/com/bw/util/poi/annotation/Excel.class b/modules/target/classes/com/bw/util/poi/annotation/Excel.class new file mode 100644 index 0000000..4fcb558 Binary files /dev/null and b/modules/target/classes/com/bw/util/poi/annotation/Excel.class differ diff --git a/modules/target/classes/com/bw/util/poi/annotation/Excels.class b/modules/target/classes/com/bw/util/poi/annotation/Excels.class new file mode 100644 index 0000000..400c1cc Binary files /dev/null and b/modules/target/classes/com/bw/util/poi/annotation/Excels.class differ diff --git a/modules/target/classes/com/bw/util/poi/exception/PoiException.class b/modules/target/classes/com/bw/util/poi/exception/PoiException.class new file mode 100644 index 0000000..1a3d66c Binary files /dev/null and b/modules/target/classes/com/bw/util/poi/exception/PoiException.class differ diff --git a/modules/target/classes/mapper/GomMapper.xml b/modules/target/classes/mapper/GomMapper.xml new file mode 100644 index 0000000..d427fd7 --- /dev/null +++ b/modules/target/classes/mapper/GomMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/modules/target/classes/mapper/SpanMapper.xml b/modules/target/classes/mapper/SpanMapper.xml new file mode 100644 index 0000000..3a56f1b --- /dev/null +++ b/modules/target/classes/mapper/SpanMapper.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/modules/target/classes/mapper/StudentMapper.xml b/modules/target/classes/mapper/StudentMapper.xml new file mode 100644 index 0000000..ef0abc9 --- /dev/null +++ b/modules/target/classes/mapper/StudentMapper.xml @@ -0,0 +1,20 @@ + + + + + + insert into t_student VALUES (null,#{name},#{age}) + + + + + + + + \ No newline at end of file diff --git a/modules/target/classes/mapper/XXXMapper.xml b/modules/target/classes/mapper/XXXMapper.xml new file mode 100644 index 0000000..024c106 --- /dev/null +++ b/modules/target/classes/mapper/XXXMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..dc85465 --- /dev/null +++ b/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.example + bwie-54 + pom + 1.0-SNAPSHOT + + common + modules + + + + 1.8 + UTF-8 + UTF-8 + 2.2.2.RELEASE + false + + + + + spring-boot-starter-parent + org.springframework.boot + 2.6.2 + + + + + \ No newline at end of file