Commit 4d064360 by java-李谡

开发航线监控定时

parent 95690c91
package com.foc;
import com.foc.service.DynamicFlightService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author LEGION
*/
public class StatisticalTask {
private static final Logger log = LoggerFactory.getLogger(StatisticalTask.class);
public static void main(String[] args) {
DynamicFlightService.init();
DynamicFlightService.sta();
}
}
package com.foc.dao;
import com.foc.entity.StatisticalEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author LEGION
*/
public interface StatisticalDao {
/**
* 获取所有类型为J,状态为ATA的航线
*
* @return
*/
List<StatisticalEntity> getFlightList();
/**
* 根据起飞地和到达地获取航线最近时间
*
* @param entity
* @param acTypes
* @return
*/
String getFlightByDepAndArr(@Param(value = "entity") StatisticalEntity entity, @Param(value = "acTypes") List acTypes);
/**
* 根据论证机型获取小机型
*
* @param verifyAcType
* @return
*/
List<String> getLacTypesByVerifyAcType(String verifyAcType);
/**
* 根据论证机型获取小机型
* @param verifyAcTypes
* @return
*/
List<String> getLacTypesByVerifyAcTypes(List<String> verifyAcTypes);
/**
* 查询开航指令
*
* @param entity
* @param verifyAcType
* @return
*/
int getSailingCommand(@Param(value = "entity") StatisticalEntity entity, @Param(value = "verifyAcType") String verifyAcType);
/**
* 批量新增或修改
*
* @param list
*/
void insertOrUpdateBatch(List<StatisticalEntity> list);
}
package com.foc.entity;
import lombok.Data;
/**
* @author LEGION
*/
@Data
public class AcType {
String type;
String lastTime;
String status;
}
package com.foc.entity;
import lombok.Data;
/**
* @author LEGION
*/
@Data
public class StatisticalEntity {
private String id;
private String arrIata;
private String arrIataName;
private String depIata;
private String depIataName;
private String lastAirlineTime;
private String updateTime;
private String airlineJson;
private Integer delFlag;
}
package com.foc.service;
import com.alibaba.fastjson.JSON;
import com.foc.dao.StatisticalDao;
import com.foc.entity.AcType;
import com.foc.entity.StatisticalEntity;
import com.foc.util.DateUtils;
import com.foc.util.PropertiesUtils;
import com.foc.util.StringUtils;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
/**
* @author LEGION
*/
public class DynamicFlightService {
private static final Logger log = LoggerFactory.getLogger(DynamicFlightService.class);
private static Reader reader;
private static SqlSessionFactory sqlSessionFactory;
private static SqlSession session;
public static void init() {
try {
reader = Resources.getResourceAsReader("mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
session = sqlSessionFactory.openSession();
} catch (IOException e) {
log.error("连接数据库异常");
e.printStackTrace();
}
}
public static void sta() {
//从配置文件中获取需要统计的大机型
Properties properties = PropertiesUtils.getProperties();
String verifyAcType = properties.getProperty("verifyAcType");
if (StringUtils.isEmpty(verifyAcType)) {
log.error("获取配置文件中机型的文件");
return;
}
List<String> verifyAcTypes = Arrays.asList(verifyAcType.split(","));
StatisticalDao dao = session.getMapper(StatisticalDao.class);
//获取航班动态表中所有航班性质为J,状态为ATA,机型为319/A320,321,320neo,330的航线的最后一班时间
List<StatisticalEntity> list = dao.getFlightList();
List<StatisticalEntity> slist = new ArrayList<>();
List<String> acTypes = dao.getLacTypesByVerifyAcTypes(verifyAcTypes);
list.forEach(e -> {
//获取该航线所有论证机型(319/A320,321,320neo,330)的最后执行时间(实际起飞时间)
String lastDate = dao.getFlightByDepAndArr(e, acTypes);
StatisticalEntity entity = new StatisticalEntity();
entity.setArrIata(e.getArrIata());
entity.setArrIataName(e.getArrIataName());
entity.setDepIata(e.getDepIata());
entity.setDepIataName(e.getDepIataName());
entity.setLastAirlineTime(lastDate);
List<AcType> acTypeList = new ArrayList<>();
//遍历论证机型查询对应小机型
for (String str : verifyAcTypes) {
AcType acType = new AcType();
acType.setType(str);
List<String> lacTypes = dao.getLacTypesByVerifyAcType(str);
if (CollectionUtils.isEmpty(lacTypes)) {
continue;
}
//获取该航线特定机型下的最后执行时间
String acTypeLastTime = dao.getFlightByDepAndArr(e, lacTypes);
if (StringUtils.isEmpty(acTypeLastTime)) {
int count = dao.getSailingCommand(e, str);
//查询开航指令,有的话为可用
if (count != 0) {
acType.setStatus("2");
//没有开航指令为不可用
} else {
acType.setStatus("3");
}
acType.setLastTime("");
} else {
acType.setStatus("1");
acType.setLastTime(acTypeLastTime);
}
acTypeList.add(acType);
}
entity.setAirlineJson(JSON.toJSONString(acTypeList));
entity.setUpdateTime(DateUtils.getTime("yyyy-MM-dd hh:mm:ss"));
entity.setDelFlag(0);
slist.add(entity);
});
dao.insertOrUpdateBatch(slist);
session.commit();
}
}
package com.foc.util;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
......@@ -16,4 +17,9 @@ public class DateUtils {
public static long until(LocalDateTime time) {
return Math.abs(LocalDateTime.now().until(time, ChronoUnit.MINUTES));
}
public static String getTime(String formatType) {
SimpleDateFormat format = new SimpleDateFormat(formatType);
return format.format(System.currentTimeMillis());
}
}
......@@ -25,4 +25,5 @@ aict=1
toEmail=zangtao@bbdtek.com
#,lisu@bbdtek.com
#lisu@bbdtek.com
fromName=sdhkxxaq
\ No newline at end of file
fromName=sdhkxxaq
verifyAcType=A319/A320,A321,A320neo,A330
\ No newline at end of file
<?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.StatisticalDao">
<select id="getFlightList" resultType="com.foc.entity.StatisticalEntity">
SELECT
d.dep_stn AS depIata,
a.city_name AS depIataName,
d.arr_stn AS arrIata,
fa.city_name AS arrIataName
FROM
foc_flight_dynamics d
LEFT JOIN foc_airports a ON d.dep_stn = a.airport_iata
LEFT JOIN foc_airports fa ON d.arr_stn = fa.airport_iata
WHERE
d.`status` = 'ATA'
AND d.`stc` = 'J'
GROUP BY
d.dep_stn,
d.arr_stn
</select>
<select id="getFlightByDepAndArr" resultType="string">
SELECT
DATE_FORMAT(atd,'%Y/%m/%d') as lastAirlineTime
from foc_flight_dynamics
where dep_stn=#{entity.depIata} and arr_stn=#{entity.arrIata}
and ac_type in
<foreach item="acType" collection="acTypes" separator="," open="(" close=")" index="">
#{acType}
</foreach>
order by atd desc limit 1;
</select>
<select id="getLacTypesByVerifyAcType" resultType="string">
SELECT
ac_type
from foc_ac_type_compare
where
verify_ac_type=#{verifyAcType}
</select>
<select id="getLacTypesByVerifyAcTypes" resultType="string">
SELECT
ac_type
from foc_ac_type_compare
where
verify_ac_type in
<foreach collection="list" item="item" index="index" separator="," open="(" close=")" >
#{item}
</foreach>
</select>
<select id="getSailingCommand" resultType="int">
SELECT
count(*)
from foc_sailing_command sc
left join foc_airline_verify a on a.id = sc.verif_id
left join foc_aircraft_type b on a.aircraft_type = b.id
where a.verif_status='02' AND a.del_flag = 0
and a.depIata=#{entity.depIata} and a.arrIata=#{entity.arrIata}
and b.id=#{verifyAcType}
</select>
<insert id="insertOrUpdateBatch" parameterType="java.util.List">
INSERT INTO foc_airline_sta
(arr_iata, arr_iata_name, dep_iata, dep_iata_name, last_airline_time, airline_json, update_date, del_flag)
VALUES
<foreach collection="list" item="item" index="index" separator="," >
(
#{item.arrIata}
, #{item.arrIataName}
, #{item.depIata}
, #{item.depIataName}
, #{item.lastAirlineTime}
, #{item.airlineJson}
, #{item.updateTime}
, #{item.delFlag}
)
</foreach>
ON DUPLICATE KEY UPDATE
last_airline_time = values(last_airline_time)
, airline_json = values(airline_json)
, update_date = values(update_date)
</insert>
</mapper>
\ No newline at end of file
......@@ -45,11 +45,11 @@
<transactionManager type="JDBC"/>
<!-- 配置数据库连接信息 -->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://106.75.97.50:3306/jd_foc?serverTimezone=CTT&amp;useUnicode=true&amp;characterEncoding=utf-8"/>
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://106.75.105.96:5508/jd_foc?serverTimezone=CTT&amp;useUnicode=true&amp;characterEncoding=utf-8"/>
<!-- <property name="url" value="jdbc:mysql://mysql_server:3306/foc?serverTimezone=CTT&amp;useUnicode=true&amp;characterEncoding=utf-8"/>-->
<property name="username" value="focuser"/>
<property name="password" value="FOC@2016"/>
<property name="username" value="sms_develop"/>
<property name="password" value="Develop2018!@#"/>
</dataSource>
</environment>
......@@ -59,6 +59,7 @@
<mappers>
<mapper resource="mapper/SoundsMaxIdMapper.xml"/>
<mapper resource="mapper/BlackIpMapper.xml"/>
<mapper resource="mapper/StatisticalMapper.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