📄 authenticationmanager.java
字号:
return null;
}
}*/
public static TravelCorp getCorp(String email){
TravelCorp tc = null;
try {
tc = (TravelCorp) CacheManager.getByEmail(email);
return tc;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
/**
* save or modify the corp material contained by corpData
* there are five attibutes , email,password,name,address
* and description
* you only need to change the content reprented by email
* if success return true
* else return false
* @param corpData
* @return
*/
public static boolean saveCorpData(Vector data){
try {
if(data.size() != TravelCorp.propertyLength){
System.out.println("data.size() != TravelCorp.propertyLength");
return false;
}
String email = (String) data.get(2); // get email;
TravelCorp tc = (TravelCorp)CacheManager.getByEmail(email);
tc.modify(data);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* return all the corps' information
* return null if failure or no corps exist
* @return
*/
public static Vector getAllCorps(){
return getAllObj(ObjectType.CORP);
}
//dept
/**
* save or modify the dept material contained by deptData
* there are five attibutes , email,password,name,address
* and description
* you only need to change the content reprented by email
* if success return true
* else return false
*/
public static boolean saveDeptData(Vector data){
try {
if(data.size() != TravelDept.propertyLength){
System.out.println("data.size() != TravelDept.propertyLength");
return false;
}
String email = (String) data.get(2); // get email;
TravelDept td = (TravelDept)CacheManager.getByEmail(email);
td.modify(data);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* return all the sightspots'information
* return null if failure or no sightspots exist
* @return
*/
public static Vector getAllSightspots(){
return getAllObj(ObjectType.SIGHTSPOT);
}
/**
* @param corpEmail
* @param name
*/
public static boolean cancelTravpahInfor(String corpEmail, String name) {
// TODO Auto-generated method stub
return cancelGroup(corpEmail, name);
}
/**
* @param id
*/
public static TshsObject getById(Long id) {
try {
return CacheManager.getById(id);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* @param long1
* @param filePath
* @param name
* @param address
* @param extention
* @param discription
* @return
*/
public static boolean UpdateSightspot(Long id, String path, String name, String address, String imagetail, String description) {
List<String> names = new ArrayList<String>();
List<Integer> types = new ArrayList<Integer>();
names.add("id");
types.add(Types.BIGINT);
names.add("name");
types.add(Types.VARCHAR);
names.add("address");
types.add(Types.VARCHAR);
names.add("image");
types.add(Types.VARCHAR);
names.add("description");
types.add(Types.VARCHAR);
ColumnInfo info = null;
try {
info = new ColumnInfo(names, types);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", id);
map.put("name", name);
map.put("address", address);
File file = new File(path + "/upload/temp"+imagetail);
if(file.exists()){
File newfile = new File(path + "/upload/" + id + imagetail);
if(newfile.exists()){
newfile.delete();
}
file.renameTo(newfile);
}
map.put("image", "/upload/" + id + imagetail);
map.put("description", description);
TableRow row = new TableRow("sightspot", map, info);
try {
DbManager.update(row);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/**
* @param args
*/
public static void main(String[] args) {
// boolean a = validateClient("liuyi@163.com", "liuyi");
// Vector v = searchTravCorp("haha");
// Vector v = showAllTravelpathList();
// Vector v = searchSightspot("xiangshan");
// boolean v = orderSubmit("liuyi@163.com", new Long(100000));
// boolean v = cancelSubmit("liuyi@163.com", new Long(100000));
// boolean v = corpRegistry("111@163.com", "111", "111", "111", "111");
// boolean v = corpLogin("111@163.com", "111");
// Vector v = searchGroups("111@163.com", "group");
// boolean v = cancelGroup("111@163.com", "group");
// boolean v = travdeptLogin("lvyouju@163.com", "lvyouju");
// boolean v = openSightspot("sight", "sight", "sight", "sight");
// boolean v = closeSightspot("xiangshan");
// Client c = getPersData("liuyi@163.com");
// TravelCorp c = getCorpData("111@163.com");
/* Vector v = getAllSightspots();
for(int i = 0; i<v.size(); i++){
System.out.println(((SightSpot)v.get(i)).getName());
}*/
boolean c = cancelTravpahInfor("111@163.com", "group");
// System.out.println(v.get(0));
System.out.println(c);
//待测savePersData(Vector data);saveCorpData(Vector data);saveDeptData(Vector data)
}
/**
* @param name
* @return
* @throws SQLException
*/
public static Vector getAllGroups() throws Exception {
TableRowIterator iterator = CacheManager.getAllObj(ObjectType.GROUP);
Vector res = new Vector();
while(iterator.hasNext()){
TableRow row = iterator.next();
DbManager.addRow("travelgroup", row);
res.add(CacheManager.convert(row));
}
return res;
}
/**
* @param sightspot
* @param name
* @return
* @throws Exception
*/
public static Vector getLikeName(ObjectType type, String name) throws Exception {
Vector res = new Vector();
if(type.equals(ObjectType.SIGHTSPOT)){
Vector sights = getAllSightspots();
if(name.trim().length()==0){
return sights;
}
SightSpot sight = null;
for(Object o: sights){
sight = (SightSpot)o;
if(sight.getName().indexOf(name)!=-1){
res.add(sight);
}
}
return res;
}else if(type.equals(ObjectType.GROUP)){
Vector groups = getAllGroups();
if(name.trim().length()==0){
return groups;
}
TravelGroup group = null;
for(Object o: groups){
group = (TravelGroup)o;
if(group.getName().indexOf(name)!=-1){
res.add(group);
}
}
return res;
}else if(type.equals(ObjectType.CORP)){
Vector corps = getAllCorps();
if(name.trim().length()==0){
return corps;
}
TravelCorp corp = null;
for(Object o: corps){
corp = (TravelCorp)o;
if(corp.getName().indexOf(name)!=-1){
res.add(corp);
}
}
return res;
}
return null;
}
/**
* @param email
* @param password
* @return
*/
public static boolean validateCorp(String email, String password) {
try{
AuthState state = authenticatePassword(email, password);
if(state == AuthState.SUCCESS){
return true;
}else{
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* @param id
* @return
* @throws SQLException
*/
public static Vector getOpenedGroup(Long id) throws Exception {
Vector vector = new Vector();
String sql = "select id from travelgroup where corpId='"+id+"';";
TableRowIterator iterator = DbManager.query(sql);
while(iterator.hasNext()){
TableRow row = iterator.next();
Long groupid = Long.valueOf(row.getColumn("id").toString());
vector.add(CacheManager.getById(groupid));
}
return vector;
}
/**
* @param id
* @param name
* @param capacity
* @param start
* @param sightids
* @param description
* @return
*/
public static boolean openGroup(Long corpid, String name, Integer capacity, Date start, Vector<Long> sightids, String description) {
List<String> names = new ArrayList<String>();
List<Integer> types = new ArrayList<Integer>();
names.add("id");
types.add(Types.BIGINT);
names.add("name");
types.add(Types.VARCHAR);
names.add("capacity");
types.add(Types.TINYINT);
names.add("start");
types.add(Types.DATE);
names.add("description");
types.add(Types.VARCHAR);
names.add("corpId");
types.add(Types.BIGINT);
ColumnInfo info = null;
try {
info = new ColumnInfo(names, types);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
Long id;
try {
id = IdGenerationFactory.generateId(ObjectType.GROUP);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return false;
} catch (DBTableFullException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return false;
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", id);
map.put("name", name);
map.put("capacity", capacity);
map.put("start", new java.sql.Date(start.getTime()));
map.put("description", description);
map.put("corpId", corpid);
TableRow row = new TableRow("travelgroup", map, info);
try {
DbManager.insert(row);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
try{
for(int i = 0; i<sightids.size(); i++){
String sql = "insert into sightspot2group(groupId, sightspotId) values('" + id + "', '"+sightids.get(i)+"')";
DbManager.excute(sql);
}
}catch(Exception e){
e.printStackTrace();
return false;
}
return true;
}
/**
* @param email
* @return
* @throws Exception
*/
public static boolean exists(String email) throws Exception {
if(CacheManager.getByEmail(email)!=null){
return true;
}
return false;
}
/**
* @param name
* @return
* @throws Exception
*/
public static boolean existGroup(String name) throws Exception {
if(CacheManager.getByUnique(ObjectType.GROUP, "name", name)!=null){
return true;
}
return false;
}
/**
* @param name
* @return
* @throws Exception
*/
public static boolean existSight(String name) throws Exception {
if(CacheManager.getByUnique(ObjectType.SIGHTSPOT, "name", name)!=null){
return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -