西餐厅管理系统的后端实现Day2

文章讲述了在开发过程中由于对队友意思的误解导致的时间浪费,强调了沟通和复习的重要性。内容涉及到使用maven管理项目依赖,遇到的无法解析符号问题以及模块间的循环依赖错误。作者尝试了各种解决方案,包括添加依赖、分析模块依赖等,最终发现无需修改,只需删除不再使用的类即可。
摘要由CSDN通过智能技术生成

前提:曲解了队友的意思,导致做错了东西。前三天的时间算是白花。

教训:不懂就要回顾复习,多问,交流,直到传达的意思和接收的意思保持一致

工具以及其他:idea, mysql, navicat, git, 云效, maven

任务:完成产品类别。

下面为任务细化。

回顾上学期的category板块

搞清楚来龙去脉以及加入mybatis之后的改动。

1.maven是啥?

简单了解一下。Maven是一个项目管理工具,核心:叙述项目间的依赖关系,就是通过pom.xml文件的配置获取jar包不用手动的去添加jar包,作用:方便高效,可以自动运行单元测试。

修改路径如下,该配置保存在项目的.idea目录夹中。因此IDEA新建一个项目,会恢复使用默认的maven配置。可以通过新项目设置修改maven配置解决。

 下面的库并没有导入

<dependencies>
  <!-- https://mvnrepository.com/artifact/junit/junit -->
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
    <scope>test</scope>
  </dependency>

</dependencies>

插曲:

问题:运行报错

第一个报错显示:Cannot resolve symbol 'mapper'

根据下面文章修改,把下面的代码加到每一个module的pom.xml中

(113条消息) 多模块maven项目子模块不能引用其他模块的类_M1Q84的博客-CSDN博客

<dependencies>
        <dependency>
            <groupId>edu.scau</groupId>
            <artifactId>mis-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.scau</groupId>
            <artifactId>mis-gen</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.scau</groupId>
            <artifactId>mis-pos</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.scau</groupId>
            <artifactId>mis-system</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.scau</groupId>
            <artifactId>mis-web</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

结果当然出错了

Annotation processing is not supported for module cycles. Please ensure that all modules from cycle are excluded from annotation processing

(113条消息) Error:java: Annotation processing is not supported for module cycles. Please ensure that all modules_王者丶丿风范的博客-CSDN博客

上面的文章解释了 当A B两个模块互相添加对方的依赖就会出现这种异常

但是文章所说的Analyze->Analyze Module Dependencies…我的idea的顶端工具栏没有显示,点击CODE----AnalyzeCode-----Module depen.......

但是没有已经删除循环依赖,不适合菜狗啊~

下面的文章也是解决循环的,比较清楚一点,即A依赖B,B又依赖A,则把B中的A依赖删掉,A依赖B,B依赖C,C又依赖A,则把C中的A依赖删掉。(A文件夹下面显示B表示“A依赖B

(113条消息) IDEA上循环依赖报错问题Error:java: Annotation processing is not supported for module cycles_please ensure that all modules from cycle_一米阳光zw的博客-CSDN博客

没办法只能 ctrl z

然后我已经知道,是system模块中没有依赖pos

解决:把pos中的system依赖删除,在system增加pos依赖,然后修改报错的类

例如,MenuServiceImpl,import完,显示@override错误,按提示走,修改如下:

 其他两个接口也做改动

然后就是包的问题,依赖的问题,没有这个依赖,等等等等。这些应该都是迁移项目和建立多模块的常见问题了。

 结果队友说其实不用改。

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

---------------------------------------------------------------------------------------------------------------------------------

·································································································································

ta直接把所有的类都删掉,直接不用依赖,因为这些类我们之后也不用。

我先把要删掉的贴在这

package edu.scau.mis.system.service.impl;

import edu.scau.mis.pos.domain.Category;
import edu.scau.mis.pos.mapper.CategoryMapper;
import edu.scau.mis.system.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MenuServiceImpl implements IMenuService {
    @Autowired
    private CategoryMapper categoryMapper;
    //private ProductCatalog categoryCatalog;
    @Override
    public Category getCategoryById(Long categoryId) {
        return categoryMapper.getCategoryById(categoryId);
    }

    public List<Category> listAllCategory() {
        return categoryMapper.listAllCategory();
    }

    @Override
    public List<Category> selectCategoryList(Category category) {
        return categoryMapper.selectCategoryList(category);
    }

    @Override
    public int insertCategory(Category category) {
        category.setCreateTime(new Date());
        return categoryMapper.insertCategory(category);
    }

    @Override
    public int updateCategory(Category category) {
        category.setUpdateTime(new Date());
        return categoryMapper.updateCategory(category);
    }

    @Override
    public int deleteCategoryById(Long categoryId) {
        return categoryMapper.deleteCategoryById(categoryId);

    }

}
package edu.scau.mis.system.service.impl;

import edu.scau.mis.pos.domain.ProductDescription;
import edu.scau.mis.pos.mapper.ProductMapper;
import edu.scau.mis.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class RoleServiceImpl implements IRoleService {
    @Autowired
    private ProductMapper productMapper;
    /**
     * 根据SN找产品
     * @param productSn
     * @return
     */
    @Override
    public ProductDescription getProductByProductSn(String productSn){
        return productMapper.getProductBySn(productSn);
    }

    /**
     * 列出所有产品
     * @return
     */
    @Override
    public List<ProductDescription> listAllProduct(){
        return productMapper.listAllProduct();
    }

    @Override
    public ProductDescription selectProductById(Long productId) {
        return productMapper.selectProductById(productId);
    }

    @Override
    public List<ProductDescription> selectProductList(ProductDescription productDescription) {
        return productMapper.selectProductList(productDescription);
    }

    @Override
    public int insertProduct(ProductDescription productDescription) {
        productDescription.setCreateTime(new Date());
        return productMapper.insertProduct(productDescription);
    }

    @Override
    public int updateProduct(ProductDescription productDescription) {
        productDescription.setUpdateTime(new Date());
        return productMapper.updateProduct(productDescription);
    }

    @Override
    public int deleteProductById(Long productId) {
        return productMapper.deleteProductById(productId);
    }

}
package edu.scau.mis.system.service.impl;

import cn.hutool.core.util.IdUtil;
import edu.scau.mis.pos.constants.SaleItemStatusConstants;
import edu.scau.mis.pos.constants.SaleStatusConstants;
import edu.scau.mis.pos.domain.Payment;
import edu.scau.mis.pos.domain.ProductDescription;
import edu.scau.mis.pos.domain.Sale;
import edu.scau.mis.pos.domain.SaleItem;
import edu.scau.mis.pos.mapper.SaleItemMapper;
import edu.scau.mis.pos.mapper.SaleMapper;
import edu.scau.mis.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    private Sale currentSale;
    @Autowired
    private SaleMapper saleMapper;
    @Autowired
    private SaleItemMapper saleItemMapper;

    /**
     * 开始新的销售
     *
     * @return currentSale对象
     */
    @Override
    public Sale makeNewSale(){
        currentSale = new Sale();
        Date saleDate = new Date();
        currentSale.setSaleTime(saleDate);
        String saleNo = "so-"+ IdUtil.getSnowflakeNextId();
        currentSale.setSaleNo(saleNo);
        currentSale.setStatus(SaleStatusConstants.ORDER_RESERVED);
        currentSale.setTotal(new BigDecimal("0.00"));
        return currentSale;
    }

    /**
     * 实例化SaleItem
     * @param product 商品对象
     * @param quantity 数量
     */
    @Override
    public void makeLineItem(ProductDescription product, int quantity){
        //判断商品是否已经录入
        if (!isEntered(product.getProductSn(),quantity)){
            SaleItem saleItem = new SaleItem();
            saleItem.setProductId(product.getProductId());
            saleItem.setProductDescription(product);
            saleItem.setPrice(product.getPrice());
            saleItem.setQuantity(quantity);
            currentSale.getSaleItems().add(saleItem);
        }
    }

    /**
     * 结束订单商品录入
     * @return 总金额
     */
    @Override
    public BigDecimal endSale(){
        BigDecimal total = this.getTotal();
        currentSale.setTotal(total);
        currentSale.setStatus(SaleStatusConstants.ORDER_RESERVED);
        currentSale.setCreateTime(new Date());
        saleMapper.insertSale(currentSale);
        //将订单中商品持久化
        this.insertSaleItemsOfCurrentSale(currentSale);
        return total;
    }

    /**
     * 订单支付
     * @param cashTendered 付款金额
     * @return 找零
     */
    @Override
    public BigDecimal makePayment(BigDecimal cashTendered){
        BigDecimal total = currentSale.getTotal();
        Payment payment = new Payment();
        payment.setAmount(total);
        payment.setPayTime(new Date());
        currentSale.setPayment(payment);
        currentSale.setStatus(SaleStatusConstants.ORDER_PAID);
        currentSale.setUpdateTime(new Date());
        //Change找零
        BigDecimal change = cashTendered.subtract(total);
        saleMapper.updateSale(currentSale);
        //更新订单商品明细的状态和更新时间
        this.updateSaleItemsOfCurrentSaleForMakePayment(currentSale);
        return change;
    }



    /**
     * 修改一行订单明细数量
     * @param itemSn
     * @param quantity
     */
    @Override
    public void changeQuantityOfSaleItem(String itemSn, int quantity) {
        for(SaleItem si: currentSale.getSaleItems()) {
            //如果已经录入则修改数量
            if (itemSn.equals(si.getProductDescription().getProductSn())) {
                si.setQuantity(quantity);
            }
        }
    }
    /**
     * 删除一行订单明细
     * @param itemSn
     */
    @Override
    public void deleteSaleItem(String itemSn) {
        for(int i = currentSale.getSaleItems().size() - 1;i >= 0;i--){
            if(itemSn.equals(currentSale.getSaleItems().get(1).getProductDescription().getProductSn())){
                currentSale.getSaleItems().remove(i);
            }
        }
    }

    /**
     * 计算总金额
     * @return
     */
    private BigDecimal getTotal(){
        BigDecimal total = new BigDecimal(0);
        List<SaleItem> saleItemList = currentSale.getSaleItems();
        for(SaleItem si:saleItemList){
            total = total.add(si.getSubTotal());
        }
        return total;
    }

    /**
     * 计算小计
     * @param saleItem
     * @return
     */
    private BigDecimal getSubTotal(SaleItem saleItem){
        return saleItem.getPrice().multiply(new BigDecimal(saleItem.getQuantity()));
    }

    /**
     * 判断商品是否已经录入
     * @param itemSn
     * @param quantity
     * @return
     */
    private boolean isEntered(String itemSn,int quantity){
        boolean flag = false;
        for(SaleItem si: currentSale.getSaleItems()) {
            //如果已经录入则修改数量
            if (itemSn.equals(si.getProductDescription().getProductSn())) {
                flag = true;
                int quantityOriginal = si.getQuantity();
                si.setQuantity(quantityOriginal + quantity);

            }
        }
        return flag;
    }

    /**
     * 将sale中的saleItem存入数据库
     * @param currentSale 当前sale对象
     */
    private void insertSaleItemsOfCurrentSale(Sale currentSale){
        List<SaleItem> saleItemList = currentSale.getSaleItems();
        for(SaleItem si: saleItemList){
            si.setStatus(SaleItemStatusConstants.ITEM_RESERVED);
            si.setDelFlag("0");
            si.setCreateTime(new Date());
            //注意sale插入自增生成id后才能getSaleId()取到id值
            si.setSaleId(currentSale.getSaleId());
        }
        saleMapper.batchInsertSaleItemOfCurrentSale(saleItemList);
    }

    /**
     * 支付后修改商品明细
     * 修改【状态】和【更新时间】
     * @param currentSale 当前sale对象
     *是否能在最后一步makePayment再持久化sale和saleItem?
     * 取决于挂单业务需求,非技术问题
     * 所谓挂单:存储订单,一定时间后再取出订单支付。
     * 本代码目前后端service支持挂单。但前端界面没有提供入口按钮。
     */
    private void updateSaleItemsOfCurrentSaleForMakePayment(Sale currentSale){
        SaleItem param = new SaleItem();
        param.setSaleId(currentSale.getSaleId());
        List<SaleItem> saleItems = saleItemMapper.selectSaleItemList(param);
        for (SaleItem si : saleItems) {
            si.setStatus(SaleItemStatusConstants.ITEM_PAID);
            si.setUpdateTime(new Date());
            // 建议动态sql写一个批量修改saleItem接口,避免创建多条更新的sql语句。
            // 同学可以自行参考笔记批量新增saleItem代码自行完成。
            saleItemMapper.updateSaleItem(si);
        }
    }
}

东西太多,今日份over

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值