springboot194基于springboot的医药管理系统设计与实现

博主介绍:专注于Java(springboot ssm 等开发框架) vue  .net  php phython node.js    uniapp 微信小程序 等诸多技术领域和毕业项目实战、企业信息化系统建设,从业十五余年开发设计教学工作
☆☆☆ 精彩专栏推荐订阅☆☆☆☆☆不然下次找不到哟
我的博客空间发布了2000+毕设题目 方便大家学习使用
感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人
文末下方有源码获取地址

4.2 功能模块设计

对管理员具体功能的设计结果将以图4.1所示的管理员功能结构图来进行体现。管理员对于医药管理系统操作的功能包括增删改查药品,供应商,员工信息,管理药品进货和销售信息,管理供应商信用等级和药品类型信息等。

图4.1 管理员功能结构图

对员工具体功能的设计结果将以图4.2所示的员工功能结构图来进行体现。员工对于医药管理系统操作的功能包括查看供应商信息,查询药品,新增药品进货,新增药品销售,查询药品进货和销售信息。

图4.2 员工功能结构图

4.3 数据库设计

4.3.1 数据库E-R图

(5)设计的各实体间关系E-R图如下。

图4.8 实体间关系E-R图

4.3.2 数据库结构

表4.1 供应商信息表

字段

注释

类型

id (主键)

主键

int(11)

gongyingshang_name

供应商名称

varchar(200)

gongyingshang_types

供应商类型

int(11)

gongyingshang_xinyongdengji_types

信用等级

int(11)

gongyingshang_content

供应商详情

text

create_time

创建时间

timestamp

表4.2 进货表

字段

注释

类型

id (主键)

主键

int(11)

jinhuo_uuid_number

进货编号

varchar(200)

yaopin_id

药品

int(11)

yuangong_id

员工

int(11)

jinhuo_shuliang_number

进货数量

int(11)

jinhuo_content

备注

text

jinhuo_time

进货时间

timestamp

insert_time

添加时间

timestamp

create_time

创建时间

timestamp

表4.3 管理员表

字段

注释

类型

id (主键)

主键

bigint(20)

username

用户名

varchar(100)

password

密码

varchar(100)

role

角色

varchar(100)

addtime

新增时间

timestamp

表4.4 销售表

字段

注释

类型

id (主键)

主键

int(11)

xiaoshou_uuid_number

销售编号

varchar(200)

yaopin_id

药品

int(11)

yuangong_id

员工

int(11)

xiaoshou_shuliang_number

销售数量

int(11)

xiaoshou_content

备注

text

xiaoshou_time

销售时间

timestamp

insert_time

添加时间

timestamp

create_time

创建时间

timestamp

表4.5 药品表

字段

注释

类型

id (主键)

主键

int(11)

gongyingshang_id

供应商

int(11)

yaopin_uuid_number

药品编号

varchar(200)

yaopin_name

药品名称

varchar(200)

yaopin_gongxiao

药品功效

varchar(200)

yaopin_jibing

所治疾病

varchar(200)

yaopin_photo

药品照片

varchar(200)

yaopin_types

药品类型

int(11)

yaopin_kucun_number

药品库存

int(11)

yaopin_jinjia_money

进价

decimal(10,2)

yaopin_xiaoshou_money

售价

decimal(10,2)

yaopin_content

药品介绍

text

yaopin_delete

逻辑删除

int(11)

create_time

创建时间

timestamp

表4.6 员工表

字段

注释

类型

id (主键)

主键

int(11)

username

账户

varchar(200)

password

密码

varchar(200)

yuangong_name

员工姓名

varchar(200)

yuangong_phone

员工手机号

varchar(200)

yuangong_id_number

员工身份证号

varchar(200)

yuangong_photo

员工头像

varchar(200)

sex_types

性别

int(11)

yuangong_email

电子邮箱

varchar(200)

create_time

创建时间

timestamp


5 系统实现

下面主要是通过功能实现界面截图的形式,并且运用文字来描述功能实现界面的内容。

5.1 管理员功能实现

5.1.1 药品管理

该功能主要用于实现对药品基本信息的管理,药品管理界面的运行效果见图5.1。在此界面,管理员需要对药品所治疾病,药品功效,药品库存,药品照片,供应商名称等信息进行添加,如果发现有登记错误的药品信息,管理员则可以使用修改功能及时更正,对于需要删除的药品信息则可以使用删除功能及时删除。同时,管理员也能对药品库存进行管理,包括增加药品库存,减少药品库存等操作。

图5.1 药品管理界面

5.1.2 员工管理

该功能主要用于实现对员工基本信息的管理,员工管理界面的运行效果见图5.2。在此界面,员工的姓名,性别,员工的手机号码等信息都可以让管理员添加以及修改,同时,对于需要删除的员工信息,管理员也能及时删除。

图5.2 员工管理界面


package com.controller;

import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
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.*;
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.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;

/**
 * 员工
 * 后端接口
 * @author
 * @email
*/
@RestController
@Controller
@RequestMapping("/yuangong")
public class YuangongController {
    private static final Logger logger = LoggerFactory.getLogger(YuangongController.class);

    @Autowired
    private YuangongService yuangongService;


    @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));
        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永不会进入");
        else if("员工".equals(role))
            params.put("yuangongId",request.getSession().getAttribute("userId"));
        if(params.get("orderBy")==null || params.get("orderBy")==""){
            params.put("orderBy","id");
        }
        PageUtils page = yuangongService.queryPage(params);

        //字典表数据转换
        List<YuangongView> list =(List<YuangongView>)page.getList();
        for(YuangongView c:list){
            //修改对应字典表字段
            dictionaryService.dictionaryConvert(c, request);
        }
        return R.ok().put("data", page);
    }

    /**
    * 后端详情
    */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id, HttpServletRequest request){
        logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
        YuangongEntity yuangong = yuangongService.selectById(id);
        if(yuangong !=null){
            //entity转view
            YuangongView view = new YuangongView();
            BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中

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

    }

    /**
    * 后端保存
    */
    @RequestMapping("/save")
    public R save(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
        logger.debug("save方法:,,Controller:{},,yuangong:{}",this.getClass().getName(),yuangong.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
        if(false)
            return R.error(511,"永远不会进入");

        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            .or()
            .eq("yuangong_id_number", yuangong.getYuangongIdNumber())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity==null){
            yuangong.setCreateTime(new Date());
            yuangong.setPassword("123456");
            yuangongService.insert(yuangong);
            return R.ok();
        }else {
            return R.error(511,"账户或者员工手机号或者员工身份证号已经被使用");
        }
    }

    /**
    * 后端修改
    */
    @RequestMapping("/update")
    public R update(@RequestBody YuangongEntity yuangong, HttpServletRequest request){
        logger.debug("update方法:,,Controller:{},,yuangong:{}",this.getClass().getName(),yuangong.toString());

        String role = String.valueOf(request.getSession().getAttribute("role"));
//        if(false)
//            return R.error(511,"永远不会进入");
        //根据字段查询是否有相同数据
        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .notIn("id",yuangong.getId())
            .andNew()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            .or()
            .eq("yuangong_id_number", yuangong.getYuangongIdNumber())
            ;

        logger.info("sql语句:"+queryWrapper.getSqlSegment());
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if("".equals(yuangong.getYuangongPhoto()) || "null".equals(yuangong.getYuangongPhoto())){
                yuangong.setYuangongPhoto(null);
        }
        if(yuangongEntity==null){
            yuangongService.updateById(yuangong);//根据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());
        yuangongService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }


    /**
     * 批量上传
     */
    @RequestMapping("/batchInsert")
    public R save( String fileName){
        logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
        try {
            List<YuangongEntity> yuangongList = new ArrayList<>();//上传的东西
            Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段
            Date date = new Date();
            int lastIndexOf = fileName.lastIndexOf(".");
            if(lastIndexOf == -1){
                return R.error(511,"该文件没有后缀");
            }else{
                String suffix = fileName.substring(lastIndexOf);
                if(!".xls".equals(suffix)){
                    return R.error(511,"只支持后缀为xls的excel文件");
                }else{
                    URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
                    File file = new File(resource.getFile());
                    if(!file.exists()){
                        return R.error(511,"找不到上传文件,请联系管理员");
                    }else{
                        List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
                        dataList.remove(0);//删除第一行,因为第一行是提示
                        for(List<String> data:dataList){
                            //循环
                            YuangongEntity yuangongEntity = new YuangongEntity();
//                            yuangongEntity.setUsername(data.get(0));                    //账户 要改的
//                            //yuangongEntity.setPassword("123456");//密码
//                            yuangongEntity.setYuangongName(data.get(0));                    //员工姓名 要改的
//                            yuangongEntity.setYuangongPhone(data.get(0));                    //员工手机号 要改的
//                            yuangongEntity.setYuangongIdNumber(data.get(0));                    //员工身份证号 要改的
//                            yuangongEntity.setYuangongPhoto("");//照片
//                            yuangongEntity.setSexTypes(Integer.valueOf(data.get(0)));   //性别 要改的
//                            yuangongEntity.setYuangongEmail(data.get(0));                    //电子邮箱 要改的
//                            yuangongEntity.setCreateTime(date);//时间
                            yuangongList.add(yuangongEntity);


                            //把要查询是否重复的字段放入map中
                                //账户
                                if(seachFields.containsKey("username")){
                                    List<String> username = seachFields.get("username");
                                    username.add(data.get(0));//要改的
                                }else{
                                    List<String> username = new ArrayList<>();
                                    username.add(data.get(0));//要改的
                                    seachFields.put("username",username);
                                }
                                //员工手机号
                                if(seachFields.containsKey("yuangongPhone")){
                                    List<String> yuangongPhone = seachFields.get("yuangongPhone");
                                    yuangongPhone.add(data.get(0));//要改的
                                }else{
                                    List<String> yuangongPhone = new ArrayList<>();
                                    yuangongPhone.add(data.get(0));//要改的
                                    seachFields.put("yuangongPhone",yuangongPhone);
                                }
                                //员工身份证号
                                if(seachFields.containsKey("yuangongIdNumber")){
                                    List<String> yuangongIdNumber = seachFields.get("yuangongIdNumber");
                                    yuangongIdNumber.add(data.get(0));//要改的
                                }else{
                                    List<String> yuangongIdNumber = new ArrayList<>();
                                    yuangongIdNumber.add(data.get(0));//要改的
                                    seachFields.put("yuangongIdNumber",yuangongIdNumber);
                                }
                        }

                        //查询是否重复
                         //账户
                        List<YuangongEntity> yuangongEntities_username = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("username", seachFields.get("username")));
                        if(yuangongEntities_username.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_username){
                                repeatFields.add(s.getUsername());
                            }
                            return R.error(511,"数据库的该表中的 [账户] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //员工手机号
                        List<YuangongEntity> yuangongEntities_yuangongPhone = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("yuangong_phone", seachFields.get("yuangongPhone")));
                        if(yuangongEntities_yuangongPhone.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_yuangongPhone){
                                repeatFields.add(s.getYuangongPhone());
                            }
                            return R.error(511,"数据库的该表中的 [员工手机号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                         //员工身份证号
                        List<YuangongEntity> yuangongEntities_yuangongIdNumber = yuangongService.selectList(new EntityWrapper<YuangongEntity>().in("yuangong_id_number", seachFields.get("yuangongIdNumber")));
                        if(yuangongEntities_yuangongIdNumber.size() >0 ){
                            ArrayList<String> repeatFields = new ArrayList<>();
                            for(YuangongEntity s:yuangongEntities_yuangongIdNumber){
                                repeatFields.add(s.getYuangongIdNumber());
                            }
                            return R.error(511,"数据库的该表中的 [员工身份证号] 字段已经存在 存在数据为:"+repeatFields.toString());
                        }
                        yuangongService.insertBatch(yuangongList);
                        return R.ok();
                    }
                }
            }
        }catch (Exception e){
            return R.error(511,"批量插入数据异常,请联系管理员");
        }
    }


    /**
    * 登录
    */
    @IgnoreAuth
    @RequestMapping(value = "/login")
    public R login(String username, String password, String captcha, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("username", username));
        if(yuangong==null || !yuangong.getPassword().equals(password))
            return R.error("账号或密码不正确");
        //  // 获取监听器中的字典表
        // ServletContext servletContext = ContextLoader.getCurrentWebApplicationContext().getServletContext();
        // Map<String, Map<Integer, String>> dictionaryMap= (Map<String, Map<Integer, String>>) servletContext.getAttribute("dictionaryMap");
        // Map<Integer, String> role_types = dictionaryMap.get("role_types");
        // role_types.get(.getRoleTypes());
        String token = tokenService.generateToken(yuangong.getId(),username, "yuangong", "员工");
        R r = R.ok();
        r.put("token", token);
        r.put("role","员工");
        r.put("username",yuangong.getYuangongName());
        r.put("tableName","yuangong");
        r.put("userId",yuangong.getId());
        return r;
    }

    /**
    * 注册
    */
    @IgnoreAuth
    @PostMapping(value = "/register")
    public R register(@RequestBody YuangongEntity yuangong){
//    	ValidatorUtils.validateEntity(user);
        Wrapper<YuangongEntity> queryWrapper = new EntityWrapper<YuangongEntity>()
            .eq("username", yuangong.getUsername())
            .or()
            .eq("yuangong_phone", yuangong.getYuangongPhone())
            .or()
            .eq("yuangong_id_number", yuangong.getYuangongIdNumber())
            ;
        YuangongEntity yuangongEntity = yuangongService.selectOne(queryWrapper);
        if(yuangongEntity != null)
            return R.error("账户或者员工手机号或者员工身份证号已经被使用");
        yuangong.setCreateTime(new Date());
        yuangongService.insert(yuangong);
        return R.ok();
    }

    /**
     * 重置密码
     */
    @GetMapping(value = "/resetPassword")
    public R resetPassword(Integer  id){
        YuangongEntity yuangong = new YuangongEntity();
        yuangong.setPassword("123456");
        yuangong.setId(id);
        yuangongService.updateById(yuangong);
        return R.ok();
    }


    /**
     * 忘记密码
     */
    @IgnoreAuth
    @RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request) {
        YuangongEntity yuangong = yuangongService.selectOne(new EntityWrapper<YuangongEntity>().eq("username", username));
        if(yuangong!=null){
            yuangong.setPassword("123456");
            boolean b = yuangongService.updateById(yuangong);
            if(!b){
               return R.error();
            }
        }else{
           return R.error("账号不存在");
        }
        return R.ok();
    }


    /**
    * 获取用户的session用户信息
    */
    @RequestMapping("/session")
    public R getCurrYuangong(HttpServletRequest request){
        Integer id = (Integer)request.getSession().getAttribute("userId");
        YuangongEntity yuangong = yuangongService.selectById(id);
        if(yuangong !=null){
            //entity转view
            YuangongView view = new YuangongView();
            BeanUtils.copyProperties( yuangong , view );//把实体数据重构到view中

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


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





}

5.1.3 供应商管理

该功能主要用于实现对供应商基本信息的管理,供应商管理界面的运行效果见图5.3。在此界面,管理员对供应商的信用等级,供应商名称,还有供应商的类型进行添加,当供应商信息比较多时,就需要管理员使用查询功能对供应商信息进行查询,查询前只需要在查询框中编辑供应商名称即可查询。

图5.3 供应商管理界面

5.1.4 销售管理

销售管理界面的运行效果见图5.4。在此界面,管理员查看销售药品的员工信息以及销售的药品信息,可以更改药品销售数据,可以使用销售编号实现对销售药品的查询。

图5.4 销售管理界面

5.1.5 销售药品统计报表

销售药品统计报表界面的运行效果见图5.5。在此界面,管理员查看各种药品的销售数量信息,同时管理员可以下载销售药品统计报表,可以把销售药品统计报表在柱状图与折线图之间进行切换。

图5.5 销售药品统计报表界面

大家点赞、收藏、关注、评论啦  其他的定制服务 商务合作  下方联系卡片↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 或者私信作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

翰文编程

你的鼓励 是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值