parent
a2121be839
commit
48918dc0ea
@ -0,0 +1,162 @@
|
||||
package action;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import service.ILoginService;
|
||||
import util.AddJson;
|
||||
import model.User;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.ModelDriven;
|
||||
|
||||
public class UserAction extends ActionSupport implements ModelDriven<User>{
|
||||
|
||||
User user=new User();
|
||||
@Override
|
||||
public User getModel() {
|
||||
return user;
|
||||
}
|
||||
|
||||
ILoginService iLoginService;
|
||||
public void setiLoginService(ILoginService iLoginService) {
|
||||
this.iLoginService = iLoginService;
|
||||
}
|
||||
|
||||
|
||||
HttpServletRequest req=ServletActionContext.getRequest();
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @return
|
||||
*/
|
||||
public String UserLogin(){
|
||||
//HttpServletRequest req=ServletActionContext.getRequest();
|
||||
if(user==null){
|
||||
this.addActionError("请输入账号和密码!");
|
||||
return "login";
|
||||
}
|
||||
|
||||
User u=this.iLoginService.findByUser(user);
|
||||
if(u==null){
|
||||
this.addActionError("用户名或密码错误!");
|
||||
return "login";
|
||||
}else{
|
||||
req.getSession().setAttribute("User", u);
|
||||
return "index";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
public String userRegister(){
|
||||
//通过用户名先查询该用户是否已经注册
|
||||
User u=this.iLoginService.findUserByName(user.getUsername());
|
||||
if(u!=null){
|
||||
this.addActionError("该用户已被注册!");
|
||||
return "registerFail";
|
||||
}
|
||||
//user.setHeadPic("images/logo-s.jpg");
|
||||
this.iLoginService.saveUser(user);
|
||||
return "registerSuccess";
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过账号找回密码步骤1
|
||||
*/
|
||||
public String forgetPwd(){
|
||||
//HttpServletRequest req=ServletActionContext.getRequest();
|
||||
String userName=req.getParameter("userName");
|
||||
User u=this.iLoginService.findUserByName(userName);
|
||||
if(u==null){
|
||||
this.addFieldError(userName, "用户名错误!");
|
||||
return "getPwdFail";
|
||||
}
|
||||
if(u.getQusetion()==null){
|
||||
this.addActionError("抱歉!你没有设置问题和密码!");
|
||||
return "getPwdFail";
|
||||
}
|
||||
req.getSession().setAttribute("User", u);
|
||||
return "getPwdSuccess";
|
||||
|
||||
}
|
||||
/**
|
||||
* 提交问题2
|
||||
*/
|
||||
public String checkAnswer(){
|
||||
//HttpServletRequest req=ServletActionContext.getRequest();
|
||||
String answertext=req.getParameter("answer");
|
||||
User u=this.iLoginService.findUserByName(user.getUsername());
|
||||
if(u!=null){
|
||||
String answer=u.getAnswer();
|
||||
if(!answer.equals(answertext)){
|
||||
this.addActionError("抱歉!回答错误!");
|
||||
return "answerFalse";
|
||||
}
|
||||
}
|
||||
req.getSession().setAttribute("User", u);
|
||||
return "answerTrue";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新设置密码3
|
||||
*/
|
||||
public String updatePwd(){
|
||||
this.iLoginService.updatePed(user);
|
||||
return "updatePwdSuccess";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户账号信息
|
||||
* @throws Exception
|
||||
*/
|
||||
public void searchPersonalInfo() throws Exception{
|
||||
//HttpServletRequest req=ServletActionContext.getRequest();
|
||||
int uid=Integer.parseInt(req.getParameter("uid"));
|
||||
if(uid==0){
|
||||
throw new Exception("用户不存在!");
|
||||
}
|
||||
user=this.iLoginService.searchUserInfoById(uid);
|
||||
AddJson json=new AddJson();
|
||||
json.toJson(user);
|
||||
//return "findUserInfoSuccess";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*/
|
||||
public void updateUserInfoById(){
|
||||
int uid=Integer.parseInt(req.getParameter("id"));
|
||||
String uname=req.getParameter("userName");
|
||||
String pass=req.getParameter("password");
|
||||
String phone=req.getParameter("phone");
|
||||
String qusetion=req.getParameter("qusetion");
|
||||
String answer=req.getParameter("answer");
|
||||
int sex=Integer.parseInt(req.getParameter("sex"));
|
||||
User uu=new User();
|
||||
uu.setAnswer(answer);
|
||||
uu.setPassword(pass);
|
||||
uu.setPhone(phone);
|
||||
uu.setId(uid);
|
||||
uu.setUsername(uname);
|
||||
uu.setQusetion(qusetion);
|
||||
uu.setSex(sex);
|
||||
this.iLoginService.updateUser(uu);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户退出的登录
|
||||
*/
|
||||
public String userExitLogin(){
|
||||
req.getSession().removeAttribute("User");
|
||||
return "UserexitSuccess";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package dao;
|
||||
|
||||
//import model.Admin;
|
||||
import model.User;
|
||||
|
||||
public interface ILoginDao {
|
||||
|
||||
/**
|
||||
* 通过用户名和密码查询用户
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
User findByUser(User user);
|
||||
|
||||
/**
|
||||
* 通过账号和密码查询管理员
|
||||
* @param admin
|
||||
* @return
|
||||
*/
|
||||
//Admin findByAdmin(Admin admin);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
User findUserByName(String userName);
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
* @param user
|
||||
*/
|
||||
void saveUser(User user);
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @param user
|
||||
*/
|
||||
void updatePed(User user);
|
||||
|
||||
/**
|
||||
* 通过用户id查询用户信息
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
User searchUserInfoById(int uid);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
* @param user
|
||||
*/
|
||||
void updateUser(User user);
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
package dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import model.Classify;
|
||||
import model.Goods;
|
||||
import model.User;
|
||||
//import model.UserAdmin;
|
||||
|
||||
public interface IUserDao {
|
||||
|
||||
/**
|
||||
* 发布供求信息
|
||||
* @param product
|
||||
*/
|
||||
void saveGood(Goods good);
|
||||
|
||||
/**
|
||||
* 查询分类列表
|
||||
* @return
|
||||
*/
|
||||
List<Classify> searchClassifyList();
|
||||
|
||||
/**
|
||||
* 查询商品
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
List<Goods> searchLostGoodList(Map<Object, String> map);
|
||||
List<Goods> searchFoundGoodList(Map<Object, String> map);
|
||||
/**
|
||||
* 查询商品数量
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
int searchLostGoodCount(Map<Object, String> map);
|
||||
int searchFoundGoodCount(Map<Object, String> map);
|
||||
/**
|
||||
* 查询商品详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Goods getLostGoodDetail(String id);
|
||||
Goods getFoundGoodDetail(String id);
|
||||
|
||||
/**
|
||||
* 通过分类id获取分类信息
|
||||
* @param classifyId
|
||||
*/
|
||||
Classify getClassifyById(Integer classifyId);
|
||||
|
||||
User getUserById(Integer creatorId);
|
||||
|
||||
/*void updateProduct(Product product);*/
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 查询我发布的商品列表数量</p>
|
||||
* @param parseInt
|
||||
* @return
|
||||
*/
|
||||
int searchMyLostGoodCount(int parseInt);
|
||||
int searchMyFoundGoodCount(int parseInt);
|
||||
/**
|
||||
* <p>Description: 查询我发布的商品列表信息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
List<Goods> getMyLostGoodList(Map<Object, String> map);
|
||||
List<Goods> getMyFoundGoodList(Map<Object, String> map);
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 删除我发布的商品</p>
|
||||
* @param pid
|
||||
*/
|
||||
void delectGoodById(int pid);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 保存用户消息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
// void saveUserMessage(UserAdmin uaa);
|
||||
|
||||
/**
|
||||
* <p>Description: 保存用户消息数量</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
// int searchMessageCount(int uid, String flag);
|
||||
|
||||
/**
|
||||
* <p>Description: 保存用户消息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
// List<UserAdmin> getMessageList(Map<Object, String> map);
|
||||
|
||||
/**
|
||||
* 通过id删除消息
|
||||
*/
|
||||
void deleteMessage(int id);
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package dao.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
//import model.Admin;
|
||||
import model.User;
|
||||
import dao.ILoginDao;
|
||||
|
||||
public class LoginDao extends HibernateDaoSupport implements ILoginDao {
|
||||
|
||||
/**
|
||||
* 通过账号和密码查询用户
|
||||
*/
|
||||
@Override
|
||||
public User findByUser(User user) {
|
||||
String hql="from User u where u.userName=? and u.password=?";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
List<User> list=this.getHibernateTemplate().find(hql,user.getUsername(),user.getPassword());
|
||||
if(list.size()>0){
|
||||
return list.get(0);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过账号和密码查询管理员
|
||||
*/
|
||||
/* @Override
|
||||
public Admin findByAdmin(Admin admin) {
|
||||
String hql="from Admin a where a.name=? and a.password=?";
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Admin> list=this.getHibernateTemplate().find(hql, admin.getName(),admin.getPassword());
|
||||
if(list.size()>0){
|
||||
return list.get(0);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*/
|
||||
@Override
|
||||
public User findUserByName(String userName) {
|
||||
String hql="from User where userName=?";
|
||||
@SuppressWarnings("unchecked")
|
||||
List<User> list=this.getHibernateTemplate().find(hql,userName);
|
||||
if(list.size()>0){
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
*/
|
||||
@Override
|
||||
public void saveUser(User user) {
|
||||
this.getHibernateTemplate().save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
*/
|
||||
@Override
|
||||
public void updatePed(User user) {
|
||||
User u=this.getHibernateTemplate().get(User.class, user.getId());
|
||||
u.setPassword(user.getPassword());
|
||||
this.getHibernateTemplate().update(u);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户id查询用户信息
|
||||
*/
|
||||
@Override
|
||||
public User searchUserInfoById(int uid) {
|
||||
User u=this.getHibernateTemplate().get(User.class, uid);
|
||||
return u;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*/
|
||||
@Override
|
||||
public void updateUser(User user) {
|
||||
this.getHibernateTemplate().update(user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,362 @@
|
||||
package dao.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import model.Classify;
|
||||
import model.Goods;
|
||||
import model.User;
|
||||
//import model.UserAdmin;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.criterion.DetachedCriteria;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
import dao.IUserDao;
|
||||
|
||||
public class UserDao extends HibernateDaoSupport implements IUserDao {
|
||||
|
||||
/**
|
||||
* 发布供求信息
|
||||
*/
|
||||
@Override
|
||||
public void saveGood(Goods good) {
|
||||
this.getHibernateTemplate().saveOrUpdate (good);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类列表
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Classify> searchClassifyList() {
|
||||
String hql="from Classify";
|
||||
return this.getHibernateTemplate().find(hql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Goods> searchLostGoodList(Map<Object, String> map) {
|
||||
String cid=map.get("cid");
|
||||
DetachedCriteria dc=DetachedCriteria.forClass(Goods.class);
|
||||
//dc.addOrder(Order.desc("createTime"));
|
||||
//dc.add(Restrictions.ne("proHassum", 0));
|
||||
/*if(proName!=null){
|
||||
proName="%"+map.get("keyword")+"%";
|
||||
dc.add(Restrictions.like("proName",proName, MatchMode.ANYWHERE));
|
||||
}*/
|
||||
if(cid!=null){
|
||||
dc.add(Restrictions.eq("classify.cid",Integer.parseInt(cid)));
|
||||
}
|
||||
dc.add(Restrictions.eq("goodsStatus",0));
|
||||
/*if(condition!=null){
|
||||
int con=Integer.parseInt(condition);
|
||||
switch(con){
|
||||
case 5:
|
||||
dc.add(Restrictions.eq("type",1));
|
||||
break;
|
||||
case 4:
|
||||
dc.add(Restrictions.eq("type",0));
|
||||
break;
|
||||
case 1:
|
||||
dc.addOrder(Order.desc("proClicknum"));
|
||||
break;
|
||||
case 2:
|
||||
dc.addOrder(Order.asc("proPrice"));
|
||||
break;
|
||||
case 3:
|
||||
dc.addOrder(Order.desc("proPrice"));
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
List<Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品数量
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int searchLostGoodCount(Map<Object, String> map) {
|
||||
StringBuffer br=new StringBuffer();
|
||||
StringBuffer order=new StringBuffer();
|
||||
//String proName=map.get("keyword");
|
||||
String cid=map.get("cid");
|
||||
//String condition=map.get("conditon");
|
||||
String count_hql="select count(*) from Product where goodsstatus='0'";
|
||||
/*if(proName!=null){
|
||||
proName="%"+map.get("keyword")+"%";
|
||||
br.append(" and proName like '"+proName+"'");
|
||||
}*/
|
||||
if(cid!=null){
|
||||
br.append(" and classify.cid='"+Integer.parseInt(cid)+"'");
|
||||
}
|
||||
/*if(condition!=null){
|
||||
int con=Integer.parseInt(condition);
|
||||
order.append(" order by createTime DESC");
|
||||
switch(con){
|
||||
case 1:
|
||||
order.append(" ,proClicknum DESC");
|
||||
break;
|
||||
case 2:
|
||||
order.append(" ,proPrice ASC");
|
||||
break;
|
||||
case 3:
|
||||
order.append(" ,proPrice DESC");
|
||||
break;
|
||||
case 4:
|
||||
br.append(" and type=0");
|
||||
break;
|
||||
case 5:
|
||||
br.append(" and type=1");
|
||||
break;
|
||||
|
||||
}
|
||||
}*/
|
||||
List<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
|
||||
if(list.size()>0){
|
||||
return list.get(0).intValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Goods> searchFoundGoodList(Map<Object, String> map) {
|
||||
String cid=map.get("cid");
|
||||
DetachedCriteria dc=DetachedCriteria.forClass(Goods.class);
|
||||
if(cid!=null){
|
||||
dc.add(Restrictions.eq("classify.cid",Integer.parseInt(cid)));
|
||||
}
|
||||
dc.add(Restrictions.eq("goodsStatus",0));
|
||||
List<Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品数量
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int searchFoundGoodCount(Map<Object, String> map) {
|
||||
StringBuffer br=new StringBuffer();
|
||||
StringBuffer order=new StringBuffer();
|
||||
String cid=map.get("cid");
|
||||
String count_hql="select count(*) from Product where goodsstatus='1'";
|
||||
if(cid!=null){
|
||||
br.append(" and classify.cid='"+Integer.parseInt(cid)+"'");
|
||||
}
|
||||
List<Long> list=this.getHibernateTemplate().find(count_hql+br.toString()+order.toString());
|
||||
if(list.size()>0){
|
||||
return list.get(0).intValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Goods getLostGoodDetail(String id) {
|
||||
int pid=0;
|
||||
if(id!=null&&id!=""){
|
||||
pid=Integer.parseInt(id);
|
||||
}
|
||||
String hql=" from Product where id=?";
|
||||
List<Goods> list=this.getHibernateTemplate().find(hql,pid);
|
||||
if(list.size()>0){
|
||||
Goods p=list.get(0);
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Goods getFoundGoodDetail(String id) {
|
||||
int pid=0;
|
||||
if(id!=null&&id!=""){
|
||||
pid=Integer.parseInt(id);
|
||||
}
|
||||
String hql=" from Product where id=?";
|
||||
List<Goods> list=this.getHibernateTemplate().find(hql,pid);
|
||||
if(list.size()>0){
|
||||
Goods p=list.get(0);
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Classify getClassifyById(Integer classifyId) {
|
||||
String hql="from Classify where cid=?";
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Classify> c=this.getHibernateTemplate().find(hql, classifyId);
|
||||
if(c.size()>0){
|
||||
Classify cla=c.get(0);
|
||||
return cla;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserById(Integer creatorId) {
|
||||
String hql="from User where uid=?";
|
||||
@SuppressWarnings("unchecked")
|
||||
List<User> u=this.getHibernateTemplate().find(hql, creatorId);
|
||||
if(u.size()>0){
|
||||
User user=u.get(0);
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void updateProduct(Product product) {
|
||||
this.getHibernateTemplate().update(product);
|
||||
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 查询我发布的商品列表数量</p>
|
||||
* @param parseInt
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int searchMyLostGoodCount(int uid) {
|
||||
String hql="select count(*) from Product where user.uid = ? and goodsstatus='0'";
|
||||
List<Long> list=this.getHibernateTemplate().find(hql,uid);
|
||||
if(list.size()>0){
|
||||
return list.get(0).intValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int searchMyFoundGoodCount(int uid) {
|
||||
String hql="select count(*) from Product where user.uid = ? and goodsstatus='1'";
|
||||
List<Long> list=this.getHibernateTemplate().find(hql,uid);
|
||||
if(list.size()>0){
|
||||
return list.get(0).intValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 查询我发布的商品列表信息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Goods> getMyLostGoodList(Map<Object, String> map) {
|
||||
DetachedCriteria dc=DetachedCriteria.forClass(model.Goods.class);
|
||||
dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId"))));
|
||||
dc.add(Restrictions.eq("goodsstatus",0));
|
||||
dc.addOrder(Order.desc("createTime"));
|
||||
List<model.Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
|
||||
return list;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Goods> getMyFoundGoodList(Map<Object, String> map) {
|
||||
DetachedCriteria dc=DetachedCriteria.forClass(model.Goods.class);
|
||||
dc.add(Restrictions.eq("user.uid",Integer.parseInt(map.get("userId"))));
|
||||
dc.add(Restrictions.eq("goodsstatus",1));
|
||||
dc.addOrder(Order.desc("createTime"));
|
||||
List<model.Goods> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 删除我发布的商品</p>
|
||||
* @param pid
|
||||
*/
|
||||
@Override
|
||||
public void delectGoodById(int pid) {
|
||||
Goods good=this.getHibernateTemplate().get(Goods.class, pid);
|
||||
if(good!=null){
|
||||
this.getHibernateTemplate().delete(good);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 保存用户消息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
/*@Override
|
||||
public void saveUserMessage(UserAdmin uaa) {
|
||||
this.getHibernateTemplate().save(uaa);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int searchMessageCount(int uid, String flag) {
|
||||
StringBuffer sb=new StringBuffer();
|
||||
String hql="select count(*) from UserAndAdmin where 1=1 ";
|
||||
if(flag=="0"||"0".equals(flag)){
|
||||
sb.append(" and status='0' and userId="+uid);
|
||||
}else{
|
||||
sb.append(" and status='1' and userId="+uid);
|
||||
}
|
||||
List<Long> list=this.getHibernateTemplate().find(hql+sb.toString());
|
||||
if(list.size()>0){
|
||||
return list.get(0).intValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<UserAdmin> getMessageList(Map<Object, String> map) {
|
||||
DetachedCriteria dc=DetachedCriteria.forClass(model.UserAdmin.class);
|
||||
String flag=map.get("flag");
|
||||
if(flag=="0"||"0".equals(flag)){
|
||||
dc.add(Restrictions.eq("userId",Integer.parseInt( map.get("userId"))));
|
||||
dc.add(Restrictions.eq("status",0));
|
||||
}else{
|
||||
dc.add(Restrictions.eq("userId",Integer.parseInt( map.get("userId"))));
|
||||
dc.add(Restrictions.eq("status",1));
|
||||
}
|
||||
List<model.UserAdmin> list=this.getHibernateTemplate().findByCriteria(dc,Integer.parseInt(map.get("begin")),Integer.parseInt(map.get("pageSize")));
|
||||
return list;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 通过id删除消息
|
||||
*/
|
||||
@Override
|
||||
public void deleteMessage(int id) {
|
||||
String hql="delete from UserAndAdmin where id="+id;
|
||||
SessionFactory factory=this.getHibernateTemplate().getSessionFactory();
|
||||
Session session=factory.openSession();
|
||||
Query query=session.createQuery(hql);
|
||||
query.executeUpdate();
|
||||
session.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<!--
|
||||
Mapping file autogenerated by MyEclipse Persistence Tools
|
||||
-->
|
||||
<hibernate-mapping>
|
||||
<class name="model.TClassify" table="t_classify" catalog="lostfound">
|
||||
<id name="cid" type="java.lang.Integer">
|
||||
<column name="CID" />
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
<property name="cname" type="java.lang.String">
|
||||
<column name="CNAME" />
|
||||
</property>
|
||||
<property name="csort" type="java.lang.Integer">
|
||||
<column name="CSORT" />
|
||||
</property>
|
||||
<set name="TGoodses" inverse="true">
|
||||
<key>
|
||||
<column name="classify_id" />
|
||||
</key>
|
||||
<one-to-many class="model.TGoods" />
|
||||
</set>
|
||||
</class>
|
||||
</hibernate-mapping>
|
@ -0,0 +1,57 @@
|
||||
package model;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TClassify entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
|
||||
public class Classify implements java.io.Serializable {
|
||||
|
||||
// Fields
|
||||
|
||||
private Integer cid;
|
||||
private String cname;
|
||||
private Integer csort;
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public Classify() {
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
public Classify(String cname, Integer csort) {
|
||||
this.cname = cname;
|
||||
this.csort = csort;
|
||||
}
|
||||
|
||||
// Property accessors
|
||||
|
||||
public Integer getCid() {
|
||||
return this.cid;
|
||||
}
|
||||
|
||||
public void setCid(Integer cid) {
|
||||
this.cid = cid;
|
||||
}
|
||||
|
||||
public String getCname() {
|
||||
return this.cname;
|
||||
}
|
||||
|
||||
public void setCname(String cname) {
|
||||
this.cname = cname;
|
||||
}
|
||||
|
||||
public Integer getCsort() {
|
||||
return this.csort;
|
||||
}
|
||||
|
||||
public void setCsort(Integer csort) {
|
||||
this.csort = csort;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<!--
|
||||
Mapping file autogenerated by MyEclipse Persistence Tools
|
||||
-->
|
||||
<hibernate-mapping>
|
||||
<class name="model.Goods" table="t_goods" catalog="lostfound">
|
||||
<id name="id" type="java.lang.Integer">
|
||||
<column name="id" />
|
||||
<generator class="assigned" />
|
||||
</id>
|
||||
<many-to-one name="user" class="model.User" fetch="select">
|
||||
<column name="creator_id" not-null="true" />
|
||||
</many-to-one>
|
||||
<many-to-one name="classify" class="model.Classify" fetch="select">
|
||||
<column name="classify_id" />
|
||||
</many-to-one>
|
||||
<property name="goodsdescribe" type="java.lang.String">
|
||||
<column name="goodsdescribe" />
|
||||
</property>
|
||||
<property name="goodsname" type="java.lang.String">
|
||||
<column name="goodsname" length="30" />
|
||||
</property>
|
||||
<property name="goodsstatus" type="java.lang.Integer">
|
||||
<column name="goodsstatus" not-null="true" />
|
||||
</property>
|
||||
<property name="goodstime" type="java.sql.Timestamp">
|
||||
<column name="goodstime" length="19" />
|
||||
</property>
|
||||
<property name="area" type="java.lang.String">
|
||||
<column name="area" length="30" />
|
||||
</property>
|
||||
<property name="contact" type="java.lang.String">
|
||||
<column name="contact" length="30" />
|
||||
</property>
|
||||
<property name="qq" type="java.lang.String">
|
||||
<column name="qq" length="30" />
|
||||
</property>
|
||||
<property name="picture" type="java.lang.String">
|
||||
<column name="picture" length="255" />
|
||||
</property>
|
||||
<property name="createTime" type="java.sql.Timestamp">
|
||||
<column name="createtime" length="19" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
@ -0,0 +1,168 @@
|
||||
package model;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* TGoods entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
|
||||
public class Goods implements java.io.Serializable {
|
||||
|
||||
// Fields
|
||||
|
||||
private Integer id;
|
||||
private User user;
|
||||
private Classify classify;
|
||||
private String goodsdescribe;
|
||||
private String goodsname;
|
||||
private Integer goodsstatus;//区分招领和寻物
|
||||
private Date goodstime;//什么时候捡到的、丢的
|
||||
private String area;
|
||||
private String contact;//联系人姓名
|
||||
private String qq;
|
||||
private String picture;
|
||||
private Date createTime;
|
||||
private Integer creatorId;//发布者id
|
||||
private Integer classifyId;//分类id
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public Goods() {
|
||||
}
|
||||
|
||||
/** minimal constructor */
|
||||
/*public Goods(Integer id, User TUser, Integer goodsstatus) {
|
||||
this.id = id;
|
||||
this.User = TUser;
|
||||
this.goodsstatus = goodsstatus;
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
/*public Goods(Integer id, User TUser, Classify TClassify,
|
||||
String goodsdescribe, String goodsname, Integer goodsstatus,
|
||||
Timestamp goodstime, String area, String contact, String qq) {
|
||||
this.id = id;
|
||||
this.TUser = TUser;
|
||||
this.TClassify = TClassify;
|
||||
this.goodsdescribe = goodsdescribe;
|
||||
this.goodsname = goodsname;
|
||||
this.goodsstatus = goodsstatus;
|
||||
this.goodstime = goodstime;
|
||||
this.area = area;
|
||||
this.contact = contact;
|
||||
this.qq = qq;
|
||||
}*/
|
||||
|
||||
// Property accessors
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPicture() {
|
||||
return picture;
|
||||
}
|
||||
public void setPicture(String picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
|
||||
public String getGoodsdescribe() {
|
||||
return this.goodsdescribe;
|
||||
}
|
||||
|
||||
public void setGoodsdescribe(String goodsdescribe) {
|
||||
this.goodsdescribe = goodsdescribe;
|
||||
}
|
||||
|
||||
public String getGoodsname() {
|
||||
return this.goodsname;
|
||||
}
|
||||
|
||||
public void setGoodsname(String goodsname) {
|
||||
this.goodsname = goodsname;
|
||||
}
|
||||
|
||||
public Integer getGoodsstatus() {
|
||||
return this.goodsstatus;
|
||||
}
|
||||
|
||||
public void setGoodsstatus(Integer goodsstatus) {
|
||||
this.goodsstatus = goodsstatus;
|
||||
}
|
||||
|
||||
public Date getGoodstime() {
|
||||
return this.goodstime;
|
||||
}
|
||||
|
||||
public void setGoodstime(Timestamp goodstime) {
|
||||
this.goodstime = goodstime;
|
||||
}
|
||||
|
||||
public String getArea() {
|
||||
return this.area;
|
||||
}
|
||||
|
||||
public void setArea(String area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getContact() {
|
||||
return this.contact;
|
||||
}
|
||||
|
||||
public void setContact(String contact) {
|
||||
this.contact = contact;
|
||||
}
|
||||
|
||||
public String getQq() {
|
||||
return this.qq;
|
||||
}
|
||||
|
||||
public void setQq(String qq) {
|
||||
this.qq = qq;
|
||||
}
|
||||
|
||||
public Integer getCreatorId() {
|
||||
return creatorId;
|
||||
}
|
||||
|
||||
public void setCreatorId(Integer creatorId) {
|
||||
this.creatorId = creatorId;
|
||||
}
|
||||
|
||||
public Integer getClassifyId() {
|
||||
return classifyId;
|
||||
}
|
||||
|
||||
public void setClassifyId(Integer classifyId) {
|
||||
this.classifyId = classifyId;
|
||||
}
|
||||
|
||||
public Classify getClassify() {
|
||||
return classify;
|
||||
}
|
||||
public void setClassify(Classify classify) {
|
||||
this.classify = classify;
|
||||
}
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,118 @@
|
||||
package model;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
/**
|
||||
* Configures and provides access to Hibernate sessions, tied to the
|
||||
* current thread of execution. Follows the Thread Local Session
|
||||
* pattern, see {@link http://hibernate.org/42.html }.
|
||||
*/
|
||||
public class HibernateSessionFactory {
|
||||
|
||||
/**
|
||||
* Location of hibernate.cfg.xml file.
|
||||
* Location should be on the classpath as Hibernate uses
|
||||
* #resourceAsStream style lookup for its configuration file.
|
||||
* The default classpath location of the hibernate config file is
|
||||
* in the default package. Use #setConfigFile() to update
|
||||
* the location of the configuration file for the current session.
|
||||
*/
|
||||
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
|
||||
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
|
||||
private static Configuration configuration = new Configuration();
|
||||
private static org.hibernate.SessionFactory sessionFactory;
|
||||
private static String configFile = CONFIG_FILE_LOCATION;
|
||||
|
||||
static {
|
||||
try {
|
||||
configuration.configure(configFile);
|
||||
sessionFactory = configuration.buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("%%%% Error Creating SessionFactory %%%%");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private HibernateSessionFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ThreadLocal Session instance. Lazy initialize
|
||||
* the <code>SessionFactory</code> if needed.
|
||||
*
|
||||
* @return Session
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public static Session getSession() throws HibernateException {
|
||||
Session session = (Session) threadLocal.get();
|
||||
|
||||
if (session == null || !session.isOpen()) {
|
||||
if (sessionFactory == null) {
|
||||
rebuildSessionFactory();
|
||||
}
|
||||
session = (sessionFactory != null) ? sessionFactory.openSession()
|
||||
: null;
|
||||
threadLocal.set(session);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild hibernate session factory
|
||||
*
|
||||
*/
|
||||
public static void rebuildSessionFactory() {
|
||||
try {
|
||||
configuration.configure(configFile);
|
||||
sessionFactory = configuration.buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("%%%% Error Creating SessionFactory %%%%");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the single hibernate session instance.
|
||||
*
|
||||
* @throws HibernateException
|
||||
*/
|
||||
public static void closeSession() throws HibernateException {
|
||||
Session session = (Session) threadLocal.get();
|
||||
threadLocal.set(null);
|
||||
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return session factory
|
||||
*
|
||||
*/
|
||||
public static org.hibernate.SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* return session factory
|
||||
*
|
||||
* session factory will be rebuilded in the next call
|
||||
*/
|
||||
public static void setConfigFile(String configFile) {
|
||||
HibernateSessionFactory.configFile = configFile;
|
||||
sessionFactory = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* return hibernate configuration
|
||||
*
|
||||
*/
|
||||
public static Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PageBean<T> {
|
||||
private int currPage;//当前页
|
||||
private int pageSize;//每页记录数
|
||||
private int totalCount;//总记录数
|
||||
private int totalPage;//总页数
|
||||
List<T> list;//每页显示的数据
|
||||
|
||||
public PageBean() {
|
||||
}
|
||||
public int getCurrPage() {
|
||||
return currPage;
|
||||
}
|
||||
public void setCurrPage(int currPage) {
|
||||
this.currPage = currPage;
|
||||
}
|
||||
public int getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
public int getTotalPage() {
|
||||
return totalPage;
|
||||
}
|
||||
public void setTotalPage(int totalPage) {
|
||||
this.totalPage = totalPage;
|
||||
}
|
||||
public List<T> getList() {
|
||||
return list;
|
||||
}
|
||||
public void setList(List<T> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<!--
|
||||
Mapping file autogenerated by MyEclipse Persistence Tools
|
||||
-->
|
||||
<hibernate-mapping>
|
||||
<class name="model.TUser" table="t_user" catalog="lostfound">
|
||||
<id name="id" type="java.lang.Integer">
|
||||
<column name="id" />
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
<property name="username" type="java.lang.String">
|
||||
<column name="username" />
|
||||
</property>
|
||||
<property name="sex" type="java.lang.Integer">
|
||||
<column name="SEX" />
|
||||
</property>
|
||||
<property name="phone" type="java.lang.String">
|
||||
<column name="PHONE" />
|
||||
</property>
|
||||
<property name="password" type="java.lang.String">
|
||||
<column name="PASSWORD" />
|
||||
</property>
|
||||
<property name="qusetion" type="java.lang.String">
|
||||
<column name="QUSETION" />
|
||||
</property>
|
||||
<property name="answer" type="java.lang.String">
|
||||
<column name="ANSWER" />
|
||||
</property>
|
||||
<set name="TGoodses" inverse="true">
|
||||
<key>
|
||||
<column name="user_id" not-null="true" />
|
||||
</key>
|
||||
<one-to-many class="model.TGoods" />
|
||||
</set>
|
||||
</class>
|
||||
</hibernate-mapping>
|
@ -0,0 +1,95 @@
|
||||
package model;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TUser entity. @author MyEclipse Persistence Tools
|
||||
*/
|
||||
|
||||
public class User implements java.io.Serializable {
|
||||
|
||||
// Fields
|
||||
|
||||
private Integer id;
|
||||
private String username;
|
||||
private Integer sex;
|
||||
private String phone;
|
||||
private String password;
|
||||
private String qusetion;
|
||||
private String answer;
|
||||
|
||||
// Constructors
|
||||
|
||||
/** default constructor */
|
||||
public User() {
|
||||
}
|
||||
|
||||
/** full constructor */
|
||||
public User(String username, String password,String qusetion, String answer) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.qusetion = qusetion;
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
// Property accessors
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Integer getSex() {
|
||||
return this.sex;
|
||||
}
|
||||
|
||||
public void setSex(Integer sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return this.phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getQusetion() {
|
||||
return this.qusetion;
|
||||
}
|
||||
|
||||
public void setQusetion(String qusetion) {
|
||||
this.qusetion = qusetion;
|
||||
}
|
||||
|
||||
public String getAnswer() {
|
||||
return this.answer;
|
||||
}
|
||||
|
||||
public void setAnswer(String answer) {
|
||||
this.answer = answer;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package service;
|
||||
|
||||
//import model.Admin;
|
||||
import model.User;
|
||||
|
||||
public interface ILoginService {
|
||||
|
||||
/**
|
||||
* 通过用户名和密码查询用户
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
User findByUser(User user);
|
||||
|
||||
/**
|
||||
* 通过管理员帐户和密码查询管理员
|
||||
* @param admin
|
||||
* @return
|
||||
*/
|
||||
//Admin findByAdmin(Admin admin);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
User findUserByName(String userName);
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
* @param user
|
||||
*/
|
||||
void saveUser(User user);
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @param user
|
||||
*/
|
||||
void updatePed(User user);
|
||||
|
||||
/**
|
||||
* 通过用户id查询用户信息
|
||||
* @param uid
|
||||
* @return
|
||||
*/
|
||||
User searchUserInfoById(int uid);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
* @param user
|
||||
*/
|
||||
void updateUser(User user);
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import model.Classify;
|
||||
import model.PageBean;
|
||||
import model.Goods;
|
||||
import model.User;
|
||||
//import model.UserAdmin;
|
||||
|
||||
public interface IUserService {
|
||||
|
||||
/**
|
||||
* 发布供求信息
|
||||
* @param product
|
||||
*/
|
||||
void saveGood(Goods good);
|
||||
|
||||
/**
|
||||
* 查询分类列表
|
||||
* @return
|
||||
*/
|
||||
List<Classify> searchClassifyList();
|
||||
|
||||
/**
|
||||
* 查询商品
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
PageBean<Goods> searchLostGoodList(Map<Object, String> map);
|
||||
PageBean<Goods> searchFoundGoodList(Map<Object, String> map);
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Goods getLostGoodDetail(String id);
|
||||
Goods getFoundGoodDetail(String id);
|
||||
|
||||
/**
|
||||
* 通过分类id获取分类信息
|
||||
* @param classifyId
|
||||
*/
|
||||
Classify getClassifyById(Integer classifyId);
|
||||
|
||||
User getUserById(Integer creatorId);
|
||||
|
||||
/*void updateProduct(Product product);*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 查询我发布的商品列表信息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
PageBean<Goods> searchMyLostGoodByPage(Map<Object, String> map);
|
||||
PageBean<Goods> searchMyFoundGoodByPage(Map<Object, String> map);
|
||||
|
||||
|
||||
/**
|
||||
* <p>Description: 删除我发布的商品</p>
|
||||
* @param pid
|
||||
*/
|
||||
void delectGoodById(int pid);
|
||||
|
||||
|
||||
/**
|
||||
* 保存用户消息
|
||||
* @param uaa
|
||||
*/
|
||||
//void saveUserMessage(UserAdmin uaa);
|
||||
|
||||
/**
|
||||
* 分页消息
|
||||
* @throws Exception
|
||||
* @param flag 0系统消息,1用户消息
|
||||
*/
|
||||
//PageBean<UserAdmin> searchMessageByPage(Map<Object, String> map);
|
||||
|
||||
/**
|
||||
* 通过id删除消息
|
||||
* @param parseInt
|
||||
*/
|
||||
void deleteMessage(int id);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package service.impl;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import dao.ILoginDao;
|
||||
//import model.Admin;
|
||||
import model.User;
|
||||
import service.ILoginService;
|
||||
@Transactional
|
||||
public class LoginService implements ILoginService{
|
||||
|
||||
private ILoginDao iLoginDao;
|
||||
|
||||
public void setiLoginDao(ILoginDao iLoginDao) {
|
||||
this.iLoginDao = iLoginDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户帐户和密码查询用户
|
||||
*/
|
||||
@Override
|
||||
public User findByUser(User user) {
|
||||
return iLoginDao.findByUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过管理员帐户和密码查询管理员
|
||||
*/
|
||||
/* @Override
|
||||
public Admin findByAdmin(Admin admin) {
|
||||
return iLoginDao.findByAdmin(admin);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
*/
|
||||
@Override
|
||||
public User findUserByName(String userName) {
|
||||
return this.iLoginDao.findUserByName(userName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
*/
|
||||
@Override
|
||||
public void saveUser(User user) {
|
||||
this.iLoginDao.saveUser(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
*/
|
||||
@Override
|
||||
public void updatePed(User user) {
|
||||
this.iLoginDao.updatePed(user);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户id查询用户信息
|
||||
*/
|
||||
@Override
|
||||
public User searchUserInfoById(int uid) {
|
||||
|
||||
return this.iLoginDao.searchUserInfoById(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*/
|
||||
@Override
|
||||
public void updateUser(User user) {
|
||||
this.iLoginDao.updateUser(user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,264 @@
|
||||
package service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import model.Classify;
|
||||
import model.PageBean;
|
||||
import model.Goods;
|
||||
import model.User;
|
||||
//import model.UserAdmin;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import service.IUserService;
|
||||
import dao.IUserDao;
|
||||
@Transactional
|
||||
public class UserService implements IUserService {
|
||||
|
||||
private IUserDao iUserDao;
|
||||
|
||||
public void setiUserDao(IUserDao iUserDao) {
|
||||
this.iUserDao = iUserDao;
|
||||
}
|
||||
Integer currPage=1;
|
||||
/**
|
||||
* 发布供求信息
|
||||
*/
|
||||
@Override
|
||||
public void saveGood(Goods good) {
|
||||
this.iUserDao.saveGood(good);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类列表
|
||||
*/
|
||||
@Override
|
||||
public List<Classify> searchClassifyList() {
|
||||
|
||||
return this.iUserDao.searchClassifyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品
|
||||
*/
|
||||
@Override
|
||||
public PageBean<Goods> searchLostGoodList(Map<Object, String> map) {
|
||||
PageBean<Goods> pageBean=new PageBean<Goods>();
|
||||
//封装当前页
|
||||
currPage=Integer.parseInt(map.get("currPage"));
|
||||
pageBean.setCurrPage(currPage);
|
||||
//封装每页记录数
|
||||
int pageSize=12;
|
||||
pageBean.setPageSize(pageSize);
|
||||
//封装总记录数
|
||||
int totalCount=this.iUserDao.searchLostGoodCount(map);
|
||||
pageBean.setTotalCount(totalCount);
|
||||
//封装总页数
|
||||
double tc=totalCount;
|
||||
Double num=Math.ceil(tc/pageSize);
|
||||
if(num==0){
|
||||
num=(double) 1;
|
||||
}
|
||||
pageBean.setTotalPage(num.intValue());
|
||||
//封装每页显示的数据
|
||||
int begin=(currPage-1)*pageSize;
|
||||
map.put("begin", begin+"");
|
||||
map.put("pageSize", pageSize+"");
|
||||
List<Goods> list=this.iUserDao.searchLostGoodList(map);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<Goods> searchFoundGoodList(Map<Object, String> map) {
|
||||
PageBean<Goods> pageBean=new PageBean<Goods>();
|
||||
//封装当前页
|
||||
currPage=Integer.parseInt(map.get("currPage"));
|
||||
pageBean.setCurrPage(currPage);
|
||||
//封装每页记录数
|
||||
int pageSize=12;
|
||||
pageBean.setPageSize(pageSize);
|
||||
//封装总记录数
|
||||
int totalCount=this.iUserDao.searchFoundGoodCount(map);
|
||||
pageBean.setTotalCount(totalCount);
|
||||
//封装总页数
|
||||
double tc=totalCount;
|
||||
Double num=Math.ceil(tc/pageSize);
|
||||
if(num==0){
|
||||
num=(double) 1;
|
||||
}
|
||||
pageBean.setTotalPage(num.intValue());
|
||||
//封装每页显示的数据
|
||||
int begin=(currPage-1)*pageSize;
|
||||
map.put("begin", begin+"");
|
||||
map.put("pageSize", pageSize+"");
|
||||
List<Goods> list=this.iUserDao.searchFoundGoodList(map);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品详情
|
||||
*/
|
||||
@Override
|
||||
public Goods getLostGoodDetail(String id) {
|
||||
|
||||
return this.iUserDao.getLostGoodDetail(id);
|
||||
}
|
||||
@Override
|
||||
public Goods getFoundGoodDetail(String id) {
|
||||
|
||||
return this.iUserDao.getFoundGoodDetail(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Classify getClassifyById(Integer classifyId) {
|
||||
return this.iUserDao.getClassifyById(classifyId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUserById(Integer creatorId) {
|
||||
|
||||
return this.iUserDao.getUserById(creatorId);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void updateProduct(Product product) {
|
||||
this.iUserDao.updateProduct(product);
|
||||
|
||||
}*/
|
||||
|
||||
/**
|
||||
* <p>Description: 查询我发布的商品列表信息</p>
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageBean<Goods> searchMyLostGoodByPage(Map<Object, String> map) {
|
||||
PageBean<Goods> pageBean=new PageBean<Goods>();
|
||||
//封装当前页
|
||||
currPage=Integer.parseInt(map.get("currPage"));
|
||||
pageBean.setCurrPage(currPage);
|
||||
//封装每页记录数
|
||||
int pageSize=5;
|
||||
pageBean.setPageSize(pageSize);
|
||||
//封装总记录数
|
||||
int totalCount=this.iUserDao.searchMyLostGoodCount(Integer.parseInt(map.get("userId")));
|
||||
pageBean.setTotalCount(totalCount);
|
||||
//封装总页数
|
||||
double tc=totalCount;
|
||||
Double num=Math.ceil(tc/pageSize);
|
||||
if(num==0){
|
||||
num=(double) 1;
|
||||
}
|
||||
pageBean.setTotalPage(num.intValue());
|
||||
//封装每页显示的数据
|
||||
int begin=(currPage-1)*pageSize;
|
||||
map.put("begin", begin+"");
|
||||
map.put("pageSize", pageSize+"");
|
||||
List<Goods> list=this.iUserDao.getMyLostGoodList(map);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
public PageBean<Goods> searchMyFoundGoodByPage(Map<Object, String> map) {
|
||||
PageBean<Goods> pageBean=new PageBean<Goods>();
|
||||
//封装当前页
|
||||
currPage=Integer.parseInt(map.get("currPage"));
|
||||
pageBean.setCurrPage(currPage);
|
||||
//封装每页记录数
|
||||
int pageSize=5;
|
||||
pageBean.setPageSize(pageSize);
|
||||
//封装总记录数
|
||||
int totalCount=this.iUserDao.searchMyFoundGoodCount(Integer.parseInt(map.get("userId")));
|
||||
pageBean.setTotalCount(totalCount);
|
||||
//封装总页数
|
||||
double tc=totalCount;
|
||||
Double num=Math.ceil(tc/pageSize);
|
||||
if(num==0){
|
||||
num=(double) 1;
|
||||
}
|
||||
pageBean.setTotalPage(num.intValue());
|
||||
//封装每页显示的数据
|
||||
int begin=(currPage-1)*pageSize;
|
||||
map.put("begin", begin+"");
|
||||
map.put("pageSize", pageSize+"");
|
||||
List<Goods> list=this.iUserDao.getMyFoundGoodList(map);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Description: 删除我发布的商品</p>
|
||||
* @param pid
|
||||
*/
|
||||
@Override
|
||||
public void delectGoodById(int pid) {
|
||||
this.iUserDao.delectGoodById(pid);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存用户消息
|
||||
* @param uaa
|
||||
*/
|
||||
/* @Override
|
||||
public void saveUserMessage(UserAdmin uaa) {
|
||||
this.iUserDao.saveUserMessage(uaa);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页消息
|
||||
* @throws Exception
|
||||
* @param flag 0系统消息,1用户消息
|
||||
*/
|
||||
/* @Override
|
||||
public PageBean<UserAdmin> searchMessageByPage(Map<Object, String> map) {
|
||||
PageBean<UserAdmin> pageBean=new PageBean<UserAdmin>();
|
||||
//封装当前页
|
||||
currPage=Integer.parseInt(map.get("currPage"));
|
||||
pageBean.setCurrPage(currPage);
|
||||
//封装每页记录数
|
||||
int pageSize=10;
|
||||
pageBean.setPageSize(pageSize);
|
||||
//封装总记录数
|
||||
int totalCount=this.iUserDao.searchMessageCount(Integer.parseInt(map.get("userId")),map.get("flag"));
|
||||
pageBean.setTotalCount(totalCount);
|
||||
//封装总页数
|
||||
double tc=totalCount;
|
||||
Double num=Math.ceil(tc/pageSize);
|
||||
if(num==0){
|
||||
num=(double) 1;
|
||||
}
|
||||
pageBean.setTotalPage(num.intValue());
|
||||
//封装每页显示的数据
|
||||
int begin=(currPage-1)*pageSize;
|
||||
map.put("begin", begin+"");
|
||||
map.put("pageSize", pageSize+"");
|
||||
List<UserAdmin> list=this.iUserDao.getMessageList(map);
|
||||
pageBean.setList(list);
|
||||
return pageBean;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 通过id删除消息
|
||||
*/
|
||||
@Override
|
||||
public void deleteMessage(int id) {
|
||||
this.iUserDao.deleteMessage(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue