Java女装商城系统的实现流程

网友投稿 297 2022-11-20

Java女装商城系统的实现流程

一、项目简述功能

javaweb 网上商城系统,前台+后台管理,用户注册,登录,上哦展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等.

二、项目运行

环境配置: Jdk1.8 + Tomcats . 5 + mysql + Eclispe ( IntelliJ IDEA ,Eclispe , MyEclispe , sts 都支持)

项目技术: jsP + Spring + SpringMVC + MyBatis + html + css + javascript + jquery + Ajax + layui + maven 等等。

后台管理平台登录代码:

/**

* 后台管理-主页

*/

@Controller

public class AdminHomeController extends BaseController {

@Resource(name = "adminService")

private AdminService adminService;

@Resource(name = "productOrderService")

private ProductOrderService productOrderService;

@Resource(name = "productService")

private ProductService productService;

@Resource(name = "userService")

private UserService userService;

/**

* 转到后台管理-主页

* @param session session对象

* @param map 前台传入的Map

* @return 响应数据

* @throws ParseException 转换异常

*/

@RequestMapping(value = "admin", method = RequestMethod.GET)

public String goToPage(HttpSession session, Map map) throws ParseException {

logger.info("获取管理员信息");

Object adminId = checkAdmin(session);

if (adminId == null) {

return "redirect:/admin/login";

}

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));

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 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 转换异常

*/

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 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;

//循环订单集合数据的结果集

for(int j = 0; j < orderGroupList.size(); j++){

OrderGroup orderGroup = orderGroupList.get(j);

//如果该订单日期与当前日期一致

if(orderGroup.getProductOrder_pay_date().equals(formatDate)){

//从结果集中移除数据

orderGroupList.remove(j);

//根据订单状态将统计结果存入对应的订单状态数组中

switch (orderGroup.getProductOrder_status()) {

case 0:

//未付款订单

orderUnpaidArray[i] = orderGroup.getProductOrder_count();

break;

case 1:

//未发货订单

orderNotShippedArray[i] = orderGroup.getProductOrder_count();

break;

case 2:

//未确认订单

orderUnconfirmedArray[i] = orderGroup.getProductOrder_count();

break;

case 3:

//交易成功订单

orderSuccessArray[i] = orderGroup.getProductOrder_count();

break;

}

//累加当前日期的订单总数

orderCount += orderGroup.getProductOrder_count();

}

}

//将统计的订单总数存入总交易订单数统计数组

orderTotalArray[i] = orderCount;

}

logger.info("返回结果集map");

jsonObject.put("orderTotalArray", orderTotalArray);

jsonObject.put("orderUnpaidArray", orderUnpaidArray);

jsonObject.put("orderNotShippedArray", orderNotShippedArray);

jsonObject.put("orderUnconfirmedArray", orderUnconfirmedArray);

jsonObject.put("orderSuccessArray", orderSuccessArray);

jsonObject.put("dateStr",dateStr);

return jsonObject;

}

}

商品信息控制层:

/**

* @author yy

*/

@Controller

@RequestMapping("/admin")

public class NewBeeMallGoodsController {

@Resource

private NewBeeMallGoodsService newBeeMallGoodsService;

@Resource

private NewBeeMallCategoryService newBeeMallCategoryService;

@GetMapping("/goods")

public String goodsPage(HttpServletRequest request) {

request.setAttribute("path", "newbee_mall_goods");

return "admin/newbee_mall_goods";

}

@GetMapping("/goods/edit")

public String edit(HttpServletRequest request) {

request.setAttribute("path", "edit");

//查询所有的一级分类

List firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel());

if (!CollectionUtils.isEmpty(firstLevelCategories)) {

//查询一级分类列表中第一个实体的所有二级分类

List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel());

if (!CollectionUtils.isEmpty(secondLevelCategories)) {

//查询二级分类列表中第一个实体的所有三级分类

List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel());

request.setAttribute("firstLevelCategories", firstLevelCategories);

request.setAttribute("secondLevelCategories", secondLevelCategories);

request.setAttribute("thirdLevelCategories", thirdLevelCategories);

request.setAttribute("path", "goods-edit");

return "admin/newbee_mall_goods_edit";

}

}

return "error/error_5xx";

}

@GetMapping("/goods/edit/{goodsId}")

public String edit(HttpServletRequest request, @PathVariable("goodsId") Long goodsId) {

request.setAttribute("path", "edit");

NewBeeMallGoods newBeeMallGoods = newBeeMallGoodsService.getNewBeeMallGoodsById(goodsId);

if (newBeeMallGoods == null) {

return "error/error_400";

}

if (newBeeMallGoods.getGoodsCategoryId() > 0) {

if (newBeeMallGoods.getGoodsCategoryId() != null || newBeeMallGoods.getGoodsCategoryId() > 0) {

//有分类字段则查询相关分类数据返回给前端以供分类的三级联动显示

GoodsCategory currentGoodsCategory = newBeeMallCategoryService.getGoodsCategoryById(newBeeMallGoods.getGoodsCategoryId());

//商品表中存储的分类id字段为三级分类的id,不为三级分类则是错误数据

if (currentGoodsCategory != null && currentGoodsCategory.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()) {

//查询所有的一级分类

List firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel());

//根据parentId查询当前parentId下所有的三级分类

List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(currentGoodsCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel());

//查询当前三级分类的父级二级分类

GoodsCategory secondCategory = newBeeMallCategoryService.getGoodsCategoryById(currentGoodsCategory.getParentId());

if (secondCategory != null) {

//根据parentId查询当前parentId下所有的二级分类

List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel());

//查询当前二级分类的父级一级分类

GoodsCategory firestCategory = newBeeMallCategoryService.getGoodsCategoryById(secondCategory.getParentId());

if (firestCategory != null) {

//所有分类数据都得到之后放到request对象中供前端读取

request.setAttribute("firstLevelCategories", firstLevelCategories);

request.setAttribute("secondLevelCategories", secondLevelCategories);

request.setAttribute("thirdLevelCategories", thirdLevelCategories);

request.setAttribute("firstLevelCategoryId", firestCategory.getCategoryId());

request.setAttribute("secondLevelCategoryId", secondCategory.getCategoryId());

request.setAttribute("thirdLevelCategoryId", currentGoodsCategory.getCategoryId());

}

}

}

}

}

if (newBeeMallGoods.getGoodsCategoryId() == 0) {

//查询所有的一级分类

List firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel());

if (!CollectionUtils.isEmpty(firstLevelCategories)) {

//查询一级分类列表中第一个实体的所有二级分类

List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel());

if (!CollectionUtils.isEmpty(secondLevelCategories)) {

//查询二级分类列表中第一个实体的所有三级分类

List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel());

request.setAttribute("firstLevelCategories", firstLevelCategories);

request.setAttribute("secondLevelCategories", secondLevelCategories);

request.setAttribute("thirdLevelCategories", thirdLevelCategories);

}

}

}

request.setAttribute("goods", newBeeMallGoods);

request.setAttribute("path", "goods-edit");

return "admin/newbee_mall_goods_edit";

}

/**

* 列表

*/

@RequestMapping(value = "/goods/list", method = RequestMethod.GET)

@ResponseBody

public Result list(@RequestParam Map params) {

if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {

return ResultGenerator.genFailResult("参数异常!");

}

PageQueryUtil pageUtil = new PageQueryUtil(params);

return ResultGenerator.genSuccessResult(newBeeMallGoodsService.getNewBeeMallGoodsPage(pageUtil));

}

/**

* 添加

*/

@RequestMapping(value = "/goods/save", method = RequestMethod.POST)

@ResponseBody

public Result save(@RequestBody NewBeeMallGoods newBeeMallGoods) {

if (StringUtils.isEmpty(newBeeMallGoods.getGoodsName())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsIntro())

|| StringUtils.isEmpty(newBeeMallGoods.getTag())

|| Objects.isNull(newBeeMallGoods.getOriginalPrice())

|| Objects.isNull(newBeeMallGoods.getGoodsCategoryId())

|| Objects.isNull(newBeeMallGoods.getSellingPrice())

|| Objects.isNull(newBeeMallGoods.getStockNum())

|| Objects.isNull(newBeeMallGoods.getGoodsSellStatus())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsCoverImg())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsDetailContent())) {

return ResultGenerator.genFailResult("参数异常!");

}

String result = newBeeMallGoodsService.saveNewBeeMallGoods(newBeeMallGoods);

if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {

return ResultGenerator.genSuccessResult();

} else {

return ResultGenerator.genFailResult(result);

}

}

/**

* 修改

*/

@RequestMapping(value = "/goods/update", method = RequestMethod.POST)

@ResponseBody

public Result update(@RequestBody NewBeeMallGoods newBeeMallGoods) {

if (Objects.isNull(newBeeMallGoods.getGoodsId())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsName())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsIntro())

|| StringUtils.isEmpty(newBeeMallGoods.getTag())

|| Objects.isNull(newBeeMallGoods.getOriginalPrice())

|| Objects.isNull(newBeeMallGoods.getSellingPrice())

|| Objects.isNull(newBeeMallGoods.getGoodsCategoryId())

|| Objects.isNull(newBeeMallGoods.getStockNum())

|| Objects.isNull(newBeeMallGoods.getGoodsSellStatus())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsCoverImg())

|| StringUtils.isEmpty(newBeeMallGoods.getGoodsDetailContent())) {

return ResultGenerator.genFailResult("参数异常!");

}

String result = newBeeMallGoodsService.updateNewBeeMallGoods(newBeeMallGoods);

if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {

return ResultGenerator.genSuccessResult();

} else {

return ResultGenerator.genFailResult(result);

}

}

/**

* 详情

*/

@GetMapping("/goods/info/{id}")

@ResponseBody

public Result info(@PathVariable("id") Long id) {

NewBeeMallGoods goods = newBeeMallGoodsService.getNewBeeMallGoodsById(id);

if (goods == null) {

return ResultGenerator.genFailResult(ServiceResultEnum.DATA_NOT_EXIST.getResult());

}

return ResultGenerator.genSuccessResult(goods);

}

/**

* 批量修改销售状态

*/

@RequestMapping(value = "/goods/status/{sellStatus}", method = RequestMethod.PUT)

@ResponseBody

public Result delete(@RequestBody Long[] ids, @PathVariable("sellStatus") int sellStatus) {

if (ids.length < 1) {

return ResultGenerator.genFailResult("参数异常!");

}

if (sellStatus != Constants.SELL_STATUS_UP && sellStatus != Constants.SELL_STATUS_DOWN) {

return ResultGenerator.genFailResult("状态异常!");

}

if (newBeeMallGoodsService.batchUpdateSellStatus(ids, sellStatus)) {

return ResultGenerator.genSuccessResult();

} else {

return ResultGenerator.genFailResult("修改失败");

}

}

}

商品分类控制器:

/**

* @author yy

*/

@Controller

@RequestMapping("/admin")

public class NewBeeMallGoodsCategoryController {

@Resource

private NewBeeMallCategoryService newBeeMallCategoryService;

@GetMapping("/categories")

public String categoriesPage(HttpServletRequest request, @RequestParam("categoryLevel") Byte categoryLevel, @RequestParam("parentId") Long parentId, @RequestParam("backParentId") Long backParentId) {

if (categoryLevel == null || categoryLevel < 1 || categoryLevel > 3) {

return "error/error_5xx";

}

request.setAttribute("path", "newbee_mall_category");

request.setAttribute("parentId", parentId);

request.setAttribute("backParentId", backParentId);

request.setAttribute("categoryLevel", categoryLevel);

return "admin/newbee_mall_category";

}

/**

* 列表

*/

@RequestMapping(value = "/categories/list", method = RequestMethod.GET)

@ResponseBody

public Result list(@RequestParam Map params) {

if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {

return ResultGenerator.genFailResult("参数异常!");

}

PageQueryUtil pageUtil = new PageQueryUtil(params);

return ResultGenerator.genSuccessResult(newBeeMallCategoryService.getCategorisPage(pageUtil));

}

/**

* 列表

*/

@RequestMapping(value = "/categories/listForSelect", method = RequestMethod.GET)

@ResponseBody

public Result listForSelect(@RequestParam("categoryId") Long categoryId) {

if (categoryId == null || categoryId < 1) {

return ResultGenerator.genFailResult("缺少参数!");

}

GoodsCategory category = newBeeMallCategoryService.getGoodsCategoryById(categoryId);

//既不是一级分类也不是二级分类则为不返回数据

if (category == null || category.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()) {

return ResultGenerator.genFailResult("参数异常!");

}

Map categoryResult = new HashMap(2);

if (category.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()) {

//如果是一级分类则返回当前一级分类下的所有二级分类,以及二级分类列表中第一条数据下的所有三级分类列表

//查询一级分类列表中第一个实体的所有二级分类

List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(categoryId), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel());

if (!CollectionUtils.isEmpty(secondLevelCategories)) {

//查询二级分类列表中第一个实体的所有三级分类

List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel());

categoryResult.put("secondLevelCategories", secondLevelCategories);

categoryResult.put("thirdLevelCategories", thirdLevelCategories);

}

}

if (category.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()) {

//如果是二级分类则返回当前分类下的所有三级分类列表

List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(categoryId), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel());

categoryResult.put("thirdLevelCategories", thirdLevelCategories);

}

return ResultGenerator.genSuccessResult(categoryResult);

}

/**

* 添加

*/

@RequestMapping(value = "/categories/save", method = RequestMethod.POST)

@ResponseBody

public Result save(@RequestBody GoodsCategory goodsCategory) {

if (Objects.isNull(goodsCategory.getCategoryLevel())

|| StringUtils.isEmpty(goodsCategory.getCategoryName())

|| Objects.isNull(goodsCategory.getParentId())

|| Objects.isNull(goodsCategory.getCategoryRank())) {

return ResultGenerator.genFailResult("参数异常!");

}

String result = newBeeMallCategoryService.saveCategory(goodsCategory);

if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {

return ResultGenerator.genSuccessResult();

} else {

return ResultGenerator.genFailResult(result);

}

}

/**

* 修改

*/

@RequestMapping(value = "/categories/update", method = RequestMethod.POST)

@ResponseBody

public Result update(@RequestBody GoodsCategory goodsCategory) {

if (Objects.isNull(goodsCategory.getCategoryId())

|| Objects.isNull(goodsCategory.getCategoryLevel())

|| StringUtils.isEmpty(goodsCategory.getCategoryName())

|| Objects.isNull(goodsCategory.getParentId())

|| Objects.isNull(goodsCategory.getCategoryRank())) {

return ResultGenerator.genFailResult("参数异常!");

}

String result = newBeeMallCategoryService.updateGoodsCategory(goodsCategory);

if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {

return ResultGenerator.genSuccessResult();

} else {

return ResultGenerator.genFailResult(result);

}

}

/**

* 详情

*/

@GetMapping("/categories/info/{id}")

@ResponseBody

public Result info(@PathVariable("id") Long id) {

GoodsCategory goodsCategory = newBeeMallCategoryService.getGoodsCategoryById(id);

if (goodsCategory == null) {

return ResultGenerator.genFailResult("未查询到数据");

}

return ResultGenerator.genSuccessResult(goodsCategory);

}

/**

* 分类删除

*/

@RequestMapping(value = "/categories/delete", method = RequestMethod.POST)

@ResponseBody

public Result delete(@RequestBody Integer[] ids) {

if (ids.length < 1) {

return ResultGenerator.genFailResult("参数异常!");

}

if (newBeeMallCategoryService.deleteBatch(ids)) {

return ResultGenerator.genSuccessResult();

} else {

return ResultGenerator.genFailResult("删除失败");

}

}

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:6位LED动态显示接口电路
下一篇:【ElasticSearch面试】10道不得不会的ElasticSearch面试题
相关文章

 发表评论

暂时没有评论,来抢沙发吧~