123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package com.zskk.control;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.NodeList;
- import com.jfinal.core.Controller;
- import com.jfinal.kit.PropKit;
- import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
- import com.jfinal.plugin.activerecord.Db;
- import com.jfinal.plugin.activerecord.Record;
- import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
- import com.jfinal.plugin.druid.DruidPlugin;
- import com.zskk.tools.ExecUtil;
- import com.zskk.tools.XmlHelper;
- import okhttp3.FormBody;
- import okhttp3.MediaType;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- public class ViewController extends Controller {
- private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
- private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
- /**
- * 在被连接数据库执行sql语句
- */
- public void executeSql() {
- List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
- this.renderJson(d);
- }
-
- public void exe() {
- String dateString = parseStringToDate();
- String fileString = dateString.replace("0", "o");
- String execCmd = ExecUtil.execCmd("/zskk_system/other/cfind.sh " + dateString + " STUDYUID_" + fileString + ".xml");
- if (execCmd.contains("Connection refused")) {
- return;
- }
- this.renderText(execCmd);
- }
- public void testConn() {
- try {
- DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
- druidPluginConnected.start();
- // 配置ActiveRecord插件
- ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
- arpConnected.setDialect(new SqlServerDialect());
- arpConnected.start();
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- public void tempmatch() {
- String fileName2String ="";
- // List<String> files = new ArrayList<String>();
- // File file = new File("/home/zskk/CFIND_XML");
- // File[] tempList = file.listFiles();
- // for (int m = 0; m < tempList.length; m++) {
- // if (tempList[m].isFile()) {
- // files.add(tempList[m].toString());
- // //文件名,不包含路径
- // String fileName = tempList[m].getName();
- // fileName2String = fileName2String+fileName+"**";
- File fin_floder = new File("/home/zskk/CFIND_XML/tt51.xml");
- // 创建从文件读取数据的FileInputStream流
- FileInputStream fin;
- try {
- fin = new FileInputStream(fin_floder);
- InputStreamReader isr = null;
- isr = new InputStreamReader(fin);
- BufferedReader raf = null;
- raf = new BufferedReader(isr);
- String xmlContent = null;
- xmlContent = raf.readLine();
- xmlContent = xmlContent.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
- xmlContent = "<zskk>" + xmlContent + "</zskk>";
- XmlHelper xmlHelper = XmlHelper.of(xmlContent);
- fileName2String = xmlContent;
- // NativeDicomModel节点列表
- NodeList nativeDicomModelList = xmlHelper.getNodeList("/zskk/NativeDicomModel");
- for (int i = 0; i < nativeDicomModelList.getLength(); i++) {
- String qString = "";
- String studyuidString = "";
- String modalitiesString = "";
- // DicomAttribute节点列表
- NodeList dicomAttributeList = xmlHelper.getNodeList(nativeDicomModelList.item(i), "DicomAttribute");
- for (int j = 0; j < dicomAttributeList.getLength(); j++) {
- // DicomAttribute节点属性列表
- NamedNodeMap attributeMap = dicomAttributeList.item(j).getAttributes();
- if (attributeMap != null && attributeMap.getLength() > 0) {
- for (int k = 0; k < attributeMap.getLength(); k++) {
- if (attributeMap.item(k).getNodeName().equals("tag")) {
- // 获取studyuid
- if (attributeMap.item(k).getNodeValue().equals("0020000D")) {
- studyuidString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
- continue;
- }
- // 获取检查类型
- if (attributeMap.item(k).getNodeValue().equals("00080061")) {
- modalitiesString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
- }
- }
- }
- }
- }
- Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
- studyuidString);
- if (studyidfind == null) {
- Record studyinfo = new Record().set("studyuid", studyuidString).set("modalities", modalitiesString)
- .set("status", 1).set("createAt", parseStringToDateTime()).set("updateAt", parseStringToDateTime());
- Db.use("local").save("study", studyinfo);
- }
- }
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- this.renderText(e.toString());
- }
- // }
- // if (tempList[m].isDirectory()) {
- // //这里就不递归了,
- // }
- //
- // }
- this.renderText(fileName2String);
- }
- public static DruidPlugin createConnectedDruidPlugin() {
- return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
- }
-
- /**
- * post请求
- * @param url-请求地址
- * @param map-参数集合
- * @return
- */
- private static String doPost(String url, Map<String, String> map) {
- FormBody.Builder builder = new FormBody.Builder();
- for (String key : map.keySet()) {
- builder.add(key, map.get(key));
- }
- RequestBody formBody = builder.build();
- Request request = new Request.Builder().url(url).post(formBody).build();
-
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
-
- private String parseStringToDate() {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
- Date date = new Date();
- long dInteger = date.getTime();
- String daString = sdf.format(new Date(dInteger));
- return daString;
- }
-
- /**
- * 日期字符串格式转换年月日时分秒
- *
- * @param dateStr
- * @return
- */
- private String parseStringToDateTime() {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = new Date();
- String daString = sdf.format(date);
- return daString;
- }
- }
|