package com.murong.ecp.app.mbu.action.bmbuurm8;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.murong.ecp.app.mbu.common.BuiMessageCode;
import com.murong.ecp.app.mbu.dao.bmbuurm8.XyHealthDictMapper;
import com.murong.ecp.app.pub.atc.PUBATCUtil;
import com.yuangou.ecp.biz.transengine.AbstractTransaction;
import com.yuangou.ecp.biz.transengine.Utils;
import com.yuangou.ecp.bp.core.common.exception.YGException;
import com.yuangou.ecp.bp.core.common.message.YGBizMessage;
import com.yuangou.ecp.bp.core.common.message.YGBizMessageContext;
import com.yuangou.ecp.bp.core.common.message.YGEDB;
import com.yuangou.ecp.bp.core.common.yglog4j.Logger;
import com.yuangou.ecp.bp.core.common.yglog4j.YGLogger;

@Service("healthdictexport")
public class XyHealthDictExportAction extends AbstractTransaction{

@Autowired
XyHealthDictMapper xyHealthDictMapper;

@Override
public void doProcess(YGBizMessageContext bizCtx) throws YGException {
YGBizMessage yGBizMessage = bizCtx.getCurrentMsg();
Logger logger = YGLogger.getLogger(yGBizMessage);
YGEDB edb = yGBizMessage.getEDBBody();
edb.setData("rsp_ajx", "true");
PUBATCUtil.GDASetMsg(bizCtx, BuiMessageCode.SUCCESS, "");
logger.info("导出医疗字典到js文件start");

logger.info("开启游标:");
PUBATCUtil.openCursor(bizCtx, "qryHealthDictList", "healthDictListCursor");
logger.info("开启游标:");

List<String> typList = new ArrayList<>();
//将数据拼接成字符串
StringBuffer stringBuffer=new StringBuffer("var mrdict = new Object();");
int i=0;
while (true) {
PUBATCUtil.fetchCursor(bizCtx, "healthDictListCursor", "healthDictListCursor"+i);
if (Utils.eval(bizCtx, "~retcod=2")) {
logger.info("关闭游标:11");
PUBATCUtil.closeCursor(bizCtx, "healthDictListCursor");
logger.info("关闭游标:12");
break;
}else{
String idStr = edb.getData("healthDictListCursor"+i+".id");
String textStr = edb.getData("healthDictListCursor"+i+".text");
String typStr = edb.getData("healthDictListCursor"+i+".typ");
//直接拼接
logger.info("i======================================="+i);
if (typList.contains(typStr)) {
stringBuffer.append(",").append("\""+idStr+"\":\""+textStr+"\"");
}else {
//先将typName放入Set,再拼接
typList.add(typStr);
//非首次进入判断才追加"}"
if (i != 0) {
stringBuffer.append("};");
}
stringBuffer.append("\n").append("mrdict.").append(typStr).append("={\""+idStr+"\":\""+textStr+"\"");
}
i++;
}
}
logger.info("游标执行总数="+i);

logger.info("关闭游标:21");
PUBATCUtil.closeCursor(bizCtx, "healthDictListCursor");
logger.info("关闭游标:22");

String line = "\r\n";
String t ="\t";
String fn = "Formatter = function(val,row) {"+line+t+
"var data = mrdict.";
String fn1 = line+t+"try { "+line+t+
"if( !data.hasOwnProperty(val) ) {"+line+t+
"return val;"+line+t+
"}"+line+t+
" } catch(error) {"+line+t+
"console.error(error);"+line+t+
"return val;"+line+t+
" }"+line+t+
"return data[val];"+line+
"}";
stringBuffer.append("};");
for (int j = 0; j < typList.size(); j++) {
stringBuffer.append("\n").append("mrdict.").append(typList.get(j)).append(fn).append(typList.get(j)+";").append(fn1);
}
//上传到服务器的位置
String path = "/home/iver/ejbs/mrbui/healthDict.js";

try {
OutputStream output = new FileOutputStream(path);
byte[] date=stringBuffer.toString().getBytes();

output.write(date);
output.close();
logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

} catch (Exception e) {
logger.info("医疗字典导出js文件异常");
logger.info(e);
}

PUBATCUtil.GDASetMsg(bizCtx, "CMM00000", "");

logger.info("导出医疗字典到js文件over");

}

}

读取 excel文件组装字典数据的更多相关文章

  1. 用python的pandas读取excel文件中的数据

    一.读取Excel文件   使用pandas的read_excel()方法,可通过文件路径直接读取.注意到,在一个excel文件中有多个sheet,因此,对excel文件的读取实际上是读取指定文件.并 ...

  2. .Net读取Excel文件时丢失数据的问题 (转载)

    相信很多人都试过通过OleDB读取Excel文件,这种方法效率十分高,只是有一点会让人十分头痛,就是当一列中既有混合型数据,又有纯数据时,往往容易丢失数据. 百度过后,改连接字符串 “HDR=YES; ...

  3. matlab读取excel文件中的数据

    1.读取sheet1中的所有数据 1.1首先我们建立一个sheet表,表名为‘111’ 1.2 默认这些文本以及数字都放在sheet1中,我们将此excel选入当前工作目录(必要步骤), 选入当前工作 ...

  4. gridview读取Excel文件中的数据,并将其导入数据库

    原文发布时间为:2008-10-16 -- 来源于本人的百度文章 [由搬家工具导入] //将需要导入的文件上传到服务器           string filePath = "" ...

  5. java 读取Excel文件并数据持久化方法Demo

    import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util ...

  6. spring boot 使用 POI 读取Excel文件

    内容简介 本文主要介绍使用POI进行Excel文件的相关操作,涉及读取文件,获取sheet表格,对单元格内容进行读写操作,以及合并单元格的操作. Excel文件目录 Excel模板文件存了resour ...

  7. 如何在C#中打开和读取EXCEL文件

    这篇文章向您展示如何在C#Windows Forms Application中使用ExcelDataReader,ExcelDataReader.DataSet打开和读取Excel文件.创建一个新的W ...

  8. 上传读取Excel文件数据

    /// <summary> /// 上传读取Excel文件数据 /// 来自http://www.cnblogs.com/cielwater /// </summary> // ...

  9. python xlwt模块生成excel文件并写入数据 xlrd读取数据

    python中一般使用 xlwt (excel write)来生成Excel文件(可以控制单元格格式),用 xlrd 来读取Excel文件,用xlrd读取excel是不能对其进行操作的. 1.xlrd ...

随机推荐

  1. web自动化-绕过登录

    两个方法: 1.常用的方法: 第一种方法是登录后查看网站的 cookie,请求 url 的时候把 cookie 带上(缺点是:cookie有时间限制.优点:简单,方便) 2.添加cookies的方式: ...

  2. 天池新闻推荐比赛1:赛题理解+baseline

    天池新闻推荐比赛1:赛题理解+baseline 一.比赛信息 比赛链接: ​ https://tianchi.aliyun.com/competition/entrance/531842/inform ...

  3. CentOS7系统tab命令补全

    在新安装的CentOS7系统中,如果没有安装命令补全的话,在systemctl管理服务的时候就没法用tab来自动补全,因此在安装完系统后,我们要再安装命令补全这个软件: yum -y install ...

  4. 自动化运维工具之Puppet变量、正则表达式、流程控制、类和模板

    前文我们了解了puppet的file.exec.cron.notify这四种核心资源类型的使用以及资源见定义通知/订阅关系,回顾请参考https://www.cnblogs.com/qiuhom-18 ...

  5. DBeaver连接达梦|虚谷|人大金仓等国产数据库

    前言 工作中有些项目可能会接触到「达梦.虚谷.人大金仓」等国产数据库,但通常这些数据库自带的连接工具使用并不方便,所以这篇文章记录一下 DBeaver 连接国产数据库的通用模版,下文以达梦为例(其他国 ...

  6. IdentityServer4系列 | 简化模式

    一.前言 从上一篇关于资源密码凭证模式中,通过使用client_id和client_secret以及用户名密码通过应用Client(客户端)直接获取,从而请求获取受保护的资源,但是这种方式存在clie ...

  7. HTTP协议数据包

    HTTP数据包 简介:由w3c制定的一种网络应用层协议,定义了浏览器与web服务器之间通信时所使用的数据格式. 0x00 数据包格式 1.请求行:请求类型/请求资源路径.协议的版本和类型 2.请求头: ...

  8. 02day

    1.python注释(不执行) #:单行注释 ''' '''或者""" """:多行注释 2.python2中文解决方法 #coding=u ...

  9. Python学习随笔:PyCharm的错误检测使用及调整配置减少错误数量

    老猿使用PyCharm有将近一个月了,发现PyCharm并不能很好的完成语法检查,有时运行时突然终止,仔细核查却发现是基本的语法错误,不过有次无意中移动鼠标到代码最右边的边框时发现其实PyCharm有 ...

  10. WPF中DatePiker值绑定以及精简查询

    WPF中DatePiker值绑定以及精简查询 1.WPF中DatePiker值绑定 Xaml中值绑定使用Text <DatePicker Text="{Binding strMinDa ...