You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HTML/src/Houduan/index1.js

1794 lines
74 KiB

const express = require('express');
const app = express();
const mysql = require('mysql');
const fs = require('fs');
const { exec } = require('child_process');
const http = require('http');
const querystring = require('querystring');
function dj(){
}
function arrayToCsv(data) {
return data.map(row => row.map(field => {
// 如果 field 不是字符串,先转换为字符串
const strField = field.toString();
// 然后进行替换操作
return `"${strField.replace(/"/g, '""')}"`;
}).join(',')).join('\n');
}
// 创建连接对象
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
// 开启连接
connection.connect();
var asd=' ';
// 执行查询
connection.query('Select * from 账户;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
asd = results;
console.log(results);
});
// 关闭连接
connection.end();
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', 'http://127.0.0.1:5500'); // 替换为您的前端应用域名
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.setHeader("Content-Security-Policy", "default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'")
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
//登录账户
app.get('/', (req, res) => {
if (req.method === 'POST'){
}else{
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 账户;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
asd = results;
res.send(asd);
});
connection.end();
}
});
app.post('/', (req, res) => {
if (req.method === 'POST'){
console.log("ssssssssss");
let body = '';
req.on('data', chunk => {
body += chunk.toString(); // 转换为字符串
});
req.on('end', () => {
// 解析POST参数
console.log(body);
const postParams = JSON.parse(body);
// 处理POST参数
console.log('POST parameters:', postParams);
var abc = ' ';
//注册账户
if (postParams.wenti == 0){
console.log("注册账户。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('insert into 账户 values ("'+String(postParams.用户名)+'","'+String(postParams.密码)+'")'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = {"账户注册情况":'成功',"用户名":String(postParams.用户名),"密码":String(postParams.密码)};
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询药库
if (postParams.wenti == 1){
console.log("查询药库。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 主页面 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查找药品
if (postParams.wenti ==2){
console.log("查找药品。");
// console.log(postParams);
// var as = String(postParams.id);
// console.log(as);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
var sortnum = 0;
findid1='';
if (postParams.id!=null){
//console.log(postParams.id);
findid1+=' where id = ';
findid1+=String(postParams.id);
sortnum++;
}
findtype1='';
if (postParams.type!=null){
//console.log(postParams.type);
if (sortnum!=0){
findtype1+=' and ';
findtype1+=' type like ';
findtype1+='"%'+String(postParams.type)+'%"';
sortnum++;
console.log(findtype1);
}
else{
findtype1+=' where type like ';
findtype1+='"%'+String(postParams.type)+'%"';
sortnum++;
}
}
findname1='';
if(postParams.name!=null){
//console.log(postParams.name);
if (sortnum!=0){
findname1+=' and ';
findname1+=' name like ';
findname1+='"%'+String(postParams.name)+'%"';
sortnum++;
}
else{
findname1+=' where name like ';
findname1+='"%'+String(postParams.name)+'%"';
sortnum++;
}
}
findprice1='';
if (postParams.price!=null){
//console.log(postParams.price);
if (sortnum!=0){
findprice1+=' and ';
findprice1+=' price = ';
findprice1+=String(postParams.price);
sortnum++;
}
else{
findprice1+=' where price = ';
findprice1+=String(postParams.price);
sortnum++;
}
}
findamount1='';
if (postParams.amount!=null){
if (sortnum!=0){
findamount1+=' and ';
findamount1+=' amount =';
findamount1+=String(postParams.amount);
sortnum++;
}
else{
findamount1+=' where amount = ';
findamount1+=String(postParams.amount);
sortnum++;
}
}
// connection.connect();
connection.query('Select * from 主页面'+findid1+findtype1+findname1+findprice1+findamount1+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//修改药品信息
if (postParams.wenti ==3){
console.log("修改药品信息。");
console.log(postParams);
const currentTime = new Date();
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
if (postParams.type==null && postParams.name==null && postParams.price==null && postParams.amount==null ){
console.log('没有说明要修改的字段');
}
else{
//修改主页面药品信息
sortnum2=0;
findid2 = '';
findid2 = String(postParams.id);
findtype2 = '';
if (postParams.type != null){
findtype2 += ' type = ';
findtype2 += ' "'+String(postParams.type)+'" ';
sortnum2++;
}
findname2 = '';
if (postParams.name != null){
if (sortnum2 == 0){
findname2 += 'name =';
findname2 += ' "'+String(postParams.name)+'" ';
sortnum2++;
}
else{
findname2 += ' , ';
findname2 += 'name =';
findname2 += ' "'+String(postParams.name)+'" ';
sortnum2++;
}
}
findprice2 = '';
if (postParams.price != null){
if (sortnum2 == 0){
findprice2 += 'price = ';
findprice2 += ' '+String(postParams.price)+' ';
sortnum2++;
}
else{
findprice2 += ' , ';
findprice2 += 'price = ';
findprice2 += ' '+String(postParams.price)+' ';
sortnum2++;
}
}
findamount2 = '';
if (postParams.amount != null){
if (sortnum2 == 0){
findamount2 += 'amount = ';
findamount2 += ' '+String(postParams.amount)+' ';
sortnum2++;
}
else{
findamount2 += ' , ';
findamount2 += 'amount = ';
findamount2 += ' '+String(postParams.amount)+' ';
sortnum2++;
}
}
//修改具体药品类型表
var sortnum21 = 0;
findname21 = '';
if (postParams.name != null){
if (sortnum21 == 0){
findname21 += 'name =';
findname21 += ' "'+String(postParams.name)+'" ';
sortnum21++;
}
else{
findname21 += ' , ';
findname21 += 'name =';
findname21 += ' "'+String(postParams.name)+'" ';
sortnum21++;
}
}
findprice21= '';
if (postParams.price != null){
if (sortnum21 == 0){
findprice21 += 'price = ';
findprice21 += ' '+String(postParams.price)+' ';
sortnum21++;
}
else{
findprice21 += ' , ';
findprice21 += 'price = ';
findprice21 += ' '+String(postParams.price)+' ';
sortnum21++;
}
}
findamount21 = '';
if (postParams.amount != null){
if (sortnum21 == 0){
findamount21 += 'amount = ';
findamount21 += ' '+String(postParams.amount)+' ';
sortnum21++;
}
else{
findamount21 += ' , ';
findamount21 += 'amount = ';
findamount21 += ' '+String(postParams.amount)+' ';
sortnum21++;
}
}
//如果数量发生变化,自动生成出库或进库记录
if (postParams.amount != postParams.amounted){
console.log(postParams.amount - postParams.amounted);
if (postParams.amount > postParams.amounted){//添加进库药品统计
console.log('insert into 进库药品统计 (name,company,phonenumber,price,purprice) select name,company,phonenumber,price,purprice from ' + String(postParams.type) + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) +';');
console.log(' update 进库药品统计 set amount = ' + String(postParams.amount - postParams.amounted) + ' , '+ 'time = ' + '"' + currentTime.toLocaleString()+ '" ' + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) + ' and time is NULL and amount is NULL'+';');
connection.query('insert into 进库药品统计 (name,company,phonenumber,price,purprice) select name,company,phonenumber,price,purprice from ' + String(postParams.type) + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) +';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query(' update 进库药品统计 set amount = ' + String(postParams.amount - postParams.amounted) + ' , '+ 'time = ' + '"' + currentTime.toLocaleString()+ '" ' + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) + ' and time is NULL and amount is NULL'+';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
}
else if (postParams.amount < postParams.amounted){//添加出库药品统计
console.log('insert into 出库药品统计 (name,company,phonenumber,price,purprice) select name,company,phonenumber,price,purprice from ' + String(postParams.type) + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) +';');
console.log(' update 出库药品统计 set amount = ' + String(postParams.amounted - postParams.amount) + ' , '+ 'time = ' + '"' + currentTime.toLocaleString()+ '" ' + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) + ' and time is NULL and amount is NULL'+';');
connection.query('insert into 出库药品统计 (name,company,phonenumber,price,purprice) select name,company,phonenumber,price,purprice from ' + String(postParams.type) + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) +';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query(' update 出库药品统计 set amount = ' + String(postParams.amounted - postParams.amount) + ' , '+ 'time = ' + '"' + currentTime.toLocaleString()+ '" ' + ' where name = ' + '"' + String(postParams.nameed) + '"' + ' and price = ' + String(postParams.priceed) + ' and time is NULL and amount is NULL'+';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
}
}
//执行数据库操作
console.log(' update '+ String(postParams.type) + ' set ' + findname21 + findprice21 + findamount21 + ' where name = "' + String(postParams.nameed) + '" and price = ' + String(postParams.priceed) + ';');
console.log(' update 主页面 set ' + findtype2 + findname2 + findprice2 + findamount2 +' where id = '+findid2+';');
if (sortnum2 != 0){
connection.query(' update 主页面 set ' + findtype2 + findname2 + findprice2 + findamount2 +' where id = '+findid2+';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query(' update '+ String(postParams.type) + ' set ' + findname21 + findprice21 + findamount21 + ' where name = "' + String(postParams.nameed) + '" and price = ' + String(postParams.priceed) + ';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
}
}
connection.query('Select * from 主页面 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
//console.log(results.length)
});
connection.end();
}
//删除药品
if (postParams.wenti ==4){
console.log("删除药品。");
console.log(postParams);
const currentTime = new Date();
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
sortnum3 = 0;
if (postParams.id == null){
console.log('没有待删除的药品的序号');
}
else{
findid3 = ' where id = ';
if (postParams.id != null){
findid3 += String(postParams.id);
findid3 += ' ';
sortnum3++;
}
findname3 = '';
if (postParams.name != null){
if (sortnum3 != 0){
findname3 += ' and ';
findname3 += ' name = ';
findname3 += ' "';
findname3 += String(postParams.name);
findname3 += '" ';
}
}
findtype3 = String(postParams.type);
findname31 = ' where name = ';
findname31 += ' "';
findname31 += String(postParams.name);
findname31 += '" ';
findprice3 = 'and price = ';
findprice3 += parseFloat(postParams.price);
findtime3 = '"' + currentTime.toLocaleString()+ '"';
// console.log('delete from '+ findtype3 + findname31 + findprice3+';');
// console.log('insert into 出库药品统计 (name,company,phonenumber,amount,price) select * from ' + findtype3 + findname31 + findprice3+';');
// console.log('update 出库药品统计 set time = ' + findtime3 + findname31 + findprice3+';');
connection.query('insert into 出库药品统计 (name,company,phonenumber,amount,price,purprice) select name,company,phonenumber,amount,price,purprice from ' + findtype3 + findname31 + findprice3+';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query('update 出库药品统计 set time = ' + findtime3 + findname31 + findprice3+ ' and time is NULL' +';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query('delete from '+ findtype3 + findname31 + findprice3+';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query(' delete from 主页面 ' + findid3 + findname3+';', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
}
connection.query('Select * from 主页面 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
//console.log(results.length)
});
connection.end();
}
//添加药品
if (postParams.wenti == 5){
console.log("添加药品。");
console.log(postParams);
const currentTime = new Date();
//console.log((currentTime.toLocaleString()));
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
findid4 = String(postParams.id);
findtype4 = '"' + String(postParams.type)+ '"';
findtype41 = String(postParams.type);
findname4 = '"' + String(postParams.name)+ '"';
findprice4 = String(postParams.price);
findpurprice4 = String(postParams.purprice);
findamount4 = String(postParams.amount);
findcompany4 = '"' + String(postParams.company)+ '"';
findphonenumber4 = '"' + String(postParams.phonenumber)+ '"';
findtime4 = '"' + currentTime.toLocaleString()+ '"';
//console.log(' insert into 主页面 values ('+ findid4 + ',' + findtype4 + ',' + findname4 + ',' + findprice4 + ',' + findamount4 +');');
//console.log(' insert into '+findtype41+' values ('+ findname4 + ',' + findcompany4 + ',' + findphonenumber4 + ',' + findprice4 + ',' + findamount4 +');');
connection.query(' insert into 主页面 values ('+ findid4 + ',' + findtype4 + ',' + findname4 + ',' + findprice4 + ',' + findamount4 +');', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query(' insert into '+findtype41+' values ('+ findname4 + ',' + findcompany4 + ',' + findphonenumber4 + ',' + findprice4 + ',' + findamount4 +','+ findpurprice4+');', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query(' insert into '+'进库药品统计'+' values ('+ findname4 + ',' + findcompany4 + ',' + findphonenumber4 + ',' + findamount4 + ',' + findprice4 + ',' + findpurprice4 + ',' +findtime4+');', (error, results, fields) => {
if (error) throw error;
//console.log(results);
// 处理查询结果
});
connection.query('Select * from 主页面 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询呼吸系统药
if (postParams.wenti == 11){
console.log("查询呼吸系统药。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 呼吸系统药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询消化系统药
if (postParams.wenti == 21){
console.log("查询消化系统药。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 消化系统药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询皮肤科用药
if (postParams.wenti == 31){
console.log("查询皮肤科用药。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 皮肤科用药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询心血管系统药
if (postParams.wenti == 41){
console.log("查询心血管系统药。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 心血管系统药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询眼科用药
if (postParams.wenti == 51){
console.log("查询眼科用药。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 眼科用药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询骨科用药
if (postParams.wenti == 61){
console.log("查询骨科用药。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 骨科用药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询出库药品统计
if (postParams.wenti == 71){
console.log("查询出库药品统计。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 出库药品统计 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//查询进库药品统计
if (postParams.wenti == 81){
console.log("查询进库药品统计。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 进库药品统计 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
//导入csv数据
if (postParams.wenti==1001){
//导入数据到主页面
if (postParams.table == '主页面'){
console.log(postParams.table);
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.id != null && date.price != null && date.amount !=null){
console.log('insert into 主页面 values ('+String(date.id)+','+'"'+String(date.type)+'","'+String(date.name)+'",'+String(date.price)+','+String(date.amount)+');');
connection.query('insert into 主页面 values ('+String(date.id)+','+'"'+String(date.type)+'","'+String(date.name)+'",'+String(date.price)+','+String(date.amount)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到骨科用药
if (postParams.table == '骨科用药'){
console.log(postParams.table);
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 骨科用药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');');
connection.query('insert into 骨科用药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到眼科用药
if (postParams.table == '眼科用药'){
console.log(postParams.table);
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 眼科用药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');');
connection.query('insert into 眼科用药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到皮肤科用药
if (postParams.table == '皮肤科用药'){
console.log(postParams.table);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 皮肤科用药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');');
connection.query('insert into 皮肤科用药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到呼吸系统药
if (postParams.table == '呼吸系统药'){
console.log(postParams.table);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 呼吸系统药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');');
connection.query('insert into 呼吸系统药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到消化系统药
if (postParams.table == '消化系统药'){
console.log(postParams.table);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 消化系统药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');');
connection.query('insert into 消化系统药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到心血管系统药
if (postParams.table == '心血管系统药'){
console.log(postParams.table);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 心血管系统药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');');
connection.query('insert into 心血管系统药 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.price)+','+String(date.amount)+','+String(date.purprice)+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到进库药品统计
if (postParams.table == '进库药品统计'){
console.log(postParams.table);
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 进库药品统计 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.amount)+','+String(date.price)+','+String(date.purprice)+','+'"'+String(date.time)+'"'+');');
connection.query('insert into 进库药品统计 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.amount)+','+String(date.price)+','+String(date.purprice)+','+'"'+String(date.time)+'"'+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
//导入数据到出库药品统计
if (postParams.table == '出库药品统计'){
console.log(postParams.table);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
for (i =0;i<postParams.shuju.length;i++){
console.log(postParams.shuju[i]);
const date = postParams.shuju[i];
if (date.price != null && date.amount !=null && date.purprice!= null){
console.log('insert into 出库药品统计 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.amount)+','+String(date.price)+','+String(date.purprice)+','+'"'+String(date.time)+'"'+');');
connection.query('insert into 出库药品统计 values (' + '"' + String(date.name) + '",'+'"'+String(date.company)+'","'+String(date.phonenumber)+'",'+String(date.amount)+','+String(date.price)+','+String(date.purprice)+','+'"'+String(date.time)+'"'+');', (error, results, fields) => {
if (error) throw error;
console.log(results);
});
}
}
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
}
}
//导出csv数据
if (postParams.wenti==1002){
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select * from 主页面;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["id","type","name","price","amount"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].id),String(shuju[i].type),String(shuju[i].name),String(shuju[i].price),String(shuju[i].amount)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/主页面.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 眼科用药;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/眼科用药.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 骨科用药;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/骨科用药.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 皮肤科用药;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/皮肤科用药.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 呼吸系统药;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/呼吸系统药.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 消化系统药;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/消化系统药.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 心血管系统药;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/心血管系统药.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 出库药品统计;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","amount","price","purprice","time"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].amount),String(shuju[i].price),String(shuju[i].purprice),String(shuju[i].time)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/出库药品统计.csv';
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('Select * from 进库药品统计;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["name","company","phonenumber","amount","price","purprice","time"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].amount),String(shuju[i].price),String(shuju[i].purprice),String(shuju[i].time)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/进库药品统计.csv';
const Dir = __dirname;
console.log(Dir);
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
connection.query('select 主页面.id ,主页面.type,主页面.name,眼科用药.company,眼科用药.phonenumber,眼科用药.price,眼科用药.amount,眼科用药.purprice from 主页面,眼科用药 where 主页面.name = 眼科用药.name and 主页面.price = 眼科用药.price union all select 主页面.id ,主页面.type,主页面.name,骨科用药.company,骨科用药.phonenumber,骨科用药.price,骨科用药.amount,骨科用药.purprice from 主页面,骨科用药 where 主页面.name = 骨科用药.name and 主页面.price = 骨科用药.price union all select 主页面.id ,主页面.type,主页面.name,皮肤科用药.company,皮肤科用药.phonenumber,皮肤科用药.price,皮肤科用药.amount,皮肤科用药.purprice from 主页面,皮肤科用药 where 主页面.name = 皮肤科用药.name and 主页面.price = 皮肤科用药.price union all select 主页面.id ,主页面.type,主页面.name,呼吸系统药.company,呼吸系统药.phonenumber,呼吸系统药.price,呼吸系统药.amount,呼吸系统药.purprice from 主页面,呼吸系统药 where 主页面.name = 呼吸系统药.name and 主页面.price = 呼吸系统药.price union all select 主页面.id ,主页面.type,主页面.name,消化系统药.company,消化系统药.phonenumber,消化系统药.price,消化系统药.amount,消化系统药.purprice from 主页面,消化系统药 where 主页面.name = 消化系统药.name and 主页面.price = 消化系统药.price union all select 主页面.id ,主页面.type,主页面.name,心血管系统药.company,心血管系统药.phonenumber,心血管系统药.price,心血管系统药.amount,心血管系统药.purprice from 主页面,心血管系统药 where 主页面.name = 心血管系统药.name and 主页面.price = 心血管系统药.price order by id;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
var shuju = results;
var csvData = [];
csvData.push(["id","type","name","company","phonenumber","price","amount","purprice"]);
for (i=0;i<shuju.length;i++){
csvData.push([String(shuju[i].id),String(shuju[i].type),String(shuju[i].name),String(shuju[i].company),String(shuju[i].phonenumber),String(shuju[i].price),String(shuju[i].amount),String(shuju[i].purprice)]);
}
// CSV 字符串
var csvString = arrayToCsv(csvData);
csvString="\uFEFF"+csvString;
// 要写入的文件路径(当前文件夹)
const filePath = 'D:/迁移/总共信息.csv';
const Dir = __dirname;
console.log(Dir);
// 写入文件
fs.writeFile(filePath, csvString, { encoding: 'utf8' },(err) => {
if (err) throw err;
console.log('CSV 文件已被保存到:', filePath);
});
});
//关闭连接
connection.end();
var abc = ' ';
abc = '已经收到并处理完消息';
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
const command = "explorer D:\\迁移";
exec(command, (error, stdout, stderr) => {
});
}
if (postParams.wenti == 20011){
console.log("药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select name,amount from 骨科用药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20012){
console.log("药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select name,amount from 皮肤科用药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20013){
console.log("药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select name,amount from 眼科用药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20014){
console.log("药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select name,amount from 呼吸系统药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20015){
console.log("药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select name,amount from 消化系统药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20016){
console.log("药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('Select name,amount from 心血管系统药 '+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20021){
console.log("出库药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select left(time,9) AS name,round((price-purprice)*amount,2) AS value from 出库药品统计;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20022){
console.log("出库药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select left(time,9) AS name,round((price-purprice)*amount,2) AS value from 出库药品统计 where time like '+'"%'+String(postParams.data)+'%"'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20023){
console.log("出库药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select name from 出库药品统计'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20024){
console.log("出库药品数量统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select left(time,9) AS name,round((price-purprice)*amount,2) AS value from 出库药品统计 where name like '+'"%'+String(postParams.data)+'%"'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20031){
console.log("药品支出统计分析。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select left(time,9) AS name,round(purprice*amount,2) AS value from 进库药品统计;', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20032){
console.log("药品支出统计。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select left(time,9) AS name,round(purprice*amount,2) AS value from 进库药品统计 where time like '+'"%'+String(postParams.data)+'%"'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20033){
console.log("药品支出统计。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select name from 进库药品统计'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
if (postParams.wenti == 20034){
console.log("药品支出统计。");
console.log(postParams);
const connection = mysql.createConnection({
host: 'localhost', // 数据库服务器地址
user: 'root', // 数据库用户名
password: 'CYH123456', // 数据库密码
database: 'cyh1' // 要连接的数据库名
});
connection.connect();
connection.query('select left(time,9) AS name,round(purprice*amount,2) AS value from 进库药品统计 where name like '+'"%'+String(postParams.data)+'%"'+';', (error, results, fields) => {
if (error) throw error;
// 处理查询结果
abc = results;
res.writeHead(200, {'Content-Type': 'application/json'});
const responseData = abc ;
// 发送响应数据
res.end(JSON.stringify(responseData));
//console.log(JSON.stringify(responseData));
});
connection.end();
}
// res.writeHead(200, {'Content-Type': 'application/json'});
// const responseData = {name:'POST request received'} ;
// // 发送响应数据
// res.end(JSON.stringify(responseData));
// console.log(JSON.stringify(responseData));
});
}
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});