| 7290 |
rajveer |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
import org.apache.commons.codec.binary.Base64;
|
|
|
3 |
|
|
|
4 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
5 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
|
|
6 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
7 |
|
|
|
8 |
import java.io.UnsupportedEncodingException;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
|
|
11 |
import javax.servlet.http.HttpServletResponse;
|
|
|
12 |
|
|
|
13 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
14 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
16 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
17 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
18 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
19 |
import org.apache.thrift.TException;
|
|
|
20 |
import org.apache.thrift.transport.TTransportException;
|
|
|
21 |
import org.slf4j.Logger;
|
|
|
22 |
import org.slf4j.LoggerFactory;
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
@InterceptorRefs({
|
|
|
26 |
@InterceptorRef("defaultStack")
|
|
|
27 |
})
|
|
|
28 |
@Results({
|
|
|
29 |
@Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
|
|
|
30 |
})
|
|
|
31 |
public class PriceApprovalController implements ServletRequestAware, ServletResponseAware {
|
|
|
32 |
|
|
|
33 |
private static Logger logger = LoggerFactory.getLogger(PriceApprovalController.class);
|
|
|
34 |
private HttpServletRequest request;
|
|
|
35 |
private HttpServletResponse response;
|
|
|
36 |
private long orderId;
|
|
|
37 |
private boolean approve;
|
|
|
38 |
private boolean displayForm = false;
|
|
|
39 |
|
|
|
40 |
public String index() throws NumberFormatException, UnsupportedEncodingException {
|
|
|
41 |
String ohash = request.getParameter("xszbg");
|
|
|
42 |
orderId = Long.parseLong(decodeString(ohash));
|
|
|
43 |
displayForm = true;
|
|
|
44 |
return "index";
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public String create(){
|
|
|
48 |
Client client;
|
|
|
49 |
try {
|
|
|
50 |
client = (new TransactionClient()).getClient();
|
|
|
51 |
|
|
|
52 |
if(approve){
|
|
|
53 |
client.verifyOrder(orderId);
|
|
|
54 |
}else{
|
|
|
55 |
client.refundOrder(orderId, "Store Area Manager", "Can not sell below minimum price");
|
|
|
56 |
}
|
|
|
57 |
} catch (TTransportException e) {
|
|
|
58 |
// TODO Auto-generated catch block
|
|
|
59 |
e.printStackTrace();
|
|
|
60 |
} catch (TransactionServiceException e) {
|
|
|
61 |
// TODO Auto-generated catch block
|
|
|
62 |
e.printStackTrace();
|
|
|
63 |
} catch (TException e) {
|
|
|
64 |
// TODO Auto-generated catch block
|
|
|
65 |
e.printStackTrace();
|
|
|
66 |
}
|
|
|
67 |
return "index";
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public static String encodeString(String str) throws UnsupportedEncodingException{
|
|
|
71 |
byte[] encodedBytes = Base64.encodeBase64(str.getBytes("UTF8"));
|
|
|
72 |
return (new String(encodedBytes, "UTF8"));
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public static String decodeString(String str) throws UnsupportedEncodingException{
|
|
|
76 |
byte[] decodedBytes = Base64.decodeBase64(str.getBytes("UTF8"));
|
|
|
77 |
return (new String(decodedBytes, "UTF8"));
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public static void main(String[] args) throws UnsupportedEncodingException {
|
|
|
81 |
System.out.println(encodeString("1881818"));
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
@Override
|
|
|
85 |
public void setServletResponse(HttpServletResponse arg0) {
|
|
|
86 |
this.response = arg0;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
@Override
|
|
|
90 |
public void setServletRequest(HttpServletRequest arg0) {
|
|
|
91 |
this.request = arg0;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public boolean displayForm(){
|
|
|
95 |
return displayForm;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public void setOrderId(long orderId) {
|
|
|
99 |
this.orderId = orderId;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public String getOrderId() {
|
|
|
103 |
return Long.toString(orderId);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public void setApprove(boolean approve) {
|
|
|
107 |
this.approve = approve;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
public boolean isApprove() {
|
|
|
111 |
return approve;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
public String getServletContextPath() {
|
|
|
115 |
return request.getContextPath();
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
}
|