Initial commit
This commit is contained in:
4
src/com/qf/service/AddressService.java
Normal file
4
src/com/qf/service/AddressService.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.qf.service;
|
||||
|
||||
public interface AddressService {
|
||||
}
|
19
src/com/qf/service/CartService.java
Normal file
19
src/com/qf/service/CartService.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.qf.service;
|
||||
|
||||
import com.qf.entity.Cart;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public interface CartService {
|
||||
void createCart(int uid, String pid) throws SQLException, InvocationTargetException, IllegalAccessException;
|
||||
|
||||
List<Cart> findAll(int uid) throws SQLException, InvocationTargetException, IllegalAccessException;
|
||||
|
||||
void deleteCartByCid(String cid) throws SQLException;
|
||||
|
||||
void updateCartByCid(String cid, String price, String cnum) throws SQLException;
|
||||
|
||||
void clearCartByUid(String uid) throws SQLException;
|
||||
}
|
12
src/com/qf/service/ProductService.java
Normal file
12
src/com/qf/service/ProductService.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.qf.service;
|
||||
|
||||
import com.qf.entity.PageBean;
|
||||
import com.qf.entity.Product;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface ProductService {
|
||||
PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException;
|
||||
|
||||
Product findProductByPid(String pid) throws SQLException;
|
||||
}
|
13
src/com/qf/service/TypeService.java
Normal file
13
src/com/qf/service/TypeService.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.qf.service;
|
||||
|
||||
import com.qf.entity.Type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public interface TypeService {
|
||||
|
||||
//查询返回所有类别表中对应的type信息
|
||||
List<Type> findAll() throws SQLException;
|
||||
|
||||
}
|
17
src/com/qf/service/UserService.java
Normal file
17
src/com/qf/service/UserService.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.qf.service;
|
||||
|
||||
import com.qf.entity.User;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
//查询用户名是否存在
|
||||
boolean checkedUser(String username) throws SQLException;
|
||||
|
||||
//注册业务逻辑
|
||||
int registerUser(User user) throws SQLException;
|
||||
|
||||
//登录的业务逻辑
|
||||
User login(String username, String password) throws SQLException;
|
||||
}
|
6
src/com/qf/service/impl/AddressServiceImpl.java
Normal file
6
src/com/qf/service/impl/AddressServiceImpl.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.qf.service.impl;
|
||||
|
||||
import com.qf.service.AddressService;
|
||||
|
||||
public class AddressServiceImpl implements AddressService {
|
||||
}
|
88
src/com/qf/service/impl/CartServiceImpl.java
Normal file
88
src/com/qf/service/impl/CartServiceImpl.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package com.qf.service.impl;
|
||||
|
||||
import com.qf.dao.CartDao;
|
||||
import com.qf.dao.ProductDao;
|
||||
import com.qf.dao.impl.CartDaoImpl;
|
||||
import com.qf.dao.impl.ProductDaoImpl;
|
||||
import com.qf.entity.Cart;
|
||||
import com.qf.entity.Product;
|
||||
import com.qf.service.CartService;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class CartServiceImpl implements CartService {
|
||||
//1.向购物车中添加物品
|
||||
@Override
|
||||
public void createCart(int uid, String pid) throws SQLException, InvocationTargetException, IllegalAccessException {
|
||||
//1.判断商品是否已经存在
|
||||
CartDao cartDao = new CartDaoImpl();
|
||||
Cart cart = cartDao.hasCart(uid, pid);
|
||||
|
||||
if (cart != null) {
|
||||
//已存在该物品,修改数量
|
||||
cart.setCnum(cart.getCnum() + 1);
|
||||
cartDao.updateCart(cart);
|
||||
} else {
|
||||
//不存在该物品,添加该物品
|
||||
ProductDao productDao = new ProductDaoImpl();
|
||||
Product product = productDao.selectProductByPid(pid);
|
||||
|
||||
//完成添加
|
||||
cart = new Cart();
|
||||
cart.setCnum(1);
|
||||
cart.setPid(Integer.parseInt(pid));
|
||||
cart.setProduct(product);
|
||||
cart.setUid(uid);
|
||||
|
||||
//完成插入操作
|
||||
cartDao.insertCart(cart);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//2.根据uid查询所有商品
|
||||
@Override
|
||||
public List<Cart> findAll(int uid) throws SQLException, InvocationTargetException, IllegalAccessException {
|
||||
|
||||
CartDao cartDao = new CartDaoImpl();
|
||||
//1.根据用户 id 查询对应购物车里面的商品
|
||||
List<Cart> carts = cartDao.selectCartByUid(uid);
|
||||
return carts;
|
||||
}
|
||||
|
||||
//3.根据cid删除购物车中物品
|
||||
@Override
|
||||
public void deleteCartByCid(String cid) throws SQLException {
|
||||
CartDao cartDao = new CartDaoImpl();
|
||||
cartDao.deleteCartByCid(cid);
|
||||
}
|
||||
|
||||
//4.购物车修改数量
|
||||
@Override
|
||||
public void updateCartByCid(String cid, String price, String cnum) throws SQLException {
|
||||
|
||||
//1.将对应的 cnum 和 price 转换成对应的大数据类型
|
||||
BigDecimal cnumbig = new BigDecimal(cnum);
|
||||
BigDecimal prciebig = new BigDecimal(price);
|
||||
|
||||
//2.进行小计计算
|
||||
BigDecimal count = prciebig.multiply(cnumbig);
|
||||
|
||||
//3.数据库中修改
|
||||
CartDao cartDao = new CartDaoImpl();
|
||||
cartDao.updateByCid(count, cnumbig, cid);
|
||||
|
||||
}
|
||||
|
||||
//5.清空购物车
|
||||
@Override
|
||||
public void clearCartByUid(String uid) throws SQLException {
|
||||
|
||||
CartDao cartDao = new CartDaoImpl();
|
||||
cartDao.clearCartByUid(uid);
|
||||
|
||||
}
|
||||
}
|
34
src/com/qf/service/impl/ProductServiceImpl.java
Normal file
34
src/com/qf/service/impl/ProductServiceImpl.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.qf.service.impl;
|
||||
|
||||
import com.qf.dao.ProductDao;
|
||||
import com.qf.dao.impl.ProductDaoImpl;
|
||||
import com.qf.entity.PageBean;
|
||||
import com.qf.entity.Product;
|
||||
import com.qf.service.ProductService;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
@Override
|
||||
public PageBean<Product> findPage(String tid, int page, int pageSize) throws SQLException {
|
||||
ProductDao productDao = new ProductDaoImpl();
|
||||
//1.查询有多少条数据
|
||||
long count = productDao.selectCountByTid(tid);
|
||||
|
||||
//
|
||||
List<Product> list = productDao.selectProductByPage(page, pageSize, tid);
|
||||
|
||||
return new PageBean<Product>(list, page, pageSize, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Product findProductByPid(String pid) throws SQLException {
|
||||
//1.先到数据库中进行商品查询
|
||||
ProductDao productDao = new ProductDaoImpl();
|
||||
//2.定义一个productdao里面对应的方法,返回product
|
||||
Product product = productDao.selectProductByPid(pid);
|
||||
//3.返回product信息
|
||||
return product;
|
||||
}
|
||||
}
|
20
src/com/qf/service/impl/TypeServiceImpl.java
Normal file
20
src/com/qf/service/impl/TypeServiceImpl.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.qf.service.impl;
|
||||
|
||||
import com.qf.dao.TypeDao;
|
||||
import com.qf.dao.impl.TypeDaoImpl;
|
||||
import com.qf.entity.Type;
|
||||
import com.qf.service.TypeService;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeServiceImpl implements TypeService {
|
||||
|
||||
@Override
|
||||
public List<Type> findAll() throws SQLException {
|
||||
//这里调用TypeDao接口(Dao层)
|
||||
TypeDao typeDao = new TypeDaoImpl();
|
||||
List<Type> types = typeDao.selectAll();
|
||||
return types;
|
||||
}
|
||||
}
|
52
src/com/qf/service/impl/UserServiceImpl.java
Normal file
52
src/com/qf/service/impl/UserServiceImpl.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.qf.service.impl;
|
||||
|
||||
import com.qf.dao.UserDao;
|
||||
import com.qf.dao.impl.UserDaoImpl;
|
||||
import com.qf.entity.User;
|
||||
import com.qf.service.UserService;
|
||||
import com.qf.utils.MD5Utils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UserServiceImpl implements UserService {
|
||||
//查询用户名是否存在
|
||||
@Override
|
||||
public boolean checkedUser(String username) throws SQLException {
|
||||
|
||||
//根据dao访问对象
|
||||
UserDao userDao = new UserDaoImpl();
|
||||
User user = userDao.selectUserByUname(username);
|
||||
|
||||
//处理返回值
|
||||
if (user != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//没有查询到
|
||||
return false;
|
||||
}
|
||||
|
||||
//注册业务逻辑
|
||||
@Override
|
||||
public int registerUser(User user) throws SQLException {
|
||||
UserDao userDao = new UserDaoImpl();
|
||||
int row = userDao.insertUser(user);
|
||||
return row;
|
||||
}
|
||||
|
||||
//登录的业务逻辑
|
||||
@Override
|
||||
public User login(String username, String password) throws SQLException {
|
||||
//1.密码加密处理(数据库中密码已加密处理)便于比较
|
||||
String md5password = MD5Utils.md5(password);
|
||||
//2.根据用户名查询用户
|
||||
UserDao userDao = new UserDaoImpl();
|
||||
User user = userDao.selectUserByUname(username);
|
||||
//3.账号密码对比(正确返回user)
|
||||
if (user != null && user.getUpassword().equals(md5password)) {
|
||||
return user;
|
||||
}
|
||||
//错误返回空 null
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user