Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gdtel-gztel-school-center
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴学德
gdtel-gztel-school-center
Commits
8d9c8598
Commit
8d9c8598
authored
May 11, 2020
by
董有沛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
奖励结算模块
parent
671a73cd
Hide whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
5221 additions
and
51 deletions
+5221
-51
common/src/main/java/com/winsun/bean/BonusApply.java
+68
-0
common/src/main/java/com/winsun/bean/HhrUser.java
+2
-3
common/src/main/java/com/winsun/bean/SalesOrder.java
+10
-0
common/src/main/java/com/winsun/mapper/BonusMapper.java
+43
-0
service-manager/pom.xml
+29
-0
service-manager/src/main/java/com/winsun/controller/BillController.java
+906
-0
service-manager/src/main/java/com/winsun/controller/BonusController.java
+708
-0
service-manager/src/main/java/com/winsun/controller/SalesOrderController.java
+8
-23
service-manager/src/main/java/com/winsun/controller/SchoolManagementController.java
+28
-25
service-manager/src/main/java/com/winsun/tenpay/AlipayGlobals.java
+36
-0
service-manager/src/main/java/com/winsun/tenpay/CorporatePrepayResponse.java
+156
-0
service-manager/src/main/java/com/winsun/tenpay/InitPropLoader.java
+40
-0
service-manager/src/main/java/com/winsun/tenpay/NewIntfRequestHandler.java
+134
-0
service-manager/src/main/java/com/winsun/tenpay/TenpayNotify.java
+139
-0
service-manager/src/main/java/com/winsun/tenpay/WxCorpRequestHandler.java
+64
-0
service-manager/src/main/java/com/winsun/tenpay/business/TenpayXyjlBusiness.java
+128
-0
service-manager/src/main/java/com/winsun/tenpay/util/ConstantUtil.java
+22
-0
service-manager/src/main/java/com/winsun/tenpay/util/HttpClientUtil.java
+239
-0
service-manager/src/main/java/com/winsun/tenpay/util/HttpUtil.java
+257
-0
service-manager/src/main/java/com/winsun/tenpay/util/MD5Util.java
+46
-0
service-manager/src/main/java/com/winsun/tenpay/util/Sha1Util.java
+46
-0
service-manager/src/main/java/com/winsun/tenpay/util/StringUtil.java
+969
-0
service-manager/src/main/java/com/winsun/tenpay/util/TenpayHttpClient.java
+433
-0
service-manager/src/main/java/com/winsun/tenpay/util/TenpayUtil.java
+87
-0
service-manager/src/main/java/com/winsun/tenpay/util/WXUtil.java
+17
-0
service-manager/src/main/java/com/winsun/tenpay/util/XmlParser.java
+549
-0
service-manager/src/main/java/com/winsun/utils/ExcelDealUtils.java
+36
-0
service-manager/src/main/resources/apiclient_cert.p12
+0
-0
service-manager/src/main/resources/tenpayconfig.properties
+21
-0
No files found.
common/src/main/java/com/winsun/bean/BonusApply.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
bean
;
import
java.io.Serializable
;
import
java.util.Date
;
import
com.baomidou.mybatisplus.annotations.TableId
;
import
com.baomidou.mybatisplus.annotations.TableName
;
import
com.baomidou.mybatisplus.enums.IdType
;
import
lombok.Data
;
@SuppressWarnings
(
"serial"
)
@TableName
(
"hhr_bonus"
)
@Data
public
class
BonusApply
implements
Serializable
{
/**
* 主键
*/
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
/**
* 申请单号
*/
private
String
applyNum
;
/**
* 佣金记录编号
*/
private
String
bonusNum
;
/**
* 佣金所有者
*/
private
String
userId
;
/**
* 佣金
*/
private
Double
bonus
;
/**
* 状态
*/
private
String
state
;
/**
* 创建日期
*/
private
Date
createDate
;
/**
* 申请人id
*/
private
String
applicantId
;
/**
* 申请人
*/
private
String
applicant
;
/**
* 审核时间
*/
private
String
auditDate
;
}
common/src/main/java/com/winsun/bean/HhrUser.java
View file @
8d9c8598
...
...
@@ -25,7 +25,7 @@ public class HhrUser implements Serializable{
private
String
idCard
;
/**
* 年
纪
* 年
级
*/
private
String
grade
;
...
...
@@ -40,10 +40,9 @@ public class HhrUser implements Serializable{
private
String
wxHeadImgUrl
;
/**
* mybatis 可以跟新为空
* 公众号openid
*/
@TableField
(
fill
=
FieldFill
.
UPDATE
)
//
@TableField(fill = FieldFill.UPDATE)
private
String
openId
;
/**
...
...
common/src/main/java/com/winsun/bean/SalesOrder.java
View file @
8d9c8598
...
...
@@ -26,6 +26,16 @@ public class SalesOrder {
private
String
userId
;
/**
* 放号人
*/
private
String
name
;
/**
* 放号人账号
*/
private
String
account
;
/**
* 创建时间
*/
private
Date
createTime
;
...
...
common/src/main/java/com/winsun/mapper/BonusMapper.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
mapper
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Update
;
import
org.springframework.stereotype.Component
;
import
com.baomidou.mybatisplus.mapper.BaseMapper
;
import
com.winsun.bean.Bill
;
import
com.winsun.bean.BonusApply
;
/**
*
* @author Warden
*
*/
@Mapper
@Component
public
interface
BonusMapper
extends
BaseMapper
<
BonusApply
>{
@Insert
(
" insert into hhr_bonus_detail(bonus,apply_num,bonus_num,sales_id,order_phone) values(#{bonus},#{applyNum},#{bonusNum},#{salesId},#{orderPhone}) "
)
int
addApplyDetail
(
@Param
(
"bonus"
)
double
bonus
,
@Param
(
"applyNum"
)
String
applyNum
,
@Param
(
"bonusNum"
)
String
bonusNum
,
@Param
(
"salesId"
)
int
salesId
,
@Param
(
"orderPhone"
)
String
orderPhone
);
@Insert
(
" insert into hhr_bonus_log(order_num,request_desc,pay_type,create_id,create_date,state) values(#{orderNum},#{requestDesc},#{payType},#{createId},now(),#{state}) "
)
int
addBonusLog
(
@Param
(
"orderNum"
)
String
orderNum
,
@Param
(
"requestDesc"
)
String
requestDesc
,
@Param
(
"payType"
)
String
payType
,
@Param
(
"createId"
)
int
createId
,
@Param
(
"state"
)
int
state
);
@Update
(
" update hhr_bonus set state = #{state} where id = #{id} "
)
int
updateBonus
(
@Param
(
"state"
)
int
state
,
@Param
(
"int"
)
int
id
);
@Update
(
" update hhr_bonus_log set response_desc = #{responseDesc},pay_order_num = #{payOrderNum},state = #{state} where order_num = #{orderNum} "
)
int
updateBonusLog
(
@Param
(
"responseDesc"
)
String
responseDesc
,
@Param
(
"payOrderNum"
)
String
payOrderNum
,
@Param
(
"state"
)
int
state
,
@Param
(
"orderNum"
)
String
orderNum
);
@Select
(
" select * from hhr_bonus_detail where bonus_num = #{bonusNum} "
)
List
<
Map
<
String
,
Object
>>
getBonusDetail
(
@Param
(
"bonusNum"
)
String
bonusNum
);
}
service-manager/pom.xml
View file @
8d9c8598
...
...
@@ -135,6 +135,35 @@
<groupId>com.winsun.framework</groupId>
<artifactId>winsun-core-service</artifactId>
</dependency>-->
<dependency>
<groupId>
dom4j
</groupId>
<artifactId>
dom4j
</artifactId>
</dependency>
<dependency>
<groupId>
jaxen
</groupId>
<artifactId>
jaxen
</artifactId>
</dependency>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
</dependency>
<dependency>
<groupId>
commons-logging
</groupId>
<artifactId>
commons-logging
</artifactId>
<version>
1.1.1
</version>
</dependency>
<dependency>
<groupId>
commons-codec
</groupId>
<artifactId>
commons-codec
</artifactId>
</dependency>
<dependency>
<groupId>
commons-httpclient
</groupId>
<artifactId>
commons-httpclient
</artifactId>
<version>
3.0.1
</version>
</dependency>
</dependencies>
<build>
...
...
service-manager/src/main/java/com/winsun/controller/BillController.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
controller
;
import
java.io.IOException
;
import
java.text.DecimalFormat
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFCellStyle
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.baomidou.mybatisplus.mapper.Wrapper
;
import
com.baomidou.mybatisplus.plugins.Page
;
import
com.winsun.auth.core.annotion.Permission
;
import
com.winsun.auth.core.base.controller.BaseController
;
import
com.winsun.auth.core.common.model.ResponseData
;
import
com.winsun.auth.core.shiro.ShiroUser
;
import
com.winsun.auth.core.util.IOUtils
;
import
com.winsun.bean.Bill
;
import
com.winsun.bean.HhrUser
;
import
com.winsun.bean.School
;
import
com.winsun.bean.SysUser
;
import
com.winsun.mapper.BillMapper
;
import
com.winsun.mapper.HhrUserMapper
;
import
com.winsun.mapper.SchoolMapper
;
import
com.winsun.mapper.SysUserMapper
;
import
com.winsun.utils.ExcelDealUtils
;
import
com.winsun.utils.ImportExcel
;
import
com.winsun.utils.MapUtil
;
import
lombok.extern.slf4j.Slf4j
;
/**
* 账单管理
* @author Warden
*
*/
@Slf4j
@RestController
@RequestMapping
(
"/bill"
)
public
class
BillController
extends
BaseController
{
private
static
BillMapper
billMapper
;
private
static
SysUserMapper
sysUserMapper
;
private
static
HhrUserMapper
hhrUserMapper
;
private
static
SchoolMapper
schoolMapper
;
/**
* 导入
*/
private
static
final
int
HEADER_NUM
=
-
1
;
private
static
final
int
SHEET_INDEX
=
0
;
private
static
String
E_SORT
=
"序号"
;
private
static
String
E_MONTH
=
"月份"
;
private
static
String
E_BILL_TYPE
=
"项目类型"
;
private
static
String
E_BILL_DETAIL
=
"收支详情"
;
private
static
String
E_SUBST_NAME
=
"县分"
;
private
static
String
E_SCHOOL_NAME
=
"学校"
;
private
static
String
E_CAMPUS
=
"校区"
;
private
static
String
E_NETWORK_NAME
=
"网点名称"
;
private
static
String
E_NETWORK_CODE
=
"网点编码"
;
private
static
String
E_AMOUNT
=
"金额"
;
private
static
String
E_TAX_POINT
=
"税点"
;
@Autowired
public
BillController
(
BillMapper
billMapper
,
SysUserMapper
sysUserMapper
,
HhrUserMapper
hhrUserMapper
,
SchoolMapper
schoolMapper
)
{
BillController
.
billMapper
=
billMapper
;
BillController
.
sysUserMapper
=
sysUserMapper
;
BillController
.
hhrUserMapper
=
hhrUserMapper
;
BillController
.
schoolMapper
=
schoolMapper
;
}
@Permission
(
menuname
=
"获取账单清单"
,
value
=
"/list"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
Bill
>>
getList
(
@Param
(
"substName"
)
String
substName
,
@Param
(
"schoolName"
)
String
schoolName
,
@Param
(
"billType"
)
String
billType
,
@Param
(
"billDetail"
)
String
billDetail
,
@Param
(
"month"
)
String
month
,
@Param
(
"pageNo"
)
Integer
pageNo
,
@Param
(
"pageSize"
)
Integer
pageSize
){
Page
<
Bill
>
page
=
new
Page
<>(
pageNo
,
pageSize
);
Wrapper
<
Bill
>
wrapper
=
new
EntityWrapper
<
Bill
>();
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"subst_name"
,
substName
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
billDetail
),
"bill_detail"
,
billDetail
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapper
.
eq
(
"del_flag"
,
0
);
List
<
Bill
>
billList
=
billMapper
.
selectPage
(
page
,
wrapper
);
page
.
setRecords
(
billList
);
return
ResponseData
.
success
(
page
,
"查询成功"
);
}
@Permission
(
menuname
=
"删除账单"
,
value
=
"/deleteBill"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Object
>
deleteBill
(
@Param
(
"id"
)
String
id
){
Bill
bill
=
new
Bill
();
bill
.
setId
(
id
);
bill
.
setDelFlag
(
1
);
int
num
=
billMapper
.
updateById
(
bill
);
if
(
num
>
0
)
{
return
ResponseData
.
success
(
"删除成功!"
);
}
return
ResponseData
.
error
(
"删除失败"
);
}
@Permission
(
menuname
=
"导出账单清单"
,
value
=
"exportList"
,
method
=
RequestMethod
.
POST
)
public
void
exportList
(
@Param
(
"substName"
)
String
substName
,
@Param
(
"schoolName"
)
String
schoolName
,
@Param
(
"billType"
)
String
billType
,
@Param
(
"billDetail"
)
String
billDetail
,
@Param
(
"month"
)
String
month
)
throws
IOException
{
Wrapper
<
Bill
>
wrapper
=
new
EntityWrapper
<
Bill
>();
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"subst_name"
,
substName
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
billDetail
),
"bill_detail"
,
billDetail
);
wrapper
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapper
.
eq
(
"del_flag"
,
0
);
List
<
Map
<
String
,
Object
>>
list
=
billMapper
.
selectMaps
(
wrapper
);
ServletOutputStream
os
=
null
;
XSSFWorkbook
workbook
=
ExcelDealUtils
.
getWorkBook
(
ExcelDealUtils
.
billExcel
(
"账单清单"
),
list
);
try
{
HttpServletResponse
response
=
getHttpServletResponse
();
response
.
reset
();
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
os
=
response
.
getOutputStream
();
workbook
.
write
(
os
);
os
.
flush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"文件出错!"
+
e
.
getMessage
(),
e
);
}
finally
{
IOUtils
.
closeQuite
(
workbook
,
os
);
}
}
@Permission
(
menuname
=
"账单导入模板"
,
method
=
RequestMethod
.
POST
,
value
=
"downloadTemplate"
)
public
ResponseData
<
String
>
downloadTemplate
()
{
ArrayList
<
String
>
columns
=
new
ArrayList
<>();
columns
.
add
(
E_SORT
);
columns
.
add
(
E_MONTH
);
columns
.
add
(
E_BILL_TYPE
);
columns
.
add
(
E_BILL_DETAIL
);
columns
.
add
(
E_SUBST_NAME
);
columns
.
add
(
E_SCHOOL_NAME
);
columns
.
add
(
E_CAMPUS
);
columns
.
add
(
E_NETWORK_NAME
);
columns
.
add
(
E_NETWORK_CODE
);
columns
.
add
(
E_AMOUNT
);
columns
.
add
(
E_TAX_POINT
);
ServletOutputStream
os
=
null
;
XSSFWorkbook
workbook
=
new
XSSFWorkbook
();
try
{
//创建工作表
XSSFSheet
sheet
=
workbook
.
createSheet
(
"账单导入模板"
);
//添加表头
final
XSSFRow
row
=
sheet
.
createRow
(
0
);
XSSFCellStyle
cellStyle
=
workbook
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
columns
.
forEach
(
val
->
{
XSSFCell
cell
=
row
.
createCell
(
Math
.
max
(
row
.
getLastCellNum
(),
0
));
cell
.
setCellValue
(
val
);
});
HttpServletResponse
response
=
getHttpServletResponse
();
response
.
reset
();
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/vnd.ms-excel"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;fileName=data.xlsx"
);
os
=
response
.
getOutputStream
();
workbook
.
write
(
os
);
os
.
flush
();
}
catch
(
IOException
e
)
{
log
.
error
(
"账单导入模板文件出错!"
+
e
.
getMessage
(),
e
);
}
finally
{
IOUtils
.
closeQuite
(
workbook
,
os
);
}
return
ResponseData
.
error
(
"账单导入模板出错"
);
}
@Permission
(
menuname
=
"上传账单数据"
,
value
=
"importBill"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
importOrder
(
@RequestParam
(
name
=
"file"
)
MultipartFile
file
)
{
StringBuffer
info
=
new
StringBuffer
();
if
(!
StringUtils
.
endsWithAny
(
file
.
getOriginalFilename
(),
"xlsx"
,
"xls"
))
{
return
ResponseData
.
error
(
"手工上传数据仅支持Excel文件,其他格式不支持!"
);
}
ShiroUser
user
=
getShiroUser
();
// 当前是否有数据权限
boolean
hasDataPermission
=
user
.
getRoleNames
().
stream
().
anyMatch
(
data
->
StringUtils
.
equalsAny
(
data
,
"活动上单员"
,
"数据管理员"
,
"超级管理员"
));
if
(!
hasDataPermission
)
{
return
ResponseData
.
error
(
"无数据权限!"
);
}
ImportExcel
importExcel
=
null
;
try
{
importExcel
=
new
ImportExcel
(
file
,
HEADER_NUM
,
SHEET_INDEX
);
}
catch
(
Exception
e
)
{
log
.
error
(
"受理单导入异常"
,
e
.
getMessage
());
return
ResponseData
.
error
(
"导入异常!"
);
}
List
<
Map
<
String
,
Object
>>
listMap
=
importExcel
.
getDataListMap
();
if
(
listMap
.
size
()
==
1
)
{
return
ResponseData
.
error
(
"文件不能为空"
);
}
if
(!
listMap
.
get
(
0
).
get
(
"c"
).
toString
().
equals
(
E_BILL_TYPE
))
{
return
ResponseData
.
error
(
"模板不对,请选择正确的模板!"
);
}
if
(!
listMap
.
get
(
0
).
get
(
"d"
).
toString
().
equals
(
E_BILL_DETAIL
))
{
return
ResponseData
.
error
(
"模板不对,请选择正确的模板!"
);
}
if
(!
listMap
.
get
(
0
).
get
(
"j"
).
toString
().
equals
(
E_AMOUNT
))
{
return
ResponseData
.
error
(
"模板不对,请选择正确的模板!"
);
}
if
(!
listMap
.
get
(
0
).
get
(
"k"
).
toString
().
equals
(
E_TAX_POINT
))
{
return
ResponseData
.
error
(
"模板不对,请选择正确的模板!"
);
}
if
(
listMap
.
get
(
0
).
size
()
!=
11
)
{
return
ResponseData
.
error
(
"模板不对,请选择正确的模板!"
);
}
//校验数据
try
{
//校验数据
for
(
int
i
=
1
;
i
<
listMap
.
size
();
i
++)
{
Map
<
String
,
Object
>
temp
=
listMap
.
get
(
i
);
if
(!
temp
.
containsKey
(
"c"
))
{
return
ResponseData
.
error
(
"第"
+
(
i
+
1
)
+
"行的项目类型不能为空"
);
}
if
(
StringUtils
.
isBlank
(
temp
.
get
(
"d"
).
toString
()))
{
return
ResponseData
.
error
(
"第"
+
(
i
+
1
)
+
"行的收支详情不能为空"
);
}
if
(
StringUtils
.
isBlank
(
temp
.
get
(
"j"
).
toString
()))
{
return
ResponseData
.
error
(
"第"
+
(
i
+
1
)
+
"行的金额不能为空"
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"放号清单导入异常"
+
e
.
getMessage
(),
e
);
return
ResponseData
.
error
(
"导入异常!"
);
}
// 去掉首行标题
listMap
.
remove
(
0
);
int
num
=
dealUploadData
(
listMap
);
info
.
append
(
"导入"
+
num
+
"条数据!"
);
return
ResponseData
.
success
(
info
.
toString
(),
"导入完成"
);
}
public
int
dealUploadData
(
List
<
Map
<
String
,
Object
>>
list
){
int
num
=
0
;
List
<
Map
<
String
,
Object
>>
insertList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
List
<
Map
<
String
,
Object
>>
phoneSchoolList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
map
:
list
)
{
String
month
=
(
String
)
map
.
get
(
"b"
);
String
billType
=
(
String
)
map
.
get
(
"c"
);
String
billDetail
=
(
String
)
map
.
get
(
"d"
);
String
substName
=
(
String
)
map
.
get
(
"e"
);
String
schoolName
=
(
String
)
map
.
get
(
"f"
);
String
campus
=
(
String
)
map
.
get
(
"g"
);
String
networkName
=
(
String
)
map
.
get
(
"h"
);
String
networkCode
=
(
String
)
map
.
get
(
"i"
);
double
amount
=
Double
.
parseDouble
((
String
)
map
.
get
(
"j"
));
Bill
bill
=
new
Bill
();
if
(
StringUtils
.
isNoneBlank
((
String
)
map
.
get
(
"k"
)))
{
double
taxPoint
=
Double
.
parseDouble
((
String
)
map
.
get
(
"k"
));
double
taxAmount
=
amount
/
taxPoint
;
bill
.
setTaxPoint
(
taxPoint
);
bill
.
setTaxAmount
(
taxAmount
);;
}
bill
.
setMonth
(
month
);
bill
.
setBillType
(
billType
);
bill
.
setBillDetail
(
billDetail
);
bill
.
setSubstName
(
substName
);
bill
.
setSchoolName
(
schoolName
);
bill
.
setCampus
(
campus
);
bill
.
setNetworkName
(
networkName
);
bill
.
setNetworkCode
(
networkCode
);
bill
.
setAmount
(
amount
);
num
+=
billMapper
.
insert
(
bill
);
}
return
num
;
}
@Permission
(
menuname
=
"获取账单汇总"
,
value
=
"/statisList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
Map
<
String
,
Object
>>>
statisList
(
@Param
(
"month"
)
String
month
,
@Param
(
"statisType"
)
String
statisType
,
@Param
(
"substName"
)
String
substName
,
@Param
(
"schoolName"
)
String
schoolName
,
@Param
(
"expenseType"
)
String
expenseType
,
@Param
(
"pageNo"
)
Integer
pageNo
,
@Param
(
"pageSize"
)
Integer
pageSize
){
Page
<
Map
<
String
,
Object
>>
page
=
new
Page
<>(
pageNo
,
pageSize
);
// 支出部分
String
billType
=
"佣金入账"
;
Wrapper
<
Bill
>
wrapperIncome
=
new
EntityWrapper
<
Bill
>();
wrapperIncome
.
setSqlSelect
(
" month,subst_name substName,school_name schoolName,bill_type billType,bill_detail billDetail,round(sum(amount),2) amount,round(sum(tax_amount),2) taxAmount "
);
wrapperIncome
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperIncome
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"subst_name"
,
substName
);
wrapperIncome
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
wrapperIncome
.
eq
(
"bill_type"
,
billType
);
wrapperIncome
.
eq
(
"del_flag"
,
0
);
if
(
"substName"
.
equals
(
statisType
))
{
wrapperIncome
.
groupBy
(
"subst_name"
).
groupBy
(
"bill_detail"
).
groupBy
(
"month"
);
wrapperIncome
.
orderBy
(
"subst_name"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
}
else
if
(
"schoolName"
.
equals
(
statisType
))
{
wrapperIncome
.
groupBy
(
"subst_name"
).
groupBy
(
"school_name"
).
groupBy
(
"bill_detail"
).
groupBy
(
"month"
);
wrapperIncome
.
orderBy
(
"subst_name"
,
true
).
orderBy
(
"school_name"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
}
else
{
wrapperIncome
.
groupBy
(
"month"
).
groupBy
(
"bill_detail"
);
wrapperIncome
.
orderBy
(
"bill_type"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
}
List
<
Map
<
String
,
Object
>>
incomeBillList
=
billMapper
.
selectMaps
(
wrapperIncome
);
Wrapper
<
Bill
>
wrapperIncomeSum
=
new
EntityWrapper
<
Bill
>();
wrapperIncomeSum
.
setSqlSelect
(
" sum(amount) amount,sum(tax_amount) tax_amount "
);
wrapperIncomeSum
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperIncomeSum
.
eq
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
wrapperIncomeSum
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"subst_name"
,
substName
);
wrapperIncomeSum
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
Map
<
String
,
Object
>
incomeSumMap
=
billMapper
.
selectMaps
(
wrapperIncomeSum
).
get
(
0
);
// 支出部分
billType
=
expenseType
.
indexOf
(
"成本"
)
>
-
1
?
"佣金支出,外包成本,营销成本"
:
"佣金支出"
;
Wrapper
<
Bill
>
wrapperExpense
=
new
EntityWrapper
<
Bill
>();
wrapperExpense
.
setSqlSelect
(
" month,subst_name substName,school_name schoolName,bill_type billType,bill_detail billDetail,round(sum(amount),2) amount,round(sum(tax_amount),2) taxAmount "
);
wrapperExpense
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperExpense
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"subst_name"
,
substName
);
wrapperExpense
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
wrapperExpense
.
in
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
wrapperExpense
.
eq
(
"del_flag"
,
0
);
if
(
"substName"
.
equals
(
statisType
))
{
wrapperExpense
.
groupBy
(
"subst_name"
).
groupBy
(
"bill_detail"
).
groupBy
(
"month"
);
wrapperExpense
.
orderBy
(
"subst_name"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
}
else
if
(
"schoolName"
.
equals
(
statisType
))
{
wrapperExpense
.
groupBy
(
"subst_name"
).
groupBy
(
"school_name"
).
groupBy
(
"bill_detail"
).
groupBy
(
"month"
);
wrapperExpense
.
orderBy
(
"subst_name"
,
true
).
orderBy
(
"school_name"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
}
else
{
wrapperExpense
.
groupBy
(
"month"
).
groupBy
(
"bill_detail"
);
wrapperExpense
.
orderBy
(
"bill_type"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
}
List
<
Map
<
String
,
Object
>>
expenseBillList
=
billMapper
.
selectMaps
(
wrapperExpense
);
Wrapper
<
Bill
>
wrapperExpenseSum
=
new
EntityWrapper
<
Bill
>();
wrapperExpenseSum
.
setSqlSelect
(
" sum(amount) amount,sum(tax_amount) tax_amount "
);
wrapperExpenseSum
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperExpenseSum
.
in
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
wrapperExpenseSum
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"subst_name"
,
substName
);
wrapperExpenseSum
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
Map
<
String
,
Object
>
expenseSumMap
=
billMapper
.
selectMaps
(
wrapperExpenseSum
).
get
(
0
);
String
incomeSum
=
"0"
;
String
expenseSum
=
"0"
;
String
taxAmount
=
"0"
;
DecimalFormat
df
=
new
DecimalFormat
(
"#.00"
);
if
(
null
!=
incomeSumMap
){
incomeSum
=
df
.
format
((
Double
)
incomeSumMap
.
get
(
"amount"
));
}
if
(
null
!=
expenseSumMap
){
expenseSum
=
df
.
format
((
Double
)
expenseSumMap
.
get
(
"amount"
));
taxAmount
=
df
.
format
((
Double
)
expenseSumMap
.
get
(
"tax_amount"
));
}
Map
<
String
,
Object
>
firstMap
=
new
HashMap
<>();
firstMap
.
put
(
"month"
,
"总计"
);
firstMap
.
put
(
"substName"
,
""
);
firstMap
.
put
(
"schoolName"
,
""
);
firstMap
.
put
(
"target"
,
statisType
);
firstMap
.
put
(
"billType"
,
""
);
firstMap
.
put
(
"billDetail"
,
""
);
firstMap
.
put
(
"amount"
,
incomeSum
);
firstMap
.
put
(
"billTypeExpense"
,
""
);
firstMap
.
put
(
"billDetailExpense"
,
""
);
firstMap
.
put
(
"amountExpense"
,
expenseSum
);
firstMap
.
put
(
"taxAmount"
,
taxAmount
);
List
<
Map
<
String
,
Object
>>
imcomeList
=
addGroupSum
(
incomeBillList
,
statisType
);
List
<
Map
<
String
,
Object
>>
expenseList
=
addGroupSum
(
expenseBillList
,
statisType
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
if
(
"substName"
.
equals
(
statisType
)
||
"schoolName"
.
equals
(
statisType
))
{
dataList
=
dealDataOther
(
imcomeList
,
expenseList
,
statisType
);
}
else
{
dataList
=
dealData
(
imcomeList
,
expenseList
,
statisType
);
}
dataList
.
add
(
0
,
firstMap
);
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
if
(
dataList
.
size
()
<
pageNo
*
pageSize
)
{
resultList
=
dataList
.
subList
((
pageNo
-
1
)*
pageSize
,
dataList
.
size
());
}
else
{
resultList
=
dataList
.
subList
((
pageNo
-
1
)*
pageSize
,
pageNo
*
pageSize
);
}
page
.
setRecords
(
resultList
);
page
.
setTotal
(
dataList
.
size
());
return
ResponseData
.
success
(
page
,
"查询成功"
);
}
@Permission
(
menuname
=
"导出账单汇总清单"
,
value
=
"exportStatisList"
,
method
=
RequestMethod
.
POST
)
public
void
exportStatisList
(
@Param
(
"month"
)
String
month
,
@Param
(
"statisType"
)
String
statisType
,
@Param
(
"dataType"
)
String
dataType
,
@Param
(
"substName"
)
String
substName
,
@Param
(
"schoolName"
)
String
schoolName
,
@Param
(
"expenseType"
)
String
expenseType
)
throws
IOException
{
// 支出部分
String
billType
=
"佣金入账"
;
Wrapper
<
Bill
>
wrapperIncome
=
new
EntityWrapper
<
Bill
>();
wrapperIncome
.
setSqlSelect
(
" month,school_name schoolName,bill_type billType,bill_detail billDetail,round(sum(amount),2) amount,round(sum(tax_amount),2) taxAmount "
);
wrapperIncome
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperIncome
.
eq
(
"bill_type"
,
billType
);
wrapperIncome
.
eq
(
"del_flag"
,
0
);
wrapperIncome
.
groupBy
(
"month"
).
groupBy
(
"bill_detail"
);
wrapperIncome
.
orderBy
(
"bill_type"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
List
<
Map
<
String
,
Object
>>
incomeBillList
=
billMapper
.
selectMaps
(
wrapperIncome
);
Wrapper
<
Bill
>
wrapperIncomeSum
=
new
EntityWrapper
<
Bill
>();
wrapperIncomeSum
.
setSqlSelect
(
" sum(amount) amount,sum(tax_amount) tax_amount "
);
wrapperIncomeSum
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperIncomeSum
.
eq
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
Map
<
String
,
Object
>
incomeSumMap
=
billMapper
.
selectMaps
(
wrapperIncomeSum
).
get
(
0
);
// 支出部分
billType
=
"佣金部分"
.
equals
(
statisType
)
?
"佣金支出"
:
"佣金支出,外包成本,营销成本"
;
Wrapper
<
Bill
>
wrapperExpense
=
new
EntityWrapper
<
Bill
>();
wrapperExpense
.
setSqlSelect
(
" month,school_name schoolName,bill_type billType,bill_detail billDetail,round(sum(amount),2) amount,round(sum(tax_amount),2) taxAmount "
);
wrapperExpense
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperExpense
.
in
(
"bill_type"
,
billType
);
wrapperExpense
.
eq
(
"del_flag"
,
0
);
wrapperExpense
.
groupBy
(
"month"
).
groupBy
(
"bill_detail"
);
wrapperExpense
.
orderBy
(
"bill_type"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
List
<
Map
<
String
,
Object
>>
expenseBillList
=
billMapper
.
selectMaps
(
wrapperExpense
);
Wrapper
<
Bill
>
wrapperExpenseSum
=
new
EntityWrapper
<
Bill
>();
wrapperExpenseSum
.
setSqlSelect
(
" sum(amount) amount,sum(tax_amount) tax_amount "
);
wrapperExpenseSum
.
eq
(
StringUtils
.
isNoneBlank
(
month
),
"month"
,
month
);
wrapperExpenseSum
.
in
(
"bill_type"
,
billType
);
Map
<
String
,
Object
>
expenseSumMap
=
billMapper
.
selectMaps
(
wrapperExpenseSum
).
get
(
0
);
String
incomeSum
=
"0"
;
String
expenseSum
=
"0"
;
String
taxAmount
=
"0"
;
DecimalFormat
df
=
new
DecimalFormat
(
"#.00"
);
if
(
null
!=
incomeSumMap
.
get
(
"amount"
)){
incomeSum
=
df
.
format
((
Double
)
incomeSumMap
.
get
(
"amount"
));
}
if
(
null
!=
expenseSumMap
.
get
(
"amount"
)){
expenseSum
=
df
.
format
((
Double
)
expenseSumMap
.
get
(
"amount"
));
taxAmount
=
df
.
format
((
Double
)
expenseSumMap
.
get
(
"tax_amount"
));
}
Map
<
String
,
Object
>
firstMap
=
new
HashMap
<>();
firstMap
.
put
(
"month"
,
"总计"
);
firstMap
.
put
(
"county"
,
""
);
firstMap
.
put
(
"school"
,
""
);
firstMap
.
put
(
"target"
,
dataType
);
firstMap
.
put
(
"billType"
,
""
);
firstMap
.
put
(
"billDetail"
,
""
);
firstMap
.
put
(
"amount"
,
incomeSum
);
firstMap
.
put
(
"billTypeExpense"
,
""
);
firstMap
.
put
(
"billDetailExpense"
,
""
);
firstMap
.
put
(
"amountExpense"
,
expenseSum
);
firstMap
.
put
(
"taxAmount"
,
taxAmount
);
List
<
Map
<
String
,
Object
>>
imcomeList
=
addGroupSum
(
incomeBillList
,
""
);
List
<
Map
<
String
,
Object
>>
expenseList
=
addGroupSum
(
expenseBillList
,
""
);
List
<
Map
<
String
,
Object
>>
dataList
=
dealData
(
imcomeList
,
expenseList
,
dataType
);
dataList
.
add
(
0
,
firstMap
);
ServletOutputStream
os
=
null
;
XSSFWorkbook
workbook
=
ExcelDealUtils
.
getWorkBook
(
ExcelDealUtils
.
billStatisExcel
(
"账单汇总清单"
),
dataList
);
try
{
HttpServletResponse
response
=
getHttpServletResponse
();
response
.
reset
();
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
os
=
response
.
getOutputStream
();
workbook
.
write
(
os
);
os
.
flush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"文件出错!"
+
e
.
getMessage
(),
e
);
}
finally
{
IOUtils
.
closeQuite
(
workbook
,
os
);
}
}
@Permission
(
menuname
=
"获取账单汇总(总经理)"
,
value
=
"/statisManagerList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
Map
<
String
,
Object
>>>
statisManagerList
(
@Param
(
"statisType"
)
String
statisType
,
@Param
(
"expenseType"
)
String
expenseType
,
@Param
(
"userName"
)
String
name
,
@Param
(
"pageNo"
)
Integer
pageNo
,
@Param
(
"pageSize"
)
Integer
pageSize
)
throws
ParseException
{
Page
<
Map
<
String
,
Object
>>
page
=
new
Page
<>(
pageNo
,
pageSize
);
statisType
=
"userName"
;
// 支出部分
String
billType
=
"佣金入账"
;
Wrapper
<
Bill
>
wrapperIncome
=
new
EntityWrapper
<
Bill
>();
wrapperIncome
.
setSqlSelect
(
" month,subst_name substName,school_name schoolName,bill_type billType,bill_detail billDetail,round(sum(amount),2) amount,round(sum(tax_amount),2) taxAmount "
);
wrapperIncome
.
eq
(
"bill_type"
,
billType
);
wrapperIncome
.
eq
(
"del_flag"
,
0
);
wrapperIncome
.
groupBy
(
"subst_name"
).
groupBy
(
"school_name"
).
groupBy
(
"bill_detail"
).
groupBy
(
"month"
);
wrapperIncome
.
orderBy
(
"subst_name"
,
true
).
orderBy
(
"school_name"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
List
<
Map
<
String
,
Object
>>
incomeBillList
=
billMapper
.
selectMaps
(
wrapperIncome
);
// Wrapper<Bill> wrapperIncomeSum = new EntityWrapper<Bill>();
// wrapperIncomeSum.setSqlSelect(" sum(amount) amount,sum(tax_amount) tax_amount ");
// wrapperIncomeSum.eq(StringUtils.isNoneBlank(billType), "bill_type", billType);
// wrapperIncomeSum.eq(StringUtils.isNoneBlank(substName), "subst_name", substName);
// wrapperIncomeSum.eq(StringUtils.isNoneBlank(schoolName), "school_name", schoolName);
// Map<String, Object> incomeSumMap = billMapper.selectMaps(wrapperIncomeSum).get(0);
// 支出部分
billType
=
expenseType
.
indexOf
(
"成本"
)
>
-
1
?
"佣金支出,外包成本,营销成本"
:
"佣金支出"
;
Wrapper
<
Bill
>
wrapperExpense
=
new
EntityWrapper
<
Bill
>();
wrapperExpense
.
setSqlSelect
(
" month,subst_name substName,school_name schoolName,bill_type billType,bill_detail billDetail,round(sum(amount),2) amount,round(sum(tax_amount),2) taxAmount "
);
wrapperExpense
.
in
(
StringUtils
.
isNoneBlank
(
billType
),
"bill_type"
,
billType
);
wrapperExpense
.
eq
(
"del_flag"
,
0
);
wrapperExpense
.
groupBy
(
"subst_name"
).
groupBy
(
"school_name"
).
groupBy
(
"bill_detail"
).
groupBy
(
"month"
);
wrapperExpense
.
orderBy
(
"subst_name"
,
true
).
orderBy
(
"school_name"
,
true
).
orderBy
(
"bill_detail"
,
true
).
orderBy
(
"month"
,
false
);
List
<
Map
<
String
,
Object
>>
expenseBillList
=
billMapper
.
selectMaps
(
wrapperExpense
);
// Wrapper<Bill> wrapperExpenseSum = new EntityWrapper<Bill>();
// wrapperExpenseSum.setSqlSelect(" sum(amount) amount,sum(tax_amount) tax_amount ");
// wrapperExpenseSum.eq(StringUtils.isNoneBlank(month), "month", month);
// wrapperExpenseSum.in(StringUtils.isNoneBlank(billType), "bill_type", billType);
// wrapperExpenseSum.eq(StringUtils.isNoneBlank(substName), "subst_name", substName);
// wrapperExpenseSum.eq(StringUtils.isNoneBlank(schoolName), "school_name", schoolName);
// Map<String, Object> expenseSumMap = billMapper.selectMaps(wrapperExpenseSum).get(0);
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" school_name schoolName,id "
);
wrapperSchool
.
eq
(
"status"
,
"1"
);
Map
<
String
,
Object
>
schoolMaps
=
MapUtil
.
listToMap
(
schoolMapper
.
selectMaps
(
wrapperSchool
),
"id"
,
"schoolName"
);
//List<Map<String, Object>> schoolList = schoolMapper.selectMaps(wrapperSchool);
List
<
Map
<
String
,
Object
>>
schoolRefList
=
schoolMapper
.
getSupervisorSchoolRef
();
//Map<String, Object> schoolRefMap = MapUtil.listToMap(schoolMapper.getSupervisorSchoolRef(), "user_id", "school");
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
setSqlSelect
(
" id,name "
);
wrapperSys
.
eq
(
"status"
,
"1"
);
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
name
),
"name"
,
name
);
//List<Map<String, Object>> sysUserList = sysUserMapper.selectMaps(wrapperSys);
Map
<
String
,
Object
>
sysMaps
=
MapUtil
.
listToMap
(
sysUserMapper
.
selectMaps
(
wrapperSys
),
"id"
,
"name"
);
Wrapper
<
HhrUser
>
wrapperHhrUser
=
new
EntityWrapper
<
HhrUser
>();
wrapperHhrUser
.
setSqlSelect
(
" id "
);
wrapperHhrUser
.
eq
(
"position"
,
"督导"
);
List
<
Map
<
String
,
Object
>>
hhrUserList
=
hhrUserMapper
.
selectMaps
(
wrapperHhrUser
);
//Map<String, Object> hhrUserMap = MapUtil.listToMap(hhrUserMapper.selectMaps(wrapperHhrUser), "id", "id");
List
<
Map
<
String
,
Object
>>
managerSchoolList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
map
:
hhrUserList
)
{
if
(
null
!=
sysMaps
.
get
(
map
.
get
(
"id"
)))
{
int
userId
=
Integer
.
parseInt
(
map
.
get
(
"id"
).
toString
());
String
userName
=
sysMaps
.
get
(
map
.
get
(
"id"
)).
toString
();
for
(
Map
<
String
,
Object
>
schoolRefMap
:
schoolRefList
)
{
if
((
int
)
schoolRefMap
.
get
(
"user_id"
)
==
userId
)
{
String
schoolId
=
schoolRefMap
.
get
(
"school"
).
toString
();
String
schoolName
=
schoolMaps
.
get
(
schoolId
).
toString
();
Map
<
String
,
Object
>
managerSchoolMap
=
new
HashMap
<
String
,
Object
>();
managerSchoolMap
.
put
(
"schoolName"
,
schoolName
);
managerSchoolMap
.
put
(
"userName"
,
userName
);
managerSchoolList
.
add
(
managerSchoolMap
);
}
}
}
}
double
incomeSum
=
0
;
double
expenseSum
=
0
;
double
taxAmount
=
0
;
DecimalFormat
df
=
new
DecimalFormat
(
"#.00"
);
List
<
Map
<
String
,
Object
>>
imcomeList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
List
<
Map
<
String
,
Object
>>
expenseList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
Map
<
String
,
Object
>
managerSchoolMaps
=
MapUtil
.
listToMap
(
managerSchoolList
,
"schoolName"
,
"userName"
);
for
(
Map
<
String
,
Object
>
map
:
incomeBillList
)
{
if
(
null
!=
managerSchoolMaps
.
get
(
map
.
get
(
"schoolName"
)))
{
map
.
put
(
"userName"
,
managerSchoolMaps
.
get
(
map
.
get
(
"schoolName"
)).
toString
());
incomeSum
+=
(
double
)
map
.
get
(
"amount"
);
imcomeList
.
add
(
map
);
}
}
for
(
Map
<
String
,
Object
>
map
:
expenseBillList
)
{
if
(
null
!=
managerSchoolMaps
.
get
(
map
.
get
(
"schoolName"
)))
{
map
.
put
(
"userName"
,
managerSchoolMaps
.
get
(
map
.
get
(
"schoolName"
)).
toString
());
expenseSum
+=
(
double
)
map
.
get
(
"amount"
);
expenseList
.
add
(
map
);
}
}
Map
<
String
,
Object
>
firstMap
=
new
HashMap
<>();
firstMap
.
put
(
"month"
,
"总计"
);
firstMap
.
put
(
"substName"
,
""
);
firstMap
.
put
(
"schoolName"
,
""
);
firstMap
.
put
(
"target"
,
statisType
);
firstMap
.
put
(
"billType"
,
""
);
firstMap
.
put
(
"billDetail"
,
""
);
firstMap
.
put
(
"amount"
,
df
.
parse
(
Double
.
toString
(
incomeSum
)));
firstMap
.
put
(
"billTypeExpense"
,
""
);
firstMap
.
put
(
"billDetailExpense"
,
""
);
firstMap
.
put
(
"amountExpense"
,
df
.
parse
(
Double
.
toString
(
expenseSum
)));
firstMap
.
put
(
"taxAmount"
,
df
.
parse
(
Double
.
toString
(
taxAmount
)));
imcomeList
=
addGroupSum
(
imcomeList
,
statisType
);
expenseList
=
addGroupSum
(
expenseList
,
statisType
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
dataList
=
dealDataOther
(
imcomeList
,
expenseList
,
statisType
);
dataList
.
add
(
0
,
firstMap
);
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
if
(
dataList
.
size
()
<
pageNo
*
pageSize
)
{
resultList
=
dataList
.
subList
((
pageNo
-
1
)*
pageSize
,
dataList
.
size
());
}
else
{
resultList
=
dataList
.
subList
((
pageNo
-
1
)*
pageSize
,
pageNo
*
pageSize
);
}
page
.
setRecords
(
resultList
);
page
.
setTotal
(
dataList
.
size
());
return
ResponseData
.
success
(
page
,
"查询成功"
);
}
public
List
<
Map
<
String
,
Object
>>
addGroupSum
(
List
<
Map
<
String
,
Object
>>
list
,
String
key
){
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<>();
DecimalFormat
df
=
new
DecimalFormat
(
"#.00"
);
if
(
list
.
size
()
>
0
)
{
// 取出第一个账单详情
Map
<
String
,
Object
>
theMap
=
list
.
get
(
0
);
String
theDetail
=
(
String
)
theMap
.
get
(
"billDetail"
);
double
groupSum
=
0.0
;
double
grouptTaxSum
=
0.0
;
String
target
=
(
String
)
theMap
.
get
(
key
);
boolean
existKey
=
"month"
.
equals
(
key
)
?
false
:
true
;
for
(
Map
<
String
,
Object
>
map
:
list
){
String
billDetail
=
(
String
)
map
.
get
(
"billDetail"
);
Double
amount
=
(
Double
)
map
.
get
(
"amount"
);
Double
taxAmount
=
(
Double
)
map
.
get
(
"taxAmount"
);
String
compareTarget
=
existKey
?
map
.
get
(
key
).
toString
()
:
""
;
if
((!
existKey
&&
theDetail
.
equals
(
billDetail
))
||
(
existKey
&&
theDetail
.
equals
(
billDetail
)
&&
compareTarget
.
equals
(
target
))
){
groupSum
+=
amount
;
grouptTaxSum
+=
taxAmount
;
resultList
.
add
(
map
);
}
else
{
Map
<
String
,
Object
>
sumMap
=
new
HashMap
<>();
sumMap
.
put
(
"billDetail"
,
"小计"
);
sumMap
.
put
(
"amount"
,
Double
.
parseDouble
(
df
.
format
(
groupSum
)));
sumMap
.
put
(
"taxAmount"
,
Double
.
parseDouble
(
df
.
format
(
grouptTaxSum
)));
sumMap
.
put
(
key
,
target
);
if
(
existKey
)
{
sumMap
.
put
(
key
,
target
);
}
resultList
.
add
(
sumMap
);
resultList
.
add
(
map
);
target
=
compareTarget
;
theDetail
=
billDetail
;
groupSum
=
amount
;
grouptTaxSum
=
taxAmount
;
}
}
Map
<
String
,
Object
>
lastMap
=
new
HashMap
<>();
lastMap
.
put
(
"billDetail"
,
"小计"
);
lastMap
.
put
(
"amount"
,
groupSum
);
lastMap
.
put
(
"taxAmount"
,
grouptTaxSum
);
lastMap
.
put
(
key
,
target
);
if
(
existKey
)
{
lastMap
.
put
(
key
,
target
);
}
resultList
.
add
(
lastMap
);
}
return
resultList
;
}
// 把支出和收入数据拼接
public
List
<
Map
<
String
,
Object
>>
dealData
(
List
<
Map
<
String
,
Object
>>
list1
,
List
<
Map
<
String
,
Object
>>
list2
,
String
target
){
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<>();
int
j
=
0
;
for
(
int
i
=
0
;
i
<
list1
.
size
()
;
i
++){
Map
<
String
,
Object
>
map1
=
list1
.
get
(
i
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
if
(
i
<
list2
.
size
()){
j
=
i
;
Map
<
String
,
Object
>
map2
=
list2
.
get
(
i
);
map
.
put
(
"month"
,
(
String
)
map1
.
get
(
"month"
));
map
.
put
(
"county"
,
(
String
)
map1
.
get
(
"county"
));
map
.
put
(
"school"
,
(
String
)
map1
.
get
(
"school"
));
map
.
put
(
target
,
(
String
)
map1
.
get
(
target
));
map
.
put
(
"billType"
,
(
String
)
map1
.
get
(
"billType"
));
map
.
put
(
"billDetail"
,
(
String
)
map1
.
get
(
"billDetail"
));
map
.
put
(
"amount"
,
Double
.
toString
((
Double
)
map1
.
get
(
"amount"
)));
map
.
put
(
"monthExpense"
,
(
String
)
map2
.
get
(
"month"
));
// map.put("county2", (String)map2.get("county"));
map
.
put
(
"billTypeExpense"
,
(
String
)
map2
.
get
(
"billType"
));
map
.
put
(
"billDetailExpense"
,
(
String
)
map2
.
get
(
"billDetail"
));
map
.
put
(
"amountExpense"
,
Double
.
toString
((
Double
)
map2
.
get
(
"amount"
)));
map
.
put
(
"taxAmount"
,
Double
.
toString
((
Double
)
map2
.
get
(
"taxAmount"
)));
resultList
.
add
(
map
);
}
else
{
// 没找到,则支出项留空
map
.
put
(
"month"
,
(
String
)
map1
.
get
(
"month"
));
map
.
put
(
"county"
,
(
String
)
map1
.
get
(
"county"
));
map
.
put
(
"school"
,
(
String
)
map1
.
get
(
"school"
));
map
.
put
(
target
,
(
String
)
map1
.
get
(
target
));
map
.
put
(
"billType"
,
(
String
)
map1
.
get
(
"billType"
));
map
.
put
(
"billDetail"
,
(
String
)
map1
.
get
(
"billDetail"
));
map
.
put
(
"amount"
,
Double
.
toString
((
Double
)
map1
.
get
(
"amount"
)));
map
.
put
(
"monthExpense"
,
""
);
// map.put("county2", "");
map
.
put
(
"billTypeExpense"
,
""
);
map
.
put
(
"billDetailExpense"
,
""
);
map
.
put
(
"amountExpense"
,
""
);
map
.
put
(
"taxAmount"
,
""
);
resultList
.
add
(
map
);
}
}
for
(
j
++;
j
<
list2
.
size
()
;
j
++){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map2
=
list2
.
get
(
j
);
map
.
put
(
"month"
,
""
);
map
.
put
(
"county"
,
(
String
)
map2
.
get
(
"county"
));
map
.
put
(
"school"
,
(
String
)
map2
.
get
(
"school"
));
map
.
put
(
"billType"
,
""
);
map
.
put
(
"billDetail"
,
""
);
map
.
put
(
"amount"
,
""
);
map
.
put
(
"monthExpense"
,
(
String
)
map2
.
get
(
"month"
));
// map.put("county2", (String)map2.get("county"));
map
.
put
(
"billTypeExpense"
,
(
String
)
map2
.
get
(
"billType"
));
map
.
put
(
"billDetailExpense"
,
(
String
)
map2
.
get
(
"billDetail"
));
map
.
put
(
"amountExpense"
,
Double
.
toString
((
Double
)
map2
.
get
(
"amount"
)));
map
.
put
(
"taxAmount"
,
Double
.
toString
((
Double
)
map2
.
get
(
"taxAmount"
)));
resultList
.
add
(
map
);
}
return
resultList
;
}
// 把支出和收入数据拼接
public
List
<
Map
<
String
,
Object
>>
dealDataOther
(
List
<
Map
<
String
,
Object
>>
list1
,
List
<
Map
<
String
,
Object
>>
list2
,
String
target
){
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
firstmap
=
list1
.
get
(
0
);
String
theTarget
=
(
String
)
firstmap
.
get
(
target
);
for
(
int
i
=
0
;
i
<
list1
.
size
()
;
i
++){
Map
<
String
,
Object
>
map1
=
list1
.
get
(
i
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
boolean
isFind
=
false
;
String
target1
=
(
String
)
map1
.
get
(
target
);
// 左边还有数据时,左边不存在匹配数据,右边存在匹配数据
if
(!
theTarget
.
equals
(
target1
)){
for
(
int
j
=
0
;
j
<
list2
.
size
()
;
j
++){
Map
<
String
,
Object
>
rightmap
=
new
HashMap
<>();
Map
<
String
,
Object
>
map2
=
list2
.
get
(
j
);
String
target2
=
(
String
)
map2
.
get
(
target
);
if
(
theTarget
.
equals
(
target2
)
){
rightmap
.
put
(
"month"
,
""
);
rightmap
.
put
(
"county"
,
""
);
rightmap
.
put
(
"school"
,
(
String
)
map2
.
get
(
"school"
));
rightmap
.
put
(
target
,
""
);
rightmap
.
put
(
"billType"
,
""
);
rightmap
.
put
(
"billDetail"
,
""
);
rightmap
.
put
(
"amount"
,
""
);
rightmap
.
put
(
"monthExpense"
,
(
String
)
map2
.
get
(
"month"
));
rightmap
.
put
(
target
+
"Expense"
,
(
String
)
map2
.
get
(
target
));
rightmap
.
put
(
"billTypeExpense"
,
(
String
)
map2
.
get
(
"billType"
));
rightmap
.
put
(
"billDetailExpense"
,
(
String
)
map2
.
get
(
"billDetail"
));
rightmap
.
put
(
"amountExpense"
,
Double
.
toString
((
Double
)
map2
.
get
(
"amount"
)));
rightmap
.
put
(
"taxAmount"
,
Double
.
toString
((
Double
)
map2
.
get
(
"taxAmount"
)));
resultList
.
add
(
rightmap
);
list2
.
remove
(
j
);
j
--;
}
else
{
break
;
}
}
}
theTarget
=
target1
;
for
(
int
j
=
0
;
j
<
list2
.
size
();
j
++){
Map
<
String
,
Object
>
map2
=
list2
.
get
(
j
);
String
target2
=
(
String
)
map2
.
get
(
target
);
if
(
target1
.
equals
(
target2
)
){
map
.
put
(
"month"
,
(
String
)
map1
.
get
(
"month"
));
map
.
put
(
"county"
,
(
String
)
map1
.
get
(
"county"
));
map
.
put
(
"school"
,
(
String
)
map1
.
get
(
"school"
));
map
.
put
(
target
,
(
String
)
map1
.
get
(
target
));
map
.
put
(
"billType"
,
(
String
)
map1
.
get
(
"billType"
));
map
.
put
(
"billDetail"
,
(
String
)
map1
.
get
(
"billDetail"
));
map
.
put
(
"amount"
,
Double
.
toString
((
Double
)
map1
.
get
(
"amount"
)));
map
.
put
(
"monthExpense"
,
(
String
)
map2
.
get
(
"month"
));
map
.
put
(
target
+
"Expense"
,
(
String
)
map2
.
get
(
target
));
map
.
put
(
"billTypeExpense"
,
(
String
)
map2
.
get
(
"billType"
));
map
.
put
(
"billDetailExpense"
,
(
String
)
map2
.
get
(
"billDetail"
));
map
.
put
(
"amountExpense"
,
Double
.
toString
((
Double
)
map2
.
get
(
"amount"
)));
map
.
put
(
"taxAmount"
,
Double
.
toString
((
Double
)
map2
.
get
(
"taxAmount"
)));
isFind
=
true
;
resultList
.
add
(
map
);
list2
.
remove
(
j
);
break
;
}
}
// 找到对应支出,则跳出本次循环
if
(
isFind
)
continue
;
// 没找到,则支出项留空
map
.
put
(
"month"
,
(
String
)
map1
.
get
(
"month"
));
map
.
put
(
"county"
,
(
String
)
map1
.
get
(
"county"
));
map
.
put
(
"school"
,
(
String
)
map1
.
get
(
"school"
));
map
.
put
(
target
,
(
String
)
map1
.
get
(
target
));
map
.
put
(
"billType"
,
(
String
)
map1
.
get
(
"billType"
));
map
.
put
(
"billDetail"
,
(
String
)
map1
.
get
(
"billDetail"
));
map
.
put
(
"amount"
,
Double
.
toString
((
Double
)
map1
.
get
(
"amount"
)));
map
.
put
(
"monthExpense"
,
""
);
map
.
put
(
target
+
"Expense"
,
""
);
map
.
put
(
"billTypeExpense"
,
""
);
map
.
put
(
"billDetailExpense"
,
""
);
map
.
put
(
"amountExpense"
,
""
);
map
.
put
(
"taxAmount"
,
""
);
resultList
.
add
(
map
);
}
for
(
int
i
=
0
;
i
<
list2
.
size
()
;
i
++){
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map2
=
list2
.
get
(
i
);
map
.
put
(
"month"
,
""
);
map
.
put
(
"county"
,
(
String
)
map2
.
get
(
"county"
));
map
.
put
(
"school"
,
(
String
)
map2
.
get
(
"school"
));
map
.
put
(
target
,
""
);
map
.
put
(
"billType"
,
""
);
map
.
put
(
"billDetail"
,
""
);
map
.
put
(
"amount"
,
""
);
map
.
put
(
"monthExpense"
,
(
String
)
map2
.
get
(
"month"
));
map
.
put
(
target
+
"Expense"
,
(
String
)
map2
.
get
(
target
));
map
.
put
(
"billTypeExpense"
,
(
String
)
map2
.
get
(
"billType"
));
map
.
put
(
"billDetailExpense"
,
(
String
)
map2
.
get
(
"billDetail"
));
map
.
put
(
"amountExpense"
,
Double
.
toString
((
Double
)
map2
.
get
(
"amount"
)));
map
.
put
(
"taxAmount"
,
Double
.
toString
((
Double
)
map2
.
get
(
"taxAmount"
)));
resultList
.
add
(
map
);
}
return
resultList
;
}
}
service-manager/src/main/java/com/winsun/controller/BonusController.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
controller
;
import
java.io.IOException
;
import
java.security.SecureRandom
;
import
java.text.DecimalFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.locks.Lock
;
import
java.util.concurrent.locks.ReentrantLock
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.poi.xssf.usermodel.XSSFCell
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.baomidou.mybatisplus.mapper.Wrapper
;
import
com.baomidou.mybatisplus.plugins.Page
;
import
com.itextpdf.text.pdf.PdfStructTreeController.returnType
;
import
com.winsun.auth.core.annotion.Permission
;
import
com.winsun.auth.core.base.controller.BaseController
;
import
com.winsun.auth.core.common.model.ResponseData
;
import
com.winsun.auth.core.shiro.ShiroUser
;
import
com.winsun.auth.core.util.IOUtils
;
import
com.winsun.bean.Bill
;
import
com.winsun.bean.BonusApply
;
import
com.winsun.bean.HhrUser
;
import
com.winsun.bean.SalesOrder
;
import
com.winsun.bean.School
;
import
com.winsun.bean.SysUser
;
import
com.winsun.mapper.BonusMapper
;
import
com.winsun.mapper.HhrUserMapper
;
import
com.winsun.mapper.SalesOrderMapper
;
import
com.winsun.mapper.SchoolMapper
;
import
com.winsun.mapper.SysUserMapper
;
import
com.winsun.tenpay.CorporatePrepayResponse
;
import
com.winsun.tenpay.business.TenpayXyjlBusiness
;
import
com.winsun.utils.ExcelDealUtils
;
import
com.winsun.utils.MapUtil
;
import
lombok.extern.slf4j.Slf4j
;
/**
* 奖励结算 controller
* @Author: dongyp
* @Date: 2020/5/6
*/
@Slf4j
@RestController
@RequestMapping
(
"/bonus"
)
public
class
BonusController
extends
BaseController
{
private
static
BonusMapper
bonusMapper
;
private
static
SysUserMapper
sysUserMapper
;
private
static
SchoolMapper
schoolMapper
;
public
static
Lock
lock
=
new
ReentrantLock
();
List
<
Map
<
String
,
Object
>>
exportResponseList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
@Autowired
private
HhrUserMapper
hhrUserMapper
;
@Autowired
private
SalesOrderMapper
salesOrderMapper
;
@Autowired
public
BonusController
(
BonusMapper
bonusMapper
,
SysUserMapper
sysUserMapper
,
SchoolMapper
schoolMapper
)
{
BonusController
.
bonusMapper
=
bonusMapper
;
BonusController
.
sysUserMapper
=
sysUserMapper
;
BonusController
.
schoolMapper
=
schoolMapper
;
}
@Permission
(
menuname
=
"获取佣金申请数据"
,
value
=
"applyDataList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
Map
<
String
,
Object
>>>
applyDataList
(
@RequestParam
(
"userName"
)
String
userName
,
@RequestParam
(
"account"
)
String
account
,
@RequestParam
(
"substName"
)
String
substName
,
@RequestParam
(
name
=
"schoolName"
,
required
=
false
)
String
schoolName
,
@RequestParam
(
name
=
"isBind"
,
required
=
false
)
String
isBind
,
@RequestParam
(
name
=
"pageNo"
,
required
=
false
)
int
pageIndex
,
@RequestParam
(
name
=
"pageSize"
,
required
=
false
)
int
pageSize
)
{
Wrapper
<
SalesOrder
>
wrapperSales
=
new
EntityWrapper
<
SalesOrder
>();
wrapperSales
.
setSqlSelect
(
" user_id userId,sum(non_send_bonus) bonus "
);
wrapperSales
.
eq
(
"status"
,
3
);
wrapperSales
.
eq
(
"del_flag"
,
0
);
wrapperSales
.
ne
(
"non_send_bonus"
,
0
);
wrapperSales
.
groupBy
(
"user_id"
);
List
<
Map
<
String
,
Object
>>
salesList
=
salesOrderMapper
.
selectMaps
(
wrapperSales
);
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
setSqlSelect
(
" id,account,name "
);
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
account
),
"account"
,
account
);
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
userName
),
"name"
,
userName
);
//wrapperSys.ne("status", 1);
Map
<
String
,
Map
<
String
,
Object
>>
sysUserMaps
=
MapUtil
.
listToMap
(
sysUserMapper
.
selectMaps
(
wrapperSys
),
"id"
);
Wrapper
<
HhrUser
>
wrapperHhr
=
new
EntityWrapper
<
HhrUser
>();
wrapperHhr
.
setSqlSelect
(
" id,(case when open_id is not null then '已绑定' else '未绑定' end) isBind "
);
if
(
StringUtils
.
isNotBlank
(
isBind
))
{
if
(
"0"
.
equals
(
isBind
))
{
wrapperHhr
.
isNull
(
"open_id"
);
}
else
{
wrapperHhr
.
isNotNull
(
"open_id"
);
}
}
Map
<
String
,
Object
>
hhrUserMaps
=
MapUtil
.
listToMap
(
hhrUserMapper
.
selectMaps
(
wrapperHhr
),
"id"
,
"isBind"
);
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" sub_name substName,school_name schoolName,id "
);
wrapperSchool
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"sub_name"
,
substName
);
wrapperSchool
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
Map
<
String
,
Map
<
String
,
Object
>>
schoolMaps
=
MapUtil
.
listToMap
(
schoolMapper
.
selectMaps
(
wrapperSchool
),
"id"
);
Map
<
String
,
Object
>
schoolRefMap
=
MapUtil
.
listToMap
(
schoolMapper
.
getSchoolRef
(),
"user_id"
,
"school_id"
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
map
:
salesList
)
{
String
userId
=
map
.
get
(
"userId"
).
toString
();
boolean
isMatch
=
false
;
if
(
null
!=
sysUserMaps
.
get
(
userId
))
{
Map
<
String
,
Object
>
sysUserMap
=
sysUserMaps
.
get
(
userId
);
map
.
put
(
"account"
,
sysUserMap
.
get
(
"account"
));
map
.
put
(
"userName"
,
sysUserMap
.
get
(
"name"
));
isMatch
=
true
;
}
if
(
isMatch
&&
null
!=
hhrUserMaps
.
get
(
userId
))
{
map
.
put
(
"isBind"
,
hhrUserMaps
.
get
(
userId
).
toString
());
String
schoolId
=
schoolRefMap
.
get
(
userId
).
toString
();
if
(
null
!=
schoolMaps
.
get
(
schoolId
))
{
Map
<
String
,
Object
>
schoolMap
=
schoolMaps
.
get
(
schoolId
);
map
.
put
(
"substName"
,
schoolMap
.
get
(
"substName"
));
map
.
put
(
"schoolName"
,
schoolMap
.
get
(
"schoolName"
));
dataList
.
add
(
map
);
}
}
}
Page
<
Map
<
String
,
Object
>>
page
=
new
Page
<>(
pageIndex
,
pageSize
);
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
if
(
dataList
.
size
()
<
pageIndex
*
pageSize
)
{
list
=
dataList
.
subList
((
pageIndex
-
1
)*
pageSize
,
dataList
.
size
());
}
else
{
list
=
dataList
.
subList
((
pageIndex
-
1
)*
pageSize
,
pageIndex
*
pageSize
);
}
page
.
setRecords
(
list
);
page
.
setTotal
(
dataList
.
size
());
return
ResponseData
.
success
(
page
,
"查询完毕!"
);
}
@Permission
(
menuname
=
"发起申请生成订单"
,
value
=
"productOrder"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
productOrder
(
@RequestParam
(
"ids"
)
String
ids
,
@RequestParam
(
"status"
)
String
status
){
Wrapper
<
SalesOrder
>
wrapperSales
=
new
EntityWrapper
<
SalesOrder
>();
wrapperSales
.
setSqlSelect
(
" user_id userId,non_send_bonus bonus,order_phone orderPhone,id "
);
wrapperSales
.
eq
(
"status"
,
3
);
wrapperSales
.
eq
(
"del_flag"
,
0
);
wrapperSales
.
ne
(
"non_send_bonus"
,
0
);
wrapperSales
.
in
(
"user_id"
,
ids
);
List
<
Map
<
String
,
Object
>>
salesList
=
salesOrderMapper
.
selectMaps
(
wrapperSales
);
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
setSqlSelect
(
" id,account,name "
);
wrapperSys
.
eq
(
"status"
,
1
);
Map
<
String
,
Map
<
String
,
Object
>>
sysUserMaps
=
MapUtil
.
listToMap
(
sysUserMapper
.
selectMaps
(
wrapperSys
),
"id"
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
map
:
salesList
)
{
String
userId
=
map
.
get
(
"userId"
).
toString
();
if
(
null
!=
sysUserMaps
.
get
(
userId
))
{
dataList
.
add
(
map
);
}
}
List
<
Map
<
String
,
Object
>>
applyList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
List
<
Map
<
String
,
Object
>>
applyDetailList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
Map
<
String
,
Object
>
firstMap
=
dataList
.
get
(
0
);
String
theUserId
=
firstMap
.
get
(
"userId"
).
toString
();
double
bonus
=
0
;;
String
applyNum
=
"Tbo"
+
Long
.
toString
(
System
.
currentTimeMillis
())
+
(
int
)(
Math
.
random
()*
100000
)
;
for
(
Map
<
String
,
Object
>
map
:
dataList
)
{
String
userId
=
map
.
get
(
"userId"
).
toString
();
double
theBonus
=
(
double
)
map
.
get
(
"bonus"
);
String
bonusNum
=
"Tb"
+
Long
.
toString
(
System
.
currentTimeMillis
())
+
(
int
)(
Math
.
random
()*
100000
)
;
if
(
userId
.
equals
(
theUserId
))
{
bonus
+=
theBonus
;
}
else
{
Map
<
String
,
Object
>
applyMap
=
new
HashMap
<
String
,
Object
>();
applyMap
.
put
(
"userId"
,
theUserId
);
applyMap
.
put
(
"bonus"
,
bonus
);
applyMap
.
put
(
"applyNum"
,
applyNum
);
applyMap
.
put
(
"bonusNum"
,
bonusNum
);
applyList
.
add
(
applyMap
);
bonus
=
theBonus
;
}
map
.
put
(
"applyNum"
,
applyNum
);
map
.
put
(
"bonusNum"
,
bonusNum
);
applyDetailList
.
add
(
map
);
theUserId
=
userId
;
}
Map
<
String
,
Object
>
lastMap
=
new
HashMap
<
String
,
Object
>();
String
lastBonusNum
=
"Tb"
+
Long
.
toString
(
System
.
currentTimeMillis
())
+
(
int
)(
Math
.
random
()*
100000
)
;
lastMap
.
put
(
"userId"
,
theUserId
);
lastMap
.
put
(
"bonus"
,
bonus
);
lastMap
.
put
(
"applyNum"
,
applyNum
);
lastMap
.
put
(
"bonusNum"
,
lastBonusNum
);
applyList
.
add
(
lastMap
);
ShiroUser
user
=
getShiroUser
();
// 插入数据库
for
(
Map
<
String
,
Object
>
map
:
applyList
)
{
List
<
BonusApply
>
bonusList
=
new
ArrayList
<
BonusApply
>();
BonusApply
bonusApply
=
new
BonusApply
();
bonusApply
.
setApplyNum
(
map
.
get
(
"applyNum"
).
toString
());
bonusApply
.
setUserId
(
map
.
get
(
"userId"
).
toString
());
bonusApply
.
setBonus
((
double
)
map
.
get
(
"bonus"
));
bonusApply
.
setApplicant
(
user
.
getName
());
bonusApply
.
setBonusNum
(
map
.
get
(
"bonusNum"
).
toString
());
bonusApply
.
setApplicantId
(
Integer
.
toString
(
user
.
getId
()));
bonusApply
.
setCreateDate
(
new
Date
());
bonusMapper
.
insert
(
bonusApply
);
}
for
(
Map
<
String
,
Object
>
map
:
applyDetailList
)
{
String
orderPhone
=
map
.
get
(
"orderPhone"
).
toString
();
double
theBonus
=
(
double
)
map
.
get
(
"bonus"
);
int
salesId
=
(
int
)
map
.
get
(
"id"
);
String
theApplyNum
=
map
.
get
(
"applyNum"
).
toString
();
String
bonusNum
=
map
.
get
(
"bonusNum"
).
toString
();
bonusMapper
.
addApplyDetail
(
theBonus
,
theApplyNum
,
bonusNum
,
salesId
,
orderPhone
);
}
return
ResponseData
.
success
(
"申请成功"
);
}
@Permission
(
menuname
=
"获取佣金申请单"
,
value
=
"applyOrderList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
Map
<
String
,
Object
>>>
applyOrderList
(
@RequestParam
(
"userName"
)
String
userName
,
@RequestParam
(
"substName"
)
String
substName
,
@RequestParam
(
name
=
"schoolName"
,
required
=
false
)
String
schoolName
,
@RequestParam
(
"state"
)
String
state
,
@RequestParam
(
"applyNum"
)
String
applyNum
,
@RequestParam
(
name
=
"pageNo"
,
required
=
false
)
int
pageIndex
,
@RequestParam
(
name
=
"pageSize"
,
required
=
false
)
int
pageSize
)
{
Wrapper
<
BonusApply
>
wrapperApply
=
new
EntityWrapper
<
BonusApply
>();
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
applyNum
),
"apply_num"
,
applyNum
);
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
state
),
"state"
,
state
);
List
<
Map
<
String
,
Object
>>
applyList
=
bonusMapper
.
selectMaps
(
wrapperApply
);
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
setSqlSelect
(
" id,account,name "
);
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
userName
),
"name"
,
userName
);
wrapperSys
.
eq
(
"status"
,
1
);
Map
<
String
,
Map
<
String
,
Object
>>
sysUserMaps
=
MapUtil
.
listToMap
(
sysUserMapper
.
selectMaps
(
wrapperSys
),
"id"
);
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" sub_name substName,school_name schoolName,id "
);
wrapperSchool
.
eq
(
StringUtils
.
isNoneBlank
(
substName
),
"sub_name"
,
substName
);
wrapperSchool
.
eq
(
StringUtils
.
isNoneBlank
(
schoolName
),
"school_name"
,
schoolName
);
Map
<
String
,
Map
<
String
,
Object
>>
schoolMaps
=
MapUtil
.
listToMap
(
schoolMapper
.
selectMaps
(
wrapperSchool
),
"id"
);
Map
<
String
,
Object
>
schoolRefMap
=
MapUtil
.
listToMap
(
schoolMapper
.
getSchoolRef
(),
"user_id"
,
"school_id"
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
map
:
applyList
)
{
String
userId
=
map
.
get
(
"userId"
).
toString
();
if
(
null
!=
sysUserMaps
.
get
(
userId
))
{
Map
<
String
,
Object
>
sysUserMap
=
sysUserMaps
.
get
(
userId
);
map
.
put
(
"account"
,
sysUserMap
.
get
(
"account"
));
map
.
put
(
"userName"
,
sysUserMap
.
get
(
"name"
));
String
schoolId
=
schoolRefMap
.
get
(
userId
).
toString
();
if
(
null
!=
schoolMaps
.
get
(
schoolId
))
{
Map
<
String
,
Object
>
schoolMap
=
schoolMaps
.
get
(
schoolId
);
map
.
put
(
"substName"
,
schoolMap
.
get
(
"substName"
));
map
.
put
(
"schoolName"
,
schoolMap
.
get
(
"schoolName"
));
dataList
.
add
(
map
);
}
}
}
Page
<
Map
<
String
,
Object
>>
page
=
new
Page
<>(
pageIndex
,
pageSize
);
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<
Map
<
String
,
Object
>>();
if
(
dataList
.
size
()
<
pageIndex
*
pageSize
)
{
list
=
dataList
.
subList
((
pageIndex
-
1
)*
pageSize
,
dataList
.
size
());
}
else
{
list
=
dataList
.
subList
((
pageIndex
-
1
)*
pageSize
,
pageIndex
*
pageSize
);
}
page
.
setRecords
(
list
);
page
.
setTotal
(
dataList
.
size
());
return
ResponseData
.
success
(
page
,
"查询完毕!"
);
}
@Permission
(
menuname
=
"修改申请单状态"
,
value
=
"updateState"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
updateState
(
@RequestParam
(
"applyNums"
)
String
applyNums
,
@RequestParam
(
"state"
)
String
state
){
String
[]
applyNumArray
=
applyNums
.
split
(
","
);
for
(
String
applyNum
:
applyNumArray
)
{
Wrapper
<
BonusApply
>
wrapper
=
new
EntityWrapper
<
BonusApply
>();
wrapper
.
eq
(
"apply_num"
,
applyNum
);
BonusApply
bonusApply
=
new
BonusApply
();
bonusApply
.
setState
(
state
);
int
num
=
bonusMapper
.
update
(
bonusApply
,
wrapper
);
}
return
ResponseData
.
success
(
"申请成功"
);
}
@Permission
(
menuname
=
"获取申请单审核列表"
,
value
=
"auditOrderList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
BonusApply
>>
auditOrderList
(
@RequestParam
(
"applicant"
)
String
applicant
,
@RequestParam
(
"state"
)
String
state
,
@RequestParam
(
"applyNum"
)
String
applyNum
,
@RequestParam
(
name
=
"pageNo"
,
required
=
false
)
int
pageIndex
,
@RequestParam
(
name
=
"pageSize"
,
required
=
false
)
int
pageSize
)
{
Page
<
BonusApply
>
page
=
new
Page
<>(
pageIndex
,
pageSize
);
Wrapper
<
BonusApply
>
wrapperApply
=
new
EntityWrapper
<
BonusApply
>();
wrapperApply
.
setSqlSelect
(
" id,apply_num applyNum,state,create_date createDate,sum(bonus) bonus,applicant"
);
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
applicant
),
"applicant"
,
applicant
);
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
applyNum
),
"apply_num"
,
applyNum
);
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
state
),
"state"
,
state
);
wrapperApply
.
groupBy
(
"apply_num"
);
List
<
BonusApply
>
dataList
=
bonusMapper
.
selectPage
(
page
,
wrapperApply
);
page
.
setRecords
(
dataList
);
return
ResponseData
.
success
(
page
,
"查询完毕!"
);
}
@Permission
(
menuname
=
"获取佣金结算"
,
value
=
"bonusList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
Page
<
Map
<
String
,
Object
>>>
bonusList
(
@RequestParam
(
"account"
)
String
account
,
@RequestParam
(
"state"
)
String
state
,
@RequestParam
(
"userName"
)
String
userName
,
@RequestParam
(
name
=
"pageNo"
,
required
=
false
)
int
pageIndex
,
@RequestParam
(
name
=
"pageSize"
,
required
=
false
)
int
pageSize
)
{
Page
<
Map
<
String
,
Object
>>
page
=
new
Page
<>(
pageIndex
,
pageSize
);
Wrapper
<
BonusApply
>
wrapperApply
=
new
EntityWrapper
<
BonusApply
>();
wrapperApply
.
setSqlSelect
(
" id,state,create_date createDate,bonus,user_id userId,bonus_num bonusNum "
);
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
state
),
"state"
,
state
);
wrapperApply
.
in
(
"state"
,
"4,6,7"
);
List
<
Map
<
String
,
Object
>>
bonusList
=
bonusMapper
.
selectMaps
(
wrapperApply
);
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
account
),
"account"
,
account
);
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
userName
),
"name"
,
userName
);
wrapperSys
.
eq
(
"status"
,
1
);
List
<
Map
<
String
,
Object
>>
sysList
=
sysUserMapper
.
selectMaps
(
wrapperSys
);
Wrapper
<
HhrUser
>
wrapperHhr
=
new
EntityWrapper
<
HhrUser
>();
Map
<
String
,
Object
>
hhrMaps
=
MapUtil
.
listToMap
(
hhrUserMapper
.
selectMaps
(
wrapperHhr
),
"id"
,
"open_id"
);
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" sub_name substName,school_name schoolName,id "
);
Map
<
String
,
Map
<
String
,
Object
>>
schoolMaps
=
MapUtil
.
listToMap
(
schoolMapper
.
selectMaps
(
wrapperSchool
),
"id"
);
Map
<
String
,
Object
>
schoolRefMap
=
MapUtil
.
listToMap
(
schoolMapper
.
getSchoolRef
(),
"user_id"
,
"school_id"
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
bonusMap
:
bonusList
)
{
String
userId
=
Integer
.
toString
((
int
)
bonusMap
.
get
(
"userId"
));
bonusMap
.
put
(
"isBind"
,
"未绑定"
);
if
(
null
!=
hhrMaps
.
get
(
userId
)
&&
StringUtils
.
isNotBlank
((
String
)
hhrMaps
.
get
(
userId
)))
{
bonusMap
.
put
(
"isBind"
,
"已绑定"
);
}
for
(
Map
<
String
,
Object
>
sysMap
:
sysList
)
{
String
theUserId
=
Integer
.
toString
((
int
)
sysMap
.
get
(
"id"
));
String
schoolId
=
schoolRefMap
.
get
(
userId
).
toString
();
if
(
null
!=
schoolMaps
.
get
(
schoolId
))
{
Map
<
String
,
Object
>
schoolMap
=
schoolMaps
.
get
(
schoolId
);
bonusMap
.
put
(
"substName"
,
schoolMap
.
get
(
"substName"
));
bonusMap
.
put
(
"schoolName"
,
schoolMap
.
get
(
"schoolName"
));
}
if
(
theUserId
.
equals
(
userId
))
{
bonusMap
.
put
(
"account"
,
sysMap
.
get
(
"account"
));
bonusMap
.
put
(
"userName"
,
sysMap
.
get
(
"name"
));
dataList
.
add
(
bonusMap
);
}
}
}
if
(
dataList
.
size
()
<
pageIndex
*
pageSize
)
{
resultList
=
dataList
.
subList
((
pageIndex
-
1
)*
pageSize
,
dataList
.
size
());
}
else
{
resultList
=
dataList
.
subList
((
pageIndex
-
1
)*
pageSize
,
pageIndex
*
pageSize
);
}
page
.
setRecords
(
resultList
);
page
.
setTotal
(
dataList
.
size
());
return
ResponseData
.
success
(
page
,
"查询完毕!"
);
}
@Permission
(
menuname
=
"佣金结算"
,
value
=
"sendBonus"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
sendBonus
(
@RequestParam
(
"bonusNums"
)
String
bonusNums
)
{
Wrapper
<
BonusApply
>
wrapperApply
=
new
EntityWrapper
<
BonusApply
>();
wrapperApply
.
setSqlSelect
(
" id,state,apply_num applyNum,bonus_num bonusNum,create_date createDate,bonus,user_id userId"
);
wrapperApply
.
in
(
"bonus_num"
,
bonusNums
);
List
<
Map
<
String
,
Object
>>
bonusList
=
bonusMapper
.
selectMaps
(
wrapperApply
);
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
eq
(
"status"
,
1
);
List
<
Map
<
String
,
Object
>>
sysList
=
sysUserMapper
.
selectMaps
(
wrapperSys
);
Wrapper
<
HhrUser
>
wrapperHhr
=
new
EntityWrapper
<
HhrUser
>();
wrapperHhr
.
setSqlSelect
(
" id,open_id,grade,position "
);
Map
<
String
,
Object
>
hhrMaps
=
MapUtil
.
listToMap
(
hhrUserMapper
.
selectMaps
(
wrapperHhr
),
"id"
,
"open_id"
);
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" sub_name substName,school_name schoolName,id "
);
Map
<
String
,
Map
<
String
,
Object
>>
schoolMaps
=
MapUtil
.
listToMap
(
schoolMapper
.
selectMaps
(
wrapperSchool
),
"id"
);
Map
<
String
,
Object
>
schoolRefMap
=
MapUtil
.
listToMap
(
schoolMapper
.
getSchoolRef
(),
"user_id"
,
"school_id"
);
// 提前取出销售清单数据
Wrapper
<
SalesOrder
>
wrapperOrder
=
new
EntityWrapper
<
SalesOrder
>();
wrapperOrder
.
ne
(
"non_send_bonus"
,
0
);
wrapperOrder
.
eq
(
"del_flag"
,
0
);
Map
<
String
,
Map
<
String
,
Object
>>
orderMaps
=
MapUtil
.
listToMap
(
salesOrderMapper
.
selectMaps
(
wrapperOrder
),
"id"
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
bonusMap
:
bonusList
)
{
String
userId
=
Integer
.
toString
((
int
)
bonusMap
.
get
(
"userId"
));
bonusMap
.
put
(
"openId"
,
hhrMaps
.
get
(
userId
));
for
(
Map
<
String
,
Object
>
sysMap
:
sysList
)
{
String
theUserId
=
Integer
.
toString
((
int
)
sysMap
.
get
(
"id"
));
String
schoolId
=
schoolRefMap
.
get
(
userId
).
toString
();
if
(
null
!=
schoolMaps
.
get
(
schoolId
))
{
Map
<
String
,
Object
>
schoolMap
=
schoolMaps
.
get
(
schoolId
);
bonusMap
.
put
(
"substName"
,
schoolMap
.
get
(
"substName"
));
bonusMap
.
put
(
"schoolName"
,
schoolMap
.
get
(
"schoolName"
));
}
if
(
theUserId
.
equals
(
userId
))
{
bonusMap
.
put
(
"account"
,
sysMap
.
get
(
"account"
));
bonusMap
.
put
(
"userName"
,
sysMap
.
get
(
"name"
));
dataList
.
add
(
bonusMap
);
}
}
}
exportResponseList
=
null
;
int
num
=
wxPayBonus
(
dataList
,
orderMaps
);
StringBuffer
info
=
new
StringBuffer
();
resultMap
.
put
(
"num"
,
num
);
info
.
append
(
"成功结算"
+
num
+
"记录。"
);
if
(
dataList
.
size
()
<
num
)
{
info
.
append
((
dataList
.
size
()
-
num
)
+
"结算失败"
);
}
return
ResponseData
.
success
(
info
.
toString
(),
"success"
);
}
public
int
wxPayBonus
(
List
<
Map
<
String
,
Object
>>
list
,
Map
<
String
,
Map
<
String
,
Object
>>
orderMaps
)
{
ShiroUser
user
=
getShiroUser
();
int
successNum
=
0
;
for
(
Map
<
String
,
Object
>
map
:
list
)
{
String
account
=
map
.
get
(
"account"
).
toString
();
double
amount
=
Double
.
valueOf
(
map
.
get
(
"bonus"
).
toString
()).
doubleValue
();
int
id
=
(
int
)
map
.
get
(
"id"
);
String
openid
=
map
.
get
(
"openId"
).
toString
();
String
bonusNum
=
map
.
get
(
"bonusNum"
).
toString
();
String
orderNum
=
getOrderNumber
(
"T00"
);
String
desc
=
"发起结算;管理员"
+
user
.
getAccount
()
+
"发起向销售员"
+
account
+
"(id为"
+
id
+
")发放奖励金"
+
amount
+
"元"
;
String
sendDesc
=
"校园合伙人向您发放奖励金"
+
amount
+
"元;订单号为"
+
orderNum
+
";"
;
bonusMapper
.
addBonusLog
(
orderNum
,
desc
,
"微信企业付款"
,
user
.
getId
(),
0
);
// 测试
amount
=
1
;
openid
=
"oLLfr0_XJc2mcaRqRl3sOQ7GwmVw"
;
int
sendAmount
=
(
int
)
(
amount
*
100.0
D
);
String
createIp
=
"127.0.0.1"
;
String
check_name
=
"NO_CHECK"
;
String
re_user_name
=
""
;
CorporatePrepayResponse
resp
;
try
{
resp
=
TenpayXyjlBusiness
.
xyjlTenPayRequest
(
orderNum
,
openid
,
check_name
,
re_user_name
,
sendAmount
,
sendDesc
,
createIp
);
if
(
StringUtils
.
isNotBlank
(
resp
.
getPaymentNo
()))
{
desc
=
"结算成功;管理员"
+
user
.
getAccount
()
+
"发起向销售员"
+
account
+
"(id为"
+
id
+
")发放奖励金"
+
amount
+
"元"
;
bonusMapper
.
updateBonus
(
1
,
id
);
bonusMapper
.
updateBonusLog
(
desc
,
resp
.
getPaymentNo
(),
1
,
orderNum
);
updateSalesOrderBonus
(
bonusNum
,
orderMaps
);
successNum
++;
}
else
{
desc
=
"结算失败;管理员"
+
user
.
getAccount
()
+
"发起向销售员"
+
account
+
"发放奖励金"
+
amount
+
"元"
;
bonusMapper
.
updateBonusLog
(
desc
,
""
,
0
,
orderNum
);
Map
<
String
,
Object
>
respMap
=
new
HashMap
<
String
,
Object
>();
respMap
.
put
(
"account"
,
map
.
get
(
"account"
));
respMap
.
put
(
"name"
,
map
.
get
(
"name"
));
respMap
.
put
(
"substName"
,
map
.
get
(
"substName"
));
respMap
.
put
(
"schoolName"
,
map
.
get
(
"schoolName"
));
respMap
.
put
(
"bonus"
,
map
.
get
(
"bonus"
));
respMap
.
put
(
"desc"
,
resp
.
getErrCodeDesc
());
exportResponseList
.
add
(
respMap
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
successNum
;
}
public
void
updateSalesOrderBonus
(
String
bonusNum
,
Map
<
String
,
Map
<
String
,
Object
>>
orderMaps
)
{
List
<
Map
<
String
,
Object
>>
list
=
bonusMapper
.
getBonusDetail
(
bonusNum
);
for
(
Map
<
String
,
Object
>
map
:
list
)
{
int
salesId
=
(
int
)
map
.
get
(
"salesId"
);
double
bonus
=
(
double
)
map
.
get
(
"bonus"
);
Map
<
String
,
Object
>
orderMap
=
orderMaps
.
get
(
Integer
.
toString
((
int
)
map
.
get
(
"salesId"
)));
double
nonSendBonus
=
(
double
)
orderMap
.
get
(
"nonSendBonus"
)
-
bonus
;
double
sendBonus
=
(
double
)
orderMap
.
get
(
"SendBonus"
)
+
bonus
;
SalesOrder
salesOrder
=
new
SalesOrder
();
salesOrder
.
setId
(
salesId
);
salesOrder
.
setNonSendBonus
(
nonSendBonus
);
salesOrder
.
setSendBonus
(
sendBonus
);
salesOrderMapper
.
updateById
(
salesOrder
);
}
}
public
String
getOrderNumber
(
String
code
)
{
// 订单号格式(20):业务编码(3)+年(2)+月(2)+日(2)+时(2)+分(2)+秒(2)+五位随机数(5)
String
businessCode
=
code
;
// 业务编码,暂时没设为"T00"
SimpleDateFormat
formatter
;
formatter
=
new
SimpleDateFormat
(
"yyMMddhhmmss"
);
// 时间格式
String
times
=
formatter
.
format
(
System
.
currentTimeMillis
());
SecureRandom
random
=
new
SecureRandom
();
int
num
=
random
.
nextInt
(
100000
);
String
orderNo
=
businessCode
+
times
+
num
;
return
orderNo
;
}
@Permission
(
menuname
=
"导出奖励结算反馈"
,
value
=
"exportResult"
,
method
=
RequestMethod
.
POST
)
public
void
exportSendResult
()
throws
IOException
{
List
<
String
>
tops
=
new
ArrayList
<>();
tops
.
add
(
"账号"
);
tops
.
add
(
"姓名"
);
tops
.
add
(
"县分"
);
tops
.
add
(
"学校"
);
tops
.
add
(
"金额"
);
tops
.
add
(
"结算失败原因"
);
List
<
String
>
columns
=
new
ArrayList
<>();
columns
.
add
(
"account"
);
columns
.
add
(
"userName"
);
columns
.
add
(
"substName"
);
columns
.
add
(
"schoolName"
);
columns
.
add
(
"bonus"
);
columns
.
add
(
"desc"
);
ServletOutputStream
os
=
null
;
XSSFWorkbook
workbook
=
new
XSSFWorkbook
();
try
{
//创建工作表
XSSFSheet
sheet
=
workbook
.
createSheet
(
"结算失败清单"
);
//添加表头
final
XSSFRow
row
=
sheet
.
createRow
(
0
);
//设置列宽度
sheet
.
setColumnWidth
(
1
,
3000
);
//第一行字段名称
tops
.
forEach
(
column
->
{
XSSFCell
cell
=
row
.
createCell
(
Math
.
max
(
row
.
getLastCellNum
(),
0
));
cell
.
setCellValue
(
column
);
});
//数据
int
rowIndex
=
row
.
getRowNum
();
for
(
Map
<
String
,
Object
>
maps:
exportResponseList
)
{
final
XSSFRow
rowdata
=
sheet
.
createRow
(++
rowIndex
);
for
(
String
column
:
columns
)
{
XSSFCell
cell
=
rowdata
.
createCell
(
Math
.
max
(
rowdata
.
getLastCellNum
(),
0
));
if
(
maps
.
get
(
column
)
!=
null
)
{
cell
.
setCellValue
(
maps
.
get
(
column
).
toString
());
}
}
}
HttpServletResponse
response
=
getHttpServletResponse
();
response
.
reset
();
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
os
=
response
.
getOutputStream
();
workbook
.
write
(
os
);
os
.
flush
();
exportResponseList
=
null
;
}
catch
(
Exception
e
)
{
log
.
error
(
"文件出错!"
+
e
.
getMessage
(),
e
);
}
finally
{
IOUtils
.
closeQuite
(
workbook
,
os
);
}
}
@Permission
(
menuname
=
"导出奖励结算清单"
,
value
=
"exportSettlementList"
,
method
=
RequestMethod
.
POST
)
public
void
exportStatisList
(
@RequestParam
(
"account"
)
String
account
,
@RequestParam
(
"state"
)
String
state
,
@RequestParam
(
"userName"
)
String
userName
)
throws
IOException
{
Wrapper
<
BonusApply
>
wrapperApply
=
new
EntityWrapper
<
BonusApply
>();
wrapperApply
.
setSqlSelect
(
" id,state,create_date createDate,bonus,user_id userId"
);
wrapperApply
.
eq
(
StringUtils
.
isNotBlank
(
state
),
"state"
,
state
);
wrapperApply
.
in
(
"state"
,
"4,6,7"
);
List
<
Map
<
String
,
Object
>>
bonusList
=
bonusMapper
.
selectMaps
(
wrapperApply
);
Wrapper
<
SysUser
>
wrapperSys
=
new
EntityWrapper
<
SysUser
>();
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
account
),
"account"
,
account
);
wrapperSys
.
eq
(
StringUtils
.
isNotBlank
(
userName
),
"name"
,
userName
);
wrapperSys
.
eq
(
"status"
,
1
);
wrapperSys
.
eq
(
"del_flag"
,
0
);
List
<
Map
<
String
,
Object
>>
sysList
=
sysUserMapper
.
selectMaps
(
wrapperSys
);
Wrapper
<
HhrUser
>
wrapperHhr
=
new
EntityWrapper
<
HhrUser
>();
Map
<
String
,
Object
>
hhrMaps
=
MapUtil
.
listToMap
(
hhrUserMapper
.
selectMaps
(
wrapperHhr
),
"id"
,
"open_id"
);
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" sub_name substName,school_name schoolName,id "
);
Map
<
String
,
Map
<
String
,
Object
>>
schoolMaps
=
MapUtil
.
listToMap
(
schoolMapper
.
selectMaps
(
wrapperSchool
),
"id"
);
Map
<
String
,
Object
>
schoolRefMap
=
MapUtil
.
listToMap
(
schoolMapper
.
getSchoolRef
(),
"user_id"
,
"school_id"
);
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
List
<
Map
<
String
,
Object
>>
resultList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
for
(
Map
<
String
,
Object
>
bonusMap
:
bonusList
)
{
String
userId
=
Integer
.
toString
((
int
)
bonusMap
.
get
(
"userId"
));
bonusMap
.
put
(
"isBind"
,
"未绑定"
);
if
(
null
!=
hhrMaps
.
get
(
userId
)
&&
StringUtils
.
isNotBlank
((
String
)
hhrMaps
.
get
(
userId
)))
{
bonusMap
.
put
(
"isBind"
,
"已绑定"
);
}
for
(
Map
<
String
,
Object
>
sysMap
:
sysList
)
{
String
theUserId
=
Integer
.
toString
((
int
)
sysMap
.
get
(
"id"
));
String
schoolId
=
schoolRefMap
.
get
(
userId
).
toString
();
if
(
null
!=
schoolMaps
.
get
(
schoolId
))
{
Map
<
String
,
Object
>
schoolMap
=
schoolMaps
.
get
(
schoolId
);
bonusMap
.
put
(
"substName"
,
schoolMap
.
get
(
"substName"
));
bonusMap
.
put
(
"schoolName"
,
schoolMap
.
get
(
"schoolName"
));
}
if
(
theUserId
.
equals
(
userId
))
{
bonusMap
.
put
(
"account"
,
sysMap
.
get
(
"account"
));
bonusMap
.
put
(
"userName"
,
sysMap
.
get
(
"name"
));
dataList
.
add
(
bonusMap
);
}
}
}
ServletOutputStream
os
=
null
;
XSSFWorkbook
workbook
=
ExcelDealUtils
.
getWorkBook
(
ExcelDealUtils
.
bonusExcel
(
"奖励结算清单"
),
dataList
);
try
{
HttpServletResponse
response
=
getHttpServletResponse
();
response
.
reset
();
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setContentType
(
"application/octet-stream"
);
os
=
response
.
getOutputStream
();
workbook
.
write
(
os
);
os
.
flush
();
}
catch
(
Exception
e
)
{
log
.
error
(
"文件出错!"
+
e
.
getMessage
(),
e
);
}
finally
{
IOUtils
.
closeQuite
(
workbook
,
os
);
}
}
}
service-manager/src/main/java/com/winsun/controller/SalesOrderController.java
View file @
8d9c8598
package
com
.
winsun
.
controller
;
import
java.io.IOException
;
import
java.sql.Timestamp
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
...
...
@@ -40,7 +39,6 @@ import com.winsun.auth.core.util.IOUtils;
import
com.winsun.bean.SalesOrder
;
import
com.winsun.bean.School
;
import
com.winsun.bean.SysUser
;
import
com.winsun.bean.YrymReport
;
import
com.winsun.mapper.SalesOrderMapper
;
import
com.winsun.mapper.SchoolMapper
;
import
com.winsun.mapper.SysUserMapper
;
...
...
@@ -206,20 +204,6 @@ public class SalesOrderController extends BaseController{
* if (in != null) { in.close(); } }
*/
}
/**
* 根据县分名称获取一人一码发展统计表数据
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
private
List
<
YrymReport
>
getReportNum
(
String
startTime
,
String
endTime
)
{
List
<
YrymReport
>
resultList
=
new
ArrayList
<>();
return
resultList
;
}
/**
* 受理订单
...
...
@@ -227,7 +211,8 @@ public class SalesOrderController extends BaseController{
* @param file 上传的数据文件
* @return
*/
@Permission
(
menuname
=
"上传订单数据"
,
value
=
"importOrder"
,
method
=
RequestMethod
.
POST
)
@SuppressWarnings
(
"unchecked"
)
@Permission
(
menuname
=
"上传订单数据"
,
value
=
"importOrder"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
importOrder
(
@RequestParam
(
name
=
"file"
)
MultipartFile
file
)
{
StringBuffer
info
=
new
StringBuffer
();
if
(!
StringUtils
.
endsWithAny
(
file
.
getOriginalFilename
(),
"xlsx"
,
"xls"
))
{
...
...
@@ -397,6 +382,8 @@ public class SalesOrderController extends BaseController{
order
.
setSalesSubst
((
String
)
map
.
get
(
"salesSubst"
));
order
.
setSalesSchool
((
String
)
map
.
get
(
"salesSchool"
));
order
.
setOrderType
(
"1"
);
order
.
setName
((
String
)
map
.
get
(
"name"
));
order
.
setAccount
((
String
)
map
.
get
(
"account"
));
num
+=
salesOrderMapper
.
insert
(
order
);
}
...
...
@@ -432,7 +419,6 @@ public class SalesOrderController extends BaseController{
*/
@Permission
(
menuname
=
"充值审核"
,
value
=
"importRechargeData"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
String
>
importRechargeData
(
@RequestParam
(
name
=
"file"
)
MultipartFile
file
)
{
StringBuffer
info
=
new
StringBuffer
();
if
(!
StringUtils
.
endsWithAny
(
file
.
getOriginalFilename
(),
"xlsx"
,
"xls"
))
{
return
ResponseData
.
error
(
"手工上传数据仅支持Excel文件,其他格式不支持!"
);
}
...
...
@@ -510,7 +496,6 @@ public class SalesOrderController extends BaseController{
// 处理充值审核数据
public
int
dealRechargeData
(
List
<
Map
<
String
,
Object
>>
list
){
Map
<
String
,
Object
>
resultMap
=
new
HashMap
<
String
,
Object
>();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Calendar
calendar
=
Calendar
.
getInstance
();
...
...
@@ -524,13 +509,13 @@ public class SalesOrderController extends BaseController{
wrapperOrder
.
eq
(
"send_bonus"
,
0
);
wrapperOrder
.
ne
(
"status"
,
"0"
);
List
<
Map
<
String
,
Object
>>
orderList
=
salesOrderMapper
.
selectMaps
(
wrapperOrder
);
Map
<
String
,
Object
>
orderMaps
=
MapUtil
.
listToMap
(
orderList
,
"orderPhone"
);
Map
<
String
,
Map
<
String
,
Object
>
>
orderMaps
=
MapUtil
.
listToMap
(
orderList
,
"orderPhone"
);
// 获取学校清单比较网点
Wrapper
<
School
>
wrapperSchool
=
new
EntityWrapper
<
School
>();
wrapperSchool
.
setSqlSelect
(
" school_name as schoolName,network_name as networkName,network_code as networkCode "
);
List
<
Map
<
String
,
Object
>>
schoolList
=
schoolMapper
.
selectMaps
(
wrapperSchool
);
Map
<
String
,
Object
>
schoolMaps
=
MapUtil
.
listToMap
(
schoolList
,
"schoolName"
);
Map
<
String
,
Map
<
String
,
Object
>
>
schoolMaps
=
MapUtil
.
listToMap
(
schoolList
,
"schoolName"
);
List
<
Map
<
String
,
Object
>>
updateList
=
new
ArrayList
<
Map
<
String
,
Object
>>();
...
...
@@ -634,7 +619,7 @@ public class SalesOrderController extends BaseController{
}
@Permission
(
menuname
=
"放号上传模板"
,
method
=
RequestMethod
.
POST
,
value
=
"downloadTemplateFH"
)
public
ResponseData
downloadTemplateFH
()
{
public
ResponseData
<
String
>
downloadTemplateFH
()
{
ArrayList
<
String
>
columns
=
new
ArrayList
<>();
columns
.
add
(
FH_SORT
);
columns
.
add
(
FH_ORDER_PHONE
);
...
...
@@ -679,7 +664,7 @@ public class SalesOrderController extends BaseController{
}
@Permission
(
menuname
=
"充值审核模板"
,
method
=
RequestMethod
.
POST
,
value
=
"downloadTemplateCZ"
)
public
ResponseData
downloadTemplateCZ
()
{
public
ResponseData
<
String
>
downloadTemplateCZ
()
{
ArrayList
<
String
>
columns
=
new
ArrayList
<>();
columns
.
add
(
CZ_ORDER_PHONE
);
columns
.
add
(
CZ_ACTIVATE_TIME
);
...
...
service-manager/src/main/java/com/winsun/controller/SchoolManagementController.java
View file @
8d9c8598
package
com
.
winsun
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.baomidou.mybatisplus.enums.SqlLike
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.baomidou.mybatisplus.mapper.Wrapper
;
import
com.baomidou.mybatisplus.plugins.Page
;
import
com.winsun.auth.core.annotion.Permission
;
import
com.winsun.auth.core.base.controller.BaseController
;
import
com.winsun.auth.core.common.model.ResponseData
;
import
com.winsun.auth.core.shiro.ShiroUser
;
import
com.winsun.bean.Package
;
import
com.winsun.bean.Product
;
...
...
@@ -19,21 +33,8 @@ import com.winsun.mapper.SchoolMapper;
import
com.winsun.mapper.SchoolPackageMapper
;
import
com.winsun.utils.FileUtil
;
import
com.winsun.utils.MyBatisPlusUpdateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.winsun.auth.core.common.model.ResponseData
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
lombok.extern.slf4j.Slf4j
;
/**
* @Author: chancy
...
...
@@ -238,6 +239,7 @@ public class SchoolManagementController extends BaseController {
schoolPackages
.
forEach
(
val
->{
arrayList
.
add
(
val
.
getPackageId
());
});
hashMap
.
put
(
"choosepages"
,
arrayList
);
return
ResponseData
.
success
(
hashMap
,
"查询完毕!"
);
}
...
...
@@ -257,12 +259,13 @@ public class SchoolManagementController extends BaseController {
return
ResponseData
.
success
(
"上传成功"
);
}
@Permission
(
menuname
=
"获取县分下拉列表"
,
value
=
"substList"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
name
=
"获取县分下拉列表"
,
value
=
"substList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
List
<
Map
<
String
,
Object
>>>
substList
()
{
ShiroUser
user
=
getShiroUser
();
if
(!
user
.
getRoleNames
().
stream
().
anyMatch
(
roleName
->
StringUtils
.
equalsAny
(
roleName
,
"超级管理员"
)))
{
return
ResponseData
.
error
(
"无数据权限"
);
}
//
ShiroUser user = getShiroUser();
//
if (!user.getRoleNames().stream().anyMatch(roleName -> StringUtils.equalsAny(roleName, "超级管理员"))) {
//
return ResponseData.error("无数据权限");
//
}
// 查询县分列表
Wrapper
<
School
>
wrapperSubName
=
new
EntityWrapper
<
School
>();
...
...
@@ -274,12 +277,12 @@ public class SchoolManagementController extends BaseController {
return
ResponseData
.
success
(
substNameList
,
"查询完毕!"
);
}
@Permission
(
menu
name
=
"获取学校下拉列表"
,
value
=
"schoolList"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
name
=
"获取学校下拉列表"
,
value
=
"schoolList"
,
method
=
RequestMethod
.
POST
)
public
ResponseData
<
List
<
Map
<
String
,
Object
>>>
schoolList
(
@RequestParam
(
"substName"
)
String
substName
)
{
ShiroUser
user
=
getShiroUser
();
if
(!
user
.
getRoleNames
().
stream
().
anyMatch
(
roleName
->
StringUtils
.
equalsAny
(
roleName
,
"超级管理员"
)))
{
return
ResponseData
.
error
(
"无数据权限"
);
}
//
ShiroUser user = getShiroUser();
//
if (!user.getRoleNames().stream().anyMatch(roleName -> StringUtils.equalsAny(roleName, "超级管理员"))) {
//
return ResponseData.error("无数据权限");
//
}
// 查询县分列表
Wrapper
<
School
>
wrapper
=
new
EntityWrapper
<
School
>();
...
...
service-manager/src/main/java/com/winsun/tenpay/AlipayGlobals.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
;
import
java.util.Properties
;
public
class
AlipayGlobals
{
public
static
final
String
PARAMS_LIST
=
"paramsList"
;
private
static
Properties
properties
=
null
;
private
static
synchronized
void
loadProperties
()
{
if
(
properties
==
null
)
{
properties
=
new
InitPropLoader
().
getProperties
(
"tenpayconfig.properties"
);
}
}
public
static
synchronized
void
reloadProperties
()
{
properties
=
null
;
properties
=
new
InitPropLoader
().
getProperties
(
"tenpayconfig.properties"
);
}
public
static
String
getProperty
(
String
property
)
{
loadProperties
();
String
value
=
null
;
if
(
properties
!=
null
)
{
value
=
properties
.
getProperty
(
property
);
if
(
value
!=
null
)
{
value
=
value
.
trim
();
}
}
return
value
;
}
}
service-manager/src/main/java/com/winsun/tenpay/CorporatePrepayResponse.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
;
public
class
CorporatePrepayResponse
{
private
String
appId
;
private
String
timeStamp
;
private
String
nonceStr
;
private
String
_package
;
private
String
signType
;
private
String
paySign
;
private
String
appKey
;
private
String
mchId
;
private
String
paymentNo
;
private
int
amount
;
private
String
openid
;
private
String
partnerid
;
private
String
prepareid
;
private
String
errCodeDesc
;
public
String
getAppId
()
{
return
this
.
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
String
getTimeStamp
()
{
return
this
.
timeStamp
;
}
public
void
setTimeStamp
(
String
timeStamp
)
{
this
.
timeStamp
=
timeStamp
;
}
public
String
getNonceStr
()
{
return
this
.
nonceStr
;
}
public
void
setNonceStr
(
String
nonceStr
)
{
this
.
nonceStr
=
nonceStr
;
}
public
String
get_package
()
{
return
this
.
_package
;
}
public
void
set_package
(
String
package1
)
{
this
.
_package
=
package1
;
}
public
String
getSignType
()
{
return
this
.
signType
;
}
public
void
setSignType
(
String
signType
)
{
this
.
signType
=
signType
;
}
public
String
getPaySign
()
{
return
this
.
paySign
;
}
public
void
setPaySign
(
String
paySign
)
{
this
.
paySign
=
paySign
;
}
public
String
getAppKey
()
{
return
this
.
appKey
;
}
public
void
setAppKey
(
String
appKey
)
{
this
.
appKey
=
appKey
;
}
public
String
getPartnerid
()
{
return
this
.
partnerid
;
}
public
void
setPartnerid
(
String
partnerid
)
{
this
.
partnerid
=
partnerid
;
}
public
String
getPrepareid
()
{
return
this
.
prepareid
;
}
public
void
setPrepareid
(
String
prepareid
)
{
this
.
prepareid
=
prepareid
;
}
public
String
getMchId
()
{
return
mchId
;
}
public
void
setMchId
(
String
mchId
)
{
this
.
mchId
=
mchId
;
}
public
String
getPaymentNo
()
{
return
paymentNo
;
}
public
void
setPaymentNo
(
String
paymentNo
)
{
this
.
paymentNo
=
paymentNo
;
}
public
int
getAmount
()
{
return
amount
;
}
public
void
setAmount
(
int
amount
)
{
this
.
amount
=
amount
;
}
public
String
getOpenid
()
{
return
openid
;
}
public
void
setOpenid
(
String
openid
)
{
this
.
openid
=
openid
;
}
public
String
getErrCodeDesc
()
{
return
errCodeDesc
;
}
public
void
setErrCodeDesc
(
String
errCodeDesc
)
{
this
.
errCodeDesc
=
errCodeDesc
;
}
}
service-manager/src/main/java/com/winsun/tenpay/InitPropLoader.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
;
import
java.io.InputStream
;
import
java.util.Properties
;
public
class
InitPropLoader
{
public
Properties
getProperties
(
String
propName
)
{
Properties
prop
=
new
Properties
();
InputStream
in
=
null
;
try
{
in
=
InitPropLoader
.
class
.
getResourceAsStream
(
"/"
+
propName
);
prop
.
load
(
in
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
localException1
)
{}
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
localException2
)
{}
}
return
prop
;
}
}
service-manager/src/main/java/com/winsun/tenpay/NewIntfRequestHandler.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.winsun.tenpay.util.MD5Util
;
import
com.winsun.tenpay.util.TenpayUtil
;
public
class
NewIntfRequestHandler
{
private
String
gateUrl
;
private
String
key
;
private
SortedMap
parameters
;
private
String
debugInfo
;
protected
HttpServletRequest
request
;
protected
HttpServletResponse
response
;
public
NewIntfRequestHandler
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
this
.
request
=
request
;
this
.
response
=
response
;
// this.gateUrl = "https://gw.tenpay.com/gateway/pay.htm";
this
.
gateUrl
=
" https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
;
this
.
key
=
""
;
this
.
parameters
=
new
TreeMap
();
this
.
debugInfo
=
""
;
}
public
void
init
()
{
}
public
String
getGateUrl
()
{
return
this
.
gateUrl
;
}
public
void
setGateUrl
(
String
gateUrl
)
{
this
.
gateUrl
=
gateUrl
;
}
public
String
getKey
()
{
return
this
.
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getParameter
(
String
parameter
)
{
String
s
=
(
String
)
this
.
parameters
.
get
(
parameter
);
return
s
==
null
?
""
:
s
;
}
public
void
setParameter
(
String
parameter
,
String
parameterValue
)
{
String
v
=
""
;
if
(
parameterValue
!=
null
)
{
v
=
parameterValue
.
trim
();
}
this
.
parameters
.
put
(
parameter
,
v
);
}
public
SortedMap
getAllParameters
()
{
return
this
.
parameters
;
}
public
String
getDebugInfo
()
{
return
this
.
debugInfo
;
}
public
String
getRequestURL
()
throws
UnsupportedEncodingException
{
createSign
();
StringBuffer
sb
=
new
StringBuffer
();
String
enc
=
TenpayUtil
.
getCharacterEncoding
(
this
.
request
,
this
.
response
);
Set
es
=
this
.
parameters
.
entrySet
();
Iterator
it
=
es
.
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
it
.
next
();
String
k
=
(
String
)
entry
.
getKey
();
String
v
=
(
String
)
entry
.
getValue
();
if
(!
"spbill_create_ip"
.
equals
(
k
))
{
sb
.
append
(
k
+
"="
+
URLEncoder
.
encode
(
v
,
enc
)
+
"&"
);
}
else
{
sb
.
append
(
k
+
"="
+
v
.
replace
(
"\\."
,
"%2E"
)
+
"&"
);
}
}
String
reqPars
=
sb
.
substring
(
0
,
sb
.
lastIndexOf
(
"&"
));
return
getGateUrl
()
+
"?"
+
reqPars
;
}
public
void
doSend
()
throws
UnsupportedEncodingException
,
IOException
{
this
.
response
.
sendRedirect
(
getRequestURL
());
}
protected
void
createSign
()
{
StringBuffer
sb
=
new
StringBuffer
();
Set
es
=
this
.
parameters
.
entrySet
();
Iterator
it
=
es
.
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
it
.
next
();
String
k
=
(
String
)
entry
.
getKey
();
String
v
=
(
String
)
entry
.
getValue
();
if
((
v
!=
null
)
&&
(!
""
.
equals
(
v
))
&&
(!
"sign"
.
equals
(
k
))
&&
(!
"key"
.
equals
(
k
)))
{
sb
.
append
(
k
+
"="
+
v
+
"&"
);
}
}
sb
.
append
(
"key="
+
getKey
());
String
sign
=
MD5Util
.
MD5Encode
(
sb
.
toString
(),
"UTF-8"
).
toUpperCase
();
setParameter
(
"sign"
,
sign
);
setDebugInfo
(
sb
.
toString
()
+
" => sign:"
+
sign
);
}
protected
void
setDebugInfo
(
String
debugInfo
)
{
this
.
debugInfo
=
debugInfo
;
}
protected
HttpServletRequest
getHttpServletRequest
()
{
return
this
.
request
;
}
protected
HttpServletResponse
getHttpServletResponse
()
{
return
this
.
response
;
}
}
service-manager/src/main/java/com/winsun/tenpay/TenpayNotify.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
org.apache.log4j.Logger
;
import
org.dom4j.Document
;
import
org.dom4j.DocumentHelper
;
import
org.dom4j.Element
;
import
com.winsun.tenpay.util.ConstantUtil
;
import
com.winsun.tenpay.util.MD5Util
;
public
class
TenpayNotify
{
private
static
Logger
log
=
Logger
.
getLogger
(
TenpayNotify
.
class
);
public
static
void
buildSign
(
SortedMap
<
String
,
String
>
paramMap
)
{
try
{
StringBuffer
sb
=
new
StringBuffer
();
Set
set
=
paramMap
.
entrySet
();
Iterator
it
=
set
.
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
it
.
next
();
String
k
=
(
String
)
entry
.
getKey
();
String
v
=
(
String
)
entry
.
getValue
();
if
((
v
!=
null
)
&&
(!
""
.
equals
(
v
))
&&
(!
"sign"
.
equals
(
k
))
&&
(!
"key"
.
equals
(
k
)))
{
sb
.
append
(
k
+
"="
+
v
+
"&"
);
}
}
sb
.
append
(
"key="
+
ConstantUtil
.
APP_KEY
);
String
sign
=
MD5Util
.
MD5Encode
(
sb
.
toString
(),
"utf-8"
).
toUpperCase
();
paramMap
.
put
(
"sign"
,
sign
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
String
buildTradeSign
(
SortedMap
<
String
,
String
>
paramMap
)
{
String
sign
=
""
;
try
{
StringBuffer
sb
=
new
StringBuffer
();
Set
set
=
paramMap
.
entrySet
();
Iterator
it
=
set
.
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
it
.
next
();
String
k
=
(
String
)
entry
.
getKey
();
String
v
=
(
String
)
entry
.
getValue
();
if
((
v
!=
null
)
&&
(!
""
.
equals
(
v
))
&&
(!
"sign"
.
equals
(
k
))
&&
(!
"key"
.
equals
(
k
)))
{
sb
.
append
(
k
+
"="
+
v
+
"&"
);
}
}
sb
.
append
(
"key="
+
ConstantUtil
.
APP_KEY
);
sign
=
MD5Util
.
MD5Encode
(
sb
.
toString
(),
"utf-8"
).
toUpperCase
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
sign
;
}
public
static
boolean
verifySign
(
SortedMap
<
String
,
String
>
paramMap
)
{
try
{
StringBuffer
sb
=
new
StringBuffer
();
String
remoteSign
=
(
String
)
paramMap
.
remove
(
"sign"
);
Set
set
=
paramMap
.
entrySet
();
Iterator
it
=
set
.
iterator
();
while
(
it
.
hasNext
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
it
.
next
();
String
k
=
(
String
)
entry
.
getKey
();
String
v
=
(
String
)
entry
.
getValue
();
if
((
v
!=
null
)
&&
(!
""
.
equals
(
v
))
&&
(!
"sign"
.
equals
(
k
))
&&
(!
"key"
.
equals
(
k
)))
{
sb
.
append
(
k
+
"="
+
v
+
"&"
);
}
}
sb
.
append
(
"key="
+
ConstantUtil
.
APP_KEY
);
String
sign
=
MD5Util
.
MD5Encode
(
sb
.
toString
(),
"utf-8"
).
toUpperCase
(
Locale
.
ENGLISH
);
if
(
remoteSign
.
equals
(
sign
))
{
return
true
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
public
static
SortedMap
<
String
,
String
>
analyzeXmlToMap
(
String
xml
)
{
SortedMap
<
String
,
String
>
rtnMap
=
new
TreeMap
();
try
{
Document
doc
=
DocumentHelper
.
parseText
(
xml
);
Element
root
=
doc
.
getRootElement
();
String
code
=
root
.
element
(
"return_code"
).
getText
();
if
(
"SUCCESS"
.
equals
(
code
))
{
List
<
Element
>
elist
=
root
.
elements
();
for
(
Element
ele
:
elist
)
{
String
name
=
ele
.
getName
();
String
value
=
ele
.
getText
();
rtnMap
.
put
(
name
,
value
);
}
}
else
{
String
msg
=
root
.
element
(
"return_msg"
).
getText
();
log
.
error
(
"微信原生支付通知失败,建议校园奖励发起主动查询"
+
msg
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析微信原生支付xml异常,"
+
e
.
toString
());
e
.
printStackTrace
();
}
return
rtnMap
;
}
}
service-manager/src/main/java/com/winsun/tenpay/WxCorpRequestHandler.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
;
import
java.io.UnsupportedEncodingException
;
import
java.util.SortedMap
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.winsun.tenpay.util.HttpUtil
;
public
class
WxCorpRequestHandler
extends
NewIntfRequestHandler
{
public
WxCorpRequestHandler
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
super
(
request
,
response
);
}
public
String
getXmlBody
()
throws
UnsupportedEncodingException
{
StringBuffer
sb
=
new
StringBuffer
();
SortedMap
map
=
super
.
getAllParameters
();
/*
* <xml> <mch_appid>wxe062425f740c30d8</mch_appid>
* <mchid>10000098</mchid>
* <nonce_str>3PG2J4ILTKCH16CQ2502SI8ZNMTM67VS</nonce_str>
* <partner_trade_no>100000982014120919616</partner_trade_no>
* <openid>ohO4Gt7wVPxIT1A9GjFaMYMiZY1s</openid>
* <check_name>OPTION_CHECK</check_name> <re_user_name>张三</re_user_name>
* <amount>100</amount> <desc>节日快乐!</desc>
* <spbill_create_ip>10.2.3.10</spbill_create_ip>
* <sign>C97BDBACF37622775366F38B629F45E3</sign> </xml>
*/
sb
.
append
(
"<xml>\r\n"
);
sb
.
append
(
"<mch_appid>"
+
map
.
get
(
"mch_appid"
)
+
"</mch_appid>"
+
"\r\n"
);
sb
.
append
(
"<mchid>"
+
map
.
get
(
"mchid"
)
+
"</mchid>"
+
"\r\n"
);
sb
.
append
(
"<nonce_str>"
+
map
.
get
(
"nonce_str"
)
+
"</nonce_str>"
+
"\r\n"
);
sb
.
append
(
"<partner_trade_no>"
+
map
.
get
(
"partner_trade_no"
)
+
"</partner_trade_no>"
+
"\r\n"
);
sb
.
append
(
"<openid>"
+
map
.
get
(
"openid"
)
+
"</openid>"
+
"\r\n"
);
sb
.
append
(
"<check_name>"
+
map
.
get
(
"check_name"
)
+
"</check_name>"
+
"\r\n"
);
sb
.
append
(
"<re_user_name>"
+
map
.
get
(
"re_user_name"
)
+
"</re_user_name>"
+
"\r\n"
);
sb
.
append
(
"<amount>"
+
map
.
get
(
"amount"
)
+
"</amount>"
+
"\r\n"
);
sb
.
append
(
"<desc>"
+
map
.
get
(
"desc"
)
+
"</desc>"
+
"\r\n"
);
sb
.
append
(
"<spbill_create_ip>"
+
map
.
get
(
"spbill_create_ip"
)
+
"</spbill_create_ip>"
+
"\r\n"
);
sb
.
append
(
"<sign>"
+
map
.
get
(
"sign"
)
+
"</sign>"
+
"\r\n"
);
sb
.
append
(
"</xml>"
);
return
sb
.
toString
();
}
public
String
sendPost
()
throws
Exception
{
createSign
();
// return HttpUtil.doPostXml(getGateUrl(), getXmlBody());
return
HttpUtil
.
httpPost
(
getGateUrl
(),
getXmlBody
());
}
}
service-manager/src/main/java/com/winsun/tenpay/business/TenpayXyjlBusiness.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
business
;
import
java.util.SortedMap
;
import
java.util.TreeMap
;
import
org.apache.log4j.Logger
;
import
com.winsun.tenpay.CorporatePrepayResponse
;
import
com.winsun.tenpay.TenpayNotify
;
import
com.winsun.tenpay.WxCorpRequestHandler
;
import
com.winsun.tenpay.util.ConstantUtil
;
import
com.winsun.tenpay.util.HttpUtil
;
import
com.winsun.tenpay.util.StringUtil
;
import
com.winsun.tenpay.util.WXUtil
;
import
com.winsun.tenpay.util.XmlParser
;
public
class
TenpayXyjlBusiness
{
private
static
Logger
log
=
Logger
.
getLogger
(
TenpayXyjlBusiness
.
class
);
public
static
CorporatePrepayResponse
xyjlTenPayRequest
(
String
orderno
,
String
openid
,
String
check_name
,
String
re_user_name
,
int
amount
,
String
desc
,
String
createIp
)
throws
Exception
{
CorporatePrepayResponse
response
=
new
CorporatePrepayResponse
();
WxCorpRequestHandler
handler
=
new
WxCorpRequestHandler
(
null
,
null
);
handler
.
setGateUrl
(
ConstantUtil
.
PAY_URL
);
handler
.
setKey
(
ConstantUtil
.
APP_KEY
);
handler
.
setParameter
(
"mch_appid"
,
ConstantUtil
.
APP_ID
);
handler
.
setParameter
(
"mchid"
,
ConstantUtil
.
MCH_ID
);
handler
.
setParameter
(
"nonce_str"
,
WXUtil
.
getNonceStr
());
handler
.
setParameter
(
"partner_trade_no"
,
orderno
);
handler
.
setParameter
(
"openid"
,
openid
);
handler
.
setParameter
(
"check_name"
,
check_name
);
handler
.
setParameter
(
"re_user_name"
,
re_user_name
);
handler
.
setParameter
(
"amount"
,
amount
+
""
);
// handler.setParameter("desc", URLEncoder.encode(desc,"UTF-8"));
handler
.
setParameter
(
"desc"
,
desc
);
handler
.
setParameter
(
"spbill_create_ip"
,
createIp
);
// handler.setParameter("notify_url", notifyUrl);
String
xml
=
handler
.
sendPost
();
//String xml = "";
String
err_code
=
""
;
String
err_code_des
=
""
;
try
{
XmlParser
xmlParser
=
new
XmlParser
(
xml
);
String
payment_no
=
xmlParser
.
getSingleValue
(
"//payment_no"
);
// 企业付款成功,返回的微信订单号
if
(
StringUtil
.
isBlank
(
payment_no
))
{
err_code
=
xmlParser
.
getSingleValue
(
"//err_code"
);
err_code_des
=
xmlParser
.
getSingleValue
(
"//err_code_des"
);
response
.
setErrCodeDesc
(
err_code_des
);
//log.info("支付失败 ,code=" + err_code + "失败原因:msg= " + err_code_des);
}
String
partner_trade_no
=
xmlParser
.
getSingleValue
(
"//partner_trade_no"
);
String
mchid
=
xmlParser
.
getSingleValue
(
"//mchid"
);
String
mch_appid
=
xmlParser
.
getSingleValue
(
"//mch_appid"
);
String
device_info
=
xmlParser
.
getSingleValue
(
"//device_info"
);
String
payment_time
=
xmlParser
.
getSingleValue
(
"//payment_time"
);
String
nonce_str
=
xmlParser
.
getSingleValue
(
"//nonce_str"
);
SortedMap
<
String
,
String
>
paramMap
=
new
TreeMap
();
paramMap
.
put
(
"appid"
,
ConstantUtil
.
APP_ID
);
paramMap
.
put
(
"timestamp"
,
System
.
currentTimeMillis
()
/
1000L
+
""
);
paramMap
.
put
(
"noncestr"
,
nonce_str
);
paramMap
.
put
(
"mchid"
,
mchid
);
paramMap
.
put
(
"mchAppid"
,
mch_appid
);
paramMap
.
put
(
"partner_trade_no"
,
partner_trade_no
);
paramMap
.
put
(
"payment_no"
,
payment_no
);
paramMap
.
put
(
"deviceInfo"
,
device_info
);
paramMap
.
put
(
"payment_time"
,
payment_time
);
TenpayNotify
.
buildSign
(
paramMap
);
response
.
setAppId
((
String
)
paramMap
.
get
(
"appid"
));
response
.
setAppKey
((
String
)
paramMap
.
get
(
"appkey"
));
response
.
setNonceStr
((
String
)
paramMap
.
get
(
"noncestr"
));
response
.
setPaymentNo
((
String
)
paramMap
.
get
(
"payment_no"
));
response
.
setTimeStamp
((
String
)
paramMap
.
get
(
"payment_time"
));
response
.
setPaySign
((
String
)
paramMap
.
get
(
"sign"
));
response
.
setAmount
(
amount
);
response
.
setOpenid
(
openid
);
return
response
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
Exception
(
e
.
getMessage
());
}
}
public
static
String
query
(
String
out_trade_no
,
String
tenpay_no
)
{
String
url
=
ConstantUtil
.
QUERY_GATEURL
;
String
app_id
=
ConstantUtil
.
APP_ID
;
String
partner
=
ConstantUtil
.
MCH_ID
;
String
nonce_str
=
WXUtil
.
getNonceStr
();
SortedMap
<
String
,
String
>
paramMap
=
new
TreeMap
();
paramMap
.
put
(
"appid"
,
app_id
);
paramMap
.
put
(
"mch_id"
,
partner
);
paramMap
.
put
(
"transaction_id"
,
tenpay_no
);
paramMap
.
put
(
"out_trade_no"
,
out_trade_no
);
paramMap
.
put
(
"nonce_str"
,
nonce_str
);
String
sign
=
TenpayNotify
.
buildTradeSign
(
paramMap
);
StringBuffer
xml
=
new
StringBuffer
();
xml
.
append
(
"<xml><appid>"
+
app_id
+
"</appid><mch_id>"
+
partner
+
"</mch_id>"
);
xml
.
append
(
"<nonce_str>"
+
nonce_str
+
"</nonce_str><out_trade_no>"
+
out_trade_no
+
"</out_trade_no>"
);
xml
.
append
(
"<sign>"
+
sign
+
"</sign>"
+
"</xml>"
);
return
HttpUtil
.
doPostXml
(
url
,
xml
.
toString
());
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
orderNo
=
"1000018284310"
;
String
desc
=
"test201630"
;
int
amount
=
101
;
String
openid
=
"oJodewFb4QpzLzcp4neLllT1XDoc"
;
String
createIp
=
"10.17.66.44"
;
String
check_name
=
"NO_CHECK"
;
String
re_user_name
=
"test1"
;
String
notifyUrl
=
"dianyuanjiangli.com"
;
xyjlTenPayRequest
(
orderNo
,
openid
,
check_name
,
re_user_name
,
amount
,
desc
,
createIp
);
// xyWapRequest( orderNo, amount, desc, "", createIp, openid,
// notifyUrl);
}
}
service-manager/src/main/java/com/winsun/tenpay/util/ConstantUtil.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
com.winsun.tenpay.AlipayGlobals
;
public
class
ConstantUtil
{
public
static
String
APP_ID
=
AlipayGlobals
.
getProperty
(
"tenpay_app_id"
);
public
static
String
APP_SECRET
=
AlipayGlobals
.
getProperty
(
"tenpay_app_secret"
);
public
static
String
APP_KEY
=
AlipayGlobals
.
getProperty
(
"tenpay_app_key"
);
public
static
String
MCH_ID
=
AlipayGlobals
.
getProperty
(
"tenpay_mch_id"
);
public
static
String
PKCS12_PWD
=
"1498149672"
;
// public static String PUBLIC_APP_ID = "wx5b38a65a0b95a857";
// public static String PUBLIC_MCH_ID = "1353779102";
// public static String PUBLIC_APP_KEY = "0123winsun43243434w0s7su223xy2jl";
public
static
String
QUERY_GATEURL
=
"https://api.mch.weixin.qq.com/pay/orderquery"
;
public
static
String
PAY_URL
=
"https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
;
}
service-manager/src/main/java/com/winsun/tenpay/util/HttpClientUtil.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.security.KeyManagementException
;
import
java.security.KeyStore
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.SecureRandom
;
import
java.security.UnrecoverableKeyException
;
import
java.security.cert.Certificate
;
import
java.security.cert.CertificateException
;
import
java.security.cert.CertificateFactory
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.KeyManagerFactory
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.TrustManagerFactory
;
public
class
HttpClientUtil
{
public
static
final
String
SunX509
=
"SunX509"
;
public
static
final
String
JKS
=
"JKS"
;
public
static
final
String
PKCS12
=
"PKCS12"
;
public
static
final
String
TLS
=
"TLS"
;
public
static
HttpURLConnection
getHttpURLConnection
(
String
strUrl
)
throws
IOException
{
URL
url
=
new
URL
(
strUrl
);
HttpURLConnection
httpURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
return
httpURLConnection
;
}
public
static
HttpsURLConnection
getHttpsURLConnection
(
String
strUrl
)
throws
IOException
{
URL
url
=
new
URL
(
strUrl
);
HttpsURLConnection
httpsURLConnection
=
(
HttpsURLConnection
)
url
.
openConnection
();
return
httpsURLConnection
;
}
public
static
String
getURL
(
String
strUrl
)
{
if
(
strUrl
!=
null
)
{
int
indexOf
=
strUrl
.
indexOf
(
"?"
);
if
(-
1
!=
indexOf
)
{
return
strUrl
.
substring
(
0
,
indexOf
);
}
return
strUrl
;
}
return
strUrl
;
}
public
static
String
getQueryString
(
String
strUrl
)
{
if
(
strUrl
!=
null
)
{
int
indexOf
=
strUrl
.
indexOf
(
"?"
);
if
(-
1
!=
indexOf
)
{
return
strUrl
.
substring
(
indexOf
+
1
,
strUrl
.
length
());
}
return
""
;
}
return
strUrl
;
}
public
static
Map
queryString2Map
(
String
queryString
)
{
if
((
queryString
==
null
)
||
(
""
.
equals
(
queryString
)))
{
return
null
;
}
Map
m
=
new
HashMap
();
String
[]
strArray
=
queryString
.
split
(
"&"
);
for
(
int
index
=
0
;
index
<
strArray
.
length
;
index
++)
{
String
pair
=
strArray
[
index
];
putMapByPair
(
pair
,
m
);
}
return
m
;
}
public
static
void
putMapByPair
(
String
pair
,
Map
m
)
{
if
((
pair
==
null
)
||
(
""
.
equals
(
pair
)))
{
return
;
}
int
indexOf
=
pair
.
indexOf
(
"="
);
if
(-
1
!=
indexOf
)
{
String
k
=
pair
.
substring
(
0
,
indexOf
);
String
v
=
pair
.
substring
(
indexOf
+
1
,
pair
.
length
());
if
((
k
!=
null
)
&&
(!
""
.
equals
(
k
)))
{
m
.
put
(
k
,
v
);
}
}
else
{
m
.
put
(
pair
,
""
);
}
}
public
static
String
bufferedReader2String
(
BufferedReader
reader
)
throws
IOException
{
StringBuffer
buf
=
new
StringBuffer
();
String
line
=
null
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
buf
.
append
(
line
);
buf
.
append
(
"\r\n"
);
}
return
buf
.
toString
();
}
public
static
void
doOutput
(
OutputStream
out
,
byte
[]
data
,
int
len
)
throws
IOException
{
int
dataLen
=
data
.
length
;
int
off
=
0
;
while
(
off
<
data
.
length
)
{
if
(
len
>=
dataLen
)
{
out
.
write
(
data
,
off
,
dataLen
);
off
+=
dataLen
;
}
else
{
out
.
write
(
data
,
off
,
len
);
off
+=
len
;
dataLen
-=
len
;
}
out
.
flush
();
}
}
public
static
SSLContext
getSSLContext
(
FileInputStream
trustFileInputStream
,
String
trustPasswd
,
FileInputStream
keyFileInputStream
,
String
keyPasswd
)
throws
NoSuchAlgorithmException
,
KeyStoreException
,
CertificateException
,
IOException
,
UnrecoverableKeyException
,
KeyManagementException
{
TrustManagerFactory
tmf
=
TrustManagerFactory
.
getInstance
(
"SunX509"
);
KeyStore
trustKeyStore
=
KeyStore
.
getInstance
(
"JKS"
);
trustKeyStore
.
load
(
trustFileInputStream
,
str2CharArray
(
trustPasswd
));
tmf
.
init
(
trustKeyStore
);
char
[]
kp
=
str2CharArray
(
keyPasswd
);
KeyManagerFactory
kmf
=
KeyManagerFactory
.
getInstance
(
"SunX509"
);
KeyStore
ks
=
KeyStore
.
getInstance
(
"PKCS12"
);
ks
.
load
(
keyFileInputStream
,
kp
);
kmf
.
init
(
ks
,
kp
);
SecureRandom
rand
=
new
SecureRandom
();
SSLContext
ctx
=
SSLContext
.
getInstance
(
"TLS"
);
ctx
.
init
(
kmf
.
getKeyManagers
(),
tmf
.
getTrustManagers
(),
rand
);
return
ctx
;
}
public
static
Certificate
getCertificate
(
File
cafile
)
throws
CertificateException
,
IOException
{
CertificateFactory
cf
=
CertificateFactory
.
getInstance
(
"X.509"
);
FileInputStream
in
=
null
;
Certificate
cert
=
null
;
try
{
in
=
new
FileInputStream
(
cafile
);
cert
=
cf
.
generateCertificate
(
in
);
in
.
close
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
in
)
in
.
close
();
}
return
cert
;
}
public
static
char
[]
str2CharArray
(
String
str
)
{
if
(
str
==
null
)
{
return
null
;
}
return
str
.
toCharArray
();
}
public
static
void
storeCACert
(
Certificate
cert
,
String
alias
,
String
password
,
OutputStream
out
)
throws
KeyStoreException
,
NoSuchAlgorithmException
,
CertificateException
,
IOException
{
KeyStore
ks
=
KeyStore
.
getInstance
(
"JKS"
);
ks
.
load
(
null
,
null
);
ks
.
setCertificateEntry
(
alias
,
cert
);
ks
.
store
(
out
,
str2CharArray
(
password
));
}
public
static
InputStream
String2Inputstream
(
String
str
)
{
return
new
ByteArrayInputStream
(
str
.
getBytes
());
}
public
static
byte
[]
InputStreamTOByte
(
InputStream
in
)
throws
IOException
{
int
BUFFER_SIZE
=
4096
;
ByteArrayOutputStream
outStream
=
new
ByteArrayOutputStream
();
byte
[]
data
=
new
byte
[
BUFFER_SIZE
];
int
count
=
-
1
;
while
((
count
=
in
.
read
(
data
,
0
,
BUFFER_SIZE
))
!=
-
1
)
{
outStream
.
write
(
data
,
0
,
count
);
}
data
=
(
byte
[])
null
;
byte
[]
outByte
=
outStream
.
toByteArray
();
outStream
.
close
();
return
outByte
;
}
public
static
String
InputStreamTOString
(
InputStream
in
,
String
encoding
)
throws
IOException
{
return
new
String
(
InputStreamTOByte
(
in
),
encoding
);
}
}
service-manager/src/main/java/com/winsun/tenpay/util/HttpUtil.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.URL
;
import
java.security.KeyManagementException
;
import
java.security.KeyStore
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.UnrecoverableKeyException
;
import
java.security.cert.CertificateException
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
org.apache.commons.httpclient.HttpClient
;
import
org.apache.commons.httpclient.HttpException
;
import
org.apache.commons.httpclient.HttpStatus
;
import
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager
;
import
org.apache.commons.httpclient.methods.PostMethod
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.conn.scheme.Scheme
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLContexts
;
import
org.apache.http.conn.ssl.SSLSocketFactory
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.DefaultHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.apache.log4j.Logger
;
public
class
HttpUtil
{
private
static
HttpClient
httpClient
=
null
;
protected
static
final
Logger
log
=
Logger
.
getLogger
(
HttpUtil
.
class
);
static
{
MultiThreadedHttpConnectionManager
connectionManager
=
new
MultiThreadedHttpConnectionManager
();
httpClient
=
new
HttpClient
(
connectionManager
);
httpClient
.
getHttpConnectionManager
().
getParams
().
setConnectionTimeout
(
10000
);
httpClient
.
getHttpConnectionManager
().
getParams
().
setSoTimeout
(
20000
);
httpClient
.
setHttpConnectionFactoryTimeout
(
10000L
);
}
/**
* 访问https的网站
*
* @param httpclient
*/
private
static
void
enableSSL
(
DefaultHttpClient
httpclient
)
{
// 调用ssl
try
{
SSLContext
sslcontext
=
SSLContext
.
getInstance
(
"TLS"
);
sslcontext
.
init
(
null
,
new
TrustManager
[]
{
truseAllManager
},
null
);
SSLSocketFactory
sf
=
new
SSLSocketFactory
(
sslcontext
);
sf
.
setHostnameVerifier
(
SSLSocketFactory
.
ALLOW_ALL_HOSTNAME_VERIFIER
);
Scheme
https
=
new
Scheme
(
"https"
,
sf
,
443
);
httpclient
.
getConnectionManager
().
getSchemeRegistry
().
register
(
https
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
static
TrustManager
truseAllManager
=
new
X509TrustManager
()
{
public
void
checkClientTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
arg0
,
String
arg1
)
throws
CertificateException
{
// TODO Auto-generated method stub
}
public
void
checkServerTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
arg0
,
String
arg1
)
throws
CertificateException
{
// TODO Auto-generated method stub
}
public
java
.
security
.
cert
.
X509Certificate
[]
getAcceptedIssuers
()
{
// TODO Auto-generated method stub
return
null
;
}
};
public
static
String
doPostXml
(
String
serverAddress
,
String
xml
)
{
/*
* //CerPath证书路径 String certPath =
* ConfigurationManager.AppSettings["certPath"].ToString(); //证书密码
* String password =
* ConfigurationManager.AppSettings["password"].ToString();
* X509Certificate cert = new
* System.Security.Cryptography.X509Certificates.X509Certificate2(
* certPath, password, X509KeyStorageFlags.MachineKeySet);
*
* // 设置参数 request = WebRequest.Create(posturl) as HttpWebRequest;
*/
String
searchResult
=
""
;
String
url
=
serverAddress
;
log
.
info
(
"url="
+
url
);
PostMethod
postMethod
=
new
PostMethod
(
url
);
postMethod
.
addRequestHeader
(
"Content-Type"
,
"text/xml;charset=UTF-8"
);
postMethod
.
setRequestBody
(
xml
);
BufferedInputStream
ins
=
null
;
try
{
int
statusCode
=
httpClient
.
executeMethod
(
postMethod
);
if
(
statusCode
==
200
)
{
ins
=
new
BufferedInputStream
(
postMethod
.
getResponseBodyAsStream
());
byte
[]
resultBytes
=
readUrlStream
(
ins
);
if
((
resultBytes
!=
null
)
&&
(
resultBytes
.
length
>
0
))
{
searchResult
=
new
String
(
resultBytes
,
"UTF-8"
);
//log.info(searchResult);
}
}
}
catch
(
HttpException
e
)
{
log
.
error
(
"HttpUtil doPost unexpected exception:"
+
e
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
"HttpUtil doPost unexpected exception:"
+
e
.
toString
());
}
finally
{
postMethod
.
releaseConnection
();
try
{
if
(
null
!=
ins
)
ins
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
return
searchResult
;
}
public
static
String
httpPost
(
String
url
,
String
data
)
throws
Exception
{
Integer
statusCode
=
-
1
;
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
20000
).
setConnectTimeout
(
20000
).
build
();
SSLConnectionSocketFactory
sslsf
=
null
;
try
{
// 指定读取证书格式为PKCS12
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"PKCS12"
);
// 读取本机存放的PKCS12证书文件
URL
certUrl
=
HttpUtil
.
class
.
getClassLoader
().
getResource
(
"apiclient_cert.p12"
);
File
file
=
new
File
(
certUrl
.
getFile
());
FileInputStream
instream
=
new
FileInputStream
(
file
);
try
{
// 指定PKCS12的密码(商户ID)
System
.
out
.
println
(
ConstantUtil
.
PKCS12_PWD
);
keyStore
.
load
(
instream
,
ConstantUtil
.
PKCS12_PWD
.
toCharArray
());
}
finally
{
instream
.
close
();
}
SSLContext
sslcontext
=
SSLContexts
.
custom
()
.
loadKeyMaterial
(
keyStore
,
ConstantUtil
.
PKCS12_PWD
.
toCharArray
()).
build
();
sslsf
=
new
SSLConnectionSocketFactory
(
sslcontext
,
new
String
[]
{
"TLSv1"
},
null
,
SSLConnectionSocketFactory
.
BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
);
client
=
HttpClients
.
custom
().
setSSLSocketFactory
(
sslsf
).
build
();
// 创建http请求(get方式)
// HttpGet httpget = new
// HttpGet("https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers");
// CloseableHttpResponse response = client.execute(httpget);
// System.out.println("executing request" +
// httpget.getRequestLine());
// httpClient = (HttpClient) httpclient.getConnectionManager();
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
KeyStoreException
e1
)
{
e1
.
printStackTrace
();
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
CertificateException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
KeyManagementException
e
)
{
e
.
printStackTrace
();
}
catch
(
UnrecoverableKeyException
e
)
{
e
.
printStackTrace
();
}
finally
{
client
.
close
();
}
HttpPost
post
=
new
HttpPost
(
url
);
post
.
setConfig
(
requestConfig
);
StringEntity
entity
=
new
StringEntity
(
data
,
"UTF-8"
);
entity
.
setContentType
(
"application/json;charset=UTF-8"
);
post
.
setEntity
(
entity
);
post
.
setHeader
(
"accept"
,
"application/json"
);
post
.
setHeader
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
CloseableHttpResponse
response
=
client
.
execute
(
post
);
StringBuffer
result
=
new
StringBuffer
();
try
{
statusCode
=
response
.
getStatusLine
().
getStatusCode
();
if
(
statusCode
!=
HttpStatus
.
SC_OK
)
{
throw
new
HttpException
(
"Http Status is error: "
+
statusCode
);
}
else
{
HttpEntity
entityRsp
=
response
.
getEntity
();
BufferedReader
rd
=
new
BufferedReader
(
new
InputStreamReader
(
entityRsp
.
getContent
(),
"UTF-8"
));
try
{
String
tempLine
=
rd
.
readLine
();
while
(
tempLine
!=
null
)
{
result
.
append
(
tempLine
);
tempLine
=
rd
.
readLine
();
}
}
finally
{
rd
.
close
();
EntityUtils
.
consume
(
entityRsp
);
}
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
finally
{
response
.
close
();
}
client
.
close
();
return
result
.
toString
();
}
private
static
byte
[]
readUrlStream
(
BufferedInputStream
bufferedInputStream
)
throws
IOException
{
ByteArrayOutputStream
swapStream
=
new
ByteArrayOutputStream
();
byte
[]
buff
=
new
byte
[
100
];
int
rc
=
0
;
while
((
rc
=
bufferedInputStream
.
read
(
buff
,
0
,
100
))
>
0
)
{
swapStream
.
write
(
buff
,
0
,
rc
);
}
return
swapStream
.
toByteArray
();
}
}
service-manager/src/main/java/com/winsun/tenpay/util/MD5Util.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.security.MessageDigest
;
public
class
MD5Util
{
private
static
String
byteArrayToHexString
(
byte
[]
b
)
{
StringBuffer
resultSb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
b
.
length
;
i
++)
{
resultSb
.
append
(
byteToHexString
(
b
[
i
]));
}
return
resultSb
.
toString
();
}
private
static
String
byteToHexString
(
byte
b
)
{
int
n
=
b
;
if
(
n
<
0
)
{
n
+=
256
;
}
int
d1
=
n
/
16
;
int
d2
=
n
%
16
;
return
hexDigits
[
d1
]
+
hexDigits
[
d2
];
}
public
static
String
MD5Encode
(
String
origin
,
String
charsetname
)
{
String
resultString
=
null
;
try
{
resultString
=
new
String
(
origin
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
if
((
charsetname
==
null
)
||
(
""
.
equals
(
charsetname
)))
{
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
()));
}
else
{
resultString
=
byteArrayToHexString
(
md
.
digest
(
resultString
.
getBytes
(
charsetname
)));
}
}
catch
(
Exception
localException
)
{}
return
resultString
;
}
private
static
final
String
[]
hexDigits
=
{
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
};
}
service-manager/src/main/java/com/winsun/tenpay/util/Sha1Util.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.security.MessageDigest
;
import
java.util.Random
;
public
class
Sha1Util
{
// 生成微信签名
public
static
String
getSha1
(
String
str
)
{
if
((
str
==
null
)
||
(
str
.
length
()
==
0
))
{
return
null
;
}
char
[]
hexDigits
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
};
try
{
MessageDigest
mdTemp
=
MessageDigest
.
getInstance
(
"SHA1"
);
mdTemp
.
update
(
str
.
getBytes
());
byte
[]
md
=
mdTemp
.
digest
();
int
j
=
md
.
length
;
char
[]
buf
=
new
char
[
j
*
2
];
int
k
=
0
;
for
(
int
i
=
0
;
i
<
j
;
i
++)
{
byte
byte0
=
md
[
i
];
buf
[(
k
++)]
=
hexDigits
[(
byte0
>>>
4
&
0xF
)];
buf
[(
k
++)]
=
hexDigits
[(
byte0
&
0xF
)];
}
return
new
String
(
buf
);
}
catch
(
Exception
e
)
{
}
return
null
;
}
// 获取随机字符串
public
static
String
getNonceStr
()
{
Random
random
=
new
Random
();
return
MD5Util
.
MD5Encode
(
String
.
valueOf
(
random
.
nextInt
(
10000
)),
"UTF-8"
);
}
// 获取时间戳
public
static
String
getTimeStamp
()
{
return
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
}
}
service-manager/src/main/java/com/winsun/tenpay/util/StringUtil.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.io.File
;
import
java.math.BigDecimal
;
import
java.security.SecureRandom
;
import
java.text.CharacterIterator
;
import
java.text.NumberFormat
;
import
java.text.StringCharacterIterator
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
StringUtil
{
public
static
final
String
EMPTY_STRING
=
""
;
public
static
final
String
EMPTY_STRING_SP
=
" "
;
public
static
String
getNullToEmpty
(
String
str
)
{
if
(
str
==
null
)
return
EMPTY_STRING
;
else
return
str
;
}
public
static
String
getNullToEmpty
(
Object
str
)
{
if
(
str
==
null
)
return
EMPTY_STRING
;
else
return
str
.
toString
();
}
public
static
String
getNullToSpace
(
String
str
)
{
if
(
str
==
null
)
return
EMPTY_STRING_SP
;
else
return
str
;
}
//Replace null value to space and change '"' into String to HTML code '"'
public
static
String
getNullToSpaceHTML
(
String
str
)
{
if
(
str
==
null
)
return
EMPTY_STRING_SP
;
else
{
String
strTmp
=
str
.
replaceAll
(
"\""
,
"""
);
strTmp
=
strTmp
.
replaceAll
(
">"
,
">"
);
strTmp
=
strTmp
.
replaceAll
(
"<"
,
"<"
);
return
strTmp
;
}
}
//Replace null value to empty string and change '"' into String to HTML code '"'
public
static
String
getNullToEmptyHTML
(
String
str
)
{
if
(
str
==
null
)
return
EMPTY_STRING
;
else
{
String
strTmp
=
str
.
replaceAll
(
"\""
,
"""
);
strTmp
=
strTmp
.
replaceAll
(
">"
,
">"
);
strTmp
=
strTmp
.
replaceAll
(
"<"
,
"<"
);
return
strTmp
;
}
}
public
static
String
getNullToEmptyHTML
(
Object
obj
)
{
if
(
obj
==
null
)
return
EMPTY_STRING
;
else
return
getNullToEmptyHTML
(
obj
.
toString
());
}
//Check the string contains numeric or not
public
static
boolean
isNumber
(
String
str
)
{
boolean
result
=
true
;
try
{
Integer
.
parseInt
(
str
.
trim
());
}
catch
(
NumberFormatException
e
)
{
result
=
false
;
}
return
result
;
}
public
static
String
[]
splitString
(
String
str
)
{
if
(
str
==
null
||
str
.
length
()
==
0
)
return
new
String
[
0
];
Pattern
p
=
Pattern
.
compile
(
","
);
return
p
.
split
(
str
);
}
public
static
String
[]
splitString
(
String
str
,
String
delim
)
{
String
ls_delim
=
","
;
if
(
str
==
null
||
str
.
length
()
==
0
)
return
new
String
[
0
];
if
(
delim
!=
null
&&
delim
.
length
()
>
0
)
ls_delim
=
delim
;
Pattern
p
=
Pattern
.
compile
(
"["
+
ls_delim
+
"]"
);
return
p
.
split
(
str
);
}
public
static
String
concatString
(
String
[]
str
)
{
if
(
str
==
null
)
return
""
;
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
str
.
length
;
i
++)
{
if
(
i
>
0
)
sb
.
append
(
","
);
sb
.
append
(
str
[
i
]);
}
return
sb
.
toString
();
}
public
static
String
concatString
(
String
[]
str
,
String
delim
)
{
if
(
str
==
null
)
return
""
;
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
str
.
length
;
i
++)
{
if
(
i
>
0
)
sb
.
append
(
delim
);
sb
.
append
(
str
[
i
]);
}
return
sb
.
toString
();
}
public
static
String
padTailZero
(
String
as_input
,
int
ai_len
)
{
String
ls_result
=
as_input
;
if
(
ls_result
==
null
)
return
ls_result
;
while
(
ls_result
.
trim
().
length
()
<
ai_len
)
{
ls_result
=
ls_result
+
"0"
;
}
return
ls_result
;
}
public
static
String
padZero
(
String
as_input
,
int
ai_len
)
{
String
ls_result
=
as_input
;
if
(
ls_result
==
null
)
return
ls_result
;
while
(
ls_result
.
trim
().
length
()
<
ai_len
)
{
ls_result
=
"0"
+
ls_result
;
}
return
ls_result
;
}
public
static
String
getStrPrefix
(
String
aStr
,
int
prefixPos
)
{
String
result
=
""
;
if
(
aStr
==
null
||
aStr
.
length
()
<=
0
||
prefixPos
<=
0
||
prefixPos
>
aStr
.
length
())
return
""
;
//Log.println("prefix str = " + aStr.substring(0, prefixPos));
result
=
aStr
.
substring
(
0
,
prefixPos
);
return
result
;
}
public
static
String
getStrSuffix
(
String
aStr
,
int
suffixPos
)
{
String
result
=
""
;
if
(
aStr
==
null
||
aStr
.
length
()
<=
0
||
suffixPos
<=
0
||
suffixPos
>
aStr
.
length
())
return
""
;
int
pos
=
aStr
.
length
()
-
suffixPos
;
//Log.println("suffix str = " + aStr.substring( pos ));
result
=
aStr
.
substring
(
pos
);
return
result
;
}
public
static
String
getStrBody
(
String
aStr
,
int
prefixPos
,
int
suffixPos
)
{
String
result
=
""
;
if
(
aStr
==
null
||
aStr
.
length
()
<=
0
||
prefixPos
<
0
||
prefixPos
>
aStr
.
length
()
||
suffixPos
<
0
||
suffixPos
>
aStr
.
length
())
return
""
;
int
pos
=
aStr
.
length
()
-
suffixPos
;
//Log.println("body str = " + aStr.substring(prefixPos, pos ));
result
=
aStr
.
substring
(
prefixPos
,
pos
);
return
result
;
}
public
static
String
leadZero
(
int
innum
,
int
size
)
{
NumberFormat
digitNF
=
NumberFormat
.
getInstance
();
digitNF
.
setMinimumIntegerDigits
(
size
);
digitNF
.
setMaximumIntegerDigits
(
size
);
digitNF
.
setGroupingUsed
(
false
);
return
new
String
(
digitNF
.
format
(
innum
));
}
public
static
String
leadZeroBigDecimal
(
BigDecimal
innum
,
int
size
)
{
NumberFormat
digitNF
=
NumberFormat
.
getInstance
();
digitNF
.
setMinimumIntegerDigits
(
size
);
digitNF
.
setMaximumIntegerDigits
(
size
);
digitNF
.
setGroupingUsed
(
false
);
return
new
String
(
digitNF
.
format
(
innum
));
}
public
static
String
spacePad
(
String
instr
,
int
size
)
{
char
[]
pad
=
new
char
[
size
];
Arrays
.
fill
(
pad
,
' '
);
char
[]
strchar
=
null
;
if
(
instr
==
null
)
return
new
String
(
pad
);
else
if
(
instr
.
trim
().
length
()
>
size
)
strchar
=
instr
.
trim
().
substring
(
0
,
size
).
toCharArray
();
else
strchar
=
instr
.
trim
().
toCharArray
();
System
.
arraycopy
(
strchar
,
0
,
pad
,
0
,
strchar
.
length
);
return
new
String
(
pad
);
}
public
static
String
zeroPad
(
String
instr
,
int
size
)
{
char
[]
pad
=
new
char
[
size
];
Arrays
.
fill
(
pad
,
'0'
);
char
[]
strchar
=
null
;
if
(
instr
==
null
)
return
new
String
(
pad
);
else
if
(
instr
.
trim
().
length
()
>
size
)
strchar
=
instr
.
trim
().
substring
(
0
,
size
).
toCharArray
();
else
strchar
=
instr
.
trim
().
toCharArray
();
System
.
arraycopy
(
strchar
,
0
,
pad
,
0
,
strchar
.
length
);
return
new
String
(
pad
);
}
public
static
String
padLeadSpace
(
String
instr
,
int
size
)
{
char
[]
pad
=
new
char
[
size
];
Arrays
.
fill
(
pad
,
' '
);
char
[]
strchar
=
null
;
if
(
instr
==
null
)
return
new
String
(
pad
);
else
if
(
instr
.
trim
().
length
()
>
size
)
strchar
=
instr
.
trim
().
substring
(
0
,
size
).
toCharArray
();
else
strchar
=
instr
.
trim
().
toCharArray
();
System
.
arraycopy
(
strchar
,
0
,
pad
,
pad
.
length
-
strchar
.
length
,
strchar
.
length
);
return
new
String
(
pad
);
}
public
static
String
parseMsgString
(
String
rawMessage
,
String
replaceString
)
{
StringBuffer
result
=
new
StringBuffer
(
rawMessage
);
int
idx
=
0
;
// replace %s with replaceString
idx
=
result
.
toString
().
indexOf
(
"%"
);
while
(
idx
>
0
)
{
result
=
result
.
replace
(
idx
,
(
idx
+
1
),
replaceString
);
idx
=
result
.
toString
().
indexOf
(
"%"
);
}
return
result
.
toString
();
}
public
static
String
encode
(
byte
[]
raw
)
{
StringBuffer
encoded
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
raw
.
length
;
i
+=
3
)
{
encoded
.
append
(
encodeBlock
(
raw
,
i
));
}
return
encoded
.
toString
();
}
public
static
byte
[]
decode
(
String
base64
)
{
int
pad
=
0
;
for
(
int
i
=
base64
.
length
()
-
1
;
base64
.
charAt
(
i
)
==
'='
;
i
--)
pad
++;
int
length
=
base64
.
length
()
*
6
/
8
-
pad
;
byte
[]
raw
=
new
byte
[
length
];
int
rawIndex
=
0
;
for
(
int
i
=
0
;
i
<
base64
.
length
();
i
+=
4
)
{
int
block
=
(
getValue
(
base64
.
charAt
(
i
))
<<
18
)
+
(
getValue
(
base64
.
charAt
(
i
+
1
))
<<
12
)
+
(
getValue
(
base64
.
charAt
(
i
+
2
))
<<
6
)
+
(
getValue
(
base64
.
charAt
(
i
+
3
)));
for
(
int
j
=
0
;
j
<
3
&&
rawIndex
+
j
<
raw
.
length
;
j
++)
raw
[
rawIndex
+
j
]
=
(
byte
)
((
block
>>
(
8
*
(
2
-
j
)))
&
0xff
);
rawIndex
+=
3
;
}
return
raw
;
}
public
static
char
[]
encodeBlock
(
byte
[]
raw
,
int
offset
)
{
int
block
=
0
;
int
slack
=
raw
.
length
-
offset
-
1
;
int
end
=
(
slack
>=
2
)
?
2
:
slack
;
for
(
int
i
=
0
;
i
<=
end
;
i
++)
{
byte
b
=
raw
[
offset
+
i
];
int
neuter
=
(
b
<
0
)
?
b
+
256
:
b
;
block
+=
neuter
<<
(
8
*
(
2
-
i
));
}
char
[]
base64
=
new
char
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
int
sixbit
=
(
block
>>>
(
6
*
(
3
-
i
)))
&
0x3f
;
base64
[
i
]
=
getChar
(
sixbit
);
}
if
(
slack
<
1
)
base64
[
2
]
=
'='
;
if
(
slack
<
2
)
base64
[
3
]
=
'='
;
return
base64
;
}
public
static
char
getChar
(
int
sixBit
)
{
if
(
sixBit
>=
0
&&
sixBit
<=
25
)
return
(
char
)
(
'A'
+
sixBit
);
if
(
sixBit
>=
26
&&
sixBit
<=
51
)
return
(
char
)
(
'a'
+
(
sixBit
-
26
));
if
(
sixBit
>=
52
&&
sixBit
<=
61
)
return
(
char
)
(
'0'
+
(
sixBit
-
52
));
if
(
sixBit
==
62
)
return
'+'
;
if
(
sixBit
==
63
)
return
'/'
;
return
'?'
;
}
public
static
int
getValue
(
char
c
)
{
if
(
c
>=
'A'
&&
c
<=
'Z'
)
return
c
-
'A'
;
if
(
c
>=
'a'
&&
c
<=
'z'
)
return
c
-
'a'
+
26
;
if
(
c
>=
'0'
&&
c
<=
'9'
)
return
c
-
'0'
+
52
;
if
(
c
==
'+'
)
return
62
;
if
(
c
==
'/'
)
return
63
;
if
(
c
==
'='
)
return
0
;
return
-
1
;
}
public
static
String
combineString
(
String
str1
,
String
str2
)
{
byte
[]
bstr1
=
str1
.
getBytes
();
byte
[]
bstr2
=
str2
.
getBytes
();
byte
[]
result
=
new
byte
[
bstr1
.
length
];
for
(
int
i
=
0
;
i
<
bstr1
.
length
;
i
++)
{
result
[
i
]
=
(
byte
)
(
bstr1
[
i
]
|
bstr2
[
i
]);
}
return
new
String
(
result
);
}
public
static
String
addSQLEscapeCharactor
(
String
inStr
,
String
escapeChar
)
{
StringBuffer
outStrBuf
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
inStr
.
length
();
i
++)
{
if
(
inStr
.
charAt
(
i
)
==
'\''
)
{
outStrBuf
.
append
(
"''"
);
}
else
if
(
inStr
.
charAt
(
i
)
==
'%'
)
{
outStrBuf
.
append
(
escapeChar
).
append
(
"%"
);
}
else
{
outStrBuf
.
append
(
inStr
.
charAt
(
i
));
}
}
return
outStrBuf
.
toString
();
}
public
static
String
replaceHTMLTagToSpecificString
(
String
inStr
,
String
replaceStr
)
{
StringBuffer
outStrBuf
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
inStr
.
length
();
i
++)
{
//check again filterchars
if
(
inStr
.
substring
(
i
,
i
+
1
).
equalsIgnoreCase
(
"<"
))
{
if
(
inStr
.
substring
(
i
,
i
+
3
).
toLowerCase
().
equalsIgnoreCase
(
"<b>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
2
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
4
).
toLowerCase
().
equalsIgnoreCase
(
"</b>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
3
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
3
).
toLowerCase
().
equalsIgnoreCase
(
"<i>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
2
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
4
).
toLowerCase
().
equalsIgnoreCase
(
"</i>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
3
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
4
).
toLowerCase
().
equalsIgnoreCase
(
"<br>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
3
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
5
).
toLowerCase
().
equalsIgnoreCase
(
"</br>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
4
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
3
).
toLowerCase
().
equalsIgnoreCase
(
"<p>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
2
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
4
).
toLowerCase
().
equalsIgnoreCase
(
"</p>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
3
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
3
).
toLowerCase
().
equalsIgnoreCase
(
"<u>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
2
;
}
else
if
(
inStr
.
substring
(
i
,
i
+
4
).
toLowerCase
().
equalsIgnoreCase
(
"</u>"
))
{
outStrBuf
.
append
(
""
);
i
=
i
+
3
;
}
else
{
outStrBuf
.
append
(
inStr
.
substring
(
i
,
i
+
1
));
}
}
else
{
outStrBuf
.
append
(
inStr
.
substring
(
i
,
i
+
1
));
}
}
return
outStrBuf
.
toString
();
}
public
static
String
escapeNewline
(
String
str
)
{
//if use \r together, does not work properly for the input in event
//detail html input
String
str1
=
str
;
if
(
str
.
indexOf
(
'\n'
)
!=
-
1
//|| str.indexOf( '\r' ) != -1
)
{
str1
=
str
.
replaceAll
(
"[\n]"
,
"<br/>"
);
//str1 = str.replaceAll("[\n\r]", "<br/>");
}
return
str1
;
}
public
static
String
formatFilePath
(
String
strValue
)
{
String
strReturn
=
strValue
;
if
(
strReturn
.
indexOf
(
"/"
)>=
0
&&
File
.
separator
.
equals
(
"\\"
))
{
while
(
strReturn
.
indexOf
(
"/"
)>=
0
){
strReturn
=
strReturn
.
replace
(
"/"
,
File
.
separator
);
}
}
else
if
(
strReturn
.
indexOf
(
"\\"
)>=
0
&&
File
.
separator
.
equals
(
"/"
))
{
while
(
strReturn
.
indexOf
(
"\\"
)>=
0
){
strReturn
=
strReturn
.
replace
(
"\\"
,
File
.
separator
);
}
}
return
strReturn
;
}
public
static
String
repeatStr
(
String
strValue
,
int
intRepeatCount
){
StringBuffer
bufReturn
=
new
StringBuffer
();
if
(
intRepeatCount
<=
0
)
return
""
;
for
(
int
i
=
1
;
i
<=
intRepeatCount
;
i
++){
bufReturn
.
append
(
strValue
);
}
return
bufReturn
.
toString
();
}
public
static
String
forHTML
(
String
aText
){
final
StringBuilder
result
=
new
StringBuilder
();
final
StringCharacterIterator
iterator
=
new
StringCharacterIterator
(
aText
);
char
character
=
iterator
.
current
();
while
(
character
!=
CharacterIterator
.
DONE
){
if
(
character
==
'<'
)
{
result
.
append
(
"<"
);
}
else
if
(
character
==
'>'
)
{
result
.
append
(
">"
);
}
else
if
(
character
==
'&'
)
{
result
.
append
(
"&"
);
}
else
if
(
character
==
'\"'
)
{
result
.
append
(
"""
);
}
else
if
(
character
==
'\t'
)
{
addCharEntity
(
9
,
result
);
}
else
if
(
character
==
'!'
)
{
addCharEntity
(
33
,
result
);
}
else
if
(
character
==
'#'
)
{
addCharEntity
(
35
,
result
);
}
else
if
(
character
==
'$'
)
{
addCharEntity
(
36
,
result
);
}
else
if
(
character
==
'%'
)
{
addCharEntity
(
37
,
result
);
}
else
if
(
character
==
'\''
)
{
addCharEntity
(
39
,
result
);
}
else
if
(
character
==
'('
)
{
addCharEntity
(
40
,
result
);
}
else
if
(
character
==
')'
)
{
addCharEntity
(
41
,
result
);
}
else
if
(
character
==
'*'
)
{
addCharEntity
(
42
,
result
);
}
else
if
(
character
==
'+'
)
{
addCharEntity
(
43
,
result
);
}
else
if
(
character
==
','
)
{
addCharEntity
(
44
,
result
);
}
else
if
(
character
==
'-'
)
{
addCharEntity
(
45
,
result
);
}
else
if
(
character
==
'.'
)
{
addCharEntity
(
46
,
result
);
}
else
if
(
character
==
'/'
)
{
addCharEntity
(
47
,
result
);
}
else
if
(
character
==
':'
)
{
addCharEntity
(
58
,
result
);
}
else
if
(
character
==
';'
)
{
addCharEntity
(
59
,
result
);
}
else
if
(
character
==
'='
)
{
addCharEntity
(
61
,
result
);
}
else
if
(
character
==
'?'
)
{
addCharEntity
(
63
,
result
);
}
else
if
(
character
==
'@'
)
{
addCharEntity
(
64
,
result
);
}
else
if
(
character
==
'['
)
{
addCharEntity
(
91
,
result
);
}
else
if
(
character
==
'\\'
)
{
addCharEntity
(
92
,
result
);
}
else
if
(
character
==
']'
)
{
addCharEntity
(
93
,
result
);
}
else
if
(
character
==
'^'
)
{
addCharEntity
(
94
,
result
);
}
else
if
(
character
==
'_'
)
{
addCharEntity
(
95
,
result
);
}
else
if
(
character
==
'`'
)
{
addCharEntity
(
96
,
result
);
}
else
if
(
character
==
'{'
)
{
addCharEntity
(
123
,
result
);
}
else
if
(
character
==
'|'
)
{
addCharEntity
(
124
,
result
);
}
else
if
(
character
==
'}'
)
{
addCharEntity
(
125
,
result
);
}
else
if
(
character
==
'~'
)
{
addCharEntity
(
126
,
result
);
}
else
{
//the char is not a special one
//add it to the result as is
result
.
append
(
character
);
}
character
=
iterator
.
next
();
}
return
result
.
toString
();
}
private
static
void
addCharEntity
(
Integer
aIdx
,
StringBuilder
aBuilder
){
String
padding
=
""
;
if
(
aIdx
<=
9
){
padding
=
"00"
;
}
else
if
(
aIdx
<=
99
){
padding
=
"0"
;
}
else
{
//no prefix
}
String
number
=
padding
+
aIdx
.
toString
();
aBuilder
.
append
(
"&#"
+
number
+
";"
);
}
public
static
String
stripHTML
(
String
content
,
int
limit
,
String
atag
){
// String temp= "<div><font size='1'><br/>1234567890><12345<br/><br/>6789012345<br/>1234567890&</font></div>";
try
{
String
temp
=
content
;
int
start
=
0
;
int
start2
=
0
;
int
end
=
0
;
int
end2
=
0
;
String
result
=
new
String
(
temp
);
while
(
temp
.
indexOf
(
">"
)
>-
1
)
{
start
=
temp
.
indexOf
(
"<"
);
end
+=
temp
.
indexOf
(
">"
);
end2
=
temp
.
indexOf
(
">"
);
if
(
start
>=
0
&&
start
<
end2
)
{
temp
=
temp
.
substring
(
end2
+
1
,
temp
.
length
());
end
+=
1
;
}
else
{
result
=
((
0
==
end
)?
""
:
result
.
substring
(
0
,
end
))
+
">"
+
((
result
.
length
()==
end
+
1
)?
""
:
result
.
substring
(
end
+
1
,
result
.
length
()));
temp
=
result
;
end
=
0
;
}
}
temp
=
result
;
start
=
0
;
start2
=
0
;
end
=
0
;
end2
=
0
;
while
(
temp
.
indexOf
(
"<"
)
>-
1
)
{
start
=
temp
.
indexOf
(
"<"
);
end
=
temp
.
indexOf
(
">"
);
if
((
start
<
end
&&
(
temp
.
substring
(
start
+
1
,
end
).
indexOf
(
"<"
)>-
1
)
)
||
end
==-
1
)
{
start2
+=
start
;
result
=
((
0
==
start2
)?
""
:
result
.
substring
(
0
,
start2
))
+
"<"
+
((
result
.
length
()==
start2
+
1
)?
""
:
result
.
substring
(
start2
+
1
,
result
.
length
()));
temp
=
result
;
start2
=
0
;
}
else
if
(
start
>=
0
&&
start
<
end
)
{
temp
=
temp
.
substring
(
end
+
1
,
temp
.
length
());
start2
+=(
end
+
1
);
}
}
temp
=
result
;
// System.out.println("---------------------------------result>" + result);
start
=
0
;
end
=
0
;
int
contentLength
=
0
;
int
totalLength
=
0
;
if
(!(
temp
.
indexOf
(
"<"
)
>-
1
&&
temp
.
indexOf
(
">"
)
>
-
1
&&
temp
.
indexOf
(
"<"
)<
temp
.
lastIndexOf
(
">"
)))
totalLength
=
result
.
length
();
else
{
while
(
temp
.
indexOf
(
"<"
)
>-
1
&&
temp
.
indexOf
(
">"
)
>
-
1
&&
temp
.
indexOf
(
"<"
)<
temp
.
lastIndexOf
(
">"
))
{
start
=
temp
.
indexOf
(
"<"
);
end
=
temp
.
indexOf
(
">"
);
contentLength
+=
start
;
temp
=
temp
.
substring
(
end
+
1
,
temp
.
length
());
totalLength
+=
start
;
if
(
contentLength
>
limit
)
break
;
totalLength
+=
(
end
+
1
-
start
);
}
if
(
contentLength
>
limit
)
{
contentLength
-=
start
;
totalLength
-=
start
;
totalLength
+=
(
limit
-
contentLength
);
}
else
if
(
temp
.
length
()>
0
&&
temp
.
length
()+
contentLength
>
limit
)
totalLength
+=
(
limit
-
contentLength
);
}
// System.out.println("---------------------------------result>" + result.substring(0,totalLength));
String
temp2
=
result
.
substring
(
0
,
totalLength
);
if
(
result
.
length
()
!=
temp2
.
length
())
{
String
lastChar
=
temp2
.
substring
(
temp2
.
length
()-
1
,
temp2
.
length
());
Pattern
regex
=
Pattern
.
compile
(
"[a-zA-Z]"
);
Matcher
regexMatcher
=
regex
.
matcher
(
lastChar
);
while
(
regexMatcher
.
find
())
{
lastChar
=
temp2
.
substring
(
temp2
.
length
()-
1
,
temp2
.
length
());
regexMatcher
=
regex
.
matcher
(
lastChar
);
temp2
=
temp2
.
substring
(
0
,
temp2
.
length
()-
1
);
}
if
(
lastChar
.
equals
(
"&"
)
)
temp2
=
temp2
.
substring
(
0
,
temp2
.
lastIndexOf
(
"&"
));
}
// System.out.println("---------------------------------temp2>" + temp2);
String
temp3
=
temp2
;
// if (result.length() != temp3.length())
temp3
+=
atag
;
List
<
String
>
tagList
=
new
ArrayList
<
String
>();
while
(
temp2
.
indexOf
(
"<"
)
>-
1
&&
temp2
.
indexOf
(
">"
)
>
-
1
)
{
start
=
temp2
.
indexOf
(
"<"
);
end
=
temp2
.
indexOf
(
">"
);
if
(
temp2
.
substring
(
start
,
end
).
contains
(
" "
))
{
tagList
.
add
(
"</"
+
temp2
.
substring
(
start
+
1
,
start
+
temp2
.
substring
(
start
).
indexOf
(
" "
))
+
">"
);
}
else
tagList
.
add
(
"</"
+
temp2
.
substring
(
start
+
1
,
end
+
1
));
temp2
=
temp2
.
substring
(
end
+
1
,
temp2
.
length
());
}
for
(
int
i
=
tagList
.
size
()-
1
;
i
>=
0
;
i
--)
{
if
(
result
.
contains
((
String
)
tagList
.
get
(
i
)))
temp3
+=
(
String
)
tagList
.
get
(
i
);
}
result
=
temp3
;
// System.out.println("---------------------------------result>" + result);
return
result
;
}
catch
(
Exception
e
)
{
// Log.error(e.getMessage());
return
content
;
}
}
public
static
boolean
isBlank
(
String
str
)
{
return
str
==
null
||
str
.
trim
().
length
()
<
1
;
}
public
static
boolean
isNotBlank
(
String
str
)
{
return
!
isBlank
(
str
);
}
public
static
String
getBlankToNull
(
String
str
)
{
if
(
isBlank
(
str
))
{
return
null
;
}
else
{
return
str
;
}
}
public
static
String
getNullToBlank
(
String
str
)
{
if
(
isBlank
(
str
))
{
return
""
;
}
else
{
return
str
;
}
}
public
static
String
left
(
String
string
,
int
length
)
{
if
(
isBlank
(
string
)
||
length
<
1
)
{
return
""
;
}
if
(
string
.
length
()
<=
length
)
{
return
string
;
}
return
string
.
substring
(
0
,
length
);
}
public
static
String
right
(
String
string
,
int
length
)
{
if
(
isBlank
(
string
)
||
length
<
1
)
{
return
""
;
}
if
(
string
.
length
()
<=
length
)
{
return
string
;
}
return
string
.
substring
(
string
.
length
()
-
length
);
}
public
static
boolean
equal
(
String
str1
,
String
str2
)
{
if
(
str1
==
null
)
{
return
str2
==
null
;
}
else
{
return
str1
.
equals
(
str2
);
}
}
public
static
String
toLowerCase
(
String
str
)
{
return
str
==
null
?
null
:
str
.
toLowerCase
(
Locale
.
ENGLISH
);
}
public
static
int
compareIgnoreCase
(
String
str1
,
String
str2
)
{
return
compare
(
toLowerCase
(
str1
),
toLowerCase
(
str2
));
}
// public static int compareIgnoreCaseFirst(String str1, String str2) {
// return CommonUtil.getFirstNonZero(compareIgnoreCase(str1, str2),
// compare(toLowerCase(str1), toLowerCase(str2)));
// }
public
static
int
compare
(
String
str1
,
String
str2
)
{
if
(
equal
(
str1
,
str2
))
{
return
0
;
}
else
if
(
str1
==
null
)
{
return
-
1
;
}
else
if
(
str2
==
null
)
{
return
1
;
}
else
{
// Both non-null
return
str1
.
compareTo
(
str2
);
}
}
public
static
String
trimToEmpty
(
String
str
)
{
if
(
str
==
null
)
{
return
""
;
}
else
{
return
str
.
trim
();
}
}
public
static
List
<
String
>
splitAsList
(
String
str
,
String
pattern
)
{
String
[]
strings
=
getNullToEmpty
(
str
).
split
(
pattern
);
if
(
strings
==
null
)
{
strings
=
new
String
[
0
];
}
return
Arrays
.
asList
(
strings
);
}
public
static
List
<
String
>
splitAsListByCommas
(
String
str
)
{
return
StringUtil
.
splitAsList
(
str
,
"\\s*,\\s*"
);
}
public
static
String
join
(
Collection
<
String
>
strings
,
String
delimiter
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
Iterator
<
String
>
it
=
strings
.
iterator
();
it
.
hasNext
();)
{
builder
.
append
(
it
.
next
());
if
(
it
.
hasNext
())
{
builder
.
append
(
delimiter
);
}
}
return
builder
.
toString
();
}
public
static
boolean
isEmpty
(
String
str
)
{
return
str
==
null
||
str
.
length
()
<
1
;
}
public
static
boolean
isNotEmpty
(
String
str
)
{
return
!
isEmpty
(
str
);
}
public
static
String
getBlankOrNullLiteralToEmpty
(
String
str
)
{
if
(
isNullLiteral
(
str
))
{
return
""
;
}
else
{
return
trimToEmpty
(
str
);
}
}
public
static
boolean
isNullLiteral
(
String
str
)
{
return
compareIgnoreCase
(
trimToEmpty
(
str
),
"null"
)
==
0
;
}
public
static
boolean
isBlankOrNullLiteral
(
String
str
)
{
return
isBlank
(
str
)
||
isNullLiteral
(
str
);
}
public
static
boolean
isNotBlankOrNullLiteral
(
String
str
)
{
return
!
isBlankOrNullLiteral
(
str
);
}
public
static
String
randomString
(
int
pwdLength
)
{
StringBuffer
scode
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
pwdLength
;
i
++)
{
scode
.
append
(
randAChar
(
false
,
false
,
false
));
}
return
scode
.
toString
();
}
public
static
String
randomString_UpperOnly
(
int
pwdLength
)
{
StringBuffer
scode
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
pwdLength
;
i
++)
{
scode
.
append
(
randAChar
(
false
,
false
,
true
));
}
return
scode
.
toString
();
}
public
static
String
randNumberOnly
(
int
pwdLength
){
StringBuffer
scode
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
pwdLength
;
i
++)
{
scode
.
append
(
randAChar
(
true
,
false
,
false
));
}
return
scode
.
toString
();
}
private
static
char
randAChar
(
boolean
isNumberOnly
,
boolean
isCharOnly
,
boolean
isUpperOnly
){
SecureRandom
rd
=
new
SecureRandom
();
// 0-9 48-57
// A-Z 65-90
// a-z 97-122
int
temp
=
-
1
;
// number only
if
(
isNumberOnly
){
temp
=
rd
.
nextInt
(
10
)+
48
;
// char only
}
else
if
(
isCharOnly
){
if
(
isUpperOnly
){
temp
=
rd
.
nextInt
(
26
)+
65
;
}
else
{
temp
=
rd
.
nextInt
(
58
)+
65
;
while
(
temp
>
90
&&
temp
<
97
){
temp
=
rd
.
nextInt
(
58
)+
65
;
}
}
// number & char
}
else
{
if
(
isUpperOnly
){
temp
=
rd
.
nextInt
(
43
)+
48
;
while
(
temp
>
57
&&
temp
<
65
){
temp
=
rd
.
nextInt
(
43
)+
48
;
}
}
else
{
temp
=
rd
.
nextInt
(
75
)+
48
;
while
(
temp
>
57
&&
temp
<
65
||
temp
>
90
&&
temp
<
97
){
temp
=
rd
.
nextInt
(
75
)+
48
;
}
}
}
return
(
char
)
temp
;
}
public
static
List
<
String
>
removeStringFromList
(
List
<
String
>
list
,
List
<
String
>
toBeRemoved
)
{
if
(
toBeRemoved
==
null
)
return
list
;
for
(
int
i
=
0
;
i
<
toBeRemoved
.
size
();
i
++)
{
list
.
remove
(
toBeRemoved
.
get
(
i
));
}
return
list
;
}
public
static
String
searchReplace
(
String
data
,
String
find
,
String
replace
){
StringBuffer
sb
=
new
StringBuffer
();
int
a
=
0
,
b
;
int
findLength
=
find
.
length
();
while
((
b
=
data
.
indexOf
(
find
,
a
))
!=
-
1
)
{
sb
.
append
(
data
.
substring
(
a
,
b
));
sb
.
append
(
replace
);
a
=
b
+
findLength
;
}
if
(
a
<
data
.
length
())
{
sb
.
append
(
data
.
substring
(
a
));
}
return
sb
.
toString
();
}
}
service-manager/src/main/java/com/winsun/tenpay/util/TenpayHttpClient.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.security.KeyManagementException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.UnrecoverableKeyException
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
import
java.util.Locale
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSocketFactory
;
public
class
TenpayHttpClient
{
private
static
final
String
USER_AGENT_VALUE
=
"Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)"
;
private
static
final
String
JKS_CA_FILENAME
=
"tenpay_cacert.jks"
;
private
static
final
String
JKS_CA_ALIAS
=
"tenpay"
;
private
static
final
String
JKS_CA_PASSWORD
=
""
;
private
File
caFile
;
private
File
certFile
;
private
String
certPasswd
;
private
String
reqContent
;
private
String
resContent
;
private
String
method
;
private
String
errInfo
;
private
int
timeOut
;
private
int
responseCode
;
private
String
charset
;
private
InputStream
inputStream
;
public
TenpayHttpClient
()
{
this
.
caFile
=
null
;
this
.
certFile
=
null
;
this
.
certPasswd
=
""
;
this
.
reqContent
=
""
;
this
.
resContent
=
""
;
this
.
method
=
"POST"
;
this
.
errInfo
=
""
;
this
.
timeOut
=
30
;
this
.
responseCode
=
0
;
this
.
charset
=
"GBK"
;
this
.
inputStream
=
null
;
}
public
void
setCertInfo
(
File
certFile
,
String
certPasswd
)
{
this
.
certFile
=
certFile
;
this
.
certPasswd
=
certPasswd
;
}
public
void
setCaInfo
(
File
caFile
)
{
this
.
caFile
=
caFile
;
}
public
void
setReqContent
(
String
reqContent
)
{
this
.
reqContent
=
reqContent
;
}
public
String
getResContent
()
{
try
{
doResponse
();
}
catch
(
IOException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
return
this
.
resContent
;
}
public
void
setMethod
(
String
method
)
{
this
.
method
=
method
;
}
public
String
getErrInfo
()
{
return
this
.
errInfo
;
}
public
void
setTimeOut
(
int
timeOut
)
{
this
.
timeOut
=
timeOut
;
}
public
int
getResponseCode
()
{
return
this
.
responseCode
;
}
public
boolean
call
()
{
boolean
isRet
=
false
;
if
((
this
.
caFile
==
null
)
&&
(
this
.
certFile
==
null
))
{
try
{
callHttp
();
isRet
=
true
;
}
catch
(
IOException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
return
isRet
;
}
try
{
callHttps
();
isRet
=
true
;
}
catch
(
UnrecoverableKeyException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
catch
(
KeyManagementException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
catch
(
CertificateException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
catch
(
KeyStoreException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
catch
(
NoSuchAlgorithmException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
catch
(
IOException
e
)
{
this
.
errInfo
=
e
.
getMessage
();
}
return
isRet
;
}
protected
void
callHttp
()
throws
IOException
{
if
(
"POST"
.
equals
(
this
.
method
.
toUpperCase
(
Locale
.
ENGLISH
)))
{
String
url
=
HttpClientUtil
.
getURL
(
this
.
reqContent
);
String
queryString
=
HttpClientUtil
.
getQueryString
(
this
.
reqContent
);
byte
[]
postData
=
queryString
.
getBytes
(
this
.
charset
);
httpPostMethod
(
url
,
postData
);
return
;
}
httpGetMethod
(
this
.
reqContent
);
}
protected
void
callHttps
()
throws
IOException
,
CertificateException
,
KeyStoreException
,
NoSuchAlgorithmException
,
UnrecoverableKeyException
,
KeyManagementException
{
String
caPath
=
this
.
caFile
.
getParent
();
File
jksCAFile
=
new
File
(
caPath
+
"/"
+
"tenpay_cacert.jks"
);
if
(!
jksCAFile
.
isFile
())
{
X509Certificate
cert
=
(
X509Certificate
)
HttpClientUtil
.
getCertificate
(
this
.
caFile
);
FileOutputStream
out
=
new
FileOutputStream
(
jksCAFile
);
HttpClientUtil
.
storeCACert
(
cert
,
"tenpay"
,
""
,
out
);
out
.
close
();
}
FileInputStream
trustStream
=
new
FileInputStream
(
jksCAFile
);
FileInputStream
keyStream
=
new
FileInputStream
(
this
.
certFile
);
SSLContext
sslContext
=
HttpClientUtil
.
getSSLContext
(
trustStream
,
""
,
keyStream
,
this
.
certPasswd
);
keyStream
.
close
();
trustStream
.
close
();
if
(
"POST"
.
equals
(
this
.
method
.
toUpperCase
(
Locale
.
ENGLISH
)))
{
String
url
=
HttpClientUtil
.
getURL
(
this
.
reqContent
);
String
queryString
=
HttpClientUtil
.
getQueryString
(
this
.
reqContent
);
byte
[]
postData
=
queryString
.
getBytes
(
this
.
charset
);
httpsPostMethod
(
url
,
postData
,
sslContext
);
return
;
}
httpsGetMethod
(
this
.
reqContent
,
sslContext
);
}
public
boolean
callHttpPost
(
String
url
,
String
postdata
)
{
boolean
flag
=
false
;
try
{
byte
[]
postData
=
postdata
.
getBytes
(
this
.
charset
);
httpPostMethod
(
url
,
postData
);
flag
=
true
;
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
return
flag
;
}
public
void
callHttpPostXml
(
String
xml
)
throws
Exception
{
String
caPath
=
this
.
caFile
.
getParent
();
File
jksCAFile
=
new
File
(
caPath
+
"/"
+
"wxpay_trust.jks"
);
if
(!
jksCAFile
.
isFile
())
{
X509Certificate
cert
=
(
X509Certificate
)
HttpClientUtil
.
getCertificate
(
this
.
caFile
);
FileOutputStream
out
=
new
FileOutputStream
(
jksCAFile
);
HttpClientUtil
.
storeCACert
(
cert
,
"tenpay"
,
"123456"
,
out
);
out
.
close
();
}
FileInputStream
trustStream
=
new
FileInputStream
(
jksCAFile
);
FileInputStream
keyStream
=
new
FileInputStream
(
this
.
certFile
);
SSLContext
sslContext
=
HttpClientUtil
.
getSSLContext
(
trustStream
,
"123456"
,
keyStream
,
this
.
certPasswd
);
keyStream
.
close
();
trustStream
.
close
();
if
(
"POST"
.
equals
(
this
.
method
.
toUpperCase
(
Locale
.
ENGLISH
)))
{
String
url
=
HttpClientUtil
.
getURL
(
this
.
reqContent
);
byte
[]
postData
=
xml
.
getBytes
(
this
.
charset
);
httpsPostMethodXml
(
url
,
postData
,
sslContext
);
return
;
}
httpsGetMethod
(
this
.
reqContent
,
sslContext
);
}
protected
void
httpPostMethod
(
String
url
,
byte
[]
postData
)
throws
IOException
{
HttpURLConnection
conn
=
HttpClientUtil
.
getHttpURLConnection
(
url
);
doPost
(
conn
,
postData
);
}
protected
void
httpGetMethod
(
String
url
)
throws
IOException
{
HttpURLConnection
httpConnection
=
HttpClientUtil
.
getHttpURLConnection
(
url
);
setHttpRequest
(
httpConnection
);
httpConnection
.
setRequestMethod
(
"GET"
);
this
.
responseCode
=
httpConnection
.
getResponseCode
();
this
.
inputStream
=
httpConnection
.
getInputStream
();
}
protected
void
httpsGetMethod
(
String
url
,
SSLContext
sslContext
)
throws
IOException
{
SSLSocketFactory
sf
=
sslContext
.
getSocketFactory
();
HttpsURLConnection
conn
=
HttpClientUtil
.
getHttpsURLConnection
(
url
);
conn
.
setSSLSocketFactory
(
sf
);
doGet
(
conn
);
}
protected
void
httpsPostMethod
(
String
url
,
byte
[]
postData
,
SSLContext
sslContext
)
throws
IOException
{
SSLSocketFactory
sf
=
sslContext
.
getSocketFactory
();
HttpsURLConnection
conn
=
HttpClientUtil
.
getHttpsURLConnection
(
url
);
conn
.
setSSLSocketFactory
(
sf
);
doPost
(
conn
,
postData
);
}
protected
void
httpsPostMethodXml
(
String
url
,
byte
[]
postData
,
SSLContext
sslContext
)
throws
IOException
{
SSLSocketFactory
sf
=
sslContext
.
getSocketFactory
();
HttpsURLConnection
conn
=
HttpClientUtil
.
getHttpsURLConnection
(
url
);
conn
.
setSSLSocketFactory
(
sf
);
doPostXml
(
conn
,
postData
);
}
protected
void
setHttpRequest
(
HttpURLConnection
httpConnection
)
{
httpConnection
.
setConnectTimeout
(
this
.
timeOut
*
1000
);
httpConnection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)"
);
httpConnection
.
setUseCaches
(
false
);
httpConnection
.
setDoInput
(
true
);
httpConnection
.
setDoOutput
(
true
);
}
protected
void
doResponse
()
throws
IOException
{
if
(
this
.
inputStream
==
null
)
{
return
;
}
this
.
resContent
=
HttpClientUtil
.
InputStreamTOString
(
this
.
inputStream
,
this
.
charset
);
this
.
inputStream
.
close
();
}
protected
void
doPost
(
HttpURLConnection
conn
,
byte
[]
postData
)
throws
IOException
{
conn
.
setRequestMethod
(
"POST"
);
setHttpRequest
(
conn
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
BufferedOutputStream
out
=
new
BufferedOutputStream
(
conn
.
getOutputStream
());
int
len
=
1024
;
HttpClientUtil
.
doOutput
(
out
,
postData
,
1024
);
out
.
close
();
this
.
responseCode
=
conn
.
getResponseCode
();
this
.
inputStream
=
conn
.
getInputStream
();
}
protected
void
doPostXml
(
HttpURLConnection
conn
,
byte
[]
postData
)
throws
IOException
{
conn
.
setRequestMethod
(
"POST"
);
setHttpRequest
(
conn
);
conn
.
setRequestProperty
(
"Content-Type"
,
"text/xml;charset=UTF-8"
);
BufferedOutputStream
out
=
new
BufferedOutputStream
(
conn
.
getOutputStream
());
int
len
=
1024
;
HttpClientUtil
.
doOutput
(
out
,
postData
,
1024
);
out
.
close
();
this
.
responseCode
=
conn
.
getResponseCode
();
this
.
inputStream
=
conn
.
getInputStream
();
}
protected
void
doGet
(
HttpURLConnection
conn
)
throws
IOException
{
conn
.
setRequestMethod
(
"GET"
);
setHttpRequest
(
conn
);
this
.
responseCode
=
conn
.
getResponseCode
();
this
.
inputStream
=
conn
.
getInputStream
();
}
public
String
getCharset
()
{
return
this
.
charset
;
}
public
void
setCharset
(
String
charset
)
{
this
.
charset
=
charset
;
}
}
service-manager/src/main/java/com/winsun/tenpay/util/TenpayUtil.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
public
class
TenpayUtil
{
public
static
String
toString
(
Object
obj
)
{
if
(
obj
==
null
)
{
return
""
;
}
return
obj
.
toString
();
}
public
static
int
toInt
(
Object
obj
)
{
int
a
=
0
;
try
{
if
(
obj
!=
null
)
{
a
=
Integer
.
parseInt
(
obj
.
toString
());
}
}
catch
(
Exception
localException
)
{}
return
a
;
}
public
static
String
getCurrTime
()
{
Date
now
=
new
Date
();
SimpleDateFormat
outFormat
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
String
s
=
outFormat
.
format
(
now
);
return
s
;
}
public
static
String
formatDate
(
Date
date
)
{
SimpleDateFormat
formatter
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
String
strDate
=
formatter
.
format
(
date
);
return
strDate
;
}
public
static
int
buildRandom
(
int
length
)
{
int
num
=
1
;
double
random
=
Math
.
random
();
if
(
random
<
0.1
D
)
{
random
+=
0.1
D
;
}
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
num
*=
10
;
}
return
(
int
)(
random
*
num
);
}
public
static
String
getCharacterEncoding
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
((
request
==
null
)
||
(
response
==
null
))
{
return
"gbk"
;
}
String
enc
=
request
.
getCharacterEncoding
();
if
((
enc
==
null
)
||
(
""
.
equals
(
enc
)))
{
enc
=
response
.
getCharacterEncoding
();
}
if
((
enc
==
null
)
||
(
""
.
equals
(
enc
)))
{
enc
=
"gbk"
;
}
return
enc
;
}
public
static
long
getUnixTime
(
Date
date
)
{
if
(
date
==
null
)
{
return
0L
;
}
return
date
.
getTime
()
/
1000L
;
}
public
static
String
date2String
(
Date
date
,
String
formatType
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
formatType
);
return
sdf
.
format
(
date
);
}
}
service-manager/src/main/java/com/winsun/tenpay/util/WXUtil.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.util.Random
;
public
class
WXUtil
{
public
static
String
getNonceStr
()
{
Random
random
=
new
Random
();
return
MD5Util
.
MD5Encode
(
String
.
valueOf
(
random
.
nextInt
(
10000
)),
"GBK"
);
}
public
static
String
getTimeStamp
()
{
return
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000L
);
}
}
service-manager/src/main/java/com/winsun/tenpay/util/XmlParser.java
0 → 100644
View file @
8d9c8598
package
com
.
winsun
.
tenpay
.
util
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
org.apache.log4j.Logger
;
import
org.dom4j.Attribute
;
import
org.dom4j.Document
;
import
org.dom4j.DocumentException
;
import
org.dom4j.DocumentHelper
;
import
org.dom4j.Element
;
import
org.dom4j.Node
;
import
org.dom4j.io.SAXReader
;
public
class
XmlParser
{
Logger
logger
=
Logger
.
getLogger
(
XmlParser
.
class
);
private
final
String
SPCODE_XPATH
=
"/params/spcode"
;
private
final
String
PARAMS_XPATH
=
"/params/*"
;
Document
doc
;
public
XmlParser
()
{
}
public
XmlParser
(
String
xmlString
)
throws
DocumentException
{
loadXml
(
xmlString
);
}
/**
* 设置bean属性值
*
* @param clazz
* @param obj
* @param nodes
* @throws Exception
*/
public
void
setValues
(
Object
obj
,
List
<
Node
>
nodes
)
throws
Exception
{
try
{
for
(
Node
node
:
nodes
)
{
Method
[]
methods
=
obj
.
getClass
().
getMethods
();
for
(
Method
method
:
methods
)
{
Class
<?>[]
paramTypes
=
method
.
getParameterTypes
();
if
(
method
.
getName
().
toLowerCase
(
Locale
.
ENGLISH
).
equals
(
"set"
+
node
.
getName
()))
{
if
(
StringUtil
.
isNotEmpty
(
node
.
getStringValue
().
trim
())){
if
(
paramTypes
[
0
].
getCanonicalName
().
endsWith
(
"Long"
))
{
method
.
invoke
(
obj
,
new
Long
(
node
.
getStringValue
()));
}
else
if
(
paramTypes
[
0
].
getCanonicalName
().
endsWith
(
"Double"
))
{
method
.
invoke
(
obj
,
new
Double
(
node
.
getStringValue
()));
}
else
{
method
.
invoke
(
obj
,
node
.
getStringValue
());
}
}
}
}
}
}
catch
(
RuntimeException
e
)
{
logger
.
error
(
"设置bean属性值失败。"
,
e
);
throw
e
;
}
}
/**
* 根据xml串和xpath获取spcode
*
* @param xmlString
* @param xpath
* @return
* @throws Exception
*/
public
String
getSpCode
(
String
xmlString
)
throws
Exception
{
return
getSingleValue
(
xmlString
,
SPCODE_XPATH
);
}
/**
* 获取单个属性的值
*
* @param xmlString
* @param xpath
* @return
* @throws Exception
*/
public
String
getSingleValue
(
String
xmlString
,
String
xpath
)
throws
Exception
{
try
{
if
((
xmlString
==
null
||
xmlString
.
trim
().
equals
(
""
))
&&
doc
==
null
)
{
return
null
;
}
load
(
xmlString
);
Node
node
=
doc
.
selectSingleNode
(
xpath
);
if
(
node
!=
null
)
return
node
.
getStringValue
();
else
{
logger
.
info
(
"xml中没有指定的属性信息。"
+
xpath
);
return
null
;
}
}
catch
(
RuntimeException
e
)
{
logger
.
error
(
"获取指定属性值失败。"
,
e
);
throw
e
;
}
}
/**
* 获取单个属性的值
*
* @param xpath
* @return
*/
public
String
getSingleValue
(
String
xpath
)
throws
Exception
{
return
getSingleValue
(
null
,
xpath
);
}
/**
* 根据输入的xpath,找出所有属性值
*
* @param xmlString
* @param xpath
* @return
* @throws Exception
*/
@SuppressWarnings
(
"unchecked"
)
public
List
<
String
>
getMultiValue
(
String
xmlString
,
String
xpath
)
throws
Exception
{
try
{
load
(
xmlString
);
List
<
Node
>
nodes
=
doc
.
selectNodes
(
xpath
);
List
<
String
>
results
=
new
ArrayList
<
String
>(
0
);
if
(
nodes
!=
null
&&
nodes
.
size
()
>
0
)
{
for
(
Node
node
:
nodes
)
{
results
.
add
(
node
.
getStringValue
());
}
return
results
;
}
else
{
logger
.
info
(
"找不到对应的节点."
+
xpath
);
return
null
;
}
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"获取属性值失败。"
,
e
);
throw
e
;
}
}
public
List
<
String
>
getMultiValue
(
String
xpath
)
throws
Exception
{
return
getMultiValue
(
null
,
xpath
);
}
/**
* 根据输入的参数名称,从xml串获取参数值
*
* @param xmlString
* @param 参数名称集
* @return
*/
public
List
<
String
>
getParams
(
String
xmlString
,
String
[]
paramNames
)
throws
Exception
{
reload
(
xmlString
);
return
getParams
(
paramNames
,
PARAMS_XPATH
);
}
public
List
<
String
>
getParams
(
String
[]
paramNames
)
throws
Exception
{
return
getParams
(
null
,
paramNames
);
}
/**
* 根据输入的参数名称,从xml串获取值,需要xpath
*
* @param xmlString
* @param paramNames
* @param xpath
* @return
* @throws Exception
*/
public
List
<
String
>
getParams
(
String
xmlString
,
String
[]
paramNames
,
String
xpath
)
throws
Exception
{
try
{
List
<
Node
>
nodes
=
getNodes
(
xmlString
,
xpath
);
List
<
String
>
rtnObj
=
new
ArrayList
<
String
>(
0
);
if
(
nodes
==
null
)
return
null
;
Outer:
for
(
String
name
:
paramNames
)
{
for
(
Node
node
:
nodes
)
{
if
(
node
.
getName
().
equals
(
name
))
{
rtnObj
.
add
(
node
.
getStringValue
());
continue
Outer
;
}
}
logger
.
error
(
"传入XML参数中未找到 "
+
name
+
" 字段"
);
throw
new
Exception
(
"传入XML参数中未找到 "
+
name
+
" 字段"
);
}
return
rtnObj
;
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"从xml串解析参数列表失败。"
,
e
);
throw
e
;
}
}
public
List
<
String
>
getParams
(
String
[]
paramNames
,
String
xpath
)
throws
Exception
{
try
{
List
<
Node
>
nodes
=
getNodes
(
xpath
);
List
<
String
>
rtnObj
=
new
ArrayList
<
String
>(
0
);
if
(
nodes
==
null
)
return
null
;
Outer:
for
(
String
name
:
paramNames
)
{
for
(
Node
node
:
nodes
)
{
if
(
node
.
getName
().
equals
(
name
))
{
rtnObj
.
add
(
node
.
getStringValue
());
continue
Outer
;
}
}
logger
.
error
(
"传入XML参数中未找到 "
+
name
+
" 字段"
);
//throw new Exception("传入XML参数中未找到 " + name + " 字段");
}
return
rtnObj
;
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"从xml串解析参数列表失败。"
,
e
);
throw
e
;
}
}
/**
* 过滤xmlString,根据输入的xml和节点名字以及值过滤条件过滤掉不需要的节点。
* (注意,被删除掉的是输入的节点的父节点,会有非根结点的验证。)
*
* @param xmlString
* 需要过滤的串
* @param xpath
* 查找的xpath串(包含查找的条件信息)
* @return 过滤后的xml串
*/
@SuppressWarnings
(
"unchecked"
)
public
String
filterOutput
(
String
xmlString
,
String
xpath
)
throws
Exception
{
try
{
load
(
xmlString
);
if
(
doc
==
null
)
return
null
;
List
<
Node
>
nodes
=
doc
.
selectNodes
(
xpath
);
for
(
Node
node
:
nodes
)
{
node
.
getParent
().
remove
(
node
);
}
return
doc
.
asXML
();
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"过滤xml串失败。"
,
e
);
throw
e
;
}
}
public
void
appendData
(
String
xpath
,
String
...
xmlStrings
)
{
}
/**
* 根据指定的xpath获取节点集合。
*
* @param xpath
* @return
* @throws Exception
*/
@SuppressWarnings
(
"unchecked"
)
public
List
<
Element
>
getELements
(
String
xmlString
,
String
xpath
)
throws
Exception
{
try
{
load
(
xmlString
);
if
(
doc
==
null
)
return
null
;
List
<
Element
>
nodes
=
doc
.
selectNodes
(
xpath
);
return
nodes
;
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"获取节点集合失败。"
,
e
);
throw
e
;
}
}
public
List
<
Element
>
getELements
(
String
xpath
)
throws
Exception
{
return
getELements
(
null
,
xpath
);
}
@SuppressWarnings
(
"unchecked"
)
public
List
<
Node
>
getNodes
(
String
xmlString
,
String
xpath
)
throws
Exception
{
try
{
load
(
xmlString
);
if
(
doc
==
null
)
return
new
ArrayList
<
Node
>(
0
);
List
<
Node
>
nodes
=
doc
.
selectNodes
(
xpath
);
return
nodes
;
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"获取节点失败。"
,
e
);
throw
e
;
}
}
public
List
<
Node
>
getNodes
(
String
xpath
)
throws
Exception
{
if
(
doc
==
null
)
return
null
;
return
doc
.
selectNodes
(
xpath
);
}
public
Node
getSingleNode
(
String
xmlString
,
String
xpath
)
throws
Exception
{
try
{
load
(
xmlString
);
if
(
doc
==
null
)
return
null
;
Node
node
=
doc
.
selectSingleNode
(
xpath
);
return
node
;
}
catch
(
RuntimeException
e
)
{
logger
.
error
(
"获取节点失败。"
,
e
);
throw
e
;
}
}
public
Node
getSingleNode
(
String
xpath
)
throws
Exception
{
return
getSingleNode
(
null
,
xpath
);
}
@SuppressWarnings
(
"unchecked"
)
public
String
addNodes
(
String
xmlString
,
String
xpath
,
String
nodeName
,
String
value
)
{
try
{
load
(
xmlString
);
if
(
doc
==
null
)
return
null
;
List
<
Node
>
nodes
=
doc
.
selectNodes
(
xpath
);
for
(
Node
node
:
nodes
)
{
Element
e
=
(
Element
)
node
;
Element
c
=
e
.
addElement
(
nodeName
);
c
.
addText
(
value
);
}
return
doc
.
asXML
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"添加节点失败。"
,
e
);
return
null
;
}
}
public
String
addNodes
(
String
xpath
,
String
nodeName
,
String
value
)
{
return
addNodes
(
null
,
xpath
,
nodeName
,
value
);
}
private
boolean
validateNull
(
Object
s
)
{
if
(
s
==
null
||
s
.
toString
().
trim
().
equals
(
""
))
{
return
false
;
}
return
true
;
}
public
String
getAttributeValue
(
String
xmlString
,
String
xpath
)
throws
DocumentException
{
try
{
load
(
xmlString
);
if
(
doc
==
null
)
return
null
;
Attribute
a
=
(
Attribute
)
doc
.
selectObject
(
xpath
);
return
a
.
getValue
();
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"获取属性值失败。"
,
e
);
throw
e
;
}
catch
(
RuntimeException
e
)
{
logger
.
error
(
"获取属性值失败。"
,
e
);
throw
e
;
}
}
public
String
getAttributeValue
(
String
xpath
)
throws
DocumentException
{
return
getAttributeValue
(
null
,
xpath
);
}
public
String
getXmlString
()
{
if
(
doc
!=
null
)
return
doc
.
asXML
();
else
return
null
;
}
private
void
loadXml
(
String
xml
)
throws
DocumentException
{
try
{
if
(
xml
==
null
||
xml
.
equals
(
""
))
{
return
;
}
doc
=
DocumentHelper
.
parseText
(
xml
);
}
catch
(
DocumentException
e
)
{
logger
.
error
(
"创建xml解析器失败。"
,
e
);
throw
e
;
}
}
private
void
load
(
String
xml
)
throws
DocumentException
{
if
(
doc
==
null
&&
xml
!=
null
&&
!
xml
.
trim
().
equals
(
""
))
{
loadXml
(
xml
);
}
}
/**
* 强行重新读入xml
*
* @param xmlString
* @throws DocumentException
*/
public
void
reload
(
String
xmlString
)
throws
DocumentException
{
loadXml
(
xmlString
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
xml
=
"<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\"><s:Header><a:Action s:mustUnderstand=\"1\">http://tempuri.org/ISarftService/ProcessResponse</a:Action><ActivityId CorrelationId=\"ef4f07d1-fa4a-48ec-9cb3-73d1b02edcff\" xmlns=\"http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics\">47cd77f2-ed60-4084-9d4c-87bf3c78bc1d</ActivityId></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><reply xmlns=\"http://www.crifst.ac.cn/2013/OTSAPI\"><msg><?xml version=\"1.0\" encoding=\"utf-8\"?><OnlineTicketingServiceReply xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" Datetime=\"2014-12-02T15:38:30\" Version=\"1.0\"><QuerySessionReply ErrorCode=\"\" ErrorMessage=\"\" Id=\"ID_QuerySessionReply\" Status=\"Success\"><Sessions CinemaCode=\"0042\"></Sessions></QuerySessionReply></OnlineTicketingServiceReply></msg></reply></s:Body></s:Envelope>"
;
XmlParser
parser
=
new
XmlParser
();
parser
.
reload
(
xml
);
Document
resultDoc
=
null
;
try
{
resultDoc
=
DocumentHelper
.
parseText
(
xml
);
}
catch
(
DocumentException
e
)
{
e
.
printStackTrace
();
}
Element
rootEle
=
resultDoc
.
getRootElement
();
Element
ele
=
rootEle
.
element
(
"s:Body"
);
System
.
out
.
print
(
"end"
);
}
/**
* 根据request将XML流解析成MAP
*
* @param request
* @return
* @throws IOException
* @throws DocumentException
*/
public
static
Map
<
String
,
String
>
xmlToMap
(
InputStream
in
)
throws
DocumentException
,
IOException
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
SAXReader
reader
=
new
SAXReader
();
Document
document
=
reader
.
read
(
in
);
Element
root
=
document
.
getRootElement
();
List
<
Element
>
list
=
root
.
elements
();
for
(
Element
e
:
list
)
{
map
.
put
(
e
.
getName
(),
e
.
getText
());
}
in
.
close
();
return
map
;
}
/**
* map转xml map中没有根节点的键
* @param map
* @param rootName
* @throws DocumentException
* @throws IOException
*//*
public static Document map2xml(Map<String, Object> map, String rootName) throws DocumentException, IOException {
Document doc = DocumentHelper.createDocument();
Element root = DocumentHelper.createElement(rootName);
doc.add(root);
map2xml(map, root);
//System.out.println(doc.asXML());
//System.out.println(formatXml(doc));
return doc;
}
*//**
* map转xml map中含有根节点的键
* @param map
* @throws DocumentException
* @throws IOException
*//*
public static Document map2xml(Map<String, Object> map) throws DocumentException, IOException {
Iterator<Map.Entry<String, Object>> entries = map.entrySet().iterator();
if(entries.hasNext()){ //获取第一个键创建根节点
Map.Entry<String, Object> entry = entries.next();
Document doc = DocumentHelper.createDocument();
Element root = DocumentHelper.createElement(entry.getKey());
doc.add(root);
map2xml((Map)entry.getValue(), root);
//System.out.println(doc.asXML());
//System.out.println(formatXml(doc));
return doc;
}
return null;
}
*//**
* map转xml
* @param map
* @param body xml元素
* @return
*//*
private static Element map2xml(Map<String, Object> map, Element body) {
Iterator<Map.Entry<String, Object>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Object> entry = entries.next();
String key = entry.getKey();
Object value = entry.getValue();
if(key.startsWith("@")){ //属性
body.addAttribute(key.substring(1, key.length()), value.toString());
} else if(key.equals("#text")){ //有属性时的文本
body.setText(value.toString());
} else {
if(value instanceof java.util.List ){
List list = (List)value;
Object obj;
for(int i=0; i<list.size(); i++){
obj = list.get(i);
//list里是map或String,不会存在list里直接是list的,
if(obj instanceof java.util.Map){
Element subElement = body.addElement(key);
map2xml((Map)list.get(i), subElement);
} else {
body.addElement(key).setText((String)list.get(i));
}
}
} else if(value instanceof java.util.Map ){
Element subElement = body.addElement(key);
map2xml((Map)value, subElement);
} else {
body.addElement(key).setText(value.toString());
}
}
//System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
return body;
} */
public
static
String
map2XmlString
(
Map
<
String
,
String
>
map
)
{
String
xmlResult
=
""
;
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"<xml>"
);
for
(
String
key
:
map
.
keySet
())
{
String
value
=
"<![CDATA["
+
map
.
get
(
key
)
+
"]]>"
;
sb
.
append
(
"<"
+
key
+
">"
+
value
+
"</"
+
key
+
">"
);
}
sb
.
append
(
"</xml>"
);
xmlResult
=
sb
.
toString
();
return
xmlResult
;
}
}
service-manager/src/main/java/com/winsun/utils/ExcelDealUtils.java
View file @
8d9c8598
...
...
@@ -266,4 +266,40 @@ public class ExcelDealUtils {
return
resultMap
;
}
// 账单汇总导出excel表头
public
static
Map
<
String
,
Object
>
billStatisExcel
(
String
sheetName
){
Map
<
String
,
Object
>
headMap
=
new
LinkedHashMap
<
String
,
Object
>();
headMap
.
put
(
"项目类型"
,
"billType"
);
headMap
.
put
(
"月份"
,
"month"
);
headMap
.
put
(
"收支详情"
,
"billDetail"
);
headMap
.
put
(
"金额"
,
"amount"
);
headMap
.
put
(
"项目类型"
,
"billTypeExpense"
);
headMap
.
put
(
"月份"
,
"monthExpense"
);
headMap
.
put
(
"收支详情"
,
"billDetailExpense"
);
headMap
.
put
(
"不含税金额"
,
"amountExpense"
);
headMap
.
put
(
"含税金额"
,
"taxAmount"
);
Map
<
String
,
Object
>
resultMap
=
dealHeadMap
(
headMap
);
resultMap
.
put
(
"sheetName"
,
sheetName
);
return
resultMap
;
}
// 奖励结算导出excel表头
public
static
Map
<
String
,
Object
>
bonusExcel
(
String
sheetName
){
Map
<
String
,
Object
>
headMap
=
new
LinkedHashMap
<
String
,
Object
>();
headMap
.
put
(
"账号"
,
"account"
);
headMap
.
put
(
"姓名"
,
"userName"
);
headMap
.
put
(
"县分"
,
"substName"
);
headMap
.
put
(
"学校"
,
"schoolName"
);
headMap
.
put
(
"金额"
,
"bonus"
);
headMap
.
put
(
"佣金状态"
,
"state"
);
Map
<
String
,
Object
>
resultMap
=
dealHeadMap
(
headMap
);
resultMap
.
put
(
"sheetName"
,
sheetName
);
return
resultMap
;
}
}
service-manager/src/main/resources/apiclient_cert.p12
0 → 100644
View file @
8d9c8598
File added
service-manager/src/main/resources/tenpayconfig.properties
0 → 100644
View file @
8d9c8598
##### wx pay config#########
##
# xiaoyuan
##
tenpay_app_id
=
wx0641dc1dc4d34384
tenpay_app_secret
=
3b43b46fc94d4e98588ee6ad992fa5c7
tenpay_mch_id
=
1498149672
#tenpay_app_key=168168ABCDHENGYIDE66XYJL51525388
tenpay_app_key
=
WINSUN123456xyjl987654wxpay88888
##
# test winsun
##
#tenpay_app_id=wxfc18f5186b729d15
#tenpay_app_secret=122278f3fb555468848ff040620505ad
#tenpay_mch_id=1346602601
#tenpay_app_key=wi20nsu17nt07est18go16nb88168123
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