Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
Y
YX_IDENT_beijing_auxiliary_YD
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangyusheng
YX_IDENT_beijing_auxiliary_YD
Commits
a91e411e
Commit
a91e411e
authored
Feb 28, 2019
by
suichenguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xml解析
parent
b080dab9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
334 additions
and
6 deletions
+334
-6
pom.xml
pom.xml
+5
-0
ExportExcelApi.java
src/main/java/com/yxproject/start/api/ExportExcelApi.java
+1
-0
ImportXmlApi.java
src/main/java/com/yxproject/start/api/ImportXmlApi.java
+182
-0
ReadXMLApi.java
src/main/java/com/yxproject/start/api/ReadXMLApi.java
+0
-5
YingxinApi.java
src/main/java/com/yxproject/start/api/YingxinApi.java
+1
-1
ImportXmlMapper.java
...main/java/com/yxproject/start/mapper/ImportXmlMapper.java
+17
-0
IDCardFactory.java
src/main/java/com/yxproject/start/utils/IDCardFactory.java
+0
-0
YXJSONResponse.java
src/main/java/com/yxproject/start/utils/YXJSONResponse.java
+128
-0
No files found.
pom.xml
View file @
a91e411e
...
...
@@ -82,6 +82,11 @@
<artifactId>
jxl
</artifactId>
<version>
2.6.10
</version>
</dependency>
<dependency>
<groupId>
javax.ws.rs
</groupId>
<artifactId>
javax.ws.rs-api
</artifactId>
<version>
2.0
</version>
</dependency>
</dependencies>
...
...
src/main/java/com/yxproject/start/api/ExportExcelApi.java
View file @
a91e411e
...
...
@@ -11,4 +11,5 @@ import java.util.List;
public
class
ExportExcelApi
{
}
src/main/java/com/yxproject/start/api/ImportXmlApi.java
0 → 100644
View file @
a91e411e
package
com
.
yxproject
.
start
.
api
;
import
com.yxproject.start.entity.PreproPersonEntity
;
import
com.yxproject.start.service.ImportXmlService
;
import
com.yxproject.start.utils.IDCardFactory
;
import
com.yxproject.start.utils.YXJSONResponse
;
import
com.yxproject.start.utils.YXStringUtils
;
import
org.apache.catalina.Manager
;
import
org.apache.tomcat.util.http.fileupload.FileItem
;
import
org.apache.tomcat.util.http.fileupload.FileUploadException
;
import
org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory
;
import
org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload
;
import
org.dom4j.DocumentException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.ws.rs.core.Context
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"importXML"
)
public
class
ImportXmlApi
{
@Autowired
private
ImportXmlService
importXmlService
;
/**
* 导入检测XML
* @param resp 响应请求
* @param requ 获得请求
* @return 成功返回 上传完成 失败返回 异常信息
*/
@RequestMapping
(
"getXMLToCheck"
)
public
String
getXMLToCheck
(
@Context
HttpServletResponse
resp
,
@Context
HttpServletRequest
requ
)
{
YXJSONResponse
yxresp
=
new
YXJSONResponse
();
resp
.
setCharacterEncoding
(
"UTF-8"
);
String
filename
=
""
;
DiskFileItemFactory
factory
=
new
DiskFileItemFactory
();
// 设置缓冲区的大小为100KB,如果不指定,那么缓冲区的大小默认是10KB
factory
.
setSizeThreshold
(
1024
*
100
);
ServletFileUpload
upload
=
new
ServletFileUpload
(
factory
);
upload
.
setHeaderEncoding
(
"UTF-8"
);
// 设置上传单个文件的大小的最大值,目前是设置为1024*1024*10字节,也就是10MB
upload
.
setFileSizeMax
(
1024
*
1024
*
10
);
// 设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为4000MB
upload
.
setSizeMax
(
1024
*
1024
*
4000
);
// 将普通属性存入map中,之后调用
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
List
<
FileItem
>
list
=
null
;
try
{
list
=
upload
.
parseRequest
(
requ
);
for
(
FileItem
item
:
list
)
{
try
{
// 如果fileitem中封装的是普通输入项的数据
if
(
item
.
isFormField
())
{
String
name
=
item
.
getFieldName
();
// 解决普通输入项的数据的中文乱码问题
String
value
=
item
.
getString
(
"UTF-8"
);
// value = new String(value.getBytes("iso8859-1"),"UTF-8");
map
.
put
(
name
,
value
);
}
else
{
// 如果fileitem中封装的是上传文件
// 得到上传的文件名称,
filename
=
item
.
getName
();
if
(
filename
==
null
||
filename
.
trim
().
equals
(
""
))
{
continue
;
}
InputStream
in
=
item
.
getInputStream
();
String
str
=
YXStringUtils
.
inputStream2String
(
in
,
"utf-8"
);
in
.
close
();
IDCardFactory
idCardFactory
=
new
IDCardFactory
();
idcardsFactory
(
idCardFactory
.
extractIDCard
(
str
));
}
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
yxresp
.
outPutError
(
"UnsupportedEncodingException"
,
"上传文件时发现文件编码错误:"
+
e
.
getMessage
());
continue
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
yxresp
.
outPutError
(
"IOException"
,
"上传文件时发生IO错误:"
+
e
.
getMessage
());
continue
;
}
catch
(
DocumentException
e
)
{
e
.
printStackTrace
();
yxresp
.
outPutError
(
"DocumentException"
,
"上传文件时发生IO错误:"
+
e
.
getMessage
());
continue
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
yxresp
.
outPutError
(
"Exception"
,
"上传文件时发生错误,非法XML文件:"
+
filename
);
continue
;
}
}
}
catch
(
FileUploadException
e
)
{
e
.
printStackTrace
();
yxresp
.
outPutError
(
"FileUploadException"
,
"文件上载发生异常:"
+
e
.
getMessage
());
}
finally
{
return
yxresp
.
toJSONString
();
}
}
private
void
idcardsFactory
(
Map
<
String
,
Object
>
map1
)
{
Map
<
String
,
Object
>
packageMap
=
(
Map
<
String
,
Object
>)
map1
.
get
(
"package"
);
PreproPersonEntity
preproPersonEntity
=
new
PreproPersonEntity
();
preproPersonEntity
.
set
specialpackageEntity
.
setBbh
((
String
)
packageMap
.
get
(
"BBH"
));
specialpackageEntity
.
setChecknum
((
Integer
)
packageMap
.
get
(
"checknum"
));
specialpackageEntity
.
setCount
((
Integer
)
packageMap
.
get
(
"COUNT"
));
specialpackageEntity
.
setDwdm
((
String
)
packageMap
.
get
(
"DWDM"
));
specialpackageEntity
.
setDwmc
((
String
)
packageMap
.
get
(
"DWMC"
));
specialpackageEntity
.
setJls
((
String
)
packageMap
.
get
(
"JLS"
));
specialpackageEntity
.
setScsj
((
String
)
packageMap
.
get
(
"SCSJ"
));
specialpackageEntity
.
setSjbbh
((
String
)
packageMap
.
get
(
"SJBBH"
));
ArrayList
<
ProductionEntity
>
arrayList
=
new
ArrayList
<
ProductionEntity
>();
List
<
Map
<
String
,
Object
>>
personList
=
(
List
<
Map
<
String
,
Object
>>)
map1
.
get
(
"person"
);
for
(
Map
<
String
,
Object
>
person
:
personList
)
{
ProductionEntity
productionEntity
=
new
ProductionEntity
();
productionEntity
.
setJmsfzslh
((
String
)
person
.
get
(
"JMSFZSLH"
));
productionEntity
.
setGmsfhm
((
String
)
person
.
get
(
"GMSFHM"
));
if
(
person
.
get
(
"sid"
)
!=
null
)
{
productionEntity
.
setSid
((
String
)
person
.
get
(
"sid"
));
}
productionEntity
.
setXm
((
String
)
person
.
get
(
"XM"
));
productionEntity
.
setXbdm
((
String
)
person
.
get
(
"XBDM"
));
productionEntity
.
setMzdm
((
String
)
person
.
get
(
"MZDM"
));
productionEntity
.
setCsrq
((
String
)
person
.
get
(
"CSRQ"
));
productionEntity
.
setSsxqdm
((
String
)
person
.
get
(
"SSXQDM"
));
productionEntity
.
setDzmc
((
String
)
person
.
get
(
"DZMC"
));
productionEntity
.
setSdxp
((
String
)
person
.
get
(
"SDXP"
));
productionEntity
.
setZwyZwtxsj
((
String
)
person
.
get
(
"ZWY_ZWTXSJ"
));
productionEntity
.
setZwyZwtzsj
((
String
)
person
.
get
(
"ZWY_ZWTZSJ"
));
productionEntity
.
setZweZwtxsj
((
String
)
person
.
get
(
"ZWE_ZWTXSJ"
));
productionEntity
.
setZweZwtzsj
((
String
)
person
.
get
(
"ZWE_ZWTZSJ"
));
productionEntity
.
setQfjgGajgmc
((
String
)
person
.
get
(
"QFJG_GAJGMC"
));
productionEntity
.
setYxqqsrq
((
String
)
person
.
get
(
"YXQQSRQ"
));
productionEntity
.
setYxqjzrq
((
String
)
person
.
get
(
"YXQJZRQ"
));
productionEntity
.
setJmsfzslyydm
((
String
)
person
.
get
(
"JMSFZSLYYDM"
));
productionEntity
.
setJmsfzzzlxdm
((
String
)
person
.
get
(
"JMSFZZZLXDM"
));
productionEntity
.
setYxLczt
(
0
);
productionEntity
.
setJmsfzlzfsdm
((
String
)
person
.
get
(
"JMSFZLZFSDM"
));
productionEntity
.
setSjrXm
((
String
)
person
.
get
(
"SJR_XM"
));
productionEntity
.
setSjrLxdh
((
String
)
person
.
get
(
"SJR_LXDH"
));
productionEntity
.
setSjrYzbm
((
String
)
person
.
get
(
"SJR_YZBM"
));
productionEntity
.
setYxSjbh
((
String
)
packageMap
.
get
(
"SJBBH"
));
productionEntity
.
setSjrTxdz
((
String
)
person
.
get
(
"SJR_TXDZ"
));
productionEntity
.
setYxZpzlfk
(
"0"
);
if
(
person
.
get
(
"SJBLX"
)
!=
null
)
{
productionEntity
.
setSjblx
((
String
)
person
.
get
(
"SJBLX"
));
}
arrayList
.
add
(
productionEntity
);
}
Manager
manager
=
(
Manager
)
SpringBeanUtil
.
getContext
().
getBean
(
"manager"
);
try
{
manager
.
saveProductionEntityByList
(
arrayList
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
manager
.
saveSpecialpackageBySpecialpackageEntity
(
specialpackageEntity
);
}
}
src/main/java/com/yxproject/start/api/ReadXMLApi.java
deleted
100644 → 0
View file @
b080dab9
package
com
.
yxproject
.
start
.
api
;
public
class
ReadXMLApi
{
}
src/main/java/com/yxproject/start/api/YingxinApi.java
View file @
a91e411e
...
...
@@ -74,7 +74,7 @@ public class YingxinApi {
preproPersonEntity
.
setSid
(
fooElement
.
elementText
(
"sid"
));
list
.
add
(
preproPersonEntity
);
}
i
mportXmlService
.
importPersonXml
(
list
);
I
mportXmlService
.
importPersonXml
(
list
);
}
else
{
continue
;
}
...
...
src/main/java/com/yxproject/start/mapper/ImportXmlMapper.java
0 → 100644
View file @
a91e411e
package
com
.
yxproject
.
start
.
mapper
;
import
com.yxproject.start.entity.PreproPersonEntity
;
import
com.yxproject.start.entity.SysPermission
;
import
org.apache.ibatis.annotations.Insert
;
import
java.util.List
;
/**
* 导入xml
*/
public
interface
ImportXmlMapper
{
@Insert
(
"INSERT INTO "
)
public
void
addPreproPerson
(
List
<
PreproPersonEntity
>
preproPersonEntity
);
}
src/main/java/com/yxproject/start/utils/IDCardFactory.java
View file @
a91e411e
This diff is collapsed.
Click to expand it.
src/main/java/com/yxproject/start/utils/YXJSONResponse.java
0 → 100644
View file @
a91e411e
package
com
.
yxproject
.
start
.
utils
;
import
net.sf.json.JSON
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.omg.CORBA.Any
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* Created by yuzhanyang on 17/6/8.
*/
public
class
YXJSONResponse
{
private
long
ServerProcessingDur
=
0
;
private
long
start_stamp
=
0
;
private
long
ServerProcessingFinishStamp
=
0
;
public
boolean
Error
=
false
;
public
String
ReturnCode
=
"PASS"
;
private
String
ReturnMsg
=
"PASS_DESC"
;
public
JSON
RespData
=
null
;
/**
* 构造方法 设定返回值对象的开始时间戳
*/
public
YXJSONResponse
()
{
this
.
start_stamp
=
System
.
currentTimeMillis
();
}
/**
* 返回一个只有起止时间的空返回值对象
* @return 返回值对象
*/
public
YXJSONResponse
outPutSuccess
()
{
this
.
ServerProcessingFinishStamp
=
System
.
currentTimeMillis
();
this
.
ServerProcessingDur
=
this
.
ServerProcessingFinishStamp
-
this
.
start_stamp
;
this
.
Error
=
false
;
return
this
;
}
/**
* 通过map设定返回JSON
* @param dataMap map类型的返回值
* @return 返回值对象
*/
public
YXJSONResponse
outPutSuccess
(
Map
dataMap
)
{
this
.
ServerProcessingFinishStamp
=
System
.
currentTimeMillis
();
this
.
ServerProcessingDur
=
this
.
ServerProcessingFinishStamp
-
this
.
start_stamp
;
this
.
Error
=
false
;
this
.
RespData
=
JSONObject
.
fromObject
(
dataMap
);
return
this
;
}
/**
* 通过list设定返回JSON
* @param dataList list类型的返回值
* @return 返回值对象
*/
public
YXJSONResponse
outPutSuccess
(
List
dataList
)
{
this
.
ServerProcessingFinishStamp
=
System
.
currentTimeMillis
();
this
.
ServerProcessingDur
=
this
.
ServerProcessingFinishStamp
-
this
.
start_stamp
;
this
.
Error
=
false
;
this
.
RespData
=
JSONArray
.
fromObject
(
dataList
);
return
this
;
}
/**
* 通过json设定返回值
* @param json json类型的返回值
* @return 返回值对象
*/
public
YXJSONResponse
outPutSuccessJSON
(
JSON
json
)
{
this
.
ServerProcessingFinishStamp
=
System
.
currentTimeMillis
();
this
.
ServerProcessingDur
=
this
.
ServerProcessingFinishStamp
-
this
.
start_stamp
;
this
.
Error
=
false
;
this
.
RespData
=
json
;
return
this
;
}
/**
* 通过String设定返回值
* @param string String类型的返回值
* @return 返回值对象
*/
public
YXJSONResponse
outPutSuccess
(
String
string
)
{
this
.
ServerProcessingFinishStamp
=
System
.
currentTimeMillis
();
this
.
ServerProcessingDur
=
this
.
ServerProcessingFinishStamp
-
this
.
start_stamp
;
this
.
Error
=
false
;
HashMap
map
=
new
HashMap
<
String
,
Any
>();
map
.
put
(
"string"
,
string
);
this
.
RespData
=
JSONObject
.
fromObject
(
map
);
return
this
;
}
/**
* 设定出错返回值
* @param returnCode 错误码
* @param returnMsg 错误信息
* @return 返回值对象
*/
public
YXJSONResponse
outPutError
(
String
returnCode
,
String
returnMsg
)
{
this
.
ServerProcessingFinishStamp
=
System
.
currentTimeMillis
();
this
.
ServerProcessingDur
=
this
.
ServerProcessingFinishStamp
-
this
.
start_stamp
;
this
.
ReturnCode
=
returnCode
;
this
.
ReturnMsg
=
returnMsg
;
this
.
Error
=
true
;
return
this
;
}
private
JSONObject
toJSON
()
{
HashMap
map
=
new
HashMap
<
String
,
Any
>();
map
.
put
(
"ServerProcessingDur"
,
this
.
ServerProcessingDur
);
map
.
put
(
"ServerProcessingFinishStamp"
,
this
.
ServerProcessingFinishStamp
);
map
.
put
(
"ReturnCode"
,
this
.
ReturnCode
);
map
.
put
(
"ReturnMsg"
,
this
.
ReturnMsg
);
map
.
put
(
"Error"
,
this
.
Error
);
map
.
put
(
"respData"
,
this
.
RespData
);
return
JSONObject
.
fromObject
(
map
);
}
public
String
toJSONString
()
{
return
this
.
toJSON
().
toString
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment