基于javaweb和mysql的springboot化妆品商城系统(java+springboot+ssm+mysql+jsp+maven)
·
基于javaweb和mysql的springboot化妆品商城系统(java+springboot+ssm+mysql+jsp+maven)
私信源码获取及调试交流
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot化妆品商城系统(java+springboot+ssm+mysql+jsp+maven)
后台管理:
admin 123456
前台:
user1 123456
user2 123456
user3 123456
前台用户:
注册、登录、个人信息修改、商品浏览、商品查询、详情查询、立即购买、购物车管理、结算支付、订单查看、收货评价等等
后台管理员:
查询统计、产品管理、分类管理、用户管理、订单管理及发货、评价管理、信息修改等等。
orderItemTotal = productOrderItemService.getTotalByUserId(Integer.valueOf(userId.toString()));
logger.info("获取用户购物车内的商品信息");
for (ProductOrderItem orderItem : orderItemList) {
Integer product_id = orderItem.getProductOrderItem_product().getProduct_id();
Product product = productService.get(product_id);
product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, null));
product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
orderItem.setProductOrderItem_product(product);
}
}
map.put("orderItemList", orderItemList);
map.put("orderItemTotal", orderItemTotal);
logger.info("转到前台天猫-购物车页");
return "fore/productBuyCarPage";
}
//更新订单信息为已支付,待发货-ajax
@ResponseBody
@RequestMapping(value = "order/pay/{order_code}", method = RequestMethod.PUT)
public String orderPay(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("订单状态不正确,返回订单列表页");
object.put("success", false);
object.put("url", "/order/0/10");
return object.toJSONString();
}
logger.info("验证用户与订单是否一致");
if (order.getProductOrder_user().getUser_id() != Integer.parseInt(userId.toString())) {
logger.warn("用户与订单信息不一致,返回订单列表页");
object.put("success", false);
map.put("districtAddressId", districtAddressId);
return "fore/userDetails";
} else {
return "redirect:/login";
}
}
//前台天猫-用户更换头像
@ResponseBody
@RequestMapping(value = "user/uploadUserHeadImage", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
public String uploadUserHeadImage(@RequestParam MultipartFile file, HttpSession session
){
String originalFileName = file.getOriginalFilename();
logger.info("获取图片原始文件名:{}", originalFileName);
String extension = originalFileName.substring(originalFileName.lastIndexOf('.'));
String fileName = UUID.randomUUID() + extension;
String filePath = session.getServletContext().getRealPath("/") + "res/images/item/userProfilePicture/" + fileName;
logger.info("文件上传路径:{}", filePath);
JSONObject jsonObject = new JSONObject();
try {
logger.info("文件上传中...");
file.transferTo(new File(filePath));
logger.info("文件上传成功!");
jsonObject.put("success", true);
jsonObject.put("fileName", fileName);
} catch (IOException e) {
logger.warn("文件上传失败!");
e.printStackTrace();
jsonObject.put("success", false);
}
return jsonObject.toJSONString();
}
//前台天猫-用户详情更新
@RequestMapping(value="user/update",method=RequestMethod.POST,produces ="application/json;charset=utf-8")
public String userUpdate(HttpSession session, Map<String,Object> map,
@RequestParam(value = "user_nickname") String user_nickname /*用户昵称 */,
@RequestParam(value = "user_realname") String user_realname /*真实姓名*/,
@RequestParam(value = "user_gender") String user_gender /*用户性别*/,
@RequestParam(value = "user_birthday") String user_birthday /*用户生日*/,
@RequestParam(value = "user_address") String user_address /*用户所在地 */,
@RequestParam(value = "user_profile_picture_src", required = false)
String user_profile_picture_src /* 用户头像*/,
@RequestParam(value = "user_password") String user_password/* 用户密码 */
) throws ParseException, UnsupportedEncodingException {
);
logger.info("获取产品详情-分类信息对应的属性列表");
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;
}
}
}
map.put("propertyList",propertyList);
logger.info("获取分类列表");
List<Category> categoryList = categoryService.getList(null,null);
map.put("categoryList",categoryList);
logger.info("转到后台管理-产品详情页-ajax方式");
return "admin/include/productDetails";
}
//转到后台管理-产品添加页-ajax
@RequestMapping(value = "admin/product/new",method = RequestMethod.GET)
public String goToAddPage(HttpSession session,Map<String, Object> map){
logger.info("获取分类列表");
List<Category> categoryList = categoryService.getList(null,null);
map.put("categoryList",categoryList);
logger.info("获取第一个分类信息对应的属性列表");
List<Property> propertyList = propertyService.getList(
new Property().setProperty_category(categoryList.get(0)),null
);
map.put("propertyList",propertyList);
logger.info("转到后台管理-产品添加页-ajax方式");
return "admin/include/productDetails";
}
//添加产品信息-ajax.
@ResponseBody
@RequestMapping(value = "admin/product", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
public String addProduct(@RequestParam String product_name/* 产品名称 */,
@RequestParam String product_title/* 产品标题 */,
@RequestParam Integer product_category_id/* 产品类型ID */,
@RequestParam Double product_sale_price/* 产品促销价 */,
@RequestParam Double product_price/* 产品原价 */,
@RequestParam Byte product_isEnabled/* 产品状态 */,
@RequestParam String propertyJson/* 产品属性JSON */,
@RequestParam Integer product_stock_count/* 产品库存 */,
* @param endDate 结束日期
* @param days 天数
* @return 图表数据的JSON对象
* @throws ParseException 转换异常
*/
private JSONObject getChartData(Date beginDate,Date endDate,int days) throws ParseException {
JSONObject jsonObject = new JSONObject();
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd", Locale.UK);
SimpleDateFormat time2 = new SimpleDateFormat("MM/dd", Locale.UK);
SimpleDateFormat timeSpecial = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
//如果没有指定开始和结束日期
if (beginDate == null || endDate == null) {
//指定一周前的日期为开始日期
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1-days);
beginDate = time.parse(time.format(cal.getTime()));
//指定当前日期为结束日期
cal = Calendar.getInstance();
endDate = cal.getTime();
} else {
beginDate = time.parse(time.format(beginDate));
endDate = timeSpecial.parse(time.format(endDate) + " 23:59:59");
}
logger.info("根据订单状态分类");
//未付款订单数统计数组
int[] orderUnpaidArray = new int[7];
//未发货订单数统计叔祖
int[] orderNotShippedArray = new int[7];
//未确认订单数统计数组
int[] orderUnconfirmedArray = new int[7];
//交易成功订单数统计数组
int[] orderSuccessArray = new int[7];
//总交易订单数统计数组
int[] orderTotalArray = new int[7];
logger.info("从数据库中获取统计的订单集合数据");
List<OrderGroup> orderGroupList = productOrderService.getTotalByDate(beginDate, endDate);
//初始化日期数组
JSONArray dateStr = new JSONArray(days);
//按指定的天数进行循环
for (int i = 0; i < days; i++) {
//格式化日期串(MM/dd)并放入日期数组中
Calendar cal = Calendar.getInstance();
cal.setTime(beginDate);
cal.add(Calendar.DATE, i);
String formatDate = time2.format(cal.getTime());
dateStr.add(formatDate);
//该天的订单总数
int orderCount = 0;
//循环订单集合数据的结果集
/**
* 转到后台管理-主页(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 {
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();
}
}
map.put("orderItem", productOrderItem);
}
map.put("product", product);
logger.info("转到前台天猫-订单完成页");
return "fore/orderSuccessPage";
}
//转到前台天猫-购物车页
@RequestMapping(value = "cart", method = RequestMethod.GET)
public String goToCartPage(Map<String, Object> map, HttpSession session) {
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("获取用户购物车信息");
List<ProductOrderItem> orderItemList = productOrderItemService.getListByUserId(Integer.valueOf(userId.toString()), null);
Integer orderItemTotal = 0;
if (orderItemList.size() > 0) {
logger.info("获取用户购物车的商品总数");
orderItemTotal = productOrderItemService.getTotalByUserId(Integer.valueOf(userId.toString()));
logger.info("获取用户购物车内的商品信息");
for (ProductOrderItem orderItem : orderItemList) {
Integer product_id = orderItem.getProductOrderItem_product().getProduct_id();
Product product = productService.get(product_id);
product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, null));
product.setProduct_category(categoryService.get(product.getProduct_category().getCategory_id()));
orderItem.setProductOrderItem_product(product);
}
}
map.put("orderItemList", orderItemList);
map.put("orderItemTotal", orderItemTotal);
logger.info("转到前台天猫-购物车页");
return "fore/productBuyCarPage";
}
//更新订单信息为已支付,待发货-ajax
@ResponseBody
@RequestMapping(value = "order/pay/{order_code}", method = RequestMethod.PUT)
public String orderPay(HttpSession session, @PathVariable("order_code") String order_code) {
JSONObject object = new JSONObject();
/**
* 登陆页
*/
@Controller
public class ForeLoginController extends BaseController {
@Resource(name = "userService")
private UserService userService;
//转到前台天猫-登录页
@RequestMapping(value = "login", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map) {
logger.info("转到前台天猫-登录页");
return "fore/loginPage";
}
@RequestMapping(value = "not", method = RequestMethod.GET)
public String not(HttpSession session, Map<String, Object> map) {
logger.info("转到cuwu页");
return "fore/not";
}
//登陆验证-ajax
@ResponseBody
@RequestMapping(value = "login/doLogin", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
public String checkLogin(HttpSession session, @RequestParam String username, @RequestParam String password) {
logger.info("用户验证登录");
User user = userService.login(username, password);
JSONObject jsonObject = new JSONObject();
if (user == null) {
logger.info("登录验证失败");
jsonObject.put("success", false);
} else {
logger.info("登录验证成功,用户ID传入会话");
session.setAttribute("userId", user.getUser_id());
jsonObject.put("success", true);
}
return jsonObject.toJSONString();
}
//退出当前账号
@RequestMapping(value = "login/logout", method = RequestMethod.GET)
public String logout(HttpSession session) {
Object o = session.getAttribute("userId");
builder.append(addressStack.pop());
}
logger.info("订单地址字符串:{}", builder);
order.setProductOrder_detail_address(builder.toString());
map.put("productOrder", order);
map.put("orderTotalPrice", orderTotalPrice);
logger.info("转到前台天猫-订单支付成功页");
return "fore/productPaySuccessPage";
}
//转到前台天猫-订单确认页
@RequestMapping(value = "order/confirm/{order_code}", method = RequestMethod.GET)
public String goToOrderConfirmPage(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() != 2) {
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));
double orderTotalPrice = 0.00;
if (order.getProductOrderItemList().size() == 1) {
logger.info("获取单订单项的产品信息");
ProductOrderItem productOrderItem = order.getProductOrderItemList().get(0);
Integer product_id = productOrderItem.getProductOrderItem_product().getProduct_id();
Product product = productService.get(product_id);
product.setSingleProductImageList(productImageService.getList(product_id, (byte) 0, new PageUtil(0, 1)));
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));
map.put("productTotal", productTotal);
map.put("userTotal", userTotal);
map.put("orderTotal", orderTotal);
logger.info("转到后台管理-主页");
return "admin/homePage";
}
/**
* 转到后台管理-主页(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 开始日期
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");
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);
List<ProductOrderItem> productOrderItemList = new ArrayList<>();
productOrderItemList.add(productOrderItem);
map.put("orderItemList", productOrderItemList);
map.put("addressList", addressList);
map.put("cityList", cityAddress);
map.put("districtList", districtAddress);
map.put("orderTotalPrice", productOrderItem.getProductOrderItem_price());
map.put("addressId", addressId);
map.put("cityAddressId", cityAddressId);
map.put("districtAddressId", districtAddressId);
map.put("order_post", order_post);
map.put("order_receiver", order_receiver);
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);
List<ProductOrderItem> productOrderItemList = new ArrayList<>();
productOrderItemList.add(productOrderItem);
map.put("orderItemList", productOrderItemList);
map.put("addressList", addressList);
map.put("cityList", cityAddress);
map.put("districtList", districtAddress);
map.put("orderTotalPrice", productOrderItem.getProductOrderItem_price());
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/create/byCart", method = RequestMethod.GET)
public String goToOrderConfirmPageByCart(Map<String, Object> map,
logger.info("转到后台管理-分类添加页-ajax方式");
return "admin/include/categoryDetails";
}
//添加产品类型信息-ajax
@ResponseBody
@RequestMapping(value = "admin/category", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
public String addCategory(@RequestParam String category_name/* 分类名称 */,
@RequestParam String category_image_src/* 分类图片路径 */) {
JSONObject jsonObject = new JSONObject();
logger.info("整合分类信息");
Category category = new Category()
.setCategory_name(category_name)
.setCategory_image_src(category_image_src.substring(category_image_src.lastIndexOf("/") + 1));
logger.info("添加分类信息");
boolean yn = categoryService.add(category);
if (yn) {
int category_id = lastIDService.selectLastID();
logger.info("添加成功!,新增分类的ID值为:{}", category_id);
jsonObject.put("success", true);
jsonObject.put("category_id", category_id);
} else {
jsonObject.put("success", false);
logger.warn("添加失败!事务回滚");
throw new RuntimeException();
}
return jsonObject.toJSONString();
}
//更新产品类型信息-ajax
@ResponseBody
@RequestMapping(value = "admin/category/{category_id}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
public String updateCategory(@RequestParam String category_name/* 分类名称 */,
@RequestParam String category_image_src/* 分类图片路径 */,
@PathVariable("category_id") Integer category_id/* 分类ID */) {
JSONObject jsonObject = new JSONObject();
logger.info("整合分类信息");
Category category = new Category()
.setCategory_id(category_id)
.setCategory_name(category_name)
.setCategory_image_src(category_image_src.substring(category_image_src.lastIndexOf("/") + 1));
logger.info("更新分类信息,分类ID值为:{}", category_id);
boolean yn = categoryService.update(category);
if (yn) {
user_name = "".equals(user_name) ? null : URLDecoder.decode(user_name, "UTF-8");
}
if (orderBy != null && "".equals(orderBy)) {
orderBy = null;
}
//封装查询条件
User user = new User()
.setUser_name(user_name)
.setUser_gender(gender);
OrderUtil orderUtil = null;
if (orderBy != null) {
logger.info("根据{}排序,是否倒序:{}",orderBy,isDesc);
orderUtil = new OrderUtil(orderBy, isDesc);
}
JSONObject object = new JSONObject();
logger.info("按条件获取第{}页的{}条用户", index + 1, count);
PageUtil pageUtil = new PageUtil(index, count);
List<User> userList = userService.getList(user, orderUtil, pageUtil);
object.put("userList", JSONArray.parseArray(JSON.toJSONString(userList)));
logger.info("按条件获取用户总数量");
Integer userCount = userService.getTotal(user);
object.put("userCount", userCount);
logger.info("获取分页信息");
pageUtil.setTotal(userCount);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
}
}
/**
* 后台管理-产品类型页
*/
@Controller
public class CategoryController extends BaseController {
@Resource(name = "categoryService")
private CategoryService categoryService;
@Resource(name = "lastIDService")
private LastIDService lastIDService;
@Resource(name = "propertyService")
private PropertyService propertyService;
//转到后台管理-产品类型页-ajax
@RequestMapping(value = "admin/category", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map) {
logger.info("获取前10条产品类型列表");
PageUtil pageUtil = new PageUtil(0, 10);
List<Category> categoryList = categoryService.getList(null, pageUtil);
map.put("categoryList", categoryList);
logger.info("获取产品类型总数量");
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() != 1) {
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));
double orderTotalPrice = 0.00;
if (order.getProductOrderItemList().size() == 1) {
logger.info("获取单订单项的产品信息");
ProductOrderItem productOrderItem = order.getProductOrderItemList().get(0);
// Product pro = pro.setProduct_id(productOrderItem.getProductOrderItem_product().getProduct_id());
Product pro = productService.get(productOrderItem.getProductOrderItem_product().getProduct_id());
System.out.println(pro.getProduct_stock_count());
System.out.println(productOrderItem.getProductOrderItem_number());
pro.setProduct_stock_count(pro.getProduct_stock_count()-productOrderItem.getProductOrderItem_number());
// 此处减库存
productService.update(pro);
orderTotalPrice = productOrderItem.getProductOrderItem_price();
} else {
for (ProductOrderItem productOrderItem : order.getProductOrderItemList()) {
Product pro = productService.get(productOrderItem.getProductOrderItem_product().getProduct_id());
System.out.println(pro.getProduct_stock_count());
System.out.println(productOrderItem.getProductOrderItem_number());
pro.setProduct_stock_count(pro.getProduct_stock_count()-productOrderItem.getProductOrderItem_number());
// 此处减库存
productService.update(pro);
orderTotalPrice += productOrderItem.getProductOrderItem_price();
}
}
logger.info("订单总金额为:{}元", orderTotalPrice);
logger.info("获取订单详情-地址信息");
Address address = addressService.get(order.getProductOrder_address().getAddress_areaId());
Stack<String> addressStack = new Stack<>();
//详细地址
addressStack.push(order.getProductOrder_detail_address());
for (String imageName : productDetailsImageList) {
productImageList.add(new ProductImage()
.setProductImage_type((byte) 1)
.setProductImage_src(imageName.substring(imageName.lastIndexOf("/") + 1))
.setProductImage_product(new Product().setProduct_id(product_id))
);
}
logger.info("共有{}条产品详情图片数据", productImageList.size());
yn = productImageService.addList(productImageList);
if (yn) {
logger.info("产品详情图片添加成功!");
} else {
logger.warn("产品详情图片添加失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
logger.info("产品信息及其子信息添加成功!");
jsonObject.put("success", true);
jsonObject.put("product_id", product_id);
return jsonObject.toJSONString();
}
//更新产品信息-ajax
@ResponseBody
@RequestMapping(value = "admin/product/{product_id}", method = RequestMethod.PUT, produces = "application/json;charset=utf-8")
public String updateProduct(@RequestParam String product_name/* 产品名称 */,
@RequestParam String product_title/* 产品标题 */,
@RequestParam Integer product_category_id/* 产品类型ID */,
@RequestParam Double product_sale_price/* 产品促销价 */,
@RequestParam Double product_price/* 产品原价 */,
@RequestParam Byte product_isEnabled/* 产品状态 */,
@RequestParam String propertyAddJson/* 产品添加属性JSON */,
@RequestParam String propertyUpdateJson/* 产品更新属性JSON */,
@RequestParam Integer product_stock_count/* 产品库存 */,
@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());
product.setProduct_stock_count(product_stock_count);
logger.info("更新产品信息,产品ID值为:{}", product_id);
} else {
return getChartData(null, null,7).toJSONString();
}
}
/**
* 按日期获取图表数据
* @param beginDate 开始日期
* @param endDate 结束日期
* @param days 天数
* @return 图表数据的JSON对象
* @throws ParseException 转换异常
*/
private JSONObject getChartData(Date beginDate,Date endDate,int days) throws ParseException {
JSONObject jsonObject = new JSONObject();
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd", Locale.UK);
SimpleDateFormat time2 = new SimpleDateFormat("MM/dd", Locale.UK);
SimpleDateFormat timeSpecial = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK);
//如果没有指定开始和结束日期
if (beginDate == null || endDate == null) {
//指定一周前的日期为开始日期
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1-days);
beginDate = time.parse(time.format(cal.getTime()));
//指定当前日期为结束日期
cal = Calendar.getInstance();
endDate = cal.getTime();
} else {
beginDate = time.parse(time.format(beginDate));
endDate = timeSpecial.parse(time.format(endDate) + " 23:59:59");
}
logger.info("根据订单状态分类");
//未付款订单数统计数组
int[] orderUnpaidArray = new int[7];
//未发货订单数统计叔祖
int[] orderNotShippedArray = new int[7];
//未确认订单数统计数组
int[] orderUnconfirmedArray = new int[7];
//交易成功订单数统计数组
int[] orderSuccessArray = new int[7];
//总交易订单数统计数组
int[] orderTotalArray = new int[7];
logger.info("从数据库中获取统计的订单集合数据");
List<OrderGroup> orderGroupList = productOrderService.getTotalByDate(beginDate, endDate);
//初始化日期数组
JSONArray dateStr = new JSONArray(days);






更多推荐


所有评论(0)