JavaWeb课程设计-药品管理系统/药物管理系统源码
立即下载
资源介绍:
基于Maven的药品管理系统/药物管理系统源码
使用ElementUI插件
实现的功能主要有:
药品信息的增删改查
员工信息的增删改查
敏感词汇的过滤
拦截器、文件上传等功能
还使用ECharts展示药品销量等数据
大概是这样
package cn.edu.hncu.medicine.web.servlet;
import cn.edu.hncu.medicine.domain.ResultInfo;
import cn.edu.hncu.medicine.domain.Supplier;
import cn.edu.hncu.medicine.service.TableService;
import cn.edu.hncu.medicine.service.impl.TableServiceImp;
import cn.edu.hncu.medicine.util.ExcelUtil;
import cn.edu.hncu.medicine.util.LoadFileUtils;
import cn.edu.hncu.medicine.util.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.poi.util.IOUtils;
import sun.tools.jconsole.JConsole;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.xml.ws.RequestWrapper;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.io.IOException;
import static cn.edu.hncu.medicine.util.StringUtils.convertToString;
@WebServlet("/table/*")
public class TableServlet extends BaseServlet {
private TableService service = new TableServiceImp();
private StringUtils stringUtil = new StringUtils();
private String tableNameToFile = "";
private LoadFileUtils fileUtils = new LoadFileUtils();
/**
* 获取表头数据
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void getTableHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String curTableName = request.getParameter("curTableName");
// 传表名 获得表头数据名
// System.out.println("getTableHead-----" + curTableName);
// System.out.println(service.getTableHead(curTableName));
// System.out.println(curTableName);
writeValue(service.getTableHead(curTableName),response);
}
/**
* 获取入库表数据
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void getAllInput(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
writeValue(service.getAllInput(),response);
}
/**
* 获取输出表数据
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void getAllOutput(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
writeValue(service.getAllOutput(),response);
}
/**
* 保质期检查 表数据
* @param request
* @param response
*/
public void getAllGuarantee(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println(service.getAllGuarantee());
writeValue(service.getAllGuarantee(),response);
}
/**
* 点击侧边栏 通过接收表名 获取数据
*/
public void getAllDataByTableName(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String curTableName = request.getParameter("curTableName");
// System.out.println(service.getAllDataByTableName(curTableName));
writeValue(service.getAllDataByTableName(curTableName),response);
}
/**
* 保存 修改的数据
*/
public void saveChange(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
saveAlter(request,response);
}
public void addInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
Map map = request.getParameterMap();
//参数已经获取 以键值对 的形式 {"factoryId":"ff","factoryName":"f","factoryContent":"f","createTime":"sa"}
//map 的值为String[] 直接 map.get("factoryId") 得到的是数组 打印出来是[Ljava.lang.String;@59c8c636
//System.out.println(map.get("factoryId")[0]);
//参数map转成 形式
Map dataMap = new HashMap<>();
for(Map.Entry entry: map.entrySet()){
dataMap.put(entry.getKey(),entry.getValue()[0]);
};
System.out.println(dataMap);
String tableName = dataMap.get("tableName");
//如果是员工表格 交给 userServlet 处理
if("tab_user".equals(tableName)){
new UserServlet().addUser(request,response,"table");
return ;
}
// System.out.println(dataMap.get("inputTime") + "--servlet接受到的字符串格式"); 2024-4-23 12:00:00
dataMap.remove("tableName");
boolean flag = service.addInfo(dataMap,tableName,-1);
ResultInfo resInfo = new ResultInfo();
if(flag){
// 关键字不存在
resInfo.setFlag(true);
}else{
// 关键字存在
resInfo.setFlag(false);
resInfo.setErrorMsg("关键字已经存在,添加失败!");
}
writeValue(resInfo,response);
}
/**
* 查找路径 post请求
*/
public void findStr(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// String keyWord = request.getParameter("searchData"); //搜索的关键字
// String curTableName = request.getParameter("searchTableName"); //搜索表格
String totalData = stringUtil.convertToString(request.getInputStream());
totalData = totalData.trim();
Map searchMap = new HashMap<>();
searchMap = stringUtil.splitParameter(totalData);
// System.out.println(searchMap);
// 传需要找的表名 和关键字
// 获取后端返回的数据 并传输
// 编码问题
// %E7%99%BD%E4%BA%91%E5%B1%B1
// java.net.URLDecoder.decode
String searchData = null;
if(searchMap.get("searchData") != null){
searchData = java.net.URLDecoder.decode(searchMap.get("searchData"),"utf-8");
System.out.println(java.net.URLDecoder.decode(searchMap.get("searchData"),"utf-8") + "----搜索关键字");
}
// System.out.println(service.findTableData(searchMap.get("searchTableName"),searchMap.get("searchData")));
writeValue(service.findTableData(searchMap.get("searchTableName"),searchData),response);
}
/**
* 删除按钮 函数
*/
public void clickDel(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println("row---" + request.getParameter("infoId"));
// System.out.println("table---" + request.getParameter("tableName"));
String infoId = request.getParameter("infoId");
String taleName = request.getParameter("tableName");
boolean success = service.deleteData(taleName,infoId);
ResultInfo info = new ResultInfo();
if(success){
// 删除成功
info.setFlag(true);
}else{
// 删除失败
info.setFlag(false);
info.setErrorMsg("删除失败!请稍后再试。");
}
// 将结果信息对象 传给前端
writeValue(info,response);
}
/**
* 保存修改 按钮
*/
public void saveAlter(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String totalData = stringUtil.convertToString(request.getInputStream());
totalData = totalData.trim();
totalData = java.net.URLDecoder.decode(totalData,"utf-8");
System.out.println("修改函数中的字符串 数据 " + totalData);
资源文件列表:
Medicine_Manager_00.zip 大约有2624个文件