第七篇 Scrum冲刺博客
第七篇 Scrum冲刺博客
目录
Part one 作业地址
这个作业属于哪个课程 | 软件工程 |
---|---|
作业要求 | 第七篇 Scrum冲刺博客 |
作业目标 | 团队集体协作完成项目开发,促进彼此间的交流 |
Part two 站立式会议
1.1 微信会议照片
注:这次开会主要还是讨论昨天个人的进度问题以及做任务时候遇到的困难,然后大家一起解决。
1.2成员工作情况
成员 | 昨天已完成的工作 | 今天计划完成的工作 | 工作中遇到的困难 |
---|---|---|---|
张天 | 做好接下来优化的计划 | 基本完成项目 | 商城的运行依然出现一些问题 |
黄炜恒 | 商家入驻环境优化好了 | 实现上架入驻模式的规则 | 商家入驻规则已经基本考虑完毕 |
黄浩捷 | 完成商城按钮轮转界面 | 优化商品的显示界面 | 商城界面仍然乱码 |
陈伟升 | 商城跳转支付界面 | 支付模块 | 支付模块的代码有些杂乱 |
曾广宁 | 整理商城架构 | 完成设计购物车的整体架构 | 购物车排列依然不美观 |
曾春华 | 查阅相关资料 | 构思商品的整体架构 | 商品名命名还是差了许多 |
Part three 项目燃尽图
注:接下来的任务主要是对商城当中的细节进行优化。
Part four 代码/文档签入记录
3.1 代码签入
说明:第七天git操作已经较为熟练
3.2 Issue链接
成员 | Issue链接 |
---|---|
张天 | 实现一些工具组件类1 |
黄炜恒 | 商家入驻模块 |
黄浩捷 | 商城主界面 |
陈伟升 | 支付模块 |
曾广宁 | 商品的整体架构 |
曾春华 | 商品的整体架构 |
Part five 最新程序/模块
4.1 程序代码
package com.nanrailgun.order_service_provider.service; //订单状态与订单服务模块
import com.nanrailgun.config.common.*;
import com.nanrailgun.config.utils.MyBeanUtil;
import com.nanrailgun.config.utils.PageQueryUtil;
import com.nanrailgun.config.utils.PageResult;
import com.nanrailgun.goods_api.api.MallGoodsService;
import com.nanrailgun.goods_api.entity.MallGoods;
import com.nanrailgun.goods_api.entity.StockNum;
import com.nanrailgun.order_api.api.MallOrderService;
import com.nanrailgun.order_api.api.MallShoppingCartItemService;
import com.nanrailgun.order_api.api.dto.MallOrderDetailDTO;
import com.nanrailgun.order_api.api.dto.MallOrderItemDTO;
import com.nanrailgun.order_api.api.dto.MallOrderListDTO;
import com.nanrailgun.order_api.api.dto.MallShoppingCartItemDTO;
import com.nanrailgun.order_api.entity.MallOrder;
import com.nanrailgun.order_api.entity.MallOrderAddress;
import com.nanrailgun.order_api.entity.MallOrderItem;
import com.nanrailgun.order_service_provider.dao.MallOrderAddressMapper;
import com.nanrailgun.order_service_provider.dao.MallOrderItemMapper;
import com.nanrailgun.order_service_provider.dao.MallOrderMapper;
import com.nanrailgun.order_service_provider.dao.MallShoppingCartItemMapper;
import com.nanrailgun.springbootstartersnowflake.beans.IdWorker;
import com.nanrailgun.user_api.entity.MallUser;
import com.nanrailgun.user_api.entity.MallUserAddress;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.groupingBy;
@Service
public class MallOrderServiceImpl implements MallOrderService {
@Resource
MallOrderMapper mallOrderMapper;
@Resource
MallOrderItemMapper mallOrderItemMapper;
@Resource
MallOrderAddressMapper mallOrderAddressMapper;
@Resource
MallShoppingCartItemMapper mallShoppingCartItemMapper;
@Reference
private MallGoodsService mallGoodsService;
@Autowired
MallShoppingCartItemService mallShoppingCartItemService;
@Autowired
IdWorker idWorker;
@Override
public MallOrderDetailDTO getOrderDetailByOrderNo(String orderNo, Long userId) {
MallOrder mallOrder = mallOrderMapper.selectByOrderNo(orderNo);
if (mallOrder == null) {
MallException.fail(ServiceResultEnum.DATA_NOT_EXIST.getResult());
}
if (!userId.equals(mallOrder.getUserId())) {
MallException.fail(ServiceResultEnum.REQUEST_FORBIDEN_ERROR.getResult());
}
List<MallOrderItem> mallOrderItems = mallOrderItemMapper.getMallOrderItemListByOrderId(mallOrder.getOrderId());
if (CollectionUtils.isEmpty(mallOrderItems)) {
MallException.fail(ServiceResultEnum.ORDER_ITEM_NULL_ERROR.getResult());
}
MallOrderDetailDTO mallOrderDetailDTO = new MallOrderDetailDTO();
mallOrderDetailDTO.setMallOrderItemVOS(MyBeanUtil.copyList(mallOrderItems, MallOrderItemDTO.class));
mallOrderDetailDTO.setOrderStatusString(MallOrderStatusEnum.getMallOrderStatusEnumByStatus(mallOrder.getOrderStatus()).getName());
mallOrderDetailDTO.setPayTypeString(PayTypeEnum.getPayTypeEnumByType(mallOrder.getPayType()).getName());
BeanUtils.copyProperties(mallOrder, mallOrderDetailDTO);
return mallOrderDetailDTO;
}
@Override
public PageResult<MallOrderListDTO> getMyOrders(PageQueryUtil util, int page, int limit) {
util.setPage(page);
util.setLimit(limit);
int total = mallOrderMapper.getTotalMallOrders(util);
List<MallOrder> mallOrders = mallOrderMapper.findMallOrderList(util);
List<MallOrderListDTO> mallOrderListVOS = new ArrayList<>();
if (!CollectionUtils.isEmpty(mallOrders) && total > 0) {
mallOrderListVOS = MyBeanUtil.copyList(mallOrders, MallOrderListDTO.class);
mallOrderListVOS.forEach(item -> item.setOrderStatusString(MallOrderStatusEnum.getMallOrderStatusEnumByStatus(item.getOrderStatus()).getName()));
List<Long> orderIds = mallOrderListVOS.stream().map(MallOrderListDTO::getOrderId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(orderIds)) {
List<MallOrderItem> mallOrderItems = mallOrderItemMapper.getMallOrderItemListByOrderIds(orderIds);
Map<Long, List<MallOrderItem>> map = mallOrderItems.stream().collect(groupingBy(MallOrderItem::getOrderId));
mallOrderListVOS.forEach(item -> item.setMallOrderItemVOS(MyBeanUtil.copyList(map.get(item.getOrderId()), MallOrderItemDTO.class)));
}
}
return new PageResult<>(mallOrderListVOS, total, util.getLimit(), util.getPage());
}
@Override
public String cancelOrder(String orderNo, Long userId) {
MallOrder order = mallOrderMapper.selectByOrderNo(orderNo);
if (order != null) {
if (!userId.equals(order.getUserId())) {
return ServiceResultEnum.REQUEST_FORBIDEN_ERROR.getResult();
}
if (mallOrderMapper.closeOrder(order.getOrderId(), MallOrderStatusEnum.ORDER_CLOSED_BY_USER.getOrderStatus()) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
return ServiceResultEnum.DB_ERROR.getResult();
}
}
return ServiceResultEnum.DATA_NOT_EXIST.getResult();
}
@Override
public String finishOrder(String orderNo, Long userId) {
MallOrder order = mallOrderMapper.selectByOrderNo(orderNo);
if (order != null) {
if (!userId.equals(order.getUserId())) {
return ServiceResultEnum.REQUEST_FORBIDEN_ERROR.getResult();
}
order.setOrderStatus((byte) MallOrderStatusEnum.ORDER_SUCCESS.getOrderStatus());
order.setUpdateTime(new Date());
if (mallOrderMapper.updateByPrimaryKey(order) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
return ServiceResultEnum.DB_ERROR.getResult();
}
}
return ServiceResultEnum.DATA_NOT_EXIST.getResult();
}
/**
* 锁订单->检测订单状态|支付状态->修改支付状态
*/
@Override
@Transactional
public String pay(String orderNo, int payType) {
//加锁
MallOrder mallOrder = mallOrderMapper.selectByOrderNoForUpdate(orderNo);
if (mallOrder != null) {
//检测订单状态 是否为待支付
//检测支付状态 是否为待支付
if (mallOrder.getOrderStatus().intValue() != MallOrderStatusEnum.ORDER_PRE_PAY.getOrderStatus()
&& mallOrder.getPayStatus() != PayStatusEnum.DEFAULT.getPayStatus()) {
MallException.fail("非待支付状态下的订单无法支付");
}
//设置支付方式
mallOrder.setPayType((byte) payType);
//支付状态修改为 支付中
mallOrder.setPayStatus((byte) PayStatusEnum.PAY_ING.getPayStatus());
mallOrder.setPayTime(new Date());
mallOrder.setUpdateTime(new Date());
if (mallOrderMapper.updateByPrimaryKey(mallOrder) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
MallException.fail(ServiceResultEnum.DB_ERROR.getResult());
}
}
MallException.fail(ServiceResultEnum.ORDER_NOT_EXIST_ERROR.getResult());
return "";
}
/**
* 加锁->判断订单状态|支付状态->修改支付状态&订单状态
*/
@Override
@Transactional
public String paySuccess(String orderNo) {
//加锁
MallOrder mallOrder = mallOrderMapper.selectByOrderNoForUpdate(orderNo);
if (mallOrder != null) {
//判断订单状态|支付状态
if (mallOrder.getOrderStatus().intValue() != MallOrderStatusEnum.ORDER_PRE_PAY.getOrderStatus()) {
MallException.fail("订单状态异常");
}
if (mallOrder.getPayStatus() != PayStatusEnum.PAY_ING.getPayStatus()) {
MallException.fail("支付异常");
}
//修改订单状态 为已支付
mallOrder.setOrderStatus((byte) MallOrderStatusEnum.ORDER_PAID.getOrderStatus());
//修改支付状态 为支付成功
mallOrder.setPayStatus((byte) PayStatusEnum.PAY_SUCCESS.getPayStatus());
mallOrder.setPayTime(new Date());
mallOrder.setUpdateTime(new Date());
if (mallOrderMapper.updateByPrimaryKey(mallOrder) > 0) {
return ServiceResultEnum.SUCCESS.getResult();
} else {
MallException.fail(ServiceResultEnum.DB_ERROR.getResult());
}
}
MallException.fail(ServiceResultEnum.ORDER_NOT_EXIST_ERROR.getResult());
return "";
}
@Override
@GlobalTransactional
public String saveOrder(MallUser user, List<Long> cartItemIds, MallUserAddress address) {
List<MallShoppingCartItemDTO> shoppingCartItems = mallShoppingCartItemService.getShoppingCartItemByCartItemIds(user.getUserId(), cartItemIds);
Map<Long, MallShoppingCartItemDTO> mallShoppingCartItemVOMap = shoppingCartItems.stream().collect(Collectors.toMap(MallShoppingCartItemDTO::getGoodsId, Function.identity()));
List<Long> goodsIdList = shoppingCartItems.stream().map(MallShoppingCartItemDTO::getGoodsId).collect(Collectors.toList());
List<Long> mallShoppingCartItemIds = shoppingCartItems.stream().map(MallShoppingCartItemDTO::getCartItemId).collect(Collectors.toList());
List<MallGoods> goodsList = mallGoodsService.selectByPrimaryKeys(goodsIdList);
if (shoppingCartItems.size() != cartItemIds.size() || goodsList.size() != cartItemIds.size()) {
MallException.fail(ServiceResultEnum.GOODS_NOT_EXIST.getResult());
}
goodsList.forEach(item -> {
if (item.getGoodsSellStatus() != Constants.SELL_STATUS_UP) {
MallException.fail(item.getGoodsName() + "已下架,无法生成订单!");
}
if (item.getStockNum() < mallShoppingCartItemVOMap.get(item.getGoodsId()).getGoodsCount()) {
MallException.fail(item.getGoodsName() + "库存不足,无法生成订单!");
}
});
//删除购物项
if (mallShoppingCartItemMapper.deleteBatch(mallShoppingCartItemIds) < 1) {
MallException.fail(ServiceResultEnum.DB_ERROR.getResult());
}
//减库存
List<StockNum> stockNums = MyBeanUtil.copyList(shoppingCartItems, StockNum.class);
int result = mallGoodsService.updateStockNum(stockNums);
if (result < 1) {
MallException.fail(ServiceResultEnum.DB_ERROR.getResult());
}
String orderNo = String.valueOf(idWorker.nextId());
int totalPrice = 0;
MallOrder order = new MallOrder();
order.setOrderNo(orderNo);
order.setUserId(user.getUserId());
//计算总价
for (MallShoppingCartItemDTO item : shoppingCartItems) {
totalPrice = totalPrice + item.getGoodsCount() * item.getSellingPrice();
}
if (totalPrice < 1) {
MallException.fail(ServiceResultEnum.ORDER_PRICE_ERROR.getResult());
}
order.setTotalPrice(totalPrice);
order.setExtraInfo("");
if (mallOrderMapper.insert(order) < 1) {
MallException.fail(ServiceResultEnum.DB_ERROR.getResult());
}
MallOrderAddress mallOrderAddress = new MallOrderAddress();
order = mallOrderMapper.selectByOrderNo(orderNo);
mallOrderAddress.setOrderId(order.getOrderId());
BeanUtils.copyProperties(address, mallOrderAddress);
if (mallOrderAddressMapper.insert(mallOrderAddress) < 1) {
MallException.fail(ServiceResultEnum.ORDER_PRICE_ERROR.getResult());
}
List<MallOrderItem> mallOrderItems = MyBeanUtil.copyList(shoppingCartItems, MallOrderItem.class);
MallOrder temp = order;
mallOrderItems.forEach(item -> item.setOrderId(temp.getOrderId()));
if (mallOrderItemMapper.insertBatch(mallOrderItems) < 1) {
MallException.fail(ServiceResultEnum.DB_ERROR.getResult());
}
//测试分布式事务
//throw new MallException("test");
return orderNo;
}
}
4.2 运行截图
用户显示的界面
用户支付界面
Part six 每人每日总结
成员 | 小结 |
---|---|
张天 | 项目开发到这里,已经基本完成 |
黄炜恒 | 任务终于结束了,累,准备休息 |
黄浩捷 | 经过这段时间,编程的能力已经有了明显的提升 |
陈伟升 | 写支付模块真累 |
曾广宁 | 继续努力,多学习 |
曾春华 | 要更努力的学习 |