基于ssm的超市管理系统

一、运行环境

mysql5.6以上

tomcat8.0+

jdk1.8

idea、eclipse或者myeclipse

二、功能截图

基于ssm的超市管理系统_第1张图片

基于ssm的超市管理系统_第2张图片

基于ssm的超市管理系统_第3张图片 

基于ssm的超市管理系统_第4张图片 

基于ssm的超市管理系统_第5张图片

基于ssm的超市管理系统_第6张图片

三、主要代码

package com.wxl.sms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxl.sms.bean.Group;
import com.wxl.sms.bean.to.Sale;
import com.wxl.sms.service.GroupService;
import com.wxl.sms.service.ProductService;
import com.wxl.sms.service.SaleService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 销售统计Controller
 *
 */
@Controller
@RequestMapping("/sale")
public class SaleController {
    @Resource
    private SaleService saleService;
    @Resource
    private ProductService productService;
    @Resource
    private GroupService groupService;


    /**
     * 重定向后进入sale.jsp页面
     *
     * @return 重定向到sale.jsp
     */
    @RequestMapping("/toSale")
    public String toSalePage() {
        return "forward:/sale/saleInfo";
    }

    /**
     * 用于显示销售统计页面的信息
     *
     * @param pn 页码
     * @param request 原生API, 用于获取表单输入信息以进行条件查询
     * @param model 存储数据域中
     * @return sale.jsp
     */
    @Deprecated
    @RequestMapping("/saleInfo")
    public String showSaleInfo(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
                               HttpServletRequest request,
                               Model model) {
        System.out.println("preGroupId ===> " + request.getParameter("groupIdInForm"));
        Integer groupId = null;
        String startDate = "";
        String endDate = "";

        if (request.getParameter("groupIdInForm") != null &&
                !request.getParameter("groupIdInForm").equals("0")) {
            // 表单输入的商品类别
            groupId = Integer.parseInt(request.getParameter("groupIdInForm"));
        }
        if (request.getParameter("startDate") != null &&
                request.getParameter("endDate") != null) {
            startDate = request.getParameter("startDate");
            endDate = request.getParameter("endDate");
        }

//        System.out.println("********************************");
//        System.out.println("groupId ===> " + groupId);
//        System.out.println("startDate ===> " + startDate);
//        System.out.println("endDate ===> " + endDate);
//        System.out.println("********************************");

        List sales = saleService.getSaleInfoByCondition(groupId, startDate, endDate);
        for (Sale sale : sales) {
            sale.setProduct(productService.getProductByProductId(sale.getProductId()));
            sale.getProduct().setGroup(groupService.getGroupByGroupId(sale.getProduct().getGroupId()));
        }

        model.addAttribute("sales", sales);

        // 2021年5月5日01:13:06添加, 为了让条件查询更容容易, 这里由填写商品分类, 修改为选择下拉框
        List allGroups = groupService.getAllGroups();
        model.addAttribute("allGroups", allGroups);

        return "sale/sale";
    }



    /**
     * 用于显示销售统计页面的信息
     *
     * @param pn 页码
     * @param request 原生API, 用于获取表单输入信息以进行条件查询
     * @param model 存储数据域中
     * @param postGroupId 存储上一次表单提交的商品分类值
     * @return sale.jsp
     */
    @RequestMapping("/saleInfoPro")
    public String showSaleInfoPro(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
                                  HttpServletRequest request,
                                  Model model,
                                  @RequestParam(value = "groupId", defaultValue = "0") Integer postGroupId) {
//        System.out.println("preGroupId ===> " + request.getParameter("groupIdInForm"));
        Integer groupId = null;
        String startDate = "";
        String endDate = "";

        if (postGroupId == 0) {
            if (request.getParameter("groupIdInForm") != null &&
                    !request.getParameter("groupIdInForm").equals("0")) {
                // 表单输入的商品类别
                groupId = Integer.parseInt(request.getParameter("groupIdInForm"));
            }
        } else {
            groupId = postGroupId;
        }

        if (request.getParameter("startDate") != null &&
                request.getParameter("endDate") != null) {
            startDate = request.getParameter("startDate");
            endDate = request.getParameter("endDate");
        }


       /* PageHelper.startPage(pn, 5);*/
        List sales = saleService.getSaleInfoByCondition(groupId, startDate, endDate);
        for (Sale sale : sales) {
            sale.setProduct(productService.getProductByProductId(sale.getProductId()));
            sale.getProduct().setGroup(groupService.getGroupByGroupId(sale.getProduct().getGroupId()));
        }

     /*   PageInfo pageInfo = new PageInfo<>(sales, 5);*/
        model.addAttribute("sales", sales);

        // 2021年5月5日01:13:06添加, 为了让条件查询更容容易, 这里由填写商品分类, 修改为选择下拉框
        List allGroups = groupService.getAllGroups();
        model.addAttribute("allGroups", allGroups);

        // 2021年5月10日14:12:48 Pro版, 解决分页BUG
        model.addAttribute("groupId", groupId);

        return "sale/sale";
    }
}

package com.wxl.sms.dao;

import com.wxl.sms.bean.to.Sale;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 销售表Mapper
 *
 * @author wxl on 2021/5/2 1:10
 */
public interface SaleMapper {

    /**
     * 增加一条销售记录(事务操作)
     *
     * @return 影响的行数
     */
    int insertSaleItemFinal(@Param("productId") Integer productId,
                            @Param("productName") String productName,
                            @Param("groupId") Integer groupId,
                            @Param("purchasePrice") float purchasePrice,
                            @Param("salePrice") float salePrice,
                            @Param("saleCount") Integer saleCount,
                            @Param("saleVolume") float saleVolume,
                            @Param("netProfit") float netProfit);

    
    /**
     * 用于根据条件展示销售信息
     *
     * @param groupId 商品分类信息

     * @return TO集合
     */

     List getSaleInfoByCondition(@Param("groupId") Integer groupId,
                                      @Param("startDate") String startDate,
                                      @Param("endDate") String endDate);

}
package com.wxl.sms.service;

import com.wxl.sms.bean.to.Sale;

import java.util.List;

/**
 * @author wxl on 2021/5/2 1:22
 */
public interface SaleService {

    /**
     * 增加一条销售记录
     *
     * @param productId 售出商品id
     * @param saleCount 售出数量
     * @return 影响的行数
     */
    int insertSaleItem(Integer productId, Integer saleCount);

    /**
     * 用于根据条件展示销售信息
     * @param startDate 搜索开始时间
     * @param endDate 搜索结束时间
     * @param groupId 商品分类信息
     * @return TO集合
     */



      List getSaleInfoByCondition(Integer groupId, String startDate, String endDate);
}
package com.wxl.sms.service.impl;

import com.wxl.sms.bean.Product;
import com.wxl.sms.bean.to.Sale;
import com.wxl.sms.dao.ProductMapper;
import com.wxl.sms.dao.SaleMapper;
import com.wxl.sms.service.SaleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SaleServiceImpl implements SaleService {
    @Resource
    private SaleMapper saleMapper;
    @Resource
    private ProductMapper productMapper;

    @Override
    public int insertSaleItem(Integer productId, Integer saleCount) {
        Product product = productMapper.getProductByProductId(productId);

        String productName = product.getProductName();
        Integer groupId = product.getGroupId();
        float purchasePrice = product.getPurchasePrice();
        float salePrice = product.getSalePrice();
        // saleVolume - 销售额
        float saleVolume = saleCount * purchasePrice;
        // netProfit - 净利润
        float netProfit = (salePrice - purchasePrice) * saleCount;

        return saleMapper.insertSaleItemFinal(productId, productName, groupId, purchasePrice, salePrice,
                saleCount, saleVolume, netProfit);
    }

    @Override
    public List getSaleInfoByCondition(Integer groupId, String startDate, String endDate) {
        return saleMapper.getSaleInfoByCondition(groupId, startDate, endDate);
    }
}
/*    public List getSaleInfoByCondition(Integer groupId, String startDate, String endDate) {
        return saleMapper.getSaleInfoByCondition(groupId, startDate, endDate);
    }*/




    
    

    

    
    
        
        
        
        
    

    
    
        
        
    

    
    
        
        
        
        
        
    

    
    
    
    
    

    
    
        
        
        
    

    
    
        
        
    

    
    
        
        
        
        
    

    
    
        
            
            
            
            
        
    

    

    



你可能感兴趣的:(Java源码,mysql,ssm,java,开发语言,mvc,ssm,mysql)