|
|
|
@ -15,9 +15,11 @@ import com.jianshui.invoice.domain.Invoice; |
|
|
|
|
import com.jianshui.invoice.domain.dto.HXResponse; |
|
|
|
|
import com.jianshui.invoice.domain.dto.api.jcsk.FileAcquisitionTwoDTO; |
|
|
|
|
import com.jianshui.invoice.mapper.InvoiceMapper; |
|
|
|
|
import com.jianshui.platform.dto.DownLoadDTO; |
|
|
|
|
import com.jianshui.platform.service.InvoiceDownloadService; |
|
|
|
|
import com.jianshui.platform.utils.BatchDownloadUtils; |
|
|
|
|
import com.jianshui.platform.utils.InvoiceAllYhdjUtils; |
|
|
|
|
import com.jianshui.platform.vo.DownLoadErrorVO; |
|
|
|
|
import com.jianshui.system.domain.InvoiceAllYhdj; |
|
|
|
|
import com.jianshui.system.mapper.CompanyserviceMapper; |
|
|
|
|
import com.jianshui.system.mapper.SysUserMapper; |
|
|
|
@ -64,6 +66,9 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
SysUser sysUser = sysUserMapper.selectUserById(userId); |
|
|
|
|
//根据企业id获取企业信息
|
|
|
|
|
Companyservice companyservice = companyServiceMapper.selectCompanyserviceByCompanyid(sysUser.getCompanyId()); |
|
|
|
|
if (companyservice == null){ |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.NOTCOMPANYINFO); |
|
|
|
|
} |
|
|
|
|
//获取登记用户信息
|
|
|
|
|
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils(); |
|
|
|
|
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice); |
|
|
|
@ -71,12 +76,20 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.NOINFORMATIONISFOUND); |
|
|
|
|
} |
|
|
|
|
//pfd文件集合
|
|
|
|
|
List<String> pdfList = new ArrayList<>(); |
|
|
|
|
List<DownLoadDTO> pdfDownLoad = new ArrayList<>(); |
|
|
|
|
//下载失败集合
|
|
|
|
|
List<DownLoadErrorVO> errorList = new ArrayList<>(); |
|
|
|
|
for (Long id : ids) { |
|
|
|
|
DownLoadDTO downLoadDTO = new DownLoadDTO(); |
|
|
|
|
Invoice invoice = invoiceMapper.selectInvoiceById(id); |
|
|
|
|
if (invoice == null){ |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.NOTINVOICEINFO); |
|
|
|
|
} |
|
|
|
|
String invoicePdfUrl = invoice.getInvoicePdfUrl(); |
|
|
|
|
if (invoicePdfUrl != null) { |
|
|
|
|
pdfList.add(invoicePdfUrl); |
|
|
|
|
downLoadDTO.setUrl(invoicePdfUrl); |
|
|
|
|
downLoadDTO.setFphm(invoice.getFphm()); |
|
|
|
|
pdfDownLoad.add(downLoadDTO); |
|
|
|
|
} else { |
|
|
|
|
//获取pfd下载地址
|
|
|
|
|
//封装请求实体类
|
|
|
|
@ -94,6 +107,8 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
String kprqFormat = simpleDateFormat.format(kprq); |
|
|
|
|
map.put(InvoiceCommonConstants.KPRQ, kprqFormat); |
|
|
|
|
fileAcquisitionDTO.setJsonData(map); |
|
|
|
|
//下载失败信息类
|
|
|
|
|
DownLoadErrorVO downLoadErrorVO = new DownLoadErrorVO(); |
|
|
|
|
cn.hutool.json.JSONObject result = null; |
|
|
|
|
try { |
|
|
|
|
result = ApiHttp.request(WebServiceConstant.FPEWMXZ, WebServiceConstant.URL, fileAcquisitionDTO, companyservice); |
|
|
|
@ -103,20 +118,34 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
if (InvoiceCommonConstants.SUCCESSCODE.equals(code) && StrUtil.isNotEmpty(data)) { |
|
|
|
|
cn.hutool.json.JSONObject json = JSONUtil.parseObj(data); |
|
|
|
|
String pdfUrl = json.get(InvoiceCommonConstants.PDFURL) != null ? json.get(InvoiceCommonConstants.PDFURL).toString() : ""; |
|
|
|
|
pdfList.add(pdfUrl); |
|
|
|
|
downLoadDTO.setFphm(invoice.getFphm()); |
|
|
|
|
downLoadDTO.setUrl(pdfUrl); |
|
|
|
|
pdfDownLoad.add(downLoadDTO); |
|
|
|
|
} else { |
|
|
|
|
return AjaxResult.error(msg); |
|
|
|
|
//设置错误信息
|
|
|
|
|
downLoadErrorVO.setFphm(invoice.getFphm()); |
|
|
|
|
downLoadErrorVO.setMsg(msg); |
|
|
|
|
errorList.add(downLoadErrorVO); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("【金四服务类】【金财数科】【获取发票下载地址】API请求异常,外部报文返回code非0000。错误信息:{}", e.getMessage()); |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.DOWNLOADADDRESSERROR); |
|
|
|
|
//设置错误信息
|
|
|
|
|
downLoadErrorVO.setFphm(invoice.getFphm()); |
|
|
|
|
downLoadErrorVO.setMsg(e.getMessage()); |
|
|
|
|
errorList.add(downLoadErrorVO); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//下载pfd文件
|
|
|
|
|
BatchDownloadUtils.downloadAndZipFiles(pdfList,InvoiceCommonConstants.PDFSTATUS,response); |
|
|
|
|
return AjaxResult.success(InvoiceCommonConstants.DOWNLOADSUCCESSCODE); |
|
|
|
|
if (errorList.size() > 0 || errorList != null){ |
|
|
|
|
//下载pdf文件集合
|
|
|
|
|
BatchDownloadUtils.downloadAndZipFiles(pdfDownLoad,InvoiceCommonConstants.PDFSTATUS,response); |
|
|
|
|
return AjaxResult.error(errorList); |
|
|
|
|
}else { |
|
|
|
|
//下载pdf文件集合;
|
|
|
|
|
BatchDownloadUtils.downloadAndZipFiles(pdfDownLoad,InvoiceCommonConstants.PDFSTATUS,response); |
|
|
|
|
return AjaxResult.success(InvoiceCommonConstants.DOWNLOADSUCCESSCODE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -137,6 +166,9 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
SysUser sysUser = sysUserMapper.selectUserById(userId); |
|
|
|
|
//根据企业id获取企业信息
|
|
|
|
|
Companyservice companyservice = companyServiceMapper.selectCompanyserviceByCompanyid(sysUser.getCompanyId()); |
|
|
|
|
if (companyservice == null){ |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.NOTCOMPANYINFO); |
|
|
|
|
} |
|
|
|
|
//获取登记用户信息
|
|
|
|
|
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils(); |
|
|
|
|
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice); |
|
|
|
@ -144,12 +176,20 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
return new HXResponse(InvoiceCommonConstants.NOINFORMATIONISFOUND); |
|
|
|
|
} |
|
|
|
|
//ofd文件集合
|
|
|
|
|
List<String> ofdList = new ArrayList<>(); |
|
|
|
|
List<DownLoadDTO> ofdDownLoad = new ArrayList<>(); |
|
|
|
|
//下载失败集合
|
|
|
|
|
List<DownLoadErrorVO> errorList = new ArrayList<>(); |
|
|
|
|
for (Long id : ids) { |
|
|
|
|
Invoice invoice = invoiceMapper.selectInvoiceById(id); |
|
|
|
|
DownLoadDTO downLoadDTO = new DownLoadDTO(); |
|
|
|
|
if (invoice == null){ |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.NOTINVOICEINFO); |
|
|
|
|
} |
|
|
|
|
String invoiceOfdUrl = invoice.getcOfdUrl(); |
|
|
|
|
if (invoiceOfdUrl != null) { |
|
|
|
|
ofdList.add(invoiceOfdUrl); |
|
|
|
|
downLoadDTO.setUrl(invoiceOfdUrl); |
|
|
|
|
downLoadDTO.setFphm(invoice.getFphm()); |
|
|
|
|
ofdDownLoad.add(downLoadDTO); |
|
|
|
|
} else { |
|
|
|
|
//获取ofd下载地址
|
|
|
|
|
//封装请求实体类
|
|
|
|
@ -167,6 +207,8 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
String kprqFormat = simpleDateFormat.format(kprq); |
|
|
|
|
map.put(InvoiceCommonConstants.KPRQ, kprqFormat); |
|
|
|
|
fileAcquisitionDTO.setJsonData(map); |
|
|
|
|
//下载失败信息类
|
|
|
|
|
DownLoadErrorVO downLoadErrorVO = new DownLoadErrorVO(); |
|
|
|
|
cn.hutool.json.JSONObject result = null; |
|
|
|
|
try { |
|
|
|
|
result = ApiHttp.request(WebServiceConstant.FPEWMXZ, WebServiceConstant.URL, fileAcquisitionDTO, companyservice); |
|
|
|
@ -176,20 +218,34 @@ public class InvoiceDownloadServiceImpl implements InvoiceDownloadService { |
|
|
|
|
if (InvoiceCommonConstants.SUCCESSCODE.equals(code) && StrUtil.isNotEmpty(data)) { |
|
|
|
|
cn.hutool.json.JSONObject json = JSONUtil.parseObj(data); |
|
|
|
|
String ofdUrl = json.get(InvoiceCommonConstants.OFDURL) != null ? json.get(InvoiceCommonConstants.OFDURL).toString() : ""; |
|
|
|
|
ofdList.add(ofdUrl); |
|
|
|
|
downLoadDTO.setFphm(invoice.getFphm()); |
|
|
|
|
downLoadDTO.setUrl(ofdUrl); |
|
|
|
|
ofdDownLoad.add(downLoadDTO); |
|
|
|
|
} else { |
|
|
|
|
return AjaxResult.error(msg); |
|
|
|
|
//设置错误信息
|
|
|
|
|
downLoadErrorVO.setFphm(invoice.getFphm()); |
|
|
|
|
downLoadErrorVO.setMsg(msg); |
|
|
|
|
errorList.add(downLoadErrorVO); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("【金四服务类】【金财数科】【获取发票下载地址】API请求异常,外部报文返回code非0000。错误信息:{}", e.getMessage()); |
|
|
|
|
return AjaxResult.error(InvoiceCommonConstants.DOWNLOADADDRESSERROR); |
|
|
|
|
//设置错误信息
|
|
|
|
|
downLoadErrorVO.setFphm(invoice.getFphm()); |
|
|
|
|
downLoadErrorVO.setMsg(e.getMessage()); |
|
|
|
|
errorList.add(downLoadErrorVO); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//下载ofd文件集合
|
|
|
|
|
BatchDownloadUtils.downloadAndZipFiles(ofdList,InvoiceCommonConstants.OFDSTATUS,response); |
|
|
|
|
return AjaxResult.success(InvoiceCommonConstants.DOWNLOADSUCCESSCODE); |
|
|
|
|
if (errorList.size() > 0 || errorList != null){ |
|
|
|
|
//下载ofd文件集合
|
|
|
|
|
BatchDownloadUtils.downloadAndZipFiles(ofdDownLoad,InvoiceCommonConstants.OFDSTATUS,response); |
|
|
|
|
return AjaxResult.error(errorList); |
|
|
|
|
}else { |
|
|
|
|
//下载ofd文件集合
|
|
|
|
|
BatchDownloadUtils.downloadAndZipFiles(ofdDownLoad,InvoiceCommonConstants.OFDSTATUS,response); |
|
|
|
|
return AjaxResult.success(InvoiceCommonConstants.DOWNLOADSUCCESSCODE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|