checkDetails

master
dida 5 years ago
commit 3640480dfd

@ -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 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<Admin> 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<User> 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<Classify> 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<Product> pageBean=this.iAdminInfoService.findAllProductInfo(currPage,name,cate1,type1);
if(pageBean!=null){
ActionContext.getContext().getValueStack().push(pageBean);
}
List<Classify> 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";
}
}

@ -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<Product>{
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<Classify> 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<Object,String> map=new HashMap<Object,String>();
if(keyword!=null&&keyword!=""){
map.put("keyword", keyword);
}
if(cid!=null&&cid!=""){
map.put("cid", cid);
}
if(conditon!=null&&conditon!=""){
map.put("conditon", conditon);
}
map.put("currPage", currPage+"");
PageBean<Product> 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<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getUid()+"");
PageBean<Product> 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;
}
/**
*
* <p>Description: </p>
* @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<Object, String> map=new HashMap<Object, String>();
map.put("currPage", currPage+"");
map.put("userId", user.getUid()+"");
map.put("flag", flag);
PageBean<UserAndAdmin> message=this.iUserService.searchMessageByPage(map);
if(message!=null){
ActionContext.getContext().getValueStack().push(message);
}
}
if(flag=="0"||"0".equals(flag)){
return "sysmessage";
}else{
return "usermessage";
}
}
private String flag;
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
/**
*
* @return
* @throws Exception
*/
public String deleteMessage() throws Exception{
User user=(User) req.getSession().getAttribute("User");
//String flag=req.getParameter("flag");
if(user==null){
throw new Exception("用户帐户为空,请重新登录!");
}else{
String id=req.getParameter("id");
this.iUserService.deleteMessage(Integer.parseInt(id));
}
if(flag=="0"||"0".equals(flag)){
return "sysmsgDelete";
}else{
return "usermsgDelete";
}
}
}

@ -0,0 +1,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 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";
}
}

@ -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<Admin> findAllAdminInfo(int begin, int pageSize);
/**
*
* @param name
* @return
*/
int findUserCount(String name);
/**
*
* @param begin
* @param pageSize
* @param name
* @return
*/
List<User> findAllUserInfo(int begin, int pageSize,String name);
/**
*
* @param name
* @return
*/
int findCateCount(String name);
/**
*
* @param begin
* @param pageSize
* @param name
* @return
*/
List<Classify> 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<Product> findAllProductInfo(int begin, int pageSize, String name, int cate, int type);
/**
*
* @return
*/
List<Classify> 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);
/**
* <p>Description: </p>
* @param uaa
*/
void saveSystemMessage(UserAndAdmin uaa);
}

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

@ -0,0 +1,111 @@
package dao;
import java.util.List;
import java.util.Map;
import model.Classify;
import model.Product;
import model.User;
import model.UserAndAdmin;
public interface IUserDao {
/**
*
* @param product
*/
void saveProduct(Product product);
/**
*
* @return
*/
List<Classify> searchClassifyList();
/**
*
* @param map
* @return
*/
List<Product> searchProductList(Map<Object, String> map);
/**
*
* @param map
* @return
*/
int searchProductCount(Map<Object, String> map);
/**
*
* @param id
* @return
*/
Product getProductDetail(String id);
/**
* id
* @param classifyId
*/
Classify getClassifyById(Integer classifyId);
User getUserById(Integer creatorId);
void updateProduct(Product product);
/**
* <p>Description: </p>
* @param parseInt
* @return
*/
int searchMyProductCount(int parseInt);
/**
* <p>Description: </p>
* @param map
* @return
*/
List<Product> getMyProductList(Map<Object, String> map);
/**
* <p>Description: </p>
* @param pid
*/
void delectProductById(int pid);
/**
* <p>Description: </p>
* @param map
* @return
*/
void saveUserMessage(UserAndAdmin uaa);
/**
* <p>Description: </p>
* @param map
* @return
*/
int searchMessageCount(int uid, String flag);
/**
* <p>Description: </p>
* @param map
* @return
*/
List<UserAndAdmin> getMessageList(Map<Object, String> map);
/**
* id
*/
void deleteMessage(int id);
}

@ -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<Admin> findAllAdminInfo(int begin, int pageSize) {
DetachedCriteria dc=DetachedCriteria.forClass(Admin.class);
@SuppressWarnings("unchecked")
List<Admin> list=this.getHibernateTemplate().findByCriteria(dc, begin, pageSize);
return list;
}
@Override
public int findAdminCount() {
String hql="select count(*) from Admin";
@SuppressWarnings("unchecked")
List<Long> 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<Long> list=this.getHibernateTemplate().find(hql+br.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@Override
public List<User> 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<User> 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<Long> list=this.getHibernateTemplate().find(hql+br.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@Override
public List<Classify> 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<Classify> 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<Long> list=this.getHibernateTemplate().find(hql+br.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@Override
public List<Product> 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<Product> list=this.getHibernateTemplate().findByCriteria(dc,begin,pageSize);
return list;
}
@Override
public List<Classify> findAllCateList() {
String hql="from Classify";
@SuppressWarnings("unchecked")
List<Classify> cateList=this.getHibernateTemplate().find(hql);
return cateList;
}
@Override
public Product searchProductDetail(int pid) {
String hql=" from Product p where p.id=? ";
@SuppressWarnings("unchecked")
List<Product> 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<Admin> 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<Classify> 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);
}
/**
* <p>Description: </p>
* @param uaa
*/
@Override
public void saveSystemMessage(UserAndAdmin uaa) {
this.getHibernateTemplate().save(uaa);
}
}

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

@ -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<Classify> searchClassifyList() {
String hql="from Classify";
return this.getHibernateTemplate().find(hql);
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public List<Product> searchProductList(Map<Object, String> map) {
String proName=map.get("keyword");//输入框输入
String cid=map.get("cid");//分类
String condition=map.get("conditon");//按人气或价格升、降或供、求查询
//DetachedCriteria 是离线的,创建时无需 SessionDetachedCriteria 提供了 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<Product> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public int searchProductCount(Map<Object, String> map) {
StringBuffer br=new StringBuffer();
StringBuffer order=new StringBuffer();
String proName=map.get("keyword");
String cid=map.get("cid");
String condition=map.get("conditon");
String count_hql="select count(*) from Product where 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<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
/**
*
*/
@SuppressWarnings("unchecked")
@Override
public Product getProductDetail(String id) {
int pid=0;
if(id!=null&&id!=""){
pid=Integer.parseInt(id);
}
String hql=" from Product where id=?";
List<Product> 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<Classify> c=this.getHibernateTemplate().find(hql, classifyId);
if(c.size()>0){
Classify cla=c.get(0);
return cla;
}
return null;
}
@Override
public User getUserById(Integer creatorId) {
String hql="from User where uid=?";
@SuppressWarnings("unchecked")
List<User> u=this.getHibernateTemplate().find(hql, creatorId);
if(u.size()>0){
User user=u.get(0);
return user;
}
return null;
}
@Override
public void updateProduct(Product product) {
this.getHibernateTemplate().update(product);
}
/**
* <p>Description: </p>
* @param parseInt
* @return
*/
@Override
public int searchMyProductCount(int uid) {
String hql="select count(*) from Product where user.uid = ?";
List<Long> list=this.getHibernateTemplate().find(hql,uid);
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
/**
* <p>Description: </p>
* @param map
* @return
*/
@Override
public List<Product> getMyProductList(Map<Object, String> 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<model.Product> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
* <p>Description: </p>
* @param pid
*/
@Override
public void delectProductById(int pid) {
Product product=this.getHibernateTemplate().get(Product.class, pid);
if(product!=null){
this.getHibernateTemplate().delete(product);
}
}
/**
* <p>Description: </p>
* @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<Long> list=this.getHibernateTemplate().find(hql+sb.toString());
if(list.size()>0){
return list.get(0).intValue();
}
return 0;
}
@Override
public List<UserAndAdmin> getMessageList(Map<Object, String> 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<model.UserAndAdmin> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
return list;
}
/**
* id
*/
@Override
public void deleteMessage(int id) {
String hql="delete from UserAndAdmin where id="+id;
SessionFactory factory=this.getHibernateTemplate().getSessionFactory();
Session session=factory.openSession();
Query query=session.createQuery(hql);
query.executeUpdate();
session.close();
}
}

@ -0,0 +1,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;
}
}

@ -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;
}
}

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

@ -0,0 +1,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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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<Admin> findAllAdminInfo(int currPage);
/**
*
* @param currPage
* @param name
* @return
*/
PageBean<User> findAllUserInfo(int currPage,String name);
/**
*
* @param currPage
* @param name
* @return
*/
PageBean<Classify> findAllCateInfo(int currPage, String name);
/**
*
* @param currPage
* @param name
* @param cate
* @param type
* @return
*/
PageBean<Product> findAllProductInfo(int currPage, String name, int cate, int type);
/**
*
* @return
*/
List<Classify> 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);
/**
* <p>Description: </p>
* @param uaa
*/
void saveSystemMessage(UserAndAdmin uaa);
}

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

@ -0,0 +1,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<Classify> searchClassifyList();
/**
*
* @param map
* @return
*/
PageBean<Product> searchProductList(Map<Object, String> map);
/**
*
* @param id
* @return
*/
Product getProductDetail(String id);
/**
* id
* @param classifyId
*/
Classify getClassifyById(Integer classifyId);
User getUserById(Integer creatorId);
void updateProduct(Product product);
/**
* <p>Description: </p>
* @param map
* @return
*/
PageBean<Product> searchMyProductByPage(Map<Object, String> map);
/**
* <p>Description: </p>
* @param pid
*/
void delectProductById(int pid);
/**
*
* @param uaa
*/
void saveUserMessage(UserAndAdmin uaa);
/**
*
* @throws Exception
* @param flag 0,1
*/
PageBean<UserAndAdmin> searchMessageByPage(Map<Object, String> map);
/**
* id
* @param parseInt
*/
void deleteMessage(int id);
}

@ -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<Admin> findAllAdminInfo(int currPage) {
PageBean<Admin> pageBean=new PageBean<Admin>();
//封装当前页
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<Admin> list=this.iAdminInfoDao.findAllAdminInfo(begin,pageSize);
pageBean.setList(list);
return pageBean;
}
/**
*
* @param currPage
* @param name
* @return
*/
@Override
public PageBean<User> findAllUserInfo(int currPage,String name) {
PageBean<User> pageBean=new PageBean<User>();
//封装当前页
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<User> list=this.iAdminInfoDao.findAllUserInfo(begin,pageSize,name);
pageBean.setList(list);
return pageBean;
}
/**
*
* @param currPage
* @param name
* @return
*/
@Override
public PageBean<Classify> findAllCateInfo(int currPage, String name) {
PageBean<Classify> pageBean=new PageBean<Classify>();
//封装当前页
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<Classify> list=this.iAdminInfoDao.findAllCateInfo(begin,pageSize,name);
pageBean.setList(list);
return pageBean;
}
/**
*
* @param currPage
* @param name
* @param cate
* @param type
* @return
*/
@Override
public PageBean<Product> findAllProductInfo(int currPage, String name,int cate,int type) {
PageBean<Product> pageBean=new PageBean<Product>();
//封装当前页
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<Product> list=this.iAdminInfoDao.findAllProductInfo(begin,pageSize,name,cate,type);
pageBean.setList(list);
return pageBean;
}
/**
*
* @return
*/
@Override
public List<Classify> findAllCateList() {
List<Classify> 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);
}
/**
* <p>Description: </p>
* @param uaa
*/
@Override
public void saveSystemMessage(UserAndAdmin uaa) {
this.iAdminInfoDao.saveSystemMessage(uaa);
}
}

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

@ -0,0 +1,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<Classify> searchClassifyList() {
return this.iUserDao.searchClassifyList();
}
/**
*
*/
@Override
public PageBean<Product> searchProductList(Map<Object, String> map) {
PageBean<Product> pageBean=new PageBean<Product>();
//封装当前页
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<Product> 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);
}
/**
* <p>Description: </p>
* @param map
* @return
*/
@Override
public PageBean<Product> searchMyProductByPage(Map<Object, String> map) {
PageBean<Product> pageBean=new PageBean<Product>();
//封装当前页
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<Product> list=this.iUserDao.getMyProductList(map);
pageBean.setList(list);
return pageBean;
}
/**
* <p>Description: </p>
* @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<UserAndAdmin> searchMessageByPage(Map<Object, String> map) {
PageBean<UserAndAdmin> pageBean=new PageBean<UserAndAdmin>();
//封装当前页
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<UserAndAdmin> list=this.iUserDao.getMessageList(map);
pageBean.setList(list);
return pageBean;
}
/**
* id
*/
@Override
public void deleteMessage(int id) {
this.iUserDao.deleteMessage(id);
}
}

@ -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;
}
};
/**
* JavaBeanJSON
* @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();
}
/**
* JavaBeanJSONObject
* @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();
}
/**
* JavaBeanJSONArray
* @param list
* @throws IOException
*/
public <T> void toJsonArray(List<T> 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 <T> void toJsonList(int len,List<T> 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();
}
}
Loading…
Cancel
Save