📄 hotspotadminserviceimp.java
字号:
package com.shandong.business.imp;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import org.apache.struts.upload.FormFile;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Expression;
import com.shandong.bean.RPanoramaHotspot;
import com.shandong.bean.THotspot;
import com.shandong.bean.base._BaseRootDAO;
import com.shandong.bean.dao.iface.RPanoramaHotspotDAO;
import com.shandong.bean.dao.iface.THotspotDAO;
import com.shandong.business.iface.HotspotAdminService;
import com.shandong.struts.form.HotspotForm;
import com.shandong.struts.form.QueryHotspotForm;
import com.shandong.util.FileUploadHelper;
public class HotspotAdminServiceImp implements HotspotAdminService {
public boolean newHotspot(HotspotForm form, String realPath) {
// TODO Auto-generated method stub
THotspot hotspot = new THotspot();
hotspot.setInfo(form.getInfo());
hotspot.setName(form.getName());
FormFile file = form.getVideo();
if (file != null) {
hotspot.setVideo(FileUploadHelper.saveFile(file, realPath));
}
try {
_BaseRootDAO.initialize();
THotspotDAO dao = new com.shandong.bean.dao.THotspotDAO();
dao.saveOrUpdate(hotspot);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public List findAllHotspot() {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
THotspotDAO dao = new com.shandong.bean.dao.THotspotDAO();
return dao.findAll();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public boolean deleteHotspot(int id, String realPath) {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
THotspotDAO dao = new com.shandong.bean.dao.THotspotDAO();
THotspot hotspot = dao.get(new Integer(id));
FileUploadHelper.deleteFile(hotspot.getVideo(), realPath);
dao.delete(hotspot);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean updateHotspot(HotspotForm form, String realPath) {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
THotspotDAO dao = new com.shandong.bean.dao.THotspotDAO();
THotspot hotspot = dao.get(new Integer(form.getId()));
hotspot.setName(form.getName());
hotspot.setInfo(form.getInfo());
if (form.getVideo() != null
&& !"".equals(form.getVideo().getFileName())) {
hotspot.setVideo(FileUploadHelper.rewriteFile(hotspot
.getVideo(), form.getVideo(), realPath));
}
dao.saveOrUpdate(hotspot);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public THotspot findHotspotById(int id) {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
THotspotDAO dao = new com.shandong.bean.dao.THotspotDAO();
THotspot hotspot = dao.get(new Integer(id));
return hotspot;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public List findHotspot(QueryHotspotForm form) {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
_BaseRootDAO dao = new com.shandong.bean.dao.THotspotDAO();
THotspot hotspot = new THotspot();
try {
int i = Integer.parseInt(form.getId());
hotspot.setId(new Integer(i));
} catch (Exception e) {
hotspot.setId(null);
}
hotspot.setName((form.getName() == null || ""
.equals(form.getName())) ? null : "%" + form.getName()
+ "%");
hotspot.setInfo((form.getInfo() == null || ""
.equals(form.getInfo())) ? null : "%" + form.getInfo()
+ "%");
hotspot.setVideo(null);
Example example = Example.create(hotspot).ignoreCase().enableLike();
Criteria criteria = dao.getSession().createCriteria(THotspot.class);
criteria.add(example);
if (hotspot.getId() != null) {
criteria.add(Expression.eq("id", hotspot.getId()));
}
return criteria.list();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public boolean deleteHotspotVideo(int id, String realPath) {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
THotspotDAO dao = new com.shandong.bean.dao.THotspotDAO();
THotspot hotspot = dao.get(new Integer(id));
hotspot.setVideo(null);
if (!FileUploadHelper.deleteFile(hotspot.getVideo(), realPath))
return false;
dao.saveOrUpdate(hotspot);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
protected int generateId() {
try {
_BaseRootDAO.initialize();
_BaseRootDAO dao = new com.shandong.bean.dao.THotspotDAO();
Query q = dao.getSession().createQuery(
"select max(c.id) from THotspot c");
List l = q.list();
// System.out.println(l.size());
Integer i = (Integer) (l.get(0));
return i.intValue() + 1;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
protected String generateLink(String info) {
String a = info.substring(0, 1);
String c = info.substring(1);
int d;
try {
d = Integer.parseInt(c);
} catch (Exception e) {
e.printStackTrace();
return null;
}
StringBuffer b = new StringBuffer();
if (a.toLowerCase().equals("p")) {
b.append("100-");
} else if (a.toLowerCase().equals("q")) {
b.append("101-");
} else if (a.toLowerCase().equals("a")) {
b.append("102-");
} else if (a.toLowerCase().equals("b")) {
b.append("103-");
} else if (a.toLowerCase().equals("c")) {
b.append("104-");
} else if (a.toLowerCase().equals("d")) {
b.append("105-");
} else if (a.toLowerCase().equals("e")) {
b.append("106-");
} else if (a.toLowerCase().equals("f")) {
b.append("107-");
} else if (a.toLowerCase().equals("g")) {
b.append("108-");
} else if (a.toLowerCase().equals("h")) {
b.append("109-");
} else if (a.toLowerCase().equals("i")) {
b.append("110-");
} else if (a.toLowerCase().equals("j")) {
b.append("111-");
} else if (a.toLowerCase().equals("k")) {
b.append("112-");
}
int f = d * 2 - 1;
if (f < 10) {
b.append("0");
}
b.append(f);
b.append("-");
int g = d * 2;
if (g < 10) {
b.append("0");
}
b.append(g);
return b.toString();
}
public boolean insertHotspot(String name, String info) {
// TODO Auto-generated method stub
try {
_BaseRootDAO.initialize();
THotspotDAO hsDao = new com.shandong.bean.dao.THotspotDAO();
RPanoramaHotspotDAO phDao = new com.shandong.bean.dao.RPanoramaHotspotDAO();
int id = generateId();
if (id == -1) {
return false;
}
THotspot hotspot = new THotspot();
hotspot.setId(id);
hotspot.setName(name);
hotspot.setInfo(info);
hotspot.setLink(generateLink(info));
RPanoramaHotspot ph = new RPanoramaHotspot();
ph.setPanorama(generateLink(name));
ph.setHotspot(id);
hsDao.save(hotspot);
phDao.save(ph);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean exportHotspot(List l, String fileName) {
try {
_BaseRootDAO.initialize();
_BaseRootDAO dao = new com.shandong.bean.dao.THotspotDAO();
StringBuffer hql = new StringBuffer("from THotspot t where ");
boolean first = true;
Iterator it = l.iterator();
while (it.hasNext()) {
if (first) {
first = false;
} else {
hql.append(" or ");
}
hql.append("t.Name like ");
hql.append("'%" + (String) (it.next()) + "%'");
}
List results = dao.getSession().createQuery(hql.toString()).list();
FileOutputStream fos = new FileOutputStream(fileName);
it = results.iterator();
while (it.hasNext()) {
THotspot hotspot = (THotspot) (it.next());
fos.write(hotspot.getName().getBytes());
fos.write(' ');
fos.write(hotspot.getInfo().getBytes());
fos.write("\r\n".getBytes());
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -