Merge branch 'beta' into kk

beta-enc
dongxiaoke 2 years ago
commit 77d65532ec
  1. 7
      jianshui-admin/src/main/java/com/jianshui/web/controller/platform/InvoiceDeliveryController.java
  2. 37
      jianshui-admin/src/main/java/com/jianshui/web/controller/platform/InvoiceDownloadController.java
  3. 20
      jianshui-common/src/main/java/com/jianshui/common/constant/InvoiceAllYhdjConstants.java
  4. 96
      jianshui-common/src/main/java/com/jianshui/common/constant/InvoiceCommonConstants.java
  5. 16
      jianshui-platform/src/main/java/com/jianshui/platform/domain/InvoiceDelivery.java
  6. 6
      jianshui-platform/src/main/java/com/jianshui/platform/mapper/InvoiceDeliveryMapper.java
  7. 4
      jianshui-platform/src/main/java/com/jianshui/platform/service/InvoiceDeliveryService.java
  8. 29
      jianshui-platform/src/main/java/com/jianshui/platform/service/InvoiceDownloadService.java
  9. 46
      jianshui-platform/src/main/java/com/jianshui/platform/service/impl/InvoiceDeliveryServiceImpl.java
  10. 196
      jianshui-platform/src/main/java/com/jianshui/platform/service/impl/InvoiceDownloadServiceImpl.java
  11. 125
      jianshui-platform/src/main/java/com/jianshui/platform/utils/BatchDownloadUtils.java
  12. 7
      jianshui-platform/src/main/resources/com/jianshui/platform/mapper/InvoiceDeliveryMapper.xml

@ -1,6 +1,6 @@
package com.jianshui.web.controller.platform; package com.jianshui.web.controller.platform;
import com.jianshui.invoice.domain.dto.HXResponse; import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO; import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO;
import com.jianshui.platform.service.InvoiceDeliveryService; import com.jianshui.platform.service.InvoiceDeliveryService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -29,8 +29,7 @@ public class InvoiceDeliveryController {
@ApiOperation("发票交付") @ApiOperation("发票交付")
@PostMapping("/delivery") @PostMapping("/delivery")
public Object invoiceDelivery(@RequestBody List<InvoiceDeliveryJsonDataDTO> dtos){ public AjaxResult invoiceDelivery(@RequestBody List<InvoiceDeliveryJsonDataDTO> dtos){
HXResponse response = invoiceDeliveryService.invoiceDelivery(dtos); return invoiceDeliveryService.invoiceDelivery(dtos);
return response;
} }
} }

@ -0,0 +1,37 @@
package com.jianshui.web.controller.platform;
import com.jianshui.common.constant.InvoiceCommonConstants;
import com.jianshui.platform.service.InvoiceDownloadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
/**
* @Author: kane
* @Description: 发票批量下载接口
* @CreateTime: 2023-06-08 14:27
* @Version: 1.0
**/
@Api(tags = "发票批量下载")
@RestController
@RequestMapping("/platForm/invoiceDownLoad")
public class InvoiceDownloadController {
@Autowired
private InvoiceDownloadService invoiceDownloadService;
@ApiOperation("发票批量下载")
@GetMapping("/dowmLoadPdf/{ids}/{status}")
public Object downLoad(@PathVariable Long[] ids,@PathVariable String status,HttpServletResponse response){
if (InvoiceCommonConstants.PDFSTATUS.equals(status)){
return invoiceDownloadService.dowmLoadPdf(ids,response);
}else {
return invoiceDownloadService.dowmLoadOfd(ids,response);
}
}
}

@ -1,20 +0,0 @@
package com.jianshui.common.constant;
/**
* @Author: xinzge
* @Description: 用户登记信息常量类
* @CreateTime: 2023-06-06 13:35
* @Version: 1.0
**/
public class InvoiceAllYhdjConstants {
/**
* 异步
*/
public final static String ASYNC = "true";
/**
* 同步
*/
public final static String SYNC = "false";
}

@ -0,0 +1,96 @@
package com.jianshui.common.constant;
/**
* @Author: xinzge
* @Description: 用户登记信息常量类
* @CreateTime: 2023-06-06 13:35
* @Version: 1.0
**/
public class InvoiceCommonConstants {
/**
* 异步
*/
public final static String ASYNC = "true";
/**
* 同步
*/
public final static String SYNC = "false";
/**
* 信息为空
*/
public final static String INVOICEINFORMATIONISEMPTY = "未传入发票信息,请检查!";
/**
* 未查询到登记信息
*/
public final static String NOINFORMATIONISFOUND = "未查询到登记信息!";
/**
* 开票日期格式
*/
public final static String DATEFORMAT = "yyyyMMddHHmmss";
/**
* 发票号码
*/
public final static String FPHM = "fphm";
/**
* 开票日期
*/
public final static String KPRQ = "kprq";
/**
* 响应码
*/
public final static String CODE = "code";
/**
* 错误信息
*/
public final static String MSG = "msg";
/**
* 响应数据
*/
public final static String DATA = "data";
/**
* 成功响应状态码
*/
public final static String SUCCESSCODE = "0000";
/**
* pdf地址
*/
public final static String PDFURL = "pdfUrl";
/**
* 发票下载地址错误
*/
public final static String DOWNLOADADDRESSERROR = "获取发票下载地址错误!";
/**
* 下载成功
*/
public final static String DOWNLOADSUCCESSCODE = "下载成功!";
/**
* ofd地址
*/
public final static String OFDURL = "ofdUrl";
/**
* pdf状态
*/
public final static String PDFSTATUS = "0";
/**
* ofd状态
*/
public final static String OFDSTATUS = "1";
}

@ -9,7 +9,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
* 发票交付对象 invoice_delivery * 发票交付对象 invoice_delivery
* *
* @author jianshui * @author jianshui
* @date 2023-06-06 * @date 2023-06-08
*/ */
public class InvoiceDelivery extends BaseEntity public class InvoiceDelivery extends BaseEntity
{ {
@ -58,6 +58,10 @@ public class InvoiceDelivery extends BaseEntity
@Excel(name = "创建人id") @Excel(name = "创建人id")
private Long clerk; private Long clerk;
/** 订单来源(1-模板导入,2-API调用,3-手工录入,4-扫码开票) */
@Excel(name = "订单来源", readConverterExp = "订单来源(1-模板导入,2-API调用,3-手工录入,4-扫码开票)")
private String source;
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
@ -157,6 +161,15 @@ public class InvoiceDelivery extends BaseEntity
{ {
return clerk; return clerk;
} }
public void setSource(String source)
{
this.source = source;
}
public String getSource()
{
return source;
}
@Override @Override
public String toString() { public String toString() {
@ -174,6 +187,7 @@ public class InvoiceDelivery extends BaseEntity
.append("clerk", getClerk()) .append("clerk", getClerk())
.append("createTime", getCreateTime()) .append("createTime", getCreateTime())
.append("remark", getRemark()) .append("remark", getRemark())
.append("source", getSource())
.toString(); .toString();
} }
} }

@ -1,15 +1,13 @@
package com.jianshui.platform.mapper; package com.jianshui.platform.mapper;
import com.jianshui.platform.domain.InvoiceDelivery;
import java.util.List; import java.util.List;
import com.jianshui.platform.domain.InvoiceDelivery;
/** /**
* 发票交付Mapper接口 * 发票交付Mapper接口
* *
* @author jianshui * @author jianshui
* @date 2023-06-06 * @date 2023-06-08
*/ */
public interface InvoiceDeliveryMapper public interface InvoiceDeliveryMapper
{ {

@ -1,6 +1,6 @@
package com.jianshui.platform.service; package com.jianshui.platform.service;
import com.jianshui.invoice.domain.dto.HXResponse; import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO; import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO;
import java.util.List; import java.util.List;
@ -18,5 +18,5 @@ public interface InvoiceDeliveryService {
* @param dtos 多张单张交付信息 * @param dtos 多张单张交付信息
* @return : com.jianshui.invoice.domain.dto.HXResponse * @return : com.jianshui.invoice.domain.dto.HXResponse
*/ */
HXResponse invoiceDelivery(List<InvoiceDeliveryJsonDataDTO> dtos); AjaxResult invoiceDelivery(List<InvoiceDeliveryJsonDataDTO> dtos);
} }

@ -0,0 +1,29 @@
package com.jianshui.platform.service;
import javax.servlet.http.HttpServletResponse;
/**
* @Author: kane
* @Description: 发票下载业务层
* @CreateTime: 2023-06-08 14:36
* @Version: 1.0
**/
public interface InvoiceDownloadService {
/**
* 功能描述: 发票pdf版下载
* @param ids
* @param response
* @return : java.lang.Object
*/
Object dowmLoadPdf(Long[] ids, HttpServletResponse response);
/**
* 功能描述: 发票ofd版下载
* @param ids
* @param response
* @return : java.lang.Object
*/
Object dowmLoadOfd(Long[] ids, HttpServletResponse response);
}

@ -4,40 +4,31 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.jianshui.common.constant.InvoiceCommonConstants;
import com.jianshui.common.constant.InvoiceAllYhdjConstants;
import com.jianshui.common.constant.WebServiceConstant; import com.jianshui.common.constant.WebServiceConstant;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice; import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.core.domain.entity.SysUser; import com.jianshui.common.core.domain.entity.SysUser;
import com.jianshui.common.core.redis.RedisCache;
import com.jianshui.common.utils.BeanToMapUtils; import com.jianshui.common.utils.BeanToMapUtils;
import com.jianshui.common.utils.InvoiceUtils;
import com.jianshui.common.utils.SecurityUtils; import com.jianshui.common.utils.SecurityUtils;
import com.jianshui.common.utils.ValidateUtils; import com.jianshui.common.utils.ValidateUtils;
import com.jianshui.common.utils.jcsk.ApiHttp; import com.jianshui.common.utils.jcsk.ApiHttp;
import com.jianshui.common.utils.spring.SpringUtils; import com.jianshui.invoice.enums.ChannelSource;
import com.jianshui.invoice.domain.dto.HXResponse;
import com.jianshui.platform.domain.InvoiceDelivery; import com.jianshui.platform.domain.InvoiceDelivery;
import com.jianshui.platform.dto.InvoiceDeliveryDTO; import com.jianshui.platform.dto.InvoiceDeliveryDTO;
import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO; import com.jianshui.platform.dto.InvoiceDeliveryJsonDataDTO;
import com.jianshui.platform.mapper.InvoiceDeliveryMapper; import com.jianshui.platform.mapper.InvoiceDeliveryMapper;
import com.jianshui.platform.service.InvoiceDeliveryService; import com.jianshui.platform.service.InvoiceDeliveryService;
import com.jianshui.platform.utils.InvoiceAllYhdjUtils; import com.jianshui.platform.utils.InvoiceAllYhdjUtils;
import com.jianshui.system.domain.InvoiceAllApiLog;
import com.jianshui.system.domain.InvoiceAllYhdj; import com.jianshui.system.domain.InvoiceAllYhdj;
import com.jianshui.system.mapper.CompanyserviceMapper; import com.jianshui.system.mapper.CompanyserviceMapper;
import com.jianshui.system.mapper.InvoiceAllApiLogMapper;
import com.jianshui.system.mapper.InvoiceAllYhdjMapper;
import com.jianshui.system.mapper.SysUserMapper; import com.jianshui.system.mapper.SysUserMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
* @Author: xingze * @Author: xingze
@ -56,8 +47,6 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
@Autowired @Autowired
private InvoiceDeliveryMapper invoiceDeliveryMapper; private InvoiceDeliveryMapper invoiceDeliveryMapper;
@Autowired
private InvoiceAllApiLogMapper allApiLogMapper;
/** /**
* 功能描述: 发票交付 * 功能描述: 发票交付
@ -65,7 +54,7 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
* @return : com.jianshui.invoice.domain.dto.HXResponse * @return : com.jianshui.invoice.domain.dto.HXResponse
*/ */
@Override @Override
public HXResponse invoiceDelivery(List<InvoiceDeliveryJsonDataDTO> dtos) { public AjaxResult invoiceDelivery(List<InvoiceDeliveryJsonDataDTO> dtos) {
//获取用户id //获取用户id
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
//根据用户id获取用户信息 //根据用户id获取用户信息
@ -76,11 +65,11 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils(); InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils();
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice); InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice);
if (BeanUtil.isEmpty(userInfo)) { if (BeanUtil.isEmpty(userInfo)) {
return new HXResponse("未查询到登记信息!"); return AjaxResult.error("未查询到登记信息!");
} }
//封装上游接口实体类 //封装上游接口实体类
InvoiceDeliveryDTO invoiceDeliveryDTO = new InvoiceDeliveryDTO(); InvoiceDeliveryDTO invoiceDeliveryDTO = new InvoiceDeliveryDTO();
invoiceDeliveryDTO.setAsync(InvoiceAllYhdjConstants.SYNC); invoiceDeliveryDTO.setAsync(InvoiceCommonConstants.SYNC);
invoiceDeliveryDTO.setBsrysfzjhm(userInfo.getBsrysfzjhm()); invoiceDeliveryDTO.setBsrysfzjhm(userInfo.getBsrysfzjhm());
invoiceDeliveryDTO.setDqbm(userInfo.getDqbm()); invoiceDeliveryDTO.setDqbm(userInfo.getDqbm());
invoiceDeliveryDTO.setNsrsbh(userInfo.getNsrsbh()); invoiceDeliveryDTO.setNsrsbh(userInfo.getNsrsbh());
@ -99,15 +88,6 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
String code = result.get("code") != null ? result.get("code").toString() : ""; String code = result.get("code") != null ? result.get("code").toString() : "";
String msg = result.get("msg") != null ? result.get("msg").toString() : ""; String msg = result.get("msg") != null ? result.get("msg").toString() : "";
String data = result.get("data") != null ? result.get("data").toString() : ""; String data = result.get("data") != null ? result.get("data").toString() : "";
//封装调用日志
InvoiceAllApiLog allApiLog = new InvoiceAllApiLog();
allApiLog.setUrl(WebServiceConstant.INVOIVEDELIVERY);
allApiLog.setSendMsg(invoiceDeliveryDTO.toString());
allApiLog.setResultMsg(JSONUtil.toJsonStr(result));
allApiLog.setCompany(companyservice.getSellertax());
allApiLog.setIdentityId(companyservice.getIdentity());
allApiLog.setCreateTime(new Date());
allApiLog.setRequestId(UUID.randomUUID().toString());
//封装实体类 //封装实体类
BeanUtils.copyProperties(invoiceDeliveryDTO, invoiceDelivery); BeanUtils.copyProperties(invoiceDeliveryDTO, invoiceDelivery);
invoiceDelivery.setJflx(dto.getJflx()); invoiceDelivery.setJflx(dto.getJflx());
@ -117,27 +97,25 @@ public class InvoiceDeliveryServiceImpl implements InvoiceDeliveryService {
invoiceDelivery.setType("1"); invoiceDelivery.setType("1");
invoiceDelivery.setClerk(sysUser.getUserId()); invoiceDelivery.setClerk(sysUser.getUserId());
invoiceDelivery.setCreateTime(new Date()); invoiceDelivery.setCreateTime(new Date());
invoiceDelivery.setSource(ChannelSource.PLATFORM.getCode());
if ("0000".equals(code) && StrUtil.isNotEmpty(data)) { if ("0000".equals(code) && StrUtil.isNotEmpty(data)) {
//存入调用日志表
allApiLogMapper.insertInvoiceAllApiLog(allApiLog);
//将数据存入业务表 //将数据存入业务表
invoiceDelivery.setStatus("0"); invoiceDelivery.setStatus("0");
invoiceDeliveryMapper.insertInvoiceDelivery(invoiceDelivery); invoiceDeliveryMapper.insertInvoiceDelivery(invoiceDelivery);
} else { } else {
//存入日志调用表
allApiLogMapper.insertInvoiceAllApiLog(allApiLog);
//将数据存入业务表 //将数据存入业务表
invoiceDelivery.setStatus("1"); invoiceDelivery.setStatus("1");
invoiceDeliveryMapper.insertInvoiceDelivery(invoiceDelivery); invoiceDeliveryMapper.insertInvoiceDelivery(invoiceDelivery);
return new HXResponse(msg); log.error("【发票交付】API请求异常,外部报文返回code非0000。错误id{},错误信息:{}", invoiceDelivery.getId(),msg);
return AjaxResult.error(msg);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("【金四服务类】【金财数科】【申请红字信息表】API请求异常,外部报文返回code非0000。错误信息:{}", e.getMessage()); log.error("【发票交付】API请求异常,外部报文返回code非0000。错误信息:{}", e.getMessage());
return new HXResponse("发票支付接口异常"); return AjaxResult.error("发票支付接口异常");
} }
} }
return new HXResponse("0000", "处理成功"); return AjaxResult.success("0000", "处理成功");
} }
} }

@ -0,0 +1,196 @@
package com.jianshui.platform.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.jianshui.common.constant.InvoiceCommonConstants;
import com.jianshui.common.constant.WebServiceConstant;
import com.jianshui.common.core.domain.AjaxResult;
import com.jianshui.common.core.domain.entity.Companyservice;
import com.jianshui.common.core.domain.entity.SysUser;
import com.jianshui.common.utils.SecurityUtils;
import com.jianshui.common.utils.jcsk.ApiHttp;
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.service.InvoiceDownloadService;
import com.jianshui.platform.utils.BatchDownloadUtils;
import com.jianshui.platform.utils.InvoiceAllYhdjUtils;
import com.jianshui.system.domain.InvoiceAllYhdj;
import com.jianshui.system.mapper.CompanyserviceMapper;
import com.jianshui.system.mapper.SysUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Author: kane
* @Description: 发票下载业务层
* @CreateTime: 2023-06-08 14:36
* @Version: 1.0
**/
@Service
@Slf4j
public class InvoiceDownloadServiceImpl implements InvoiceDownloadService {
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private CompanyserviceMapper companyServiceMapper;
@Autowired
private InvoiceMapper invoiceMapper;
/**
* 功能描述: 发票pfd版下载
* @param ids
* @param response
* @return : java.lang.Object
*/
@Override
public Object dowmLoadPdf(Long[] ids, HttpServletResponse response) {
//判空
if (ids == null) {
return AjaxResult.error(InvoiceCommonConstants.INVOICEINFORMATIONISEMPTY);
}
//获取用户id
Long userId = SecurityUtils.getUserId();
//根据用户id获取用户信息
SysUser sysUser = sysUserMapper.selectUserById(userId);
//根据企业id获取企业信息
Companyservice companyservice = companyServiceMapper.selectCompanyserviceByCompanyid(sysUser.getCompanyId());
//获取登记用户信息
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils();
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice);
if (BeanUtil.isEmpty(userInfo)) {
return AjaxResult.error(InvoiceCommonConstants.NOINFORMATIONISFOUND);
}
//pfd文件集合
List<String> pdfList = new ArrayList<>();
for (Long id : ids) {
Invoice invoice = invoiceMapper.selectInvoiceById(id);
String invoicePdfUrl = invoice.getInvoicePdfUrl();
if (invoicePdfUrl != null) {
pdfList.add(invoicePdfUrl);
} else {
//获取pfd下载地址
//封装请求实体类
FileAcquisitionTwoDTO fileAcquisitionDTO = new FileAcquisitionTwoDTO();
//发送同步请求
fileAcquisitionDTO.setAsync(InvoiceCommonConstants.SYNC);
fileAcquisitionDTO.setNsrsbh(userInfo.getNsrsbh());
fileAcquisitionDTO.setBsrysfzjhm(userInfo.getBsrysfzjhm());
fileAcquisitionDTO.setDqbm(userInfo.getDqbm());
Map<String, Object> map = new JSONObject();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InvoiceCommonConstants.DATEFORMAT);
map.put(InvoiceCommonConstants.FPHM, invoice.getFphm());
Date kprq = invoice.getKprq();
//修改日期格式(请求接口要求)
String kprqFormat = simpleDateFormat.format(kprq);
map.put(InvoiceCommonConstants.KPRQ, kprqFormat);
fileAcquisitionDTO.setJsonData(map);
cn.hutool.json.JSONObject result = null;
try {
result = ApiHttp.request(WebServiceConstant.FPEWMXZ, WebServiceConstant.URL, fileAcquisitionDTO, companyservice);
String code = result.get(InvoiceCommonConstants.CODE) != null ? result.get(InvoiceCommonConstants.CODE).toString() : "";
String msg = result.get(InvoiceCommonConstants.MSG) != null ? result.get(InvoiceCommonConstants.MSG).toString() : "";
String data = result.get(InvoiceCommonConstants.DATA) != null ? result.get(InvoiceCommonConstants.DATA).toString() : "";
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);
} else {
return AjaxResult.error(msg);
}
} catch (Exception e) {
e.printStackTrace();
log.error("【金四服务类】【金财数科】【获取发票下载地址】API请求异常,外部报文返回code非0000。错误信息:{}", e.getMessage());
return AjaxResult.error(InvoiceCommonConstants.DOWNLOADADDRESSERROR);
}
}
}
//下载pfd文件
BatchDownloadUtils.downloadAndZipFiles(pdfList,InvoiceCommonConstants.PDFSTATUS,response);
return AjaxResult.success(InvoiceCommonConstants.DOWNLOADSUCCESSCODE);
}
/**
* 功能描述: 发票ofd版下载
* @param ids
* @param response
* @return : java.lang.Object
*/
@Override
public Object dowmLoadOfd(Long[] ids, HttpServletResponse response) {
//判空
if (ids == null) {
return AjaxResult.error(InvoiceCommonConstants.INVOICEINFORMATIONISEMPTY);
}
//获取用户id
Long userId = SecurityUtils.getUserId();
//根据用户id获取用户信息
SysUser sysUser = sysUserMapper.selectUserById(userId);
//根据企业id获取企业信息
Companyservice companyservice = companyServiceMapper.selectCompanyserviceByCompanyid(sysUser.getCompanyId());
//获取登记用户信息
InvoiceAllYhdjUtils invoiceAllYhdjUtils = new InvoiceAllYhdjUtils();
InvoiceAllYhdj userInfo = invoiceAllYhdjUtils.getUserInfo(companyservice);
if (BeanUtil.isEmpty(userInfo)) {
return new HXResponse(InvoiceCommonConstants.NOINFORMATIONISFOUND);
}
//ofd文件集合
List<String> ofdList = new ArrayList<>();
for (Long id : ids) {
Invoice invoice = invoiceMapper.selectInvoiceById(id);
String invoiceOfdUrl = invoice.getcOfdUrl();
if (invoiceOfdUrl != null) {
ofdList.add(invoiceOfdUrl);
} else {
//获取ofd下载地址
//封装请求实体类
FileAcquisitionTwoDTO fileAcquisitionDTO = new FileAcquisitionTwoDTO();
//发送同步请求
fileAcquisitionDTO.setAsync(InvoiceCommonConstants.SYNC);
fileAcquisitionDTO.setNsrsbh(userInfo.getNsrsbh());
fileAcquisitionDTO.setBsrysfzjhm(userInfo.getBsrysfzjhm());
fileAcquisitionDTO.setDqbm(userInfo.getDqbm());
Map<String, Object> map = new JSONObject();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InvoiceCommonConstants.DATEFORMAT);
map.put(InvoiceCommonConstants.FPHM, invoice.getFphm());
Date kprq = invoice.getKprq();
//修改日期格式(请求接口要求)
String kprqFormat = simpleDateFormat.format(kprq);
map.put(InvoiceCommonConstants.KPRQ, kprqFormat);
fileAcquisitionDTO.setJsonData(map);
cn.hutool.json.JSONObject result = null;
try {
result = ApiHttp.request(WebServiceConstant.FPEWMXZ, WebServiceConstant.URL, fileAcquisitionDTO, companyservice);
String code = result.get(InvoiceCommonConstants.CODE) != null ? result.get(InvoiceCommonConstants.CODE).toString() : "";
String msg = result.get(InvoiceCommonConstants.MSG) != null ? result.get(InvoiceCommonConstants.MSG).toString() : "";
String data = result.get(InvoiceCommonConstants.DATA) != null ? result.get(InvoiceCommonConstants.DATA).toString() : "";
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);
} else {
return AjaxResult.error(msg);
}
} catch (Exception e) {
e.printStackTrace();
log.error("【金四服务类】【金财数科】【获取发票下载地址】API请求异常,外部报文返回code非0000。错误信息:{}", e.getMessage());
return AjaxResult.error(InvoiceCommonConstants.DOWNLOADADDRESSERROR);
}
}
}
//下载ofd文件集合
BatchDownloadUtils.downloadAndZipFiles(ofdList,InvoiceCommonConstants.OFDSTATUS,response);
return AjaxResult.success(InvoiceCommonConstants.DOWNLOADSUCCESSCODE);
}
}

@ -0,0 +1,125 @@
package com.jianshui.platform.utils;
import com.jianshui.common.constant.InvoiceCommonConstants;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* @Author: kane
* @Description: 批量下载工具类
* @CreateTime: 2023-06-09 15:46
* @Version: 1.0
**/
public class BatchDownloadUtils {
/**
* 功能描述: 批量下载
* @param status 文件类型0-pfd 1-ofd
* @param urls
* @return : void
*/
public static void downloadAndZipFiles(List<String> urls, String status, HttpServletResponse response) {
Date now = new Date();
SimpleDateFormat format = new SimpleDateFormat(InvoiceCommonConstants.DATEFORMAT);
String name = format.format(now);
String zipFileName = name + ".zip";
OutputStream ops = null;
ZipOutputStream zos = null;
InputStream inputStream = null;
try {
response.setHeader("Content-Disposition", "attachment;filename=" + zipFileName);
response.setCharacterEncoding("utf-8");
ops = response.getOutputStream();
zos = new ZipOutputStream(ops);
for (String url : urls) {
if (StringUtils.hasText(url)) {
URL downloadUrl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) downloadUrl.openConnection();
int responseCode = httpConn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
String fileName = getFileName(httpConn, status);
inputStream = httpConn.getInputStream();
ZipEntry zipEntry = new ZipEntry(fileName);
zos.putNextEntry(zipEntry);
int bytesRead = -1;
byte[] buffer = new byte[4096];
while ((bytesRead = inputStream.read(buffer)) != -1) {
zos.write(buffer, 0, bytesRead);
}
}
httpConn.disconnect();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}finally {
if (inputStream != null){
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (zos != null){
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (ops != null){
try {
ops.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* 功能描述: 获取下载后的文件名
* @param httpConn
* @return : java.lang.String
*/
private static String getFileName(HttpURLConnection httpConn, String status) {
String fileName = "";
String disposition = httpConn.getHeaderField("Content-Disposition");
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InvoiceCommonConstants.DATEFORMAT);
if (disposition != null) {
int index = disposition.indexOf("filename=");
if (index > 0) {
fileName = disposition.substring(index + 10, disposition.length() - 1);
if ("0".equals(status)) {
String name = simpleDateFormat.format(date);
fileName = name + ".pdf";
} else {
String name = simpleDateFormat.format(date);
fileName = name + ".ofd";
}
}
}
if (StringUtils.isEmpty(fileName)) {
fileName = httpConn.getURL().getFile().substring(httpConn.getURL().getFile().lastIndexOf("/") + 1);
if ("0".equals(status)) {
String name = simpleDateFormat.format(date);
fileName = name + ".pdf";
} else {
String name = simpleDateFormat.format(date);
fileName = name + ".ofd";
}
}
return fileName;
}
}

@ -18,10 +18,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="clerk" column="clerk" /> <result property="clerk" column="clerk" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="source" column="source" />
</resultMap> </resultMap>
<sql id="selectInvoiceDeliveryVo"> <sql id="selectInvoiceDeliveryVo">
select id, bsrysfzjhm, dqbm, jflx, fphm, gmflxdh, gmfyx, nsrsbh, status, type, clerk, create_time, remark from invoice_delivery select id, bsrysfzjhm, dqbm, jflx, fphm, gmflxdh, gmfyx, nsrsbh, status, type, clerk, create_time, remark, source from invoice_delivery
</sql> </sql>
<select id="selectInvoiceDeliveryList" parameterType="InvoiceDelivery" resultMap="InvoiceDeliveryResult"> <select id="selectInvoiceDeliveryList" parameterType="InvoiceDelivery" resultMap="InvoiceDeliveryResult">
@ -37,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''"> and status = #{status}</if> <if test="status != null and status != ''"> and status = #{status}</if>
<if test="type != null and type != ''"> and type = #{type}</if> <if test="type != null and type != ''"> and type = #{type}</if>
<if test="clerk != null "> and clerk = #{clerk}</if> <if test="clerk != null "> and clerk = #{clerk}</if>
<if test="source != null and source != ''"> and source = #{source}</if>
</where> </where>
</select> </select>
@ -60,6 +62,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clerk != null">clerk,</if> <if test="clerk != null">clerk,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
<if test="source != null and source != ''">source,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="bsrysfzjhm != null and bsrysfzjhm != ''">#{bsrysfzjhm},</if> <if test="bsrysfzjhm != null and bsrysfzjhm != ''">#{bsrysfzjhm},</if>
@ -74,6 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clerk != null">#{clerk},</if> <if test="clerk != null">#{clerk},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
<if test="source != null and source != ''">#{source},</if>
</trim> </trim>
</insert> </insert>
@ -92,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="clerk != null">clerk = #{clerk},</if> <if test="clerk != null">clerk = #{clerk},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="source != null and source != ''">source = #{source},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>

Loading…
Cancel
Save