服务端代码
pom文件
<dependencies>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<!-- Spring end -->
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.9</version>
</dependency>
<!-- End CXF -->
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
<!-- fastjson end -->
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<!-- mybatis end -->
<!-- MyBatis Generator -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- MyBatis Generator end -->
<!-- jdbc驱动包 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<!-- jdbc驱动包 end -->
<!-- 添加Servlet支持 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- 添加Servlet支持 end -->
</dependencies>
xml文件
<display-name>cxf_server</display-name>
<!-- 以下3项参数与log4j的配置相关 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:Log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<!-- cxf相关 -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
<!-- Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
spring配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Import apache CXF bean definition 固定 -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- services接口配置 -->
<bean id="getLicensesBean" class="com.axze.zzxc.service.GetLicensesImpl" />
<bean id="getInvoiceBean" class="com.axze.zzxc.service.GetInvoiceImpl" />
<bean id="sendCargoBean" class="com.axze.zzxc.service.SendCargoImpl" />
<bean id="sendDrugCheckBean" class="com.axze.zzxc.service.SendDrugCheckImpl" />
<!-- 拦截器配置 -->
<bean id="getInterceptorBean" class="com.axze.zzxc.interceptor.AuthInterceptor" />
<!-- CXF 配置WebServices的服务名及访问地址 -->
<jaxws:server id="getLicensesService" serviceClass="com.axze.zzxc.service.GetLicensesI"
address="/GetLicenses">
<jaxws:serviceBean>
<ref bean="getLicensesBean" />
</jaxws:serviceBean>
</jaxws:server>
<jaxws:server id="getInvoiceService" serviceClass="com.axze.zzxc.service.GetInvoiceI"
address="/GetInvoice">
<jaxws:serviceBean>
<ref bean="getInvoiceBean" />
</jaxws:serviceBean>
</jaxws:server>
<jaxws:server id="sendCargoIService" serviceClass="com.axze.zzxc.service.SendCargoI"
address="/SendCargo">
<jaxws:serviceBean>
<ref bean="sendCargoBean" />
</jaxws:serviceBean>
</jaxws:server>
<jaxws:server id="sendDrugCheckIService" serviceClass="com.axze.zzxc.service.SendDrugCheckI"
address="/SendDrugCheck">
<jaxws:serviceBean>
<ref bean="sendDrugCheckBean" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
实体类
package com.axze.zzxc.entity;
//证照文件
import javax.activation.DataHandler;
import javax.xml.bind.annotation.XmlMimeType;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "CxfFileWrapper")
public class LicenseFile {
private String fileName;// 文件名
private long fileSize;// 文件大小
private DataHandler file;// 文件二进制数据
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public long getFileSize() {
return fileSize;
}
public void setFileSize(long fileSize) {
this.fileSize = fileSize;
}
// 注解该字段为二进制流
@XmlMimeType("application/octet-stream")
public DataHandler getFile() {
return file;
}
public void setFile(DataHandler file) {
this.file = file;
}
}
package com.axze.zzxc.entity;
//证照文件信息(数据库)
import java.util.Date;
public class LicenseFileInfo {
private int fileid;// 文件id
private int opid;// 功能id
private int pkid;// 证照细单id
private String filename;// 文件名
private int inputmanid;// 录入人
private Date credate;// 创建时间
private int modifymanid;
private Date modifydate;
private long filesize;// 文件大小
private String classname;// 文件分类名称
private String steclassname;
private Date sysModifydate;
private Date syndate;
private String goodsownerlicenseid;// 原货主证照主键id
private int updategoodsownerid;// 上传货主id
public LicenseFileInfo(int fileid, String filename, Date credate, long filesize, String goodsownerlicenseid, int updategoodsownerid) {
super();
this.fileid = fileid;
this.filename = filename;
this.credate = credate;
this.filesize = filesize;
this.goodsownerlicenseid = goodsownerlicenseid;
this.updategoodsownerid = updategoodsownerid;
}
public int getFileid() {
return fileid;
}
public void setFileid(int fileid) {
this.fileid = fileid;
}
public int getOpid() {
return opid;
}
public void setOpid(int opid) {
this.opid = opid;
}
public int getPkid() {
return pkid;
}
public void setPkid(int pkid) {
this.pkid = pkid;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public int getInputmanid() {
return inputmanid;
}
public void setInputmanid(int inputmanid) {
this.inputmanid = inputmanid;
}
public Date getCredate() {
return credate;
}
public void setCredate(Date credate) {
this.credate = credate;
}
public int getModifymanid() {
return modifymanid;
}
public void setModifymanid(int modifymanid) {
this.modifymanid = modifymanid;
}
public Date getModifydate() {
return modifydate;
}
public void setModifydate(Date modifydate) {
this.modifydate = modifydate;
}
public long getFilesize() {
return filesize;
}
public void setFilesize(long filesize) {
this.filesize = filesize;
}
public String getClassname() {
return classname;
}
public void setClassname(String classname) {
this.classname = classname;
}
public String getSteclassname() {
return steclassname;
}
public void setSteclassname(String steclassname) {
this.steclassname = steclassname;
}
public Date getSysModifydate() {
return sysModifydate;
}
public void setSysModifydate(Date sysModifydate) {
this.sysModifydate = sysModifydate;
}
public Date getSyndate() {
return syndate;
}
public void setSyndate(Date syndate) {
this.syndate = syndate;
}
public String getGoodsownerlicenseid() {
return goodsownerlicenseid;
}
public void setGoodsownerlicenseid(String goodsownerlicenseid) {
this.goodsownerlicenseid = goodsownerlicenseid;
}
public int getUpdategoodsownerid() {
return updategoodsownerid;
}
public void setUpdategoodsownerid(int updategoodsownerid) {
this.updategoodsownerid = updategoodsownerid;
}
}
package com.axze.zzxc.entity;
//从货主得到的证照信息
import java.util.Date;
public class LicenseInfoGetFromHZ {
private String secretkey;// 秘钥
private int LicensesType1;// 证照大类型(货主证照,单位证照,货品证照)
private int LicensesType2;// 证照类型(营业执照,经营许可证之类的)
private String licenseno;// 证照编码
private Date signdate;// 签发日期
private Date validstartdate;// 生效日期
private Date validenddate;// 有效期至
private String scopedefidordrugformid;// 经营范围/剂型id
private int goodsownerid;// 货主id
private String gcompanyid;// 货主原单位id
private int companystyle;// 单位类型
private String goodsownid;// 货主原货品id
private String goodsownerlicenseid;// 货主原证照id
private int usestatus;// 证照状态
private String memo;// 备注
public int getCompanystyle() {
return companystyle;
}
public void setCompanystyle(int companystyle) {
this.companystyle = companystyle;
}
public String getSecretkey() {
return secretkey;
}
public void setSecretkey(String secretkey) {
this.secretkey = secretkey;
}
public int getLicensesType1() {
return LicensesType1;
}
public void setLicensesType1(int licensesType1) {
LicensesType1 = licensesType1;
}
public int getLicensesType2() {
return LicensesType2;
}
public void setLicensesType2(int licensesType2) {
LicensesType2 = licensesType2;
}
public String getLicenseno() {
return licenseno;
}
public void setLicenseno(String licenseno) {
this.licenseno = licenseno;
}
public Date getSigndate() {
return signdate;
}
public void setSigndate(Date signdate) {
this.signdate = signdate;
}
public Date getValidstartdate() {
return validstartdate;
}
public void setValidstartdate(Date validstartdate) {
this.validstartdate = validstartdate;
}
public Date getValidenddate() {
return validenddate;
}
public void setValidenddate(Date validenddate) {
this.validenddate = validenddate;
}
public String getScopedefidordrugformid() {
return scopedefidordrugformid;
}
public void setScopedefidordrugformid(String scopedefidordrugformid) {
this.scopedefidordrugformid = scopedefidordrugformid;
}
public int getGoodsownerid() {
return goodsownerid;
}
public void setGoodsownerid(int goodsownerid) {
this.goodsownerid = goodsownerid;
}
public String getGcompanyid() {
return gcompanyid;
}
public void setGcompanyid(String gcompanyid) {
this.gcompanyid = gcompanyid;
}
public String getGoodsownid() {
return goodsownid;
}
public void setGoodsownid(String goodsownid) {
this.goodsownid = goodsownid;
}
public String getGoodsownerlicenseid() {
return goodsownerlicenseid;
}
public void setGoodsownerlicenseid(String goodsownerlicenseid) {
this.goodsownerlicenseid = goodsownerlicenseid;
}
public int getUsestatus() {
return usestatus;
}
public void setUsestatus(int usestatus) {
this.usestatus = usestatus;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
}
package com.axze.zzxc.entity;
//查询数据库用的证照信息
import java.util.Date;
public class LicenseInfoSendDB {
private int licenseid;// 证照细单ID
private int licensesType1;// 证照大类型(货主证照,单位证照,货品证照)
private int licensesType2;// 证照类型(营业执照,经营许可证之类的)
private String licenseno;// 证照编码
private Date signdate;// 签发日期
private Date validstartdate;// 生效日期
private Date validenddate;// 有效期至
private String scopedefidordrugformid;// 经营范围/剂型id
private String scopedefordrugform;// 经营范围/剂型
private int goodsownerid;// 货主id
private long companyid;// 单位id
private long ownergoodsid;// 货主货品id
private Date inputdate;// 录入时间
private String goodsownerlicenseid;// 货主原证照id
private int usestatus;// 证照状态
private String memo;// 备注
public LicenseInfoSendDB() {}
public LicenseInfoSendDB(int licensesType1, int licensesType2, String licenseno, Date signdate, Date validstartdate,
Date validenddate, String scopedefidordrugformid, int goodsownerid, Date inputdate,
String scopedefordrugform, String goodsownerlicenseid, int usestatus, String memo) {
super();
this.licensesType1 = licensesType1;
this.licensesType2 = licensesType2;
this.licenseno = licenseno;
this.signdate = signdate;
this.validstartdate = validstartdate;
this.validenddate = validenddate;
this.scopedefidordrugformid = scopedefidordrugformid;
this.goodsownerid = goodsownerid;
this.inputdate = inputdate;
this.scopedefordrugform = scopedefordrugform;
this.goodsownerlicenseid = goodsownerlicenseid;
this.usestatus = usestatus;
this.memo = memo;
}
public int getLicenseid() {
return licenseid;
}
public void setLicenseid(int licenseid) {
this.licenseid = licenseid;
}
public int getLicensesType1() {
return licensesType1;
}
public void setLicensesType1(int licensesType1) {
this.licensesType1 = licensesType1;
}
public int getLicensesType2() {
return licensesType2;
}
public void setLicensesType2(int licensesType2) {
this.licensesType2 = licensesType2;
}
public String getLicenseno() {
return licenseno;
}
public void setLicenseno(String licenseno) {
this.licenseno = licenseno;
}
public Date getSigndate() {
return signdate;
}
public void setSigndate(Date signdate) {
this.signdate = signdate;
}
public Date getValidstartdate() {
return validstartdate;
}
public void setValidstartdate(Date validstartdate) {
this.validstartdate = validstartdate;
}
public Date getValidenddate() {
return validenddate;
}
public void setValidenddate(Date validenddate) {
this.validenddate = validenddate;
}
public String getScopedefidordrugformid() {
return scopedefidordrugformid;
}
public void setScopedefidordrugformid(String scopedefidordrugformid) {
this.scopedefidordrugformid = scopedefidordrugformid;
}
public String getScopedefordrugform() {
return scopedefordrugform;
}
public void setScopedefordrugform(String scopedefordrugform) {
this.scopedefordrugform = scopedefordrugform;
}
public int getGoodsownerid() {
return goodsownerid;
}
public void setGoodsownerid(int goodsownerid) {
this.goodsownerid = goodsownerid;
}
public long getCompanyid() {
return companyid;
}
public void setCompanyid(long companyid) {
this.companyid = companyid;
}
public long getOwnergoodsid() {
return ownergoodsid;
}
public void setOwnergoodsid(long ownergoodsid) {
this.ownergoodsid = ownergoodsid;
}
public Date getInputdate() {
return inputdate;
}
public void setInputdate(Date inputdate) {
this.inputdate = inputdate;
}
public String getGoodsownerlicenseid() {
return goodsownerlicenseid;
}
public void setGoodsownerlicenseid(String goodsownerlicenseid) {
this.goodsownerlicenseid = goodsownerlicenseid;
}
public int getUsestatus() {
return usestatus;
}
public void setUsestatus(int usestatus) {
this.usestatus = usestatus;
}
public String getMemo() {
return memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
}
dao层的接口类
package com.axze.zzxc.dao;
import com.axze.zzxc.entity.LicenseInfoSendDB;
public interface LicenseInfoMapper {
String getOwnergoodsid(String goodsownid, int goodsownerid);
String getGcompanyidid(String gcompanyid, int goodsownerid, int companystyle);
int totalGoodsownerNumber();
int totalCompanyNumber();
int totalGoodsNumber();
LicenseInfoSendDB getGoodsownerLicensetypeid(String goodsownerlicenseid);
LicenseInfoSendDB getCompanyLicensetypeid(String goodsownerlicenseid);
LicenseInfoSendDB getGoodsLicensetypeid(String goodsownerlicenseid);
int insertGoodsownerLicense(LicenseInfoSendDB record);
int insertCompanyLicense(LicenseInfoSendDB record);
int insertGoodsLicense(LicenseInfoSendDB record);
int updateGoodsownerLicense(LicenseInfoSendDB record);
int updateCompanyLicense(LicenseInfoSendDB record);
int updateGoodsLicense(LicenseInfoSendDB record);
}
package com.axze.zzxc.dao;
import com.axze.zzxc.entity.LicenseFileInfo;
public interface LicenseFileInfoMapper {
int totalLicenseFileNumber();
int insertLicenseFileInfo(LicenseFileInfo record);
int deleteLicenseFileInfoList(String goodsownerlicenseid, int updategoodsownerid);
}
连接数据的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.axze.zzxc.dao.LicenseInfoMapper">
<resultMap id="BaseResultMap" type="com.axze.zzxc.entity.LicenseInfoSendDB">
<id column="LICENSEID" property="licenseid" />
<result column="LICENSETYPEID" property="licensesType2" />
<result column="GOODSOWNERID" property="goodsownerid" />
<result column="LICENSENO" property="licenseno" />
<result column="SIGNDATE" property="signdate" />
<result column="VALIDSTARTDATE" property="validstartdate" />
<result column="VALIDENDDATE" property="validenddate" />
<result column="SCOPEDEFIDS" property="scopedefidordrugformid" />
<result column="INPUTDATE" property="inputdate" />
<result column="SCOPENAMES" property="scopedefordrugform" />
<result column="GOODSOWNERLICENSEID" property="goodsownerlicenseid" />
<result column="USESTATUS" property="usestatus" />
<result column="MEMO" property="memo" />
</resultMap>
<select id="getOwnergoodsid" resultType="String">
select t.ownergoodsid from TPL_GOODS t where t.goodsownid = #{arg0,jdbcType=VARCHAR} and t.goodsownerid = #{arg1}
</select>
<select id="getGcompanyidid" resultType="String">
select t.companyid from TPL_GO_COMPANY t where t.gcompanyid = #{arg0,jdbcType=VARCHAR} and t.goodsownerid = #{arg1} and t.companystyle = #{arg2}
</select>
<select id="totalGoodsownerNumber" parameterType="int" resultType="int">
SELECT MAX(LICENSEID) FROM gsp_goodsowner_license
</select>
<select id="totalCompanyNumber" parameterType="int" resultType="int">
SELECT MAX(LICENSEID) FROM gsp_company_license
</select>
<select id="totalGoodsNumber" parameterType="int" resultType="int">
SELECT MAX(LICENSEID) FROM gsp_goods_license
</select>
<select id="getGoodsownerLicensetypeid" resultMap="BaseResultMap">
select * from gsp_goodsowner_license t where t.goodsownerlicenseid=#{arg0,jdbcType=VARCHAR}
</select>
<select id="getCompanyLicensetypeid" resultMap="BaseResultMap">
select * from gsp_company_license t where t.goodsownerlicenseid=#{arg0,jdbcType=VARCHAR}
</select>
<select id="getGoodsLicensetypeid" resultMap="BaseResultMap">
select * from gsp_goods_license t where t.goodsownerlicenseid=#{arg0,jdbcType=VARCHAR}
</select>
<insert id="insertGoodsownerLicense" parameterType="com.axze.zzxc.entity.LicenseInfoSendDB">
insert into
gsp_goodsowner_license
(LICENSEID,LICENSETYPEID,GOODSOWNERID,LICENSENO,SIGNDATE,VALIDSTARTDATE,VALIDENDDATE,SCOPEDEFIDS,INPUTDATE,SCOPENAMES,GOODSOWNERLICENSEID,USESTATUS,MEMO)
values
(#{licenseid},#{licensesType2},#{goodsownerid},#{licenseno},#{signdate},#{validstartdate},#{validenddate},#{scopedefidordrugformid},#{inputdate},#{scopedefordrugform,jdbcType=VARCHAR},#{goodsownerlicenseid},#{usestatus},#{memo})
</insert>
<insert id="insertCompanyLicense" parameterType="com.axze.zzxc.entity.LicenseInfoSendDB">
insert into
gsp_company_license
(LICENSEID,LICENSETYPEID,COMPANYID,LICENSENO,SIGNDATE,VALIDSTARTDATE,VALIDENDDATE,SCOPEDEFIDS,INPUTDATE,SCOPENAMES,GOODSOWNERLICENSEID,USESTATUS,MEMO)
values
(#{licenseid},#{licensesType2},#{companyid},#{licenseno},#{signdate},#{validstartdate},#{validenddate},#{scopedefidordrugformid},#{inputdate},#{scopedefordrugform,jdbcType=VARCHAR},#{goodsownerlicenseid},#{usestatus},#{memo})
</insert>
<insert id="insertGoodsLicense" parameterType="com.axze.zzxc.entity.LicenseInfoSendDB">
insert into
gsp_goods_license
(LICENSEID,LICENSETYPEID,OWNERGOODSID,LICENSENO,SIGNDATE,VALIDSTARTDATE,VALIDENDDATE,SCOPEDEFIDS,INPUTDATE,SCOPENAMES,GOODSOWNERLICENSEID,USESTATUS,MEMO)
values
(#{licenseid},#{licensesType2},#{ownergoodsid},#{licenseno},#{signdate},#{validstartdate},#{validenddate},#{scopedefidordrugformid},#{inputdate},#{scopedefordrugform,jdbcType=VARCHAR},#{goodsownerlicenseid},#{usestatus},#{memo})
</insert>
<update id="updateGoodsownerLicense" parameterType="com.axze.zzxc.entity.LicenseInfoSendDB">
update
gsp_goodsowner_license set
LICENSEID = #{licenseid},
LICENSETYPEID = #{licensesType2},
GOODSOWNERID = #{goodsownerid},
LICENSENO = #{licenseno},
SIGNDATE = #{signdate},
VALIDSTARTDATE = #{validstartdate},
VALIDENDDATE = #{validenddate},
SCOPEDEFIDS = #{scopedefidordrugformid},
INPUTDATE = #{inputdate},
SCOPENAMES = #{scopedefordrugform,jdbcType=VARCHAR},
GOODSOWNERLICENSEID = #{goodsownerlicenseid},
USESTATUS = #{usestatus},
MEMO = #{memo}
where LICENSEID = #{licenseid}
</update>
<update id="updateCompanyLicense" parameterType="com.axze.zzxc.entity.LicenseInfoSendDB">
update
gsp_company_license set
LICENSEID = #{licenseid},
LICENSETYPEID = #{licensesType2},
COMPANYID = #{companyid},
LICENSENO = #{licenseno},
SIGNDATE = #{signdate},
VALIDSTARTDATE = #{validstartdate},
VALIDENDDATE = #{validenddate},
SCOPEDEFIDS = #{scopedefidordrugformid},
INPUTDATE = #{inputdate},
SCOPENAMES = #{scopedefordrugform,jdbcType=VARCHAR},
GOODSOWNERLICENSEID = #{goodsownerlicenseid},
USESTATUS = #{usestatus},
MEMO = #{memo}
where LICENSEID = #{licenseid}
</update>
<update id="updateGoodsLicense" parameterType="com.axze.zzxc.entity.LicenseInfoSendDB">
update
gsp_goods_license set
LICENSEID = #{licenseid},
LICENSETYPEID = #{licensesType2},
OWNERGOODSID = #{ownergoodsid},
LICENSENO = #{licenseno},
SIGNDATE = #{signdate},
VALIDSTARTDATE = #{validstartdate},
VALIDENDDATE = #{validenddate},
SCOPEDEFIDS = #{scopedefidordrugformid},
INPUTDATE = #{inputdate},
SCOPENAMES = #{scopedefordrugform,jdbcType=VARCHAR},
GOODSOWNERLICENSEID = #{goodsownerlicenseid},
USESTATUS = #{usestatus},
MEMO = #{memo}
where LICENSEID = #{licenseid}
</update>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.axze.zzxc.dao.LicenseFileInfoMapper">
<resultMap id="BaseResultMap" type="com.axze.zzxc.entity.LicenseFileInfo">
<id column="FILEID" jdbcType="DECIMAL" property="fileid" />
<result column="OPID" jdbcType="DECIMAL" property="opid" />
<result column="PKID" jdbcType="DECIMAL" property="pkid" />
<result column="FILENAME" jdbcType="VARCHAR" property="filename" />
<result column="INPUTMANID" jdbcType="DECIMAL" property="inputmanid" />
<result column="CREDATE" jdbcType="TIMESTAMP" property="credate" />
<result column="MODIFYMANID" jdbcType="DECIMAL" property="modifymanid" />
<result column="MODIFYDATE" jdbcType="TIMESTAMP" property="modifydate" />
<result column="FILESIZE" jdbcType="DECIMAL" property="filesize" />
<result column="CLASSNAME" jdbcType="VARCHAR" property="classname" />
<result column="STECLASSNAME" jdbcType="VARCHAR" property="steclassname" />
<result column="SYS_MODIFYDATE" jdbcType="TIMESTAMP" property="sysModifydate" />
<result column="SYNDATE" jdbcType="TIMESTAMP" property="syndate" />
<result column="GOODSOWNERLICENSEID" jdbcType="DECIMAL"
property="goodsownerlicenseid" />
<result column="UPDATEGOODSOWNERID" jdbcType="DECIMAL"
property="updategoodsownerid" />
</resultMap>
<select id="totalLicenseFileNumber" parameterType="int"
resultType="int">
SELECT MAX(FILEID) FROM NP_EFILES_OP_FILE
</select>
<insert id="insertLicenseFileInfo" parameterType="com.axze.zzxc.entity.LicenseFileInfo">
insert into
np_efiles_op_file
(FILEID,OPID,PKID,FILENAME,FILESIZE,CREDATE,CLASSNAME,STECLASSNAME,GOODSOWNERLICENSEID,UPDATEGOODSOWNERID)
values
(#{fileid},#{opid},#{pkid},#{filename},#{filesize},#{credate},#{classname},#{steclassname},#{goodsownerlicenseid},#{updategoodsownerid})
</insert>
<delete id="deleteLicenseFileInfoList">
delete from np_efiles_op_file where
GOODSOWNERLICENSEID = #{arg0} and
UPDATEGOODSOWNERID = #{arg1}
</delete>
</mapper>
业务接口类
package com.axze.zzxc.service;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.axze.zzxc.entity.LicenseFile;
@WebService(name = "FileWS", targetNamespace = "http://www.tmp.com/services/file")
public interface GetLicensesI {
/**
* 文件上传
* @param file 文件上传包装类
* @return 上传成功返回true,上传失败返回false。
* @throws Exception
*/
@WebMethod
String getLicenses(@WebParam(name = "file") List<LicenseFile> file,String json) throws Exception;
}
业务实现类
package com.axze.zzxc.service;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;
import javax.jws.WebService;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.axze.zzxc.dao.BusiScopeMapper;
import com.axze.zzxc.dao.LicenseFileInfoMapper;
import com.axze.zzxc.dao.LicenseInfoMapper;
import com.axze.zzxc.dao.LicenseSecretkeyMapper;
import com.axze.zzxc.dao.Tpl_DrugformMapper;
import com.axze.zzxc.entity.BusiScope;
import com.axze.zzxc.entity.LicenseFile;
import com.axze.zzxc.entity.LicenseFileInfo;
import com.axze.zzxc.entity.LicenseInfoGetFromHZ;
import com.axze.zzxc.entity.LicenseInfoSendDB;
import com.axze.zzxc.entity.LicenseSecretkey;
import com.axze.zzxc.entity.Tpl_Drugform;
import com.axze.zzxc.tools.MyBatisUtil;
@Component("fileWS")
@WebService
public class GetLicensesImpl implements GetLicensesI {
@Override
public String getLicenses(List<LicenseFile> file, String json) throws Exception {
Logger log = Logger.getLogger(GetLicensesImpl.class);
long start = System.currentTimeMillis();
String result = null;
SqlSession ss = MyBatisUtil.getSqlSession();
LicenseInfoMapper lim = ss.getMapper(LicenseInfoMapper.class);
BusiScopeMapper bsm = ss.getMapper(BusiScopeMapper.class);
Tpl_DrugformMapper tdm = ss.getMapper(Tpl_DrugformMapper.class);
LicenseFileInfoMapper Lfim = ss.getMapper(LicenseFileInfoMapper.class);
LicenseSecretkeyMapper lskm = ss.getMapper(LicenseSecretkeyMapper.class);
LicenseInfoGetFromHZ lig = JSON.parseObject(json, LicenseInfoGetFromHZ.class);
List<LicenseSecretkey> selectByPrimaryKey = lskm.selectByPrimaryKey(lig.getGoodsownerid(), lig.getSecretkey(), 1);
if (!(null != selectByPrimaryKey && 1 == selectByPrimaryKey.size())) {
throw new Exception("货主id或秘钥错误,传输失败!");
}
String scopedefidordrugformid = lig.getScopedefidordrugformid();
String scopedefordrugform = null;
if (null != scopedefidordrugformid && (lig.getLicensesType2() == 2 || lig.getLicensesType2() == 41)) {
scopedefordrugform = productionOrOperation(lig.getLicensesType2(), scopedefidordrugformid, bsm, tdm);
} else {
scopedefidordrugformid = "";
}
LicenseInfoSendDB lis = new LicenseInfoSendDB(lig.getLicensesType1(), lig.getLicensesType2(),
lig.getLicenseno(), lig.getSigndate(), lig.getValidstartdate(), lig.getValidenddate(),
scopedefidordrugformid, lig.getGoodsownerid(), new Date(), scopedefordrugform,
lig.getGoodsownerlicenseid(), lig.getUsestatus(), lig.getMemo());
int opid = 0;
int pkid = 0;
String classname = "";
String steclassname = "";
if(0 == lig.getLicensesType1()) {
throw new Exception("证照的大类型(LicensesType1)选择错误,请选择:1.货主证照2.企业证照3.货品证照");
}
if(null == lig.getGoodsownerlicenseid() || "".equals(lig.getGoodsownerlicenseid())) {
throw new Exception("货主原证照id(goodsownerlicenseid)不能为空");
}
if (1 == lig.getLicensesType1()) {
result = uploadGoodsownerLicense(opid, pkid, classname, steclassname, lim, lis, lig, file, Lfim);
}
if (2 == lig.getLicensesType1()) {
String companyid = lim.getGcompanyidid(lig.getGcompanyid(), lig.getGoodsownerid(), lig.getCompanystyle());
if (null == companyid) {
throw new Exception("没有该企业,请先新增企业总单,再添加证照!");
}
lis.setCompanyid(Long.parseLong(companyid));
result = uploadCompanyLicense(opid, pkid, classname, steclassname, lim, lis, lig, file, Lfim);
}
if (3 == lig.getLicensesType1()) {
String ownergoodsid = lim.getOwnergoodsid(lig.getGoodsownid(), lig.getGoodsownerid());
if (null == ownergoodsid) {
throw new Exception("没有该货品,请先新增货品总单,再添加证照!");
}
lis.setOwnergoodsid(Long.parseLong(ownergoodsid));
result = uploadGoodsLicense(opid, pkid, classname, steclassname, lim, lis, lig, file, Lfim);
}
ss.commit();
long end = System.currentTimeMillis();
log.info("parameter:" + json + "\n" + "result:" + result + "\n" + "time:" + (end - start) + "hs");
return result;
}
/**
* 上传文件
*
* @param file
* 文件集合
* @param opid
* 功能id
* @param pkid
* 细单id
* @param classname
* 文件分类名称
* @param steclassname
* 位置
* @return
*/
public String uploadFile(List<LicenseFile> file, int opid, int pkid, String classname, String steclassname) {
String result = null;
OutputStream os = null;
InputStream is = null;
BufferedOutputStream bos = null;
try {
for (LicenseFile licenseFile : file) {
is = licenseFile.getFile().getInputStream();
String path = getUrl(opid, pkid, steclassname, steclassname);
File dest1 = new File(path);
if (!dest1.exists()) {
dest1.mkdirs();
}
File dest = new File(path + licenseFile.getFileName());
os = new FileOutputStream(dest);
bos = new BufferedOutputStream(os);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.flush();
}
result = "证照传输成功";
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (Exception e) {
}
}
if (os != null) {
try {
os.close();
} catch (Exception e) {
}
}
if (is != null) {
try {
is.close();
} catch (Exception e) {
}
}
}
return result;
}
/**
* 判断是药品经营许可还是生产许可
*
* @param LicensesType2
* @param scopedefidsordrugformids
* @param bsm
* @return
* @throws Exception
*/
public String productionOrOperation(int LicensesType2, String scopedefidsordrugformids, BusiScopeMapper bsm,
Tpl_DrugformMapper tdm) throws Exception {
String productionOrOperation = null;
if (LicensesType2 == 2) {
productionOrOperation = getScopenames(scopedefidsordrugformids, bsm);
}
if (LicensesType2 == 41) {
productionOrOperation = getDrugform(scopedefidsordrugformids, tdm);
}
return productionOrOperation;
}
/**
* 获取经营范围
*
* @param scopedefid
* 经营范围id数组json
* @param bsm
* @return
* @throws Exception
*/
public String getScopenames(String scopedefid, BusiScopeMapper bsm) throws Exception {
String scopenames = null;
System.out.println(scopedefid);
if (!"".equals(scopedefid)) {
String[] scopedefids = scopedefid.split(",");
int[] scopedefids2 = new int[scopedefids.length];
for (int i = 0; i < scopedefids.length; i++) {
scopedefids2[i] = Integer.parseInt(scopedefids[i]);
}
List<BusiScope> selectBusiScope = bsm.selectBusiScope(scopedefids2);
for (BusiScope busiScope : selectBusiScope) {
if (null == scopenames) {
scopenames = busiScope.getScopename() + ",";
} else {
scopenames = scopenames + busiScope.getScopename() + ",";
}
}
scopenames = scopenames.substring(0, scopenames.length() - 1);
} else {
throw new Exception("药品经营许可证必须指定经营范围!");
}
return scopenames;
}
/**
* 获取剂型
*
* @param drugformid
* 剂型数组json
* @param bsm
* @return
* @throws Exception
*/
public String getDrugform(String drugformid, Tpl_DrugformMapper tdm) throws Exception {
String drugform = null;
if (!"".equals(drugformid)) {
String[] drugformids = drugformid.split(",");
int[] drugformids2 = new int[drugformids.length];
for (int i = 0; i < drugformids.length; i++) {
drugformids2[i] = Integer.parseInt(drugformids[i]);
}
List<Tpl_Drugform> selectDrugform = tdm.selectDrugform(drugformids2);
for (Tpl_Drugform dpl_drugform : selectDrugform) {
if (null == drugform) {
drugform = dpl_drugform.getDrugform() + ",";
} else {
drugform = drugform + dpl_drugform.getDrugform() + ",";
}
}
drugform = drugform.substring(0, drugform.length() - 1);
} else {
throw new Exception("药品生产许可证必须指定剂型!");
}
return drugform;
}
/**
* 上传货主证照
*
* @param opid
* @param pkid
* @param classname
* @param steclassname
* @param lim
* @param lis
* @param lig
* @param file
* @param Lfim
*/
public String uploadGoodsownerLicense(int opid, int pkid, String classname, String steclassname,
LicenseInfoMapper lim, LicenseInfoSendDB lis, LicenseInfoGetFromHZ lig, List<LicenseFile> file,
LicenseFileInfoMapper Lfim) {
opid = 10009;
classname = "货主证照";
steclassname = "货主证照";
if (null == lim.getGoodsownerLicensetypeid(lig.getGoodsownerlicenseid())) {
pkid = lim.totalGoodsownerNumber() + 1;
lis.setLicenseid(pkid);
lim.insertGoodsownerLicense(lis);
} else {
pkid = lim.getGoodsownerLicensetypeid(lig.getGoodsownerlicenseid()).getLicenseid();
lis.setLicenseid(pkid);
lim.updateGoodsownerLicense(lis);
Lfim.deleteLicenseFileInfoList(lig.getGoodsownerlicenseid(), lig.getGoodsownerid());
deleteDir(new File(getUrl(opid, pkid, steclassname, steclassname)));
}
for (LicenseFile licenseFile : file) {
LicenseFileInfo lfi = new LicenseFileInfo(Lfim.totalLicenseFileNumber() + 1, licenseFile.getFileName(),
new Date(), licenseFile.getFileSize(), lig.getGoodsownerlicenseid(), lig.getGoodsownerid());
insertFileInfo(lfi, Lfim, opid, pkid, classname, steclassname);
}
return uploadFile(file, opid, pkid, classname, steclassname);
}
/**
* 上传企业证照
*
* @param opid
* @param pkid
* @param classname
* @param steclassname
* @param lim
* @param lis
* @param lig
* @param file
* @param Lfim
* @return
*/
public String uploadCompanyLicense(int opid, int pkid, String classname, String steclassname, LicenseInfoMapper lim,
LicenseInfoSendDB lis, LicenseInfoGetFromHZ lig, List<LicenseFile> file, LicenseFileInfoMapper Lfim) {
opid = 7112;
classname = "企业证照";
steclassname = "证照信息";
if (null == lim.getCompanyLicensetypeid(lig.getGoodsownerlicenseid())) {
pkid = lim.totalCompanyNumber() + 1;
lis.setLicenseid(pkid);
lim.insertCompanyLicense(lis);
} else {
pkid = lim.getCompanyLicensetypeid(lig.getGoodsownerlicenseid()).getLicenseid();
lis.setLicenseid(pkid);
lim.updateCompanyLicense(lis);
Lfim.deleteLicenseFileInfoList(lig.getGoodsownerlicenseid(), lig.getGoodsownerid());
deleteDir(new File(getUrl(opid, pkid, steclassname, steclassname)));
}
for (LicenseFile licenseFile : file) {
LicenseFileInfo lfi = new LicenseFileInfo(Lfim.totalLicenseFileNumber() + 1, licenseFile.getFileName(),
new Date(), licenseFile.getFileSize(), lig.getGoodsownerlicenseid(), lig.getGoodsownerid());
insertFileInfo(lfi, Lfim, opid, pkid, classname, steclassname);
}
return uploadFile(file, opid, pkid, classname, steclassname);
}
/**
* 上传货品证照
*
* @param opid
* @param pkid
* @param classname
* @param steclassname
* @param lim
* @param lis
* @param lig
* @param file
* @param Lfim
* @return
*/
public String uploadGoodsLicense(int opid, int pkid, String classname, String steclassname, LicenseInfoMapper lim,
LicenseInfoSendDB lis, LicenseInfoGetFromHZ lig, List<LicenseFile> file, LicenseFileInfoMapper Lfim) {
opid = 10063;
classname = "货品证照";
steclassname = "货品证照";
if (null == lim.getGoodsLicensetypeid(lig.getGoodsownerlicenseid())) {
pkid = lim.totalGoodsNumber() + 1;
lis.setLicenseid(pkid);
lim.insertGoodsLicense(lis);
} else {
pkid = lim.getGoodsLicensetypeid(lig.getGoodsownerlicenseid()).getLicenseid();
lis.setLicenseid(pkid);
lim.updateGoodsLicense(lis);
Lfim.deleteLicenseFileInfoList(lig.getGoodsownerlicenseid(), lig.getGoodsownerid());
deleteDir(new File(getUrl(opid, pkid, steclassname, steclassname)));
}
for (LicenseFile licenseFile : file) {
LicenseFileInfo lfi = new LicenseFileInfo(Lfim.totalLicenseFileNumber() + 1, licenseFile.getFileName(),
new Date(), licenseFile.getFileSize(), lig.getGoodsownerlicenseid(), lig.getGoodsownerid());
insertFileInfo(lfi, Lfim, opid, pkid, classname, steclassname);
}
return uploadFile(file, opid, pkid, classname, steclassname);
}
/**
* 新增文件信息
*
* @param lfi
* @param Lfim
* @param opid
* @param pkid
* @param classname
* @param steclassname
*/
public void insertFileInfo(LicenseFileInfo lfi, LicenseFileInfoMapper Lfim, int opid, int pkid, String classname,
String steclassname) {
lfi.setOpid(opid);
lfi.setPkid(pkid);
lfi.setClassname(classname);
lfi.setSteclassname(steclassname);
lfi.setFileid(Lfim.totalLicenseFileNumber() + 1);
Lfim.insertLicenseFileInfo(lfi);
}
/**
* 获取文件路径
*
* @param opid
* @param pkid
* @param steclassname
* @param classname
* @return
*/
public String getUrl(int opid, int pkid, String steclassname, String classname) {
return "C:\\电子档案根目录\\功能电子档案\\" + opid + "\\" + steclassname + "\\" + pkid + "\\" + classname + "\\";
}
/**
* 删除文件
*
* @param dir
* @return
*/
private static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}
return dir.delete();
}
}
mybatis工具类
package com.axze.zzxc.tools;
import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
/**
* 工具类
*/
public class MyBatisUtil {
private static ThreadLocal<SqlSession> threadLocal = new ThreadLocal<SqlSession>();
private static SqlSessionFactory sqlSessionFactory;
/**
* 加载位于src/mybatis-config.xml配置文件
*/
static{
try {
Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
/**
* 禁止外界通过new方法创建
*/
private MyBatisUtil(){}
/**
* 获取SqlSession
*/
public static SqlSession getSqlSession(){
//从当前线程中获取SqlSession对象
SqlSession sqlSession = threadLocal.get();
//如果SqlSession对象为空
if(sqlSession == null){
//在SqlSessionFactory非空的情况下,获取SqlSession对象
sqlSession = sqlSessionFactory.openSession();
//将SqlSession对象与当前线程绑定在一起
threadLocal.set(sqlSession);
}
//返回SqlSession对象
return sqlSession;
}
/**
* 关闭SqlSession与当前线程分开
*/
public static void closeSqlSession(){
//从当前线程中获取SqlSession对象
SqlSession sqlSession = threadLocal.get();
//如果SqlSession对象非空
if(sqlSession != null){
//关闭SqlSession对象
sqlSession.close();
//分开当前线程与SqlSession对象的关系,目的是让GC尽早回收
threadLocal.remove();
}
}
}
客户端代码
pom文件
<dependencies>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.12</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<!-- Spring end -->
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-core</artifactId>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.9</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.9</version>
</dependency>
<!-- End CXF -->
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
<!-- fastjson end -->
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<!-- mybatis end -->
<!-- MyBatis Generator -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<!-- MyBatis Generator end -->
<!-- jdbc驱动包 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<!-- jdbc驱动包 end -->
<!-- 添加Servlet支持 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- 添加Servlet支持 end -->
</dependencies>
spring配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Import apache CXF bean definition -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:client id="uploadFileService" serviceClass="aa.FileWS"
address="http://127.0.0.1:8080/axzezzxc/webservice/GetLicenses">
</jaxws:client>
</beans>
实体类,接口类这些都通过wsdl2java命令生产
wsdl2java -p com -d D:\\src -all xx.wsdl
-p 指定其wsdl的命名空间,也就是要生成代码的包名:
-d 指定要产生代码所在目录
-client 生成客户端测试web service的代码
-server 生成服务器启动web service的代码
-impl 生成web service的实现代码
-ant 生成build.xml文件
-all 生成所有开始端点代码:types,service proxy,,service interface, server mainline, client mainline, implementation object, and an Ant build.xml file.
业务类(获取文件及文件信息,并调用服务端方法)
package aa;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@SuppressWarnings("unused")
public class UploadFileClient {
private static void invokingUploadFileBySpring(List<String> filePath, String json) {
CxfFileWrapper fileEntity;
String s = null;
ArrayList<CxfFileWrapper> fileEntitise = new ArrayList<>();
for (String string : filePath) {
fileEntity = constructFileEntity(string);
fileEntitise.add(fileEntity);
}
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
FileWS uploadFileService = applicationContext.getBean("uploadFileService", FileWS.class);
try {
s = uploadFileService.getLicenses(fileEntitise, json);
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println(s);
}
}
private static CxfFileWrapper constructFileEntity(String filePath) {
// construct FileEntity
CxfFileWrapper fileEntity = new CxfFileWrapper();
File file = new File(filePath);
fileEntity.setFileName(file.getName());
fileEntity.setFileSize(file.length());
DataSource source = new FileDataSource(file);
DataHandler handler = new DataHandler(source);
fileEntity.setFile(handler);
return fileEntity;
}
public static void main(String[] args) {
String filePath = "D:\\tab_4 - 副本.jpg";
String filePath1 = "D:\\tab_4.jpg";
String filePath2 = "D:\\tab_4 - 副本 (2).jpg";
String filePath3 = "D:\\tab_4 - 副本 1.jpg";
ArrayList<String> filePaths = new ArrayList<>();
filePaths.add(filePath);
// filePaths.add(filePath1);
// filePaths.add(filePath2);
// filePaths.add(filePath3);
// filePaths.add(filePath4);
// for (int i = 1; i <= 10; i++) {
// invokingUploadFileBySpring(filePaths,
// "{\"secretkey\":\"zhengzhaochuanshu_aixinzhuoer#103221\",\"LicensesType1\":\"2\",\"LicensesType2\":\"41\",\"licenseno\":\"xuefnsdlsad\",\"signdate\":\"2016-08-17\",\"validstartdate\":\"2016-08-17\",\"validenddate\":\"2016-08-17\",\"scopedefidordrugformid\":\"21,22\",\"gcompanyid\":\"bbbbbbb\",\"goodsownerid\":\"221\",\"goodsownid\":\"\",\"goodsownerlicenseid\":"
// + i + ",\"usestatus\":\"1\",\"memo\":\"马上到期测试9992\"}");
// }
// int i = 1;
// invokingUploadFileBySpring(filePaths,
// "{\"secretkey\":\"zhengzhaochuanshu_aixinzhuoer#103221\",\"LicensesType2\":\"1\",\"licenseno\":\"54465sdhsdjkfsdhf\",\"signdate\":\"2016-12-17\",\"validstartdate\":\"2016-08-19\",\"validenddate\":\"2016-08-17\",\"scopedefidordrugformid\":\"\",\"gcompanyid\":\"\",\"goodsownerid\":\"221\",\"goodsownid\":\"\",\"goodsownerlicenseid\":"
// + i + ",\"usestatus\":\"1\",\"memo\":\"马上到期测试9992\"}");
// int i = 1;
// invokingUploadFileBySpring(filePaths,
// "{\"secretkey\":\"zhengzhaochuanshu_aixinzhuoer#103221\",\"LicensesType1\":\"2\",\"LicensesType2\":\"1\",\"licenseno\":\"54465sdhsdjkfsdhf\",\"signdate\":\"2016-12-17\",\"validstartdate\":\"2016-08-19\",\"validenddate\":\"2016-08-17\",\"scopedefidordrugformid\":\"\",\"gcompanyid\":\"bbbbbbb\",\"goodsownerid\":\"221\",\"goodsownid\":\"\",\"usestatus\":\"1\",\"memo\":\"马上到期测试9992\"}");
String i = "\"bb\"";
invokingUploadFileBySpring(filePaths,
"{\"secretkey\":\"zhengzhaochuanshu_xizangchengyi#10321\",\"LicensesType1\":\"1\",\"LicensesType2\":\"26\",\"licenseno\":\"54as5dhf\",\"signdate\":\"2016-12-17\",\"validstartdate\":\"2016-08-19\",\"validenddate\":\"2016-08-17\",\"scopedefidordrugformid\":\"\",\"gcompanyid\":\"\",\"companystyle\":\"\",\"goodsownerid\":\"21\",\"goodsownid\":\"\",\"goodsownerlicenseid\":"
+ i + ",\"usestatus\":\"1\",\"memo\":\"马上到期测试9992\"}");
}
}