second commit

master
coral 5 years ago
parent a2121be839
commit 48918dc0ea

@ -0,0 +1,354 @@
package action;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import model.Classify;
import model.PageBean;
import model.Goods;
import model.User;
//import model.UserAdmin;
import org.apache.struts2.ServletActionContext;
import org.aspectj.util.FileUtil;
import service.IUserService;
import util.AddJson;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class GoodsAction extends ActionSupport implements ModelDriven<Goods>{
IUserService iUserService;
public void setiUserService(IUserService iUserService) {
this.iUserService = iUserService;
}
Goods good=new Goods();
@Override
public Goods getModel() {
return good;
}
HttpServletRequest req=ServletActionContext.getRequest();
AddJson json=new AddJson();
private int currPage=1;//当前页
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
private File proPictureFile;
private String proPictureFileFileName;
private String proPictureContentType;
private final int BUFFER_SIZE=16*1024;
private Integer classifyId;
public Integer getClassifyId() {
return classifyId;
}
public void setClassifyId(Integer classifyId) {
this.classifyId = classifyId;
}
public File getProPictureFile() {
return proPictureFile;
}
public void setProPictureFile(File proPictureFile) {
this.proPictureFile = proPictureFile;
}
public String getProPictureContentType() {
return proPictureContentType;
}
public void setProPictureContentType(String proPictureContentType) {
this.proPictureContentType = proPictureContentType;
}
public String getProPictureFileFileName() {
return proPictureFileFileName;
}
public void setProPictureFileFileName(String proPictureFileFileName) {
this.proPictureFileFileName = proPictureFileFileName;
}
/**
*
*/
public String addLostGood() throws Exception{
String newFileName=new Date().getTime()+getExtention(proPictureFileFileName);
String path=ServletActionContext.getServletContext().getRealPath("/upload");
File picFile=new File(path);
if(!picFile.exists()){
picFile.mkdir();
}
FileUtil.copyFile(proPictureFile, new File(picFile,newFileName));
//copy(proPictureFile,picFile);
good.setPicture(newFileName);
good.setCreateTime(new Date());
Classify c=this.iUserService.getClassifyById(good.getClassifyId());
User u=this.iUserService.getUserById(good.getCreatorId());
good.setClassify(c);
good.setUser(u);
good.setGoodsstatus(0);
this.iUserService.saveGood(good);
this.addActionMessage("发布成功!");
return "uploadSuccess";
}
public String addFoundGood() throws Exception{
String newFileName=new Date().getTime()+getExtention(proPictureFileFileName);
String path=ServletActionContext.getServletContext().getRealPath("/upload");
File picFile=new File(path);
if(!picFile.exists()){
picFile.mkdir();
}
FileUtil.copyFile(proPictureFile, new File(picFile,newFileName));
//copy(proPictureFile,picFile);
good.setPicture(newFileName);
good.setCreateTime(new Date());
Classify c=this.iUserService.getClassifyById(good.getClassifyId());
User u=this.iUserService.getUserById(good.getCreatorId());
good.setClassify(c);
good.setUser(u);
good.setGoodsstatus(1);
this.iUserService.saveGood(good);
this.addActionMessage("发布成功!");
return "uploadSuccess";
}
/**
* io
* @param src
* @param dst
* @throws Exception
*/
private void copy(File src, File dst)throws Exception {
InputStream in=null;
OutputStream out=null;
try {
in=new BufferedInputStream(new FileInputStream(src),BUFFER_SIZE);
out=new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
while(in.read(buffer)>0){
out.write(buffer);
}
} catch (Exception e) {
throw e;
}finally{
try {
in.close();
} catch (Exception e2) {
}
try {
out.close();
} catch (Exception e2) {
}
}
}
/**
*
* @param filename
* @return
*/
private String getExtention(String filename) {
int pos=filename.lastIndexOf(".");
return filename.substring(pos);
}
/**
*
* @throws IOException
*/
public void searchClassifyList() throws IOException{
List<Classify> list=this.iUserService.searchClassifyList();
this.json.toJsonArray(list);
}
/**
*
*/
public void searchLostGoodList() throws Exception{
//String keyword=req.getParameter("keyword");
String cid=req.getParameter("cid");
//String conditon=req.getParameter("condition");
Map<Object,String> map=new HashMap<Object,String>();
/*if(keyword!=null&&keyword!=""){
map.put("keyword", keyword);
}*/
if(cid!=null&&cid!=""){
map.put("cid", cid);
}
/*if(conditon!=null&&conditon!=""){
map.put("conditon", conditon);
}*/
map.put("currPage", currPage+"");
PageBean<Goods> proList=this.iUserService.searchLostGoodList(map);
this.json.toJsonObj(proList);
}
public void searchFoundGoodList() throws Exception{
String cid=req.getParameter("cid");
Map<Object,String> map=new HashMap<Object,String>();
if(cid!=null&&cid!=""){
map.put("cid", cid);
}
map.put("currPage", currPage+"");
PageBean<Goods> proList=this.iUserService.searchFoundGoodList(map);
this.json.toJsonObj(proList);
}
/**
*
*/
public void getLostGoodDetail() throws Exception{
String id=req.getParameter("id");
Goods good=this.iUserService.getLostGoodDetail(id);
this.json.toJson(good);
}
public void getFoundGoodDetail() throws Exception{
String id=req.getParameter("id");
Goods good=this.iUserService.getFoundGoodDetail(id);
this.json.toJson(good);
}
/**
*
* @throws Exception
*/
public void searchMyLostProductByPage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
Map<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getId()+"");
PageBean<Goods> myproList=this.iUserService.searchMyLostGoodByPage(map);
this.json.toJson(myproList);
}
}
public void searchMyProductByPage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
Map<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getId()+"");
PageBean<Goods> myproList=this.iUserService.searchMyFoundGoodByPage(map);
this.json.toJson(myproList);
}
}
private String repContent;
private String content;
public String getRepContent() {
return repContent;
}
public void setRepContent(String repContent) {
this.repContent = repContent;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
/**
*
* <p>Description: </p>
* @throws Exception
*/
public void deleteMyGoodById() throws Exception{
User user=(User) req.getSession().getAttribute("User");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
int pid=Integer.parseInt(req.getParameter("id"));
this.iUserService.delectGoodById(pid);
}
}
/**
*
* @throws Exception
* @param flag 0,1
*/
/* public String searchMessageByPage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
String flag="";
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
flag=req.getParameter("flag");//0系统消息,1用户消息
Map<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getId()+"");
map.put("flag", flag);
PageBean<UserAdmin> message=this.iUserService.searchMessageByPage(map);
if(message!=null){
ActionContext.getContext().getValueStack().push(message);
}
}
if(flag=="0"||"0".equals(flag)){
return "sysmessage";
}else{
return "usermessage";
}
}
private String flag;
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
/**
*
* @return
* @throws Exception
*/
/* public String deleteMessage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
//String flag=req.getParameter("flag");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
String id=req.getParameter("id");
this.iUserService.deleteMessage(Integer.parseInt(id));
}
if(flag=="0"||"0".equals(flag)){
return "sysmsgDelete";
}else{
return "usermsgDelete";
}
}*/
}

@ -0,0 +1,162 @@
package action;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import service.ILoginService;
import util.AddJson;
import model.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class UserAction extends ActionSupport implements ModelDriven<User>{
User user=new User();
@Override
public User getModel() {
return user;
}
ILoginService iLoginService;
public void setiLoginService(ILoginService iLoginService) {
this.iLoginService = iLoginService;
}
HttpServletRequest req=ServletActionContext.getRequest();
/**
*
* @return
*/
public String UserLogin(){
//HttpServletRequest req=ServletActionContext.getRequest();
if(user==null){
this.addActionError("请输入账号和密码!");
return "login";
}
User u=this.iLoginService.findByUser(user);
if(u==null){
this.addActionError("用户名或密码错误!");
return "login";
}else{
req.getSession().setAttribute("User", u);
return "index";
}
}
/**
*
*/
public String userRegister(){
//通过用户名先查询该用户是否已经注册
User u=this.iLoginService.findUserByName(user.getUsername());
if(u!=null){
this.addActionError("该用户已被注册!");
return "registerFail";
}
//user.setHeadPic("images/logo-s.jpg");
this.iLoginService.saveUser(user);
return "registerSuccess";
}
/**
* 1
*/
public String forgetPwd(){
//HttpServletRequest req=ServletActionContext.getRequest();
String userName=req.getParameter("userName");
User u=this.iLoginService.findUserByName(userName);
if(u==null){
this.addFieldError(userName, "用户名错误!");
return "getPwdFail";
}
if(u.getQusetion()==null){
this.addActionError("抱歉!你没有设置问题和密码!");
return "getPwdFail";
}
req.getSession().setAttribute("User", u);
return "getPwdSuccess";
}
/**
* 2
*/
public String checkAnswer(){
//HttpServletRequest req=ServletActionContext.getRequest();
String answertext=req.getParameter("answer");
User u=this.iLoginService.findUserByName(user.getUsername());
if(u!=null){
String answer=u.getAnswer();
if(!answer.equals(answertext)){
this.addActionError("抱歉!回答错误!");
return "answerFalse";
}
}
req.getSession().setAttribute("User", u);
return "answerTrue";
}
/**
* 3
*/
public String updatePwd(){
this.iLoginService.updatePed(user);
return "updatePwdSuccess";
}
/**
*
* @throws Exception
*/
public void searchPersonalInfo() throws Exception{
//HttpServletRequest req=ServletActionContext.getRequest();
int uid=Integer.parseInt(req.getParameter("uid"));
if(uid==0){
throw new Exception("用户不存在!");
}
user=this.iLoginService.searchUserInfoById(uid);
AddJson json=new AddJson();
json.toJson(user);
//return "findUserInfoSuccess";
}
/**
*
*/
public void updateUserInfoById(){
int uid=Integer.parseInt(req.getParameter("id"));
String uname=req.getParameter("userName");
String pass=req.getParameter("password");
String phone=req.getParameter("phone");
String qusetion=req.getParameter("qusetion");
String answer=req.getParameter("answer");
int sex=Integer.parseInt(req.getParameter("sex"));
User uu=new User();
uu.setAnswer(answer);
uu.setPassword(pass);
uu.setPhone(phone);
uu.setId(uid);
uu.setUsername(uname);
uu.setQusetion(qusetion);
uu.setSex(sex);
this.iLoginService.updateUser(uu);
}
/**
* 退
*/
public String userExitLogin(){
req.getSession().removeAttribute("User");
return "UserexitSuccess";
}
}

@ -0,0 +1,53 @@
package dao;
//import model.Admin;
import model.User;
public interface ILoginDao {
/**
*
* @param user
* @return
*/
User findByUser(User user);
/**
*
* @param admin
* @return
*/
//Admin findByAdmin(Admin admin);
/**
*
* @param userName
* @return
*/
User findUserByName(String userName);
/**
*
* @param user
*/
void saveUser(User user);
/**
*
* @param user
*/
void updatePed(User user);
/**
* id
* @param uid
* @return
*/
User searchUserInfoById(int uid);
/**
*
* @param user
*/
void updateUser(User user);
}

@ -0,0 +1,111 @@
package dao;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.Goods;
import model.User;
//import model.UserAdmin;
public interface IUserDao {
/**
*
* @param product
*/
void saveGood(Goods good);
/**
*
* @return
*/
List<Classify> searchClassifyList();
/**
*
* @param map
* @return
*/
List<Goods> searchLostGoodList(Map<Object, String> map);
List<Goods> searchFoundGoodList(Map<Object, String> map);
/**
*
* @param map
* @return
*/
int searchLostGoodCount(Map<Object, String> map);
int searchFoundGoodCount(Map<Object, String> map);
/**
*
* @param id
* @return
*/
Goods getLostGoodDetail(String id);
Goods getFoundGoodDetail(String id);
/**
* id
* @param classifyId
*/
Classify getClassifyById(Integer classifyId);
User getUserById(Integer creatorId);
/*void updateProduct(Product product);*/
/**
* <p>Description: </p>
* @param parseInt
* @return
*/
int searchMyLostGoodCount(int parseInt);
int searchMyFoundGoodCount(int parseInt);
/**
* <p>Description: </p>
* @param map
* @return
*/
List<Goods> getMyLostGoodList(Map<Object, String> map);
List<Goods> getMyFoundGoodList(Map<Object, String> map);
/**
* <p>Description: </p>
* @param pid
*/
void delectGoodById(int pid);
/**
* <p>Description: </p>
* @param map
* @return
*/
// void saveUserMessage(UserAdmin uaa);
/**
* <p>Description: </p>
* @param map
* @return
*/
// int searchMessageCount(int uid, String flag);
/**
* <p>Description: </p>
* @param map
* @return
*/
// List<UserAdmin> getMessageList(Map<Object, String> map);
/**
* id
*/
void deleteMessage(int id);
}

@ -0,0 +1,96 @@
package dao.impl;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
//import model.Admin;
import model.User;
import dao.ILoginDao;
public class LoginDao extends HibernateDaoSupport implements ILoginDao {
/**
*
*/
@Override
public User findByUser(User user) {
String hql="from User u where u.userName=? and u.password=?";
@SuppressWarnings("unchecked")
List<User> list=this.getHibernateTemplate().find(hql,user.getUsername(),user.getPassword());
if(list.size()>0){
return list.get(0);
}else{
return null;
}
}
/**
*
*/
/* @Override
public Admin findByAdmin(Admin admin) {
String hql="from Admin a where a.name=? and a.password=?";
@SuppressWarnings("unchecked")
List<Admin> list=this.getHibernateTemplate().find(hql, admin.getName(),admin.getPassword());
if(list.size()>0){
return list.get(0);
}else{
return null;
}
}*/
/**
*
*/
@Override
public User findUserByName(String userName) {
String hql="from User where userName=?";
@SuppressWarnings("unchecked")
List<User> list=this.getHibernateTemplate().find(hql,userName);
if(list.size()>0){
return list.get(0);
}
return null;
}
/**
*
*/
@Override
public void saveUser(User user) {
this.getHibernateTemplate().save(user);
}
/**
*
*/
@Override
public void updatePed(User user) {
User u=this.getHibernateTemplate().get(User.class, user.getId());
u.setPassword(user.getPassword());
this.getHibernateTemplate().update(u);
}
/**
* id
*/
@Override
public User searchUserInfoById(int uid) {
User u=this.getHibernateTemplate().get(User.class, uid);
return u;
}
/**
*
*/
@Override
public void updateUser(User user) {
this.getHibernateTemplate().update(user);
}
}

@ -0,0 +1,362 @@
package dao.impl;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.Goods;
import model.User;
//import model.UserAdmin;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import dao.IUserDao;
public class UserDao extends HibernateDaoSupport implements IUserDao {
/**
*
*/
@Override
public void saveGood(Goods good) {
this.getHibernateTemplate().saveOrUpdate (good);
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public List<Classify> searchClassifyList() {
String hql="from Classify";
return this.getHibernateTemplate().find(hql);
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public List<Goods> searchLostGoodList(Map<Object, String> map) {
String cid=map.get("cid");
DetachedCriteria dc=DetachedCriteria.forClass(Goods.class);
//dc.addOrder(Order.desc("createTime"));
//dc.add(Restrictions.ne("proHassum", 0));
/*if(proName!=null){
proName="%"+map.get("keyword")+"%";
dc.add(Restrictions.like("proName",proName, MatchMode.ANYWHERE));
}*/
if(cid!=null){
dc.add(Restrictions.eq("classify.cid",Integer.parseInt(cid)));
}
dc.add(Restrictions.eq("goodsStatus",0));
/*if(condition!=null){
int con=Integer.parseInt(condition);
switch(con){
case 5:
dc.add(Restrictions.eq("type",1));
break;
case 4:
dc.add(Restrictions.eq("type",0));
break;
case 1:
dc.addOrder(Order.desc("proClicknum"));
break;
case 2:
dc.addOrder(Order.asc("proPrice"));
break;
case 3:
dc.addOrder(Order.desc("proPrice"));
break;
}
}*/
List<Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public int searchLostGoodCount(Map<Object, String> map) {
StringBuffer br=new StringBuffer();
StringBuffer order=new StringBuffer();
//String proName=map.get("keyword");
String cid=map.get("cid");
//String condition=map.get("conditon");
String count_hql="select count(*) from Product where goodsstatus='0'";
/*if(proName!=null){
proName="%"+map.get("keyword")+"%";
br.append(" and proName like '"+proName+"'");
}*/
if(cid!=null){
br.append(" and classify.cid='"+Integer.parseInt(cid)+"'");
}
/*if(condition!=null){
int con=Integer.parseInt(condition);
order.append(" order by createTime DESC");
switch(con){
case 1:
order.append(" ,proClicknum DESC");
break;
case 2:
order.append(" ,proPrice ASC");
break;
case 3:
order.append(" ,proPrice DESC");
break;
case 4:
br.append(" and type=0");
break;
case 5:
br.append(" and type=1");
break;
}
}*/
List<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@SuppressWarnings("unchecked")
@Override
public List<Goods> searchFoundGoodList(Map<Object, String> map) {
String cid=map.get("cid");
DetachedCriteria dc=DetachedCriteria.forClass(Goods.class);
if(cid!=null){
dc.add(Restrictions.eq("classify.cid",Integer.parseInt(cid)));
}
dc.add(Restrictions.eq("goodsStatus",0));
List<Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public int searchFoundGoodCount(Map<Object, String> map) {
StringBuffer br=new StringBuffer();
StringBuffer order=new StringBuffer();
String cid=map.get("cid");
String count_hql="select count(*) from Product where goodsstatus='1'";
if(cid!=null){
br.append(" and classify.cid='"+Integer.parseInt(cid)+"'");
}
List<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public Goods getLostGoodDetail(String id) {
int pid=0;
if(id!=null&&id!=""){
pid=Integer.parseInt(id);
}
String hql=" from Product where id=?";
List<Goods> list=this.getHibernateTemplate().find(hql,pid);
if(list.size()>0){
Goods p=list.get(0);
return p;
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public Goods getFoundGoodDetail(String id) {
int pid=0;
if(id!=null&&id!=""){
pid=Integer.parseInt(id);
}
String hql=" from Product where id=?";
List<Goods> list=this.getHibernateTemplate().find(hql,pid);
if(list.size()>0){
Goods p=list.get(0);
return p;
}
return null;
}
@Override
public Classify getClassifyById(Integer classifyId) {
String hql="from Classify where cid=?";
@SuppressWarnings("unchecked")
List<Classify> c=this.getHibernateTemplate().find(hql, classifyId);
if(c.size()>0){
Classify cla=c.get(0);
return cla;
}
return null;
}
@Override
public User getUserById(Integer creatorId) {
String hql="from User where uid=?";
@SuppressWarnings("unchecked")
List<User> u=this.getHibernateTemplate().find(hql, creatorId);
if(u.size()>0){
User user=u.get(0);
return user;
}
return null;
}
/*@Override
public void updateProduct(Product product) {
this.getHibernateTemplate().update(product);
}*/
/**
* <p>Description: </p>
* @param parseInt
* @return
*/
@SuppressWarnings("unchecked")
@Override
public int searchMyLostGoodCount(int uid) {
String hql="select count(*) from Product where user.uid = ? and goodsstatus='0'";
List<Long> list=this.getHibernateTemplate().find(hql,uid);
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@SuppressWarnings("unchecked")
@Override
public int searchMyFoundGoodCount(int uid) {
String hql="select count(*) from Product where user.uid = ? and goodsstatus='1'";
List<Long> list=this.getHibernateTemplate().find(hql,uid);
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
/**
* <p>Description: </p>
* @param map
* @return
*/
@SuppressWarnings("unchecked")
@Override
public List<Goods> getMyLostGoodList(Map<Object, String> map) {
DetachedCriteria dc=DetachedCriteria.forClass(model.Goods.class);
dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId"))));
dc.add(Restrictions.eq("goodsstatus",0));
dc.addOrder(Order.desc("createTime"));
List<model.Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
@SuppressWarnings("unchecked")
@Override
public List<Goods> getMyFoundGoodList(Map<Object, String> map) {
DetachedCriteria dc=DetachedCriteria.forClass(model.Goods.class);
dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId"))));
dc.add(Restrictions.eq("goodsstatus",1));
dc.addOrder(Order.desc("createTime"));
List<model.Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
* <p>Description: </p>
* @param pid
*/
@Override
public void delectGoodById(int pid) {
Goods good=this.getHibernateTemplate().get(Goods.class, pid);
if(good!=null){
this.getHibernateTemplate().delete(good);
}
}
/**
* <p>Description: </p>
* @param map
* @return
*/
/*@Override
public void saveUserMessage(UserAdmin uaa) {
this.getHibernateTemplate().save(uaa);
}
@SuppressWarnings("unchecked")
@Override
public int searchMessageCount(int uid, String flag) {
StringBuffer sb=new StringBuffer();
String hql="select count(*) from UserAndAdmin where 1=1 ";
if(flag=="0"||"0".equals(flag)){
sb.append(" and status='0' and userId="+uid);
}else{
sb.append(" and status='1' and userId="+uid);
}
List<Long> list=this.getHibernateTemplate().find(hql+sb.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@SuppressWarnings("unchecked")
@Override
public List<UserAdmin> getMessageList(Map<Object, String> map) {
DetachedCriteria dc=DetachedCriteria.forClass(model.UserAdmin.class);
String flag=map.get("flag");
if(flag=="0"||"0".equals(flag)){
dc.add(Restrictions.eq("userId",Integer.parseInt( map.get("userId"))));
dc.add(Restrictions.eq("status",0));
}else{
dc.add(Restrictions.eq("userId",Integer.parseInt( map.get("userId"))));
dc.add(Restrictions.eq("status",1));
}
List<model.UserAdmin> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}*/
/**
* id
*/
@Override
public void deleteMessage(int id) {
String hql="delete from UserAndAdmin where id="+id;
SessionFactory factory=this.getHibernateTemplate().getSessionFactory();
Session session=factory.openSession();
Query query=session.createQuery(hql);
query.executeUpdate();
session.close();
}
}

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="model.TClassify" table="t_classify" catalog="lostfound">
<id name="cid" type="java.lang.Integer">
<column name="CID" />
<generator class="identity" />
</id>
<property name="cname" type="java.lang.String">
<column name="CNAME" />
</property>
<property name="csort" type="java.lang.Integer">
<column name="CSORT" />
</property>
<set name="TGoodses" inverse="true">
<key>
<column name="classify_id" />
</key>
<one-to-many class="model.TGoods" />
</set>
</class>
</hibernate-mapping>

@ -0,0 +1,57 @@
package model;
import java.util.HashSet;
import java.util.Set;
/**
* TClassify entity. @author MyEclipse Persistence Tools
*/
public class Classify implements java.io.Serializable {
// Fields
private Integer cid;
private String cname;
private Integer csort;
// Constructors
/** default constructor */
public Classify() {
}
/** full constructor */
public Classify(String cname, Integer csort) {
this.cname = cname;
this.csort = csort;
}
// Property accessors
public Integer getCid() {
return this.cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCname() {
return this.cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public Integer getCsort() {
return this.csort;
}
public void setCsort(Integer csort) {
this.csort = csort;
}
}

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="model.Goods" table="t_goods" catalog="lostfound">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="assigned" />
</id>
<many-to-one name="user" class="model.User" fetch="select">
<column name="creator_id" not-null="true" />
</many-to-one>
<many-to-one name="classify" class="model.Classify" fetch="select">
<column name="classify_id" />
</many-to-one>
<property name="goodsdescribe" type="java.lang.String">
<column name="goodsdescribe" />
</property>
<property name="goodsname" type="java.lang.String">
<column name="goodsname" length="30" />
</property>
<property name="goodsstatus" type="java.lang.Integer">
<column name="goodsstatus" not-null="true" />
</property>
<property name="goodstime" type="java.sql.Timestamp">
<column name="goodstime" length="19" />
</property>
<property name="area" type="java.lang.String">
<column name="area" length="30" />
</property>
<property name="contact" type="java.lang.String">
<column name="contact" length="30" />
</property>
<property name="qq" type="java.lang.String">
<column name="qq" length="30" />
</property>
<property name="picture" type="java.lang.String">
<column name="picture" length="255" />
</property>
<property name="createTime" type="java.sql.Timestamp">
<column name="createtime" length="19" />
</property>
</class>
</hibernate-mapping>

@ -0,0 +1,168 @@
package model;
import java.sql.Timestamp;
import java.util.Date;
/**
* TGoods entity. @author MyEclipse Persistence Tools
*/
public class Goods implements java.io.Serializable {
// Fields
private Integer id;
private User user;
private Classify classify;
private String goodsdescribe;
private String goodsname;
private Integer goodsstatus;//区分招领和寻物
private Date goodstime;//什么时候捡到的、丢的
private String area;
private String contact;//联系人姓名
private String qq;
private String picture;
private Date createTime;
private Integer creatorId;//发布者id
private Integer classifyId;//分类id
// Constructors
/** default constructor */
public Goods() {
}
/** minimal constructor */
/*public Goods(Integer id, User TUser, Integer goodsstatus) {
this.id = id;
this.User = TUser;
this.goodsstatus = goodsstatus;
}
/** full constructor */
/*public Goods(Integer id, User TUser, Classify TClassify,
String goodsdescribe, String goodsname, Integer goodsstatus,
Timestamp goodstime, String area, String contact, String qq) {
this.id = id;
this.TUser = TUser;
this.TClassify = TClassify;
this.goodsdescribe = goodsdescribe;
this.goodsname = goodsname;
this.goodsstatus = goodsstatus;
this.goodstime = goodstime;
this.area = area;
this.contact = contact;
this.qq = qq;
}*/
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public String getGoodsdescribe() {
return this.goodsdescribe;
}
public void setGoodsdescribe(String goodsdescribe) {
this.goodsdescribe = goodsdescribe;
}
public String getGoodsname() {
return this.goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
public Integer getGoodsstatus() {
return this.goodsstatus;
}
public void setGoodsstatus(Integer goodsstatus) {
this.goodsstatus = goodsstatus;
}
public Date getGoodstime() {
return this.goodstime;
}
public void setGoodstime(Timestamp goodstime) {
this.goodstime = goodstime;
}
public String getArea() {
return this.area;
}
public void setArea(String area) {
this.area = area;
}
public String getContact() {
return this.contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getQq() {
return this.qq;
}
public void setQq(String qq) {
this.qq = qq;
}
public Integer getCreatorId() {
return creatorId;
}
public void setCreatorId(Integer creatorId) {
this.creatorId = creatorId;
}
public Integer getClassifyId() {
return classifyId;
}
public void setClassifyId(Integer classifyId) {
this.classifyId = classifyId;
}
public Classify getClassify() {
return classify;
}
public void setClassify(Classify classify) {
this.classify = classify;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

@ -0,0 +1,118 @@
package model;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}

@ -0,0 +1,47 @@
package model;
import java.util.List;
public class PageBean<T> {
private int currPage;//当前页
private int pageSize;//每页记录数
private int totalCount;//总记录数
private int totalPage;//总页数
List<T> list;//每页显示的数据
public PageBean() {
}
public int getCurrPage() {
return currPage;
}
public void setCurrPage(int currPage) {
this.currPage = currPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
}

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="model.TUser" table="t_user" catalog="lostfound">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="username" type="java.lang.String">
<column name="username" />
</property>
<property name="sex" type="java.lang.Integer">
<column name="SEX" />
</property>
<property name="phone" type="java.lang.String">
<column name="PHONE" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="qusetion" type="java.lang.String">
<column name="QUSETION" />
</property>
<property name="answer" type="java.lang.String">
<column name="ANSWER" />
</property>
<set name="TGoodses" inverse="true">
<key>
<column name="user_id" not-null="true" />
</key>
<one-to-many class="model.TGoods" />
</set>
</class>
</hibernate-mapping>

@ -0,0 +1,95 @@
package model;
import java.util.HashSet;
import java.util.Set;
/**
* TUser entity. @author MyEclipse Persistence Tools
*/
public class User implements java.io.Serializable {
// Fields
private Integer id;
private String username;
private Integer sex;
private String phone;
private String password;
private String qusetion;
private String answer;
// Constructors
/** default constructor */
public User() {
}
/** full constructor */
public User(String username, String password,String qusetion, String answer) {
this.username = username;
this.password = password;
this.qusetion = qusetion;
this.answer = answer;
}
// Property accessors
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public Integer getSex() {
return this.sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getQusetion() {
return this.qusetion;
}
public void setQusetion(String qusetion) {
this.qusetion = qusetion;
}
public String getAnswer() {
return this.answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}

@ -0,0 +1,53 @@
package service;
//import model.Admin;
import model.User;
public interface ILoginService {
/**
*
* @param user
* @return
*/
User findByUser(User user);
/**
*
* @param admin
* @return
*/
//Admin findByAdmin(Admin admin);
/**
*
* @param userName
* @return
*/
User findUserByName(String userName);
/**
*
* @param user
*/
void saveUser(User user);
/**
*
* @param user
*/
void updatePed(User user);
/**
* id
* @param uid
* @return
*/
User searchUserInfoById(int uid);
/**
*
* @param user
*/
void updateUser(User user);
}

@ -0,0 +1,95 @@
package service;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.PageBean;
import model.Goods;
import model.User;
//import model.UserAdmin;
public interface IUserService {
/**
*
* @param product
*/
void saveGood(Goods good);
/**
*
* @return
*/
List<Classify> searchClassifyList();
/**
*
* @param map
* @return
*/
PageBean<Goods> searchLostGoodList(Map<Object, String> map);
PageBean<Goods> searchFoundGoodList(Map<Object, String> map);
/**
*
* @param id
* @return
*/
Goods getLostGoodDetail(String id);
Goods getFoundGoodDetail(String id);
/**
* id
* @param classifyId
*/
Classify getClassifyById(Integer classifyId);
User getUserById(Integer creatorId);
/*void updateProduct(Product product);*/
/**
* <p>Description: </p>
* @param map
* @return
*/
PageBean<Goods> searchMyLostGoodByPage(Map<Object, String> map);
PageBean<Goods> searchMyFoundGoodByPage(Map<Object, String> map);
/**
* <p>Description: </p>
* @param pid
*/
void delectGoodById(int pid);
/**
*
* @param uaa
*/
//void saveUserMessage(UserAdmin uaa);
/**
*
* @throws Exception
* @param flag 0,1
*/
//PageBean<UserAdmin> searchMessageByPage(Map<Object, String> map);
/**
* id
* @param parseInt
*/
void deleteMessage(int id);
}

@ -0,0 +1,79 @@
package service.impl;
import org.springframework.transaction.annotation.Transactional;
import dao.ILoginDao;
//import model.Admin;
import model.User;
import service.ILoginService;
@Transactional
public class LoginService implements ILoginService{
private ILoginDao iLoginDao;
public void setiLoginDao(ILoginDao iLoginDao) {
this.iLoginDao = iLoginDao;
}
/**
*
*/
@Override
public User findByUser(User user) {
return iLoginDao.findByUser(user);
}
/**
*
*/
/* @Override
public Admin findByAdmin(Admin admin) {
return iLoginDao.findByAdmin(admin);
}*/
/**
*
*/
@Override
public User findUserByName(String userName) {
return this.iLoginDao.findUserByName(userName);
}
/**
*
*/
@Override
public void saveUser(User user) {
this.iLoginDao.saveUser(user);
}
/**
*
*/
@Override
public void updatePed(User user) {
this.iLoginDao.updatePed(user);
}
/**
* id
*/
@Override
public User searchUserInfoById(int uid) {
return this.iLoginDao.searchUserInfoById(uid);
}
/**
*
*/
@Override
public void updateUser(User user) {
this.iLoginDao.updateUser(user);
}
}

@ -0,0 +1,264 @@
package service.impl;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.PageBean;
import model.Goods;
import model.User;
//import model.UserAdmin;
import org.springframework.transaction.annotation.Transactional;
import service.IUserService;
import dao.IUserDao;
@Transactional
public class UserService implements IUserService {
private IUserDao iUserDao;
public void setiUserDao(IUserDao iUserDao) {
this.iUserDao = iUserDao;
}
Integer currPage=1;
/**
*
*/
@Override
public void saveGood(Goods good) {
this.iUserDao.saveGood(good);
}
/**
*
*/
@Override
public List<Classify> searchClassifyList() {
return this.iUserDao.searchClassifyList();
}
/**
*
*/
@Override
public PageBean<Goods> searchLostGoodList(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=12;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchLostGoodCount(map);
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.searchLostGoodList(map);
pageBean.setList(list);
return pageBean;
}
@Override
public PageBean<Goods> searchFoundGoodList(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=12;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchFoundGoodCount(map);
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.searchFoundGoodList(map);
pageBean.setList(list);
return pageBean;
}
/**
*
*/
@Override
public Goods getLostGoodDetail(String id) {
return this.iUserDao.getLostGoodDetail(id);
}
@Override
public Goods getFoundGoodDetail(String id) {
return this.iUserDao.getFoundGoodDetail(id);
}
@Override
public Classify getClassifyById(Integer classifyId) {
return this.iUserDao.getClassifyById(classifyId);
}
@Override
public User getUserById(Integer creatorId) {
return this.iUserDao.getUserById(creatorId);
}
/*@Override
public void updateProduct(Product product) {
this.iUserDao.updateProduct(product);
}*/
/**
* <p>Description: </p>
* @param map
* @return
*/
@Override
public PageBean<Goods> searchMyLostGoodByPage(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=5;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchMyLostGoodCount(Integer.parseInt(map.get("userId")));
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.getMyLostGoodList(map);
pageBean.setList(list);
return pageBean;
}
public PageBean<Goods> searchMyFoundGoodByPage(Map<Object, String> map) {
PageBean<Goods> pageBean=new PageBean<Goods>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=5;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchMyFoundGoodCount(Integer.parseInt(map.get("userId")));
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<Goods> list=this.iUserDao.getMyFoundGoodList(map);
pageBean.setList(list);
return pageBean;
}
/**
* <p>Description: </p>
* @param pid
*/
@Override
public void delectGoodById(int pid) {
this.iUserDao.delectGoodById(pid);
}
/**
*
* @param uaa
*/
/* @Override
public void saveUserMessage(UserAdmin uaa) {
this.iUserDao.saveUserMessage(uaa);
}
/**
*
* @throws Exception
* @param flag 0,1
*/
/* @Override
public PageBean<UserAdmin> searchMessageByPage(Map<Object, String> map) {
PageBean<UserAdmin> pageBean=new PageBean<UserAdmin>();
//封装当前页
currPage=Integer.parseInt(map.get("currPage"));
pageBean.setCurrPage(currPage);
//封装每页记录数
int pageSize=10;
pageBean.setPageSize(pageSize);
//封装总记录数
int totalCount=this.iUserDao.searchMessageCount(Integer.parseInt(map.get("userId")),map.get("flag"));
pageBean.setTotalCount(totalCount);
//封装总页数
double tc=totalCount;
Double num=Math.ceil(tc/pageSize);
if(num==0){
num=(double) 1;
}
pageBean.setTotalPage(num.intValue());
//封装每页显示的数据
int begin=(currPage-1)*pageSize;
map.put("begin", begin+"");
map.put("pageSize", pageSize+"");
List<UserAdmin> list=this.iUserDao.getMessageList(map);
pageBean.setList(list);
return pageBean;
}*/
/**
* id
*/
@Override
public void deleteMessage(int id) {
this.iUserDao.deleteMessage(id);
}
}
Loading…
Cancel
Save