Merge branches '0602L' and 'test' of http://192.168.12.182/invoice/pt into test

release
yishiqihuasheng 2 years ago
commit 05c8d38e3c
  1. 10
      dxhy-base/src/main/java/com/dxhy/base/service/fpxxrz/BaseRzFpxxServiceImpl.java
  2. 11
      dxhy-base/src/main/java/com/dxhy/base/service/invoicecheck/BaseInvoiceManualCheckServiceImpl.java
  3. 5
      dxhy-base/src/main/java/com/dxhy/base/service/tdxrecordinvoice/BaseFpdrrzServiceImpl.java
  4. 4
      dxhy-base/src/main/resources/mapper/BaseFpZhMapper.xml
  5. 14
      dxhy-base/src/main/resources/mapper/BaseSggxcxMapper.xml
  6. 1
      dxhy-common/src/main/java/com/dxhy/common/service/impl/DictdetaServciceImpl.java
  7. 2
      dxhy-core/pom.xml
  8. 29
      dxhy-core/src/main/java/com/dxhy/core/thread/FpcjhzExportThread.java
  9. 24
      dxhy-core/src/main/java/com/dxhy/core/thread/PoolAddTaxThread.java
  10. 23
      dxhy-core/src/main/java/com/dxhy/core/thread/PoolSaleThread.java
  11. 48
      dxhy-core/src/main/resources/mapper/ExtPaperMapper.xml
  12. 1
      dxhy-core/src/main/resources/mapper/FpZhMapper.xml
  13. 2
      dxhy-customs/pom.xml
  14. 2
      dxhy-erp/pom.xml
  15. 113
      dxhy-erp/src/main/java/com/dxhy/erp/service/impl/InvoiceAuthServiceImpl.java
  16. 39
      dxhy-extend/src/main/java/com/dxhy/extend/controller/ExtFpzhcxController.java
  17. 39
      dxhy-extend/src/main/java/com/dxhy/extend/controller/ExtInvoicePoolController.java
  18. 56
      dxhy-extend/src/main/resources/mapper/ExtBbfpzhMapper.xml
  19. 2
      dxhy-extend/src/main/resources/mapper/ExtBbycfpcxMapper.xml
  20. 44
      dxhy-extend/src/main/resources/mapper/ExtInvoicePoolMapper.xml
  21. 22
      dxhy-extend/src/main/resources/mapper/ExtJxssbbMapper.xml
  22. 1
      dxhy-oss/README
  23. 132
      dxhy-oss/pom.xml
  24. 154
      dxhy-oss/src/main/java/com/dxhy/oss/config/OssConfig.java
  25. 27
      dxhy-oss/src/main/java/com/dxhy/oss/config/OssReturnConfig.java
  26. 19
      dxhy-oss/src/main/java/com/dxhy/oss/model/FileModel.java
  27. 41
      dxhy-oss/src/main/java/com/dxhy/oss/service/AliOssService.java
  28. 72
      dxhy-oss/src/main/java/com/dxhy/oss/service/FileService.java
  29. 275
      dxhy-oss/src/main/java/com/dxhy/oss/service/FtpService.java
  30. 46
      dxhy-oss/src/main/java/com/dxhy/oss/service/JdOssService.java
  31. 165
      dxhy-oss/src/main/java/com/dxhy/oss/service/SshService.java
  32. 186
      dxhy-oss/src/main/java/com/dxhy/oss/service/impl/AliOssServiceImpl.java
  33. 328
      dxhy-oss/src/main/java/com/dxhy/oss/service/impl/FileServiceImpl.java
  34. 213
      dxhy-oss/src/main/java/com/dxhy/oss/service/impl/JdOssServiceImpl.java
  35. 55
      dxhy-oss/src/main/java/com/dxhy/oss/service/impl/OssClientFactory.java
  36. 60
      dxhy-oss/src/main/java/com/dxhy/oss/utils/FileTypeUtils.java
  37. 32
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SftpConfig.java
  38. 67
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SftpFactory.java
  39. 41
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SftpPool.java
  40. 15
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SftpPoolException.java
  41. 61
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SftpProperties.java
  42. 31
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SshConfig.java
  43. 70
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SshFactory.java
  44. 41
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SshPool.java
  45. 61
      dxhy-oss/src/main/java/com/dxhy/oss/utils/SshProperties.java
  46. 13
      dxhy-oss/src/test/java/com/dxhy/DxhyOssApplication.java
  47. 40
      dxhy-oss/src/test/java/com/dxhy/OfdHandle.java
  48. 127
      dxhy-oss/src/test/java/com/dxhy/OssTest.java
  49. 43
      dxhy-oss/src/test/java/com/dxhy/SpringContextUtils.java
  50. 48
      dxhy-oss/src/test/resources/application.yml
  51. 2
      dxhy-portrait/pom.xml
  52. 2
      dxhy-sign/pom.xml
  53. 1
      pom.xml

@ -72,6 +72,7 @@ public class BaseRzFpxxServiceImpl extends MpBaseServiceImpl<BaseFpxxZhDao, Base
orgList.add(t.getTaxno());
}
}
log.info("orgList======>{}",orgList);
if (gfshList.size() == 0) {
// 未从getUserInfo()获取到购方税号信息
@ -124,11 +125,9 @@ public class BaseRzFpxxServiceImpl extends MpBaseServiceImpl<BaseFpxxZhDao, Base
for (int i = 0; i < pageList.size(); i++) {
pageList.get(i).setSelect(false);
String taxno = pageList.get(i).getGfsh();
// if (orgList.contains(taxno) && "1".equals(pageList.get(i).getRzzt())) {
// pageList.get(i).setSelect(true);
// }
if ("0".equals(pageList.get(i).getRzzt())) {
if (orgList.contains(taxno) && "1".equals(pageList.get(i).getRzzt())) {
pageList.get(i).setSelect(true);
log.info("rzzt和orgList设置成true");
}
String skssq = pageList.get(i).getSkssq();
QueryWrapper<BaseTDxTaxCurrent> queryWrapper = new QueryWrapper<>();
@ -138,6 +137,7 @@ public class BaseRzFpxxServiceImpl extends MpBaseServiceImpl<BaseFpxxZhDao, Base
if (!taxCurrent.getCurrentTaxPeriod().equals(skssq)
|| !"1".equals(pageList.get(i).getRzzt())) {
pageList.get(i).setSelect(false);
log.info("skssq设置为false");
}
}
@ -155,6 +155,7 @@ public class BaseRzFpxxServiceImpl extends MpBaseServiceImpl<BaseFpxxZhDao, Base
if (!"0".equals(pageList.get(i).getCxrzStatus())
&& !"5".equals(pageList.get(i).getCxrzStatus())) {
pageList.get(i).setSelect(false);
log.info("撤销认证状态设置false");
}
String sign = (String) pramsMap.get("sign");
if (!"88".equals(sign)){
@ -166,6 +167,7 @@ public class BaseRzFpxxServiceImpl extends MpBaseServiceImpl<BaseFpxxZhDao, Base
if ("1".equals(pageList.get(i).getOutStatus()) || "2".equals(pageList.get(i).getOutStatus())) {
pageList.get(i).setSelect(false);
log.info("转出状态设置false");
}
// 字典转换

@ -65,6 +65,7 @@ public class BaseInvoiceManualCheckServiceImpl extends MpBaseServiceImpl<BaseTDx
@Override
public String selectByManualCheck(Map<String, Object> pramsMap, int curr, int size) {
long enter = System.currentTimeMillis();
log.info("入参是:{}",pramsMap);
JSONObject json;
DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
@ -106,7 +107,9 @@ public class BaseInvoiceManualCheckServiceImpl extends MpBaseServiceImpl<BaseTDx
String hjsl = "0";
String hjje = "0";
String hjse = "0";
long start = System.currentTimeMillis();
List<BaseTDxRecordInvoice> hjList = super.baseMapper.selectHj(pramsMap);
log.info("手工认证 查询统计信息耗时:{}",System.currentTimeMillis()-start);
BaseTDxRecordInvoice hjxx = hjList.get(0);
hjsl = hjxx.getSfygx();
if (!"0".equals(hjsl)) {
@ -123,12 +126,16 @@ public class BaseInvoiceManualCheckServiceImpl extends MpBaseServiceImpl<BaseTDx
}
}
log.info("查询合计耗时:{}",System.currentTimeMillis()-enter);
PageHelper.startPage(curr, size);
long start1 = System.currentTimeMillis();
List<BaseTDxRecordInvoice> pageList = super.baseMapper.selectSggxcx(pramsMap);
log.info("手工认证 查询列表信息耗时:{}",System.currentTimeMillis()-start1);
PageInfo<BaseTDxRecordInvoice> pageInfo = new PageInfo<>(pageList);
log.info("返回的列表为:{}",pageList);
log.info("查询耗时:{}",System.currentTimeMillis()-enter);
// 转化为页面展示对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (pageList.size() > 0) {
@ -262,6 +269,8 @@ public class BaseInvoiceManualCheckServiceImpl extends MpBaseServiceImpl<BaseTDx
}
json.put("total", pageInfo.getTotal());
json.put("datalist", voList);
log.info("总计耗时:{}",System.currentTimeMillis()-enter);
} catch (Exception e) {
// 统一设置操作异常标识
log.info("错误信息为:{}",e.getMessage());

@ -81,12 +81,14 @@ public class BaseFpdrrzServiceImpl extends MpBaseServiceImpl<BaseFpdrrzDao, Base
String fphm = jsonObject.getString("invoiceNo");
String kprq = jsonObject.getString("invoiceDate");
String se = jsonObject.getString("taxAmount");
String dkse1 = jsonObject.getString("taxAmount");
BaseFpdrrzRespVO rzlb = new BaseFpdrrzRespVO();
rzlb.setSelect(true);
rzlb.setXh(String.valueOf(i + 1));
rzlb.setBkrzts("");
rzlb.setFpdm(fpdm);
rzlb.setFphm(fphm);
rzlb.setDkse(dkse1);
if (fphm.length() == 20) {
rzlb.setFpdm(fphm.substring(0, 12));
rzlb.setFphm(fphm.substring(12, 20));
@ -144,6 +146,9 @@ public class BaseFpdrrzServiceImpl extends MpBaseServiceImpl<BaseFpdrrzDao, Base
QueryWrapper<BaseTDxRecordInvoice> queryRecord = new QueryWrapper<>();
queryRecord.eq("uuid", uuid);
BaseTDxRecordInvoice rdxRecordInvoice = baseTDxRecordInvoiceDao.selectOne(queryRecord);
if (rdxRecordInvoice.getDkTaxAmount() != null && StringHelper.isNotBlank(rdxRecordInvoice.getDkTaxAmount().toPlainString())){
rzlb.setDkse(rdxRecordInvoice.getDkTaxAmount().toPlainString());
}
if (rdxRecordInvoice != null) {
if (list == null || list.size() == 0 || !list.contains(rdxRecordInvoice.getGfTaxNo())) {
rzlb.setBkrzts("无该发票购方税号权限");

@ -73,7 +73,7 @@
bdk_date,t.rzh_back_msg,t.in_account_status,t.payment_status,date_format(t.payment_date,'%Y-%m-%d')payment_date,
voucher_number,t.ele_invoice_no, sn_voucher_number, account_period, posting_time ,image_id
from t_dx_record_invoice t
WHERE date_format(t.invoice_date,'%Y-%m-%d') between #{kpksrq} and #{kpjsrq}
WHERE t.invoice_date between #{kpksrq} and #{kpjsrq}
and (t.invoice_type in('01','03','08','14','31','283','161','183','185') or (t.invoice_type ='32' and t.lq_tdyslxDm='08'))
and t.bdk_status in ('1','2')
and t.export_mark = '0'
@ -353,7 +353,7 @@
resultMap="RzcxhjResultMap" databaseId="mysql">
select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
from t_dx_record_invoice t
WHERE date_format(t.invoice_date,'%Y-%m-%d') between #{kpksrq} and #{kpjsrq}
WHERE t.invoice_date between #{kpksrq} and #{kpjsrq}
and (t.invoice_type in('01','03','08','14','31','283','161','183','185') or (t.invoice_type ='32' and t.lq_tdyslxDm='08'))
and t.auth_status != '0'
and t.bdk_status in ('1','2')

@ -72,7 +72,7 @@
t.inaccount_status,t.payment_status,DATE_FORMAT(t.payment_date,'%Y-%m-%d')payment_date,t.settlement_no,t.ele_invoice_no
from t_dx_record_invoice t left join t_dx_tax_current c on t.gf_tax_no = c.taxno
left join t_dx_dk_count d on c.taxno = d.taxno and c.current_tax_period = d.skssq
WHERE date_format(t.invoice_date,'%Y-%m-%d') between #{kpksrq} and #{kpjsrq}
WHERE t.invoice_date between #{kpksrq} and #{kpjsrq}
and (t.invoice_type in('01','03','08','14','31','283','161','183','185') or (t.invoice_type ='32' and t.lq_tdyslxDm='08'))
and t.rzh_yesorno = '0'
and t.auth_status in('0','5','6')
@ -82,14 +82,14 @@
and t.invoice_status in ('0','7')
and t.invoice_amount>0
and t.tax_amount>=0
and date_format(t.invoice_date,'%Y%m%d') between c.select_start_date and c.select_end_date
and t.invoice_date between c.select_start_date and c.select_end_date
and d.tj_status in('0','3')
</if>
<if test="sfkrz != '99' and sfkrz != null and sfkrz != '' and sfkrz != 'null' and sfkrz == '0'.toString()">
and (t.invoice_status in ('1','2','3','4','8','80') or t.invoice_amount &lt;0 or t.tax_amount &lt;0 or
date_format(t.invoice_date,'%Y%m%d') &lt;= c.select_start_date or
date_format(t.invoice_date,'%Y%m%d') &gt;=
t.invoice_date &lt;= c.select_start_date or
t.invoice_date &gt;=
c.select_end_date or d.tj_status in ('1','2'))
</if>
@ -109,9 +109,9 @@
<foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
#{companyCode}
</foreach>
or t.comp_code is null or t.comp_code = ''
)
</if>
<!-- or t.comp_code is null or t.comp_code = ''-->
<if test="companyCode != null and companyCode != '99' and companyCode != '88' and companyCode != '' and companyCode != 'null'" >
and t.comp_code = #{companyCode}
</if>
@ -223,7 +223,6 @@
<!-- <if test="qsksrq==null or qsksrq=='' or qsjsrq==null or qsjsrq==''">-->
<!-- order by t.invoice_date desc-->
<!-- </if>-->
order by t.bzdh desc
</select>
<select id="selectDksh" parameterType="java.util.Map"
resultType="com.dxhy.base.entity.BaseTDxDkCount"
@ -396,7 +395,7 @@
select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
from t_dx_record_invoice t left join t_dx_tax_current c on t.gf_tax_no = c.taxno
left join t_dx_dk_count d on c.taxno = d.taxno and c.current_tax_period = d.skssq
WHERE date_format(t.invoice_date,'%Y-%m-%d') between #{kpksrq} and #{kpjsrq}
WHERE t.invoice_date between #{kpksrq} and #{kpjsrq}
and (t.invoice_type in('01','03','08','14','31','283','161','183','185') or (t.invoice_type ='32' and t.lq_tdyslxDm='08'))
and t.rzh_yesorno = '0'
and t.auth_status in('0','5','6')
@ -553,7 +552,6 @@
<if test="accountPeriod != null and accountPeriod != '' and accountPeriod != 'null' and accountPeriod != '99'">
and t.account_period = #{accountPeriod}
</if>
order by t.bzdh desc
</select>
<select id="selectHj" parameterType="java.util.Map"

@ -34,7 +34,6 @@ public class DictdetaServciceImpl implements DictdetaServcice {
@Override
public String queryDictName(String type,String code) {
log.info("type={},code={}",type,code);
String dictJson = redisUtils.get(RedisConstant.KEY_DICT + type);
List<DictdetaModel> dictdetaModels = JSON.parseArray(dictJson, DictdetaModel.class);
Map<String, String> collect = dictdetaModels.stream().collect(Collectors.toMap(DictdetaModel::getDictcode, DictdetaModel::getDictname));

@ -150,7 +150,7 @@
<dependency>
<groupId>com.dxhy.jxpt</groupId>
<artifactId>dxhy-oss</artifactId>
<version>3.2.9</version>
<version>3.3.3</version>
</dependency>
<!-- itext pdf相关 -->
<dependency>

@ -169,14 +169,18 @@ public class FpcjhzExportThread extends BaseThread {
excelFile.append(ftpFileName.toString());
// 递归导出数据到excel
this.cicleExport(pramsMap, default_curr, excelFile.toString(), jsonObject);
// FTP文件存储路径
String[] toDay = DateUtil.today().split("-");
String ftpFilePath = fileService.getPathPrefix() + userName + "/" + "excelFile/" + toDay[0] + "/"
+ toDay[1] + "/" + toDay[2] + "/" + ftpFileName.toString();
// 文件上传ftp
fileService.uploadFile(ftpFilePath, excelFile.toString());
String ftpFilePath = "";
String rtnMsg = this.cicleExport(pramsMap, default_curr, excelFile.toString(), jsonObject);
if("ok".equals(rtnMsg)) {
// FTP文件存储路径
String[] toDay = DateUtil.today().split("-");
ftpFilePath = fileService.getPathPrefix() + userName + "/" + "excelFile/" + toDay[0] + "/"
+ toDay[1] + "/" + toDay[2] + "/" + ftpFileName.toString();
// 文件上传ftp
fileService.uploadFile(ftpFilePath, excelFile.toString());
}else{
ftpFilePath = rtnMsg;
}
// 设置成功消息内容
msg.put("title", super.getSuccTitle(title));
@ -222,12 +226,15 @@ public class FpcjhzExportThread extends BaseThread {
*
*/
private boolean cicleExport(Map<String, Object> pramsMap, int curr, String excelFile, JSONObject jsonObject)
private String cicleExport(Map<String, Object> pramsMap, int curr, String excelFile, JSONObject jsonObject)
throws Exception {
// 查询指定页数的数据
JSONObject pageData = fpcjService.selectByGfshAndCjrq(pramsMap, curr, default_size);
boolean hasNext = pageData.getBooleanValue("hasNext");
List<FpcjCjhzRespVO> dataList = (List<FpcjCjhzRespVO>)pageData.get("datalist");
if(dataList.size() > 5000){
return "数据不能超过5000条";
}
boolean firstPage = false;
if (curr == default_curr) {
@ -243,7 +250,7 @@ public class FpcjhzExportThread extends BaseThread {
// 写入当前页数据
ExcelPoiUtil.exportListArrayToExcel1(excelFile, title, jsonObject, dataList, firstPage, false);
// 更新页数
return cicleExport(pramsMap, nextPage, excelFile, jsonObject);
cicleExport(pramsMap, nextPage, excelFile, jsonObject);
} else {
// 写入最后一页数据
FpcjCjhzRespVO vo = new FpcjCjhzRespVO();
@ -253,7 +260,7 @@ public class FpcjhzExportThread extends BaseThread {
vo.setSe(hjse);
dataList.add(vo);
ExcelPoiUtil.exportListArrayToExcel1(excelFile, title, jsonObject, dataList, firstPage, true);
return hasNext;
}
return "ok";
}
}

@ -181,6 +181,12 @@ public class PoolAddTaxThread extends BaseThread {
} else {
pramsMap.put("gfsh", gfshList);
}
boolean flag = checkList(gfshList);
if (flag){
pramsMap.put("sign","88");
log.info("登陆账号无税号");
}
if (cjksyf != null && !"".equals(cjksyf)) {
pramsMap.put("cjksyf", DateUtils.getMorning(DateUtils.strToDate(cjksyf)));
}
@ -468,4 +474,22 @@ public class PoolAddTaxThread extends BaseThread {
return filePath.toString();
}
public boolean checkList(List<String> list) {
boolean flag =false;
if (list == null || list.isEmpty()){
flag = true;
}else {
String s = list.toString().replace("[","").replace("]","");
if (StringHelper.isBlank(s)){
flag = true;
}
if (StringHelper.isNotBlank(s) && s.contains(",")){
String replace = s.replace(",", "");
if (StringHelper.isBlank(replace)){
flag = true;
}
}
}
return flag;
}
}

@ -186,6 +186,11 @@ public class PoolSaleThread extends BaseThread {
} else {
pramsMap.put("gfsh", gfshList);
}
boolean flag = checkList(gfshList);
if (flag){
pramsMap.put("sign","88");
log.info("登陆账号无税号");
}
if (cjksyf != null && !"".equals(cjksyf)) {
pramsMap.put("cjksyf", DateUtils.getMorning(DateUtils.strToDate(cjksyf)));
}
@ -468,4 +473,22 @@ public class PoolSaleThread extends BaseThread {
return filePath.toString();
}
public boolean checkList(List<String> list) {
boolean flag =false;
if (list == null || list.isEmpty()){
flag = true;
}else {
String s = list.toString().replace("[","").replace("]","");
if (StringHelper.isBlank(s)){
flag = true;
}
if (StringHelper.isNotBlank(s) && s.contains(",")){
String replace = s.replace(",", "");
if (StringHelper.isBlank(replace)){
flag = true;
}
}
}
return flag;
}
}

@ -293,10 +293,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
</if>
@ -400,10 +403,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.xf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.xf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
</if>
@ -547,7 +553,7 @@
from
${dxhyTertiary}.t_dx_record_invoice t
left JOIN ${dxhyDetail}.t_dx_record_invoice_detail b ON t.uuid = b.uuid
where t.detail_yesorno = '1'
where '1' = '1'
<if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
AND t.create_date BETWEEN #{cjksyf} and #{cjjsyf}
</if>
@ -559,10 +565,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
</if>
@ -657,7 +666,7 @@
from
${dxhyTertiary}.t_dx_sale_record_invoice t
left JOIN ${dxhyDetail}.t_dx_record_invoice_detail_sales b ON t.uuid = b.uuid
where t.detail_yesorno = '1'
where 1 = 1
<if test="cjksyf != null and cjksyf!= '' and cjjsyf != null and cjjsyf != ''">
AND t.create_date between #{cjksyf} and #{cjjsyf}
</if>
@ -669,10 +678,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.xf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.xf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
</if>

@ -100,7 +100,6 @@
and t.bdk_status in ('1','2')
and t.export_mark = '0'
and t.auth_status != '0'
and t.rzh_yesorno != '0'
and t.company = #{company}
<if test="sign !='88'">
and t.gf_tax_no in

@ -111,7 +111,7 @@
<dependency>
<groupId>com.dxhy.jxpt</groupId>
<artifactId>dxhy-oss</artifactId>
<version>3.2.9</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>

@ -107,7 +107,7 @@
<dependency>
<groupId>com.dxhy.jxpt</groupId>
<artifactId>dxhy-oss</artifactId>
<version>3.2.9</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>

@ -10,8 +10,6 @@ import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.FplxEnum;
import com.dxhy.common.enums.ReturnCodeEnum;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.util.DateOrderUtil;
import com.dxhy.common.util.StringHelper;
import com.dxhy.common.util.pojo.Authorize;
import com.dxhy.common.util.pojo.GlobalInfo;
import com.dxhy.erp.dao.*;
@ -21,11 +19,7 @@ import com.dxhy.erp.model.auth.InterfaceCode;
import com.dxhy.erp.service.InvoiceAuthService;
import com.dxhy.erp.service.TDxInvoiceReimburseService;
import com.dxhy.erp.utils.CheckUtils;
import com.dxhy.erp.utils.DateUtil;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -34,14 +28,12 @@ import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author dxhy
*/
@SuppressWarnings({"AlibabaMethodTooLong", "AlibabaUndefineMagicConstant"})
@Service
@Slf4j
public class InvoiceAuthServiceImpl extends MpBaseServiceImpl<RecordInvoiceDao, RecordInvoice>
implements InvoiceAuthService {
@ -347,19 +339,7 @@ public class InvoiceAuthServiceImpl extends MpBaseServiceImpl<RecordInvoiceDao,
fplxList.add("31");
fplxList.add("32");
for(ZDATA zdata1:zdata){
log.info("zdata1.getZFPHM()===>{}",zdata1.getZFPHM());
String collect = fplxList.stream().collect(Collectors.joining(","));
if(!collect.contains(convertFpzldm(zdata1.getZFPLX()))){
log.info("非增值税先不处理:{}",JSON.toJSONString(zdata1));
continue;
}
String fphm = zdata1.getZFPHM();
if (org.apache.commons.lang3.StringUtils.isNotBlank(fphm) && fphm.length() > 8 && !("26".equals(zdata1.getZFPLX()) || "27".equals(zdata1.getZFPLX()))){
fphm = fphm.replace(zdata1.getZFPDM(),"");
log.info("非全电但是号码");
}
log.info("发票号码{}",fphm);
String uuid = zdata1.getZFPDM()+fphm;
String uuid = zdata1.getZFPDM()+zdata1.getZFPHM();
zdata1.setZFPLX(convertFpzldm(zdata1.getZFPLX()));
TdxRecordInvoice recordInvoiceByUuid = tDxrecordInvoiceDao.getRecordInvoiceByUuid(uuid);
//查询票池
@ -381,21 +361,27 @@ public class InvoiceAuthServiceImpl extends MpBaseServiceImpl<RecordInvoiceDao,
for(ZDATA zdata1:zdata){
//成功或者失败标识
boolean flag = false;
log.info("zdata1.getZFPHM():{}",zdata1.getZFPHM());
String fphm = zdata1.getZFPHM();
if (org.apache.commons.lang3.StringUtils.isNotBlank(fphm) && fphm.length() > 8 && !("26".equals(zdata1.getZFPLX()) || "27".equals(zdata1.getZFPLX()))){
fphm = fphm.replace(zdata1.getZFPDM(),"");
log.info("非全电但是号码");
}
log.info("发票号码{}",fphm);
String uuid = zdata1.getZFPDM()+fphm;
String uuid = zdata1.getZFPDM()+zdata1.getZFPHM();
//销项标识
String xxbs = zdata1.getXXBS();
DynamicContextHolder.push("business"+DbConstant.BUSINESS_READ);
if(fplxList.contains(zdata1.getZFPLX()) && !"X".equalsIgnoreCase(xxbs)){
TdxRecordInvoice recordInvoiceByUuid = tDxrecordInvoiceDao.getRecordInvoiceByUuid(uuid);
if(recordInvoiceByUuid!=null){
UpdateWrapper updateWrapper = convertRecordInvoice(zdata1,uuid);
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("uuid",uuid);
//凭证号
updateWrapper.set("sn_voucher_number",zdata1.getBELNR());
//凭证过账日期
updateWrapper.set("posting_time",zdata1.getBUDAT());
//账期
updateWrapper.set("account_period",zdata1.getBUDAT().substring(0,7));
//报账单号
updateWrapper.set("bzdh",zdata1.getZBZDH());
//入账状态
updateWrapper.set("inaccount_status",zdata1.getZYWZT());
updateWrapper.set("comp_code",zdata1.getZGSDM());
updateWrapper.set("bzr",zdata1.getZJBRT());
DynamicContextHolder.push("business"+DbConstant.BUSINESS_WRITE);
int update = tDxrecordInvoiceDao.update(null, updateWrapper);
if(update>0){
@ -418,13 +404,34 @@ public class InvoiceAuthServiceImpl extends MpBaseServiceImpl<RecordInvoiceDao,
}
}
}else {
UpdateWrapper updateWrapper = convertRecordInvoice(zdata1,uuid);
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.eq("uuid",uuid);
//凭证号
updateWrapper.set("sn_voucher_number",zdata1.getBELNR());
//凭证过账日期
updateWrapper.set("posting_time",zdata1.getBUDAT());
//账期
updateWrapper.set("account_period",zdata1.getBUDAT().substring(0,7));
//报账单号
updateWrapper.set("bzdh",zdata1.getZBZDH());
//入账状态
updateWrapper.set("inaccount_status",zdata1.getZYWZT());
updateWrapper.set("comp_code",zdata1.getZGSDM());
updateWrapper.set("bzr",zdata1.getZJBRT());
DynamicContextHolder.push("business"+DbConstant.BUSINESS_WRITE);
tDxInvoiceReimburseService.getBaseMapper().update(null,updateWrapper);
}
if ("X".equalsIgnoreCase(xxbs)){
DynamicContextHolder.push("business"+DbConstant.BUSINESS_WRITE);
UpdateWrapper updateWrapper = convertRecordInvoice(zdata1,uuid);
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.set("sn_voucher_number",zdata1.getBELNR());
updateWrapper.set("posting_time",zdata1.getBUDAT());
updateWrapper.set("account_period",zdata1.getBUDAT().substring(0,7));
updateWrapper.set("bzdh",zdata1.getZBZDH());
updateWrapper.set("inaccount_status",zdata1.getZYWZT());
updateWrapper.set("comp_code",zdata1.getZGSDM());
updateWrapper.set("bzr",zdata1.getZJBRT());
updateWrapper.eq("uuid",uuid);
tdxSaleRecordInvoiceDao.update(null,updateWrapper);
}
@ -439,25 +446,6 @@ public class InvoiceAuthServiceImpl extends MpBaseServiceImpl<RecordInvoiceDao,
return es;
}
public UpdateWrapper convertRecordInvoice(ZDATA zdata,String uuid){
UpdateWrapper updateWrapper = new UpdateWrapper();
updateWrapper.set("sn_voucher_number",zdata.getBELNR());
try {
DateTime parse = DateTime.parse(zdata.getBUDAT());
updateWrapper.set("posting_time",zdata.getBUDAT());
//账期
updateWrapper.set("account_period",zdata.getBUDAT().substring(0,7));
} catch (Exception e) {
log.error("时间转换异常:{}",e);
}
updateWrapper.set("bzdh",zdata.getZBZDH());
updateWrapper.set("inaccount_status",zdata.getZYWZT());
updateWrapper.set("comp_code",zdata.getZGSDM());
updateWrapper.set("bzr",zdata.getZJBRT());
updateWrapper.eq("uuid",uuid);
return updateWrapper;
}
public ReturnStateInfo getCheckData(List<Map<String, Object>> authStateList, Integer contentRows) {
ReturnStateInfo run = new ReturnStateInfo();
if (contentRows == null || authStateList.size() != contentRows) {
@ -531,26 +519,9 @@ public class InvoiceAuthServiceImpl extends MpBaseServiceImpl<RecordInvoiceDao,
}
public static void main(String[] args) {
Date date = DateUtil.strToDate("0000-00-00");
DateTime parse1 = DateTime.parse("2012-12-01");
Date date11 = parse1.toDate();
HashMap<Object, Object> map = Maps.newHashMap();
map.put("1","3");
try {
DateTime parse = DateTime.parse("0000-00-00");
map.put("2","3");
Date date1 = parse.toDate();
String s = parse.toString("yyyy-MM-dd ");
System.out.println("");
} catch (Exception e) {
// throw new RuntimeException(e);
}
map.put("3","3");
System.out.println();
// String d="2023";
// String substring = d.substring(0, 7);
// System.out.println(substring);
String d="2023";
String substring = d.substring(0, 7);
System.out.println(substring);
}

@ -3,6 +3,7 @@ package com.dxhy.extend.controller;
import com.dxhy.common.aspect.SysLog;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.util.StringHelper;
import com.dxhy.common.util.UserInfoUtil;
import com.dxhy.common.utils.DateUtils;
import com.dxhy.common.utils.R;
@ -115,6 +116,25 @@ public class ExtFpzhcxController extends AbstractController {
}
pramsMap.put("gfsh", gfshList);
boolean flag = checkList(gfshList);
if (flag){
pramsMap.put("sign","88");
}else {
pramsMap.put("sign","99");
}
String companyCode = (String) pramsMap.get("companyCode");
if (org.apache.commons.lang3.StringUtils.isNotBlank(companyCode) && "99".equals(companyCode)){
pramsMap.put("companyCodes",getUserInfo().getCompanyCodes());
log.info("组织机构====>{}",pramsMap.get("companyCodes"));
}
if (StringUtils.isNotBlank(companyCode)){
pramsMap.put("companyCode",companyCode);
}else {
return ResponseEntity.ok(R.error("所属组织不能为空"));
}
if (pramsMap.get("kpksrq") != null && !"".equals(pramsMap.get("kpksrq"))) {
pramsMap.put("kpksrq", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("kpksrq").toString())));
}
@ -199,6 +219,25 @@ public class ExtFpzhcxController extends AbstractController {
}
public boolean checkList(List<String> list) {
boolean flag =false;
if (list == null || list.isEmpty()){
flag = true;
}else {
String s = list.toString().replace("[","").replace("]","");
if (StringHelper.isBlank(s)){
flag = true;
}
if (StringHelper.isNotBlank(s) && s.contains(",")){
String replace = s.replace(",", "");
if (StringHelper.isBlank(replace)){
flag = true;
}
}
}
return flag;
}
/**
* 报表异常发票查询
*

@ -66,9 +66,14 @@ public class ExtInvoicePoolController extends AbstractController {
// }
// }
gfshList = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
if (gfshList.size() == 0) {
return ResponseEntity.ok(R.ok().put("data", ""));
boolean flag = checkList(gfshList);
if (flag){
pramsMap.put("sign","88");
log.info("登陆账号无税号");
}
// if (gfshList.size() == 0) {
// return ResponseEntity.ok(R.ok().put("data", ""));
// }
pramsMap.put("gfsh", gfshList);
if (pramsMap.get("cjksyf") != null && !"".equals(pramsMap.get("cjksyf"))) {
pramsMap.put("cjksyf", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("cjksyf").toString())));
@ -219,10 +224,16 @@ public class ExtInvoicePoolController extends AbstractController {
// return ResponseEntity.ok(R.ok().put("data", ""));
// }
// }
gfshList = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
if (gfshList.size() == 0) {
return ResponseEntity.ok(R.ok().put("data", ""));
}
boolean flag = checkList(gfshList);
if (flag){
pramsMap.put("sign","88");
log.info("登陆账号无税号");
}
// if (gfshList.size() == 0) {
// return ResponseEntity.ok(R.ok().put("data", ""));
// }
pramsMap.put("taxno", gfshList);
if (pramsMap.get("cjksyf") != null && !"".equals(pramsMap.get("cjksyf"))) {
pramsMap.put("cjksyf", DateUtils.getMorning(DateUtils.strToDate(pramsMap.get("cjksyf").toString())));
@ -327,4 +338,22 @@ public class ExtInvoicePoolController extends AbstractController {
System.out.println(replace);
}
}
public boolean checkList(List<String> list) {
boolean flag =false;
if (list == null || list.isEmpty()){
flag = true;
}else {
String s = list.toString().replace("[","").replace("]","");
if (StringHelper.isBlank(s)){
flag = true;
}
if (StringHelper.isNotBlank(s) && s.contains(",")){
String replace = s.replace(",", "");
if (StringHelper.isBlank(replace)){
flag = true;
}
}
}
return flag;
}
}

@ -69,11 +69,30 @@
t.settlement_no,t.inaccount_status,t.bzdh,
t.settlement_status,t.voucher_number,t.total_amount,t.sn_voucher_number,t.posting_time,t.image_id,t.account_period
from t_dx_record_invoice t
WHERE t.company = #{company} and t.invoice_date between #{kpksrq} and #{kpjsrq}
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
WHERE t.company = #{company}
and t.invoice_date between #{kpksrq} and #{kpjsrq}
<if test="sign != '88'">
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
and (t.comp_code in
<foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
#{companyCode}
</foreach>
or t.comp_code is null or t.comp_code = ''
)
</if>
<if test="companyCode != null and companyCode != '99' and companyCode != '88' and companyCode != '' and companyCode != 'null'" >
and t.comp_code = #{companyCode}
</if>
<if test="companyCode != null and companyCode != '' and companyCode == '88'">
and (t.comp_code = '' or t.comp_code is null)
</if>
<if test="bzdh != null and bzdh != '' and bzdh != 'null'">
and t.bzdh = #{bzdh}
</if>
@ -331,10 +350,29 @@
select count(1) hjsl,sum(t.invoice_amount)hjje,sum(t.tax_amount)hjse
from t_dx_record_invoice t
where t.invoice_date between #{kpksrq} and #{kpjsrq}
and t.company = #{company} and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
and t.company = #{company}
<if test="sign != '88'">
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="companyCode != null and companyCode != '' and companyCode != 'null' and companyCode == '99'">
and (t.comp_code in
<foreach collection="companyCodes" index="index" item="companyCode" separator="," open="(" close=")">
#{companyCode}
</foreach>
or t.comp_code is null or t.comp_code = ''
)
</if>
<if test="companyCode != null and companyCode != '99' and companyCode != '88' and companyCode != '' and companyCode != 'null'" >
and t.comp_code = #{companyCode}
</if>
<if test="companyCode != null and companyCode != '' and companyCode == '88'">
and (t.comp_code = '' or t.comp_code is null)
</if>
<if
test="invoiceStatus != null and invoiceStatus != '' and invoiceStatus != 'null' and invoiceStatus != '99'">
and t.invoice_status = #{invoiceStatus}

@ -182,7 +182,7 @@
where t.invoice_status != '0'
and t.invoice_type in ('01','03','08','14','31')
and t.company = #{company}
and DATE_FORMAT(t.invoice_date,'%Y-%m-%d') between #{kpksrq} and #{kpjsrq}
and t.invoice_date between #{kpksrq} and #{kpjsrq}
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}

@ -69,10 +69,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
</if>
@ -218,10 +221,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.gf_tax_no in
<foreach collection="gfsh" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
</if>
@ -506,10 +512,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.xf_tax_no in
<foreach collection="taxno" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.xf_tax_no in
<foreach collection="taxno" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if
test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}
@ -617,10 +626,13 @@
like
CONCAT('%',#{keyWord},'%')
</if>
and t.xf_tax_no in
<foreach collection="taxno" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
<if test="sign != '88'">
and t.xf_tax_no in
<foreach collection="taxno" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if
test="invoiceType != null and invoiceType != '' and invoiceType != 'null' and invoiceType != '99' ">
and t.invoice_type = #{invoiceType}

@ -13,8 +13,10 @@
select count(1) totalCount, ifnull(sum(invoice_amount), 0) totalAmount,
ifnull(sum(dk_tax_amount), 0) totalTax
FROM t_dx_record_invoice
WHERE valid='1' and invoice_type in ('01','03','08','14') AND invoice_status='0' AND
rzh_yesorno='1'
WHERE valid='1'
and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and t.lq_tdyslxDm='08'))
AND invoice_status='0'
AND rzh_yesorno='1'
<if test="skssq !=null and skssq != ''">
and rzh_belong_date = #{skssq}
</if>
@ -54,9 +56,11 @@
<select id="getTotalOutTax" resultType="Double" databaseId="mysql">
SELECT ifnull(sum(out_tax_amount), 0) FROM t_dx_record_invoice
WHERE valid='1' and invoice_type in ('01','03','08','14') AND invoice_status='0' AND
rzh_yesorno='1' AND
out_status in ('1','2')
WHERE valid='1'
and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and t.lq_tdyslxDm='08'))
AND invoice_status='0'
AND rzh_yesorno='1'
AND out_status in ('1','2')
<if test="skssq !=null and skssq != ''">
and out_belong_date = #{skssq}
</if>
@ -69,9 +73,11 @@
out_reason rzhDate,
ifnull(sum(out_tax_amount), 0) tax
FROM t_dx_record_invoice
WHERE valid='1' and invoice_type in ('01','03','08','14') AND invoice_status='0' AND
rzh_yesorno='1' AND
out_status in ('1','2')
WHERE valid='1'
and (invoice_type in('01','03','08','14','31','283','161','183','185') or (invoice_type ='32' and t.lq_tdyslxDm='08'))
AND invoice_status='0'
AND rzh_yesorno='1'
AND out_status in ('1','2')
<if test="skssq !=null and skssq != ''">
and out_belong_date = #{skssq}
</if>

@ -0,0 +1 @@
README

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.dxhy</groupId>
<artifactId>ofd</artifactId>
<version>3.2.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.dxhy.jxpt</groupId>
<artifactId>dxhy-oss</artifactId>
<version>3.3.3</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.13.2</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.12.131</version>
</dependency>
<!-- ftp -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<!-- 使用commons-pool2 实现ftp连接池 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- minio 存储依赖 -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>releases</id>
<name>releases</name>
<url>http://10.1.20.6:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>snapshots</name>
<url>http://10.1.20.6:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>大象慧云</id>
<name>Public Repositories</name>
<url>http://10.1.20.6:8081/nexus/content/groups/public/</url>
</repository>
<repository>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,154 @@
package com.dxhy.oss.config;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.jcraft.jsch.ChannelSftp;
import lombok.Data;
/**
* @author jiaohongyang
*/
@Component
@Data
public class OssConfig {
/**
* oss 服务类型 JD AL FTP
*/
@Value("${oss.ossType:FTP}")
public String ossType;
/**
* 阿里请求地址
*/
@Value("${oss.endpointUrl:}")
public String endpointUrl;
/**
* 访问密钥
*/
@Value("${oss.accessKeyId:}")
public String accessKeyId;
/**
* 访问密钥
*/
@Value("${oss.accessKeySecret:}")
public String accessKeySecret;
/**
* 京东云地域
*/
@Value("${oss.region:}")
public String region;
/**
* 实例
*/
@Value("${oss.bucketName:}")
public String bucketName;
/**
* ftp上传的根路径
*/
@Value("${ftp.connection.pathPrefix:}")
public String pathPrefix;
/**
* ftp服务器地址
*/
@Value("${ftp.connection.hostname:}")
public String hostname;
/**
* ftp服务器端口
*/
@Value("${ftp.connection.port:62236}")
public String port;
/**
* ftp登录密码
*/
@Value("${ftp.connection.password:}")
public String password;
@Value("${ftp.connection.timeout:6000}")
public String timeout;
/**
* ftp登录账号
*/
@Value("${ftp.connection.username:}")
public String username;
@Value("${ftp.connection.localPathDefault:}")
public String localPathDefault;
/**
* 临时路径
*/
@Value("${ftp.connection.tempPath:}")
public String tempPath;
/**
* ftp配置信息
*/
@Value("${ftp.connection.size:2}")
public String pdfSize;
/**
* 图片的最大大小
*/
@Value("${oss.imageSize:10485760}")
public long imageSize;
/**
* 其他文件的最大大小
*/
@Value("${oss.fileSize:1073741824}")
public long fileSize;
private Pool pool = new Pool();
public static class Pool extends GenericObjectPoolConfig<ChannelSftp> {
private int maxTotal = DEFAULT_MAX_TOTAL;
private int maxIdle = DEFAULT_MAX_IDLE;
private int minIdle = DEFAULT_MIN_IDLE;
public Pool() {
super();
}
@Override
public int getMaxTotal() {
return maxTotal;
}
@Override
public void setMaxTotal(int maxTotal) {
this.maxTotal = maxTotal;
}
@Override
public int getMaxIdle() {
return maxIdle;
}
@Override
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}
@Override
public int getMinIdle() {
return minIdle;
}
@Override
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
}
}

@ -0,0 +1,27 @@
package com.dxhy.oss.config;
/**
* @author jiaohongyang焦红阳
* @date 2020-09-30
*/
public interface OssReturnConfig {
String SUCCESS = "000000";
String ERROR_01 = "000001";
String ERROR_09 = "999999";
String JD = "JD";
String AL = "AL";
String FTP = "FTP";
String SSH = "SSH";
String LOCAL = "LOCAL";
String TOS = "TOS";
String MINIO = "MINIO";
}

@ -0,0 +1,19 @@
package com.dxhy.oss.model;
import lombok.Data;
/**
* @author jiaohongyang焦红阳
* @date 2020-10-17
*/
@Data
public class FileModel {
/**
* 编码
*/
private String code;
/**
* 文件地址
*/
private String filePath;
}

@ -0,0 +1,41 @@
package com.dxhy.oss.service;
import com.dxhy.oss.model.FileModel;
/**
* @author jiaohongyang
*/
public interface AliOssService {
/**
* 阿里云OSS文件存储
*
* @param file 文件
* @return 返回
*/
FileModel uploadFile(String fileName, String file);
/**
* 下载
*
* @param fileName 文件名称
* @param filePath 本地文件存储地址
* @return 返回
*/
FileModel downloadFile(String fileName, String filePath);
/**
* 删除文件
*
* @param file 文件名
* @return 返回
*/
FileModel deleteFile(String file);
/**
* 生产文件下载地址
*
* @param key 文件传输路径加名称
* @return 返回下载地址
*/
FileModel getUrl(String key);
}

@ -0,0 +1,72 @@
package com.dxhy.oss.service;
import com.dxhy.oss.model.FileModel;
/**
* @author jiaohongyang
*/
public interface FileService {
/**
* 文件上传
*
* @param fileName 文件 ftp名称
* @param originFileName 本地文件地址
* @return 返回
* @throws Exception 异常
*/
FileModel uploadFile(String fileName, String originFileName) throws Exception;
/**
* 文件下载
*
* @param downloadFile 下载文件
* @param saveFile 保存文件地址
* @return 返回
* @throws Exception 异常
*/
FileModel downFile(String downloadFile, String saveFile) throws Exception;
/**
* 生成文件下载地址
*
* @param key 文件传输路径加名称
* @return 返回文件下载地址
*/
FileModel getUrl(String key);
/**
* 删除文件
*
* @param file 文件地址
* @return 返回
*/
FileModel deleteFile(String file);
/**
* 获取ftp 上传地址
*
* @return 返回
*/
String getPathPrefix();
/**
* 图片本地地址
*
* @return 返回
*/
String getLocalPathDefault();
/**
* 临时路径
*/
String getTempPath();
/**
* PDF 上传文件大小
*/
String getFtpPdfSize();
}

@ -0,0 +1,275 @@
package com.dxhy.oss.service;
import com.dxhy.oss.utils.SftpPool;
import com.dxhy.oss.utils.SftpPoolException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.springframework.stereotype.Service;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class FtpService {
private final SftpPool pool;
public FtpService(SftpPool pool) {
this.pool = pool;
}
/**
* ftp上传文件
*
* @param serviceDec
* @param fileName
* @param localDec 本地目录
* @return
*/
public boolean uploadFile( String serviceDec, String fileName, String localDec) throws InterruptedException {
FTPClient ftpClient = null;
InputStream inputStream = null;
boolean result =true;
try {
inputStream = new FileInputStream(new File(localDec));
log.info("开始上传文件");
ftpClient = pool.borrowObject();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
createDirecroty(ftpClient, serviceDec);
ftpClient.makeDirectory(serviceDec);
ftpClient.changeWorkingDirectory(serviceDec);
ftpClient.storeFile(fileName, inputStream);
inputStream.close();
ftpClient.logout();
log.info("上传文件成功");
} catch (Exception e) {
e.printStackTrace();
log.error("上传文件失败" + e);
result =false;
} finally {
try {
log.info("回收线程");
pool.returnObject(ftpClient);
if (null != inputStream) {
inputStream.close();
}
} catch (IOException e) {
log.error("上传文件失败" + e);
result =false;
}
}
return result;
}
public boolean deleteFile(String directory, String deleteFile) {
FTPClient ftpClient = null;
try {
ftpClient = pool.borrowObject();
return ftpClient.deleteFile(directory + File.separator + deleteFile);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (ftpClient != null) {
log.info("回收线程");
pool.returnObject(ftpClient);
}
}
}
private static boolean createDirecroty(FTPClient ftpClient, String remote) throws IOException {
boolean success = true;
String directory = remote + "/";
// 如果远程目录不存在,则递归创建远程服务器目录
if (!directory.equalsIgnoreCase("/") && !changeWorkingDirectory(ftpClient, new String(directory))) {
int start = 0;
int end = 0;
if (directory.startsWith("/")) {
start = 1;
} else {
start = 0;
}
end = directory.indexOf("/", start);
String path = "";
String paths = "";
while (true) {
String subDirectory = new String(remote.substring(start, end).getBytes("GBK"), "iso-8859-1");
path = path + "/" + subDirectory;
if (!existFile(ftpClient, path)) {
if (makeDirectory(ftpClient, subDirectory)) {
changeWorkingDirectory(ftpClient, subDirectory);
} else {
log.info("创建目录[" + subDirectory + "]失败");
changeWorkingDirectory(ftpClient, subDirectory);
}
} else {
changeWorkingDirectory(ftpClient, subDirectory);
}
paths = paths + "/" + subDirectory;
start = end + 1;
end = directory.indexOf("/", start);
// 检查所有目录是否创建完毕
if (end <= start) {
break;
}
}
}
return success;
}
//改变目录路径
private static boolean changeWorkingDirectory(FTPClient ftpClient, String directory) {
boolean flag = true;
try {
flag = ftpClient.changeWorkingDirectory(directory);
if (flag) {
log.info("进入文件夹" + directory + " 成功!");
} else {
log.info("进入文件夹" + directory + " 失败!开始创建文件夹");
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
return flag;
}
//判断ftp服务器文件是否存在
private static boolean existFile(FTPClient ftpClient, String path) throws IOException {
boolean flag = false;
FTPFile[] ftpFileArr = ftpClient.listFiles(path);
if (ftpFileArr.length > 0) {
flag = true;
}
return flag;
}
//创建目录
private static boolean makeDirectory(FTPClient ftpClient, String dir) {
boolean flag = true;
try {
flag = ftpClient.makeDirectory(dir);
if (flag) {
log.info("创建文件夹" + dir + " 成功!");
} else {
log.info("创建文件夹" + dir + " 失败!");
}
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
/**
* 获取FTP某一特定目录下的所有文件名称
*
* @param ftpClient 已经登陆成功的FTPClient
* @param ftpDirPath FTP上的目标文件路径
*/
public static List getFileNameList(FTPClient ftpClient, String ftpDirPath) {
List list = new ArrayList();
try {
if (ftpDirPath.startsWith("/") && ftpDirPath.endsWith("/")) {
// 通过提供的文件路径获取FTPFile对象列表
FTPFile[] files = ftpClient.listFiles(ftpDirPath);
// 遍历文件列表,打印出文件名称
for (int i = 0; i < files.length; i++) {
FTPFile ftpFile = files[i];
// 此处只打印文件,未遍历子目录(如果需要遍历,加上递归逻辑即可)
if (ftpFile.isFile()) {
// log.info(ftpDirPath + ftpFile.getName());
list.add(ftpFile.getName());
}
}
log.info("当前FTP路径可用");
} else {
log.info("当前FTP路径不可用");
}
} catch (IOException e) {
log.error("错误" + e);
}
return list;
}
/**
* @param servicePath ftp的路径
* @param fileName 文件名称
* @param localFilePath 下载到本地的文件夹
* @return
*/
public boolean downloadFile(String servicePath, String fileName, String localFilePath) {
FTPClient ftpClient;
try {
ftpClient = pool.borrowObject();
String name = dowFile(ftpClient, servicePath, fileName, localFilePath);
if (name != null && !name.equals("")){
return true;
}
} catch (SftpPoolException e) {
e.printStackTrace();
}
return false;
}
/**
*
* @param ftpClient
* @param servicePath ftp的路径
* @param fileName 文件名称
* @param localFilePath 下载到本地的文件夹
* @return
*/
private static String dowFile(FTPClient ftpClient, String servicePath, String fileName, String localFilePath) {
InputStream is = null;
FileOutputStream fos = null;
try {
ftpClient.enterLocalPassiveMode();
is = ftpClient.retrieveFileStream(servicePath + fileName);// 获取ftp上的文件
directoryIsExists(localFilePath);
fos = new FileOutputStream(new File(localFilePath + fileName));
// 文件读取方式一
int i;
byte[] bytes = new byte[1024];
while ((i = is.read(bytes)) != -1) {
fos.write(bytes, 0, i);
}
ftpClient.completePendingCommand();
log.info("FTP文件下载成功!");
} catch (Exception e) {
log.error("FTP文件下载失败!" + e);
} finally {
try {
if (fos != null) {fos.close();}
if (is != null) {is.close();}
} catch (IOException e) {
log.error("下载流关闭失败" + e);
return null;
}
}
return localFilePath + fileName;
}
public static void directoryIsExists(String path) {
File directory = new File(path);
if (directory.exists()) {
return;
}
if (!directory.mkdir()) {
return;
}
if (directory.canWrite()) {
return;
}
boolean setWritable = directory.setWritable(true);
log.info("是否创建文件 directoryIsExists :{} ", setWritable);
}
}

@ -0,0 +1,46 @@
package com.dxhy.oss.service;
import com.dxhy.oss.model.FileModel;
/**
* @author jiaohongyang
*/
public interface JdOssService {
/**
* 阿里云OSS文件存储
*
* @param file
* 文件
* @return 返回
*/
FileModel uploadFile(String fileName, String file);
/**
* 下载
*
* @param fileName
* 文件名称
* @param filePath
* 本地文件存储地址
* @return 返回
*/
FileModel downloadFile(String fileName, String filePath);
/**
* 生成文件下载地址
*
* @param key
* 文件传输路径加名称
* @return 返回文件下载地址
*/
FileModel getUrl(String key);
/**
* 删除文件
*
* @param file
* 文件信息
* @return 返回
*/
FileModel deleteFile(String file);
}

@ -0,0 +1,165 @@
package com.dxhy.oss.service;
import cn.hutool.core.io.FileUtil;
import com.dxhy.oss.utils.SshPool;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
/**
* @author jiaohongyang
*/
@Slf4j
public class SshService {
private final SshPool pool;
public SshService(SshPool pool) {
this.pool = pool;
}
/**
* 将输入流的数据上传到sftp作为文件文件完整路径 = basePath+directory
*
* @param pathName ftp服务保存地址完整路径
* @param fileName 上传到ftp的文件名
* @param originFileName 待上传文件的名称绝对地址
*/
public boolean uploadFile(String pathName, String fileName, String originFileName) {
log.info("开始上传文件");
ChannelSftp sftp = null;
InputStream inputStream;
try {
sftp = pool.borrowObject();
try {
sftp.cd(pathName);
} catch (SftpException e) {
// 目录不存在,则创建文件夹
String[] dirs = pathName.split("/");
String tempPath = "";
for (String dir : dirs) {
if (null == dir || "".equals(dir)) {
continue;
}
tempPath += "/" + dir;
try {
sftp.cd(tempPath);
} catch (SftpException ex) {
try {
sftp.mkdir(tempPath);
sftp.cd(tempPath);
} catch (SftpException e1) {
e1.printStackTrace();
}
}
}
}
File orgFile = new File(originFileName);
inputStream = Files.newInputStream(orgFile.toPath());
sftp.put(inputStream, fileName);
inputStream.close();
// 删除本地文件,防止服务器空间不足
FileUtil.del(orgFile);
log.info("上传文件成功");
return true;
} catch (Exception e) {
e.printStackTrace();
log.info("上传文件失败");
return false;
} finally {
if (sftp != null) {
log.info("回收线程");
pool.returnObject(sftp);
}
}
}
public boolean downloadFile(String directory, String downloadFile, String saveFile) {
log.info("开始下载文件!");
ChannelSftp sftp = null;
try {
sftp = pool.borrowObject();
if (directory != null && !"".equals(directory)) {
sftp.cd(directory);
}
String file = saveFile + "/" + downloadFile;
File fileLocal = new File(file);
if (fileLocal.exists()) {
boolean delete = fileLocal.delete();
log.info("删除本地路径文件:{}", delete);
}
this.directoryIsExists(saveFile);
sftp.get(downloadFile, file);
log.info("下载文件成功!");
return true;
} catch (Exception e) {
e.printStackTrace();
log.info("下载文件失败!");
return false;
} finally {
if (sftp != null) {
log.info("回收线程");
pool.returnObject(sftp);
}
}
}
/**
* 删除文件
*
* @param directory 要删除文件所在目录
* @param deleteFile 要删除的文件
* @return 返回是否删除成功
*/
public boolean deleteFile(String directory, String deleteFile) {
ChannelSftp sftp = null;
try {
sftp = pool.borrowObject();
sftp.cd(directory);
sftp.rm(deleteFile);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (sftp != null) {
log.info("回收线程");
pool.returnObject(sftp);
}
}
}
public void directoryIsExists(String path) {
File directory = new File(path);
if (directory.exists()) {
return;
}
if (!directory.mkdir()) {
return;
}
if (directory.canWrite()) {
return;
}
boolean setWritable = directory.setWritable(true);
log.info("是否创建文件 directoryIsExists :{} ", setWritable);
}
}

@ -0,0 +1,186 @@
package com.dxhy.oss.service.impl;
import cn.hutool.core.io.FileUtil;
import com.aliyun.oss.OSS;
import com.aliyun.oss.model.GetObjectRequest;
import com.dxhy.oss.config.OssConfig;
import com.dxhy.oss.config.OssReturnConfig;
import com.dxhy.oss.model.FileModel;
import com.dxhy.oss.service.AliOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.net.URL;
import java.util.Date;
/**
* @author jiaohongyang
*/
@Service("aliOssService")
@Slf4j
public class AliOssServiceImpl implements AliOssService {
private final OssConfig ossConfig;
@Autowired
public AliOssServiceImpl(OssConfig ossConfig) {
this.ossConfig = ossConfig;
}
/**
* 阿里云OSS文件存储
*
* @param filePath 文件
* @return 返回
*/
@Override
public FileModel uploadFile(String fileName, String filePath) {
OSS ossClient = null;
FileModel fileModel;
log.info("文件存储阿里OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), fileName);
try {
// 创建连接
ossClient =
OssClientFactory.getInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
if (ossClient == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
// 进行文件上传
ossClient.putObject(ossConfig.getBucketName(), fileName, new File(filePath));
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
fileModel.setFilePath(fileName);
return fileModel;
} catch (Exception e) {
log.error("文件存储阿里OSS失败,异常:{}", e.getMessage());
e.printStackTrace();
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
FileUtil.del(filePath);
}
}
@Override
public FileModel getUrl(String key) {
OSS ossClient = null;
FileModel fileModel;
try {
ossClient =
OssClientFactory.getInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
if (ossClient == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
// 设置URL过期时间为10年 3600l* 1000*24*365*10
Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24);
// 生成URL
URL url = ossClient.generatePresignedUrl(ossConfig.getBucketName(), key, expiration);
if (url != null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
fileModel.setFilePath(url.toString());
return fileModel;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
/**
* 下载
*
* @param fileName 文件名称
* @param filePath 本地文件存储地址
* @return 返回
*/
@Override
public FileModel downloadFile(String fileName, String filePath) {
log.info("下载文件阿里OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), fileName);
OSS ossClient = null;
FileModel fileModel;
try {
// 创建连接
ossClient =
OssClientFactory.getInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
if (ossClient == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
ossClient.getObject(new GetObjectRequest(ossConfig.getBucketName(), fileName), new File(filePath));
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
fileModel.setFilePath(filePath);
return fileModel;
} catch (Exception e) {
log.error("文件下载阿里OSS失败,异常:{}", e.getMessage());
e.printStackTrace();
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
/**
* 删除文件
*
* @param file 文件名
* @return 返回
*/
@Override
public FileModel deleteFile(String file) {
log.info("文件删除阿里OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), file);
OSS ossClient = null;
FileModel fileModel;
try {
// 创建连接
ossClient =
OssClientFactory.getInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
if (ossClient == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
ossClient.deleteObject(ossConfig.getBucketName(), file);
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
return fileModel;
} catch (Exception e) {
log.error("文件删除阿里OSS失败,异常:{}", e.getMessage());
e.printStackTrace();
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}

@ -0,0 +1,328 @@
package com.dxhy.oss.service.impl;
import cn.hutool.core.io.FileUtil;
import com.dxhy.oss.config.OssConfig;
import com.dxhy.oss.config.OssReturnConfig;
import com.dxhy.oss.model.FileModel;
import com.dxhy.oss.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author jiaohongyang
*/
@Slf4j
@Service("fileService")
public class FileServiceImpl implements FileService {
private final OssConfig ossConfig;
private final AliOssService aliOssService;
private final JdOssService jdOssService;
private final FtpService ftpService;
private final SshService sshService;
@Autowired
public FileServiceImpl(OssConfig ossConfig, AliOssService aliOssService, JdOssService jdOssService, FtpService ftpService, SshService sshService) {
this.ossConfig = ossConfig;
this.aliOssService = aliOssService;
this.jdOssService = jdOssService;
this.ftpService = ftpService;
this.sshService = sshService;
}
/**
* 文件上传
*
* @param fileName 上传文件路径+ 名称
* @param originFileName 本地文件地址
* @return 返回
* @throws Exception 异常
*/
@Override
public FileModel uploadFile(String fileName, String originFileName) {
log.info("上传文件地址:{} , 本地存储文件地址:{}", fileName, originFileName);
FileModel fileModel;
if (OssReturnConfig.AL.equals(ossConfig.getOssType())) {
if (fileName.startsWith("/")) {
fileName = fileName.substring(1);
}
fileModel = aliOssService.uploadFile(fileName, originFileName);
} else if (OssReturnConfig.JD.equals(ossConfig.getOssType())) {
if (fileName.startsWith("/")) {
fileName = fileName.substring(1);
}
fileModel = jdOssService.uploadFile(fileName, originFileName);
} else if (OssReturnConfig.SSH.equals(ossConfig.getOssType())){
if (!fileName.startsWith("/")) {
fileName = "/" + fileName;
}
String directory = fileName.substring(0, fileName.lastIndexOf("/"));
File directoryFile = new File(fileName);
String downloadFileName = directoryFile.getName();
boolean b = sshService.uploadFile(directory, downloadFileName, originFileName);
fileModel = new FileModel();
fileModel.setFilePath(fileName);
if (b) {
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel.setCode(OssReturnConfig.ERROR_09);
}
}else if (OssReturnConfig.FTP.equals(ossConfig.getOssType())) {
if (!fileName.startsWith("/")) {
fileName = "/" + fileName;
}
String directory = fileName.substring(0, fileName.lastIndexOf("/"));
File directoryFile = new File(fileName);
String downloadFileName = directoryFile.getName();
boolean b = false;
try {
b = ftpService.uploadFile(directory, downloadFileName, originFileName);
} catch (InterruptedException e) {
log.error(e.getMessage());
}
fileModel = new FileModel();
fileModel.setFilePath(fileName);
if (b) {
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel.setCode(OssReturnConfig.ERROR_09);
}
} else if(OssReturnConfig.LOCAL.equals(ossConfig.getOssType())){
//创建目录
boolean b = false;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
File directory = new File(fileName.substring(0, fileName.lastIndexOf("/")));
if(!directory.exists()){
directory.mkdirs();
}
File sourceFile = new File(originFileName);
File file = new File(fileName);
if(!file.exists()){
file.createNewFile();
}
fis = new FileInputStream(sourceFile);
fos = new FileOutputStream(file);
//复制文件
byte[] bytes = new byte[1024];
while (fis.read(bytes) != -1){
fos.write(bytes);
}
fos.flush();
b = true;
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
if(fis != null){fis.close();}
if(fos != null){fos.close();}
} catch (IOException e) {
log.error("上传文件关闭文件流异常:{}",e.getMessage());
}
}
fileModel = new FileModel();
fileModel.setFilePath(fileName);
if (b) {
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel.setCode(OssReturnConfig.ERROR_09);
}
} else {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
}
log.info("文件上传结果编码:{},地址信息返回:{}", fileModel.getCode(), fileModel.getFilePath());
return fileModel;
}
/**
*
* @param downloadFile 下载文件 服务器路径
* @param saveFile 保存文件地址 本地路劲
* @return
*/
@Override
public FileModel downFile(String downloadFile, String saveFile) {
log.info("下载文件地址:{} , 本地存储文件地址:{}", downloadFile, saveFile);
// 获取下载文件存储路径 ,路径不存在则创建路径
File file = new File(saveFile);
String path = file.getParent();
FileUtil.mkdir(path);
FileModel fileModel;
if (OssReturnConfig.AL.equals(ossConfig.getOssType())) {
if (downloadFile.startsWith("/")) {
downloadFile = downloadFile.substring(1);
}
fileModel = aliOssService.downloadFile(downloadFile, saveFile);
} else if (OssReturnConfig.JD.equals(ossConfig.getOssType())) {
if (downloadFile.startsWith("/")) {
downloadFile = downloadFile.substring(1);
}
fileModel = jdOssService.downloadFile(downloadFile, saveFile);
} else if(OssReturnConfig.SSH.equals(ossConfig.getOssType())){
String directory = downloadFile.substring(0, downloadFile.lastIndexOf("/"));
String downloadFileName = downloadFile.substring(downloadFile.lastIndexOf("/") + 1);
boolean b = sshService.downloadFile(directory, downloadFileName, path);
fileModel = new FileModel();
fileModel.setFilePath(saveFile);
if (b) {
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel.setCode(OssReturnConfig.ERROR_09);
}
}else if (OssReturnConfig.FTP.equals(ossConfig.getOssType())) {
String directory = downloadFile.substring(0, downloadFile.lastIndexOf("/"));
File directoryFile = new File(downloadFile);
String downloadFileName = directoryFile.getName();
boolean b = ftpService.downloadFile(directory, downloadFileName, path);
fileModel = new FileModel();
fileModel.setFilePath(saveFile);
if (b) {
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel.setCode(OssReturnConfig.ERROR_09);
}
} else if(OssReturnConfig.LOCAL.equals(ossConfig.getOssType())){
//创建目录
boolean b = false;
FileInputStream fis = null;
FileOutputStream fos = null;
try {
File download = new File(downloadFile);
fis = new FileInputStream(download);
fos = new FileOutputStream(file);
//复制文件
byte[] bytes = new byte[1024];
while (fis.read(bytes) != -1){
fos.write(bytes);
}
fos.flush();
b = true;
} catch (IOException e) {
log.error("本地导出异常:{}",e);
}finally {
try {
if(fis != null){fis.close();}
if(fos != null){fos.close();}
} catch (IOException e) {
log.error("上传文件关闭文件流异常:{}",e.getMessage());
}
}
fileModel = new FileModel();
fileModel.setFilePath(saveFile);
if (b) {
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel.setCode(OssReturnConfig.ERROR_09);
}
} else {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
}
log.info("文件下载结果编码:{},地址信息返回:{}", fileModel.getCode(), fileModel.getFilePath());
return fileModel;
}
@Override
public FileModel getUrl(String key) {
FileModel fileModel;
log.info("生成文件下载地址:{} ", key);
if (OssReturnConfig.AL.equals(ossConfig.getOssType())) {
fileModel = aliOssService.getUrl(key);
} else if (OssReturnConfig.JD.equals(ossConfig.getOssType())) {
fileModel = jdOssService.getUrl(key);
} else {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
}
log.info("生成文件下载地址结果编码:{},地址链接返回:{}", fileModel.getCode(), fileModel.getFilePath());
return fileModel;
}
@Override
public FileModel deleteFile(String path) {
log.info("删除文件信息:{} ", path);
FileModel fileModel;
if (OssReturnConfig.AL.equals(ossConfig.getOssType())) {
if (path.startsWith("/")) {
path = path.substring(1);
}
fileModel = aliOssService.deleteFile(path);
} else if (OssReturnConfig.JD.equals(ossConfig.getOssType())) {
if (path.startsWith("/")) {
path = path.substring(1);
}
fileModel = jdOssService.deleteFile(path);
} else if(OssReturnConfig.SSH.equals(ossConfig.getOssType())){
File file = new File(path);
boolean b = sshService.deleteFile(file.getParent(), file.getName());
if (b) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_01);
}
}else if (OssReturnConfig.FTP.equals(ossConfig.getOssType())) {
File file = new File(path);
boolean b = ftpService.deleteFile(file.getParent(), file.getName());
if (b) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_01);
}
} else if(OssReturnConfig.LOCAL.equals(ossConfig.getOssType())){
File file = new File(path);
boolean b = file.delete();
if (b) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
} else {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_01);
}
}else{
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
}
log.info("删除文件信息返回结果编码:{}", fileModel.getCode());
return fileModel;
}
@Override
public String getPathPrefix() {
return ossConfig.getPathPrefix();
}
@Override
public String getLocalPathDefault() {
return ossConfig.getLocalPathDefault();
}
@Override
public String getTempPath() {
return ossConfig.getTempPath();
}
/**
* PDF 上传文件大小
*/
@Override
public String getFtpPdfSize() {
return ossConfig.getPdfSize();
}
}

@ -0,0 +1,213 @@
package com.dxhy.oss.service.impl;
import cn.hutool.core.io.FileUtil;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.dxhy.oss.config.OssConfig;
import com.dxhy.oss.config.OssReturnConfig;
import com.dxhy.oss.model.FileModel;
import com.dxhy.oss.service.JdOssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
/**
* @author jiaohongyang
*/
@Service("jdOssService")
@Slf4j
public class JdOssServiceImpl implements JdOssService {
private final OssConfig ossConfig;
@Autowired
public JdOssServiceImpl(OssConfig ossConfig) {
this.ossConfig = ossConfig;
}
/**
* 京东云OSS文件存储
*
* @param filePath 文件
* @return 返回
*/
@Override
public FileModel uploadFile(String fileName, String filePath) {
FileModel fileModel;
AmazonS3 jdInstance = null;
log.info("文件存储京东OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), fileName);
try {
// 创建连接
jdInstance = OssClientFactory.getJdInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(),
ossConfig.getAccessKeySecret(), ossConfig.getRegion());
if (jdInstance == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
// 进行文件上传
jdInstance.putObject(ossConfig.getBucketName(), fileName, new File(filePath));
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
fileModel.setFilePath(fileName);
return fileModel;
} catch (Exception e) {
log.error("文件存储京东OSS失败,异常:{}", e.getMessage());
e.printStackTrace();
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
} finally {
if (jdInstance != null) {
jdInstance.shutdown();
}
FileUtil.del(filePath);
}
}
/**
* 下载
*
* @param fileName 文件名称
* @param filePath 本地文件存储地址
* @return 返回
*/
@Override
public FileModel downloadFile(String fileName, String filePath) {
log.info("下载文件京东OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), fileName);
AmazonS3 jdInstance = null;
S3ObjectInputStream s3is = null;
FileOutputStream fos = null;
FileModel fileModel;
try {
// 创建连接
jdInstance = OssClientFactory.getJdInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(),
ossConfig.getAccessKeySecret(), ossConfig.getRegion());
if (jdInstance == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
S3Object object = jdInstance.getObject(ossConfig.getBucketName(), fileName);
s3is = object.getObjectContent();
fos = new FileOutputStream(filePath);
byte[] readBuf = new byte[1024];
int readLen = 0;
while ((readLen = s3is.read(readBuf)) > 0) {
fos.write(readBuf, 0, readLen);
}
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
fileModel.setFilePath(filePath);
return fileModel;
} catch (Exception e) {
e.printStackTrace();
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
} finally {
try {
if (s3is != null) {
s3is.close();
}
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
if (jdInstance != null) {
jdInstance.shutdown();
}
}
}
@Override
public FileModel getUrl(String key) {
log.info("生成文件下载地址京东OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), key);
AmazonS3 jdInstance = null;
FileModel fileModel;
try {
// 创建连接
jdInstance = OssClientFactory.getJdInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(),
ossConfig.getAccessKeySecret(), ossConfig.getRegion());
if (jdInstance == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
// 设置URL过期时间为10年 3600l* 1000*24*365*10
Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000 * 24 * 365 * 2);
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(ossConfig.getBucketName(), key);
request.setExpiration(expiration);
URL url = jdInstance.generatePresignedUrl(request);
if (url != null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
fileModel.setFilePath(url.toString());
return fileModel;
}
} catch (Exception e) {
e.printStackTrace();
log.error("文件下载京东OSS失败,异常:{}", e.getMessage());
} finally {
if (jdInstance != null) {
jdInstance.shutdown();
}
}
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
/**
* 删除文件
*
* @param file 文件名
* @return 返回
*/
@Override
public FileModel deleteFile(String file) {
log.info("文件删除京东云OSS,存储目录:{} , 存储文件名:{} ", ossConfig.getBucketName(), file);
AmazonS3 jdInstance = null;
FileModel fileModel;
try {
// 创建连接
// 创建连接
jdInstance = OssClientFactory.getJdInstance(ossConfig.getEndpointUrl(), ossConfig.getAccessKeyId(),
ossConfig.getAccessKeySecret(), ossConfig.getRegion());
if (jdInstance == null) {
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
}
jdInstance.deleteObject(ossConfig.getBucketName(), file);
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.SUCCESS);
return fileModel;
} catch (Exception e) {
log.error("文件删除京东云OSS失败,异常:{}", e.getMessage());
e.printStackTrace();
fileModel = new FileModel();
fileModel.setCode(OssReturnConfig.ERROR_09);
return fileModel;
} finally {
if (jdInstance != null) {
jdInstance.shutdown();
}
}
}
}

@ -0,0 +1,55 @@
package com.dxhy.oss.service.impl;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
/**
* @author jiaohongyang
*/
@Slf4j
public class OssClientFactory {
private OssClientFactory() {
}
/**
* 创建连接
*/
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static OSS getInstance(String endpointUrl, String accessKeyId, String accessKeySecret) {
return new OSSClientBuilder().build(endpointUrl, accessKeyId, accessKeySecret);
}
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static AmazonS3 getJdInstance(String endpointUrl, String accessKeyId, String accessKeySecret,
String region) {
ClientConfiguration config = new ClientConfiguration();
AwsClientBuilder.EndpointConfiguration endpointConfig =
new AwsClientBuilder.EndpointConfiguration(endpointUrl, region);
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, accessKeySecret);
AWSCredentialsProvider awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);
return AmazonS3Client.builder().withEndpointConfiguration(endpointConfig).withClientConfiguration(config)
.withCredentials(awsCredentialsProvider).disableChunkedEncoding().withPathStyleAccessEnabled(true)
.build();
}
}

@ -0,0 +1,60 @@
package com.dxhy.oss.utils;
import cn.hutool.core.io.FileTypeUtil;
import java.io.InputStream;
/**
* 文件类型工具类
* TODO 其中只是定义了部分文件格式有缺失的自己添加
*/
public class FileTypeUtils {
private final static String IMAGE_TYPE = "image/";
private final static String AUDIO_TYPE = "audio/";
private final static String VIDEO_TYPE = "video/";
private final static String APPLICATION_TYPE = "application/";
private final static String TXT_TYPE = "text/";
public static String getFileType(InputStream fileInputStream) {
String type = null;
try {
type = FileTypeUtil.getType(fileInputStream);
if (type.equalsIgnoreCase("JPG") || type.equalsIgnoreCase("JPEG")
|| type.equalsIgnoreCase("GIF") || type.equalsIgnoreCase("PNG")
|| type.equalsIgnoreCase("BMP") || type.equalsIgnoreCase("PCX")
|| type.equalsIgnoreCase("TGA") || type.equalsIgnoreCase("PSD")
|| type.equalsIgnoreCase("TIFF")) {
return IMAGE_TYPE + type;
}
if (type.equalsIgnoreCase("mp3") || type.equalsIgnoreCase("OGG")
|| type.equalsIgnoreCase("WAV") || type.equalsIgnoreCase("REAL")
|| type.equalsIgnoreCase("APE") || type.equalsIgnoreCase("MODULE")
|| type.equalsIgnoreCase("MIDI") || type.equalsIgnoreCase("VQF")
|| type.equalsIgnoreCase("CD")) {
return AUDIO_TYPE + type;
}
if (type.equalsIgnoreCase("mp4") || type.equalsIgnoreCase("avi")
|| type.equalsIgnoreCase("MPEG-1") || type.equalsIgnoreCase("RM")
|| type.equalsIgnoreCase("ASF") || type.equalsIgnoreCase("WMV")
|| type.equalsIgnoreCase("qlv") || type.equalsIgnoreCase("MPEG-2")
|| type.equalsIgnoreCase("MPEG4") || type.equalsIgnoreCase("mov")
|| type.equalsIgnoreCase("3gp")) {
return VIDEO_TYPE + type;
}
if (type.equalsIgnoreCase("doc") || type.equalsIgnoreCase("docx")
|| type.equalsIgnoreCase("ppt") || type.equalsIgnoreCase("pptx")
|| type.equalsIgnoreCase("xls") || type.equalsIgnoreCase("xlsx")
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("jar")) {
return APPLICATION_TYPE + type;
}
if (type.equalsIgnoreCase("txt")) {
return TXT_TYPE + type;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,32 @@
package com.dxhy.oss.utils;
import com.dxhy.oss.service.FtpService;
import com.dxhy.oss.service.SshService;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
// ftp配置
@Configuration
@EnableConfigurationProperties(SftpProperties.class)
public class SftpConfig {
// 工厂
@Bean
public SftpFactory sftpFactory(SftpProperties properties) {
return new SftpFactory(properties);
}
// 连接池
@Bean
public SftpPool sftpPool(SftpFactory sftpFactory) {
return new SftpPool(sftpFactory);
}
// 辅助类
@Bean
public FtpService ftpService(SftpPool sftpPool) {
return new FtpService(sftpPool);
}
}

@ -0,0 +1,67 @@
package com.dxhy.oss.utils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import java.io.IOException;
@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
public class SftpFactory extends BasePooledObjectFactory<FTPClient> {
private SftpProperties ossConfig;
public SftpFactory(SftpProperties ossConfig) {
this.ossConfig = ossConfig;
}
@Override
public FTPClient create() throws Exception{
FTPClient ftpClient = null;
try {
ftpClient = new FTPClient();
ftpClient.setControlEncoding("UTF-8");// 中文支持
ftpClient.setConnectTimeout(1000 * 30);//设置连接超时时间
ftpClient.connect(ossConfig.getHostname(), Integer.valueOf(ossConfig.getPort()));// 连接FTP服务器
ftpClient.login(ossConfig.getUsername(), ossConfig.getPassword());// 登陆FTP服务器
// 设置文件类型为二进制(如果从FTP下载或上传的文件是压缩文件的时候,不进行该设置可能会导致获取的压缩文件解压失败)
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
// ftpClient.enterLocalPassiveMode();//开启被动模式,否则文件上传不成功,也不报错
if (!FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
log.info("连接FTP失败,用户名或密码错误。");
ftpClient.disconnect();
} else {
log.info("FTP连接成功!");
}
} catch (Exception e) {
log.info("登陆FTP失败,请检查FTP相关配置信息是否正确!" + e);
return null;
}
return ftpClient;
}
@Override
public PooledObject<FTPClient> wrap(FTPClient channelSftp) {
return new DefaultPooledObject<>(channelSftp);
}
// 销毁对象
@Override
public void destroyObject(PooledObject<FTPClient> p) {
FTPClient ftpClient = p.getObject();
try {
ftpClient.disconnect();
} catch (IOException e) {
log.error("登出ftp失败,请检查FTP相关配置信息是否正确!" + e);
}
}
}

@ -0,0 +1,41 @@
package com.dxhy.oss.utils;
import lombok.Data;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.pool2.impl.GenericObjectPool;
@Data
public class SftpPool {
private GenericObjectPool<FTPClient> pool;
public SftpPool(SftpFactory factory) {
this.pool = new GenericObjectPool<>(factory, factory.getOssConfig().getPool());
}
/**
* 获取一个sftp连接对象
*
* @return sftp连接对象
*/
public FTPClient borrowObject() throws SftpPoolException {
try {
return pool.borrowObject();
} catch (Exception e) {
e.printStackTrace();
throw new SftpPoolException("获取ftp连接失败", e);
}
}
/**
* 归还一个sftp连接对象
*
* @param ftpClient sftp连接对象
*/
public void returnObject(FTPClient ftpClient) {
if (ftpClient != null) {
pool.returnObject(ftpClient);
}
}
}

@ -0,0 +1,15 @@
package com.dxhy.oss.utils;
/**
* @author jiaohongyang
* @date 2019年3月26日 下午5:57:26
*/
public class SftpPoolException extends Exception {
public SftpPoolException(String message, Exception e) {
super(message, e);
}
}

@ -0,0 +1,61 @@
package com.dxhy.oss.utils;
import lombok.Data;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties(prefix = "ftp.connection")
public class SftpProperties {
private String hostname;
private String port;
private String username;
private String password;
private String timeout;
private Pool pool = new Pool();
public static class Pool extends GenericObjectPoolConfig<FTPClient> {
private int maxTotal = DEFAULT_MAX_TOTAL;
private int maxIdle = DEFAULT_MAX_IDLE;
private int minIdle = DEFAULT_MIN_IDLE;
public Pool() {
super();
}
@Override
public int getMaxTotal() {
return maxTotal;
}
@Override
public void setMaxTotal(int maxTotal) {
this.maxTotal = maxTotal;
}
@Override
public int getMaxIdle() {
return maxIdle;
}
@Override
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}
@Override
public int getMinIdle() {
return minIdle;
}
@Override
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
}
}

@ -0,0 +1,31 @@
package com.dxhy.oss.utils;
import com.dxhy.oss.service.FtpService;
import com.dxhy.oss.service.SshService;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
// ftp配置
@Configuration
@EnableConfigurationProperties(SshProperties.class)
public class SshConfig {
// 工厂
@Bean
public SshFactory sshFactory(SshProperties properties) {
return new SshFactory(properties);
}
// 连接池
@Bean
public SshPool sshPool(SshFactory sshFactory) {
return new SshPool(sshFactory);
}
// 辅助类
@Bean
public SshService sshService(SshPool sftpPool) {
return new SshService(sftpPool);
}
}

@ -0,0 +1,70 @@
package com.dxhy.oss.utils;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import java.util.Properties;
@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
public class SshFactory extends BasePooledObjectFactory<ChannelSftp> {
private SshProperties ossConfig;
public SshFactory(SshProperties ossConfig) {
this.ossConfig = ossConfig;
}
@Override
public ChannelSftp create() throws SftpPoolException {
try {
JSch jsch = new JSch();
Session session = jsch.getSession(ossConfig.getUsername(), ossConfig.getHostname(), Integer.parseInt(ossConfig.getPort()));
// 设置密码
if (ossConfig.getPassword() != null) {
session.setPassword(ossConfig.getPassword());
}
// 设置密码
if (ossConfig.getPassword() != null) {
session.setPassword(ossConfig.getPassword());
}
// 为Session对象设置properties
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
// 设置超时时间
session.setTimeout(Integer.parseInt(ossConfig.getTimeout()));
// 建立链接
session.connect();
// 打开SFTP通道
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
// 建立SFTP通道的连接
channel.connect();
return channel;
} catch (JSchException e) {
throw new SftpPoolException("获取ftp连接失败", e);
}
}
@Override
public PooledObject<ChannelSftp> wrap(ChannelSftp channelSftp) {
return new DefaultPooledObject<>(channelSftp);
}
// 销毁对象
@Override
public void destroyObject(PooledObject<ChannelSftp> p) {
ChannelSftp channelSftp = p.getObject();
channelSftp.disconnect();
}
}

@ -0,0 +1,41 @@
package com.dxhy.oss.utils;
import com.jcraft.jsch.ChannelSftp;
import lombok.Data;
import org.apache.commons.pool2.impl.GenericObjectPool;
@Data
public class SshPool {
private GenericObjectPool<ChannelSftp> pool;
public SshPool(SshFactory factory) {
this.pool = new GenericObjectPool<>(factory, factory.getOssConfig().getPool());
}
/**
* 获取一个sftp连接对象
*
* @return sftp连接对象
*/
public ChannelSftp borrowObject() throws SftpPoolException {
try {
return pool.borrowObject();
} catch (Exception e) {
e.printStackTrace();
throw new SftpPoolException("获取ftp连接失败", e);
}
}
/**
* 归还一个sftp连接对象
*
* @param channelSftp sftp连接对象
*/
public void returnObject(ChannelSftp channelSftp) {
if (channelSftp != null) {
pool.returnObject(channelSftp);
}
}
}

@ -0,0 +1,61 @@
package com.dxhy.oss.utils;
import com.jcraft.jsch.ChannelSftp;
import lombok.Data;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties(prefix = "ftp.connection")
public class SshProperties {
private String hostname;
private String port = "22";
private String username;
private String password;
private String timeout;
private Pool pool = new Pool();
public static class Pool extends GenericObjectPoolConfig<ChannelSftp> {
private int maxTotal = DEFAULT_MAX_TOTAL;
private int maxIdle = DEFAULT_MAX_IDLE;
private int minIdle = DEFAULT_MIN_IDLE;
public Pool() {
super();
}
@Override
public int getMaxTotal() {
return maxTotal;
}
@Override
public void setMaxTotal(int maxTotal) {
this.maxTotal = maxTotal;
}
@Override
public int getMaxIdle() {
return maxIdle;
}
@Override
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}
@Override
public int getMinIdle() {
return minIdle;
}
@Override
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
}
}

@ -0,0 +1,13 @@
package com.dxhy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.dxhy.*")
public class DxhyOssApplication {
public static void main(String[] args) {
SpringApplication.run(DxhyOssApplication.class, args);
}
}

@ -0,0 +1,40 @@
package com.dxhy;
import com.dxhy.oss.model.FileModel;
import com.dxhy.oss.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.File;
/**
* @author user
*/
@SuppressWarnings("FieldCanBeLocal")
@Slf4j
public class OfdHandle extends Thread {
private final File file;
@Autowired
private FileService fileService;
public OfdHandle(File file) {
this.file = file;
}
@Override
public void run() {
fileService = (FileService) SpringContextUtils.getBean("fileService");
FileModel fileModel = new FileModel();
try {
fileModel = fileService.uploadFile(file.getPath(), file.getPath());
} catch (Exception e) {
e.printStackTrace();
}
log.info("文件上传返回结果:" + fileModel.getCode() + " " + fileModel.getFilePath());
}
}

@ -0,0 +1,127 @@
package com.dxhy;
import java.io.File;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.dxhy.oss.model.FileModel;
import com.dxhy.oss.service.FileService;
import cn.hutool.core.io.FileUtil;
/**
* @author jiaohongyang焦红阳
* @date 2020-09-30
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DxhyOssApplication.class)
public class OssTest {
@Resource
private FileService fileService;
@Test
public void ossUploadTest() {
String fileName = "/GYL/YONGHUI/2022/09/08/update.zip";
String originFileName = "/Users/jiaohongyang/product/project/project/jxpt/ofd/pdf/update.zip";
FileModel fileModel = new FileModel();
try {
fileModel = fileService.uploadFile(fileName, originFileName);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("文件上传返回结果:" + fileModel.getCode() + " " + fileModel.getFilePath());
}
@Test
public void ossGylUploadTest() {
String fileName = "/GYL/DUODIAN/2022/12/07/update.zip";
String originFileName = "/Users/jiaohongyang/product/project/project/jxpt/ofd/pdf/update.zip";
FileModel fileModel = new FileModel();
try {
fileModel = fileService.uploadFile(fileName, originFileName);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("文件上传返回结果:" + fileModel.getCode() + " " + fileModel.getFilePath());
}
@Test
public void ossGylSdlpUploadTest() {
String fileName = "/GYL/SDLP/2022/09/20/51发票助手_local_J_1.4.8.exe";
String originFileName = "/Users/jiaohongyang/product/project/project/jxpt/ofd/pdf/51发票助手_local_J_1.4.8.exe";
FileModel fileModel = new FileModel();
try {
fileModel = fileService.uploadFile(fileName, originFileName);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("文件上传返回结果:" + fileModel.getCode() + " " + fileModel.getFilePath());
}
@Test
public void ossDownloadTest() {
String downloadFile = "/jxfp/pdf/2022/1111/dxhy-admin.jar";
// String downloadFile = "/jxfp/excel/2020/10/12/1282510566564315137_进项票据采集_2020-10-12_1602489969696.xlsx";
String saveFile = "/Users/jiaohongyang/product/project/project/jxpt/ofd/pdf/dxhy-admin.jar";
FileModel fileModel = new FileModel();
try {
fileModel = fileService.downFile(downloadFile, saveFile);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("文件下载返回结果" + fileModel.getCode() + " " + fileModel.getFilePath());
}
@Test
public void ossgetUrlTest() {
String key = "/GYL/SDLP/2022/09/14/供应链协同开票助手-v1.1.0.1.20220914-x86_Setup.zip";
FileModel fileModel = fileService.getUrl(key);
System.out.println(fileModel.getCode() + " " + fileModel.getFilePath());
}
@Test
public void ossDeleteTest() {
String downloadFile = "GYL/DUODIAN/2022/12/01/20221201(1.1.0.2).zip";
FileModel fileModel = new FileModel();
try {
fileModel = fileService.deleteFile(downloadFile);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("文件删除返回结果" + fileModel.getCode());
}
@Test
public void ossPush() {
String path = "/Volumes/product/PDF/";
try {
File[] ls = FileUtil.ls(path);
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2000, 10000, 60L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(ls.length), r -> new Thread(r, "oss推送-" + r.hashCode()));
for (File file : ls) {
if (!threadPoolExecutor.isShutdown()) {
threadPoolExecutor.execute(new OfdHandle(file));
}
}
threadPoolExecutor.shutdown();
threadPoolExecutor.awaitTermination(60, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,43 @@
package com.dxhy;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
* Spring Context 工具类
*
* @author jiaohongyang
*/
@Component
public class SpringContextUtils implements ApplicationContextAware {
public static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextUtils.applicationContext = applicationContext;
}
public static Object getBean(String name) {
return applicationContext.getBean(name);
}
public static <T> T getBean(String name, Class<T> requiredType) {
return applicationContext.getBean(name, requiredType);
}
public static boolean containsBean(String name) {
return applicationContext.containsBean(name);
}
public static boolean isSingleton(String name) {
return applicationContext.isSingleton(name);
}
public static Class<?> getType(String name) {
return applicationContext.getType(name);
}
}

@ -0,0 +1,48 @@
#oss:
# ossType: AL
# endpointUrl: http://oss-accelerate.aliyuncs.com
# accessKeyId: LTAI4G6XxTTwUzcY3ByWa6Yb
# accessKeySecret: kkgPJ4DIvkOcvfZPl4BE1FVqyQlPiq
# region:
# bucketName: jiaohongyang
#oss:
# ossType: JD
# endpointUrl: https://storage.jd.local
# accessKeyId: bfac05320eaf11cc80cf1823e4fb87d98523fc94
# accessKeySecret: 70ec454ffb302043a7837417e0909e12d1288d0b
# region: cn-north-1
# bucketName: input-tax-invoice
#oss:
# ossType: AL
# endpointUrl: http://oss-cn-beijing-internal.aliyuncs.com
# accessKeyId: LTAI4GHGCEiWsXxTZ651wV22
# accessKeySecret: hTXim31f5JmIMz3rcj7WIopKAUscsE
# region:
# bucketName: guowangtest
#oss:
# ossType: MINIO
# endpointUrl: http://10.1.2.107:9000
# accessKeyId: minioadmin
# accessKeySecret: minioadmin
# region:
# bucketName: jxpt
oss:
ossType: JD
endpointUrl: https://s3.cn-north-1.jdcloud-oss.com
accessKeyId: 4B2A089EA1C8F776357A15948DBCA363
accessKeySecret: 570296481BA33BFC4A8C9EEB5E00652A
region: cn-north-1
bucketName: jxdownload
ftp:
connection:
hostname: 10.1.2.87
username: dxhy1
password: dxhy
port: 62236
timeout: 60000
pathPrefix: /jxfp/excel/
# 连接池参数
pool:
max-total: 10
max-idle: 10
min-idle: 5

@ -106,7 +106,7 @@
<dependency>
<groupId>com.dxhy.jxpt</groupId>
<artifactId>dxhy-oss</artifactId>
<version>3.2.9</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>

@ -118,7 +118,7 @@
<dependency>
<groupId>com.dxhy.jxpt</groupId>
<artifactId>dxhy-oss</artifactId>
<version>3.2.9</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>

@ -21,6 +21,7 @@
<module>dxhy-admin</module>
<module>dxhy-gateway</module>
<module>dxhy-base</module>
<module>dxhy-oss</module>
<module>dxhy-core</module>
<module>dxhy-erp</module>
<module>dxhy-extend</module>

Loading…
Cancel
Save