基于javaweb+mysql的springboot+mybatis网上商城项目(java+springboot+ssm+jsp+mysql+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot+MyBatis网上商城项目(java+springboot+ssm+jsp+mysql+maven)
一、项目简述
功能:网上商城系统,前台+后台管理,用户注册,登录, 上哦展示,分组展示,搜索,收货地址管理,购物车管 理,添加,购买,个人信息修改。订单查询等等,后台商 品管理,分类管理,库存管理,订单管理,用户管理,信 息、修改等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +SpringBoot+Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
}
List<Product> loveProductList = productService.getList(new Product().setProduct_category(
new Category().setCategory_id(category_id)),
new Byte[]{0, 2},
null,
new PageUtil().setCount(3).setPageStart(i)
);
if (loveProductList != null) {
logger.info("获取产品列表的相应的一张预览图片");
for (Product loveProduct : loveProductList) {
loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
}
}
logger.info("获取分类列表");
List<Category> categoryList = categoryService.getList(null, new PageUtil(0, 3));
map.put("loveProductList", loveProductList);
map.put("categoryList", categoryList);
map.put("propertyList", propertyList);
map.put("product", product);
map.put("guessNumber", i);
map.put("pageUtil", new PageUtil(0, 10).setTotal(product.getProduct_review_count()));
logger.info("转到前台-产品详情页");
return "fore/productDetailsPage";
}
//按产品ID加载产品评论列表-ajax
@Deprecated
@ResponseBody
@RequestMapping(value = "review/{pid}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String loadProductReviewList(@PathVariable("pid") String pid/*产品ID*/,
@RequestParam Integer index/* 页数 */,
@RequestParam Integer count/* 行数 */) {
logger.info("获取产品ID");
Integer product_id = Integer.parseInt(pid);
logger.info("获取产品评论列表");
List<Review> reviewList = reviewService.getListByProductId(product_id, new PageUtil(index, count));
JSONObject jsonObject = new JSONObject();
jsonObject.put("reviewList", JSONArray.parseArray(JSON.toJSONString(reviewList)));
return jsonObject.toJSONString();
return object.toJSONString();
}
}
/**
* 产品详情页
*/
@Controller
public class ForeProductDetailsController extends BaseController {
@Resource(name = "productService")
private ProductService productService;
@Resource(name = "userService")
private UserService userService;
@Resource(name = "productImageService")
private ProductImageService productImageService;
@Resource(name = "categoryService")
private CategoryService categoryService;
@Resource(name = "propertyValueService")
private PropertyValueService propertyValueService;
@Resource(name = "propertyService")
private PropertyService propertyService;
@Resource(name = "reviewService")
private ReviewService reviewService;
@Resource(name = "productOrderItemService")
private ProductOrderItemService productOrderItemService;
//转到前台天猫-产品详情页
@RequestMapping(value = "product/{pid}", method = RequestMethod.GET)
.setProduct_sale_price(product_sale_price)
.setProduct_price(product_price)
.setProduct_isEnabled(product_isEnabled)
.setProduct_create_date(new Date());
logger.info("添加产品信息");
boolean yn = productService.add(product);
if (!yn) {
logger.warn("产品添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
int product_id = lastIDService.selectLastID();
logger.info("添加成功!,新增产品的ID值为:{}", product_id);
JSONObject object = JSON.parseObject(propertyJson);
Set<String> propertyIdSet = object.keySet();
if (propertyIdSet.size() > 0) {
logger.info("整合产品子信息-产品属性");
List<PropertyValue> propertyValueList = new ArrayList<>(5);
for (String key : propertyIdSet) {
String value = object.getString(key);
PropertyValue propertyValue = new PropertyValue()
.setPropertyValue_value(value)
.setPropertyValue_property(new Property().setProperty_id(Integer.valueOf(key)))
.setPropertyValue_product(new Product().setProduct_id(product_id));
propertyValueList.add(propertyValue);
}
logger.info("共有{}条产品属性数据", propertyValueList.size());
yn = propertyValueService.addList(propertyValueList);
if (yn) {
logger.info("产品属性添加成功!");
} else {
logger.warn("产品属性添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
if (productSingleImageList != null && productSingleImageList.length > 0) {
logger.info("整合产品子信息-产品预览图片");
List<ProductImage> productImageList = new ArrayList<>(5);
for (String imageName : productSingleImageList) {
.setProductImage_product(product)
);
}
logger.info("共有{}条产品预览图片数据", productImageList.size());
yn = productImageService.addList(productImageList);
if (yn) {
logger.info("产品预览图片添加成功!");
} else {
logger.warn("产品预览图片添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
if (productDetailsImageList != null && productDetailsImageList.length > 0) {
logger.info("整合产品子信息-产品详情图片");
List<ProductImage> productImageList = new ArrayList<>(5);
for (String imageName : productDetailsImageList) {
productImageList.add(new ProductImage()
.setProductImage_type((byte) 1)
.setProductImage_src(imageName.substring(imageName.lastIndexOf("/") + 1))
.setProductImage_product(product)
);
}
logger.info("共有{}条产品详情图片数据", productImageList.size());
yn = productImageService.addList(productImageList);
if (yn) {
logger.info("产品详情图片添加成功!");
} else {
logger.warn("产品详情图片添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
jsonObject.put("success", true);
jsonObject.put("product_id", product_id);
return jsonObject.toJSONString();
}
//按条件查询产品-ajax
@ResponseBody
@RequestMapping(value = "admin/product/{index}/{count}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String getProductBySearch(@RequestParam(required = false) String product_name/* 产品名称 */,
@RequestParam(required = false) Integer category_id/* 产品类型ID */,
@RequestParam(required = false) Double product_sale_price/* 产品促销价 */,
@RequestParam(required = false) Double product_price/* 产品原价 */,
@RequestParam Double product_sale_price/* 产品促销价 */,
@RequestParam Double product_price/* 产品原价 */,
@RequestParam Byte product_isEnabled/* 产品状态 */,
@RequestParam String propertyAddJson/* 产品添加属性JSON */,
@RequestParam String propertyUpdateJson/* 产品更新属性JSON */,
@RequestParam(required = false) Integer[] propertyDeleteList/* 产品删除属性ID数组 */,
@RequestParam(required = false) String[] productSingleImageList/*产品预览图片名称数组*/,
@RequestParam(required = false) String[] productDetailsImageList/*产品详情图片名称数组*/,
@PathVariable("product_id") Integer product_id/* 产品ID */) {
JSONObject jsonObject = new JSONObject();
logger.info("整合产品信息");
Product product = new Product()
.setProduct_id(product_id)
.setProduct_name(product_name)
.setProduct_title(product_title)
.setProduct_category(new Category().setCategory_id(product_category_id))
.setProduct_sale_price(product_sale_price)
.setProduct_price(product_price)
.setProduct_isEnabled(product_isEnabled)
.setProduct_create_date(new Date());
logger.info("更新产品信息,产品ID值为:{}", product_id);
boolean yn = productService.update(product);
if (!yn) {
logger.info("产品信息更新失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
logger.info("产品信息更新成功!");
JSONObject object = JSON.parseObject(propertyAddJson);
Set<String> propertyIdSet = object.keySet();
if (propertyIdSet.size() > 0) {
logger.info("整合产品子信息-需要添加的产品属性");
List<PropertyValue> propertyValueList = new ArrayList<>(5);
for (String key : propertyIdSet) {
String value = object.getString(key);
PropertyValue propertyValue = new PropertyValue()
.setPropertyValue_value(value)
.setPropertyValue_property(new Property().setProperty_id(Integer.valueOf(key)))
.setPropertyValue_product(product);
propertyValueList.add(propertyValue);
}
logger.info("共有{}条需要添加的产品属性数据", propertyValueList.size());
yn = propertyValueService.addList(propertyValueList);
if (yn) {
logger.info("产品属性添加成功!");
} else {
logger.warn("产品属性添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
}
if (orderItem.getProductOrderItem_order() != null) {
logger.warn("用户订单项不属于购物车,回到购物车页");
return "redirect:/cart";
}
}
logger.info("验证通过,获取订单项的产品信息");
double orderTotalPrice = 0.0;
for (ProductOrderItem orderItem : orderItemList) {
Product product = productService.get(orderItem.getProductOrderItem_product().getProduct_id());
product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
product.setSingleProductImageList(productImageService.getList(product.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
orderItem.setProductOrderItem_product(product);
orderTotalPrice += orderItem.getProductOrderItem_price();
}
String addressId = "110000";
String cityAddressId = "110100";
String districtAddressId = "110101";
String detailsAddress = null;
String order_post = null;
String order_receiver = null;
String order_phone = null;
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
String cookieName = cookie.getName();
String cookieValue = cookie.getValue();
switch (cookieName) {
case "addressId":
addressId = cookieValue;
break;
case "cityAddressId":
cityAddressId = cookieValue;
break;
case "districtAddressId":
districtAddressId = cookieValue;
break;
case "order_post":
order_post = URLDecoder.decode(cookieValue, "UTF-8");
break;
case "order_receiver":
order_receiver = URLDecoder.decode(cookieValue, "UTF-8");
/**
* 后台管理-账户页
*/
@Controller
public class AccountController extends BaseController{
@Resource(name = "adminService")
private AdminService adminService;
//转到后台管理-账户页-ajax
@RequestMapping(value = "admin/account", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map){
logger.info("获取管理员信息");
Object adminId = checkAdmin(session);
if(adminId == null){
return "admin/include/loginMessage";
}
logger.info("获取目前登录的管理员信息,管理员ID:{}",adminId);
Admin admin = adminService.get(null,Integer.parseInt(adminId.toString()));
map.put("admin",admin);
logger.info("转到后台管理-账户页-ajax方式");
return "admin/accountManagePage";
}
//退出当前账号
@RequestMapping(value = "admin/account/logout", method = RequestMethod.GET)
public String logout(HttpSession session) {
Object o = session.getAttribute("adminId");
if (o == null) {
logger.info("无相关信息,返回管理员登陆页");
} else {
session.removeAttribute("adminId");
);
}
logger.info("共有{}条产品详情图片数据", productImageList.size());
yn = productImageService.addList(productImageList);
if (yn) {
logger.info("产品详情图片添加成功!");
} else {
logger.warn("产品详情图片添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
jsonObject.put("success", true);
jsonObject.put("product_id", product_id);
return jsonObject.toJSONString();
}
//按条件查询产品-ajax
@ResponseBody
@RequestMapping(value = "admin/product/{index}/{count}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String getProductBySearch(@RequestParam(required = false) String product_name/* 产品名称 */,
@RequestParam(required = false) Integer category_id/* 产品类型ID */,
@RequestParam(required = false) Double product_sale_price/* 产品促销价 */,
@RequestParam(required = false) Double product_price/* 产品原价 */,
@RequestParam(required = false) Byte[] product_isEnabled_array/* 产品状态数组 */,
@RequestParam(required = false) String orderBy/* 排序字段 */,
@RequestParam(required = false,defaultValue = "true") Boolean isDesc/* 是否倒序 */,
@PathVariable Integer index/* 页数 */,
@PathVariable Integer count/* 行数 */) throws UnsupportedEncodingException {
//移除不必要条件
if (product_isEnabled_array != null && (product_isEnabled_array.length <= 0 || product_isEnabled_array.length >=3)) {
product_isEnabled_array = null;
}
if (category_id != null && category_id == 0) {
category_id = null;
}
if (product_name != null) {
//如果为非空字符串则解决中文乱码:URLDecoder.decode(String,"UTF-8");
product_name = "".equals(product_name) ? null : URLDecoder.decode(product_name, "UTF-8");
}
if (orderBy != null && "".equals(orderBy)) {
orderBy = null;
}
//封装查询条件
Product product = new Product()
.setProduct_name(product_name)
.setProduct_category(new Category().setCategory_id(category_id))
.setProduct_price(product_price)
.setProduct_sale_price(product_sale_price);
OrderUtil orderUtil = null;
/**
* 注册页
*/
@Controller
public class ForeRegisterController extends BaseController{
@Resource(name = "addressService")
private AddressService addressService;
@Resource(name="userService")
private UserService userService;
//转到前台天猫-用户注册页
@RequestMapping(value = "register", method = RequestMethod.GET)
public String goToPage(Map<String,Object> map) {
String addressId = "110000";
String cityAddressId = "110100";
logger.info("获取省份信息");
List<Address> addressList = addressService.getRoot();
logger.info("获取addressId为{}的市级地址信息", addressId);
List<Address> cityAddress = addressService.getList(null, addressId);
logger.info("获取cityAddressId为{}的区级地址信息", cityAddressId);
List<Address> districtAddress = addressService.getList(null, cityAddressId);
map.put("addressList", addressList);
map.put("cityList", cityAddress);
map.put("districtList", districtAddress);
map.put("addressId", addressId);
map.put("cityAddressId", cityAddressId);
logger.info("转到前台-用户注册页");
return "fore/register";
}
//天猫前台-用户注册-ajax
@ResponseBody
@RequestMapping(value = "register/doRegister", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
public String register(
@RequestParam(value = "user_name") String user_name /*用户名 */,
@RequestParam(value = "user_nickname") String user_nickname /*用户昵称 */,
List<Property> propertyList = propertyService.getList(new Property().setProperty_category(product.getProduct_category()), null);
logger.info("属性列表和属性值列表合并");
for (Property property : propertyList) {
for (PropertyValue propertyValue : propertyValueList) {
if (property.getProperty_id().equals(propertyValue.getPropertyValue_property().getProperty_id())) {
List<PropertyValue> property_value_item = new ArrayList<>(1);
property_value_item.add(propertyValue);
property.setPropertyValueList(property_value_item);
break;
}
}
}
logger.info("获取产品子信息-产品评论信息");
product.setReviewList(reviewService.getListByProductId(product_id, null));
if (product.getReviewList() != null) {
for (Review review : product.getReviewList()) {
review.setReview_user(userService.get(review.getReview_user().getUser_id()));
}
}
logger.info("获取猜你喜欢列表");
Integer category_id = product.getProduct_category().getCategory_id();
Integer total = productService.getTotal(new Product().setProduct_category(new Category().setCategory_id(category_id)), new Byte[]{0, 2});
logger.info("分类ID为{}的产品总数为{}条", category_id, total);
//生成随机数
int i = new Random().nextInt(total);
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
}
List<Product> loveProductList = productService.getList(new Product().setProduct_category(
new Category().setCategory_id(category_id)),
new Byte[]{0, 2},
null,
new PageUtil().setCount(3).setPageStart(i)
);
if (loveProductList != null) {
logger.info("获取产品列表的相应的一张预览图片");
for (Product loveProduct : loveProductList) {
loveProduct.setSingleProductImageList(productImageService.getList(loveProduct.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
}
}
logger.info("获取分类列表");
List<Category> categoryList = categoryService.getList(null, new PageUtil(0, 3));
map.put("loveProductList", loveProductList);
map.put("categoryList", categoryList);
map.put("propertyList", propertyList);
map.put("product", product);
map.put("guessNumber", i);
map.put("pageUtil", new PageUtil(0, 10).setTotal(product.getProduct_review_count()));
logger.info("转到前台-产品详情页");
/**
* 后台管理-订单页
*/
@Controller
public class
OrderController extends BaseController{
@Resource(name="productOrderService")
private ProductOrderService productOrderService;
@Resource(name = "addressService")
private AddressService addressService;
@Resource(name="userService")
private UserService userService;
@Resource(name = "productOrderItemService")
private ProductOrderItemService productOrderItemService;
@Resource(name = "productService")
private ProductService productService;
@Resource(name = "productImageService")
private ProductImageService productImageService;
@Resource(name = "lastIDService")
private LastIDService lastIDService;
//转到后台管理-订单页-ajax
@RequestMapping(value = "admin/order", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map){
logger.info("获取前10条订单列表");
PageUtil pageUtil = new PageUtil(0, 10);
List<ProductOrder> productOrderList =
productOrderService.getList(
null,
null,
new OrderUtil("productOrder_id",
true), pageUtil);
map.put("productOrderList",productOrderList);
logger.info("获取订单总数量");
Integer productOrderCount = productOrderService.getTotal(null, null);
map.put("productOrderCount", productOrderCount);
logger.info("获取分页信息");
pageUtil.setTotal(productOrderCount);
map.put("pageUtil", pageUtil);
List<Address> cityAddress = addressService.getList(null, addressId);
logger.info("获取cityAddressId为{}的区级地址信息", cityAddressId);
List<Address> districtAddress = addressService.getList(null, cityAddressId);
map.put("orderItemList", orderItemList);
map.put("addressList", addressList);
map.put("cityList", cityAddress);
map.put("districtList", districtAddress);
map.put("orderTotalPrice", orderTotalPrice);
map.put("addressId", addressId);
map.put("cityAddressId", cityAddressId);
map.put("districtAddressId", districtAddressId);
map.put("order_post", order_post);
map.put("order_receiver", order_receiver);
map.put("order_phone", order_phone);
map.put("detailsAddress", detailsAddress);
logger.info("转到前台天猫-订单建立页");
return "fore/productBuyPage";
}
//转到前台天猫-订单支付页
@RequestMapping(value = "order/pay/{order_code}", method = RequestMethod.GET)
public String goToOrderPayPage(Map<String, Object> map, HttpSession session,
@PathVariable("order_code") String order_code) {
logger.info("检查用户是否登录");
Object userId = checkUser(session);
User user;
if (userId != null) {
logger.info("获取用户信息");
user = userService.get(Integer.parseInt(userId.toString()));
map.put("user", user);
} else {
return "redirect:/login";
}
logger.info("------验证订单信息------");
logger.info("查询订单是否存在");
ProductOrder order = productOrderService.getByCode(order_code);
if (order == null) {
logger.warn("订单不存在,返回订单列表页");
return "redirect:/order/0/10";
}
logger.info("验证订单状态");
if (order.getProductOrder_status() != 0) {
logger.warn("订单状态不正确,返回订单列表页");
return "redirect:/order/0/10";
}
logger.info("验证用户与订单是否一致");
if (order.getProductOrder_user().getUser_id() != Integer.parseInt(userId.toString())) {
logger.warn("用户与订单信息不一致,返回订单列表页");
return "redirect:/order/0/10";
}
order.setProductOrderItemList(productOrderItemService.getListByOrderId(order.getProductOrder_id(), null));
object.put("url", "/order/0/10");
return object.toJSONString();
}
logger.info("更新订单信息");
ProductOrder productOrder = new ProductOrder()
.setProductOrder_id(order.getProductOrder_id())
.setProductOrder_status((byte) 3)
.setProductOrder_confirm_date(new Date());
boolean yn = productOrderService.update(productOrder);
if (yn) {
object.put("success", true);
} else {
object.put("success", false);
}
return object.toJSONString();
}
//更新订单信息为交易关闭-ajax
@ResponseBody
@RequestMapping(value = "order/close/{order_code}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
public String orderClose(HttpSession session, @PathVariable("order_code") String order_code) {
JSONObject object = new JSONObject();
logger.info("检查用户是否登录");
Object userId = checkUser(session);
if (userId == null) {
object.put("success", false);
object.put("url", "/login");
return object.toJSONString();
}
logger.info("------验证订单信息------");
logger.info("查询订单是否存在");
ProductOrder order = productOrderService.getByCode(order_code);
if (order == null) {
logger.warn("订单不存在,返回订单列表页");
object.put("success", false);
object.put("url", "/order/0/10");
return object.toJSONString();
}
logger.info("验证订单状态");
if (order.getProductOrder_status() != 0) {
logger.warn("订单状态不正确,返回订单列表页");
* 转到后台管理-主页(ajax方式)
* @param session session对象
* @param map 前台传入的Map
* @return 响应数据
* @throws ParseException 转换异常
*/
@RequestMapping(value = "admin/home", method = RequestMethod.GET)
public String goToPageByAjax(HttpSession session, Map<String, Object> map) throws ParseException {
logger.info("获取管理员信息");
Object adminId = checkAdmin(session);
if (adminId == null) {
return "admin/include/loginMessage";
}
Admin admin = adminService.get(null, Integer.parseInt(adminId.toString()));
map.put("admin", admin);
logger.info("获取统计信息");
Integer productTotal = productService.getTotal(null, new Byte[]{0, 2});
Integer userTotal = userService.getTotal(null);
Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3});
logger.info("获取图表信息");
map.put("jsonObject", getChartData(null, null,7));
logger.info("获取图表信息");
map.put("jsonObject", getChartData(null,null,7));
map.put("productTotal", productTotal);
map.put("userTotal", userTotal);
map.put("orderTotal", orderTotal);
logger.info("转到后台管理-主页-ajax方式");
return "admin/homeManagePage";
}
/**
* 按日期查询图表数据(ajax方式)
* @param beginDate 开始日期
* @param endDate 结束日期
* @return 响应数据
* @throws ParseException 转换异常
*/
@ResponseBody
@RequestMapping(value = "admin/home/charts", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String getChartDataByDate(@RequestParam(required = false) String beginDate, @RequestParam(required = false) String endDate) throws ParseException {
//转到前台天猫-主页
@RequestMapping(value = "/", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map) {
logger.info("检查用户是否登录");
Object userId = checkUser(session);
if (userId != null) {
logger.info("获取用户信息");
User user = userService.get(Integer.parseInt(userId.toString()));
map.put("user", user);
}
logger.info("获取产品分类列表");
List<Category> categoryList = categoryService.getList(null,null);
logger.info("获取每个分类下的产品列表");
for(Category category : categoryList){
List<Product> productList = productService.getList(
new Product().setProduct_category(category),
new Byte[]{0, 2},
new OrderUtil("product_sale_count", true), new PageUtil(0, 8)
);
if (productList != null) {
for (Product product : productList) {
Integer product_id = product.getProduct_id();
product.setSingleProductImageList(
productImageService.getList(
product_id, (byte) 0, new PageUtil(0, 1)
)
);
}
}
category.setProductList(productList);
}
map.put("categoryList",categoryList);
logger.info("获取促销产品列表");
List<Product> specialProductList = productService.getList(
null, new Byte[]{2}, null, new PageUtil(0, 6)
);
map.put("specialProductList", specialProductList);
logger.info("转到前台主页");
return "fore/homePage";
order.setProductOrder_detail_address(builder.toString());
logger.info("获取订单详情-用户信息");
order.setProductOrder_user(userService.get(order.getProductOrder_user().getUser_id()));
logger.info("获取订单详情-订单项信息");
List<ProductOrderItem> productOrderItemList = productOrderItemService.getListByOrderId(oid, null);
if (productOrderItemList != null) {
logger.info("获取订单详情-订单项对应的产品信息");
for (ProductOrderItem productOrderItem : productOrderItemList) {
Integer productId = productOrderItem.getProductOrderItem_product().getProduct_id();
logger.info("获取产品ID为{}的产品信息", productId);
Product product = productService.get(productId);
if (product != null) {
logger.info("获取产品ID为{}的第一张预览图片信息", productId);
product.setSingleProductImageList(productImageService.getList(productId, (byte) 0, new PageUtil(0, 1)));
}
productOrderItem.setProductOrderItem_product(product);
}
}
order.setProductOrderItemList(productOrderItemList);
map.put("order", order);
logger.info("转到后台管理-订单详情页-ajax方式");
return "admin/include/orderDetails";
}
//更新订单信息-ajax
@ResponseBody
@RequestMapping(value = "admin/order/{order_id}", method = RequestMethod.PUT, produces = "application/json;charset=UTF-8")
public String updateOrder(@PathVariable("order_id") String order_id) {
JSONObject jsonObject = new JSONObject();
logger.info("整合订单信息");
ProductOrder productOrder = new ProductOrder()
.setProductOrder_id(Integer.valueOf(order_id))
.setProductOrder_status((byte) 2)
.setProductOrder_delivery_date(new Date());
logger.info("更新订单信息,订单ID值为:{}", order_id);
boolean yn = productOrderService.update(productOrder);
if (yn) {
logger.info("更新成功!");
jsonObject.put("success", true);
} else {
logger.info("更新失败!事务回滚");
* @throws ParseException 转换异常
*/
@RequestMapping(value = "admin/home", method = RequestMethod.GET)
public String goToPageByAjax(HttpSession session, Map<String, Object> map) throws ParseException {
logger.info("获取管理员信息");
Object adminId = checkAdmin(session);
if (adminId == null) {
return "admin/include/loginMessage";
}
Admin admin = adminService.get(null, Integer.parseInt(adminId.toString()));
map.put("admin", admin);
logger.info("获取统计信息");
Integer productTotal = productService.getTotal(null, new Byte[]{0, 2});
Integer userTotal = userService.getTotal(null);
Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3});
logger.info("获取图表信息");
map.put("jsonObject", getChartData(null, null,7));
logger.info("获取图表信息");
map.put("jsonObject", getChartData(null,null,7));
map.put("productTotal", productTotal);
map.put("userTotal", userTotal);
map.put("orderTotal", orderTotal);
logger.info("转到后台管理-主页-ajax方式");
return "admin/homeManagePage";
}
/**
* 按日期查询图表数据(ajax方式)
* @param beginDate 开始日期
* @param endDate 结束日期
* @return 响应数据
* @throws ParseException 转换异常
*/
@ResponseBody
@RequestMapping(value = "admin/home/charts", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String getChartDataByDate(@RequestParam(required = false) String beginDate, @RequestParam(required = false) String endDate) throws ParseException {
if (beginDate != null && endDate != null) {
//转换日期格式
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
return getChartData(simpleDateFormat.parse(beginDate), simpleDateFormat.parse(endDate),7).toJSONString();
} else {
return getChartData(null, null,7).toJSONString();
}
}
/**
* 按日期获取图表数据
* @param beginDate 开始日期
* @param endDate 结束日期
* @param days 天数
* @return 图表数据的JSON对象
* @throws ParseException 转换异常
case "order_post":
order_post = URLDecoder.decode(cookieValue, "UTF-8");
break;
case "order_receiver":
order_receiver = URLDecoder.decode(cookieValue, "UTF-8");
break;
case "order_phone":
order_phone = URLDecoder.decode(cookieValue, "UTF-8");
break;
case "detailsAddress":
detailsAddress = URLDecoder.decode(cookieValue, "UTF-8");
break;
}
}
}
logger.info("获取省份信息");
List<Address> addressList = addressService.getRoot();
logger.info("获取addressId为{}的市级地址信息", addressId);
List<Address> cityAddress = addressService.getList(null, addressId);
logger.info("获取cityAddressId为{}的区级地址信息", cityAddressId);
List<Address> districtAddress = addressService.getList(null, cityAddressId);
map.put("orderItemList", orderItemList);
map.put("addressList", addressList);
map.put("cityList", cityAddress);
map.put("districtList", districtAddress);
map.put("orderTotalPrice", orderTotalPrice);
map.put("addressId", addressId);
map.put("cityAddressId", cityAddressId);
map.put("districtAddressId", districtAddressId);
map.put("order_post", order_post);
map.put("order_receiver", order_receiver);
map.put("order_phone", order_phone);
map.put("detailsAddress", detailsAddress);
logger.info("转到前台天猫-订单建立页");
return "fore/productBuyPage";
}
//转到前台天猫-订单支付页