基于java的ssm电脑硬件库存管理系统源码和论文

基于java的ssm电脑硬件库存管理系统源码和论文145


 开发工具:idea 或eclipse
 数据库mysql5.7+
 数据库链接工具:navcat,小海豚等
  技术:ssm 

现如今,信息种类变得越来越多,信息的容量也变得越来越大,这就是信息时代的标志。近些年,计算机科学发展得也越来越快,而且软件开发技术也越来越成熟,因此,在生活中的各个领域,只要存在信息管理,几乎都有计算机的影子,可以说很多行业都采用计算机的方式管理信息。信息计算机化处理相比手工操作,有着保密性强,效率高,存储空间大,成本低等诸多优点。针对电脑硬件库存信息管理混乱,出错率高,信息安全性差,劳动强度大,费时费力等问题,采用电脑硬件库存管理系统可以有效管理,使信息管理能够更加科学和规范。

电脑硬件库存管理系统采用了模块化设计方法,采用Java语言进行编程设计,MySQL数据库进行数据存储和管理,JSP技术进行系统页面设计。根据电脑硬件库存管理的需求开发功能模块,实现对信息数据的添加、删除、修改、查询等基本操作,能够极大的提高电脑硬件库存管理效率。通过本系统可以实现电脑硬件库存管理的全过程,本系统主要的功能模块设计包括:用户管理,硬件类型管理,硬件管理,出入库订单管理,系统公告管理等。

设计和实现电脑硬件库存管理系统,需要学习和掌握Java语言、JSP技术、MySQL数据库等关键开发技术,并且熟练使用IDEA .Tomcat等相关的开发工具。

package com.controller;


import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.StringUtil;
import java.lang.reflect.InvocationTargetException;

import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;

import com.entity.YonghuEntity;

import com.service.YonghuService;
import com.entity.view.YonghuView;
import com.utils.PageUtils;
import com.utils.R;

/**
 * 用户表
 * 后端接口
 * @author
 * @email
 * @date 2024-04-01
*/
@RestController
@Controller
@RequestMapping("/yonghu")
public class YonghuController {
    private static final Logger logger = LoggerFactory.getLogger(YonghuController.class);

    @Autowired
    private YonghuService yonghuService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;


    //级联表service


    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        PageUtils page = yonghuService.queryPage(params);

        //字典表数据转换
        List<YonghuView> list =(List<YonghuView>)page.getList();
        for(YonghuView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c);
        }
        return R.ok().put("data", page);
    }
    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        YonghuEntity yonghu = yonghuService.selectById(id);
        if(yonghu !=null){
            //entity转view
            YonghuView view = new YonghuView();
            BeanUtils.copyProperties( yonghu , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @IgnoreAuth
    @RequestMapping("/save")
    public R save(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
        Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
            .eq("username", yonghu.getUsername())
            .or()
            .eq("phone", yonghu.getPhone())
            .or()
            .eq("id_number", yonghu.getIdNumber());
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
        if(yonghuEntity==null){
            yonghu.setRole("用户");
            yonghu.setPassword("123456");
        //  String role = String.valueOf(request.getSession().getAttribute("role"));
        //  if("".equals(role)){
        //      yonghu.set
        //  }
            yonghuService.insert(yonghu);
            return R.ok();
        }else {
            return R.error(511,"账户或者身份证号或者手机号已经被使用");
        }
    }

    /**
    * 修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody YonghuEntity yonghu, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,yonghu:{}",this.getClass().getName(),yonghu.toString());
        //根据字段查询是否有相同数据
        Wrapper<YonghuEntity> queryWrapper = new EntityWrapper<YonghuEntity>()
            .notIn("id",yonghu.getId())
            .andNew()
            .eq("username", yonghu.getUsername())
            .or()
            .eq("phone", yonghu.getPhone())
            .or()
            .eq("id_number", yonghu.getIdNumber());
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YonghuEntity yonghuEntity = yonghuService.selectOne(queryWrapper);
        if("".equals(yonghu.getImgPhoto()) || "null".equals(yonghu.getImgPhoto())){
                yonghu.setImgPhoto(null);
        }
        if(yonghuEntity==null){
            //  String role = String.valueOf(request.getSession().getAttribute("role"));
            //  if("".equals(role)){
            //      yonghu.set
            //  }
            yonghuService.updateById(yonghu);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"账户或者身份证号或者手机号已经被使用");
        }
    }


    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        yonghuService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


     /**
    * 登录
    */
    @IgnoreAuth
    @PostMapping(value = "/login")
    public R login(String username, String password, String captcha, HttpServletRequest request) {
        YonghuEntity yonghu = yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", username));
        if(yonghu==null || !yonghu.getPassword().equals(password)) {
            return R.error("账号或密码不正确");
        }
        String token = tokenService.generateToken(yonghu.getId(),username, "yonghu", "用户");
        R r = R.ok();
        r.put("token", token);
        r.put("role","用户");
        r.put("username",yonghu.getName());
        r.put("tableName","yonghu");
        r.put("userId",yonghu.getId());
        return r;
    }

    /**
    * 注册
    */
    @IgnoreAuth
    @PostMapping(value = "/register")
    public R register(@RequestBody YonghuEntity yonghu){
    //    	ValidatorUtils.validateEntity(user);
        if(yonghuService.selectOne(new EntityWrapper<YonghuEntity>().eq("username", yonghu.getUsername()).orNew().eq("phone",yonghu.getPhone()).orNew().eq("id_number",yonghu.getIdNumber())) !=null) {
            return R.error("用户已存在或手机号身份证号已经被使用");
        }
        yonghuService.insert(yonghu);
        return R.ok();
    }

    /**
     * 重置密码
     */
    @GetMapping(value = "/resetPassword")
    public R resetPassword(Integer  yonghuId){
        YonghuEntity yonghu = new YonghuEntity();
        yonghu.setPassword("123456");
        yonghu.setId(yonghuId);
        yonghuService.updateById(yonghu);
        return R.ok();
    }

    /**
    * 获取用户的session用户信息
    */
    @RequestMapping("/session")
    public R getCurrYonghu(HttpServletRequest request){
        Integer id = (Integer)request.getSession().getAttribute("userId");
        YonghuEntity yonghu = yonghuService.selectById(id);
        return R.ok().put("data", yonghu);
    }


    /**
    * 退出
    */
    @GetMapping(value = "logout")
    public R logout(HttpServletRequest request) {
        request.getSession().invalidate();
        return R.ok("退出成功");
    }

}

package com.controller;


import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;

import com.entity.GoodsEntity;
import com.entity.InOutOrderListEntity;
import com.service.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;

import com.utils.StringUtil;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;

import com.entity.InOutOrderEntity;

import com.entity.view.InOutOrderView;
import com.utils.PageUtils;
import com.utils.R;

/**
 * 出入库订单
 * 后端接口
 * @author
 * @email
 * @date
*/
@RestController
@Controller
@RequestMapping("/inOutOrder")
public class InOutOrderController {
    private static final Logger logger = LoggerFactory.getLogger(InOutOrderController.class);

    @Autowired
    private InOutOrderService inOutOrderService;


    @Autowired
    private TokenService tokenService;
    @Autowired
    private DictionaryService dictionaryService;


    //级联表service

    // 商品表
    @Autowired
    private GoodsService goodsService;
    //订单详情表
    @Autowired
    private InOutOrderListService inOutOrderListService;


    /**
    * 后端列表
    */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){
        logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(StringUtil.isNotEmpty(role) && "用户".equals(role)){
            params.put("yonghuId",request.getSession().getAttribute("userId"));
        }
        PageUtils page = inOutOrderService.queryPage(params);

        //字典表数据转换
        List<InOutOrderView> list =(List<InOutOrderView>)page.getList();
        for(InOutOrderView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c);
        }
        return R.ok().put("data", page);
    }
    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        InOutOrderEntity inOutOrder = inOutOrderService.selectById(id);
        if(inOutOrder !=null){
            //entity转view
            InOutOrderView view = new InOutOrderView();
            BeanUtils.copyProperties( inOutOrder , view );//把实体数据重构到view中

            //修改对应字典表字段
            dictionaryService.dictionaryConvert(view);
            return R.ok().put("data", view);
        }else {
            return R.error(511,"查不到数据");
        }

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody InOutOrderEntity inOutOrder, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,inOutOrder:{}",this.getClass().getName(),inOutOrder.toString());
        Wrapper<InOutOrderEntity> queryWrapper = new EntityWrapper<InOutOrderEntity>()
            .eq("order_name", inOutOrder.getOrderName())
            .eq("caozuo_name", inOutOrder.getCaozuoName())
            .eq("caozuo_table", inOutOrder.getCaozuoTable())
            .eq("order_types", inOutOrder.getOrderTypes())
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        InOutOrderEntity inOutOrderEntity = inOutOrderService.selectOne(queryWrapper);
        if(inOutOrderEntity==null){
            inOutOrder.setInsertTime(new Date());
            inOutOrder.setCreateTime(new Date());
        //  String role = String.valueOf(request.getSession().getAttribute("role"));
        //  if("".equals(role)){
        //      inOutOrder.set
        //  }
            inOutOrderService.insert(inOutOrder);
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
    * 修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody InOutOrderEntity inOutOrder, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,inOutOrder:{}",this.getClass().getName(),inOutOrder.toString());
        //根据字段查询是否有相同数据
        Wrapper<InOutOrderEntity> queryWrapper = new EntityWrapper<InOutOrderEntity>()
            .notIn("id",inOutOrder.getId())
            .eq("order_name", inOutOrder.getOrderName())
            .eq("caozuo_name", inOutOrder.getCaozuoName())
            .eq("caozuo_table", inOutOrder.getCaozuoTable())
            .eq("order_types", inOutOrder.getOrderTypes())
            ;
        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        InOutOrderEntity inOutOrderEntity = inOutOrderService.selectOne(queryWrapper);
        if(inOutOrderEntity==null){
            //  String role = String.valueOf(request.getSession().getAttribute("role"));
            //  if("".equals(role)){
            //      inOutOrder.set
            //  }
            inOutOrderService.updateById(inOutOrder);//根据id更新
            return R.ok();
        }else {
            return R.error(511,"表中有相同数据");
        }
    }

    /**
     * 出库
     */
    @RequestMapping("/outOrder")
    public R outGoods(@RequestBody  Map<String, Object> params,HttpServletRequest request){
        logger.debug("outGoods方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        Map<String, Integer> map = (Map<String, Integer>) params.get("map");
        String orderName = String.valueOf(params.get("orderName"));
        InOutOrderEntity one = inOutOrderService.selectOne(new EntityWrapper<InOutOrderEntity>().eq("order_name", orderName));
        if(one != null){
            return R.error(orderName+"的订单名已经被使用");
        }

        Set<String> ids = map.keySet();
        List<GoodsEntity> list = goodsService.selectList(new EntityWrapper<GoodsEntity>().in("id", ids));
        Date date = new Date();
        for(GoodsEntity g:list){
            Integer shiyongnumber = map.get(String.valueOf(g.getId()));
            if(g.getGoodsNumber()==null || shiyongnumber == null){
                return R.error(g.getGoodsName()+"的库存数量为空或者出库数量为空");
            }else if(g.getGoodsNumber()-shiyongnumber<0){
                return R.error(g.getGoodsName()+"的出库数量:"+shiyongnumber+"不能大于库存数量"+g.getGoodsNumber());
            }else{
                //正常出库
                g.setGoodsNumber(g.getGoodsNumber()-shiyongnumber);
            }
        }
        //修改库存
        goodsService.updateBatchById(list);

        //新增订单
        InOutOrderEntity inOutOrderEntity = new InOutOrderEntity();
        inOutOrderEntity.setCreateTime(date);
        inOutOrderEntity.setInsertTime(date);
        inOutOrderEntity.setCaozuoName(String.valueOf(request.getSession().getAttribute("username")));
        inOutOrderEntity.setCaozuoTable(String.valueOf(request.getSession().getAttribute("tableName")));
        inOutOrderEntity.setOrderTypes(1);//设置订单为出库
        inOutOrderEntity.setOrderName(orderName);
        inOutOrderService.insert(inOutOrderEntity);

        if(inOutOrderEntity.getId()!=null){
            //新增订单详情
            List<InOutOrderListEntity> inOutOrderListEntityList = new ArrayList<>();
            for(String i:ids){
                InOutOrderListEntity inOutOrderListEntity = new InOutOrderListEntity();
                inOutOrderListEntity.setCreateTime(date);
                inOutOrderListEntity.setGoodsId(Integer.valueOf(i));
                inOutOrderListEntity.setInOutOrderId(inOutOrderEntity.getId());
                inOutOrderListEntity.setOrderNumber(map.get(i));
                inOutOrderListEntityList.add(inOutOrderListEntity);
            }
            if(inOutOrderListEntityList != null && inOutOrderListEntityList.size()>0){
                inOutOrderListService.insertBatch(inOutOrderListEntityList);
                return R.ok();
            }
        }else{
            return R.error("新增订单失败");
        }
        return R.ok();
    }

    /**
     * 入库
     */
    @RequestMapping("/inOrder")
    public R inGoods(@RequestBody  Map<String, Object> params,HttpServletRequest request){
        logger.debug("inGoods方法:,,Controller:{},,map:{}",this.getClass().getName(),JSONObject.toJSONString(params));
        Map<String, Integer> map = (Map<String, Integer>) params.get("map");
        String orderName = String.valueOf(params.get("orderName"));
        InOutOrderEntity one = inOutOrderService.selectOne(new EntityWrapper<InOutOrderEntity>().eq("order_name", orderName));
        if(one != null){
            return R.error(orderName+"的订单名已经被使用");
        }
        Set<String> ids = map.keySet();

        List<GoodsEntity> list = goodsService.selectList(new EntityWrapper<GoodsEntity>().in("id", ids));
        Date date = new Date();
        for(GoodsEntity g:list){
            Integer rukunumber = map.get(String.valueOf(g.getId()));
            Integer oldGoodsNumber = g.getGoodsNumber();
            if(rukunumber == null){
                return R.error(g.getGoodsName()+"的入库数量为空");
            }else if( oldGoodsNumber== null || oldGoodsNumber == 0){
                g.setGoodsNumber(rukunumber);
            }else{
                g.setGoodsNumber(oldGoodsNumber+rukunumber);
            }
        }
        //修改库存
        goodsService.updateBatchById(list);

        //新增订单
        InOutOrderEntity inOutOrderEntity = new InOutOrderEntity();
        inOutOrderEntity.setCreateTime(date);
        inOutOrderEntity.setInsertTime(date);
        inOutOrderEntity.setCaozuoName(String.valueOf(request.getSession().getAttribute("username")));
        inOutOrderEntity.setCaozuoTable(String.valueOf(request.getSession().getAttribute("tableName")));
        inOutOrderEntity.setOrderTypes(2);//设置订单为入库
        inOutOrderEntity.setOrderName(orderName);
        inOutOrderService.insert(inOutOrderEntity);

        if(inOutOrderEntity.getId()!=null){
            //新增订单详情
            List<InOutOrderListEntity> inOutOrderListEntityList = new ArrayList<>();
            for(String i:ids){
                InOutOrderListEntity inOutOrderListEntity = new InOutOrderListEntity();
                inOutOrderListEntity.setCreateTime(date);
                inOutOrderListEntity.setGoodsId(Integer.parseInt(i));
                inOutOrderListEntity.setInOutOrderId(inOutOrderEntity.getId());
                inOutOrderListEntity.setOrderNumber(map.get(i));
                inOutOrderListEntityList.add(inOutOrderListEntity);
            }
            if(inOutOrderListEntityList != null && inOutOrderListEntityList.size()>0){
                inOutOrderListService.insertBatch(inOutOrderListEntityList);
                return R.ok();
            }
        }else{
            return R.error("新增订单失败");
        }
        return R.ok();
    }
    /**
    * 删除
    */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
        List<InOutOrderEntity> list = inOutOrderService.selectList(new EntityWrapper<InOutOrderEntity>().in("id", ids));
        inOutOrderService.deleteBatchIds(Arrays.asList(ids));
        List<Integer> inOutOrderIds = new ArrayList<>();
        for(InOutOrderEntity order:list){
            inOutOrderIds.add(order.getId());
        }
        if(inOutOrderIds != null && inOutOrderIds.size()>0){
            inOutOrderListService.delete(new EntityWrapper<InOutOrderListEntity>().in("in_out_order_id", inOutOrderIds));
        }
        return R.ok();
    }


}

猜你喜欢

转载自blog.csdn.net/weixin_46437112/article/details/132730517