diff --git a/secondHandcode/action/AdminAction.java b/secondHandcode/action/AdminAction.java new file mode 100644 index 0000000..1dce94f --- /dev/null +++ b/secondHandcode/action/AdminAction.java @@ -0,0 +1,340 @@ +package action; + + +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import model.Admin; +import model.Classify; +import model.PageBean; +import model.Product; +import model.User; +import model.UserAndAdmin; + +import org.apache.struts2.ServletActionContext; + +import service.IAdminInfoService; +import service.ILoginService; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.ModelDriven; + +public class AdminAction extends ActionSupport implements ModelDriven{ + + Admin admin=new Admin(); + @Override + public Admin getModel() { + return admin; + } + + ILoginService iLoginService; + public void setiLoginService(ILoginService iLoginService) { + this.iLoginService = iLoginService; + } + + IAdminInfoService iAdminInfoService; + public void setiAdminInfoService(IAdminInfoService iAdminInfoService) { + this.iAdminInfoService = iAdminInfoService; + } + + + /** + * 管理员登录 + */ + public String AdminLogin(){ + HttpServletRequest req=ServletActionContext.getRequest(); + if(admin==null){ + this.addActionError("请输入账号和密码!"); + return "adminLogin"; + } + Admin a=this.iLoginService.findByAdmin(admin); + if(a==null){ + this.addActionError("管理员帐户或密码错误!"); + return "adminLogin"; + }else{ + req.getSession().setAttribute("Admin", admin); + return "adminIndex"; + } + } + + /** + * 注销登录 + */ + public String Exitlogin(){ + HttpServletRequest req=ServletActionContext.getRequest(); + req.getSession().removeAttribute("Admin"); + return "adminLogin"; + } + + private int currPage=1;//当前页 + + public void setCurrPage(int currPage) { + this.currPage = currPage; + } + + + /** + * 查询所有管理员 + */ + public String findAllAdminInfo(){ + PageBean pageBean=this.iAdminInfoService.findAllAdminInfo(currPage); + if(pageBean!=null){ + ActionContext.getContext().getValueStack().push(pageBean); + } + return "adminList"; + + } + + /** + * 查询所有用户 + */ + public String findAllUserInfo(){ + HttpServletRequest req=ServletActionContext.getRequest(); + String name=req.getParameter("userName"); + if(name==null){ + name=""; + } + PageBean pageBean=this.iAdminInfoService.findAllUserInfo(currPage,name); + if(pageBean!=null){ + ActionContext.getContext().getValueStack().push(pageBean); + } + return "userList"; + + } + /** + * 查询所有分类 + */ + public String findAllCateInfo(){ + HttpServletRequest req=ServletActionContext.getRequest(); + String name=req.getParameter("classifyName"); + if(name==null){ + name=""; + } + PageBean pageBean=this.iAdminInfoService.findAllCateInfo(currPage,name); + if(pageBean!=null){ + ActionContext.getContext().getValueStack().push(pageBean); + } + return "cateList"; + + } + + /** + * 查询所有商品 + */ + public String findAllProductInfo(){ + HttpServletRequest req=ServletActionContext.getRequest(); + String name=req.getParameter("proName"); + String cate=req.getParameter("select_class"); + String type=req.getParameter("select_type"); + int cate1=0; + int type1=2; + if(name==null){ + name=""; + } + if(cate!=null&&cate!=""){ + cate1=Integer.parseInt(req.getParameter("select_class")); + } + if(type!=null&&type!=""){ + type1=Integer.parseInt(req.getParameter("select_type")); + } + PageBean pageBean=this.iAdminInfoService.findAllProductInfo(currPage,name,cate1,type1); + if(pageBean!=null){ + ActionContext.getContext().getValueStack().push(pageBean); + } + List cateList=this.iAdminInfoService.findAllCateList(); + if(cateList!=null){ + ActionContext.getContext().put("cateList", cateList); + } + return "productList"; + + } + + + /** + * 查询单个商品详情信息 + */ + public String searchProductDetail(){ + HttpServletRequest req=ServletActionContext.getRequest(); + int pid=Integer.parseInt(req.getParameter("id")); + Product product=this.iAdminInfoService.searchProductDetail(pid); + if(product!=null){ + ActionContext.getContext().put("product", product); + } + return "productDetail"; + } + /** + * 根据id删除单个商品 + */ + public String delectProductById(){ + HttpServletRequest req=ServletActionContext.getRequest(); + int pid=Integer.parseInt(req.getParameter("id")); + Product p=this.iAdminInfoService.searchProductDetail(pid); + this.iAdminInfoService.delectProductById(pid); + Admin admin=(Admin) req.getSession().getAttribute("Admin"); + UserAndAdmin uaa=new UserAndAdmin(); + uaa.setAdminId(admin.getAid()); + uaa.setCreateTime(new Date()); + uaa.setStatus(0); + uaa.setUserId(p.getUser().getUid()); + uaa.setMessage("您的商品【"+p.getTitle()+"】违反本网站的规章制度,已被管理员删除!"); + this.iAdminInfoService.saveSystemMessage(uaa); + return "success"; + } + + /** + * 查询用户详情信息 + * @return + */ + public String searchUserDetail(){ + HttpServletRequest req=ServletActionContext.getRequest(); + int uid=Integer.parseInt(req.getParameter("uid")); + User user=this.iAdminInfoService.searchUserDetail(uid); + if(user!=null){ + ActionContext.getContext().put("user", user); + } + return "userDetail"; + } + + /** + * 根据id删除分类 + */ + public String delectCateById(){ + HttpServletRequest req=ServletActionContext.getRequest(); + int id=Integer.parseInt(req.getParameter("id")); + this.iAdminInfoService.delectCateById(id); + return "delCatesuccess"; + } + + /** + * 根据id删除管理员 + */ + public String delectAdminById(){ + HttpServletRequest req=ServletActionContext.getRequest(); + int id=Integer.parseInt(req.getParameter("id")); + this.iAdminInfoService.delectAdminById(id); + return "delAdminsuccess"; + } + + /** + * 新增管理员 + */ + public String addAdmin(){ + Admin a=this.iAdminInfoService.findAdminByName(admin.getName()); + if(a!=null){ + this.addActionError("该账号已存在!"); + return "addAdminFail"; + } + this.iAdminInfoService.addAdmin(admin); + return "addAdminSucess"; + } + /** + * 管理员修改前回显内容 + */ + public String findAdminById(){ + admin=this.iAdminInfoService.findAdminById(admin.getAid()); + ActionContext.getContext().put("admin", admin); + return "findAdminSuccess"; + } + /** + * 管理员修改 + */ + public String updateAdmin(){ + /*Admin a=this.iAdminInfoService.findAdminByName(admin.getName()); + if(a!=null){ + this.addActionError("该账号已存在!"); + return "updateAdminFail"; + }*/ + this.iAdminInfoService.updateAdmin(admin); + return "updateAdminSuccess"; + + } + + + Classify cassify=new Classify(); + + public Classify getCassify() { + return cassify; + } + + public void setCassify(Classify cassify) { + this.cassify = cassify; + } + + private String classifyName; + private Integer classifySort; + private Integer cid; + public String getClassifyName() { + return classifyName; + } + + public void setClassifyName(String classifyName) { + this.classifyName = classifyName; + } + + public Integer getClassifySort() { + return classifySort; + } + + public void setClassifySort(Integer classifySort) { + this.classifySort = classifySort; + } + + + public Integer getCid() { + return cid; + } + + + public void setCid(Integer cid) { + this.cid = cid; + } + + + /** + * 新增分类 + */ + public String addCate(){ + cassify.setClassifyName(classifyName); + cassify.setClassifySort(classifySort); + Classify c=this.iAdminInfoService.findCateByName(classifyName); + if(c!=null){ + this.addActionError("该分类已存在!"); + return "addCateFail"; + } + this.iAdminInfoService.addCate(cassify); + return "addCateSucess"; + } + + /** + * 修改分类前回显 + */ + public String findCateByName(){ + HttpServletRequest req=ServletActionContext.getRequest(); + String cname=req.getParameter("cname"); + Classify c=this.iAdminInfoService.findCateByName(cname); + ActionContext.getContext().put("cate", c); + return "findCateSuccess"; + } + /** + * 修改分类 + */ + public String updateCate(){ + /*Classify c=this.iAdminInfoService.findCateByName(classifyName); + if(c!=null){ + this.addActionError("该分类已存在!"); + return "updateCateFail"; + }*/ + cassify.setCid(cid); + cassify.setClassifyName(classifyName); + cassify.setClassifySort(classifySort); + this.iAdminInfoService.updateCate(cassify); + return "updateCateSuccess"; + + } + + + +} diff --git a/secondHandcode/action/ProductAction.java b/secondHandcode/action/ProductAction.java new file mode 100644 index 0000000..bf8ef5e --- /dev/null +++ b/secondHandcode/action/ProductAction.java @@ -0,0 +1,307 @@ +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.Product; +import model.User; +import model.UserAndAdmin; + +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 ProductAction extends ActionSupport implements ModelDriven{ + + IUserService iUserService; + public void setiUserService(IUserService iUserService) { + this.iUserService = iUserService; + } + + + Product product=new Product(); + @Override + public Product getModel() { + return product; + } + 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 addProduct() 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);将上传的图片存储到picFile + product.setPicture(newFileName); + product.setCreateTime(new Date()); + Classify c=this.iUserService.getClassifyById(product.getClassifyId()); + User u=this.iUserService.getUserById(product.getCreatorId()); + product.setClassify(c); + product.setUser(u); + this.iUserService.saveProduct(product); + 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 searchProductList() 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.searchProductList(map); + this.json.toJsonObj(proList); + } + + /** + * 查询商品详情 + */ + public void getProductDetail() throws Exception{ + String id=req.getParameter("id"); + Product product=this.iUserService.getProductDetail(id); + this.json.toJson(product); + /*int clickNum=product.getProClicknum(); + product.setProClicknum(clickNum+1); + this.iUserService.updateProduct(product);*/ + } + + + /** + * 分页查询我发布的商品列表信息 + * @throws Exception + */ + 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.getUid()+""); + PageBean myproList=this.iUserService.searchMyProductByPage(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 deleteMyProductById() 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.delectProductById(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.getUid()+""); + 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/secondHandcode/action/UserAction.java b/secondHandcode/action/UserAction.java new file mode 100644 index 0000000..588e66a --- /dev/null +++ b/secondHandcode/action/UserAction.java @@ -0,0 +1,165 @@ +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("uid")); + String uname=req.getParameter("userName"); + String pass=req.getParameter("password"); + String uclass=req.getParameter("schoolClass"); + String address=req.getParameter("address"); + 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.setAddress(address); + uu.setAnswer(answer); + uu.setPassword(pass); + uu.setPhone(phone); + uu.setUid(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/secondHandcode/dao/IAdminInfoDao.java b/secondHandcode/dao/IAdminInfoDao.java new file mode 100644 index 0000000..218a131 --- /dev/null +++ b/secondHandcode/dao/IAdminInfoDao.java @@ -0,0 +1,168 @@ +package dao; + +import java.util.List; + +import model.Admin; +import model.Classify; +import model.Product; +import model.User; +import model.UserAndAdmin; + +public interface IAdminInfoDao { + + /** + * 查询管理员数量 + * @return + */ + int findAdminCount(); + + /** + * 分页查询管理员列表 + * @param begin + * @param pageSize + * @return + */ + List findAllAdminInfo(int begin, int pageSize); + + /** + * 查询用户数量 + * @param name + * @return + */ + int findUserCount(String name); + + /** + * 分页查询用户列表 + * @param begin + * @param pageSize + * @param name + * @return + */ + List findAllUserInfo(int begin, int pageSize,String name); + + /** + * 查询分类数量 + * @param name + * @return + */ + int findCateCount(String name); + + /** + * 分页查询分类列表 + * @param begin + * @param pageSize + * @param name + * @return + */ + List findAllCateInfo(int begin, int pageSize, String name); + + /** + * 查询商品数量 + * @param name + * @param cate + * @param type + * @return + */ + int findProductCount(String name, int cate, int type); + + /** + * 查询商品列表 + * @param begin + * @param pageSize + * @param name + * @param cate + * @param type + * @return + */ + List findAllProductInfo(int begin, int pageSize, String name, int cate, int type); + + /** + * 分类列表查询 + * @return + */ + List findAllCateList(); + + /** + * 查询商品详情 + * @param pid + * @return + */ + Product searchProductDetail(int pid); + + /** + * 删除商品 + * @param pid + */ + void delectProductById(int pid); + + /** + * 查询用户详情 + * @param uid + * @return + */ + User searchUserDetail(int uid); + + /** + * 删除分类 + * @param id + */ + void delectCateById(int id); + + /** + * 删除管理员 + * @param id + */ + void delectAdminById(int id); + + /** + * 新增管理员 + * @param admin + */ + void addAdmin(Admin admin); + + /** + * 通过管理员帐户查询 + * @param name + * @return + */ + Admin findAdminByName(String name); + + /** + * 通过id查询管理员信息 + * @param aid + * @return + */ + Admin findAdminById(Integer aid); + + /** + * 修改管理员 + * @param admin + */ + void updateAdmin(Admin admin); + + /** + * 根据分类名称查询分类信息 + * @param classifyName + * @return + */ + Classify findCateByName(String classifyName); + + /** + * 新增分类 + * @param cassify + */ + void addCate(Classify cassify); + + /** + * 修改分类 + * @param cassify + */ + void updateCate(Classify cassify); + + /** + *

Description: 后台删除商品发送通知给用户

+ * @param uaa + */ + void saveSystemMessage(UserAndAdmin uaa); + +} diff --git a/secondHandcode/dao/ILoginDao.java b/secondHandcode/dao/ILoginDao.java new file mode 100644 index 0000000..f9ea8ce --- /dev/null +++ b/secondHandcode/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/secondHandcode/dao/IUserDao.java b/secondHandcode/dao/IUserDao.java new file mode 100644 index 0000000..b345000 --- /dev/null +++ b/secondHandcode/dao/IUserDao.java @@ -0,0 +1,111 @@ +package dao; + +import java.util.List; +import java.util.Map; + +import model.Classify; +import model.Product; +import model.User; +import model.UserAndAdmin; + +public interface IUserDao { + + /** + * 发布供求信息 + * @param product + */ + void saveProduct(Product product); + + /** + * 查询分类列表 + * @return + */ + List searchClassifyList(); + + /** + * 查询商品 + * @param map + * @return + */ + List searchProductList(Map map); + + /** + * 查询商品数量 + * @param map + * @return + */ + int searchProductCount(Map map); + + /** + * 查询商品详情 + * @param id + * @return + */ + Product getProductDetail(String id); + + + /** + * 通过分类id获取分类信息 + * @param classifyId + */ + Classify getClassifyById(Integer classifyId); + + User getUserById(Integer creatorId); + + void updateProduct(Product product); + + + /** + *

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

+ * @param parseInt + * @return + */ + int searchMyProductCount(int parseInt); + + /** + *

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

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

Description: 删除我发布的商品

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

Description: 保存用户消息

+ * @param map + * @return + */ + void saveUserMessage(UserAndAdmin 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/secondHandcode/dao/impl/AdminInfoDao.java b/secondHandcode/dao/impl/AdminInfoDao.java new file mode 100644 index 0000000..e7de93e --- /dev/null +++ b/secondHandcode/dao/impl/AdminInfoDao.java @@ -0,0 +1,269 @@ +package dao.impl; + +import java.util.List; + +import model.Admin; +import model.Classify; +import model.Product; +import model.User; +import model.UserAndAdmin; + +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.IAdminInfoDao; + +public class AdminInfoDao extends HibernateDaoSupport implements IAdminInfoDao { + + @Override + public List findAllAdminInfo(int begin, int pageSize) { + DetachedCriteria dc=DetachedCriteria.forClass(Admin.class); + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().findByCriteria(dc, begin, pageSize); + return list; + } + + @Override + public int findAdminCount() { + String hql="select count(*) from Admin"; + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().find(hql); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; + + } + + @Override + public int findUserCount(String name) { + StringBuffer br=new StringBuffer(); + + String hql="select count(*) from User " ; + if(name!=null){ + String uname="%"+name+"%"; + br.append("where userName like '"+uname+"'"); + } + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().find(hql+br.toString()); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; + } + + @Override + public List findAllUserInfo(int begin, int pageSize,String name) { + String uname="%"+name+"%"; + DetachedCriteria dc=DetachedCriteria.forClass(User.class) + .add(Restrictions.like("userName", uname, MatchMode.ANYWHERE)) + .addOrder(Order.desc("uid")); + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().findByCriteria(dc, begin, pageSize); + return list; + } + + @Override + public int findCateCount(String name) { + StringBuffer br=new StringBuffer(); + String hql="select count(*) from Classify"; + if(name!=null){ + String uname="%"+name+"%"; + br.append(" where classifyName like '"+uname+"'"); + } + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().find(hql+br.toString()); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; + } + + @Override + public List findAllCateInfo(int begin, int pageSize, String name) { + String uname="%"+name+"%"; + DetachedCriteria dc=DetachedCriteria.forClass(Classify.class) + .add(Restrictions.like("classifyName", uname, MatchMode.ANYWHERE)) + .addOrder(Order.asc("ClassifySort"));; + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().findByCriteria(dc,begin,pageSize); + return list; + } + + @Override + public int findProductCount(String name,int cate,int type) { + StringBuffer br=new StringBuffer(); + String hql="select count(*) from Product p where 1=1"; + if(name!=""){ + String uname="%"+name+"%"; + br.append(" and p.proName like '"+uname+"'"); + } + if(cate!=0){ + br.append(" and p.classify.cid ='"+cate+"'"); + } + if(type!=2){ + br.append(" and p.type ='"+type+"'"); + } + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().find(hql+br.toString()); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; + } + + @Override + public List findAllProductInfo(int begin, int pageSize, String name,int cate,int type) { + String uname="%"+name+"%"; + + DetachedCriteria dc=DetachedCriteria.forClass(Product.class,"p") + .add(Restrictions.like("p.proName", uname, MatchMode.ANYWHERE)); + if(cate!=0){ + dc.add(Restrictions.eq("p.classify.cid", cate)); + } + if(type!=2){ + dc.add(Restrictions.eq("p.type", type)); + } + dc.addOrder(Order.desc("p.createTime")); + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().findByCriteria(dc,begin,pageSize); + return list; + } + + @Override + public List findAllCateList() { + String hql="from Classify"; + @SuppressWarnings("unchecked") + List cateList=this.getHibernateTemplate().find(hql); + return cateList; + } + + @Override + public Product searchProductDetail(int pid) { + String hql=" from Product p where p.id=? "; + + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().find(hql,pid); + if(list.size()>0){ + Product p=list.get(0); + return p; + } + return null; + } + + @Override + public void delectProductById(int pid) { + Product product=this.getHibernateTemplate().get(Product.class, pid); + if(product!=null){ + this.getHibernateTemplate().delete(product); + } + + + } + + @Override + public User searchUserDetail(int uid) { + User user=this.getHibernateTemplate().get(User.class, uid); + return user; + } + + @Override + public void delectCateById(int id) { + Classify c=this.getHibernateTemplate().get(Classify.class, id); + if(c!=null){ + this.getHibernateTemplate().delete(c); + } + + } + + @Override + public void delectAdminById(int id) { + Admin a=this.getHibernateTemplate().get(Admin.class, id); + if(a!=null){ + this.getHibernateTemplate().delete(a); + } + + } + + @Override + public void addAdmin(Admin admin) { + this.getHibernateTemplate().save(admin); + + } + + @Override + public Admin findAdminByName(String name) { + String hql="from Admin where name=?"; + @SuppressWarnings("unchecked") + List a=this.getHibernateTemplate().find(hql,name); + if(a.size()>0){ + return a.get(0); + } + return null; + } + + @Override + public Admin findAdminById(Integer aid) { + return this.getHibernateTemplate().get(Admin.class, aid); + } + + /** + * 修改管理员 + * @param admin + */ + @Override + public void updateAdmin(Admin admin) { + this.getHibernateTemplate().update(admin); + + } + + /** + * 根据分类名称查询分类信息 + * @param classifyName + * @return + */ + @Override + public Classify findCateByName(String classifyName) { + String hql="from Classify where classifyName=?"; + @SuppressWarnings("unchecked") + List list=this.getHibernateTemplate().find(hql,classifyName); + if(list.size()>0){ + return list.get(0); + } + return null; + } + + /** + * 新增分类 + * @param cassify + */ + @Override + public void addCate(Classify cassify) { + this.getHibernateTemplate().save(cassify); + + } + + /** + * 修改分类 + * @param cassify + */ + @Override + public void updateCate(Classify cassify) { + this.getHibernateTemplate().update(cassify); + } + + /** + *

Description: 后台删除商品发送通知给用户

+ * @param uaa + */ + @Override + public void saveSystemMessage(UserAndAdmin uaa) { + this.getHibernateTemplate().save(uaa); + } + + + +} diff --git a/secondHandcode/dao/impl/LoginDao.java b/secondHandcode/dao/impl/LoginDao.java new file mode 100644 index 0000000..d08fbcf --- /dev/null +++ b/secondHandcode/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.getUid()); + 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/secondHandcode/dao/impl/UserDao.java b/secondHandcode/dao/impl/UserDao.java new file mode 100644 index 0000000..1545f26 --- /dev/null +++ b/secondHandcode/dao/impl/UserDao.java @@ -0,0 +1,297 @@ +package dao.impl; + +import java.util.List; +import java.util.Map; + +import model.Classify; +import model.Product; +import model.User; +import model.UserAndAdmin; + +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 saveProduct(Product product) { + this.getHibernateTemplate().saveOrUpdate (product); + + } + + /** + * 查询分类列表 + */ + @SuppressWarnings("unchecked") + @Override + public List searchClassifyList() { + String hql="from Classify"; + return this.getHibernateTemplate().find(hql); + } + + /** + * 查询商品 + */ + @SuppressWarnings("unchecked") + @Override + public List searchProductList(Map map) { + String proName=map.get("keyword");//输入框输入 + String cid=map.get("cid");//分类 + String condition=map.get("conditon");//按人气或价格升、降或供、求查询 + //DetachedCriteria 是离线的,创建时无需 Session,DetachedCriteria 提供了 2 个静态方法 forClass(Class) 或 forEntityName(Name) 进行DetachedCriteria 实例的创建。 + //Spring 的框架提供了getHibernateTemplate ().findByCriteria(detachedCriteria) 方法可以很方便地根据DetachedCriteria 来返回查询结 果。 + DetachedCriteria dc=DetachedCriteria.forClass(Product.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))); + } + 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("sep")); + break; + case 3: + dc.addOrder(Order.desc("sep")); + break; + } + } + + List list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize"))); + return list; + } + + + /** + * 查询商品数量 + */ + @SuppressWarnings("unchecked") + @Override + public int searchProductCount(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 1=1"; + 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){ + order.append(" order by createTime DESC"); + int con=Integer.parseInt(condition); + 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 Product getProductDetail(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){ + Product 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 + */ +@Override +public int searchMyProductCount(int uid) { + String hql="select count(*) from Product where user.uid = ?"; + List list=this.getHibernateTemplate().find(hql,uid); + if(list.size()>0){ + return list.get(0).intValue(); + } + return 0; +} + +/** + *

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

+ * @param map + * @return + */ +@Override +public List getMyProductList(Map map) { + DetachedCriteria dc=DetachedCriteria.forClass(model.Product.class); + dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId")))); + 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 delectProductById(int pid) { + Product product=this.getHibernateTemplate().get(Product.class, pid); + if(product!=null){ + this.getHibernateTemplate().delete(product); + } + +} + + + + + +/** + *

Description: 保存用户消息

+ * @param map + * @return + */ +@Override +public void saveUserMessage(UserAndAdmin uaa) { + this.getHibernateTemplate().save(uaa); +} + +@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; +} + +@Override +public List getMessageList(Map map) { + DetachedCriteria dc=DetachedCriteria.forClass(model.UserAndAdmin.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/secondHandcode/model/Admin.java b/secondHandcode/model/Admin.java new file mode 100644 index 0000000..66bcfa4 --- /dev/null +++ b/secondHandcode/model/Admin.java @@ -0,0 +1,38 @@ +package model; + +public class Admin { + + private Integer aid; + private java.lang.String name; + private java.lang.String password; + private java.lang.Integer role;//角色,0超级管理员 1系统管理员 + + public Admin() { + } + public Integer getAid() { + return aid; + } + public void setAid(Integer aid) { + this.aid = aid; + } + public java.lang.String getName() { + return name; + } + public void setName(java.lang.String name) { + this.name = name; + } + public java.lang.String getPassword() { + return password; + } + public void setPassword(java.lang.String password) { + this.password = password; + } + public java.lang.Integer getRole() { + return role; + } + public void setRole(java.lang.Integer role) { + this.role = role; + } + + +} diff --git a/secondHandcode/model/Classify.java b/secondHandcode/model/Classify.java new file mode 100644 index 0000000..7a546e7 --- /dev/null +++ b/secondHandcode/model/Classify.java @@ -0,0 +1,34 @@ +package model; + +public class Classify { + + private Integer cid; + private java.lang.String classifyName;//分类名称 + private Integer ClassifySort;//分类排序 + + public Classify() { + } + public Integer getCid() { + return cid; + } + public void setCid(Integer cid) { + this.cid = cid; + } + public java.lang.String getClassifyName() { + return classifyName; + } + public void setClassifyName(java.lang.String classifyName) { + this.classifyName = classifyName; + } + public Integer getClassifySort() { + return ClassifySort; + } + public void setClassifySort(Integer classifySort) { + ClassifySort = classifySort; + } + + + + + +} diff --git a/secondHandcode/model/PageBean.java b/secondHandcode/model/PageBean.java new file mode 100644 index 0000000..05b88ef --- /dev/null +++ b/secondHandcode/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/secondHandcode/model/Product.java b/secondHandcode/model/Product.java new file mode 100644 index 0000000..beeb746 --- /dev/null +++ b/secondHandcode/model/Product.java @@ -0,0 +1,106 @@ +package model; + +import java.util.Date; +import java.util.HashSet; +import java.util.Set; + +import com.alibaba.fastjson.annotation.JSONField; + +public class Product { + + private Integer id; + private java.lang.String title;//商品名称 + private java.lang.String picture;//商品图片 + @JSONField(format = "yyyy-MM-dd") + private Date createTime;//发布时间 + private Double sep;//现在商品单价 + private Double orp;//原来商品单价 + private java.lang.String miao;//商品描述 + private Integer creatorId;//发布者id + private Integer classifyId;//分类id + private Integer type;//0供信息,1求信息 + private Classify classify;//关联实体类 + private User user;//关联实体类 + + + public Product() { + } + + 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 Integer getId() { + return id; + } + public void setId(Integer id) { + this.id = id; + } + public java.lang.String getTitle() { + return title; + } + public void setTitle(java.lang.String title) { + this.title = title; + } + public java.lang.String getPicture() { + return picture; + } + public void setPicture(java.lang.String picture) { + this.picture = picture; + } + public Date getCreateTime() { + return createTime; + } + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + public Double getSep() { + return sep; + } + public void setProPrice(Double sep) { + this.sep = sep; + } + public Double getOrg() { + return orp; + } + public void setOrg(Double orp) { + this.orp = orp; + } + + public Integer getType() { + return type; + } + public void setType(Integer type) { + this.type = type; + } + + + + +} diff --git a/secondHandcode/model/User.java b/secondHandcode/model/User.java new file mode 100644 index 0000000..8656715 --- /dev/null +++ b/secondHandcode/model/User.java @@ -0,0 +1,72 @@ +package model; + + +public class User { + + private java.lang.Integer uid; + private java.lang.String userName; + //private java.lang.String headPic; + private java.lang.Integer sex;//性别(男:0 女:1) + private java.lang.String phone; + private java.lang.String qq; + private java.lang.String password; + private java.lang.String qusetion;//密码找回的设置问题 + private java.lang.String answer;//密码找回设置答案 + + + public User() { + } + public java.lang.Integer getUid() { + return uid; + } + public void setUid(java.lang.Integer uid) { + this.uid = uid; + } + public java.lang.String getUserName() { + return userName; + } + public void setUserName(java.lang.String userName) { + this.userName = userName; + } + /*public java.lang.String getHeadPic() { + return headPic; + } + public void setHeadPic(java.lang.String headPic) { + this.headPic = headPic; + }*/ + + public java.lang.Integer getSex() { + return sex; + } + public void setSex(java.lang.Integer sex) { + this.sex = sex; + } + + public java.lang.String getPhone() { + return phone; + } + public void setPhone(java.lang.String phone) { + this.phone = phone; + } + public java.lang.String getPassword() { + return password; + } + public void setPassword(java.lang.String password) { + this.password = password; + } + public java.lang.String getQusetion() { + return qusetion; + } + public void setQusetion(java.lang.String qusetion) { + this.qusetion = qusetion; + } + public java.lang.String getAnswer() { + return answer; + } + public void setAnswer(java.lang.String answer) { + this.answer = answer; + } + + + +} diff --git a/secondHandcode/model/UserAndAdmin.java b/secondHandcode/model/UserAndAdmin.java new file mode 100644 index 0000000..e30ef36 --- /dev/null +++ b/secondHandcode/model/UserAndAdmin.java @@ -0,0 +1,54 @@ +package model; + +import java.util.Date; + +public class UserAndAdmin { + + private Integer id; + private Integer userId;//接收消息者 + private Integer adminId;//发消息者 + private java.lang.String message; + private Date createTime; + private Integer status;//0系统消息,1用户消息 + + public UserAndAdmin() { + } + public Integer getId() { + return id; + } + public void setId(Integer id) { + this.id = id; + } + public Integer getUserId() { + return userId; + } + public void setUserId(Integer userId) { + this.userId = userId; + } + public Integer getAdminId() { + return adminId; + } + public void setAdminId(Integer adminId) { + this.adminId = adminId; + } + public java.lang.String getMessage() { + return message; + } + public void setMessage(java.lang.String message) { + this.message = message; + } + public Date getCreateTime() { + return createTime; + } + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + public Integer getStatus() { + return status; + } + public void setStatus(Integer status) { + this.status = status; + } + + +} diff --git a/secondHandcode/service/IAdminInfoService.java b/secondHandcode/service/IAdminInfoService.java new file mode 100644 index 0000000..c3c249c --- /dev/null +++ b/secondHandcode/service/IAdminInfoService.java @@ -0,0 +1,135 @@ +package service; +import java.util.List; + +import model.Admin; +import model.Classify; +import model.PageBean; +import model.Product; +import model.User; +import model.UserAndAdmin; + +public interface IAdminInfoService { + + /** + * 查询管理员列表 + * @param currPage + * @return + */ + PageBean findAllAdminInfo(int currPage); + + /** + * 查询用户列表 + * @param currPage + * @param name + * @return + */ + PageBean findAllUserInfo(int currPage,String name); + + /** + * 查询分类列表 + * @param currPage + * @param name + * @return + */ + PageBean findAllCateInfo(int currPage, String name); + + /** + * 查询商品列表 + * @param currPage + * @param name + * @param cate + * @param type + * @return + */ + PageBean findAllProductInfo(int currPage, String name, int cate, int type); + + /** + * 分类列表查询 + * @return + */ + List findAllCateList(); + + /** + * 查询商品详情 + * @param pid + * @return + */ + Product searchProductDetail(int pid); + + /** + * 删除商品 + * @param pid + */ + void delectProductById(int pid); + + /** + * 查询用户详情 + * @param uid + * @return + */ + User searchUserDetail(int uid); + + /** + * 删除分类 + * @param id + */ + void delectCateById(int id); + + /** + * 删除管理员 + * @param id + */ + void delectAdminById(int id); + + /** + * 新增管理员 + * @param admin + */ + void addAdmin(Admin admin); + + /** + * 通过账号查询管理员信息 + * @param name + * @return + */ + Admin findAdminByName(String name); + + /** + * 通过id查询管理员信息 + * @param aid + * @return + */ + Admin findAdminById(Integer aid); + + /** + * 修改管理员 + * @param admin + */ + void updateAdmin(Admin admin); + + /** + * 根据分类名称查询分类信息 + * @param classifyName + * @return + */ + Classify findCateByName(String classifyName); + + /** + * 新增分类 + * @param cassify + */ + void addCate(Classify cassify); + + /** + * 修改分类 + * @param cassify + */ + void updateCate(Classify cassify); + + /** + *

Description: 后台删除商品发送通知给用户

+ * @param uaa + */ + void saveSystemMessage(UserAndAdmin uaa); + +} diff --git a/secondHandcode/service/ILoginService.java b/secondHandcode/service/ILoginService.java new file mode 100644 index 0000000..406d075 --- /dev/null +++ b/secondHandcode/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/secondHandcode/service/IUserService.java b/secondHandcode/service/IUserService.java new file mode 100644 index 0000000..fa58922 --- /dev/null +++ b/secondHandcode/service/IUserService.java @@ -0,0 +1,94 @@ +package service; + +import java.util.List; +import java.util.Map; + +import model.Classify; +import model.PageBean; +import model.Product; +import model.User; +import model.UserAndAdmin; + +public interface IUserService { + + /** + * 发布供求信息 + * @param product + */ + void saveProduct(Product product); + + /** + * 查询分类列表 + * @return + */ + List searchClassifyList(); + + /** + * 查询商品 + * @param map + * @return + */ + PageBean searchProductList(Map map); + + /** + * 查询商品详情 + * @param id + * @return + */ + Product getProductDetail(String id); + + + /** + * 通过分类id获取分类信息 + * @param classifyId + */ + Classify getClassifyById(Integer classifyId); + + User getUserById(Integer creatorId); + + void updateProduct(Product product); + + + + /** + *

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

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

Description: 删除我发布的商品

+ * @param pid + */ + void delectProductById(int pid); + + + /** + * 保存用户消息 + * @param uaa + */ + void saveUserMessage(UserAndAdmin uaa); + + /** + * 分页消息 + * @throws Exception + * @param flag 0系统消息,1用户消息 + */ + PageBean searchMessageByPage(Map map); + + /** + * 通过id删除消息 + * @param parseInt + */ + void deleteMessage(int id); + + + + + + + +} diff --git a/secondHandcode/service/impl/AdminInfoService.java b/secondHandcode/service/impl/AdminInfoService.java new file mode 100644 index 0000000..7f80e10 --- /dev/null +++ b/secondHandcode/service/impl/AdminInfoService.java @@ -0,0 +1,279 @@ +package service.impl; + +import java.util.List; + +import model.Admin; +import model.Classify; +import model.PageBean; +import model.Product; +import model.User; +import model.UserAndAdmin; + +import org.springframework.transaction.annotation.Transactional; + +import service.IAdminInfoService; +import dao.IAdminInfoDao; +@Transactional +public class AdminInfoService implements IAdminInfoService { + + IAdminInfoDao iAdminInfoDao; + public void setiAdminInfoDao(IAdminInfoDao iAdminInfoDao) { + this.iAdminInfoDao = iAdminInfoDao; + } + /** + * 分页查询管理员列表 + * @param currPage + * @return + */ + @Override + public PageBean findAllAdminInfo(int currPage) { + PageBean pageBean=new PageBean(); + //封装当前页 + pageBean.setCurrPage(currPage); + //封装每页记录数 + int pageSize=3; + pageBean.setPageSize(pageSize); + //封装总记录数 + int totalCount=this.iAdminInfoDao.findAdminCount(); + 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; + List list=this.iAdminInfoDao.findAllAdminInfo(begin,pageSize); + pageBean.setList(list); + return pageBean; + } + /** + * 分页查询用户列表 + * @param currPage + * @param name + * @return + */ + @Override + public PageBean findAllUserInfo(int currPage,String name) { + PageBean pageBean=new PageBean(); + //封装当前页 + pageBean.setCurrPage(currPage); + //封装每页记录数 + int pageSize=10; + pageBean.setPageSize(pageSize); + //封装总记录数 + int totalCount=this.iAdminInfoDao.findUserCount(name); + 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; + List list=this.iAdminInfoDao.findAllUserInfo(begin,pageSize,name); + pageBean.setList(list); + return pageBean; + } + /** + * 分页查询分类列表 + * @param currPage + * @param name + * @return + */ + @Override + public PageBean findAllCateInfo(int currPage, String name) { + PageBean pageBean=new PageBean(); + //封装当前页 + pageBean.setCurrPage(currPage); + //封装每页记录数 + int pageSize=5; + pageBean.setPageSize(pageSize); + //封装总记录数 + int totalCount=this.iAdminInfoDao.findCateCount(name); + 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; + List list=this.iAdminInfoDao.findAllCateInfo(begin,pageSize,name); + pageBean.setList(list); + return pageBean; + } + /** + * 分页 查询商品列表 + * @param currPage + * @param name + * @param cate + * @param type + * @return + */ + @Override + public PageBean findAllProductInfo(int currPage, String name,int cate,int type) { + PageBean pageBean=new PageBean(); + //封装当前页 + pageBean.setCurrPage(currPage); + //封装每页记录数 + int pageSize=10; + pageBean.setPageSize(pageSize); + //封装总记录数 + int totalCount=this.iAdminInfoDao.findProductCount(name,cate,type); + 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; + List list=this.iAdminInfoDao.findAllProductInfo(begin,pageSize,name,cate,type); + pageBean.setList(list); + return pageBean; + } + + /** + * 分类列表查询,用于下列展示 + * @return + */ + @Override + public List findAllCateList() { + List cateList=this.iAdminInfoDao.findAllCateList(); + return cateList; + } + /** + * 通过id查询商品详情 + * @param pid + * @return + */ + @Override + public Product searchProductDetail(int pid) { + Product product=this.iAdminInfoDao.searchProductDetail(pid); + return product; + } + /** + * 通过id删除商品 + * @param pid + */ + @Override + public void delectProductById(int pid) { + this.iAdminInfoDao.delectProductById(pid); + + } + /** + * 通过id查询用户详情 + * @param uid + * @return + */ + @Override + public User searchUserDetail(int uid) { + User u=this.iAdminInfoDao.searchUserDetail(uid); + return u; + } + /** + * 通过id删除分类 + * @param id + */ + @Override + public void delectCateById(int id) { + this.iAdminInfoDao.delectCateById(id); + + } + /** + * 通过id删除管理员 + * @param id + */ + @Override + public void delectAdminById(int id) { + this.iAdminInfoDao.delectAdminById(id); + + } + /** + * 新增管理员 + * @param admin + */ + @Override + public void addAdmin(Admin admin) { + this.iAdminInfoDao.addAdmin(admin); + + } + /** + * 通过管理员账号查询管理员信息 + * @param name + * @return + */ + @Override + public Admin findAdminByName(String name) { + + return this.iAdminInfoDao.findAdminByName(name); + } + /** + * 通过id查询管理员信息 + * @param aid + * @return + */ + @Override + public Admin findAdminById(Integer aid) { + + return this.iAdminInfoDao.findAdminById(aid); + } + /** + * 修改管理员 + * @param admin + */ + @Override + public void updateAdmin(Admin admin) { + this.iAdminInfoDao.updateAdmin(admin); + + } + /** + * 根据分类名称查询分类信息 + * @param classifyName + * @return + */ + @Override + public Classify findCateByName(String classifyName) { + Classify c=this.iAdminInfoDao.findCateByName(classifyName); + return c; + } + /** + * 新增分类 + * @param cassify + */ + @Override + public void addCate(Classify cassify) { + this.iAdminInfoDao.addCate(cassify); + + } + /** + * 修改分类 + * @param cassify + */ + @Override + public void updateCate(Classify cassify) { + this.iAdminInfoDao.updateCate(cassify); + + } + /** + *

Description: 后台删除商品发送通知给用户

+ * @param uaa + */ + @Override + public void saveSystemMessage(UserAndAdmin uaa) { + this.iAdminInfoDao.saveSystemMessage(uaa); + + } + + + +} diff --git a/secondHandcode/service/impl/LoginService.java b/secondHandcode/service/impl/LoginService.java new file mode 100644 index 0000000..5f96342 --- /dev/null +++ b/secondHandcode/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/secondHandcode/service/impl/UserService.java b/secondHandcode/service/impl/UserService.java new file mode 100644 index 0000000..56d77f3 --- /dev/null +++ b/secondHandcode/service/impl/UserService.java @@ -0,0 +1,210 @@ +package service.impl; + +import java.util.List; +import java.util.Map; + +import model.Classify; +import model.PageBean; +import model.Product; +import model.User; +import model.UserAndAdmin; + +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 saveProduct(Product product) { + this.iUserDao.saveProduct(product); + + } + + /** + * 查询分类列表 + */ + @Override + public List searchClassifyList() { + + return this.iUserDao.searchClassifyList(); + } + + /** + * 查询商品 + */ + @Override + public PageBean searchProductList(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.searchProductCount(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.searchProductList(map); + pageBean.setList(list); + return pageBean; + + } + + /** + * 查询商品详情 + */ + @Override + public Product getProductDetail(String id) { + + return this.iUserDao.getProductDetail(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 searchMyProductByPage(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.searchMyProductCount(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.getMyProductList(map); + pageBean.setList(list); + return pageBean; + } + + + + /** + *

Description: 删除我发布的商品

+ * @param pid + */ + @Override + public void delectProductById(int pid) { + this.iUserDao.delectProductById(pid); + + } + + + + /** + * 保存用户消息 + * @param uaa + */ + @Override + public void saveUserMessage(UserAndAdmin 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); + + } + + + + + + +} diff --git a/secondHandcode/util/AddJson.java b/secondHandcode/util/AddJson.java new file mode 100644 index 0000000..dc248f6 --- /dev/null +++ b/secondHandcode/util/AddJson.java @@ -0,0 +1,99 @@ +package util; + +import java.io.IOException; +import java.io.Writer; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.ServletActionContext; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.alibaba.fastjson.serializer.ValueFilter; +import com.opensymphony.xwork2.ActionSupport; + +/** + * 将数据转成json数据格式 + * + */ +public class AddJson extends ActionSupport{ + + private static final long serialVersionUID = 1L; + + private static ValueFilter filter = new ValueFilter() { + @Override + public Object process(Object obj, String s, Object v) { + if (v == null) + return ""; + return v; + } + }; + /** + * 将JavaBean序列化为JSON文本 + * @param str + * @throws IOException + */ + public void toJson(Object str) throws IOException{ + HttpServletResponse response=ServletActionContext.getResponse(); + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Pragma", "no-cache"); + response.setDateHeader("Expires", 0); + response.setContentType("text/html;charset=utf-8"); + + String responseStr = JSON.toJSONString(str,filter,SerializerFeature.WriteNullStringAsEmpty); + Writer writer = response.getWriter(); + writer.write(responseStr); + writer.flush(); + } + /** + * 将JavaBean转换为JSONObject + * @param str + * @throws IOException + */ + public void toJsonObj(Object str) throws IOException{ + HttpServletResponse response=ServletActionContext.getResponse(); + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Pragma", "no-cache"); + response.setDateHeader("Expires", 0); + response.setContentType("text/html;charset=utf-8"); + + Object responseStr = JSON.toJSON(str); + Writer writer = response.getWriter(); + writer.write(responseStr.toString()); + writer.flush(); + } + /** + * 将JavaBean转换为JSONArray + * @param list + * @throws IOException + */ + public void toJsonArray(List list) throws IOException{ + HttpServletResponse response=ServletActionContext.getResponse(); + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Pragma", "no-cache"); + response.setDateHeader("Expires", 0); + response.setContentType("text/html;charset=utf-8"); + + Object obj = JSON.toJSON(list); + Writer writer = response.getWriter(); + writer.write("{\"length\":"+list.size()+" ,"); + writer.write("\"data\":"+obj.toString()+"}"); + writer.flush(); + } + + public void toJsonList(int len,List list) throws IOException{ + HttpServletResponse response=ServletActionContext.getResponse(); + response.setHeader("Cache-Control", "no-cache"); + response.setHeader("Pragma", "no-cache"); + response.setDateHeader("Expires", 0); + response.setContentType("text/html;charset=utf-8"); + + String responseStr = JSON.toJSONString(list,filter); + Writer writer = response.getWriter(); + //writer.write(responseStr); + writer.write("{\"length\":"+len+" ,"); + writer.write("\"data\":"+responseStr+"}"); + writer.flush(); + } +}