From 48918dc0ea7434d239210c40991e64b1f3c5d7e1 Mon Sep 17 00:00:00 2001 From: coral <3080867419@qq.com> Date: Mon, 6 Jan 2020 07:12:56 +0800 Subject: [PATCH] second commit --- lostfoundcode/action/GoodsAction.java | 354 +++++++++++++++++ lostfoundcode/action/UserAction.java | 162 ++++++++ lostfoundcode/dao/ILoginDao.java | 53 +++ lostfoundcode/dao/IUserDao.java | 111 ++++++ lostfoundcode/dao/impl/LoginDao.java | 96 +++++ lostfoundcode/dao/impl/UserDao.java | 362 ++++++++++++++++++ lostfoundcode/model/Classify.hbm.xml | 26 ++ lostfoundcode/model/Classify.java | 57 +++ lostfoundcode/model/Goods.hbm.xml | 47 +++ lostfoundcode/model/Goods.java | 168 ++++++++ .../model/HibernateSessionFactory.java | 118 ++++++ lostfoundcode/model/PageBean.java | 47 +++ lostfoundcode/model/User.hbm.xml | 38 ++ lostfoundcode/model/User.java | 95 +++++ lostfoundcode/service/ILoginService.java | 53 +++ lostfoundcode/service/IUserService.java | 95 +++++ lostfoundcode/service/impl/LoginService.java | 79 ++++ lostfoundcode/service/impl/UserService.java | 264 +++++++++++++ 18 files changed, 2225 insertions(+) create mode 100644 lostfoundcode/action/GoodsAction.java create mode 100644 lostfoundcode/action/UserAction.java create mode 100644 lostfoundcode/dao/ILoginDao.java create mode 100644 lostfoundcode/dao/IUserDao.java create mode 100644 lostfoundcode/dao/impl/LoginDao.java create mode 100644 lostfoundcode/dao/impl/UserDao.java create mode 100644 lostfoundcode/model/Classify.hbm.xml create mode 100644 lostfoundcode/model/Classify.java create mode 100644 lostfoundcode/model/Goods.hbm.xml create mode 100644 lostfoundcode/model/Goods.java create mode 100644 lostfoundcode/model/HibernateSessionFactory.java create mode 100644 lostfoundcode/model/PageBean.java create mode 100644 lostfoundcode/model/User.hbm.xml create mode 100644 lostfoundcode/model/User.java create mode 100644 lostfoundcode/service/ILoginService.java create mode 100644 lostfoundcode/service/IUserService.java create mode 100644 lostfoundcode/service/impl/LoginService.java create mode 100644 lostfoundcode/service/impl/UserService.java diff --git a/lostfoundcode/action/GoodsAction.java b/lostfoundcode/action/GoodsAction.java new file mode 100644 index 0000000..daf6ffa --- /dev/null +++ b/lostfoundcode/action/GoodsAction.java @@ -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{ + + 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 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 map=new HashMap(); + /*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 proList=this.iUserService.searchLostGoodList(map); + this.json.toJsonObj(proList); + } + + public void searchFoundGoodList() throws Exception{ + String cid=req.getParameter("cid"); + Map map=new HashMap(); + if(cid!=null&&cid!=""){ + map.put("cid", cid); + } + map.put("currPage", currPage+""); + PageBean 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 map=new HashMap(); + map.put("currPage", currPage+""); + map.put("userId", user.getId()+""); + PageBean 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 map=new HashMap(); + map.put("currPage", currPage+""); + map.put("userId", user.getId()+""); + PageBean 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; + } + + + /** + * + *

Description: 删除我的商品

+ * @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 map=new HashMap(); + map.put("currPage", currPage+""); + map.put("userId", user.getId()+""); + map.put("flag", flag); + PageBean 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"; + } + }*/ + + + +} diff --git a/lostfoundcode/action/UserAction.java b/lostfoundcode/action/UserAction.java new file mode 100644 index 0000000..7127339 --- /dev/null +++ b/lostfoundcode/action/UserAction.java @@ -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=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"; + } + + + + +} diff --git a/lostfoundcode/dao/ILoginDao.java b/lostfoundcode/dao/ILoginDao.java new file mode 100644 index 0000000..4132442 --- /dev/null +++ b/lostfoundcode/dao/ILoginDao.java @@ -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); +} diff --git a/lostfoundcode/dao/IUserDao.java b/lostfoundcode/dao/IUserDao.java new file mode 100644 index 0000000..284e192 --- /dev/null +++ b/lostfoundcode/dao/IUserDao.java @@ -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 searchClassifyList(); + + /** + * 查询商品 + * @param map + * @return + */ + List searchLostGoodList(Map map); + List searchFoundGoodList(Map map); + /** + * 查询商品数量 + * @param map + * @return + */ + int searchLostGoodCount(Map map); + int searchFoundGoodCount(Map 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);*/ + + + /** + *

Description: 查询我发布的商品列表数量

+ * @param parseInt + * @return + */ + int searchMyLostGoodCount(int parseInt); + int searchMyFoundGoodCount(int parseInt); + /** + *

Description: 查询我发布的商品列表信息

+ * @param map + * @return + */ + List getMyLostGoodList(Map map); + List getMyFoundGoodList(Map map); + + + /** + *

Description: 删除我发布的商品

+ * @param pid + */ + void delectGoodById(int pid); + + + + + /** + *

Description: 保存用户消息

+ * @param map + * @return + */ +// void saveUserMessage(UserAdmin uaa); + + /** + *

Description: 保存用户消息数量

+ * @param map + * @return + */ +// int searchMessageCount(int uid, String flag); + + /** + *

Description: 保存用户消息

+ * @param map + * @return + */ +// List getMessageList(Map map); + + /** + * 通过id删除消息 + */ + void deleteMessage(int id); + + + +} diff --git a/lostfoundcode/dao/impl/LoginDao.java b/lostfoundcode/dao/impl/LoginDao.java new file mode 100644 index 0000000..3472772 --- /dev/null +++ b/lostfoundcode/dao/impl/LoginDao.java @@ -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 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 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 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); + + } + + + +} diff --git a/lostfoundcode/dao/impl/UserDao.java b/lostfoundcode/dao/impl/UserDao.java new file mode 100644 index 0000000..0d574f1 --- /dev/null +++ b/lostfoundcode/dao/impl/UserDao.java @@ -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 searchClassifyList() { + String hql="from Classify"; + return this.getHibernateTemplate().find(hql); + } + + /** + * 查询商品 + */ + @SuppressWarnings("unchecked") + @Override + public List searchLostGoodList(Map 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 list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize"))); + return list; + } + + /** + * 查询商品数量 + */ + @SuppressWarnings("unchecked") + @Override + public int searchLostGoodCount(Map 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 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 searchFoundGoodList(Map 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 list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize"))); + return list; + } + + /** + * 查询商品数量 + */ + @SuppressWarnings("unchecked") + @Override + public int searchFoundGoodCount(Map 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 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 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 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 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 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); + + }*/ + + + +/** + *

Description: 查询我发布的商品列表数量

+ * @param parseInt + * @return + */ + @SuppressWarnings("unchecked") +@Override +public int searchMyLostGoodCount(int uid) { + String hql="select count(*) from Product where user.uid = ? and goodsstatus='0'"; + List 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 list=this.getHibernateTemplate().find(hql,uid); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; +} + +/** + *

Description: 查询我发布的商品列表信息

+ * @param map + * @return + */ + @SuppressWarnings("unchecked") +@Override +public List getMyLostGoodList(Map 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 list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize"))); + return list; +} + + @SuppressWarnings("unchecked") + @Override + public List getMyFoundGoodList(Map 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 list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize"))); + return list; + } + + +/** + *

Description: 删除我发布的商品

+ * @param pid + */ +@Override +public void delectGoodById(int pid) { + Goods good=this.getHibernateTemplate().get(Goods.class, pid); + if(good!=null){ + this.getHibernateTemplate().delete(good); + } + +} + + +/** + *

Description: 保存用户消息

+ * @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 list=this.getHibernateTemplate().find(hql+sb.toString()); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; +} +@SuppressWarnings("unchecked") +@Override +public List getMessageList(Map 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 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(); + +} + + + + +} diff --git a/lostfoundcode/model/Classify.hbm.xml b/lostfoundcode/model/Classify.hbm.xml new file mode 100644 index 0000000..ace98b3 --- /dev/null +++ b/lostfoundcode/model/Classify.hbm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lostfoundcode/model/Classify.java b/lostfoundcode/model/Classify.java new file mode 100644 index 0000000..53fd5a3 --- /dev/null +++ b/lostfoundcode/model/Classify.java @@ -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; + } + + +} \ No newline at end of file diff --git a/lostfoundcode/model/Goods.hbm.xml b/lostfoundcode/model/Goods.hbm.xml new file mode 100644 index 0000000..c4c6c11 --- /dev/null +++ b/lostfoundcode/model/Goods.hbm.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lostfoundcode/model/Goods.java b/lostfoundcode/model/Goods.java new file mode 100644 index 0000000..6e4cd43 --- /dev/null +++ b/lostfoundcode/model/Goods.java @@ -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; + } + +} \ No newline at end of file diff --git a/lostfoundcode/model/HibernateSessionFactory.java b/lostfoundcode/model/HibernateSessionFactory.java new file mode 100644 index 0000000..76764a7 --- /dev/null +++ b/lostfoundcode/model/HibernateSessionFactory.java @@ -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 threadLocal = new ThreadLocal(); + 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 SessionFactory 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; + } + +} \ No newline at end of file diff --git a/lostfoundcode/model/PageBean.java b/lostfoundcode/model/PageBean.java new file mode 100644 index 0000000..9ab22ce --- /dev/null +++ b/lostfoundcode/model/PageBean.java @@ -0,0 +1,47 @@ +package model; + +import java.util.List; + +public class PageBean { + private int currPage;//当前页 + private int pageSize;//每页记录数 + private int totalCount;//总记录数 + private int totalPage;//总页数 + List 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 getList() { + return list; + } + public void setList(List list) { + this.list = list; + } + + + +} diff --git a/lostfoundcode/model/User.hbm.xml b/lostfoundcode/model/User.hbm.xml new file mode 100644 index 0000000..88df4b7 --- /dev/null +++ b/lostfoundcode/model/User.hbm.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lostfoundcode/model/User.java b/lostfoundcode/model/User.java new file mode 100644 index 0000000..704f8b6 --- /dev/null +++ b/lostfoundcode/model/User.java @@ -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; + } + + +} \ No newline at end of file diff --git a/lostfoundcode/service/ILoginService.java b/lostfoundcode/service/ILoginService.java new file mode 100644 index 0000000..cdefa27 --- /dev/null +++ b/lostfoundcode/service/ILoginService.java @@ -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); +} diff --git a/lostfoundcode/service/IUserService.java b/lostfoundcode/service/IUserService.java new file mode 100644 index 0000000..c35e4fd --- /dev/null +++ b/lostfoundcode/service/IUserService.java @@ -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 searchClassifyList(); + + /** + * 查询商品 + * @param map + * @return + */ + PageBean searchLostGoodList(Map map); + PageBean searchFoundGoodList(Map 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);*/ + + + + /** + *

Description: 查询我发布的商品列表信息

+ * @param map + * @return + */ + PageBean searchMyLostGoodByPage(Map map); + PageBean searchMyFoundGoodByPage(Map map); + + + /** + *

Description: 删除我发布的商品

+ * @param pid + */ + void delectGoodById(int pid); + + + /** + * 保存用户消息 + * @param uaa + */ + //void saveUserMessage(UserAdmin uaa); + + /** + * 分页消息 + * @throws Exception + * @param flag 0系统消息,1用户消息 + */ + //PageBean searchMessageByPage(Map map); + + /** + * 通过id删除消息 + * @param parseInt + */ + void deleteMessage(int id); + + + + + + + +} diff --git a/lostfoundcode/service/impl/LoginService.java b/lostfoundcode/service/impl/LoginService.java new file mode 100644 index 0000000..c724a28 --- /dev/null +++ b/lostfoundcode/service/impl/LoginService.java @@ -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); + + } + + + +} diff --git a/lostfoundcode/service/impl/UserService.java b/lostfoundcode/service/impl/UserService.java new file mode 100644 index 0000000..defabbc --- /dev/null +++ b/lostfoundcode/service/impl/UserService.java @@ -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 searchClassifyList() { + + return this.iUserDao.searchClassifyList(); + } + + /** + * 查询商品 + */ + @Override + public PageBean searchLostGoodList(Map map) { + PageBean pageBean=new PageBean(); + //封装当前页 + 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 list=this.iUserDao.searchLostGoodList(map); + pageBean.setList(list); + return pageBean; + + } + + @Override + public PageBean searchFoundGoodList(Map map) { + PageBean pageBean=new PageBean(); + //封装当前页 + 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 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); + + }*/ + + /** + *

Description: 查询我发布的商品列表信息

+ * @param map + * @return + */ + @Override + public PageBean searchMyLostGoodByPage(Map map) { + PageBean pageBean=new PageBean(); + //封装当前页 + 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 list=this.iUserDao.getMyLostGoodList(map); + pageBean.setList(list); + return pageBean; + } + + public PageBean searchMyFoundGoodByPage(Map map) { + PageBean pageBean=new PageBean(); + //封装当前页 + 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 list=this.iUserDao.getMyFoundGoodList(map); + pageBean.setList(list); + return pageBean; + } + + /** + *

Description: 删除我发布的商品

+ * @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 searchMessageByPage(Map map) { + PageBean pageBean=new PageBean(); + //封装当前页 + 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 list=this.iUserDao.getMessageList(map); + pageBean.setList(list); + return pageBean; + }*/ + + /** + * 通过id删除消息 + */ + @Override + public void deleteMessage(int id) { + this.iUserDao.deleteMessage(id); + + } + + + + + + +}