Commit d3aa88d7 authored by lihulong's avatar lihulong

李湖龙2025-8-25批量打印逻辑修改

parent 54fcf203
...@@ -153,6 +153,9 @@ public class InfoController { ...@@ -153,6 +153,9 @@ public class InfoController {
@Operation(summary = "获得客户拜访打印信息根据公司名称") @Operation(summary = "获得客户拜访打印信息根据公司名称")
@PreAuthorize("@ss.hasPermission('visit:customer-info:print')") @PreAuthorize("@ss.hasPermission('visit:customer-info:print')")
public CommonResult<List<InfoPrintVO>> getPrintListByCompanyName(@RequestParam("companyName") String companyName) { public CommonResult<List<InfoPrintVO>> getPrintListByCompanyName(@RequestParam("companyName") String companyName) {
if (companyName.isEmpty()){
throw new RuntimeException("公司名称获取异常!");
}
InfoPrintVO info = infoService.getInfoByCompanyName(companyName); InfoPrintVO info = infoService.getInfoByCompanyName(companyName);
List<InfoPrintVO> infoPrintVO = new ArrayList<>(); List<InfoPrintVO> infoPrintVO = new ArrayList<>();
if (info == null){ if (info == null){
......
...@@ -19,6 +19,8 @@ import org.apache.http.entity.ContentType; ...@@ -19,6 +19,8 @@ import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -46,6 +48,7 @@ import static java.nio.file.Files.createFile; ...@@ -46,6 +48,7 @@ import static java.nio.file.Files.createFile;
@Validated @Validated
public class InfoServiceImpl implements InfoService { public class InfoServiceImpl implements InfoService {
private static final Logger log = LoggerFactory.getLogger(InfoServiceImpl.class);
@Resource @Resource
private InfoMapper infoMapper; private InfoMapper infoMapper;
...@@ -243,11 +246,11 @@ public class InfoServiceImpl implements InfoService { ...@@ -243,11 +246,11 @@ public class InfoServiceImpl implements InfoService {
info.forEach(infoDO -> { info.forEach(infoDO -> {
InfoPrintVO infoPrintVO = new InfoPrintVO(); InfoPrintVO infoPrintVO = new InfoPrintVO();
infoPrintVO.setServiceContent(Collections.singletonList(infoDO.getServiceContent()));//本次服务内容 infoPrintVO.setServiceContent(Collections.singletonList(infoDO.getServiceContent()));//本次服务内容
//服务图片(最多张) //服务图片(最多10张)
String imagesStr = infoDO.getServiceImages(); String imagesStr = infoDO.getServiceImages();
if (StringUtils.isNotBlank(imagesStr)) { if (StringUtils.isNotBlank(imagesStr)) {
String limitedImagesStr = Arrays.stream(imagesStr.split(",")) String limitedImagesStr = Arrays.stream(imagesStr.split(","))
.limit(4) .limit(10)
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
infoPrintVO.setServiceImages(limitedImagesStr); infoPrintVO.setServiceImages(limitedImagesStr);
} else { } else {
...@@ -271,9 +274,9 @@ public class InfoServiceImpl implements InfoService { ...@@ -271,9 +274,9 @@ public class InfoServiceImpl implements InfoService {
@Override @Override
public InfoPrintVO getInfoByCompanyName(String companyName) { public InfoPrintVO getInfoByCompanyName(String companyName) {
InfoPrintVO infoPrintVO = new InfoPrintVO(); InfoPrintVO infoPrintVO = new InfoPrintVO();
//服务内容(最近次) //服务内容(最近次)
List<String> serviceContent = new ArrayList<>(); List<String> serviceContent = new ArrayList<>();
//服务图片(最多张) //服务图片(最多张)
List<String> serviceImages = new ArrayList<>(); List<String> serviceImages = new ArrayList<>();
//拜访时间记录 //拜访时间记录
List<LocalDate> visitDateList = new ArrayList<>(); List<LocalDate> visitDateList = new ArrayList<>();
...@@ -281,26 +284,35 @@ public class InfoServiceImpl implements InfoService { ...@@ -281,26 +284,35 @@ public class InfoServiceImpl implements InfoService {
YearMonth currentYearMonth = YearMonth.now(); YearMonth currentYearMonth = YearMonth.now();
//现根据客户名称获取历史拜访记录 //现根据客户名称获取历史拜访记录
List<InfoDO> info = infoMapper.selectByCompanyName(companyName); List<InfoDO> info = infoMapper.selectByCompanyName(companyName);
System.out.println("拜访信息" + info);
if (info != null && !info.isEmpty()){ if (info != null && !info.isEmpty()){
//取最近 //取最近
info = info.stream() info = info.stream()
// 筛选本月记录(基于 LocalDateTime) // 筛选本月记录(基于 LocalDateTime)
.filter(infoDO -> { // .filter(infoDO -> {
LocalDateTime visitDateTime = infoDO.getVisitDate(); // LocalDateTime visitDateTime = infoDO.getVisitDate();
return YearMonth.from(visitDateTime.toLocalDate()).equals(currentYearMonth); // return YearMonth.from(visitDateTime.toLocalDate()).equals(currentYearMonth);
}) // })
.sorted(Comparator.comparing(InfoDO::getVisitDate).reversed()).limit(4).collect(Collectors.toList()); .sorted(Comparator.comparing(InfoDO::getVisitDate)).limit(5).collect(Collectors.toList());
//取最多4张服务图片 //取最多10张服务图片
int maxImages = 4; int maxImages = 10;
int maxObjects = 5; // 最多处理5个对象
int objectCount = 0; // 对象计数器
for (InfoDO infoDO : info) { for (InfoDO infoDO : info) {
if (serviceImages.size() >= maxImages) break; // 超过最大对象数或已收集足够图片则停止
if (objectCount >= maxObjects || serviceImages.size() >= maxImages) break;
String imagesStr = infoDO.getServiceImages(); String imagesStr = infoDO.getServiceImages();
if (StringUtils.isNotBlank(imagesStr)) { if (StringUtils.isNotBlank(imagesStr)) {
List<String> imageList = Arrays.asList(imagesStr.split(",")); List<String> imageList = Arrays.asList(imagesStr.split(","));
int remaining = maxImages - serviceImages.size(); int remaining = maxImages - serviceImages.size();
serviceImages.addAll(imageList.stream().limit(remaining).collect(Collectors.toList())); // 每个对象最多取2张,同时不超过剩余需要数量
int take = Math.min(2, remaining);
serviceImages.addAll(imageList.stream().limit(take).collect(Collectors.toList()));
} }
objectCount++;
} }
//获取客户拜访记录成功,获取客户信息 //获取客户拜访记录成功,获取客户信息
info.forEach(infoDO -> { info.forEach(infoDO -> {
...@@ -326,7 +338,7 @@ public class InfoServiceImpl implements InfoService { ...@@ -326,7 +338,7 @@ public class InfoServiceImpl implements InfoService {
//拜访次数 //拜访次数
infoPrintVO.setServiceCount(info.size()); infoPrintVO.setServiceCount(info.size());
}else { }else {
return null; return infoPrintVO;
} }
return infoPrintVO; return infoPrintVO;
} }
......
...@@ -4,8 +4,8 @@ NODE_ENV=development ...@@ -4,8 +4,8 @@ NODE_ENV=development
VITE_DEV=true VITE_DEV=true
# 请求路径 # 请求路径
# VITE_BASE_URL='http://192.168.0.182:48080' VITE_BASE_URL='http://192.168.0.144:48080'
VITE_BASE_URL='https://hntqwl.com' #VITE_BASE_URL='https://hntqwl.com'
# VITE_BASE_URL='http://localhost:48080' # VITE_BASE_URL='http://localhost:48080'
# 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务 # 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持 S3 服务
......
...@@ -84,6 +84,7 @@ export const InfoApi = { ...@@ -84,6 +84,7 @@ export const InfoApi = {
//查询打印客户拜访记录 //查询打印客户拜访记录
getPrintListByCompanyName: async (companyName: string) => { getPrintListByCompanyName: async (companyName: string) => {
console.log(companyName)
return await request.get({ url: `/visit/info/getPrintListByCompanyName`, params: { companyName } }) return await request.get({ url: `/visit/info/getPrintListByCompanyName`, params: { companyName } })
}, },
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</slot> </slot>
</div> </div>
<template #file="{ file }"> <template #file="{ file }">
<img :src="file.url" class="upload-image" /> <img :src="file.url" class="upload-image" @contextmenu.prevent />
<div class="upload-handle" @click.stop> <div class="upload-handle" @click.stop>
<div class="handle-icon" @click="imagePreview(file.url!)"> <div class="handle-icon" @click="imagePreview(file.url!)">
<Icon icon="ep:zoom-in" /> <Icon icon="ep:zoom-in" />
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { UploadFile, UploadProps, UploadUserFile } from 'element-plus' import type { UploadFile, UploadProps, UploadUserFile } from 'element-plus'
import { ElNotification } from 'element-plus' import { ElNotification } from 'element-plus'
import { nextTick } from 'vue';
import { createImageViewer } from '@/components/ImageViewer' import { createImageViewer } from '@/components/ImageViewer'
import { propTypes } from '@/utils/propTypes' import { propTypes } from '@/utils/propTypes'
...@@ -56,7 +57,15 @@ const imagePreview = (imgUrl: string) => { ...@@ -56,7 +57,15 @@ const imagePreview = (imgUrl: string) => {
createImageViewer({ createImageViewer({
zIndex: 9999999, zIndex: 9999999,
urlList: [imgUrl] urlList: [imgUrl]
}) });
nextTick(() => {
// 禁止预览图右键
const viewer = document.querySelector('.el-image-viewer__wrapper');
if (viewer) {
viewer.addEventListener('contextmenu', (e) => e.preventDefault());
}
});
} }
type FileTypes = type FileTypes =
......
...@@ -242,7 +242,6 @@ const printComp = ref() ...@@ -242,7 +242,6 @@ const printComp = ref()
const handlePrint = async (companyName) => { const handlePrint = async (companyName) => {
printData.value = await InfoApi.getPrintListByCompanyName(companyName) printData.value = await InfoApi.getPrintListByCompanyName(companyName)
await nextTick() await nextTick()
console.log(printData.value)
//判断是否有数据 //判断是否有数据
if (printData.value.length === 0) { if (printData.value.length === 0) {
message.warning('该客户暂无拜访记录') message.warning('该客户暂无拜访记录')
......
...@@ -141,18 +141,23 @@ ...@@ -141,18 +141,23 @@
</div> </div>
<div <div
style="display: flex; style="display: flex;
flex-direction: column; /*flex-direction: column;*/
height: 800px; /* 父容器高度,按需设置 */" flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
height: 160px; /* 父容器高度,按需设置 */"
> >
<img <img
crossorigin="anonymous" crossorigin="anonymous"
v-for="(url, i) in getSafeImages(item.serviceImages)" v-for="(url, i) in getSafeImages(item.serviceImages)"
:key="i" :key="i"
:src="url" :src="url"
style="width: 100%; style="
height: 25%; width: 48%;
height: 100%;
object-fit: fill;/* cover是切一部分 */ object-fit: fill;/* cover是切一部分 */
border: 1px solid #ccc;" border: 1px solid #ccc;
margin: 5px 0"
/> />
</div> </div>
</div> </div>
...@@ -168,14 +173,24 @@ import {DICT_TYPE, getDictLabel} from "@/utils/dict"; ...@@ -168,14 +173,24 @@ import {DICT_TYPE, getDictLabel} from "@/utils/dict";
const props = defineProps({ dataList: Array }) const props = defineProps({ dataList: Array })
const printRef = ref(null) const printRef = ref(null)
const serviceImagesList = ref([])
serviceImagesList.value = props.dataList.map(item => item.serviceImages)
const formatDate = (date: string | Date) => { const formatDate = (date: string | Date) => {
const d = new Date(date) const d = new Date(date)
return d.toLocaleDateString() return d.toLocaleDateString()
} }
const getSafeImages = (val?: string) => { const getSafeImages = (val?: string) => {
if (!val||val==='') return [] if (!val||val==='') return []
return val.split(',').slice(0, 4) console.log(val)
return val.split(',').slice(0, 10)
} }
// const getSafeImages = (imageStr: string) => {
// if (!imageStr) return [];
// return imageStr.split(',').filter(url => url.trim() !== '').map(url => {
// return url;
// });
// };
defineExpose({ printRef }) defineExpose({ printRef })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment