作者 张天舒

WebService 提供航班时间

正在显示 76 个修改的文件 包含 1359 行增加0 行删除
Manifest-Version: 1.0
Class-Path:
... ...
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>flight</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/applicationContext.xml,
classpath:config/applicationContext-webservice.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
\ No newline at end of file
... ...
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
this is a page
</body>
</html>
\ No newline at end of file
... ...
/com/
/config/
/sqlMapper/
... ...
package com.tianbo.flight.dao;
import java.util.Map;
import com.tianbo.flight.entity.Flight;
public interface FlightDao {
public Flight getTime(Map<String,String> map);
public Flight getLastTime(Map<String, String> map);
}
... ...
package com.tianbo.flight.entity;
import java.math.BigDecimal;
import java.util.Date;
public class Flight {
private BigDecimal fid;
private BigDecimal flid;
private String fatt;
private String ffid;
private String stat;
private String ista;
private Date past;
private Date eldt;
private String msta;
private String mist;
private BigDecimal messageBakId;
private String flightnum;
private String impexp;
private BigDecimal state;
private String sendtime;
public BigDecimal getFid() {
return fid;
}
public void setFid(BigDecimal fid) {
this.fid = fid;
}
public BigDecimal getFlid() {
return flid;
}
public void setFlid(BigDecimal flid) {
this.flid = flid;
}
public String getFatt() {
return fatt;
}
public void setFatt(String fatt) {
this.fatt = fatt == null ? null : fatt.trim();
}
public String getFfid() {
return ffid;
}
public void setFfid(String ffid) {
this.ffid = ffid == null ? null : ffid.trim();
}
public String getStat() {
return stat;
}
public void setStat(String stat) {
this.stat = stat == null ? null : stat.trim();
}
public String getIsta() {
return ista;
}
public void setIsta(String ista) {
this.ista = ista == null ? null : ista.trim();
}
public Date getPast() {
return past;
}
public void setPast(Date past) {
this.past = past;
}
public Date getEldt() {
return eldt;
}
public void setEldt(Date eldt) {
this.eldt = eldt;
}
public String getMsta() {
return msta;
}
public void setMsta(String msta) {
this.msta = msta == null ? null : msta.trim();
}
public String getMist() {
return mist;
}
public void setMist(String mist) {
this.mist = mist == null ? null : mist.trim();
}
public BigDecimal getMessageBakId() {
return messageBakId;
}
public void setMessageBakId(BigDecimal messageBakId) {
this.messageBakId = messageBakId;
}
public String getFlightnum() {
return flightnum;
}
public void setFlightnum(String flightnum) {
this.flightnum = flightnum == null ? null : flightnum.trim();
}
public String getImpexp() {
return impexp;
}
public void setImpexp(String impexp) {
this.impexp = impexp == null ? null : impexp.trim();
}
public BigDecimal getState() {
return state;
}
public void setState(BigDecimal state) {
this.state = state;
}
public String getSendtime() {
return sendtime;
}
public void setSendtime(String sendtime) {
this.sendtime = sendtime == null ? null : sendtime.trim();
}
@Override
public String toString() {
return "Flight [past=" + past + ", eldt=" + eldt + ",flightnum=" + flightnum + ", impexp=" + impexp + ", sendtime=" + sendtime + "]";
}
}
... ...
package com.tianbo.flight.entity;
import java.util.Date;
public class FlightJson {
private Date ArrivalDate;
private Date DepartureDate;
private String ArrivalDateTime;
private String DepartureDateTime;
private String SendTime;
private String flag;
public String getArrivalDateTime() {
return ArrivalDateTime;
}
public void setArrivalDateTime(String arrivalDateTime) {
ArrivalDateTime = arrivalDateTime;
}
public String getDepartureDateTime() {
return DepartureDateTime;
}
public void setDepartureDateTime(String departureDateTime) {
DepartureDateTime = departureDateTime;
}
public String getSendTime() {
return SendTime;
}
public void setSendTime(String sendTime) {
SendTime = sendTime;
}
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public Date getArrivalDate() {
return ArrivalDate;
}
public void setArrivalDate(Date arrivalDate) {
ArrivalDate = arrivalDate;
}
public Date getDepartureDate() {
return DepartureDate;
}
public void setDepartureDate(Date departureDate) {
DepartureDate = departureDate;
}
}
... ...
package com.tianbo.flight.service;
import com.tianbo.flight.entity.Flight;
public interface FlightService {
public Flight getTime(String flightnum ,String impexp, String sendtime);
public Flight getLastTime(String flightnum ,String impexp);
}
... ...
package com.tianbo.flight.service.impl;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tianbo.flight.dao.FlightDao;
import com.tianbo.flight.entity.Flight;
import com.tianbo.flight.service.FlightService;
import com.tianbo.flight.util.DateUtils;
@Service
public class FlightServiceImpl implements FlightService {
@Autowired
private FlightDao flightDao;
@Override
public Flight getTime(String flightnum ,String impexp, String sendtime) {
Map<String, String> map = new HashMap<String, String>();
map.put("flightnum", flightnum);
map.put("impexp", impexp);
map.put("sendtime", sendtime);
return flightDao.getTime(map);
}
public static void main(String[] args)
{
System.out.println(UUID.randomUUID().toString());
Date currtDate = DateUtils.stringToDate((DateUtils.DateToString(new Date(), "yyyy-MM-dd")),"yyyy-MM-dd");
System.out.println(currtDate);
}
@Override
public Flight getLastTime(String flightnum, String impexp) {
Map<String, String> map = new HashMap<String, String>();
map.put("flightnum", flightnum);
map.put("impexp", impexp);
return flightDao.getLastTime(map);
}
}
... ...
package com.tianbo.flight.util;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* 然后在你的POJO上找到日期的get方法
*
* @JsonSerialize(using = CustomDateSerializer.class)
* public Date getCreateAt() { return createAt; }}
* @author zhangy
*
*/
public class CustomDateSerializer extends JsonSerializer<Date> {
@Override
public void serialize(Date value, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
JsonProcessingException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = formatter.format(value);
jgen.writeString(formattedDate);
}
}
... ...
package com.tianbo.flight.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.sun.jmx.snmp.Timestamp;
public class DateUtils {
/** 日志对象 */
/** 年-月-日 时:分:秒 显示格式 */
// 备注:如果使用大写HH标识使用24小时显示格式,如果使用小写hh就表示使用12小时制格式。
public static String DATE_TO_STRING_DETAIAL_PATTERN = "yyyy-MM-dd HH:mm:ss";
/** 年-月-日 显示格式 */
public static String DATE_TO_STRING_SHORT_PATTERN = "yyyy-MM-dd";
private static SimpleDateFormat simpleDateFormat;
/**
* Date类型转为指定格式的String类型
*
* @param source
* @param pattern
* @return
*/
public static String DateToString(Date source, String pattern) {
simpleDateFormat = new SimpleDateFormat(pattern);
return simpleDateFormat.format(source);
}
/**
*
* unix时间戳转为指定格式的String类型
*
*
* System.currentTimeMillis()获得的是是从1970年1月1日开始所经过的毫秒数
* unix时间戳:是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒
*
* @param source
* @param pattern
* @return
*/
public static String timeStampToString(long source, String pattern) {
simpleDateFormat = new SimpleDateFormat(pattern);
Date date = new Date(source * 1000);
return simpleDateFormat.format(date);
}
/**
* 将日期转换为时间戳(unix时间戳,单位秒)
*
* @param date
* @return
*/
public static long dateToTimeStamp(Date date) {
Timestamp timestamp = new Timestamp(date.getTime());
return timestamp.getDateTime() / 1000;
}
/**
*
* 字符串转换为对应日期(可能会报错异常)
*
* @param source
* @param pattern
* @return
*/
public static Date stringToDate(String source, String pattern) {
simpleDateFormat = new SimpleDateFormat(pattern);
Date date = null;
try {
date = simpleDateFormat.parse(source);
} catch (ParseException e) {
}
return date;
}
/**
* 获得当前时间对应的指定格式
*
* @param pattern
* @return
*/
public static String currentFormatDate(String pattern) {
simpleDateFormat = new SimpleDateFormat(pattern);
return simpleDateFormat.format(new Date());
}
public static String timeFormatDate(String pattern,long dateTime) {
simpleDateFormat = new SimpleDateFormat(pattern);
return simpleDateFormat.format(new Date(dateTime));
}
/**
* 获得当前unix时间戳(单位秒)
*
* @return 当前unix时间戳
*/
public static long currentTimeStamp() {
return System.currentTimeMillis() / 1000;
}
//待补充
public static void main(String args[]){
Date stringToDate = stringToDate("20180615", "yyyymmdd");
System.out.println(stringToDate);
long longTime = new Date().getTime();
System.out.println("字符串类型的Long日期转换成日期:");
String str = "1498457677473";
Long dateLong = Long.valueOf(str);
System.out.println(timeFormatDate("yyyy-MM-dd HH:mm:ss", dateLong));
}
}
\ No newline at end of file
... ...
package com.tianbo.flight.util;
import java.io.IOException;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
public class JsonConversion {
/**
* 日志.
*/
private static Logger logger = Logger.getLogger(JsonConversion.class);
private static final String SIMPLE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
/**
* java对象转换成json字符串
* @param obj
*/
public static final String writeEntityJSON(Object obj) {
if (null == obj) {
return "{}";
}
StringWriter stringWriter = new StringWriter();
ObjectMappingCustomer mapper = new ObjectMappingCustomer();
mapper.setDateFormat(new SimpleDateFormat(SIMPLE_DATE_FORMAT));
try {
mapper.writeValue(stringWriter, obj);
} catch (JsonGenerationException e) {
logger.debug(e.getMessage(), e);
} catch (JsonMappingException e) {
logger.debug(e.getMessage(), e);
} catch (IOException e) {
logger.debug(e.getMessage(), e);
}
return stringWriter.toString();
}
/**
* List集合转JSON字符串.
* @param list
* @return
*/
public static final String writeListJSON(List<?> list) {
StringWriter stringWriter = new StringWriter();
try {
ObjectMappingCustomer mapper = new ObjectMappingCustomer();
mapper.setDateFormat(new SimpleDateFormat(SIMPLE_DATE_FORMAT));
mapper.writeValue(stringWriter,list);
} catch (JsonGenerationException e) {
logger.debug(e.getMessage(), e);
} catch (JsonMappingException e) {
logger.debug(e.getMessage(), e);
} catch (IOException e) {
logger.debug(e.getMessage(), e);
}
return stringWriter.toString();
}
/**
* Map集合转换成Json字符串.
* @param map
* @return
*/
public static final String writeMapJSON(Map<?, ?> map) {
StringWriter stringWriter = new StringWriter();
try {
ObjectMappingCustomer mapper = new ObjectMappingCustomer();
mapper.setDateFormat(new SimpleDateFormat(SIMPLE_DATE_FORMAT));
mapper.writeValue(stringWriter,map);
} catch (JsonGenerationException e) {
logger.debug(e.getMessage(), e);
} catch (JsonMappingException e) {
logger.debug(e.getMessage(), e);
} catch (IOException e) {
logger.debug(e.getMessage(), e);
}
return stringWriter.toString();
}
/**
* 使用Servlet的输出java对象转换成的json字符串.
* @param json
* @throws IOException
*/
/*public static final void writeEntityJSONToHttpServletResponse(Object obj) throws IOException{
HttpServletResponse response=ServletActionContext.getResponse();
* 在调用getWriter之前未设置编码(既调用setContentType或者setCharacterEncoding方法设置编码),
* HttpServletResponse则会返回一个用默认的编码(既ISO-8859-1)编码的PrintWriter实例。这样就会
* 造成中文乱码。而且设置编码时必须在调用getWriter之前设置,不然是无效的。
*
response.setContentType("text/html;charset=utf-8");
//response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//JSON在传递过程中是普通字符串形式传递
out.println(writeEntityJSON(obj));
out.flush();
out.close();
}*/
}
... ...
package com.tianbo.flight.util;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
/**
* Depiction:模仿NSdictionary实现json解析,使用方法类似HashMap
* <p/>
* Modify:
* <p/>
* Author: Kevin Lynn
* <p/>
* Create Date:2014-4-8 下午5:28:12
* <p/>
*
* @version 1.0
* @since 1.0
*/
public class JsonMap extends HashMap<String, Object> {
private static final long serialVersionUID = 4567321902312180302L;
public boolean getBoolean(String key) {
try {
return getString(key).equals("true");
} catch (Exception e) {
}
return false;
}
public int getInt(String key) {
try {
return (int) getFloat(key);
} catch (Exception e) {
}
return 0;
}
public float getFloat(String key) {
try {
return Float.parseFloat(get(key).toString());
} catch (Exception e) {
}
return 0.0f;
}
public double getDouble(String key) {
try {
return Double.parseDouble(get(key).toString());
} catch (Exception e) {
}
return 0.0f;
}
public long getLong(String key) {
try {
return (long) getDouble(key);
} catch (Exception e) {
}
return 0l;
}
public String getString(String key) {
return get(key) != null ? get(key).toString() : null;
}
@SuppressWarnings ("unchecked")
public JsonMap getMap(String key) {
try {
Map<String, Object> map = (Map<String, Object>) get(key);
JsonMap data = new JsonMap();
for (Iterator<String> keys = map.keySet().iterator(); keys.hasNext();) {
String k = (String) keys.next();
Object v = map.get(k);
data.put(k, v);
}
return data;
} catch (Exception e) {
}
return null;
}
@SuppressWarnings ("unchecked")
public List<JsonMap> getListMap(String key) {
try {
List<Map<String, Object>> maps = (List<Map<String, Object>>) get(key);
List<JsonMap> listMap = new ArrayList<JsonMap>();
for (Map<String, Object> map : maps) {
JsonMap data = new JsonMap();
for (Iterator<String> keys = map.keySet().iterator(); keys.hasNext();) {
String k = (String) keys.next();
Object v = map.get(k);
data.put(k, v);
}
listMap.add(data);
}
return listMap;
} catch (Exception e) {
}
return null;
}
public static JsonMap toJsonMap(Map<String, Object> map) {
JsonMap data = new JsonMap();
for (Iterator<String> keys = map.keySet().iterator(); keys.hasNext();) {
String k = (String) keys.next();
Object v = map.get(k);
data.put(k, v);
}
return data;
}
/**
* Json数据解析
*
* @param json
* json源串
* @return JsonMap
*/
public static JsonMap parseJson(String json) {
return parseJson(json, JsonMap.class);
}
/**
* Json数据解析
*
* @param json
* json源串
* @return List<JsonMap>
*/
public static List<JsonMap> parseJsonArray(String json) {
List<JsonMap> listMap = new ArrayList<JsonMap>();
try {
Type listType = new TypeToken<List<Map<String, Object>>>() {}.getType();
List<Map<String, Object>> list = parseJson(json, listType);
for (Map<String, Object> map : list) {
listMap.add(toJsonMap(map));
}
} catch (Exception e) {
}
return listMap;
}
/**
* Json数据解析
*
* @param json
* json源串
* @param cls
* 存储json的实体类
* @return 相应的实体类对象
*/
public static <T> T parseJson(String json, Type cls) {
try {
Gson gson = new Gson();
return gson.fromJson(json, cls);
} catch (Exception e) {
}
return null;
}
@Override
public Object get(Object key) {
return super.get(key);
}
@Override
public String toString() {
try {
Gson gson = new Gson();
return gson.toJson(this);
} catch (Exception e) {
}
return super.toString();
}
}
... ...
package com.tianbo.flight.util;
import java.util.ArrayList;
import java.util.List;
/**
* Depiction: 多图json数据重组实现,依赖gson库
* <p>
* Modify:
* <p>
* Author: Kevin Lynn
* <p>
* Create Date:2015年11月26日 下午5:45:16
* <p>
*
* @version 1.0
* @since 1.0
*/
public class MultipleImgsJson {
private MultipleImgsJson() {
}
/**
* 重组多图的json数据,为每个图片对象添加duration字段,单位分钟。
*
* @param oldJson 原有json数据
* @return 重组后的json数据
*/
public static String rebuildJson(String oldJson) {
JsonMap data = JsonMap.parseJson(oldJson);
if (data != null) {
List<JsonMap> imgs = data.getListMap("imgs");
if (imgs != null) {
List<JsonMap> newImgs = new ArrayList<JsonMap>();
for (JsonMap img : imgs) {
String n = img.getString("n");
//11月26日16时55分
if (n != null && n.trim().length() > 0 && n.contains("日")) {
String[] array = n.split("日");
if (array != null && array.length > 1) {
String time = array[1].replace("时", "").replace("分", "");
int hour = Integer.parseInt(time.substring(0, 2));
int min = Integer.parseInt(time.substring(2, 4));
int total = hour * 60 + min;
img.put("duration", total);
newImgs.add(img);
}
}
}
data.put("imgs", newImgs);
return data.toString();
}
}
return null;
}
/**
* 重组多图的json数据,为每个图片对象添加duration字段,单位分钟。
*
* @param oldJson 原有json数据
* @return 重组后的json数据
*/
public static JsonMap rebuildJson2JsonMap(String oldJson) {
JsonMap data = JsonMap.parseJson(oldJson);
if (data != null) {
List<JsonMap> imgs = data.getListMap("imgs");
if (imgs != null) {
List<JsonMap> newImgs = new ArrayList<JsonMap>();
for (JsonMap img : imgs) {
String n = img.getString("n");
//11月26日16时55分
if (n != null && n.trim().length() > 0 && n.contains("日")) {
String[] array = n.split("日");
if (array != null && array.length > 1) {
String time = array[1].replace("时", "").replace("分", "");
int hour = Integer.parseInt(time.substring(0, 2));
int min = Integer.parseInt(time.substring(2, 4));
int total = hour * 60 + min;
img.put("duration", total);
newImgs.add(img);
}
}
}
data.put("imgs", newImgs);
return data;
}
}
return null;
}
}
... ...
package com.tianbo.flight.util;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* 解决jackson输出null为空字符串、单引号、字段和数字加引号问题.
* @author wangchenbo
*
*/
public class ObjectMappingCustomer extends ObjectMapper {
public ObjectMappingCustomer() {
super();
// 允许单引号
this.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
// 字段和值都加引号
this.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
// 转义字符-异常情况
this.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
// 数字也加引号
this.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
this.configure(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS, true);
// 空值处理为空串
this.getSerializerProvider().setNullValueSerializer(
new JsonSerializer<Object>() {
@Override
public void serialize(Object value, JsonGenerator jg,
SerializerProvider sp) throws IOException,
JsonProcessingException {
jg.writeString("");
}
});
}
}
... ...
package com.tianbo.flight.util;
import java.util.Properties;
public class PropertiesUtils {
private static Properties properties=new Properties();
static{
try {
//注意属性配置文件所在的路径
properties.load(PropertiesUtils.class.getClassLoader().getResourceAsStream("/config/time.properties"));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
//读取属性配置文件中的某个属性对应的值
public static String readProperty(String property){
return (String) properties.get(property);
}
}
\ No newline at end of file
... ...
package com.tianbo.flight.webservice;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface FlightWebService {
public String getTime(@WebParam(name="flightnum") String flightnum,@WebParam(name="impexp") String impexp,@WebParam(name="sendtime") String sendtime);
}
... ...
package com.tianbo.flight.webservice.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jws.WebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.tianbo.flight.entity.Flight;
import com.tianbo.flight.entity.FlightJson;
import com.tianbo.flight.service.FlightService;
import com.tianbo.flight.util.DateUtils;
import com.tianbo.flight.util.JsonConversion;
import com.tianbo.flight.util.PropertiesUtils;
import com.tianbo.flight.webservice.FlightWebService;
@Transactional
@Service
@WebService(endpointInterface = "com.tianbo.flight.webservice.FlightWebService", serviceName = "flightWebService")
public class FlightWebServiceImpl implements FlightWebService {
@Autowired
private FlightService flightService;
@Override
public String getTime(String flightnum, String impexp, String sendtime) {
String flag_twenty_value = PropertiesUtils.readProperty("flag_twenty");
long flag_twenty = Long.valueOf(flag_twenty_value);
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmm");
Date currentTime = new Date();
long flag = 14400000; // 4小时
// long flag_twenty = 1200000; //20分钟
long flag_half = 1800000; // 30分钟
long flag_two=7200000;//2小时
Flight flight = flightService.getTime(flightnum, impexp, sendtime);
if (flight != null) {
Date DepartureDate = flight.getPast(); // 离岗时间
Date ArrivalDate = flight.getEldt(); // 到达时间
long day = (ArrivalDate.getTime() - DepartureDate.getTime()); // 航程
FlightJson flightJson = new FlightJson();
if (day > flag) { // 航程超过4小时
flightJson.setFlag("1");
if (currentTime.getTime() - DepartureDate.getTime() > 0) { // 当前时间大于起飞时间 不符合时效
if (ArrivalDate.getTime() - currentTime.getTime() > 0) { // 当前时间早于降落时间
long sendTime = currentTime.getTime();
long departureDateTime = sendTime + flag_twenty;
long arrivalDateTime = departureDateTime + flag_twenty;
flightJson.setSendTime(df.format(sendTime) + "38038");
flightJson.setArrivalDateTime(df.format(arrivalDateTime) + "38086");
flightJson.setDepartureDateTime(df.format(departureDateTime) + "38086");
Date departureDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", departureDateTime), "yyyy-MM-dd HH:mm:ss");
Date arrivalDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", arrivalDateTime), "yyyy-MM-dd HH:mm:ss");
flightJson.setDepartureDate(departureDate);
flightJson.setArrivalDate(arrivalDate);
} else { // 晚于
flightJson.setSendTime(df.format(new Date()) + "38038");
flightJson.setArrivalDateTime(df.format(ArrivalDate) + "38086");
flightJson.setDepartureDateTime(df.format(DepartureDate) + "38086");
flightJson.setDepartureDate(DepartureDate);
flightJson.setArrivalDate(ArrivalDate);
}
} else { // 符合时效
flightJson.setSendTime(df.format(new Date()) + "38038");
flightJson.setArrivalDateTime(df.format(ArrivalDate) + "38086");
flightJson.setDepartureDateTime(df.format(DepartureDate) + "38086");
flightJson.setDepartureDate(DepartureDate);
flightJson.setArrivalDate(ArrivalDate);
}
} else {// 4小时内
flightJson.setFlag("0");
if (currentTime.getTime() - DepartureDate.getTime() > 0) {// 当前时间>起飞时间
if (ArrivalDate.getTime() - currentTime.getTime() > 0) { // 当前时间是否早于降落时间
long sendTime = currentTime.getTime();
long departureDateTime = sendTime + flag_twenty;
long arrivalDateTime = departureDateTime + flag_twenty;
flightJson.setSendTime(df.format(sendTime) + "38038");
flightJson.setArrivalDateTime(df.format(arrivalDateTime) + "38086");
flightJson.setDepartureDateTime(df.format(departureDateTime) + "38086");
Date departureDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", departureDateTime), "yyyy-MM-dd HH:mm:ss");
Date arrivalDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", arrivalDateTime), "yyyy-MM-dd HH:mm:ss");
flightJson.setDepartureDate(departureDate);
flightJson.setArrivalDate(arrivalDate);
} else { // 晚于
flightJson.setSendTime(df.format(new Date()) + "38038");
flightJson.setArrivalDateTime(df.format(ArrivalDate) + "38086");
flightJson.setDepartureDateTime(df.format(DepartureDate) + "38086");
flightJson.setDepartureDate(DepartureDate);
flightJson.setArrivalDate(ArrivalDate);
}
}else{
flightJson.setSendTime(df.format(new Date()) + "38038");
flightJson.setArrivalDateTime(df.format(ArrivalDate) + "38086");
flightJson.setDepartureDateTime(df.format(DepartureDate) + "38086");
flightJson.setDepartureDate(DepartureDate);
flightJson.setArrivalDate(ArrivalDate);
}
}
String json = JsonConversion.writeEntityJSON(flightJson);
// return flightService.getTime(flightnum,
// impexp,sendtime).toString();
return json;
} else {
FlightJson flightJson = new FlightJson();
Date date = DateUtils.stringToDate((DateUtils.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss")),"yyyy-MM-dd HH:mm:ss");
Date currtDate = DateUtils.stringToDate((DateUtils.DateToString(new Date(), "yyyy-MM-dd")),"yyyy-MM-dd");
Date DepartureDate = DateUtils.stringToDate(sendtime, "yyyyMMdd"); //最后一班到达时间
long arrivalDateTime = DepartureDate.getTime() + flag_two;
if(currtDate.getTime()-DepartureDate.getTime()!=0){ //查询航班日期与当前日期是否相差。只取年月日
flightJson.setSendTime(df.format(date) + "38038");//当前时间
flightJson.setDepartureDateTime(df.format(DepartureDate) + "38086");//查询时间
Date arrivalDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", arrivalDateTime), "yyyy-MM-dd HH:mm:ss");;
flightJson.setArrivalDate(arrivalDate);
flightJson.setDepartureDate(DepartureDate);
flightJson.setArrivalDateTime(df.format(arrivalDateTime) + "38086");
}else{
flightJson = new FlightJson();
long departureDateTime = date.getTime() + flag_half;
arrivalDateTime = departureDateTime + flag_half;
Date departureDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", departureDateTime), "yyyy-MM-dd HH:mm:ss");
Date arrivalDate = DateUtils.stringToDate(DateUtils.timeFormatDate("yyyy-MM-dd HH:mm:ss", arrivalDateTime), "yyyy-MM-dd HH:mm:ss");
flightJson.setSendTime(df.format(date) + "38038");
flightJson.setDepartureDateTime(df.format(departureDateTime) + "38086");
flightJson.setArrivalDateTime(df.format(arrivalDateTime) + "38086");
flightJson.setDepartureDate(departureDate);
flightJson.setArrivalDate(arrivalDate);
}
String json = JsonConversion.writeEntityJSON(flightJson);
return json;
}
}
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="flightWebService" address="/flightWebService"
implementor="com.tianbo.flight.webservice.impl.FlightWebServiceImpl" />
</beans>
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<!-- 采用注释的方式配置bean -->
<context:annotation-config/>
<!-- 配置要扫描的包 -->
<context:component-scan base-package="com.tianbo.flight"/>
<!-- 数据库配置文件位置 -->
<context:property-placeholder location="classpath:config/init.properties"/>
<!-- 配置数据源 oracle c3p0-->
<bean id="dataSourceTarget" class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:driverClass="${jdbc.driverClassName}"
p:jdbcUrl="${jdbc.url}"
p:user="${jdbc.username}"
p:password="${jdbc.password}"
p:checkoutTimeout="${cpool.checkoutTimeout}"
p:minPoolSize="${cpool.minPoolSize}"
p:maxPoolSize="${cpool.maxPoolSize}"
p:maxIdleTime="${cpool.maxIdleTime}"
destroy-method="close"
></bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource" ref="dataSourceTarget"></property>
</bean>
<!-- 声明式事务管理begin -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:advisor pointcut="execution(* com.tianbo.flight..*Impl.*(..))" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="load*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="search*" read-only="true"/>
<tx:method name="*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<!-- 声明式事务管理end -->
<!-- 配置mybitasSqlSessionFactoryBean -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:config/sqlmap-config.xml" />
<property name="mapperLocations" value="classpath:sqlMapper/**/*.xml" />
</bean>
<!-- 配置dao层与mapper.xml关联 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name="basePackage" value="com.tianbo.flight.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
</beans>
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration >
<!-- 这个文件可以不用管 可以删掉 -->
<classPathEntry location="D:\\\generator\\ojdbc14.jar"/>
<context id="context1" >
<commentGenerator>
<property name="suppressAllcomments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@10.50.3.69:1521:CGODB" userId="cgonms" password="1q2w3e4r" />
<javaModelGenerator targetPackage="com.test.mybatis.model" targetProject="D:\generator\src" />
<sqlMapGenerator targetPackage="com.test.mybatis.mapper" targetProject="D:\generator\src" />
<javaClientGenerator targetPackage="com.topsci.atfm.persistence.mybatis.client" targetProject="D:\generator\src" type="XMLMAPPER" />
<table schema="" tableName="ORIGINMANIFESTSECONDARY" ></table>
<!-- <table tableName="SYN_TRACK_EST" domainObjectName="AtfmTrack"></table> -->
</context>
</generatorConfiguration>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!--<properties resource="jdbc.properties" /> -->
<!--MYSQL连接器JAR包位置 -->
<!--<classPathEntry location="/Users/mrz/Documents/maven/mysql-connector-java-5.1.7-bin.jar"/>-->
<!--oracle连接器JAR包位置 -->
<classPathEntry location="D:\\\generator\\ojdbc14.jar"/>
<context id="testTables" targetRuntime="MyBatis3" >
<!--mySql分页插件 -->
<!--<plugin type="com.tianbo.mybatis.plugin.PaginationPlugin" />-->
<!-- oracle 分页插件-->
<!-- <plugin type="com.tianbo.mybatis.plugin.OraclePaginationPlugin" /> -->
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<!--<jdbcConnection driverClass="${jdbc.driver}"-->
<!--connectionURL="${jdbc.url}"-->
<!--userId="${jdbc.username}"-->
<!--password="${jdbc.password}">-->
<!--</jdbcConnection>-->
<!--<jdbcConnection driverClass="com.mysql.jdbc.Driver"-->
<!--connectionURL="jdbc:mysql://127.0.0.1:3307/statistics?characterEncoding=UTF-8"-->
<!--userId="root"-->
<!--password="">-->
<!--</jdbcConnection>-->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@10.50.3.69:1521:CGODB" userId="cgonms" password="1q2w3e4r" />
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<!--<javaTypeResolver>-->
<!--<property name="forceBigDecimals" value="true" />-->
<!--</javaTypeResolver>-->
<!-- targetProject:生成PO类的位置 -->
<javaModelGenerator targetPackage="com.tianbo.model"
targetProject="D:\generator\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="com.tianbo.mapper"
targetProject="D:\generator\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.tianbo.mapper"
targetProject="D:\generator\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定数据库表 -->
<!--<table tableName="USERS"></table>-->
<!--<table tableName="ROLE_PERMISSION"></table>-->
<!--<table tableName="USER_ROLE"></table>-->
<!--<table tableName="ROLE"></table>-->
<!--<table tableName="PERMISSION"></table>-->
<table tableName="ARRIVEDMASTER"></table>
<!-- 有些表的字段需要指定java类型
<table schema="" tableName="">
<columnOverride column="" javaType="" />
</table> -->
</context>
</generatorConfiguration>
\ No newline at end of file
... ...
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW
jdbc.username=cgoetl
jdbc.password=1q2w3e4r
cpool.checkoutTimeout=5000
cpool.minPoolSize=1
cpool.maxPoolSize=100
cpool.maxIdleTime=7200
\ 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>
<!-- changes from the defaults -->
<setting name="cacheEnabled" value="false" />
<setting name="lazyLoadingEnabled" value="false" />
<setting name="mapUnderscoreToCamelCase" value="true" />
<setting name="useColumnLabel" value="true" />
<setting name="defaultExecutorType" value="REUSE" />
<setting name="defaultStatementTimeout" value="25000" />
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
</configuration>
... ...
#\u65F6\u95F4\u8BBE\u7F6E
flag_twenty=1200000
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://www.mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tianbo.flight.dao.FlightDao">
<!-- 号源 -->
<select id="getTime" parameterType="Map"
resultType="com.tianbo.flight.entity.Flight">
SELECT
T.SEQN,
o.*
FROM
T_ETL_MESSAGE T,
T_FACT_HB_ONRE o
WHERE
T.FID=o.MESSAGE_BAK_ID
AND T.SNDR='FIMS'
AND T.STYP = 'ONRE'
AND o.FLIGHTNUM =#{flightnum}
AND o.IMPEXP=#{impexp}
AND o.SENDTIME=#{sendtime}
AND ROWNUM=1
ORDER BY
T.SEQN
</select>
<select id="getLastTime" parameterType="Map"
resultType="com.tianbo.flight.entity.Flight">
SELECT
T.SEQN,
o.*
FROM
T_ETL_MESSAGE T,
T_FACT_HB_ONRE o
WHERE
T.FID=o.MESSAGE_BAK_ID
AND T.SNDR='FIMS'
AND T.STYP = 'ONRE'
AND o.FLIGHTNUM =#{flightnum}
AND o.IMPEXP=#{impexp}
AND ROWNUM=1
ORDER BY
T.SEQN
</select>
</mapper>
\ No newline at end of file
... ...