feature: 发票预览文件下载

beta
kk 2 years ago
parent a5a79dab15
commit eee31b62ab
  1. 72
      jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java
  2. 2
      jianshui-admin/src/main/resources/application-dev.yml
  3. 13
      jianshui-invoice/src/main/java/com/jianshui/invoice/domain/InvoiceFile.java
  4. 14
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java
  5. 7
      jianshui-invoice/src/main/resources/mapper/invoice/InvoiceFileMapper.xml
  6. 9
      jianshui-ui/src/api/sdInvoicefile/sdinvoicefile.js
  7. 30
      jianshui-ui/src/views/sdinvoicefile/index.vue

@ -5,12 +5,15 @@ import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.codec.Base64Encoder; import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.jianshui.common.core.domain.AjaxResult; 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.enums.ErrorCode; import com.jianshui.common.enums.ErrorCode;
@ -28,6 +31,7 @@ import com.jianshui.invoice.domain.ele.FindRedInfoDTO;
import com.jianshui.invoice.domain.ele.HZSQDMessage; import com.jianshui.invoice.domain.ele.HZSQDMessage;
import com.jianshui.invoice.mapper.InvoiceBackMapper; import com.jianshui.invoice.mapper.InvoiceBackMapper;
import com.jianshui.invoice.mapper.InvoiceFileMapper; import com.jianshui.invoice.mapper.InvoiceFileMapper;
import com.jianshui.invoice.service.impl.api.ElephantInvoiceApiV6ServiceImpl;
import com.jianshui.invoice.task.AddInvoiceBatchTask; import com.jianshui.invoice.task.AddInvoiceBatchTask;
import com.jianshui.invoice.task.InvoiceBackTask; import com.jianshui.invoice.task.InvoiceBackTask;
import com.jianshui.invoice.utils.elephant.ElephantUtils; import com.jianshui.invoice.utils.elephant.ElephantUtils;
@ -2083,33 +2087,63 @@ public class InvoiceController {
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.Void", example = "1130", required = true), @ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.Void", example = "1130", required = true),
@ApiImplicitParam(name = "order", value = "请求体", dataType = "java.lang.Void", required = true)}) @ApiImplicitParam(name = "order", value = "请求体", dataType = "java.lang.Void", required = true)})
@PostMapping({"/api/invoice/v1/QuerySdInvoiceFileDownload/{identity}", "/api/invoice/v1/QuerySdInvoiceFileDownload", "/invoice/QuerySdInvoiceFileDownload"}) @PostMapping({"/api/invoice/v1/QuerySdInvoiceFileDownload/{identity}", "/api/invoice/v1/QuerySdInvoiceFileDownload", "/invoice/QuerySdInvoiceFileDownload"})
public Object QuerySdInvoiceFileDownload(HttpServletRequest request, String identity) throws Exception { public void QuerySdInvoiceFileDownload(HttpServletResponse response, @RequestBody JSONObject jsonParam) throws Exception {
if (StringUtils.isEmpty(identity)) { if (ObjectUtil.isEmpty(jsonParam)) {
return AjaxResult.error(ErrorCode.EMPTY_IDENTITY); return;
} }
Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity); String ty = jsonParam.get("ty") != null ? jsonParam.get("ty").toString() : "";
if (companyservice == null) { String id = jsonParam.get("id") != null ? jsonParam.get("id").toString() : "";
return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND);
InvoiceFile invoiceFile = invoiceFileMapper.selectInvoiceFileById(id);
if (BeanUtil.isEmpty(invoiceFile) || StrUtil.isEmpty(invoiceFile.getFileContent())) {
return;
} }
String fileName = invoiceFile.getFileName();
String fphm = invoiceFile.getFphm();
String tax = invoiceFile.getTax();
String identity = invoiceFile.getIdentity();
// 获得入口报文适配器 try {
String requestAdapterKey = serviceManageService.getRequestAdapterKey("invoice", companyservice.getCompanyid()); JSONObject decryptResult = new JSONObject();
IInvoiceRequestService invoiceRequestService = invoiceRequestFactory.getService(requestAdapterKey); decryptResult.put("XHFSBH", tax);
JSONObject decryptResult = invoiceRequestService.decrypt(request, companyservice, ""); decryptResult.put("ENTID", "");
decryptResult.put("SDFPHM", fphm);
decryptResult.put("WJLX", ty);
// 获得请求实例,并且进行扣费 IInvoiceApiService invoiceService = new ElephantInvoiceApiV6ServiceImpl();
String serviceKey = serviceManageService.getCompanyServiceSupplier("invoice", companyservice.getCompanyid()); Companyservice companyservice = new Companyservice();
serviceManageService.companyConsume("invoice", companyservice.getCompanyid()); companyservice.setCompanyid(Long.valueOf(identity));
HXResponse result = invoiceService.QuerySdInvoiceFile(decryptResult, companyservice);
IInvoiceApiService invoiceService = invoiceServiceFactory.getService(serviceKey); String data = result.get("data") != null ? result.get("data").toString() : "";
HXResponse result = invoiceService.QuerySdInvoiceFile(decryptResult, companyservice);
String responseAdapterKey = serviceManageService.getResponseAdapterKey("invoice", companyservice.getCompanyid()); Gson gson = new Gson();
IInvoiceResponseService invoiceResponseService = invoiceResponseFactory.getService(responseAdapterKey); JsonObject jsonObject = gson.fromJson(data, JsonObject.class);
return invoiceResponseService.response(result, companyservice, ""); JsonArray fileItemList = jsonObject.getAsJsonArray("FILEITEMLIST");
String fileContent = "";
if(!fileItemList.isEmpty()){
JsonObject fileItem = fileItemList.get(0).getAsJsonObject();
fileContent = fileItem.get("FILECONTENT").getAsString();
}
byte[] buffer = Base64Decoder.decode(fileContent); // 将文件流字符串转换为字节数组
response.reset();
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".pdf");
response.addHeader("Content-Length", "" + buffer.length);
response.setContentType("application/pdf");
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
outputStream.write(buffer);
outputStream.flush();
outputStream.close(); // 关闭输出流
} catch (IOException ex) {
ex.printStackTrace();
}
} }
@ -2135,7 +2169,7 @@ public class InvoiceController {
String content = invoiceFile.getFileContent(); String content = invoiceFile.getFileContent();
String co = convertPdfBase64ToImageBase64(content); String co = convertPdfBase64ToImageBase64(content);
return "data:image/jpeg;base64,"+co; return "data:image/jpeg;base64," + co;
} }

@ -91,6 +91,8 @@ ele_check_url: https://openapi.zncspt.com/api/
elephant_entcode_check: 91370102MA3UD2FG21 elephant_entcode_check: 91370102MA3UD2FG21
# 文件下载地址 # 文件下载地址
elephant_invoice_file: http://127.0.0.1:8081/invoice/fileUrl/ elephant_invoice_file: http://127.0.0.1:8081/invoice/fileUrl/
# 德才定制 放到数据库
#elephant_invoice_file_dc: http://127.0.0.1:8088/sdFile/
# 大象V6数电对应平台地址 # 大象V6数电对应平台地址
ele_url_v6: https://js.ele12.com/order-api ele_url_v6: https://js.ele12.com/order-api
#ele_url_v6: http://192.168.3.60:18108/order-api #ele_url_v6: http://192.168.3.60:18108/order-api

@ -38,7 +38,18 @@ public class InvoiceFile extends BaseEntity
@Excel(name = "税号") @Excel(name = "税号")
private String tax; private String tax;
public void setId(String id) @Excel(name = "发票号码")
private String fphm;
public String getFphm() {
return fphm;
}
public void setFphm(String fphm) {
this.fphm = fphm;
}
public void setId(String id)
{ {
this.id = id; this.id = id;
} }

@ -65,6 +65,7 @@ import com.jianshui.system.domain.InvoiceAllApiLog;
import com.jianshui.system.mapper.CompanyserviceMapper; import com.jianshui.system.mapper.CompanyserviceMapper;
import com.jianshui.system.mapper.CompanyservicePropMapper; import com.jianshui.system.mapper.CompanyservicePropMapper;
import com.jianshui.system.mapper.InvoiceAllApiLogMapper; import com.jianshui.system.mapper.InvoiceAllApiLogMapper;
import com.jianshui.system.service.ICompanyservicePropService;
import com.jianshui.system.service.ISysConfigService; import com.jianshui.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -128,10 +129,12 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
private InvoiceFileMapper invoiceFileMapper; private InvoiceFileMapper invoiceFileMapper;
private static String ELE_File_URL; private static String ELE_File_URL;
private static String ELE_File_URL_DC;
static { static {
Environment environment = SpringUtils.getBean(Environment.class); Environment environment = SpringUtils.getBean(Environment.class);
ELE_File_URL = environment.getProperty("elephant_invoice_file"); ELE_File_URL = environment.getProperty("elephant_invoice_file");
ELE_File_URL_DC = environment.getProperty("elephant_invoice_file_dc");
} }
/** /**
@ -619,6 +622,13 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
// 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流 // 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流
invoice.setInvoicePdfUrl(ELE_File_URL + fileId); invoice.setInvoicePdfUrl(ELE_File_URL + fileId);
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class);
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc");
if (secretIdProp != null) {
invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId);
}
} }
// end // end
@ -1294,10 +1304,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
*/ */
@Override @Override
public HXResponse uploadRedInfo(Redinfo redinfo, Companyservice companyservice) { public HXResponse uploadRedInfo(Redinfo redinfo, Companyservice companyservice) {
// TODO: 2023/10/23 一步的红字上传接口
// 处理redinfo // 处理redinfo
redinfo.setCompanyId(companyservice.getCompanyid()); redinfo.setCompanyId(companyservice.getCompanyid());
redinfo.setSystemOrderno(IdUtils.randomSystemOrderno()); redinfo.setSystemOrderno(IdUtils.randomSystemOrderno());

@ -12,10 +12,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="identity" column="identity" /> <result property="identity" column="identity" />
<result property="tax" column="tax" /> <result property="tax" column="tax" />
<result property="fphm" column="fphm" />
</resultMap> </resultMap>
<sql id="selectInvoiceFileVo"> <sql id="selectInvoiceFileVo">
select id, file_id, file_name, file_content, create_time, identity, tax from invoice_file select id, file_id, file_name, file_content, create_time, identity, tax,fphm from invoice_file
</sql> </sql>
<select id="selectInvoiceFileList" parameterType="InvoiceFile" resultMap="InvoiceFileResult"> <select id="selectInvoiceFileList" parameterType="InvoiceFile" resultMap="InvoiceFileResult">
@ -26,6 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="fileContent != null and fileContent != ''"> and file_content = #{fileContent}</if> <if test="fileContent != null and fileContent != ''"> and file_content = #{fileContent}</if>
<if test="identity != null and identity != ''"> and identity = #{identity}</if> <if test="identity != null and identity != ''"> and identity = #{identity}</if>
<if test="tax != null and tax != ''"> and tax = #{tax}</if> <if test="tax != null and tax != ''"> and tax = #{tax}</if>
<if test="fphm != null and fphm != ''"> and fphm = #{fphm}</if>
</where> </where>
</select> </select>
@ -44,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
<if test="identity != null">identity,</if> <if test="identity != null">identity,</if>
<if test="tax != null">tax,</if> <if test="tax != null">tax,</if>
<if test="fphm != fphm">fphm,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if> <if test="id != null">#{id},</if>
@ -53,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
<if test="identity != null">#{identity},</if> <if test="identity != null">#{identity},</if>
<if test="tax != null">#{tax},</if> <if test="tax != null">#{tax},</if>
<if test="fphm != null">#{fphm},</if>
</trim> </trim>
</insert> </insert>
@ -65,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="identity != null">identity = #{identity},</if> <if test="identity != null">identity = #{identity},</if>
<if test="tax != null">tax = #{tax},</if> <if test="tax != null">tax = #{tax},</if>
<if test="fphm != null">fphm = #{fphm},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>

@ -8,3 +8,12 @@ export function getFilePreview(data) {
data: data data: data
}) })
} }
// 下载文件
export function downloadFile(data) {
return request({
url: '/invoice/QuerySdInvoiceFileDownload',
method: 'post',
data: data
})
}

@ -5,9 +5,9 @@
<div class="center-container"> <div class="center-container">
<!-- 下载PDF按钮 --> <!-- 下载PDF按钮 -->
<div style="float:left;"> <div style="float:left;">
<el-button type="primary" @click="downloadPDF" class="download-button">下载PDF</el-button> <el-button type="primary" @click="download('pdf')" class="download-button">下载PDF</el-button>
<el-button type="primary" @click="downloadPDF" class="download-button">下载OFD</el-button> <el-button type="primary" @click="download('ofd')" class="download-button">下载OFD</el-button>
<el-button type="primary" @click="downloadPDF" class="download-button">下载XML</el-button> <el-button type="primary" @click="download('xml')" class="download-button">下载XML</el-button>
</div> </div>
<img :src="invoiceImageUrl" alt="发票图片损坏" class="invoice-image"> <img :src="invoiceImageUrl" alt="发票图片损坏" class="invoice-image">
@ -17,13 +17,14 @@
</template> </template>
<script> <script>
import {getFilePreview} from "@/api/sdInvoicefile/sdinvoicefile"; import {getFilePreview,downloadFile} from "@/api/sdInvoicefile/sdinvoicefile";
export default { export default {
data() { data() {
return { return {
// base64 // base64
invoiceImageUrl: '' invoiceImageUrl: '',
id: ''
}; };
}, },
mounted() { mounted() {
@ -33,19 +34,28 @@ export default {
}, },
methods: { methods: {
filePreview(id){ filePreview(id){
this.id = id;
this.loading = true; this.loading = true;
getFilePreview(id).then(response => { getFilePreview(id).then(response => {
console.info("aa="+response); // console.info("id="+response);
this.invoiceImageUrl = response; this.invoiceImageUrl = response;
// this.$forceUpdate(); // this.$forceUpdate();
}); });
}, },
// PDF // PDF
downloadPDF() { download(ty) {
// PDF const param = {
// 使PDF "ty": ty,
// window.open('your_pdf_download_link.pdf', '_blank'); "id": this.id
}
console.info("param=" + param)
downloadFile(param).then(
response =>{
console.info("请求结束");
}
);
}, },
}, },
}; };

Loading…
Cancel
Save