From a29e0df3c165dfe2ddd825bb340ed480a64865db Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期四, 02 四月 2026 15:02:30 +0800
Subject: [PATCH] 解决冲突
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolPointServiceImpl.java | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 156 insertions(+), 12 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolPointServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolPointServiceImpl.java
index 4265e5c..12799da 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolPointServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolPointServiceImpl.java
@@ -7,6 +7,7 @@
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
+import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwPatrolPointMapper;
import com.doumee.dao.business.model.Category;
@@ -21,14 +22,32 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+import com.google.zxing.qrcode.encoder.ByteMatrix;
+import com.google.zxing.qrcode.encoder.Encoder;
+import com.google.zxing.qrcode.encoder.QRCode;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.util.*;
/**
* 杩愮淮宸℃鐐逛俊鎭〃Service瀹炵幇
@@ -48,15 +67,21 @@
@Override
public Integer create(YwPatrolPoint ywPatrolPoint) {
if(Objects.isNull(ywPatrolPoint)
- || Objects.isNull(ywPatrolPoint.getCode())
+// || Objects.isNull(ywPatrolPoint.getCode())
|| Objects.isNull(ywPatrolPoint.getName())
){
throw new BusinessException(ResponseStatus.BAD_REQUEST);
}
- if(ywPatrolPointMapper.selectCount(new QueryWrapper<YwPatrolPoint>().lambda().eq(YwPatrolPoint::getIsdeleted,Constants.ZERO)
- .eq(YwPatrolPoint::getCode,ywPatrolPoint.getCode()))>Constants.ZERO){
- throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"宸℃鐐圭紪鐮侀噸澶�!");
+
+ String pre = systemDictDataBiz.queryByCode(Constants.XUNJIAN,Constants.XJ_POINT_PREFIX).getCode();
+ int length = 8;
+ try {
+ length = Integer.parseInt(systemDictDataBiz.queryByCode(Constants.XUNJIAN,Constants.XJ_POINT_CODE_LENGTH).getCode());
+ }catch (Exception e){
}
+ long num = ywPatrolPointMapper.selectCount(new QueryWrapper<YwPatrolPoint>());
+
+ ywPatrolPoint.setCode(pre+Constants.formartNumString (length,(num+1)));
LoginUserInfo loginUserInfo = ywPatrolPoint.getLoginUserInfo();
ywPatrolPoint.setCreateDate(new Date());
ywPatrolPoint.setCreator(loginUserInfo.getId());
@@ -81,10 +106,11 @@
@Override
public void deleteById(Integer id, LoginUserInfo user) {
- ywPatrolPointMapper.update(new UpdateWrapper<YwPatrolPoint>().lambda().set(YwPatrolPoint::getIsdeleted,Constants.ONE)
- .set(YwPatrolPoint::getEditDate," now() ")
+ ywPatrolPointMapper.update(new UpdateWrapper<YwPatrolPoint>().lambda()
+ .set(YwPatrolPoint::getIsdeleted,Constants.ONE)
+ .set(YwPatrolPoint::getEditDate, DateUtil.getCurrDateTime())
.set(YwPatrolPoint::getEditor,user.getId())
- .eq(YwPatrolPoint::getId,user.getId())
+ .eq(YwPatrolPoint::getId,id)
);
}
@@ -93,7 +119,120 @@
UpdateWrapper<YwPatrolPoint> deleteWrapper = new UpdateWrapper<>(ywPatrolPoint);
ywPatrolPointMapper.delete(deleteWrapper);
}
+ @Override
+ public void exportQrcodes(Integer id, HttpServletResponse response){
+ try {
+ List<File> fileList = new ArrayList<>();
+ List<YwPatrolPoint> bikesList = ywPatrolPointMapper.selectList(new QueryWrapper<YwPatrolPoint>().lambda()
+ .eq(YwPatrolPoint::getIsdeleted,Constants.ZERO)
+ .eq(id!=null,YwPatrolPoint::getId,id)
+ );
+ if(bikesList== null || bikesList.size() == 0){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
+ // 鍒涘缓涓存椂鏂囦欢鐨勫墠缂�鍜屽悗缂�
+ String path = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_AUTH_URL).getCode();
+ String uri = systemDictDataBiz.queryByCode(Constants.XUNJIAN,Constants.XJ_RERIRECT_URI).getCode();
+ String appId = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_APPID).getCode() ;
+ // 鍒涘缓涓存椂鏂囦欢
+ for(YwPatrolPoint l : bikesList){
+ if(StringUtils.isNotBlank(l.getCode())){
+ String redirectUri = uri.replace("${ywid}",l.getCode());
+ String url = path.replace("${url}",URLEncoder.encode(redirectUri)).replace("${appid}",appId);
+ File file = generateQRCodeImage(url,100,100,l.getCode()+".png");
+ if(file!=null && file.isFile()){
+ fileList.add(file);
+ }
+ }
+ }
+ if(fileList == null || fileList.size() == 0){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"瀵逛笉璧凤紝涓嬭浇鍐呭涓虹┖锛屾搷浣滃け璐ワ紒");
+ }
+ String fileName = "宸℃鐐逛簩缁寸爜瀵煎嚭_"+System.currentTimeMillis()+".zip" ;
+ String encodeFileName =URLEncoder.encode(fileName, Charset.forName("UTF-8").toString())+".zip";
+ response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
+ response.setContentType("application/octet-stream");
+ response.setHeader("eva-opera-type", "download");
+ response.setHeader("eva-download-filename", encodeFileName);
+ packFilesToZip(fileList,response.getOutputStream());
+ } catch (IOException e) {
+ throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
+ }
+ }
+ public static File generateQRCodeImage(String text, int width, int height, String fileName) {
+ try {
+ // 鍒涘缓浜岀淮鐮佹暟鎹煩闃�
+ Map<EncodeHintType, Object> hints = new HashMap<>();
+ hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); // 璁剧疆瀛楃缂栫爜涓篣TF-8
+ hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // 璁剧疆绾犻敊绛夌骇涓篐
+ hints.put(EncodeHintType.MARGIN, 0); // 璁剧疆鐧借竟涓�0
+ BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE , width, height, hints);
+ // 淇濆瓨浜岀淮鐮佸浘鐗囧埌鏂囦欢绯荤粺
+ File f = new File("temp/");
+ if(!f.exists()){
+ f.mkdirs();
+ }
+// bitMatrix = renderResult(bitMatrix,width,height);
+ Path path = FileSystems.getDefault().getPath("temp/"+fileName);
+ MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path); // 淇濆瓨涓篜NG鏍煎紡鐨勫浘鐗�
+ return path.toFile();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static void main(String[] args) {
+ File f =generateQRCodeImage("dj灏戞椂璇佃瘲涔﹀皯鏃惰璇椾功鏄拻鏄拻鏄拻",100,100,UUID.randomUUID().toString()+".png");
+ System.out.println(f.getAbsolutePath());
+ }
+
+ private static BitMatrix renderResult(BitMatrix input, int width, int height) {
+ if (input == null) {
+ return null;
+ }
+ int inputWidth = input.getWidth();
+ int inputHeight = input.getHeight();
+ // 渚濇嵁鐢ㄦ埛鐨勮緭鍏ュ楂橈紝璁$畻鏈�鍚庣殑杈撳嚭瀹介珮
+ int outputWidth = Math.max(width, inputWidth);
+ int outputHeight = Math.max(height, inputHeight);
+
+ //璁$畻缂╂斁姣斾緥
+ int multiple = Math.min(outputWidth / inputWidth, outputHeight / inputHeight);
+
+ BitMatrix output = new BitMatrix(outputWidth, outputHeight);
+ int inputY = 0;
+ // 宓屽寰幆锛屽皢ByteMatrix鐨勫唴瀹硅绠梡adding鍚庤浆鎹㈡垚BitMatrix
+ for (int outputY = 0; inputY < inputHeight; outputY += multiple) {
+ int inputX = 0;
+ for (int outputX = 0; inputX < inputWidth; outputX += multiple) {
+ if (input.get(inputX, inputY)) {
+ output.setRegion(outputX, outputY, multiple, multiple);
+ }
+ inputX++;
+ }
+ inputY++;
+ }
+
+ return output;
+ }
+ public static void packFilesToZip(List<File> files, ServletOutputStream os) throws IOException {
+ try (ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(os)) {
+ for (File file : files) {
+ ZipArchiveEntry entry = new ZipArchiveEntry(file.getName());
+ zipOutputStream.putArchiveEntry(entry);
+ try (FileInputStream fileInputStream = new FileInputStream(file)) {
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = fileInputStream.read(buffer)) > 0) {
+ zipOutputStream.write(buffer, 0, length);
+ }
+ }
+ zipOutputStream.closeArchiveEntry();
+ }
+ }
+ }
@Override
public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
if (CollectionUtils.isEmpty(ids)) {
@@ -156,13 +295,18 @@
@Override
public YwPatrolPoint getDetail(Integer id) {
YwPatrolPoint ywPatrolPoint = ywPatrolPointMapper.selectById(id);
+ if(Objects.isNull(ywPatrolPoint)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY);
+ }
Multifile multifile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getObjId,id)
- .eq(Multifile::getObjType,Constants.MultiFile.FN_PATROL_POINT_FILE).last(" limit 1"));
- if(Objects.nonNull(multifile)){
+ .eq(Multifile::getObjType,Constants.MultiFile.FN_PATROL_POINT_FILE.getKey()).orderByDesc(Multifile::getId).last(" limit 1"));
+ if(Objects.nonNull(multifile) && StringUtils.isNotBlank(multifile.getFileurl())){
String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
+systemDictDataBiz.queryByCode(Constants.FTP,Constants.YW_PATROL).getCode();
ywPatrolPoint.setFileFullUrl(path + multifile.getFileurl());
+ ywPatrolPoint.setFileUrl(multifile.getFileurl());
}
+
return ywPatrolPoint;
}
--
Gitblit v1.9.3