基于javaweb+mysql的springboot仿天猫商城系统(java+jsp+springboot+ssm+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot仿天猫商城系统(java+jsp+springboot+ssm+mysql+maven)
一、项目介绍:
迷你天猫商城是一个基于SSM框架的综合性B2C电商平台,需求设计主要参考天猫商城的购物流程:用户从注册开始,到完成登录,浏览商品,加入购物车,进行下单,确认收货,评价等一系列操作。 作为模拟天猫商城系统的核心组成部分之一,采用SSM框架的天猫数据管理后台包含商品管理,订单管理,类别管理,用户管理和交易额统计等模块,实现了对整个商城的一站式管理和维护。
二、项目运行
环境配置: Jdk1.8 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP + Springboot + SpringMVC + Spring +MyBatis + css + JavaScript + JQuery + Ajax + layui+ maven等等。
/**
* 后台管理-账户页
*/
@Controller
public class AccountController extends BaseController{
@Autowired
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");
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();
}
//按产品ID加载产品属性列表-ajax
@Deprecated
@ResponseBody
@RequestMapping(value = "property/{pid}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String loadProductPropertyList(@PathVariable("pid") String pid/*产品ID*/) {
logger.info("获取产品ID");
Integer product_id = Integer.parseInt(pid);
logger.info("获取产品详情-属性值信息");
Product product = new Product();
product.setProduct_id(product_id);
List<PropertyValue> propertyValueList = propertyValueService.getList(new PropertyValue().setPropertyValue_product(product), null);
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);
pageUtil.setTotal(productOrderCount);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
}
/**
* 后台管理-分类页
*/
@Controller
public class CategoryController extends BaseController {
@Autowired
private CategoryService categoryService;
@Autowired
private LastIDService lastIDService;
@Autowired
private PropertyService propertyService;
//转到后台管理-分类页-ajax
@RequestMapping(value = "admin/category", method = RequestMethod.GET)
public String goToPage(HttpSession session, Map<String, Object> map) {
}
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());
//最后一级地址
addressStack.push(address.getAddress_name() + " ");
//如果不是第一级地址
while (!address.getAddress_areaId().equals(address.getAddress_regionId().getAddress_areaId())) {
address = addressService.get(address.getAddress_regionId().getAddress_areaId());
addressStack.push(address.getAddress_name() + " ");
}
StringBuilder builder = new StringBuilder();
while (!addressStack.empty()) {
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("订单状态不正确,返回订单列表页");
}
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()
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();
logger.info("检查用户是否登录");
Object userId = checkUser(session);
if (userId == null) {
object.put("success", false);
object.put("url", "/login");
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");
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);
//转到前台天猫-订单完成页
@RequestMapping(value = "order/success/{order_code}", method = RequestMethod.GET)
public String goToOrderSuccessPage(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() != 3) {
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";
}
logger.info("获取订单中订单项数量");
Integer count = productOrderItemService.getTotalByOrderId(order.getProductOrder_id());
Product product = null;
if (count == 1) {
logger.info("获取订单中的唯一订单项");
ProductOrderItem productOrderItem = productOrderItemService.getListByOrderId(order.getProductOrder_id(), new PageUtil(0, 1)).get(0);
if (productOrderItem != null) {
logger.info("获取订单项评论数量");
count = reviewService.getTotalByOrderItemId(productOrderItem.getProductOrderItem_id());
if (count == 0) {
logger.info("获取订单项产品信息");
product = productService.get(productOrderItem.getProductOrderItem_product().getProduct_id());
if (product != null) {
product.setSingleProductImageList(productImageService.getList(product.getProduct_id(), (byte) 0, new PageUtil(0, 1)));
}
@RequestMapping(value = "admin/order/{index}/{count}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String getOrderBySearch(@RequestParam(required = false) String productOrder_code/* 订单号 */,
@RequestParam(required = false) String productOrder_post/* 订单邮政编码 */,
@RequestParam(required = false) Byte[] productOrder_status_array/* 订单状态数组 */,
@RequestParam(required = false) String orderBy/* 排序字段 */,
@RequestParam(required = false,defaultValue = "true") Boolean isDesc/* 是否倒序 */,
@PathVariable Integer index/* 页数 */,
@PathVariable Integer count/* 行数 */){
//移除不必要条件
if (productOrder_status_array != null && (productOrder_status_array.length <= 0 || productOrder_status_array.length >=5)) {
productOrder_status_array = null;
}
if (productOrder_code != null){
productOrder_code = "".equals(productOrder_code) ? null : productOrder_code;
}
if(productOrder_post != null){
productOrder_post = "".equals(productOrder_post) ? null : productOrder_post;
}
if (orderBy != null && "".equals(orderBy)) {
orderBy = null;
}
//封装查询条件
ProductOrder productOrder = new ProductOrder()
.setProductOrder_code(productOrder_code)
.setProductOrder_post(productOrder_post);
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<ProductOrder> productOrderList = productOrderService.getList(productOrder, productOrder_status_array, orderUtil, pageUtil);
object.put("productOrderList", JSONArray.parseArray(JSON.toJSONString(productOrderList)));
logger.info("按条件获取订单总数量");
Integer productOrderCount = productOrderService.getTotal(productOrder, productOrder_status_array);
object.put("productOrderCount", productOrderCount);
logger.info("获取分页信息");
pageUtil.setTotal(productOrderCount);
object.put("totalPage", pageUtil.getTotalPage());
object.put("pageUtil", pageUtil);
return object.toJSONString();
}
}
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,
HttpSession session, HttpServletRequest request,
@RequestParam(required = false) Integer[] order_item_list) throws UnsupportedEncodingException {
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";
}
if (order_item_list == null || order_item_list.length == 0) {
logger.warn("用户订单项数组不存在,回到购物车页");
return "redirect:/cart";
}
}
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("propertyList", JSONArray.parseArray(JSON.toJSONString(propertyList)));
return jsonObject.toJSONString();
}
//加载猜你喜欢列表-ajax
@ResponseBody
@RequestMapping(value = "guess/{cid}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
public String guessYouLike(@PathVariable("cid") Integer cid, @RequestParam Integer guessNumber) {
logger.info("获取猜你喜欢列表");
Integer total = productService.getTotal(new Product().setProduct_category(new Category().setCategory_id(cid)), new Byte[]{0, 2});
logger.info("分类ID为{}的产品总数为{}条", cid, total);
//生成随机数
int i = new Random().nextInt(total);
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
}
while (i == guessNumber) {
i = new Random().nextInt(total);
if (i + 2 >= total) {
i = total - 3;
}
if (i < 0) {
i = 0;
break;
}
}
logger.info("guessNumber值为{},新guessNumber值为{}", guessNumber, i);
List<Product> loveProductList = productService.getList(new Product().setProduct_category(new Category().setCategory_id(cid)), 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)));
}
}
JSONObject jsonObject = new JSONObject();
logger.info("获取数据成功!");
jsonObject.put("success", true);
jsonObject.put("loveProductList", JSONArray.parseArray(JSON.toJSONString(loveProductList)));
jsonObject.put("guessNumber", i);
return jsonObject.toJSONString();
}
}
Object o = session.getAttribute("userId");
if (o != null) {
session.removeAttribute("userId");
session.invalidate();
logger.info("登录信息已清除,返回用户登录页");
}
return "redirect:/login";
}
}
@Controller
public class ForeAddressController extends BaseController {
@Autowired
private AddressService addressService;
//根据address_areaId获取地址信息-ajax
@ResponseBody
@RequestMapping(value = "address/{areaId}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
protected String getAddressByAreaId(@PathVariable String areaId) {
JSONObject object = new JSONObject();
logger.info("获取AreaId为{}的地址信息");
List<Address> addressList = addressService.getList(null, areaId);
if (addressList == null || addressList.size() <= 0) {
object.put("success", false);
return object.toJSONString();
}
}
//创建订单项-购物车-ajax
@ResponseBody
@RequestMapping(value = "orderItem/create/{product_id}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
public String createOrderItem(@PathVariable("product_id") Integer product_id,
@RequestParam(required = false, defaultValue = "1") Short product_number,
HttpSession session,
HttpServletRequest request) {
JSONObject object = new JSONObject();
logger.info("检查用户是否登录");
Object userId = checkUser(session);
if (userId == null) {
object.put("url", "/login");
object.put("success", false);
return object.toJSONString();
}
logger.info("通过产品ID获取产品信息:{}", product_id);
Product product = productService.get(product_id);
if (product == null) {
object.put("url", "/login");
object.put("success", false);
return object.toJSONString();
}
ProductOrderItem productOrderItem = new ProductOrderItem();
logger.info("检查用户的购物车项");
List<ProductOrderItem> orderItemList = productOrderItemService.getListByUserId(Integer.valueOf(userId.toString()), null);
for (ProductOrderItem orderItem : orderItemList) {
if (orderItem.getProductOrderItem_product().getProduct_id().equals(product_id)) {
logger.info("找到已有的产品,进行数量追加");
int number = orderItem.getProductOrderItem_number();
number += 1;
productOrderItem.setProductOrderItem_id(orderItem.getProductOrderItem_id());
productOrderItem.setProductOrderItem_number((short) number);
productOrderItem.setProductOrderItem_price(number * product.getProduct_sale_price());
boolean yn = productOrderItemService.update(productOrderItem);
if (yn) {
object.put("success", true);
} else {
object.put("success", false);
}
return object.toJSONString();
JSONObject object = new JSONObject();
if(admin == null){
logger.info("登录验证失败");
object.put("success",false);
} else {
logger.info("登录验证成功,管理员ID传入会话");
session.setAttribute("adminId",admin);
object.put("success",true);
}
return object.toJSONString();
}
//获取管理员头像路径-ajax
@ResponseBody
@RequestMapping(value = "admin/login/profile_picture",method = RequestMethod.GET,produces = "application/json;charset=utf-8")
public String getAdminProfilePicture(@RequestParam String username){
logger.info("根据用户名获取管理员头像路径");
Admin admin = adminService.get(username,null);
JSONObject object = new JSONObject();
if(admin == null){
logger.info("未找到头像路径");
object.put("success",false);
} else {
logger.info("成功获取头像路径");
object.put("success",true);
object.put("srcString",admin.getAdmin_profile_picture_src());
}
return object.toJSONString();
}
}
@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("检查用户是否登录");
Object userId = checkUser(session);
if (userId != null) {
logger.info("获取用户信息");
User user = userService.get(Integer.parseInt(userId.toString()));
map.put("user", user);
} else {
return "redirect:/login";
}
logger.info("创建用户对象");
if (user_profile_picture_src != null && "".equals(user_profile_picture_src)) {
user_profile_picture_src = null;
}
User userUpdate = new User()
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_id(Integer.valueOf(key));
propertyValueList.add(propertyValue);
}
logger.info("共有{}条需要更新的产品属性数据", propertyValueList.size());
for (int i = 0; i < propertyValueList.size(); i++) {
logger.info("正在更新第{}条,共{}条", i + 1, propertyValueList.size());
yn = propertyValueService.update(propertyValueList.get(i));
if (yn) {
logger.info("产品属性更新成功!");
} else {
logger.warn("产品属性更新失败!事务回滚");
jsonObject.put("success", false);
throw new RuntimeException();
}
}
}
if (propertyDeleteList != null && propertyDeleteList.length > 0) {
logger.info("整合产品子信息-需要删除的产品属性");
logger.info("共有{}条需要删除的产品属性数据", propertyDeleteList.length);
yn = propertyValueService.deleteList(propertyDeleteList);
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) {
productImageList.add(new ProductImage()
.setProductImage_type((byte) 0)
.setProductImage_src(imageName.substring(imageName.lastIndexOf("/") + 1))
.setProductImage_product(product)
);
}
logger.info("共有{}条产品预览图片数据", productImageList.size());
yn = productImageService.addList(productImageList);
if (yn) {
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() != 2) {
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);
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) {