Merge branch 'master' of https://gitee.com/huoxiong/hx_common
| | |
| | | </content> |
| | | <orderEntry type="inheritedJdk" /> |
| | | <orderEntry type="sourceFolder" forTests="false" /> |
| | | <orderEntry type="library" name="Maven: com.qcloud:cos_api:5.6.32" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> |
| | | <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" /> |
| | | <orderEntry type="library" name="Maven: joda-time:joda-time:2.9.9" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.6.2" level="project" /> |
| | | <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.6" level="project" /> |
| | |
| | | <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.13" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.12" level="project" /> |
| | | <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" /> |
| | | <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" /> |
| | | <orderEntry type="library" name="Maven: cglib:cglib:3.1" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.ow2.asm:asm:4.2" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.google.zxing:core:3.3.0" level="project" /> |
| | |
| | | <orderEntry type="library" name="Maven: redis.clients:jedis:2.9.0" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.5.0" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.auth0:java-jwt:3.10.3" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" /> |
| | | <orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt:0.9.1" level="project" /> |
| | | <orderEntry type="library" name="Maven: javax.servlet.jsp.jstl:jstl-api:1.2" level="project" /> |
| | | <orderEntry type="library" name="Maven: javax.servlet:servlet-api:2.5" level="project" /> |
| | |
| | | <orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.0" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.0.5.RELEASE" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.zaxxer:HikariCP:2.7.9" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> |
| | | <orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.0.9.RELEASE" level="project" /> |
| | | <orderEntry type="library" scope="RUNTIME" name="Maven: mysql:mysql-connector-java:5.1.47" level="project" /> |
| | | <orderEntry type="library" name="Maven: com.alibaba:druid:1.1.9" level="project" /> |
| | |
| | | <artifactId>hx-common</artifactId> |
| | | <packaging>jar</packaging> |
| | | |
| | | |
| | | <dependencies> |
| | | |
| | | <!--腾讯云 cos--> |
| | | <dependency> |
| | | <groupId>com.qcloud</groupId> |
| | | <artifactId>cos_api</artifactId> |
| | | </dependency> |
| | | |
| | | <!--发送邮件--> |
| | | <dependency> |
| | | <groupId>com.sun.mail</groupId> |
| | |
| | | */ |
| | | <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**查询条数 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**查询列表,返回实体类的List |
| | | * @param mapperClass mapper类 |
| | | * @param sqlSentence 查询参数类 |
| | |
| | | */ |
| | | <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | /**查询条数 |
| | | * @param mapperClass mapper类 |
| | | * @param sqlSentence 查询参数类 |
| | | * @return 返回条数 |
| | | */ |
| | | <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence); |
| | | |
| | | |
| | | /**查询列表,返回实体类的List |
| | | * @param mapperClass mapper类 |
| | | * @param sqlSentence 查询参数类 |
| | |
| | | return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insert"),entity); |
| | | } |
| | | |
| | | /**获取条数*/ |
| | | /**获取条数 |
| | | * @return*/ |
| | | @Override |
| | | public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | public <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence) { |
| | | return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence); |
| | | } |
| | | |
| | | /**获取条数 |
| | | * @return*/ |
| | | @Override |
| | | public <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence) { |
| | | return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCountSql"),sqlSentence); |
| | | } |
| | | |
| | | /**获取列表*/ |
| | | @Override |
| | | public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) { |
| | |
| | | return commonDao.selectCount(mapperClass,sqlSentence); |
| | | } |
| | | |
| | | /**获取条数*/ |
| | | @Override |
| | | public <T extends Serializable> int selectCountSql(Class<?> mapperClass,SqlSentence sqlSentence) { |
| | | return commonDao.selectCountSql(mapperClass,sqlSentence); |
| | | } |
| | | |
| | | /**获取列表*/ |
| | | @Override |
| | | public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) { |
New file |
| | |
| | | package com.hx.exception; |
| | | |
| | | /** |
| | | * 登录提示异常 |
| | | * @author ChenJiaHe |
| | | * @Date 2020-11-17 |
| | | */ |
| | | public class LoginException extends RuntimeException { |
| | | |
| | | private Integer code; |
| | | |
| | | public LoginException(String message) { |
| | | super(message); |
| | | } |
| | | |
| | | public LoginException(String message, Integer code) { |
| | | super(message); |
| | | this.code = code; |
| | | } |
| | | |
| | | public LoginException(String message, Throwable cause, Integer code) { |
| | | super(message, cause); |
| | | this.code = code; |
| | | } |
| | | |
| | | public LoginException(Throwable cause, Integer code) { |
| | | super(cause); |
| | | this.code = code; |
| | | } |
| | | |
| | | //@Override |
| | | public int getCode() { |
| | | return this.code; |
| | | } |
| | | } |
| | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | return null; |
| | | } |
New file |
| | |
| | | package com.hx.util; |
| | | |
| | | import com.aliyun.oss.OSSClient; |
| | | import com.aliyun.oss.model.OSSObject; |
| | | import com.qcloud.cos.COSClient; |
| | | import com.qcloud.cos.ClientConfig; |
| | | import com.qcloud.cos.auth.BasicCOSCredentials; |
| | | import com.qcloud.cos.auth.COSCredentials; |
| | | import com.qcloud.cos.model.ObjectMetadata; |
| | | import com.qcloud.cos.model.PutObjectRequest; |
| | | import com.qcloud.cos.model.PutObjectResult; |
| | | import com.qcloud.cos.region.Region; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Date; |
| | | |
| | | /**腾讯云 COS |
| | | * @author ChenJiaHe |
| | | * @date 2020-12-03 |
| | | */ |
| | | public class COSUtil { |
| | | |
| | | /** 后端调用上传图片 |
| | | * @param key 上传路径(包括图片名称和和后缀),指定要上传到 COS 上对象键 |
| | | * @param localFile |
| | | * @param secretId 用户id |
| | | * @param secretKey 用户秘钥 |
| | | * @param regionName 存在域,参考腾讯云 |
| | | * @param bucketName 指定要上传到的存储桶 |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public static String uploadImg(String key,MultipartFile localFile,String secretId, String secretKey,String regionName,String bucketName) throws IOException { |
| | | |
| | | // 1 初始化用户身份信息(secretId, secretKey)。 |
| | | COSCredentials cred = new BasicCOSCredentials(secretId, secretKey); |
| | | // 2 设置 bucket 的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224 |
| | | // clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。 |
| | | Region region = new Region(regionName); |
| | | ClientConfig clientConfig = new ClientConfig(region); |
| | | // 3 生成 cos 客户端。 |
| | | COSClient cosClient = new COSClient(cred, clientConfig); |
| | | |
| | | //开始上传 |
| | | ObjectMetadata objectMetadata = new ObjectMetadata(); |
| | | // 设置输入流长度为500 |
| | | objectMetadata.setContentLength(500); |
| | | // 设置 Content type, 默认是 application/octet-stream,对于本地文件上传,默认根据本地文件的后缀进行映射 |
| | | // ,例如 jpg 文件映射 为image/jpeg对于流式上传 默认是 application/octet-stream |
| | | //objectMetadata.setContentType("application/pdf"); |
| | | PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key,localFile.getInputStream(),objectMetadata); |
| | | PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); |
| | | |
| | | //拼接路径 |
| | | StringBuilder imgUrl = new StringBuilder(); |
| | | imgUrl.append("https://"+bucketName+"-"+secretId+".cos."+regionName+".myqcloud.com"); |
| | | if(key.startsWith("/")){ |
| | | imgUrl.append(key); |
| | | }else{ |
| | | imgUrl.append("/"+key); |
| | | } |
| | | return imgUrl.toString(); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | return c.getTime(); |
| | | } |
| | | |
| | | /**时间上年数叠加 |
| | | * @Author: ChenJiaHe |
| | | * @param dateTime 时间 |
| | | * @param dayNum 天数 |
| | | * @return |
| | | */ |
| | | public static Date addYear(Date dateTime,int dayNum){ |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(dateTime); |
| | | c.add(Calendar.YEAR, dayNum); |
| | | return c.getTime(); |
| | | } |
| | | |
| | | /** |
| | | * 转换成字符串到指定的日期 |
| | | * |
| | |
| | | return weekDays[w]; |
| | | } |
| | | |
| | | /** |
| | | * endTime比startTime多的天数 |
| | | * @param startTime 最小时间 |
| | | * @param endTime 最大时间 |
| | | * @return |
| | | */ |
| | | public static Integer differDay(Date startTime,Date endTime){ |
| | | Calendar cal1 = Calendar.getInstance(); |
| | | cal1.setTime(startTime); |
| | | |
| | | Calendar cal2 = Calendar.getInstance(); |
| | | cal2.setTime(endTime); |
| | | int day1= cal1.get(Calendar.DAY_OF_YEAR); |
| | | int day2 = cal2.get(Calendar.DAY_OF_YEAR); |
| | | |
| | | int year1 = cal1.get(Calendar.YEAR); |
| | | int year2 = cal2.get(Calendar.YEAR); |
| | | if(year1 != year2) { //同一年 |
| | | int timeDistance = 0 ; |
| | | for(int i = year1 ; i < year2 ; i ++) { |
| | | if(i%4==0 && i%100!=0 || i%400==0) {//闰年 |
| | | timeDistance += 366; |
| | | } |
| | | else {//不是闰年 |
| | | timeDistance += 365; |
| | | } |
| | | } |
| | | |
| | | return timeDistance + (day2-day1) ; |
| | | } |
| | | else { //不同年 |
| | | System.out.println("判断day2 - day1 : " + (day2-day1)); |
| | | return day2-day1; |
| | | } |
| | | } |
| | | |
| | | /**判断两个时间是不是同一天*/ |
| | | public static boolean timeEqual(Date startTime,Date endTime){ |
| | | if(startTime == null || endTime==null){ |
New file |
| | |
| | | package com.hx.util; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | |
| | | public class DownFileUtil { |
| | | |
| | | /** |
| | | * 下载文件工具 |
| | | * |
| | | * @param path |
| | | * 完整路径(可用simpleToof工具获取) |
| | | */ |
| | | public static void DownFile(HttpServletRequest request,HttpServletResponse response,String path) { |
| | | final String userAgent = request.getHeader("USER-AGENT"); |
| | | try { |
| | | // AdminUpload adminUpload = dm.find(AdminUpload.class, fileName); |
| | | // String str =adminUpload.getPath(); |
| | | String filePath = path; |
| | | // System.out.println("path"+ServletActionContext.getRequest().getRealPath("/") |
| | | // + filePath); |
| | | // File downfile = new |
| | | // File(ServletActionContext.getRequest().getRealPath("/") + |
| | | // filePath); |
| | | File downfile = new File(filePath); |
| | | String filename = ""; |
| | | if(userAgent.equals("MSIE")){//IE浏览器 |
| | | filename = URLEncoder.encode(downfile.getName(),"UTF8"); |
| | | }else if(userAgent.equals("Mozilla")){//google,火狐浏览器 |
| | | filename = new String(downfile.getName().getBytes(), "ISO8859-1"); |
| | | }else{ |
| | | filename = URLEncoder.encode(downfile.getName(),"UTF8");//其他浏览器 |
| | | } |
| | | InputStream fis = new BufferedInputStream(new FileInputStream( |
| | | downfile)); |
| | | byte[] buffer = new byte[fis.available()]; |
| | | fis.read(buffer); |
| | | fis.close(); |
| | | response.reset(); |
| | | response.addHeader("Content-Disposition", |
| | | "attachment;filename=" + filename); |
| | | response.addHeader("Content-Length", |
| | | "" + downfile.length()); |
| | | OutputStream toClient = new BufferedOutputStream( |
| | | response.getOutputStream()); |
| | | response.setContentType( |
| | | "application/octet-stream"); |
| | | toClient.write(buffer); |
| | | toClient.flush(); |
| | | toClient.close(); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载文件工具(提示选择路径) |
| | | * |
| | | * @param path |
| | | * 完整路径(可用simpleToof工具获取) |
| | | */ |
| | | public static void DownFileTips(HttpServletRequest request,HttpServletResponse response,String path) { |
| | | final String userAgent = request.getHeader("USER-AGENT"); |
| | | try { |
| | | // AdminUpload adminUpload = dm.find(AdminUpload.class, fileName); |
| | | // String str =adminUpload.getPath(); |
| | | String filePath = path; |
| | | // System.out.println("path"+ServletActionContext.getRequest().getRealPath("/") |
| | | // + filePath); |
| | | // File downfile = new |
| | | // File(ServletActionContext.getRequest().getRealPath("/") + |
| | | // filePath); |
| | | File downfile = new File(filePath); |
| | | |
| | | String filename = ""; |
| | | if(userAgent.equals("MSIE")){//IE浏览器 |
| | | filename = URLEncoder.encode(downfile.getName(),"UTF8"); |
| | | }else if(userAgent.equals("Mozilla")){//google,火狐浏览器 |
| | | filename = new String(downfile.getName().getBytes(), "ISO8859-1"); |
| | | }else{ |
| | | filename = URLEncoder.encode(downfile.getName(),"UTF8");//其他浏览器 |
| | | } |
| | | InputStream fis = new BufferedInputStream(new FileInputStream( |
| | | downfile)); |
| | | byte[] buffer = new byte[fis.available()]; |
| | | fis.read(buffer); |
| | | fis.close(); |
| | | |
| | | response.addHeader("Content-Disposition", "attachment;filename="+ new String(filename.getBytes())); |
| | | OutputStream toClient= new BufferedOutputStream(response.getOutputStream()); |
| | | response.setContentType("application/vnd.ms-excel;charset=utf-8"); |
| | | |
| | | toClient.write(buffer); |
| | | toClient.flush(); |
| | | toClient.close(); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载文件工具(提示选择路径) |
| | | * |
| | | * @param downfile |
| | | * 导出的文件 |
| | | * @param fileName |
| | | * 导出的文件名称 |
| | | */ |
| | | public static void DownFileTips(HttpServletRequest request, HttpServletResponse response, File downfile, String fileName) { |
| | | final String userAgent = request.getHeader("USER-AGENT"); |
| | | try { |
| | | if(StringUtils.isEmpty(fileName)){ |
| | | fileName = downfile.getName(); |
| | | } |
| | | String filename = ""; |
| | | if(userAgent.equals("MSIE")){//IE浏览器 |
| | | filename = URLEncoder.encode(fileName,"UTF8"); |
| | | }else if(userAgent.equals("Mozilla")){//google,火狐浏览器 |
| | | filename = new String(fileName.getBytes(), "ISO8859-1"); |
| | | }else{ |
| | | filename = URLEncoder.encode(fileName,"UTF8");//其他浏览器 |
| | | } |
| | | InputStream fis = new BufferedInputStream(new FileInputStream( |
| | | downfile)); |
| | | byte[] buffer = new byte[fis.available()]; |
| | | fis.read(buffer); |
| | | fis.close(); |
| | | |
| | | response.addHeader("Content-Disposition", "attachment;filename="+ filename); |
| | | OutputStream toClient= new BufferedOutputStream(response.getOutputStream()); |
| | | response.setContentType("application/vnd.ms-excel;charset=utf-8"); |
| | | |
| | | toClient.write(buffer); |
| | | toClient.flush(); |
| | | toClient.close(); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | return filePath; |
| | | } |
| | | |
| | | /**生成临时文件 |
| | | * @param headList |
| | | * Excel文件Head标题集合 |
| | | * @param fieldList |
| | | * Excel文件Field标题集合 根据field来寻找位置填充表格 |
| | | * @param dataList |
| | | * Excel文件数据内容部分 |
| | | * @throws Exception |
| | | */ |
| | | public static File createExcel(String[] headList, String[] fieldList, |
| | | List<Map<String, Object>> dataList) throws Exception { |
| | | File file = File.createTempFile("temp", ".xls"); |
| | | try{ |
| | | // 创建新的Excel 工作簿 |
| | | HSSFWorkbook workbook = new HSSFWorkbook(); |
| | | |
| | | // 在Excel工作簿中建一工作表,其名为缺省值 |
| | | // 如要新建一名为"效益指标"的工作表,其语句为: |
| | | // HSSFSheet sheet = workbook.createSheet("效益指标"); |
| | | HSSFSheet sheet = workbook.createSheet(); |
| | | // 在索引0的位置创建行(最顶端的行) |
| | | HSSFRow row = sheet.createRow(0); |
| | | // =============================================================== |
| | | for (int i = 0; i < headList.length; i++) { |
| | | |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | | cell.setCellValue(headList[i]); |
| | | } |
| | | // =============================================================== |
| | | if (dataList != null) { |
| | | for (int n = 0; n < dataList.size(); n++) { |
| | | // 在索引1的位置创建行 |
| | | HSSFRow row_value = sheet.createRow(n + 1); |
| | | Map<String, Object> dataMap = dataList.get(n); |
| | | // =============================================================== |
| | | for (int i = 0; i < fieldList.length; i++) { |
| | | // 在索引0的位置创建单元格(左上端) |
| | | HSSFCell cell = row_value.createCell(i); |
| | | // 定义单元格为字符串类型 |
| | | cell.setCellType(HSSFCell.CELL_TYPE_STRING); |
| | | // 在单元格中输入一些内容 |
| | | cell.setCellValue(objToString(dataMap.get(fieldList[i]))); |
| | | } |
| | | // =============================================================== |
| | | } |
| | | } |
| | | |
| | | // 新建一输出文件流 |
| | | FileOutputStream fOut = new FileOutputStream(file); |
| | | // 把相应的Excel 工作簿存盘 |
| | | workbook.write(fOut); |
| | | fOut.flush(); |
| | | // 操作结束,关闭文件 |
| | | fOut.close(); |
| | | }catch (Exception e){ |
| | | |
| | | }finally { |
| | | file.deleteOnExit(); |
| | | } |
| | | return file; |
| | | } |
| | | |
| | | |
| | | private static String objToString(Object obj) { |
| | | if (obj == null) { |
| | | return ""; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.net.FileNameMap; |
| | | import java.net.URLConnection; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | |
| | | } |
| | | } |
| | | |
| | | /**视频上传的方法 |
| | | * 保存到服务器里面的 |
| | | * @param platformIconFile 视频文件 |
| | | * @param unifiedFolder NG指向的前端文件夹(统一文件夹),如:user/local/images/ |
| | | * @param saveFolder 保存到的文件夹,如:/bananer/ |
| | | * @param autoDateFolder 是否生成日期文件夹 |
| | | * @return 图片路径 |
| | | * 2020-06-29 ChenJiaHe |
| | | */ |
| | | public static String videoFileUpload(MultipartFile platformIconFile,String unifiedFolder,String saveFolder |
| | | ,boolean autoDateFolder) { |
| | | String fileName = ""; |
| | | try { |
| | | if(platformIconFile == null) { |
| | | throw new TipsException("请上传视频文件!"); |
| | | } |
| | | if(!getMimeType(platformIconFile.getOriginalFilename())){ |
| | | throw new TipsException("请上传视频格式的文件!"); |
| | | } |
| | | |
| | | //设置图片大小 |
| | | // String.format("%.1f",platformIconFile.getSize()/1024.0); |
| | | if(autoDateFolder){ |
| | | if(saveFolder.endsWith("/")){ |
| | | saveFolder = saveFolder+dateFormat(new Date(),"yyyyMM")+"/"; |
| | | }else{ |
| | | saveFolder = saveFolder+"/"+dateFormat(new Date(),"yyyyMM")+"/"; |
| | | } |
| | | } |
| | | fileName = dateFormat(new Date(),"yyyyMMddHHmmssSSS"); |
| | | if(unifiedFolder.endsWith("/")){ |
| | | if(saveFolder.startsWith("/")){ |
| | | saveFolder = saveFolder.replaceFirst("/",""); |
| | | unifiedFolder = unifiedFolder + saveFolder; |
| | | }else{ |
| | | unifiedFolder = unifiedFolder+saveFolder; |
| | | } |
| | | }else{ |
| | | if(saveFolder.startsWith("/")){ |
| | | unifiedFolder = unifiedFolder + saveFolder; |
| | | }else{ |
| | | unifiedFolder = unifiedFolder+"/"+saveFolder; |
| | | } |
| | | } |
| | | fileName = saveFolder+fileUp(platformIconFile,unifiedFolder,fileName); |
| | | } catch (RuntimeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return fileName; |
| | | } |
| | | |
| | | /**图片上传的方法 |
| | | * 保存到服务器里面的 |
| | | * @param platformIconFile 图片文件 |
| | |
| | | return targetFile; |
| | | } |
| | | |
| | | /**判断是不是视频文件 |
| | | * @param fileName 文件名称 |
| | | * @return boolean true是视频文件 |
| | | */ |
| | | public static boolean getMimeType(String fileName) { |
| | | boolean b = false; |
| | | FileNameMap fileNameMap = URLConnection.getFileNameMap(); |
| | | String type = fileNameMap.getContentTypeFor(fileName); |
| | | //是视频type是为空的 |
| | | if(StringUtils.isEmpty(type)) { |
| | | b = true; |
| | | } |
| | | return b; |
| | | } |
| | | |
| | | /** |
| | | * 判断是否为视频 |
| | | * @param fileName |
| | | * @return |
| | | */ |
| | | public static String isVideo(String fileName) { |
| | | FileNameMap fileNameMap = URLConnection.getFileNameMap(); |
| | | String type = fileNameMap.getContentTypeFor(fileName); |
| | | return type; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.activation.MimetypesFileTypeMap; |
| | | import javax.servlet.ServletInputStream; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.*; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | |
| | | /**回车换行,用于一行的结尾*/ |
| | | private static final String LINE_END = "\r\n"; |
| | | |
| | | public static String getInputStream(HttpServletRequest request) throws Exception { |
| | | ServletInputStream stream = null; |
| | | BufferedReader reader = null; |
| | | StringBuffer sb = new StringBuffer(); |
| | | try { |
| | | stream = request.getInputStream(); |
| | | // 获取响应 |
| | | reader = new BufferedReader(new InputStreamReader(stream)); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | sb.append(line); |
| | | } |
| | | } catch (IOException e) { |
| | | //logger.error(e); |
| | | throw new RuntimeException("读取返回支付接口数据流出现异常!"); |
| | | } finally { |
| | | reader.close(); |
| | | } |
| | | //logger.info("输入流返回的内容:" + sb.toString()); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public static String post(String requestUrl, String accessToken, String params) |
| | | throws Exception { |
| | |
| | | // //System.out.println("HttpURLUtil:"+wxMsgXml); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | obj = new JSONObject(); |
| | | try { |
| | | obj.put("status", 1); |
| | | obj.put("errMsg", e.getMessage()); |
| | | } catch (JSONException e1) { |
| | | e1.printStackTrace(); |
| | | } |
| | | } finally { |
| | | if (con != null) { |
| | | con.disconnect(); |
New file |
| | |
| | | package com.hx.util; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | /** |
| | | * @author ChenJiaHe |
| | | * @date 2020-12-2 |
| | | */ |
| | | public class IPUtils { |
| | | |
| | | /**获取访问ip地址*/ |
| | | public static String getIpAddr(HttpServletRequest request) { |
| | | String ip=request.getHeader("x-forwarded-for"); |
| | | if(null!=ip && ip.length()!=0 && !"unknown".equalsIgnoreCase(ip)) { |
| | | if(ip.indexOf(",")!=-1) { |
| | | ip=ip.split(",")[0]; |
| | | } |
| | | } |
| | | if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip=request.getHeader("Proxy-Client-Ip"); |
| | | } |
| | | if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip=request.getHeader("WL-Proxy-Client-IP"); |
| | | } |
| | | if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip=request.getHeader("HTTP_CLIENT_IP"); |
| | | } |
| | | if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip=request.getHeader("HTTP_X_FORWARDED_FOR"); |
| | | } |
| | | if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip=request.getHeader("X-Real-IP"); |
| | | } |
| | | if(ip==null || ip.length()==0 || "unknown".equalsIgnoreCase(ip)) { |
| | | ip=request.getRemoteAddr(); |
| | | } |
| | | return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip; |
| | | |
| | | } |
| | | } |
| | |
| | | if(SimpleTool.checkNotNull(arrString)){ |
| | | JSONArray images = JSONArray.fromObject(arrString); |
| | | for(int i = 0;i<images.size();i++){ |
| | | if(images.getString(i).indexOf("http")!=-1){ |
| | | if(images.getString(i).startsWith("http")){ |
| | | arr.add(images.getString(i)); |
| | | }else{ |
| | | arr.add(urlAddDomain(images.getString(i),domainName)); |
| | |
| | | JSONArray arr = new JSONArray(); |
| | | if(SimpleTool.checkNotNull(imagesArr)){ |
| | | for(int i = 0;i<imagesArr.size();i++){ |
| | | if(imagesArr.getString(i).indexOf("http")!=-1){ |
| | | if(imagesArr.getString(i).startsWith("http")){ |
| | | arr.add(imagesArr.getString(i)); |
| | | }else{ |
| | | arr.add(urlAddDomain(imagesArr.getString(i),domainName)); |
| | |
| | | return imagesUrl; |
| | | } |
| | | if(SimpleTool.checkNotNull(imagesUrl)){ |
| | | if(imagesUrl.indexOf("http")!=-1){ |
| | | if(imagesUrl.startsWith("http")){ |
| | | return imagesUrl; |
| | | } |
| | | if(domainName.endsWith("/")){ |
| | |
| | | |
| | | import java.awt.*; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | } |
| | | |
| | | /** |
| | | * zxing方式生成二维码 |
| | | * zxing方式生成二维码(返回base64) |
| | | * 注意: |
| | | * 1,文本生成二维码的方法独立出来,返回image流的形式,可以输出到页面 |
| | | * 2,设置容错率为最高,一般容错率越高,图片越不清晰, 但是只有将容错率设置高一点才能兼容logo图片 |
| | | * 3,logo图片默认占二维码图片的20%,设置太大会导致无法解析 |
| | | * |
| | | * @param content 二维码包含的内容,文本或网址 |
| | | * @param size 生成的二维码图片尺寸 可以自定义或者默认(250) |
| | | * @param logoPath logo的存放位置 |
| | | */ |
| | | public static String QRCodeCreate(String content, Integer size, String logoPath) { |
| | | ByteArrayOutputStream bos = null; |
| | | if(size == null){ |
| | | size = 400; |
| | | } |
| | | try{ |
| | | char[] rands = content.toCharArray(); |
| | | //获取二维码流的形式,写入到目录文件中 |
| | | BufferedImage image = getBufferedImage(content, size, logoPath); |
| | | bos = new ByteArrayOutputStream(); |
| | | ImageIO.write(image, "JPEG", bos); |
| | | byte[] buf = bos.toByteArray(); |
| | | return Base64.getEncoder().encodeToString(buf); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | }finally { |
| | | if(bos != null) { |
| | | try { |
| | | bos.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | bos = null; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * zxing方式生成二维码(返回路径) |
| | | * 注意: |
| | | * 1,文本生成二维码的方法独立出来,返回image流的形式,可以输出到页面 |
| | | * 2,设置容错率为最高,一般容错率越高,图片越不清晰, 但是只有将容错率设置高一点才能兼容logo图片 |
| | |
| | | import java.text.DecimalFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.GregorianCalendar; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | |
| | | public static SimpleDateFormat myformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | public static DecimalFormat fmt = new DecimalFormat("0.00"); |
| | | public static Byte[] lock = new Byte[] {0}; |
| | | |
| | | |
| | | /**对象转map*/ |
| | | public static Map<?, ?> objectToMap(Object obj) { |
| | | if(obj == null) |
| | | return null; |
| | | |
| | | return new org.apache.commons.beanutils.BeanMap(obj); |
| | | } |
| | | |
| | | /** |
| | | * 后台格式构建返回值格式列表-后台获取列表 |
| | | * @param count 返回总条数 |
| | |
| | | return null == str || str.trim().length() == 0 || "undefined".equals(str); |
| | | } |
| | | |
| | | /**判断空*/ |
| | | public static boolean isNull(String str) { |
| | | return null == str || str.trim().length() == 0 || "undefined".equals(str); |
| | | } |
| | | |
| | | /**判断非空*/ |
| | | public static boolean noNull(String str) { |
| | | return null != str && str.trim().length() != 0 && !"undefined".equals(str); |
| | | } |
| | | |
| | | /** |
| | | * 判断字符内容中是否存在一个为空的字符�? |
| | | * <p> |
New file |
| | |
| | | package com.hx.util.gaode; |
| | | |
| | | /** |
| | | * 获取地址经纬度 |
| | | * 响应实体化 |
| | | */ |
| | | public class AddressCode { |
| | | |
| | | /**经度*/ |
| | | private String lng; |
| | | /**维度*/ |
| | | private String lat; |
| | | /**城市编码*/ |
| | | private String cityCode; |
| | | |
| | | public AddressCode() { |
| | | } |
| | | |
| | | public String getLng() { |
| | | return lng; |
| | | } |
| | | |
| | | public void setLng(String lng) { |
| | | this.lng = lng; |
| | | } |
| | | |
| | | public String getLat() { |
| | | return lat; |
| | | } |
| | | |
| | | public void setLat(String lat) { |
| | | this.lat = lat; |
| | | } |
| | | |
| | | public String getCityCode() { |
| | | return cityCode; |
| | | } |
| | | |
| | | public void setCityCode(String cityCode) { |
| | | this.cityCode = cityCode; |
| | | } |
| | | } |
New file |
| | |
| | | package com.hx.util.gaode; |
| | | |
| | | import com.hx.util.HttpUtil; |
| | | import com.hx.util.StringUtils; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | |
| | | /** |
| | | * 高德地图工具 |
| | | * @author mgchen |
| | | * |
| | | */ |
| | | public class GaoDeMapUtil { |
| | | |
| | | /**获取经纬度*/ |
| | | public static String URL_CODE = "https://restapi.amap.com/v3/geocode/geo"; |
| | | |
| | | /** |
| | | * 获取地址的经纬度 |
| | | * @param address |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public static AddressCode addressCode(String address,String key) { |
| | | AddressCode addressCode = null; |
| | | //URL_CODE = URL_CODE+"?key="+key+"&address="+URLEncoder.encode(address,"UTF-8");//地址编译 |
| | | URL_CODE = URL_CODE+"?key="+key+"&address="+address; |
| | | JSONObject data = HttpUtil.HttpURLUtil(URL_CODE,null); |
| | | if(data.optInt("status",0) == 1){ |
| | | JSONArray geocodes = data.getJSONArray("geocodes"); |
| | | if(geocodes.size()==1){ |
| | | JSONObject locationObj = geocodes.getJSONObject(0); |
| | | String location = locationObj.optString("location"); |
| | | if(StringUtils.noNull(location)){ |
| | | String[] locations = location.split(","); |
| | | if(locations.length != 2){ |
| | | return null; |
| | | } |
| | | addressCode = new AddressCode(); |
| | | addressCode.setLng(locations[0]); |
| | | addressCode.setLat(locations[1]); |
| | | addressCode.setCityCode(locationObj.optString("citycode")); |
| | | } |
| | | } |
| | | } |
| | | return addressCode; |
| | | } |
| | | |
| | | |
| | | } |