Commit 9007fe44 by java-李谡

初始化配置

parent 89edbb59
......@@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.foc</groupId>
<artifactId>stattistic</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>task</artifactId>
<version>3.0-SNAPSHOT</version>
<properties>
<!-- log4j日志文件管理包版本 -->
......@@ -57,17 +57,15 @@
<version>1.2.7</version>
</dependency>
<!-- 封装实体依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.5.RELEASE</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.6</version>
</dependency>
<!-- 封装实体依赖 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
</dependencies>
<build>
<plugins>
......@@ -87,7 +85,7 @@
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.sms.statistic.StatisticTask</mainClass>
<mainClass>com.foc.DbSoundsMonitorTask</mainClass>
</transformer>
</transformers>
</configuration>
......
package com.foc;
/**
* @Author: lisu
* @Date: 2019/4/29 15:35
* @Description: 安科录音同步任务及数据源监控
* 1.查看定时任务最后同步时间
* 2.查看是否有录音文件记录
* 3.查看安科数据库最后一条数据
*/
public class DbSoundsMonitorTask {
public static void main(String[] args) {
//查看定时任务最后同步时间
}
}
package com.foc.dao;
import com.foc.entity.SoundsMaxId;
/**
* @Author: lisu
* @Date: 2019/4/29 16:23
* @Description: java类作用描述
*/
public interface SoundsMaxIdDao {
/**
* 获取最后更新记录
*
* @return
*/
SoundsMaxId getMaxId();
}
package com.bbd.entity;
import com.sun.istack.internal.NotNull;
package com.foc.entity;
/**
* 短信公共参数
......
package com.foc.entity;
import lombok.Data;
/**
* @Author: lisu
* @Date: 2019/4/29 16:25
* @Description: foc_soundmax_id表实体
*/
@Data
public class SoundsMaxId {
/**
* 主键ID
*/
private long id;
/**
* 更新时间
*/
private String updateDate;
}
package com.bbd.email;
package com.foc.service;
import com.bbd.utils.Coder;
import com.bbd.utils.PropertiesUtil;
import com.foc.util.Coder;
import com.foc.util.PropertiesUtil;
import com.opendata.api.ODPRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Properties;
import java.io.File;
import java.util.*;
/**
* 发邮件
......@@ -18,6 +19,20 @@ public class Email {
private static final Logger logger = LoggerFactory.getLogger(Email.class);
//正式环境服务接口请用调用地址 http://esb.hna.net/api
//测试环境服务接口请用调用地址 http://10.70.72.110/api/inner/ESBService
//API服务接口请求调用地址,查看说明文档
/**
* URL: API服务接口请求调用地址,查看说明文档
* method: API接口名称,查看个人订单-接口名称
* Appsecret: app密钥,查看个人中心-app key
* AccessToken: 应用票据,查看个人中心-app key
*/
String URL = "http://10.70.72.110/api/inner/ESBService";
String method = "Exchange_MailService_SendMail";
String Appsecret = "9eztwb08qdvkzk0zadzdvtl6j1bssqvp";
String AccessToken = "A6BD747ECB212285E6DC3528EFB482AF04B40F17";
/**
* 发送邮件
*
......@@ -77,4 +92,39 @@ public class Email {
return res;
}
public void testEmail() throws Exception {
//拼装附件mapList
List<Object> mapList = new ArrayList<Object>();
Map<String, String> map = new HashMap<String, String>();
Map<String, Object> mapAttachment = new HashMap<String, Object>();
Map<String, Object> mapAttachment2 = new HashMap<String, Object>();
map.put("FileName", "附件1.txt");//文件名称
map.put("Content", Coder.getBASE64("这是附件1的内容."));//文件内容:需要字节流的base64编码值
mapAttachment.put("Attachment", map);
mapList.add(mapAttachment);
Map<String, String> map2 = new HashMap<String, String>();
map2.put("FileName", "IMG_2005.PNG");
map2.put("Content", Coder.fileCode("E:" + File.separator + "IMG_2005.PNG"));
mapAttachment2.put("Attachment", map2);
mapList.add(mapAttachment2);
String res = new ODPRequest(URL, Appsecret)
.addTextSysPara("Method", method)
.addTextSysPara("AccessToken", AccessToken)
.addTextSysPara("Format", "json")
//应用参数
.addTextAppPara("From", "sdhkyxglzx@hnair.com")//邮件服务发件人参数//sdhkyxglzx@hnair.com
.addTextAppPara("To", "chl.zhou@hnair.com")//邮件服务收件人参数
.addTextAppPara("UserName", "sdhkyxglzx")//发件人的内网账号
.addTextAppPara("UserPwd", Coder.getBASE64("075.wxp"))//发件人的密码,需要base64编码
.addTextAppPara("Subject", "邮件标题-测试")//邮件标题
.addTextAppPara("Body", Coder.getBASE64("邮件正文,测试英文字符:You and me are working in the same organization for the same purpose."))//邮件内容参数,需要base64编码
// .addTextAppPara("Attachments", mapList)//附件
.post();
System.out.println(res);
}
}
package com.bbd.sms;
package com.foc.service;
import com.bbd.entity.AccessInfo;
import com.bbd.utils.HttpClientUtils;
import com.bbd.utils.PropertiesUtil;
import com.bbd.utils.StringUtils;
import com.foc.entity.AccessInfo;
import com.foc.util.PropertiesUtil;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
......@@ -27,12 +25,12 @@ public class Sms {
/**
* 发送短信
*
* @param accessInfo 接口公共信息
* @param mobile 手机号
* @param msg 短信内容
* @param accessInfo 接口公共信息
* @param mobile 手机号
* @param msg 短信内容
* @return
*/
public static String sendSms(AccessInfo accessInfo,String mobile,String msg){
public static String sendSms(AccessInfo accessInfo, String mobile, String msg) {
//读取配置文件
Properties properties = PropertiesUtil.getProperties();
String smsUrl = properties.getProperty("smsUrl");
......@@ -43,10 +41,10 @@ public class Sms {
try {
HttpPost httpPost = new HttpPost(smsUrl + "?ai.cp=" + accessInfo.getAicp() + "&ai.cc=" + accessInfo.getAicc()
+ "&mobile=" + mobile + "&msg=" + msg);
+ "&mobile=" + mobile + "&msg=" + msg);
HttpResponse response = httpClient.execute(httpPost);
logger.info(response.toString());
}catch (Exception ex){
} catch (Exception ex) {
ex.printStackTrace();
}
......@@ -67,7 +65,7 @@ public class Sms {
accessInfo.setAicc("5");
accessInfo.setAicp("123.56.146.7");
// accessInfo.setAict("21");
String res = Sms.sendSms(accessInfo,"13222650486","HelloWorld");
String res = Sms.sendSms(accessInfo, "13222650486", "HelloWorld");
System.out.println(res);
}
}
package com.foc.service;
import com.foc.dao.SoundsMaxIdDao;
import com.foc.entity.SoundsMaxId;
import lombok.extern.log4j.Log4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.Reader;
import java.util.Date;
/**
* @Author: lisu
* @Date: 2019/4/29 16:35
* @Description: 安库录音服务监控任务
*/
@Log4j
public class SoundMonitorService {
private Reader reader;
private SqlSessionFactory sqlSessionFactory;
private SqlSession session;
public void init() {
try {
reader = Resources.getResourceAsReader("mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
session = sqlSessionFactory.openSession();
} catch (IOException e) {
log.error("连接数据库异常");
e.printStackTrace();
} finally {
session.close();
}
}
public void test() {
SoundsMaxIdDao soundsMaxIdDao = session.getMapper(SoundsMaxIdDao.class);
SoundsMaxId maxId = soundsMaxIdDao.getMaxId();
String updateTime = maxId.getUpdateDate();
log.info("当前系统时间:" + new Date());
//比较时间,如果相差20分钟没有执行
}
}
package com.bbd.utils;
package com.foc.util;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.*;
public class Coder {
// 将 s 进行 BASE64 编码
public static String getBASE64(byte[] s) {
if (s == null)
return null;
return (new sun.misc.BASE64Encoder()).encode(s);
}
/**
* 将 s 进行 BASE64 编码
*/
public static String getBASE64(byte[] s) {
if (s == null) {
return null;
}
return (new BASE64Encoder()).encode(s);
}
// 将 s 进行 BASE64 编码
public static String getBASE64(String s) {
if (s == null)
return null;
return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
}
public static String getBASE64(String s) {
if (s == null) {
return null;
}
return (new BASE64Encoder()).encode(s.getBytes());
}
// 将 BASE64 编码的字符串 s 进行解码
public static String getFromBASE64(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
// 将 BASE64 编码的字符串 s 进行解码
public static String getFromBASE64(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
public static String fileCode(String fileurl) throws Exception {
String result = null;
// 第1步、使用File类找到一个文件
File f = new File(fileurl); // 声明File对象
// 第2步、通过子类实例化父类对象
InputStream input = null; // 准备好一个输入的对象
input = new FileInputStream(f); // 通过对象多态性,进行实例化
// 第3步、进行读操作
// byte b[] = new byte[input..available()] ; 跟使用下面的代码是一样的
byte b[] = new byte[(int) f.length()]; // 数组大小由文件决定
int len = input.read(b); // 读取内容
// 第4步、关闭输出流
input.close(); // 关闭输出流\
public static String fileCode(String fileurl) throws Exception {
String result = null;
// 第1步、使用File类找到一个文件
File f = new File(fileurl); // 声明File对象
// 第2步、通过子类实例化父类对象
InputStream input = null; // 准备好一个输入的对象
input = new FileInputStream(f); // 通过对象多态性,进行实例化
// 第3步、进行读操作
// byte b[] = new byte[input..available()] ; 跟使用下面的代码是一样的
byte b[] = new byte[(int) f.length()]; // 数组大小由文件决定
int len = input.read(b); // 读取内容
// 第4步、关闭输出流
input.close(); // 关闭输出流\
// System.out.println("读入数据的长度:" + len);
result = Coder.getBASE64(b);
result = Coder.getBASE64(b);
// System.out.println("内容为:" + result); // 把byte数组变为字符串输出
return result;
}
return result;
}
public static String fileStringCode(String fileurl) throws Exception {
String result = "";
String encoding = "GBK";
File file = new File(fileurl);
if (file.isFile() && file.exists()) { //判断文件是否存在
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
result += lineTxt;
}
public static String fileStringCode(String fileurl) throws Exception {
String result = "";
String encoding = "GBK";
File file = new File(fileurl);
if (file.isFile() && file.exists()) { //判断文件是否存在
InputStreamReader read = new InputStreamReader(new FileInputStream(file), encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while ((lineTxt = bufferedReader.readLine()) != null) {
result += lineTxt;
}
// System.out.println("内容为:" + result);
read.close();
}
return result;
}
read.close();
}
return result;
}
}
package com.bbd.utils;
package com.foc.util;
import com.google.common.collect.Lists;
import org.apache.http.Header;
......
package com.bbd.utils;
package com.foc.util;
import java.io.InputStream;
import java.util.Properties;
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.foc.dao.SoundsMaxIdDao">
<select id="getMaxId" resultType="com.foc.entity.SoundsMaxId">
SELECT MAX(id),update_date FROM `foc_soundmax_id`
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- 全局参数 -->
<settings>
<!-- 使全局的映射器启用或禁用缓存。 -->
<setting name="cacheEnabled" value="true"/>
<!-- 全局启用或禁用延迟加载。当禁用时,所有关联对象都会即时加载。 -->
<setting name="lazyLoadingEnabled" value="true"/>
<!-- 当启用时,有延迟加载属性的对象在被调用时将会完全加载任意属性。否则,每种属性将会按需要加载。 -->
<setting name="aggressiveLazyLoading" value="true"/>
<!-- 是否允许单条sql 返回多个数据集 (取决于驱动的兼容性) default:true -->
<setting name="multipleResultSetsEnabled" value="true"/>
<!-- 是否可以使用列的别名 (取决于驱动的兼容性) default:true -->
<setting name="useColumnLabel" value="true"/>
<!-- 允许JDBC 生成主键。需要驱动器支持。如果设为了true,这个设置将强制使用被生成的主键,有一些驱动器不兼容不过仍然可以执行。 default:false -->
<setting name="useGeneratedKeys" value="false"/>
<!-- 指定 MyBatis 如何自动映射 数据基表的列 NONE:不隐射 PARTIAL:部分 FULL:全部 -->
<setting name="autoMappingBehavior" value="PARTIAL"/>
<!-- 这是默认的执行类型 (SIMPLE: 简单; REUSE: 执行器可能重复使用prepared statements语句;BATCH: 执行器可以重复执行语句和批量更新) -->
<setting name="defaultExecutorType" value="SIMPLE"/>
<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 设置本地缓存范围 session:就会有数据的共享 statement:语句范围 (这样就不会有数据的共享 ) defalut:session -->
<setting name="localCacheScope" value="SESSION"/>
<!-- 设置但JDBC类型为空时,某些驱动程序 要指定值,default:OTHER,插入空值时不需要指定类型 -->
<setting name="jdbcTypeForNull" value="NULL"/>
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
<environments default="dev">
<environment id="dev">
<transactionManager type="JDBC"/>
<!-- 配置数据库连接信息 -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/sms"/>
<property name="username" value="sms_develop"/>
<property name="password" value="Develop2018!@#"/>
</dataSource>
</environment>
<environment id="prod">
<transactionManager type="JDBC"/>
<!-- 配置数据库连接信息 -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://sms.db.com:3306/sms"/>
<property name="username" value="sms_develop"/>
<property name="password" value="Develop2018!@#"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper/SoundsMaxIdMapper.xml"/>
</mappers>
</configuration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment