Commit dddd49f1 authored by fangxinjiang's avatar fangxinjiang

自定义字体-fxj

parent 1934370c
...@@ -59,6 +59,14 @@ public class TSocialFriendController { ...@@ -59,6 +59,14 @@ public class TSocialFriendController {
private final TSocialFriendPushService tSocialFriendPushService; private final TSocialFriendPushService tSocialFriendPushService;
private final TSocialFreindPushAndGetService tSocialFreindPushAndGetService; private final TSocialFreindPushAndGetService tSocialFreindPushAndGetService;
@Operation(description = "测试")
@PostMapping("/doTest")
@SysLog("测试")
public R<String> test() {
return tSocialFriendPushService.test();
}
@Operation(description = "1定时任务推送税友") @Operation(description = "1定时任务推送税友")
@PostMapping("/inner/doPushFriend") @PostMapping("/inner/doPushFriend")
@SysLog("1定时任务推送税友") @SysLog("1定时任务推送税友")
......
...@@ -42,4 +42,6 @@ public interface TSocialFriendPushService extends IService<TSocialInfo> { ...@@ -42,4 +42,6 @@ public interface TSocialFriendPushService extends IService<TSocialInfo> {
R<String> pushFriend(List<String> dispatchIdList); R<String> pushFriend(List<String> dispatchIdList);
R<String> doExportRoster(String socialId, String type, String unitCreditCode, List<SociaFriendYgsAddVo> listVo); R<String> doExportRoster(String socialId, String type, String unitCreditCode, List<SociaFriendYgsAddVo> listVo);
R<String> test();
} }
...@@ -38,6 +38,7 @@ import com.yifu.cloud.plus.v1.yifu.social.mapper.*; ...@@ -38,6 +38,7 @@ import com.yifu.cloud.plus.v1.yifu.social.mapper.*;
import com.yifu.cloud.plus.v1.yifu.social.service.*; import com.yifu.cloud.plus.v1.yifu.social.service.*;
import com.yifu.cloud.plus.v1.yifu.social.util.ExcelMergeImage; import com.yifu.cloud.plus.v1.yifu.social.util.ExcelMergeImage;
import com.yifu.cloud.plus.v1.yifu.social.util.ExcelToImage; import com.yifu.cloud.plus.v1.yifu.social.util.ExcelToImage;
import com.yifu.cloud.plus.v1.yifu.social.util.RandomFontStyleUtil;
import com.yifu.cloud.plus.v1.yifu.social.util.WordToImageUtil; import com.yifu.cloud.plus.v1.yifu.social.util.WordToImageUtil;
import com.yifu.cloud.plus.v1.yifu.social.vo.*; import com.yifu.cloud.plus.v1.yifu.social.vo.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
...@@ -1035,7 +1036,113 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1035,7 +1036,113 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
inputStreamOut.close(); inputStreamOut.close();
} }
} }
@Override
public R<String> test(){
SociaFriendYgsAddVo vo = new SociaFriendYgsAddVo();
vo.setSocialHouseholdName("11111111");
vo.setSocialId("22222222");
vo.setEmpName("房新江");
List<SociaFriendYgsAddVo> listVo = new ArrayList<>();
listVo.add(vo);
vo = new SociaFriendYgsAddVo();
vo.setSocialHouseholdName("11111111");
vo.setSocialId("22222222");
vo.setEmpName("张叁");
listVo.add(vo);
vo = new SociaFriendYgsAddVo();
vo.setSocialHouseholdName("11111111");
vo.setSocialId("22222222");
vo.setEmpName("张叁");
listVo.add(vo);
vo = new SociaFriendYgsAddVo();
vo.setSocialHouseholdName("11111111");
vo.setSocialId("22222222");
vo.setEmpName("张叁");
listVo.add(vo);
vo = new SociaFriendYgsAddVo();
vo.setSocialHouseholdName("11111111");
vo.setSocialId("22222222");
vo.setEmpName("张叁");
listVo.add(vo);
vo = new SociaFriendYgsAddVo();
vo.setSocialHouseholdName("11111111");
vo.setSocialId("22222222");
vo.setEmpName("张叁");
listVo.add(vo);
String huId ="1911679205825486849";
String fileName = DispatchConstants.SOCIAL_MEDICAL_EXPORT + vo.getSocialHouseholdName() + "_" + vo.getSocialId() + CommonConstants.XLS;
String projectRoot = System.getProperty(CommonConstants.USER_DIR);
String filePath = projectRoot + CommonConstants.DOUBLE_LINE + fileName;
//获取要导出的列表
List<TDispatchSocialPersionExportVo> list = new ArrayList<>();
ExcelWriter excelWriter = null;
File createFile = null;
try {
// 通用的模板+查到的户的模板map
Map<String, URL> templateSrcMap = new HashMap<>();
// 通用的花名册模板
List<TAttaInfo> srcList = attaInfoMapper.getTemplateSrcById();
URL url;
if (srcList != null && !srcList.isEmpty()) {
for (TAttaInfo src : srcList) {
url = ossUtil.getObjectUrl(null, src.getAttaSrc());
templateSrcMap.put("template_" + src.getId(), url);
}
}
int type = CommonConstants.TWO_INT;
String templateId = "template_11";
String relationType = "11";
if (type == CommonConstants.TWO_INT) {
templateId = "template_12";
relationType = "12";
} else if (type == CommonConstants.THREE_INT) {
templateId = "template_13";
relationType = "13";
} else if (type == CommonConstants.FOUR_INT) {
templateId = "template_14";
relationType = "14";
}
String huKey = type + CommonConstants.DOWN_LINE_STRING + huId;
URL templateUrl = templateSrcMap.get(huKey);
if (Common.isEmpty(templateUrl)) {
String templateSrc = attaInfoMapper.getTemplateSrcByIdAndType(huId, relationType);
if (Common.isNotNull(templateSrc)) {
templateUrl = ossUtil.getObjectUrl(null, templateSrc);
} else {
templateUrl = templateSrcMap.get(templateId);
templateSrcMap.put(huKey, templateUrl);
}
}
if (Common.isEmpty(templateUrl)) {
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":花名册模板OSS获取URL异常");
}
InputStream templateInStream = templateUrl.openStream();
if (Common.isEmpty(templateInStream)) {
return R.failed(CommonConstants.RESULT_DATA_FAIL + ":花名册模板OSS获取流异常");
}
try (Workbook workbook = WorkbookFactory.create(templateInStream)) {
Sheet sheet = workbook.getSheetAt(0);
// 1. 填充主表数据
fillMainData(sheet, vo);
// 2. 填充明细表数据
fillDetailData(sheet, listVo);
// 保存文件
try (FileOutputStream fos = new FileOutputStream(filePath)) {
workbook.write(fos);
}
} catch (Exception e) {
throw new RuntimeException("填充Excel模板失败", e);
}
} catch (Exception e) {
throw new RuntimeException("填充Excel模板失败", e);
}
return R.ok("成功");
}
/** /**
* @Author hgw * @Author hgw
* @Description 社保增减花名册 * @Description 社保增减花名册
...@@ -1222,8 +1329,9 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe ...@@ -1222,8 +1329,9 @@ public class TSocialFriendPushServiceImpl extends ServiceImpl<TSocialFriendMappe
**/ **/
private static void setQianMingStyle(Cell cell, String value) { private static void setQianMingStyle(Cell cell, String value) {
if (cell != null && Common.isNotNull(value)) { if (cell != null && Common.isNotNull(value)) {
// 加签名样式 // 加签名样式 随机的【潦草】字体样式设置
cell.setCellValue(value); //cell.setCellValue(value);
RandomFontStyleUtil.setRandomSignatureStyle(cell, value);
} }
} }
......
package com.yifu.cloud.plus.v1.yifu.social.util;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import lombok.extern.log4j.Log4j2;
import org.apache.poi.ss.usermodel.*;
import java.util.Random;
/**
* @Author fxj
* @Date 2025/9/10
* @Description 随机签名样式工具类
* @Version 1.0
*/
@Log4j2
public class RandomFontStyleUtil {
// 常见中文字体列表
private static final String[] FONT_NAMES = {
"宋体", "楷体", "仿宋", "黑体", "幼圆","微软雅黑",
"隶书", "华文隶书","华文行楷", "方正舒体"
};
// 字体大小范围
private static final int MIN_FONT_SIZE = 11;
private static final int MAX_FONT_SIZE = 13;
/**
* 为单元格设置随机字体样式
* @param cell Excel单元格
* @param value 单元格值
*/
public static void setRandomSignatureStyle(Cell cell, String value) {
if (cell != null && Common.isNotNull(value)) {
Workbook workbook = cell.getRow().getSheet().getWorkbook();
Font font = workbook.createFont();
// 设置随机字体
Random random = new Random();
font.setFontName(FONT_NAMES[random.nextInt(FONT_NAMES.length)]);
log.error("随机字体:" + font.getFontName());
// 设置随机字体大小
font.setFontHeightInPoints((short) (MIN_FONT_SIZE + random.nextInt(MAX_FONT_SIZE - MIN_FONT_SIZE + 1)));
// 随机设置粗体
if (random.nextBoolean()) {
font.setBold(true);
}
// 随机设置斜体
if (random.nextBoolean()) {
font.setItalic(true);
}
// 创建单元格样式并应用字体
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(font);
//设置单元格边框样式
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cell.setCellStyle(cellStyle);
cell.setCellValue(value);
}
}
}
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