From 727df755f0d32a7370e37a9f831f0e7660e15537 Mon Sep 17 00:00:00 2001 From: lzy Date: Mon, 8 Nov 2021 17:04:20 +0800 Subject: [PATCH] =?UTF-8?q?bgts=E5=9F=BA=E6=9C=AC=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E6=90=AD=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docus-ws-bgts/lombok.config | 1 + docus-ws-bgts/pom.xml | 87 +++++++++++++++++++ .../java/com/docus/bgts/DemoApplication.java | 13 +++ .../docus/bgts/config/MybatisPlusConfig.java | 66 ++++++++++++++ .../docus/bgts/config/WebServiceConfig.java | 30 +++++++ .../main/java/com/docus/bgts/enums/Codes.java | 49 +++++++++++ .../docus/bgts/handler/ITBasicWebService.java | 10 +++ .../docus/bgts/handler/TBasicWebService.java | 9 ++ .../java/com/docus/bgts/utils/JsonUtils.java | 44 ++++++++++ .../com/docus/bgts/utils/ResultUtils.java | 84 ++++++++++++++++++ .../java/com/docus/bgts/utils/XmlUtils.java | 67 ++++++++++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/application.yml | 19 ++++ 13 files changed, 480 insertions(+) create mode 100644 docus-ws-bgts/lombok.config create mode 100644 docus-ws-bgts/pom.xml create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/DemoApplication.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/config/MybatisPlusConfig.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/config/WebServiceConfig.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/utils/JsonUtils.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/utils/ResultUtils.java create mode 100644 docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java create mode 100644 docus-ws-bgts/src/main/resources/application.properties create mode 100644 docus-ws-bgts/src/main/resources/application.yml diff --git a/docus-ws-bgts/lombok.config b/docus-ws-bgts/lombok.config new file mode 100644 index 0000000..4f55f03 --- /dev/null +++ b/docus-ws-bgts/lombok.config @@ -0,0 +1 @@ +lombok.var.flagUsage = ALLOW \ No newline at end of file diff --git a/docus-ws-bgts/pom.xml b/docus-ws-bgts/pom.xml new file mode 100644 index 0000000..f54b48f --- /dev/null +++ b/docus-ws-bgts/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.5.6 + + + com.docus + demo + 0.0.1-SNAPSHOT + web service + Demo project for Spring Boot + + 1.8 + + + + org.springframework.boot + spring-boot-starter + + + + org.dom4j + dom4j + 2.1.1 + + + + jaxen + jaxen + 1.1.1 + + + com.alibaba + fastjson + 1.2.75 + + + mysql + mysql-connector-java + 8.0.15 + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + 1.16.14 + + + com.spring4all + swagger-spring-boot-starter + 1.9.0.RELEASE + + + + org.apache.commons + commons-lang3 + 3.4 + + + com.baomidou + mybatis-plus-boot-starter + 3.3.0 + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/DemoApplication.java b/docus-ws-bgts/src/main/java/com/docus/bgts/DemoApplication.java new file mode 100644 index 0000000..8d488e8 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/DemoApplication.java @@ -0,0 +1,13 @@ +package com.docus.bgts; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/config/MybatisPlusConfig.java b/docus-ws-bgts/src/main/java/com/docus/bgts/config/MybatisPlusConfig.java new file mode 100644 index 0000000..be9705c --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/config/MybatisPlusConfig.java @@ -0,0 +1,66 @@ +package com.docus.bgts.config; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties; +import com.baomidou.mybatisplus.core.MybatisConfiguration; +import com.baomidou.mybatisplus.core.config.GlobalConfig; +import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; +import lombok.RequiredArgsConstructor; +import lombok.experimental.var; +import org.apache.ibatis.logging.nologging.NoLoggingImpl; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.annotation.PostConstruct; +import java.util.Objects; + +@Configuration +@RequiredArgsConstructor +@EnableTransactionManagement +@MapperScan("com.docus.bgts.mapper") +@ConditionalOnClass(value = {PaginationInterceptor.class}) +public class MybatisPlusConfig { + + + private final MybatisPlusProperties mybatisPlusProperties; + @Bean + public PaginationInterceptor paginationInterceptor() { + PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); + return paginationInterceptor; + } + + @PostConstruct + public void initMybatisConfig(){ + mybatisPlusProperties.setMapperLocations(new String[]{"classpath*:/mapper/*Mapper.xml"}); + mybatisPlusProperties.setTypeAliasesPackage("com.docus.bgts.entity"); + + MybatisConfiguration configuration = mybatisPlusProperties.getConfiguration(); + if(Objects.isNull(configuration)){ + configuration=new MybatisConfiguration(); + } + configuration.setMapUnderscoreToCamelCase(true); + configuration.setCacheEnabled(true); + configuration.setLogImpl(NoLoggingImpl.class); + mybatisPlusProperties.setConfiguration(configuration); + + var globalConfig = mybatisPlusProperties.getGlobalConfig(); + if(Objects.isNull(globalConfig)){ + globalConfig=new GlobalConfig(); + } + GlobalConfig.DbConfig dbConfig = globalConfig.getDbConfig(); + if(Objects.isNull(dbConfig)){ + dbConfig=new GlobalConfig.DbConfig(); + } + configuration.setCallSettersOnNulls(true); + dbConfig.setIdType(IdType.ASSIGN_ID); + dbConfig.setTableUnderline(true); + dbConfig.setLogicDeleteValue("1"); + dbConfig.setLogicNotDeleteValue("0"); + dbConfig.setLogicDeleteField("def_flag"); + globalConfig.setDbConfig(dbConfig); + globalConfig.setBanner(false); + } +} \ No newline at end of file diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/config/WebServiceConfig.java b/docus-ws-bgts/src/main/java/com/docus/bgts/config/WebServiceConfig.java new file mode 100644 index 0000000..2f803db --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/config/WebServiceConfig.java @@ -0,0 +1,30 @@ +package com.docus.bgts.config; + + + +import com.docus.bgts.enums.Codes; +import com.docus.bgts.handler.ITBasicWebService; +import com.docus.bgts.handler.TBasicWebService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.xml.ws.Endpoint; + +@Configuration +public class WebServiceConfig { + //把实现类交给spring管理 + @Bean + public ITBasicWebService tBasicWebService() { + return new TBasicWebService(); + } + + @Bean + public Endpoint endpoint() { + System.out.println("-----------------------web service服务已发布-------------------------"); + String address = "http://"+"0.0.0.0"+":" + Codes.EXTERNAL.getCode()+"/" + Codes.EXTERNAL.getMessage(); + Endpoint publish = Endpoint.publish(address, tBasicWebService()); + System.out.println(" "+address); + return publish; + } + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java b/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java new file mode 100644 index 0000000..9f9b975 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/enums/Codes.java @@ -0,0 +1,49 @@ +package com.docus.bgts.enums; + +/** + * 代码库 + */ +public enum Codes { + //接口成功 + SUCCESS("0", "成功"), + //接口失败 + ERROR("1", "失败"), + //web service返回根节点 + RESPONSE("100","Response"), + //web service返回二级节点 + RET_INFO("101","RetInfo"), + //web service 返回代码 + RET_CODE("102","RetCode"), + //web service返回描述部分 + RET_CON("103","RetCon"), + //web service 服务名 + EXTERNAL("9201","docus_tBasic_data"), + //静态文件存放位置 + JSON_ADDRESS("999","\\dataConfig\\homeQualitySet.json"), + //接收二级节点 + MSG("201","Msg"), + //错误日志编号 + ERROR_CODE("500","12"), + //接收三级节点 +// PAT_INFO("202","PatInfo"), + //静态文件根元素名 + SELECT_COLUMNS("10000","selectColumns") + ; + //代码 + private String code; + //描述 + private String message; + + private Codes(String code, String messgae) { + this.code = code; + this.message = messgae; + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java new file mode 100644 index 0000000..bccf620 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/ITBasicWebService.java @@ -0,0 +1,10 @@ +package com.docus.bgts.handler; + + +import javax.jws.WebService; + +@WebService +public interface ITBasicWebService { + + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java new file mode 100644 index 0000000..8867e91 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/handler/TBasicWebService.java @@ -0,0 +1,9 @@ +package com.docus.bgts.handler; + + +import javax.jws.WebService; + +@WebService +public class TBasicWebService implements ITBasicWebService { + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/JsonUtils.java b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/JsonUtils.java new file mode 100644 index 0000000..ddc6be0 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/JsonUtils.java @@ -0,0 +1,44 @@ +package com.docus.bgts.utils; + +import java.io.*; + +/** + * json工具类 + */ +public class JsonUtils { + + /** + * 读取json文件方法 + * @param fileName:json文件存在的本地地址 + * @return + */ + public static String readJsonFile(String fileName) { + String jsonStr = ""; + Reader reader=null; + FileReader fileReader=null; + try { + File jsonFile = new File(fileName); + fileReader = new FileReader(jsonFile); + reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8"); + int ch = 0; + StringBuffer sb = new StringBuffer(); + while ((ch = reader.read()) != -1) { + sb.append((char) ch); + } + fileReader.close(); + reader.close(); + jsonStr = sb.toString(); + return jsonStr; + } catch (IOException e) { + e.printStackTrace(); + return null; + }finally { + try { + reader.close(); + fileReader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/ResultUtils.java b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/ResultUtils.java new file mode 100644 index 0000000..7456c60 --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/ResultUtils.java @@ -0,0 +1,84 @@ +package com.docus.bgts.utils; + + +import com.docus.bgts.enums.Codes; +import org.apache.commons.lang3.StringUtils; +import org.dom4j.Document; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; + +/** + * 返回结果工具类 + */ +public class ResultUtils { + /** + * 通过document对象返回节点对象 + * @param response + * @return + */ + public static Element getElement(Document response){ + Element element = response.getRootElement(); + return element; + } + + /** + * 成功返回 + * @return + */ + public static Document success(){ + // 1、创建document对象 + Document document= DocumentHelper.createDocument(); + //2.创建根节点 + Element response=document.addElement(Codes.RESPONSE.getMessage()); + // 3、生成子节点及子节点内容 + Element RetInfo = response.addElement(Codes.RET_INFO.getMessage()); + //4.生成代码和描述节点 + Element resCode = RetInfo.addElement(Codes.RET_CODE.getMessage()); + Element retCon = RetInfo.addElement(Codes.RET_CON.getMessage()); + //赋值 + resCode.setText(String.valueOf(Codes.SUCCESS.getCode())); + retCon.setText(Codes.SUCCESS.getMessage()); + return document; + } + + /** + * 失败返回 + * @return + */ + public static String fail(){ + // 1、创建document对象 + Document document= DocumentHelper.createDocument(); + //2.创建根节点 + Element response=document.addElement(Codes.RESPONSE.getMessage()); + // 3、生成子节点及子节点内容 + Element RetInfo = response.addElement(Codes.RET_INFO.getMessage()); + //4.生成代码和描述节点 + Element resCode = RetInfo.addElement(Codes.RET_CODE.getMessage()); + Element retCon = RetInfo.addElement(Codes.RET_CON.getMessage()); + //赋值 + resCode.setText(String.valueOf(Codes.ERROR.getCode())); + retCon.setText(Codes.ERROR.getMessage()); + return document.asXML(); + } + + /** + * 失败返回 + * @return + */ + public static String fail(String message){ + // 1、创建document对象 + Document document= DocumentHelper.createDocument(); + //2.创建根节点 + Element response=document.addElement(Codes.RESPONSE.getMessage()); + // 3、生成子节点及子节点内容 + Element RetInfo = response.addElement(Codes.RET_INFO.getMessage()); + //4.生成代码和描述节点 + Element resCode = RetInfo.addElement(Codes.RET_CODE.getMessage()); + Element retCon = RetInfo.addElement(Codes.RET_CON.getMessage()); + //赋值 + resCode.setText(String.valueOf(Codes.ERROR.getCode())); + retCon.setText(StringUtils.isNotBlank(message)?message:Codes.ERROR.getMessage()); + return document.asXML(); + } + +} diff --git a/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java new file mode 100644 index 0000000..c00f21f --- /dev/null +++ b/docus-ws-bgts/src/main/java/com/docus/bgts/utils/XmlUtils.java @@ -0,0 +1,67 @@ +package com.docus.bgts.utils; + + +import com.docus.bgts.enums.Codes; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import java.io.InputStream; + +public class XmlUtils { + //定义解析器和文档对象 + private SAXReader saxReader; + private Document document; + + public XmlUtils(String path) { + //获取解析器 + saxReader = new SAXReader(); + try { + //获取文档对象 + document = saxReader.read(path); + } catch (DocumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public XmlUtils(InputStream path) { + //获取解析器 + saxReader = new SAXReader(); + try { + //获取文档对象 + document = saxReader.read(path); + } catch (DocumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * 根据节点名称获取内容 + * + * @param name 节点名称 + * @return 节点内容 + */ + public String getElementText(String name) { + //定位根节点 + Element root = document.getRootElement(); + //根据名称定位节点 + Element msg = root.element(Codes.MSG.getMessage()); + if(msg==null){ + throw new RuntimeException("没有"+Codes.MSG.getMessage()+"节点"); + } +// Element patInfo = msg.element(Codes.PAT_INFO.getMessage()); +// if(patInfo==null){ +// throw new RuntimeException("没有"+Codes.PAT_INFO.getMessage()+"节点"); +// } + Element element = msg.element(name); + if(element==null){ + return null; + } + //返回节点内容 + return element.getText(); + } + +} diff --git a/docus-ws-bgts/src/main/resources/application.properties b/docus-ws-bgts/src/main/resources/application.properties new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/docus-ws-bgts/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/docus-ws-bgts/src/main/resources/application.yml b/docus-ws-bgts/src/main/resources/application.yml new file mode 100644 index 0000000..620ec4e --- /dev/null +++ b/docus-ws-bgts/src/main/resources/application.yml @@ -0,0 +1,19 @@ +server: + port: 9797 + +mybatis-plus: + configuration: + map-underscore-to-camel-case: true + call-setters-on-nulls: true + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + global-config: + db-config: + field-strategy: NOT_EMPTY + db-type: MYSQL + +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: docus + password: docus702 + url: jdbc:mysql://db.docus.cn:3306/docus_medicalrecord?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true \ No newline at end of file