From 247493f0980f703d163620ccc139b25927c28f8f Mon Sep 17 00:00:00 2001 From: lige <bestlige@outlook.com> Date: 星期二, 05 三月 2024 18:21:03 +0800 Subject: [PATCH] 文件服务器 --- ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjReportController.java | 4 ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReportController.java | 129 ++++++++++++++++++++++++++++++- ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java | 40 ++++++++- ltkj-admin/src/main/resources/application.yml | 13 ++- 4 files changed, 168 insertions(+), 18 deletions(-) diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReportController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReportController.java index 1f5a29b..b8fc5c3 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReportController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReportController.java @@ -2,15 +2,20 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.ltkj.common.core.controller.BaseController; import com.ltkj.common.core.domain.AjaxResult; import com.ltkj.common.core.page.TableDataInfo; +import com.ltkj.common.utils.SecurityUtils; import com.ltkj.common.utils.StringUtils; import com.ltkj.framework.config.UserHoder; import com.ltkj.hosp.domain.*; import com.ltkj.hosp.service.*; +import com.ltkj.mall.mallOrderUtils.TjConstants; +import com.ltkj.web.config.pdfutils.PDFBinaryUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -21,13 +26,13 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.server.session.InMemoryWebSessionStore; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URL; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -236,6 +241,8 @@ return AjaxResult.success("璇ュ鎴峰湪娌℃湁浣撴椤圭洰鏁版嵁锛�"); } + + /** * 灏忕▼搴忕偣鍑讳綋妫�鎶ュ憡鏌ヨ璇︽儏,鏄剧ず韬珮浣撻噸浣撻噸鎸囨暟鏀剁缉鍘嬭垝寮犲帇 */ @@ -314,17 +321,127 @@ } + + + /** * 灏忕▼搴忕偣鍑讳笅杞芥姤鍛� */ @GetMapping("/downloadReport") @ApiOperation(value = "灏忕▼搴�-涓嬭浇鎶ュ憡") public AjaxResult downloadReport(@RequestParam @ApiParam(value = "浣撴鍙�") String tjNumber) { - Map<String, Object> map = new HashMap<>(); - return AjaxResult.success(map); + Map<String,String> res=new HashMap<>(); + LambdaQueryWrapper<TjReport> we = new LambdaQueryWrapper<>(); + we.eq(TjReport::getTjNumber, tjNumber); + we.eq(TjReport::getType, "浣撴鎶ュ憡"); + TjReport one = reportService.getOne(we); + if ("pdf".equals(one.getPrint())){ + res.put("flag","0"); + res.put("url",one.getPath()); + return AjaxResult.success(res); + }else if ("鎶ヨ〃".equals(one.getPrint())){ + res.put("flag","1"); + res.put("url",one.getPath()); + return AjaxResult.success(res); + }else { + return AjaxResult.error("鏆傛棤浣撴鎶ュ憡"); + } } + + @GetMapping("/preview/{flag}/{TjNumber}") + @ApiOperation(value = "涓嬭浇浣撴鎶ュ憡") + public void preview(HttpServletResponse response, @PathVariable("flag") boolean flag, @PathVariable("TjNumber") String tjNumber) { + //淇敼order琛ㄤ腑鐨勪笅杞芥姤鍛婃椂闂翠负褰撳墠鏃堕棿 +// LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); +// updateWrapper.eq(TjOrder::getTjNumber, tjNumber); +// updateWrapper.set(TjOrder::getPrintLastTime, new Date()); +// updateWrapper.set(TjOrder::getDownloadLastTime, new Date()); +// updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END); +// orderService.update(updateWrapper); + + + LambdaQueryWrapper<TjOrder> wq1 = new LambdaQueryWrapper<>(); + wq1.eq(TjOrder::getTjNumber, tjNumber); + TjOrder tjOrder = orderService.getOne(wq1); + + + LambdaQueryWrapper<TjCustomer> wq2 = new LambdaQueryWrapper<>(); + wq2.eq(TjCustomer::getCusId, tjOrder.getUserId()); + TjCustomer tjCustomer = customerService.getOne(wq2); + + + LambdaQueryWrapper<TjReport> we = new LambdaQueryWrapper<>(); + we.eq(TjReport::getTjNumber, tjNumber); + we.eq(TjReport::getType, "浣撴鎶ュ憡"); + TjReport one = reportService.getOne(we); + if (one == null) { + return; + } + final UUID uuid = UUID.randomUUID(); + final String substring = uuid.toString().substring(0, 5); + +// String userId = SecurityUtils.getLoginUser().getUsername(); + PDFBinaryUtil.base64StringToPDF(one.getReport(), FileUtil.mkdir(value).getPath() + "\\" +substring+ tjNumber + tjCustomer.getCusName() + "_浣撴鎶ュ憡.pdf"); + //String filePath = one.getPath(); + String filePath = value + "\\" +substring + tjNumber + tjCustomer.getCusName() + "_浣撴鎶ュ憡.pdf"; + File f = new File(filePath); + if (filePath.isEmpty()) { + System.out.println("鏂囦欢涓嶅瓨鍦紒"); + return; + } + BufferedInputStream br = null; + OutputStream out = null; + FileInputStream fileInputStream = null; + try { + fileInputStream = new FileInputStream(f); + br = new BufferedInputStream(fileInputStream); + byte[] bs = new byte[1024]; + int len = 0; + response.reset(); // 闈炲父閲嶈 + if (flag) { + // 鍦ㄧ嚎鎵撳紑鏂瑰紡 + URL u = new URL("file:///" + filePath); + //System.out.println(u); + String contentType = u.openConnection().getContentType(); + response.setContentType(contentType); + response.setHeader("Content-Disposition", "inline;filename=" + +substring+ tjNumber + ".pdf"); + } else { + // 绾笅杞芥柟寮� + response.setContentType("application/x-msdownload"); + response.setContentType("application/pdf;charset=utf-8"); + response.setHeader("Content-Disposition", "attachment;filename=" + +substring+ tjNumber + ".pdf"); + } + out = response.getOutputStream(); + while ((len = br.read(bs)) > 0) { + out.write(bs, 0, len); + } + out.flush(); + out.close(); + br.close(); + fileInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + //System.out.println("pdf澶勭悊鏂囦欢寮傚父" + e); + } finally { + if (out != null) { + try { + out.close(); + br.close(); + fileInputStream.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + + /** * 灏忕▼搴忔煡璇綋妫�鍘嗗彶鎶ュ憡鍒楄〃 */ diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java index 10c1554..65ba644 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/app/WxloginController.java @@ -1,5 +1,6 @@ package com.ltkj.web.controller.app; +import cn.hutool.core.date.DateTime; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -25,6 +26,7 @@ import org.aspectj.bridge.MessageWriter; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.springframework.beans.factory.annotation.Value; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; import sun.misc.BASE64Decoder; @@ -71,6 +73,7 @@ /** * 灏忕▼搴忕櫥褰� + * * @param code 灏忕▼搴弚x.login杩斿洖鐨勪复鏃跺嚟璇� * @return */ @@ -110,7 +113,7 @@ wxuser.setCreateTime(new Date()); wxuser.setWxMiniOpenId(openId); wxuserService.save(wxuser); - map.put("wxuser",wxuser); + map.put("wxuser", wxuser); } // 鐢熸垚浠ょ墝 String token = JwtUtils.getToken(map); @@ -130,11 +133,12 @@ @ApiOperation(value = "灏忕▼搴忚幏鍙栫敤鎴疯鎯呬俊鎭帴鍙�") public AjaxResult getWxInfo() { Wxuser wxuser = UserHoder.getWxuser(); - LambdaQueryWrapper<Wxuser>wq=new LambdaQueryWrapper<>(); - wq.eq(Wxuser::getOpenid,wxuser.getOpenid()); + LambdaQueryWrapper<Wxuser> wq = new LambdaQueryWrapper<>(); + wq.eq(Wxuser::getOpenid, wxuser.getOpenid()); Wxuser one = wxuserService.getOne(wq); return AjaxResult.success(one); } + /** * 寰俊鎵嬫満鍙风爜缁戝畾 */ @@ -156,7 +160,7 @@ byte[] raw = decoder.decodeBuffer(sessionKey); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); IvParameterSpec iv1 = new IvParameterSpec(decoder.decodeBuffer(iv)); - Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding","BC"); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv1); OkHttpClient client = new OkHttpClient(); Request okrequest = new Request.Builder() @@ -191,6 +195,7 @@ /** * 鍙戦�佽姹傜敤code鎹㈠彇sessionKey鍜岀浉鍏充俊鎭� + * * @param code * @return */ @@ -226,7 +231,7 @@ byte[] ivByte = Base64.decode(iv); try { - // 濡傛灉瀵嗛挜涓嶈冻16浣嶏紝閭d箞灏辫ˉ瓒�. 杩欎釜if 涓殑鍐呭寰堥噸瑕� + // 濡傛灉瀵嗛挜涓嶈冻16浣嶏紝閭d箞灏辫ˉ瓒�. 杩欎釜if 涓殑鍐呭寰堥噸瑕� int base = 16; if (keyByte.length % base != 0) { int groups = keyByte.length / base + (keyByte.length % base != 0 ? 1 : 0); @@ -235,7 +240,7 @@ System.arraycopy(keyByte, 0, temp, 0, keyByte.length); keyByte = temp; } - // 鍒濆鍖� + // 鍒濆鍖� Security.addProvider(new BouncyCastleProvider()); /** * 瑙e喅java涓嶆敮鎸丄ES/CBC/PKCS7Padding妯″紡瑙e瘑 @@ -257,7 +262,6 @@ } return null; } - /** @@ -346,5 +350,27 @@ return response; } + + @PostMapping("/wx/wxbindphone") + @ApiOperation("鎵嬪姩缁戝畾鎵嬫満鍙锋帴鍙�") + @Transactional + public AjaxResult wxbindphone(@RequestParam @ApiParam(value = "openId") String openId, + @RequestParam @ApiParam(value = "phone") String phone) { + + LambdaQueryWrapper<Wxuser> wq = new LambdaQueryWrapper<>(); + wq.eq(Wxuser::getOpenid, openId); + Wxuser one = wxuserService.getOne(wq); + + if (one!=null){ + one.setPhone(phone); + one.setUpdateTime(new DateTime()); + final boolean b = wxuserService.updateById(one); + if (b){ + return AjaxResult.success("缁戝畾鎴愬姛锛�"); + } + } + return AjaxResult.error("缁戝畾澶辫触锛�"); + } + } diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjReportController.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjReportController.java index e0aade3..0668165 100644 --- a/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjReportController.java +++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/system/TjReportController.java @@ -77,6 +77,8 @@ private ITjReportTemplateService reportTemplateService; @Value("${path.filePath}") private String value; + @Value("${path.reportServer}") + private String urlValue; @Resource private ISysUserService userService; @Resource @@ -702,7 +704,7 @@ TjReport tjReport = new TjReport(); tjReport.setTjNumber(String.valueOf(tjNumber)); - tjReport.setPath(outputPath1 + outputFileName1); + tjReport.setPath(urlValue + outputFileName1); String pdfBinary = getPDFBinary(outputPath1 + outputFileName1); tjReport.setReport(pdfBinary); tjReport.setType("浣撴鎶ュ憡"); diff --git a/ltkj-admin/src/main/resources/application.yml b/ltkj-admin/src/main/resources/application.yml index 01f01e8..28df653 100644 --- a/ltkj-admin/src/main/resources/application.yml +++ b/ltkj-admin/src/main/resources/application.yml @@ -11,8 +11,8 @@ # 鏂囦欢璺緞 绀轰緥锛� Windows閰嶇疆D:/ltkj/uploadPath锛孡inux閰嶇疆 /home/ltkj/uploadPath锛� # 鐢ㄦ埛鎹㈠ご鍍忓悗鐨勫浘鐗囧瓨鍌ㄥ湴鍧� 娴嬭瘯锛欴:\ltkj\uploadPath\avatar\2022\12\14 #profile: D:/ltkj/uploadPath -# profile: https://ltpeis.xaltjdkj.cn:5502/uploadPath - profile: http://192.168.0.5:5502/uploadPath + profile: https://ltpeis.xaltjdkj.cn:5502/uploadPath +# profile: http://192.168.0.5:5502/uploadPath # 鑾峰彇ip鍦板潃寮�鍏� addressEnabled: true @@ -176,12 +176,17 @@ # 浣撴鎶ュ憡妯℃澘鍜屾姤鍛婁复鏃剁敓鎴愬瓨鍌ㄧ殑鏂囦欢澶硅矾寰� path: filePath: D:\Tjreport + # nginx鍥剧墖鏈嶅姟鍣� + reportServer: https://ltpeis.xaltjdkj.cn:5516/ + # 浣撴濂楅鍜岃疆鎾浘瀛樺偍璺緞 photoPath: D:\AppPhoto\uploadPath\ # nginx鍥剧墖鏈嶅姟鍣� -#photoServer: https://ltpeis.xaltjdkj.cn:5502/uploadPath/ -photoServer: http://192.168.0.5:5502/uploadPath/ +photoServer: https://ltpeis.xaltjdkj.cn:5502/uploadPath/ +#photoServer: http://192.168.0.5:5502/uploadPath/ + + # 寰俊灏忕▼搴廰ppid secret xcx: -- Gitblit v1.8.0