【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-TicketCancellAction.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
package atbs.view;
import javax.naming.Context;
import javax.naming.NamingException;
import java.util.*;
import atbs.session.*;
import atbs.entity.*;
public class TicketCancellAction {
private Context ctx;
private TicketSessionRemote ticketSession;
private UserLogSessionRemote userLogSession;
private List<Ticket> bookTicketList;
private String bookError;
private boolean canCancell;
private String cancellError;
private Date bookTime;
private Date flyTime;
private int bookCount;
private int allValue;
public TicketCancellAction(){
try {
ctx = RemoteContext.getContextInstance();
} catch (NamingException ex) {
ex.printStackTrace();
}
try {
ticketSession = (TicketSessionRemote) ctx.lookup("atbs/TicketSession/remote");
userLogSession = (UserLogSessionRemote)ctx.lookup("atbs/UserLogSession/remote");
} catch (NamingException ex1) {
ex1.printStackTrace();
}
SysUser user = (SysUser)ManageContext.getSessionScopeBean("user");
this.bookTicketList = ticketSession.getTicketByUserName(user.getUserName(),Ticket.Ticket_STATUS_BOOKING);
if(this.bookTicketList==null||this.bookTicketList.size() == 0){
this.bookError = "Now,you have not any booked ticket";
}else{
this.bookCount = this.bookTicketList.size();
this.allValue = 0;
for(Ticket ticket:bookTicketList){
this.allValue += ticket.getValue();
}
Date now = new Date();
bookTime = bookTicketList.get(0).getBookTime();
flyTime = bookTicketList.get(0).getAirplane().getStartTime();
long now_book_hour = (now.getTime()-bookTime.getTime())/(60*60*1000);
long now_fly_hour = (flyTime.getTime() - now.getTime())/(60*60*1000);
this.canCancell = false;
if(now_book_hour<48){
this.canCancell = false;
this.cancellError = "You ticket was booked at "+bookTime.toString()+",No cancellation without 48 hours notice";
}else{
if(now_fly_hour<24&&now_fly_hour>0){
this.canCancell = true;
this.cancellError = "You fly will at "+flyTime.toString()+",if you cancell,380 dollar penalty!";
}else{
if(now_fly_hour>24){
this.canCancell = true;
}else{
this.cancellError = "You fly was flying_off,you can not cancell!";
}
}
}
}
}
public String cancellTicket(){
if(bookTicketList==null||bookTicketList.isEmpty()){
return null;
}
if(this.ticketSession.backManyTicket(bookTicketList)){
this.cancellError = "You ticket is cancell success...";
this.canCancell = false;
SysUser user = (SysUser)ManageContext.getSessionScopeBean("user");
Map<String,String> map = new HashMap<String,String>();
map.put("address", user.getEmail());
map.put("subject", "TicketEasy:You cancell booked tickets Success");
StringBuffer content = new StringBuffer();
content.append("Welcome to TicketEasy,Access TicketEasy ,you can expediently cancell ticket you want.\r\n");
content.append("You :Cancelled Tickets:\r\n");
for(Ticket ticket:bookTicketList){
content.append("id:");
content.append(ticket.getId());
content.append(",value:");
content.append(ticket.getValue());
content.append(",airplane:");
content.append(ticket.getAirplane().getId());
content.append(",fly Time");
content.append(ticket.getAirplane().getStartTime().toString());
content.append("\r\n");
}
content.append("------------------------------------------TicketEasy");
map.put("content", content.toString());
RemoteContext.sendEmail(map);
UserLog userLog = new UserLog();
userLog.setTitle(UserLog.CANCELL_BOOK_TICKET);
userLog.setCustomer(user);
userLog.setContent(content.toString());
this.userLogSession.addUserLog(userLog);
}else{
this.cancellError = "You operation is failed,Please contact administrator...";
}
return null;
}
public List<Ticket> getBookTicketList() {
return bookTicketList;
}
public void setBookTicketList(List<Ticket> bookTicketList) {
this.bookTicketList = bookTicketList;
}
public String getBookError() {
return bookError;
}
public void setBookError(String bookError) {
this.bookError = bookError;
}
public boolean isCanCancell() {
return canCancell;
}
public void setCanCancell(boolean canCancell) {
this.canCancell = canCancell;
}
public String getCancellError() {
return cancellError;
}
public void setCancellError(String cancellError) {
this.cancellError = cancellError;
}
public Date getBookTime() {
return bookTime;
}
public void setBookTime(Date bookTime) {
this.bookTime = bookTime;
}
public Date getFlyTime() {
return flyTime;
}
public void setFlyTime(Date flyTime) {
this.flyTime = flyTime;
}
public int getBookCount() {
return bookCount;
}
public void setBookCount(int bookCount) {
this.bookCount = bookCount;
}
public int getAllValue() {
return allValue;
}
public void setAllValue(int allValue) {
this.allValue = allValue;
}
}
上一篇:
TicketBookResultAction.java
下一篇:
2018年汽车自驾运动营地攻防箭大赛总决赛圆满落幕