From c9b8fefcfa84403306477a4e52e7c22d7eb16104 Mon Sep 17 00:00:00 2001 From: jiangxiaoming <jiangxiaoming@seaskysh.com> Date: Mon, 23 Dec 2024 10:09:41 +0800 Subject: [PATCH] 1111 --- .../web/api/IBusinessInvoicingController.java | 3 + .../template/web/api/IFileController.java | 4 + .../web/dto/request/InvoiceRequest.java | 6 +- .../web/dto/result/InvoiceResult.java | 4 + .../template/business/api/FileService.java | 11 ++ .../business/dao/xml/InvoiceMapper.xml | 8 +- .../business/service/FileServiceImpl.java | 112 ++++++++++++++++++ .../seasky/template/utils/UserInfoUtil.java | 43 +++++++ .../BusinessInvoicingController.java | 1 + .../web/controller/FileController.java | 15 +++ 10 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 ServiceSiteCommon/src/main/java/com/seasky/template/business/api/FileService.java create mode 100644 ServiceSiteCommon/src/main/java/com/seasky/template/business/service/FileServiceImpl.java create mode 100644 ServiceSiteCommon/src/main/java/com/seasky/template/utils/UserInfoUtil.java diff --git a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IBusinessInvoicingController.java b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IBusinessInvoicingController.java index 40e1392..9810037 100644 --- a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IBusinessInvoicingController.java +++ b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IBusinessInvoicingController.java @@ -11,6 +11,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * @Author jxm * @Date 2024/12/19 12:52 @@ -23,4 +25,5 @@ public interface IBusinessInvoicingController { @PostMapping("page") Result<InvoiceResult> page(@Validated @RequestBody InvoiceRequest invoiceRequest); + } diff --git a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IFileController.java b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IFileController.java index 0c46de3..6c6913c 100644 --- a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IFileController.java +++ b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/api/IFileController.java @@ -6,6 +6,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @Api(tags = "鏂囦欢闄勪欢") @@ -15,4 +16,7 @@ public interface IFileController { @PostMapping("/downFile") Result<Object> downFile(@RequestBody List<String> fileId) throws Exception; + @ApiOperation("涓嬭浇鍗曚釜鏂囦欢") + @PostMapping("/downSingleFile") + Result<Object> downSingleFile(@RequestParam("fileId") String fileId) throws Exception; } diff --git a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/request/InvoiceRequest.java b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/request/InvoiceRequest.java index a319ea1..65df15f 100644 --- a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/request/InvoiceRequest.java +++ b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/request/InvoiceRequest.java @@ -36,11 +36,13 @@ public class InvoiceRequest { private String isSend; @ApiModelProperty(value = "寮€绁ㄧ被鍨�") private String invoiceType; - + @ApiModelProperty(value = "鎶ご") + private String buyerName; + @ApiModelProperty(value = "绋庡彿") + private String buyerCode; @NotNull @ApiModelProperty("pageIndex") private Integer pageIndex; - @NotNull @ApiModelProperty("pageSize") private Integer pageSize; diff --git a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/result/InvoiceResult.java b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/result/InvoiceResult.java index 7f9c498..714dfd7 100644 --- a/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/result/InvoiceResult.java +++ b/ServiceSiteCommon/facade/src/main/java/com/seasky/template/web/dto/result/InvoiceResult.java @@ -1,5 +1,6 @@ package com.seasky.template.web.dto.result; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -14,6 +15,7 @@ import java.util.Date; * @Date 2024/12/19 10:44 * @Version 1.0 */ +@JsonInclude(JsonInclude.Include.ALWAYS) // 鎬绘槸鍖呮嫭鎵€鏈夊瓧娈碉紝鍖呮嫭null鍊� @NoArgsConstructor @AllArgsConstructor @Data @@ -46,4 +48,6 @@ public class InvoiceResult { private String isSend; @ApiModelProperty(value = "绋庨") private BigDecimal tax; + @ApiModelProperty(value = "寮€绁ㄨ鏄庯紙澶囨敞锛�") + private String remark; } diff --git a/ServiceSiteCommon/src/main/java/com/seasky/template/business/api/FileService.java b/ServiceSiteCommon/src/main/java/com/seasky/template/business/api/FileService.java new file mode 100644 index 0000000..d166577 --- /dev/null +++ b/ServiceSiteCommon/src/main/java/com/seasky/template/business/api/FileService.java @@ -0,0 +1,11 @@ +package com.seasky.template.business.api; + +import com.seasky.core.base.BaseService; +import com.seasky.template.business.entity.Test; + +import java.io.IOException; + +public interface FileService{ + + void downSingleFile(String fileId) throws IOException; +} diff --git a/ServiceSiteCommon/src/main/java/com/seasky/template/business/dao/xml/InvoiceMapper.xml b/ServiceSiteCommon/src/main/java/com/seasky/template/business/dao/xml/InvoiceMapper.xml index a01f4e8..41c758a 100644 --- a/ServiceSiteCommon/src/main/java/com/seasky/template/business/dao/xml/InvoiceMapper.xml +++ b/ServiceSiteCommon/src/main/java/com/seasky/template/business/dao/xml/InvoiceMapper.xml @@ -40,7 +40,7 @@ a.buyer_name, a.invoice_date, a.invoice_state, - a.is_send, + a.is_send, a.remark, COALESCE(SUM(d.tax), 0) AS tax -- 浣跨敤 COALESCE 澶勭悊 NULL 鍊硷紝杩斿洖 0 浣滀负榛樿鍊� FROM t_invoice a @@ -85,6 +85,12 @@ <if test = "qry.amountEnd!=null"> and c.income_amount <![CDATA[<=]]> #{qry.amountEnd} </if> + <if test = "qry.buyerName!=null and qry.buyerName!=''"> + and a.buyer_name like concat(#{qry.buyerName}, '%') + </if> + <if test = "qry.buyerCode!=null and qry.buyerCode!=''"> + and a.buyer_code like concat(#{qry.buyerCode}, '%') + </if> GROUP BY c.bill_no, c.income_date, c.income_amount, a.id, a.invoice_no, a.invoice_code, a.invoice_type, diff --git a/ServiceSiteCommon/src/main/java/com/seasky/template/business/service/FileServiceImpl.java b/ServiceSiteCommon/src/main/java/com/seasky/template/business/service/FileServiceImpl.java new file mode 100644 index 0000000..8476a85 --- /dev/null +++ b/ServiceSiteCommon/src/main/java/com/seasky/template/business/service/FileServiceImpl.java @@ -0,0 +1,112 @@ +package com.seasky.template.business.service; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.seasky.core.common.Error; +import com.seasky.core.common.ResponseCode; +import com.seasky.core.exception.DataBusinessException; +import com.seasky.core.util.ExceptionUtil; +import com.seasky.template.business.api.FileService; +import com.seasky.template.utils.HttpClientUtil; +import com.seasky.template.utils.PropertyUtil; +import com.seasky.template.utils.StringToMd5Hash; +import com.seasky.template.utils.UserInfoUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; + +/** + * @Author jxm + * @Date 2024/12/23 9:08 + * @Version 1.0 + */ +@Service +public class FileServiceImpl implements FileService { + @Autowired + UserInfoUtil userInfoUtil; + @Resource + PropertyUtil propertyUtil; + @Resource + HttpServletResponse response; + @Override + public void downSingleFile(String fileId) throws IOException { + String fileUrl = propertyUtil.getFileUrl(); + String fileKey = propertyUtil.getFileKey(); + String fileSecre = propertyUtil.getFileSecre(); + if (Objects.isNull(fileUrl)) throw ExceptionUtil.getException(null, "璇烽厤缃奖鍍忓簱鎺ュ彛鍦板潃fileUrl锛�"); + if (Objects.isNull(fileKey)) throw ExceptionUtil.getException(null, "璇烽厤缃奖鍍忓簱鎺ュ彛fileKey锛�"); + if (Objects.isNull(fileSecre)) throw ExceptionUtil.getException(null, "璇烽厤缃奖鍍忓簱鎺ュ彛fileSecre锛�"); + String url = fileUrl + "/FileInfo/DownLoadFileInfo"; + Map<String, Object> map = new HashMap<>(); + LocalDateTime currentDate = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH"); + String formattedDate = currentDate.plusHours(1).format(formatter); + String token = fileKey + "|" + formattedDate + "|" + fileSecre; + map.put("Token", StringToMd5Hash.toMD5(token)); + map.put("Key", fileKey); + String code = userInfoUtil.getLoginInfoOut().getUserName(); + map.put("UserName", code); + List<Map<String, Object>> filemap=new ArrayList<>(); + List<Map<String,Object>> files = new ArrayList<>(); + Map<String, Object> m=new HashMap<>(); + m.put("SystemID","77777777-7777-7777-7777-111111111111"); + m.put("fileID",fileId); + filemap.add(m); + map.put("Data", filemap); + String ff = HttpClientUtil.doPostJson(url, JSONObject.toJSONString(map)); + JSONObject obj1 = JSONObject.parseObject(ff); + if (obj1.getString("isSuccess") == null || !"true".equals(obj1.getString("isSuccess"))) { + throw new DataBusinessException( + Error.builder() + .message(obj1.getString("errorMessage") == null ? "涓嬭浇闄勪欢澶辫触!" : obj1.getString("errorMessage")) + .responseCode(ResponseCode.DATA_ACCESS_EXCEPTION) + .build() + ); + } + JSONArray data = obj1.getJSONArray("data"); + data.stream().filter(o -> o instanceof JSONObject) + .forEach(o -> { + JSONObject jsonObject = (JSONObject) o; + String fileName = jsonObject.getString("fileName"); + byte[] bytesArr = jsonObject.getBytes("fileStream"); + Map<String, Object> mapData = new HashMap<>(); + mapData.put("fileName", fileName); + mapData.put("file", bytesArr); + files.add(mapData); + }); + if(!files.isEmpty()){ + Map<String, Object> objectMap = files.get(0); + String fileName = objectMap.get("fileName").toString(); + byte[] bytesArr = (byte[])objectMap.get("file"); + + // 1. 鑾峰彇鏂囦欢鐨� MIME 绫诲瀷 + Path tempFile = Files.createTempFile("download", fileName.substring(fileName.lastIndexOf("."))); + Files.write(tempFile, bytesArr); + String mimeType = Files.probeContentType(tempFile); + Files.delete(tempFile); + if (mimeType == null) { + mimeType = "application/octet-stream"; // 濡傛灉鏃犳硶璇嗗埆 MIME 绫诲瀷锛屼娇鐢ㄩ粯璁ゅ€� + } + + String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\""); + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); // 纭繚鍓嶇鍙互璁块棶鏂囦欢鍚� + + response.setContentType(mimeType); + ServletOutputStream outputStream = response.getOutputStream(); + outputStream.write(bytesArr); + outputStream.close(); + } + + } +} diff --git a/ServiceSiteCommon/src/main/java/com/seasky/template/utils/UserInfoUtil.java b/ServiceSiteCommon/src/main/java/com/seasky/template/utils/UserInfoUtil.java new file mode 100644 index 0000000..5b2abd6 --- /dev/null +++ b/ServiceSiteCommon/src/main/java/com/seasky/template/utils/UserInfoUtil.java @@ -0,0 +1,43 @@ +package com.seasky.template.utils; + +import com.seasky.template.business.api.LoginService; +import com.seasky.template.web.dto.request.LoginTokenRequest; +import com.seasky.template.web.dto.result.UserInfoResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; + +/** + * @Author jxm + * @Date 2024/9/19 12:56 + * @Version 1.0 + */ +@Component +public class UserInfoUtil { + @Autowired + LoginService loginQueryService; + public UserInfoResult getLoginInfoOut() { + RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); + HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest(); + LoginTokenRequest qry=new LoginTokenRequest(); + Cookie[] cookies = request.getCookies(); + if (cookies != null) { + for (Cookie cookie : cookies) { + if(cookie.getName().equals("SFP_Verify_Cookie")) + { + qry.setToken(cookie.getValue()); + break; + } + } + + } + UserInfoResult loginInfoOut= loginQueryService.GetLoginToken(qry); + if(loginInfoOut==null) + loginInfoOut=new UserInfoResult(); + return loginInfoOut; + } +} diff --git a/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/BusinessInvoicingController.java b/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/BusinessInvoicingController.java index 93038b1..26b99d5 100644 --- a/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/BusinessInvoicingController.java +++ b/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/BusinessInvoicingController.java @@ -47,4 +47,5 @@ public class BusinessInvoicingController implements IBusinessInvoicingController Pagination fromPage = Pagination.fromPage(page); return ok(ResponseCode.SUCCESS,fromPage); } + } diff --git a/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/FileController.java b/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/FileController.java index 5f0bd02..d6e5e8e 100644 --- a/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/FileController.java +++ b/ServiceSiteCommon/src/main/java/com/seasky/template/web/controller/FileController.java @@ -1,13 +1,28 @@ package com.seasky.template.web.controller; +import com.seasky.core.common.ResponseCode; import com.seasky.core.common.Result; +import com.seasky.template.business.api.FileService; import com.seasky.template.web.api.IFileController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; import java.util.List; +import static com.seasky.core.common.Response.ok; + +@RestController public class FileController implements IFileController { + @Autowired + FileService fileService; @Override public Result<Object> downFile(List<String> fileId) throws Exception { return null; } + + @Override + public Result<Object> downSingleFile(String fileId) throws Exception { + fileService.downSingleFile(fileId); + return ok(ResponseCode.SUCCESS); + } } -- GitLab