Java项目:进销存管理系统(java+Springboot+jpa+maven+jQuery+Mysql)

源码获取:俺的博客首页 "资源" 里下载!

项目介绍

本系统基本完成了一个基于spring boot + JPA的进销存管理系统,包括manager管理员与employee雇员两种角色。
主要实现采购管理、库存管理、销售管理、查询统计、资料管理和系统管理功能。
本系统的实现使用了很多计算机技术,包括Java语言、Spring boot框架、
JPA持久层框架和MySQL数据库。带文档


环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7版本;
5.是否Maven项目:是;


技术栈

springboot+jpa+mysql+maven+jquery

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,项目运行成功后在浏览器中访问:
管理员登录地址:http://localhost:8080/
manager管理员账号密码:admin/123456
employee雇员账号密码:test/123456

 

 

 

 

 

 

 

用户管理控制层:

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;


    /**
     * 登录
     *
     * @param username 用户名
     * @param password 密码
     * @param request
     * @return
     */

    @SysLog("登陆操作")
    @PostMapping("/login")
    public Result login(String username, String password, HttpServletRequest request) {
        try {
            //获取当前登录主体对象
            Subject subject = SecurityUtils.getSubject();
            UsernamePasswordToken token = new UsernamePasswordToken(username, password);
            subject.login(token);
            LoginUserVO userDTO = (LoginUserVO) subject.getPrincipal();
            request.getSession().setAttribute("username", userDTO.getUser());
            return Result.success(true, "200", "登录成功");
        } catch (UnknownAccountException e) {
            e.printStackTrace();
            return Result.error(false, "400", "登录失败,用户名不存在");
        }catch (IncorrectCredentialsException e) {
            e.printStackTrace();
            return Result.error(false, "400", "登录失败,密码错误");
        }catch (AuthenticationException e) {
            e.printStackTrace();
            return Result.error(false, "400", "登录失败,账户禁用");
        }
    }

    /**
     * 得到登陆验证码
     * @param response
     * @param session
     * @throws IOException
     */
    @RequestMapping("/getCode")
    public void getCode(HttpServletResponse response, HttpSession session) throws IOException {
        //定义图形验证码的长和宽
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(116, 36,4,5);
        session.setAttribute("code",lineCaptcha.getCode());
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            lineCaptcha.write(outputStream);
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询所有用户信息
     *
     * @param userVO
     * @return
     */
    @SysLog("用户查询操作")
    @RequestMapping("/userList")
    public DataGridViewResult userList(UserVO userVO) {
        //分页构造函数
        IPage<User> page = new Page<>(userVO.getPage(), userVO.getLimit());
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(userVO.getUsername()), "username", userVO.getUsername());
        queryWrapper.like(!StringUtils.isEmpty(userVO.getUname()), "uname", userVO.getUname());
        /**
         * 翻页查询
         * @param page         翻页对象
         * @param queryWrapper 实体对象封装操作类
         */
        IPage<User> userIPage = userService.page(page, queryWrapper);
        return new DataGridViewResult(userIPage.getTotal(), userIPage.getRecords());
    }

    /**
     * 添加用户信息
     *
     * @param user
     * @return
     */
    @SysLog("用户添加操作")
    @PostMapping("/adduser")
    public Result addRole(User user) {


        user.setUcreatetime(new Date());
        String salt = UUIDUtil.randomUUID();
        user.setPassword(PasswordUtil.md5("000000", salt, 2));
        user.setSalt(salt);
        user.setType(1);
        boolean bool = userService.save(user);

        try {
            if (bool) {
                return Result.success(true, "200", "添加成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error(false, null, "添加失败!");
    }

    /**
     * 校验用户名是否存在
     *
     * @param username
     * @return
     */

    @RequestMapping("/checkUserName")
    public String checkUserName(String username) {
        Map<String, Object> map = new HashMap<>();
        try {
            QueryWrapper<User> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("username", username);
            User user = userService.getOne(queryWrapper);
            if (user != null) {
                map.put("exist", true);
                map.put("message", "用户名已存在");
            } else {
                map.put("exist", false);
                map.put("message", "用户名可以使用");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSON.toJSONString(map);
    }

    /**
     * 修改用户信息
     *
     * @param user
     * @return
     */
    @SysLog("用户修改操作")
    @PostMapping("/updateuser")
    public Result updateUser(User user) {

        boolean bool = userService.updateById(user);
        try {
            if (bool) {
                return Result.success(true, "200", "修改成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error(false, null, "修改失败!");
    }

    /**
     * 删除单条数据
     *
     * @param id
     * @return
     */
    @SysLog("用户删除操作")
    @RequestMapping("/deleteOne")
    public Result deleteOne(int id) {
        boolean bool = userService.removeById(id);
        try {
            if (bool) {
                return Result.success(true, "200", "删除成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error(false, null, "删除失败!");
    }

    /**
     * 重置密码
     *
     * @param id
     * @return
     */
    @SysLog("用户修改操作")
    @PostMapping("/resetPwd")
    public Result resetPwd(int id) {

        User user = new User();
        String salt = UUIDUtil.randomUUID();
        user.setUid(id);
        user.setPassword(PasswordUtil.md5("000000", salt, 2));
        user.setSalt(salt);
        boolean bool = userService.updateById(user);

        try {
            if (bool) {
                return Result.success(true, "200", "重置成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error(false, null, "重置失败!");
    }

    /**
     * 根据id查询当前用户拥有的角色
     *
     * @param id
     * @return
     */
    @RequestMapping("/initRoleByUserId")
    public DataGridViewResult initRoleByUserId(int id) {
        List<Map<String, Object>> mapList = null;
        try {
            //查询所有角色列表
            mapList = roleService.listMaps();
            //根据用户id查询用户拥有的角色
            Set<Integer> roleIdList = userService.findRoleByUserId(id);
            for (Map<String, Object> map : mapList) {
                //定义标记 默认不选中
                boolean flag = false;
                int roleId = (int) map.get("roleid");
                for (Integer rid : roleIdList) {
                    if (rid == roleId) {
                        flag = true;
                        break;
                    }
                }
                map.put("LAY_CHECKED", flag);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new DataGridViewResult(Long.valueOf(mapList.size()), mapList);

    }

    /**
     * 为用户分配角色
     *
     * @param roleids
     * @param userid
     * @return
     */
    @SysLog("用户添加操作")
    @RequestMapping("/saveUserRole")
    public Result saveUserRole(String roleids, int userid) {

        try {
            if (userService.saveUserRole(userid, roleids)) {
                return Result.success(true, null, "分配成功");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.error(false, null, "分配失败");

    }

    /**
     * 修改密码
     *
     * @param newPassWord1
     * @param newPassWord2
     * @return
     */
    @RequestMapping("/updateUserPassWord")
    public Result updateUserPassWord(String newPassWord1, String newPassWord2,HttpSession session) {
        User sessionUser = (User) session.getAttribute("username");

        if (newPassWord1.equals(newPassWord2)){
            User user = new User();
            String salt = UUIDUtil.randomUUID();
            user.setUid(sessionUser.getUid());
            user.setPassword(PasswordUtil.md5(newPassWord1, salt, 2));
            user.setSalt(salt);
            boolean bool = userService.updateById(user);
            if (bool){
                return Result.success(true,null,"修改成功");
            }else {
                return Result.error(false,null,"修改失败!");
            }
        }else {
            return Result.error(false,null,"修改失败,两次密码不一致!");
        }

    }

}

销售管理控制层:

@RestController
@RequestMapping("/sale")
public class SaleController {
    @Autowired
    private SaleService saleService;

    @Autowired
    private GoodsService goodsService;
    
    @Autowired
    private CustomerService customerService;

    /**
     * 销售查询
     *
     * @param
     * @return
     */
    @SysLog("销售查询操作")
    @RequestMapping("/saleList")
    public DataGridViewResult saleList(SaleVO saleVO) {

        //创建分页信息    参数1 当前页  参数2 每页显示条数
        IPage<Sale> page = new Page<>(saleVO.getPage(), saleVO.getLimit());
        QueryWrapper<Sale> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(saleVO.getNumbering()),"numbering", saleVO.getNumbering());
        queryWrapper.eq(saleVO.getGid() != null && saleVO.getGid() != 0, "gid", saleVO.getGid());
        queryWrapper.ge(saleVO.getStartTime() != null, "buytime", saleVO.getStartTime());
        queryWrapper.le(saleVO.getEndTime() != null, "buytime", saleVO.getEndTime());

        queryWrapper.orderByDesc("buytime");

        IPage<Sale> saleIPage = saleService.page(page, queryWrapper);

        List<Sale> records = saleIPage.getRecords();

        for (Sale sale : records) {
            sale.setAllmoney(sale.getMoney()*sale.getBuyquantity());
            Customer customer = customerService.getById(sale.getCustid());

            if (null != customer) {
                sale.setCustomervip(customer.getCustvip());
                sale.setCustomername(customer.getCustname());
            }
            Goods goods = goodsService.getById(sale.getGid());
            if (null != goods) {

                sale.setGoodsname(goods.getGname());
                sale.setGnumbering(goods.getGnumbering());
            }
        }

        return new DataGridViewResult(saleIPage.getTotal(), records);

    }


    /**
     * 添加销售单信息
     *
     * @param sale
     * @return
     */
    @SysLog("销售添加操作")
    @PostMapping("/addsale")
    public Result addsale(Sale sale, HttpSession session) {
        if (sale.getGid()==0){
            return Result.error(false, null, "添加失败!未选商品");
        }
        Goods goods = goodsService.getById(sale.getGid());
        Integer gquantity = goods.getGquantity();
        if(gquantity<sale.getBuyquantity()){
            return Result.error(false, null, "添加失败!库存不足,库存为:"+gquantity);
        }
        User user = (User) session.getAttribute("username");
        String num = RandomStringUtils.randomAlphanumeric(7);
        sale.setNumbering(num);
        sale.setPerson(user.getUsername());
        sale.setBuytime(new Date());
        sale.setRealnumber(sale.getBuyquantity());
        boolean bool = saleService.save(sale);
        if (bool) {
            return Result.success(true, "200", "添加成功!");
        }
        return Result.error(false, null, "添加失败!库存不足");
    }


    /**
     * 修改销售单信息
     *
     * @param sale
     * @return
     */
    @SysLog("销售修改操作")
    @PostMapping("/updatesale")
    public Result updatesale(Sale sale, HttpSession session) {

        User user = (User) session.getAttribute("username");
        sale.setPerson(user.getUsername());
        sale.setBuytime(new Date());
        boolean bool = saleService.updateById(sale);
        if (bool) {
            return Result.success(true, "200", "修改成功!");
        }
        return Result.error(false, null, "修改失败!");
    }
    /**
     * 删除单条数据
     *
     * @param id
     * @return
     */
    @SysLog("销售删除操作")
    @RequestMapping("/deleteOne")
    public Result deleteOne(int id) {

        boolean bool = saleService.removeById(id);
        if (bool) {
            return Result.success(true, "200", "删除成功!");
        }
        return Result.error(false, null, "删除失败!");
    }



}

供应商管理控制层:

@RestController
@RequestMapping("/provider")
public class ProviderController {


    @Autowired
    private ProviderService providerService;


    /**
     * 供应商模糊查询
     * @param
     * @return
     */
    @SysLog("供应商查询操作")
    @RequestMapping("/providerList")
    public DataGridViewResult providerList(ProviderVO providerVO) {

        //创建分页信息    参数1 当前页  参数2 每页显示条数
        IPage<Provider> page = new Page<>(providerVO.getPage(), providerVO.getLimit());
        QueryWrapper<Provider> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(!StringUtils.isEmpty(providerVO.getProvidername()),"providername", providerVO.getProvidername());
        queryWrapper.like(!StringUtils.isEmpty(providerVO.getTelephone()),"telephone", providerVO.getTelephone());
        IPage<Provider> providerIPage = providerService.page(page, queryWrapper);

        /**
         * logsIPage.getTotal() 总条数
         * logsIPage.getRecords() 分页记录列表
         */
        return new DataGridViewResult(providerIPage.getTotal(),providerIPage.getRecords());

    }

    /**
     * 供应商批量删除
     * @param ids
     * @return
     */
    @SysLog("供应商删除操作")
    @RequestMapping("/deleteList")
    public Result deleteList(String ids) {
        //将字符串拆分成数组
        String[] idsStr = ids.split(",");
        List<String> list = Arrays.asList(idsStr);
        boolean bool = providerService.removeByIds(list);
        if(bool){
            return Result.success(true,"200","删除成功!");
        }
        return Result.error(false,null,"删除失败!");
    }

    /**
     * 添加供应商信息
     * @param provider
     * @param session
     * @return
     */
    @SysLog("供应商添加操作")
    @PostMapping("/addprovider")
    public Result addProvider(Provider provider, HttpSession session){
        User user = (User) session.getAttribute("username");
        provider.setOpername(user.getUname());
        boolean bool = providerService.save(provider);
        if(bool){
            return Result.success(true,"200","添加成功!");
        }
        return Result.error(false,null,"添加失败!");
    }

    /**
     * 修改供应商信息
     * @param provider
     * @return
     */
    @SysLog("供应商修改操作")
    @PostMapping("/updateprovider")
    public Result updateProvider(Provider provider){

        boolean bool = providerService.updateById(provider);
        if(bool){
            return Result.success(true,"200","修改成功!");
        }
        return Result.error(false,null,"修改失败!");
    }

    /**
     * 删除单条数据
     * @param id
     * @return
     */
    @SysLog("供应商删除操作")
    @RequestMapping("/deleteOne")
    public Result deleteOne(int id) {

        boolean bool = providerService.removeById(id);
        if(bool){
            return Result.success(true,"200","删除成功!");
        }
        return Result.error(false,null,"删除失败!");
    }


    /**
     *
     * 加载下拉框
     * @return
     */
    @RequestMapping("/loadAllProvider")
    public DataGridViewResult loadAllProvider(){
        QueryWrapper<Provider> queryWrapper = new QueryWrapper<>();
        List<Provider> list = providerService.list(queryWrapper);
        return new DataGridViewResult(list);

    }


}

源码获取:俺的博客首页 "资源" 里下载!

猜你喜欢

转载自blog.csdn.net/yuyecsdn/article/details/125815176